Example #1
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($insert) {
         if (in_array($this->match_event_type_id, self::getGoalTypes())) {
             $match = Match::findOne($this->match_id);
             $contract = Composition::findOne($this->composition_id);
             if (isset($match) && isset($contract)) {
                 if ($contract->command_id == $match->command_home_id) {
                     if ($this->match_event_type_id == self::AUTOGOAL) {
                         $match->guest_goals++;
                         $match->guest_shots++;
                         $match->guest_shots_in++;
                     } else {
                         $match->home_goals++;
                         $match->home_shots++;
                         $match->home_shots_in++;
                     }
                 } elseif ($contract->command_id == $match->command_guest_id) {
                     if ($this->match_event_type_id == self::AUTOGOAL) {
                         $match->home_goals++;
                         $match->home_shots++;
                         $match->home_shots_in++;
                     } else {
                         $match->guest_goals++;
                         $match->guest_shots++;
                         $match->guest_shots_in++;
                     }
                 }
                 $match->save();
             }
         }
     }
     return parent::beforeSave($insert);
 }
 /**
  * Finds the Composition model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Composition the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Composition::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }