コード例 #1
0
ファイル: PlaceBetModel.php プロジェクト: berksonj/bet
 /**
  * @todo put this on sql transaction
  */
 public function insert()
 {
     $dateCreated = date('Y-m-d H:i:s', time());
     $this->setDateCreated($dateCreated);
     $this->setPlayed(sizeof($this->getOdds()));
     $this->setUserIdFK($this->getUser()->getUserId());
     $this->setFinished(0);
     $this->setStatus(0);
     if (!parent::insert()) {
         return false;
     }
     $betSlipId = $this->getConnection()->getInsertId();
     $transaction = new Model_TransactionModel();
     $transaction->setMoney($this->getStake() * -1);
     $transaction->setTransactionTypeIdFK(3);
     $transaction->setUserIdFK($this->getUser()->getUserId());
     $transaction->setTransactionTypeIdendifier($betSlipId);
     $transaction->setDateCreated($dateCreated);
     if (!$transaction->insert($dateCreated)) {
         $this->setValidationError('sql', 'Server Error');
         $this->delete();
     }
     /**
      * @todo put this in one query
      */
     foreach ($this->getOdds() as $o) {
         $odds = new Model_BetSlipOddsModel();
         $odds->setOddValueIdFK($o);
         $odds->setBetSlipIdFK($betSlipId);
         $odds->insert();
     }
 }