/**
  * 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]);
 }
Esempio n. 2
0
 /**
  * @return string match result for our teams of interest
  */
 public function checkMatchWinner()
 {
     $teamsConstants = Team::getTeamsConstants();
     if (isset($this->home_goals) && isset($this->guest_goals)) {
         if ($this->home_goals == $this->guest_goals) {
             return "yellow";
         } elseif (in_array($this->command_home_id, $teamsConstants)) {
             if ($this->home_goals > $this->guest_goals) {
                 return "green";
             }
             if ($this->home_goals < $this->guest_goals) {
                 return "red";
             }
         } elseif (in_array($this->command_guest_id, $teamsConstants)) {
             if ($this->home_goals < $this->guest_goals) {
                 return "green";
             }
             if ($this->home_goals > $this->guest_goals) {
                 return "red";
             }
         }
     }
 }
Esempio n. 3
0
use common\models\Season;
use common\models\Team;
use common\models\Coach;
/* @var $this yii\web\View */
/* @var $model common\models\TeamCoach */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="team-coach-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'team_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Team::find()->where(['id' => Team::getTeamsConstants()])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите команду...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'season_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Season::find()->where(['window' => Season::WINDOW_WINTER])->orderBy(['name' => SORT_DESC])->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите сезон...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'coach_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Coach::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите тренера...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
// $availableCoaches = [];
// $coach = $model->coach;
// if(isset($coach->id)) {
//     $availableCoaches = [$coach->id => $coach->name];