コード例 #1
0
 /**
  * Creates a new Composition model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($matchId = null, $teamId = null)
 {
     $model = new Composition();
     if (!isset($matchId) || !isset($teamId)) {
         throw new \yii\web\BadRequestHttpException('Unidentified matchId and teamId');
     }
     $match = Match::findOne($matchId);
     $team = Team::findOne($teamId);
     if (!isset($match) || !isset($team)) {
         throw new \yii\web\BadRequestHttpException('Unidentified match and team models');
     }
     $model->command_id = $teamId;
     $model->match_id = $matchId;
     $model->is_basis = 1;
     $contractTeams = Team::getContractTeams();
     if (in_array($teamId, $contractTeams)) {
         $model->contract_type = Composition::CONTRACT_TYPE;
         $contractModel = new Contract();
         $contractModel->season_id = $match->season_id;
         $contractModel->is_active = 1;
     } else {
         $model->contract_type = Composition::MEMBERSHIP_TYPE;
         $contractModel = new Membership();
     }
     $contractModel->command_id = $teamId;
     if ($model->load(Yii::$app->request->post()) && $contractModel->load(Yii::$app->request->post()) && $contractModel->validate()) {
         if ($contractModel->save(false)) {
             $model->contract_id = $contractModel->id;
             $model->number = $contractModel->number;
             $model->save();
         }
         if (Yii::$app->request->isAjax) {
             $out = ['success' => 'true'];
             return Json::encode($out);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('create', ['model' => $model, 'contractModel' => $contractModel]);
         }
         return $this->render('create', ['model' => $model, 'contractModel' => $contractModel]);
     }
 }
コード例 #2
0
ファイル: Competition.php プロジェクト: kleitz/golfleague
 /**
  * find a document instance and returns it property typed.
  *
  * @return app\models\{Document,Bid,Order,Bill} the document
  */
 public static function findCompetition($id)
 {
     $model = Competition::findOne($id);
     if ($model) {
         switch ($model->competition_type) {
             case self::TYPE_MATCH:
                 return Match::findOne($id);
                 break;
             case self::TYPE_TOURNAMENT:
                 return Tournament::findOne($id);
                 break;
             case self::TYPE_SEASON:
                 return Season::findOne($id);
                 break;
         }
     }
     return null;
 }
コード例 #3
0
 /**
  * Vote for selected float answer
  * @param $matchID int
  * @return mixed Json
  */
 public function actionAutogen($matchID)
 {
     $match = \common\models\Match::findOne($matchID);
     if (!isset($match)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     if (in_array($match->teamHome->id, \common\models\Team::getTeamsConstants())) {
         $ourTeam = $match->teamHome;
         $opponentTeam = $match->teamGuest;
     } else {
         $ourTeam = $match->teamGuest;
         $opponentTeam = $match->teamHome;
     }
     $basisPlayers = \common\models\Composition::find()->where(['match_id' => $match->id, 'command_id' => $ourTeam->id, 'is_basis' => 1])->all();
     $compositionTable = \common\models\Composition::tableName();
     $matchEventTable = \common\models\MatchEvent::tableName();
     $substitutionPlayers = \common\models\Composition::find()->innerJoin($matchEventTable, "{$matchEventTable}.substitution_id = {$compositionTable}.id")->where([$compositionTable . '.match_id' => $match->id, 'command_id' => $ourTeam->id])->all();
     $teamPlayers = array_merge($basisPlayers, $substitutionPlayers);
     $question = new Question();
     $question->title = 'Оценки игрокам ' . $ourTeam->name . ' в матче с ' . $opponentTeam->name;
     $question->voutes = 0;
     $question->is_active = 1;
     $question->is_float = 1;
     $question->is_multipart = 0;
     $question->mark = 0;
     if ($question->save()) {
         foreach ($teamPlayers as $teamPlayer) {
             $answer = new Question();
             $answer->parent_id = $question->id;
             $answer->title = $teamPlayer->name;
             $answer->mark = 0;
             $answer->save();
         }
     }
     return $this->redirect(['view', 'id' => $question->id]);
 }
コード例 #4
0
 /**
  * @param integer $matchID
  * @return Json Name of match
  */
 public function actionMatchName($matchID)
 {
     $model = Match::findOne($matchID);
     if (!isset($model->id)) {
         return Json::encode(['data' => 'Матч не найден']);
     }
     $date = date('d.m.Y', strtotime($model->date));
     return Json::encode(['data' => $model->name . ' (' . $date . ')']);
 }
コード例 #5
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);
 }
コード例 #6
0
 /**
  * Url: /match/{$id}/videos
  * @param $id Match id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionMatchVideos($id)
 {
     $match = Match::findOne($id);
     if (!isset($match)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $title = "Видео матча " . $match->name;
     $videoPostTable = VideoPost::tableName();
     $relationTable = Relation::tableName();
     $query = VideoPost::find()->innerJoin($relationTable, "{$videoPostTable}.id = {$relationTable}.relationable_id")->where(['is_public' => 1, "{$relationTable}.relationable_type" => Relation::RELATIONABLE_VIDEO, "{$relationTable}.parent_id" => $match->id])->orderBy(['created_at' => SORT_DESC]);
     $videosDataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $emptyText = 'Видеозаписей к матчу не найдено';
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['menu' => ['view' => '@frontend/views/translation/menu', 'data' => compact('match')], 'content' => ['view' => '@frontend/views/site/videos', 'data' => compact('videosDataProvider', 'emptyText')]], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }