public function action()
 {
     $actionResult = NULL;
     track_stats();
     // Отслеживаем производительность
     $stadiumInstance = new Stadium();
     $stadiumInstance->initById($this->parameters->stadiumId);
     track_stats();
     // Отслеживаем производительность
     if ($stadiumInstance instanceof ErrorPoint) {
         return $stadiumInstance;
     }
     if ($this->parameters->isInGame && $stadiumInstance->getRequiredLevel() > $this->teamProfile->getLevel()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Для соверщения этой операции недостаточно уровня. У Вас " . $this->teamProfile->getLevel() . ", а необходим " . $structure->getRequiredLevel(), ErrorPoint::TYPE_USER);
     }
     if ($this->parameters->isInGame) {
         if ($stadiumInstance->getPrice() > $this->teamProfile->getMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     } else {
         if ($stadiumInstance->getRealPrice() > $this->teamProfile->getRealMoney()) {
             return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Недостаточно денежных средств", ErrorPoint::TYPE_USER);
         }
     }
     track_stats();
     // Отслеживаем производительность
     SQL::getInstance()->autocommit(false);
     track_stats();
     // Отслеживаем производительность
     if ($this->teamProfile->getStadiumId() == $stadiumInstance->getId()) {
         return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Вы уже приобрели выбранный стадион позже", ErrorPoint::TYPE_USER);
     }
     $this->teamProfile->setStadiumInstance($stadiumInstance);
     if ($this->parameters->isInGame) {
         $this->teamProfile->setMoney($this->teamProfile->getMoney() - $stadiumInstance->getPrice());
     } else {
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() - $stadiumInstance->getRealPrice());
     }
     $actionResult = $this->teamProfile->save();
     if ($actionResult instanceof ErrorPoint) {
         SQL::getInstance()->rollback();
     } else {
         SQL::getInstance()->commit();
     }
     track_stats();
     // Отслеживаем производительность
     return $actionResult;
 }
示例#2
0
 public function setStadiumInstance(Stadium $stadiumInstance)
 {
     $this->setStadiumId($stadiumInstance->getId());
     $this->stadiumInstance = $stadiumInstance;
 }
示例#3
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Stadium the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Stadium::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }