Example #1
0
 public function insert()
 {
     parent::insert();
     $id = $this->getConnection()->getInsertId();
     $betTypeData = array();
     foreach ($this->getOddsData() as $key => $o) {
         $betType = new Model_BetsTypeModel();
         $betTypeData['event_bets_id_FK'] = $id;
         $betTypeData['teams_has_bets_id_FK'] = NULL;
         $betTypeData['event_types_value_id_FK'] = $key;
         $betType->setData($betTypeData);
         if (!$betType->insert()) {
             $this->addValidationErrors($betType->getValidationErrors());
             return;
         }
         $idBetType = $this->getConnection()->getInsertId();
         $oddsData = array();
         $oddsData['odd_value'] = $o;
         $oddsData['bet_types_id_FK'] = $idBetType;
         $oddsData['active'] = 1;
         $odds = new Model_OddValueModel();
         $odds->setData($oddsData);
         if (!$odds->insert()) {
             $betType->delete();
             $this->addValidationErrors($odds->getValidationErrors());
         }
     }
 }