public function getStake() { $userId = $this->getUserId(); if (!isset($userId)) { return; } $betSlipId = $this->getBetSlipId(); $transaction = new Model_TransactionModel(); $transaction->load(array('user_id_FK' => $userId, 'transaction_type_id_FK' => 3, 'transaction_type_idendifier' => $betSlipId)); return $transaction->getMoney(); }
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); }
private function setUserBankTable() { $user = new Core_Auth_User(); $role = $user->getRole(); $userId = $this->getUserId(); if ($role == 'admin' || $role == 'superadmin') { $bank = new Extension_View_Yui35_DataTableEdit(); $bank->isAddButtonEnabled(false); $bank->isEditEnabled(false); } else { $bank = new Extension_View_Yui35_DataTablePF(); if ($userId === null) { return; } } $table = $bank->getTable(); $model = new Model_TransactionModel(); $model->setUserId($userId); if ($userId == null) { $model->addQuery('select', array('table' => $model->getTableName())); } else { $model->getTransactionsByUser(); } $model->addQuery('order', array('order' => implode($model->getPrimaryKeys(), ",") . ' DESC')); $model->addQuery('limit', array('limit' => 20)); $bank->setModel($model); $table->addColumn(array('key' => 'transaction_id', 'label' => 'ID')); $table->addColumn(array('key' => 'money', 'label' => 'Money')); $table->addColumn(array('key' => 'date_created', 'label' => 'Date')); $typeModel = new Model_TransactionTypeModel(); $typeModel->addQuery('select', array('table' => $typeModel->getTableName())); $typeCollection = new Core_Model_Adapter_ModelCollection(); $typeCollectionData = $typeCollection->getModelCollection($typeModel); $table->addColumn('{key:"transaction_type_id_FK",label:"Type Of Transaction",allowHTML:true,formatter:' . $table->getFormatter("labelFromModelCollection", array('values' => $typeCollectionData, 'value' => 'transaction_type_id', 'label' => 'transaction_name', 'attributes' => array('name' => 'model[' . $model->getModelClassName() . '][transaction_type_id_FK]'))) . '}', false, 'transaction_type_id_FK'); $url = Application::getRouter()->getFullUrl(array('controller' => 'servicehtml', 'action' => 'view')); $table->addColumn(array('key' => 'transaction_id', 'label' => 'ID')); $table->addColumn(array('key' => 'money', 'label' => 'Money')); $table->addColumn(array('key' => 'date_created', 'label' => 'Date')); $table->addColumn('{key:"transaction_type_id_FK",label: "Details",allowHTML:true,formatter:function (o){ if(o.value==2||o.value==3){return "<a class=\'systemSubServiceLinkBank\' servicehtml=\'' . $url . '&view=View_Frontend_UserBetSlip&bet_slip_id="+o.data.transaction_type_idendifier+"\' href=\'javascript:void(0)\' >View</a>";}else{return "-"}}}', false, 'bet_slip_id_view'); $status = new Extension_View_Html_Form_Elements_Select(); $status->setModel($typeCollection->toArray()); $status->setOptionLabelKey('transaction_name'); $status->setOptionValueKey('transaction_type_id'); $status->setAttributes(array('name' => 'transaction_type_id_FK', 'type' => 'text')); $status->setPrependHtml('Status: '); $bank->addFilter($status); $filterCalendar = new Extension_View_Html_Form_Elements_Calendar(); $filterCalendar->setPrependHtml('<br />Date from:'); $filterCalendar->setAttribute('name', 'date_created'); $bank->addFilter($filterCalendar, array('group' => 'added', 'operator' => 'and', 'comparison' => '>')); $filterCalendar = new Extension_View_Html_Form_Elements_Calendar(); $filterCalendar->setPrependHtml('Date to:'); $filterCalendar->setAttribute('name', 'date_created'); $bank->addFilter($filterCalendar, array('group' => 'added', 'operator' => 'and', 'comparison' => '<')); $filterMoney = new Extension_View_Html_Form_Elements_Input(); $filterMoney->setPrependHtml('<br />Money from:'); $filterMoney->setAttribute('name', 'money'); $bank->addFilter($filterMoney, array('group' => 'money', 'operator' => 'and', 'comparison' => '>')); $filterMoney = new Extension_View_Html_Form_Elements_Input(); $filterMoney->setPrependHtml('Money to:'); $filterMoney->setAppendHtml('</br>'); $filterMoney->setAttribute('name', 'money'); $bank->addFilter($filterMoney, array('group' => 'money', 'operator' => 'and', 'comparison' => '<')); if ($role == 'admin' || $role == 'superadmin') { $userIdFiterId = new Extension_View_Html_Form_Elements_Input(); $userIdFiterId->setAttributes(array('type' => 'hidden', 'name' => 'user_id_FK', 'value' => $userId, 'class' => 'filterInput')); $bank->addFilter($userIdFiterId); } else { $method = new Extension_View_Html_Form_Elements_Input(); $method->setAttributes(array('type' => 'hidden', 'name' => 'method', 'value' => 'getTransactionsByUser', 'class' => 'filterInput')); $bank->addAdditionalFilterElement($method); } $this->userBankTable = $bank; }
public function registration() { $bookhouse = new Model_BookhouseModel(); $bookhouse->loadActiveBookhouse(); if ($bookhouse->getCanUserRegister() == 0) { $this->setValidationError('Bookhouse', 'Registration is disabled'); } $userCheckModel = new Model_UserModel(); $userCheckModel->load(array('user_name' => $this->getUserName())); $userId = $userCheckModel->getUserId(); if (isset($userId)) { $this->setValidationError('username', 'Username already exist'); return; } $userCheckModel->load(array('email' => $this->getEmail())); $userId = $userCheckModel->getUserId(); if (isset($userId)) { $this->setValidationError('username', 'Email already exist'); return; } $this->setLastLogin(date('Y-m-d H:i:s')); $this->setUserStatusIdFK(3); $this->setBanned(0); $this->setEmailValidated(0); $this->insert(); $userIdFK = $this->getConnection()->getInsertId(); $transaction = new Model_TransactionModel(); $transaction->setUserIdFK($userIdFK); $transaction->setTransactionTypeIdFK(1); $transaction->setMoney($bookhouse->getDefaultMoneyValue()); $transaction->setTransactionTypeIdendifier(null); $transaction->insert(); }