public function update($forceUpdateFlag = false) { $checkIfModelIsUpdatebale = new Model_EventBetsModel(); $checkIfModelIsUpdatebale->load($this->getEventBetsId()); if ($checkIfModelIsUpdatebale->getCorrectType() != null) { return $this->setValidationError('update', 'Correct Type is set, Event can be updated anymore'); } parent::update($forceUpdateFlag); $this->load($this->getEventBetsId()); if ($this->getCorrectType() != null) { $betTypesModel = new Model_BetsTypeModel(); $betTypesModel->load(array('event_bets_id_FK' => $this->getEventBetsId(), 'event_types_value_id_FK' => $this->getCorrectType())); $betTypesModel->addQuery('select', array('table' => $betTypesModel->getTableName())); $betTypesModel->addQuery('where', array('where_condition' => 'event_bets_id_FK=' . $this->getEventBetsId())); $betTypesModelCollection = new Core_Model_Adapter_ModelCollection(); $betTypesModelCollection->getModelCollection($betTypesModel); $betTypesKeys = $betTypesModelCollection->getKeysArray('bet_types_id'); $odds = new Model_OddValueModel(); $odds->addQuery('update', array('table' => $odds->getTableName(), 'columns' => 'is_correct=0')); $odds->addQuery('where', array('where_condition' => 'bet_types_id_FK in (' . implode(',', $betTypesKeys) . ')')); $odds->executeQuery(); $odds->load(array('bet_types_id_FK' => $betTypesModel->getBetTypesId())); $odds->setIsCorrect(1); $odds->update(); $odds->addQuery('select', array('table' => $odds->getTableName())); $odds->addQuery('where', array('where_condition' => 'bet_types_id_FK in (' . implode(',', $betTypesKeys) . ')')); $oddsValuesCollection = new Core_Model_Adapter_ModelCollection(); $oddsValuesCollection->getModelCollection($odds); $oddValuesKeys = $oddsValuesCollection->getKeysArray('odd_value_id'); $betSlip = new Model_BetSlipModel(); $betSlip->addQuery('update', array('table' => $betSlip->getTableName(), 'columns' => 'finished = finished+1')); $betSlip->addQuery('where', array('where_condition' => 'bet_slip_id in (select bet_slip_id_FK from bet_slip_odds where odd_value_id_FK in (' . implode(',', $oddValuesKeys) . '))')); $betSlip->executeQuery(); $betSlip->setStatusOne(); $betSlip->proccessBetSlips(); $betSlip->setStatusTwo(); } }