/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Composition::find();
     $compositionTable = Composition::tableName();
     $teamTable = Team::tableName();
     $query->joinWith(['team' => function ($query) use($teamTable) {
         $query->from(['team' => $teamTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 30]]);
     // enable sorting for the related columns
     $addSortAttributes = ["team.name"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$compositionTable}.id" => $this->id, 'match_id' => $this->match_id, 'contract_id' => $this->contract_id, 'is_substitution' => $this->is_substitution, 'is_basis' => $this->is_basis, 'number' => $this->number, 'is_captain' => $this->is_captain, 'command_id' => $this->command_id]);
     $query->andFilterWhere(['like', 'contract_type', $this->contract_type])->andFilterWhere(['like', 'team.name', $this->getAttribute('team.name')]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompositions()
 {
     return $this->hasMany(Composition::className(), ['match_id' => 'id']);
 }
Beispiel #3
0
        <div class="col-sm-3">
            <?php 
echo $form->field($model, 'minute')->textInput();
?>
        </div>
        <div class="col-sm-3">
            <?php 
echo $form->field($model, 'additional_minute')->textInput();
?>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-6">
            <?php 
$compositionFilter = Composition::find()->where(['match_id' => $model->match_id])->all();
echo $form->field($model, 'composition_id')->widget(Select2::classname(), ['data' => ArrayHelper::map($compositionFilter, 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите игрока...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-sm-6">
            <?php 
echo $form->field($model, 'substitution_id')->widget(Select2::classname(), ['data' => ArrayHelper::map($compositionFilter, 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите игрока...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
    </div>

    <?php 
echo $form->field($model, 'notes')->textarea(['rows' => 6]);
?>

    <?php 
 /**
  * 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]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubstitution()
 {
     return $this->hasOne(Composition::className(), ['id' => 'substitution_id']);
 }
 /**
  * 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.');
     }
 }
 /**
  * Url: /match/protocol/{$id}
  * @param $id
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionMatchProtocol($id)
 {
     $match = Match::findOne($id);
     if (!isset($match)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $title = "Протокол матча " . $match->teamHome->name . " - " . $match->teamGuest->name;
     $matchEvents = MatchEvent::find()->where(['match_id' => $match->id])->all();
     $teamPlayers = Composition::find()->where(['match_id' => $match->id])->all();
     $teamPlayers = Composition::sortPlayers($teamPlayers);
     $teamHomePlayers = [];
     $teamGuestPlayers = [];
     foreach ($teamPlayers as $player) {
         if ($player->command_id == $match->command_home_id) {
             $teamHomePlayers[] = $player;
         } else {
             $teamGuestPlayers[] = $player;
         }
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['menu' => ['view' => '@frontend/views/translation/menu', 'data' => compact('match')], 'protocol' => ['view' => '@frontend/views/translation/protocol', 'data' => compact('match', 'matchEvents', 'teamHomePlayers', 'teamGuestPlayers')], 'comments' => Comment::getCommentsBlock($match->id, Comment::COMMENTABLE_MATCH)], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }