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); }
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(); }