Example #1
0
 private function setOfferTable()
 {
     $this->offerTable = new Extension_View_Yui35_DataTable();
     $eventTypesValues = new Model_EventTypesValueModel();
     $eventTypesValues->addQuery('select', array('table' => $eventTypesValues->getTableName()));
     $eventTypesId = $this->getEventTypesId();
     if (is_numeric($eventTypesId)) {
         $eventTypesValues->addQuery('where', array('where_condition' => 'event_types_id_FK=' . (int) $eventTypesId));
     } else {
         return;
     }
     $eventTypesValues->addQuery('order', array('order' => implode($eventTypesValues->getPrimaryKeys(), ",") . ' DESC'));
     $eventTypesValuesCoellction = new Core_Model_Adapter_ModelCollection();
     $eventTypesValuesCoellction->getModelCollection($eventTypesValues);
     $this->offerTable->addColumn(array('key' => 'event_bets_id', 'label' => 'ID'));
     $this->offerTable->addColumn(array('key' => 'event_bets_name', 'label' => 'Name'));
     $this->offerTable->addColumn(array('key' => 'end_date', 'label' => 'Ends'));
     foreach ($eventTypesValuesCoellction->toArray() as $a) {
         $this->offerTable->addColumn(array('key' => $a['event_types_value_id'], 'allowHTML' => true, 'formatter' => '<span class="betOfferElement">{value}</span>', 'label' => $a['event_value_name']));
     }
     $betsModel = new Model_BetsModel();
     $groupsId = $this->getGroupId();
     if (!is_numeric($groupsId)) {
         return;
     }
     $eventBetsInTable = $betsModel->completeBetData($groupsId, $eventTypesId)->executeQuery('fetchAssoc');
     $data = array();
     if (!is_array($eventBetsInTable)) {
         return;
     }
     foreach ($eventBetsInTable as $d) {
         $data[$d['event_bets_id']][$d['event_types_value_id_FK']] = $d['odd_value'];
         $data[$d['event_bets_id']]['event_bets_name'] = $d['event_bets_name'];
         $data[$d['event_bets_id']]['end_date'] = $d['end_date'];
         $data[$d['event_bets_id']]['event_bets_id'] = $d['event_bets_id'];
         $data[$d['event_bets_id']][$d['event_types_value_id_FK'] . '_odd_value_id'] = $d['odd_value_id'];
         $data[$d['event_bets_id']]['bets_id'] = $d['bets_id'];
     }
     $preperedTableArray = array();
     foreach ($data as $value) {
         $preperedTableArray[] = $value;
     }
     $this->offerTable->setData($preperedTableArray);
     return $this->offerTable;
 }
Example #2
0
 public function setSelectElement()
 {
     $groupsId = $this->getGroupId();
     $betsModel = new Model_BetsModel();
     $betsModel->addQuery('select', array('table' => $betsModel->getTableName()));
     if (is_numeric($groupsId)) {
         $betsModel->addQuery('where', array('where_condition' => 'groups_id_FK=' . $groupsId));
     }
     $betsCollection = new Core_Model_Adapter_ModelCollection();
     $betsCollectionData = $betsCollection->getModelCollection($betsModel);
     $select = new Extension_View_Html_Form_Elements_Select();
     $select->setModel($betsCollection->toArray());
     $select->setAttribute('name', 'bets_id');
     $select->setAttribute('id', $select->getId());
     $select->setOptionLabelKey('bet_name');
     $select->setOptionValueKey('bets_id');
     $this->select = $select;
 }
Example #3
0
 public function completeEventBetDataArray($groupsId = null, $eventTypesId = null)
 {
     if ($groupsId === null) {
         if (isset($_GET['groups_id'])) {
             $groupsId = (int) $_GET['groups_id'];
         }
     }
     if ($eventTypesId === null) {
         if (isset($_GET['event_types_id'])) {
             $eventTypesId = (int) $_GET['event_types_id'];
         }
     }
     $betsModel = new Model_BetsModel();
     $eventBetsInTable = $betsModel->completeBetData($groupsId, $eventTypesId)->executeQuery('fetchAssoc');
     $data = array();
     if (!is_array($eventBetsInTable)) {
         return;
     }
     foreach ($eventBetsInTable as $d) {
         $data[$d['event_bets_id']][$d['event_types_value_id_FK']] = $d['odd_value'];
         $data[$d['event_bets_id']]['event_bets_name'] = $d['event_bets_name'];
         $data[$d['event_bets_id']]['end_date'] = $d['end_date'];
         $data[$d['event_bets_id']]['event_bets_id'] = $d['event_bets_id'];
         $data[$d['event_bets_id']][$d['event_types_value_id_FK'] . '_odd_value_id'] = $d['odd_value_id'];
         $data[$d['event_bets_id']]['bets_id'] = $d['bets_id'];
         $data[$d['event_bets_id']]['score'] = $d['score'];
         $data[$d['event_bets_id']]['correct_type'] = $d['correct_type'];
         $data[$d['event_bets_id']]['add_date'] = $d['add_date'];
         $data[$d['event_bets_id']]['event_bets_id'] = $d['event_bets_id'];
     }
     $preperedTableArray = array();
     foreach ($data as $value) {
         $preperedTableArray[] = $value;
     }
     return $preperedTableArray;
 }
Example #4
0
 public function setBetsTablePanel()
 {
     $table = $this->betsTableWithPanel->getTable();
     $this->betsTableWithPanel->isAddButtonEnabled(false);
     $model = new Model_BetsModel();
     $model->addQuery('select', array('table' => $model->getTableName()));
     $model->addQuery('order', array('order' => implode($model->getPrimaryKeys(), ",") . ' DESC'));
     $model->addQuery('limit', array('limit' => 20));
     $this->betsTableWithPanel->setModel($model);
     $table->addColumn(array('key' => 'bets_id', 'label' => 'ID'));
     $table->addColumn(array('key' => 'bet_name', 'label' => 'Name'));
     $groupsModel = new Model_GroupsModel();
     $groupsModel->addQuery('select', array('table' => $groupsModel->getTableName()));
     $groupsCollection = new Core_Model_Adapter_ModelCollection();
     $groupsCollectionData = $groupsCollection->getModelCollection($groupsModel);
     $table->addColumn('{key:"groups_id_FK",label:"Group",allowHTML:true,formatter:' . $table->getFormatter("selectFromModel", array('values' => $groupsCollectionData, 'value' => 'groups_id', 'label' => 'name_of_group', 'attributes' => array('name' => 'model[' . $this->betsTableWithPanel->getModelName() . '][groups_id_FK]'))) . '}', false, 'groups');
     $table->addColumn(array('key' => 'bet_active', 'label' => 'Active'));
     $table->addColumn(array('key' => 'end_date', 'label' => 'Ends'));
     $select = new Extension_View_Html_Form_Elements_Select();
     $select->setModel($groupsCollection->toArray());
     $select->setAttribute('name', 'groups_id_FK');
     $select->setOptionLabelKey('name_of_group');
     $select->setOptionValueKey('groups_id');
     $select->setPrependHtml('Group:');
     $this->betsTableWithPanel->addFilter($select);
     $this->betsTableWithPanel->addFilterGroupOperators('active', 'and');
     $this->betsTableWithPanel->addFilterGroupOperators('end', 'and');
     $filterCalendar = new Extension_View_Html_Form_Elements_Calendar();
     $filterCalendar->setPrependHtml('Active from:');
     $filterCalendar->setAttribute('name', 'bet_active');
     $this->betsTableWithPanel->addFilter($filterCalendar, array('group' => 'active', 'operator' => 'and', 'comparison' => '>'));
     $filterCalendar = new Extension_View_Html_Form_Elements_Calendar();
     $filterCalendar->setPrependHtml('Active to:');
     $filterCalendar->setAttribute('name', 'bet_active');
     $this->betsTableWithPanel->addFilter($filterCalendar, array('group' => 'active', 'operator' => 'and', 'comparison' => '<'));
     $filterCalendar = new Extension_View_Html_Form_Elements_Calendar();
     $filterCalendar->setPrependHtml('End from:');
     $filterCalendar->setAttribute('name', 'end_date');
     $this->betsTableWithPanel->addFilter($filterCalendar, array('group' => 'end', 'operator' => 'and', 'comparison' => '>'));
     $filterCalendar = new Extension_View_Html_Form_Elements_Calendar();
     $filterCalendar->setPrependHtml('End to:');
     $filterCalendar->setAttribute('name', 'end_date');
     $this->betsTableWithPanel->addFilter($filterCalendar, array('group' => 'end', 'operator' => 'and', 'comparison' => '<'));
 }
Example #5
0
 public function validate($excludeFromValidation = array())
 {
     $userBanned = $this->getUser()->getData('banned');
     $userId = $this->getUser()->getUserId();
     $transaction = new Model_TransactionModel();
     $transaction->setUserIdFK($userId);
     $transaction->getUserMoney();
     $money = $transaction->executeQuery('fetchAssocOne');
     if ($money['money'] < $this->getStake()) {
         $this->setValidationError('money', 'You dont have enough money');
         return;
     }
     if ($userBanned == 1) {
         $this->setValidationError('user', 'You are not currently allowed to bet');
     }
     $odds = $this->getOdds();
     if (!in_array('user_id_FK', $excludeFromValidation)) {
         if (!isset($userId)) {
             $this->setValidationError('user', 'Please login');
             //if user id does not exist breaks future validation
             return;
         }
     }
     if (!in_array('odds', $excludeFromValidation)) {
         if (!isset($odds) || empty($odds)) {
             $this->setValidationError('odds', 'Odds not set');
         }
     }
     if (!in_array('stake', $excludeFromValidation)) {
         if (!$this->getStake()) {
             $this->setValidationError('stake', 'Stake not set');
         }
     }
     $bets = new Model_BetsModel();
     $currentOddsData = $bets->getInfomationByOdds($this->getOdds())->executeQuery('fetchAssoc');
     $sortedByOdds = array();
     foreach ($currentOddsData as $c) {
         $sortedByOdds[$c['odd_value_id']] = $c;
     }
     $time = time();
     $betSlipErrors = array();
     $betsIdsList = array();
     $oddsDuplicate = array();
     foreach ($odds as $o) {
         //check on duplicates
         if (in_array($o, $oddsDuplicate)) {
             $this->setValidationError('odds', 'Multiple bets: ' . $sortedByOdds[$o]['event_bets_name']);
             return;
         } else {
             $oddsDuplicate[] = $o;
         }
         if ($sortedByOdds[$o]["active"] != 1) {
             $this->setValidationError('odds', 'Odds changed ' . $sortedByOdds[$o]['event_bets_name']);
             return;
         }
         if (strtotime($sortedByOdds[$o]["end_date"]) < $time) {
             $this->setValidationError('odds', 'Time ended on ' . $sortedByOdds[$o]['event_bets_name']);
             return;
         }
         if ($sortedByOdds[$o]["correct_type"] != null) {
             $this->setValidationError('odds', 'Bet Suspended: ' . $sortedByOdds[$o]['event_bets_name']);
             return;
         }
         $betsIdsList[] = $sortedByOdds[$o]["bets_id"];
     }
     $betsIdsListDuplicates = array();
     foreach ($betsIdsList as $b) {
         if (in_array($b, $betsIdsListDuplicates)) {
             $this->setValidationError('odds', 'Multiple bets: ' . $b);
             return;
         } else {
             $betsIdsListDuplicates[] = $b;
         }
     }
     parent::validate($excludeFromValidation);
 }