Exemple #1
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);
 }