Пример #1
0
 public static function sendAutoReminder($tour, $tournament)
 {
     $users = UsersTournaments::getAutoReminderRecipients($tournament, $tour);
     if (!empty($users)) {
         return self::sendReminder($tour, $tournament, $users);
     } else {
         throw new ErrorException('Error sending reminders');
     }
 }
 public function up()
 {
     $this->addColumn('{{%users_tournaments}}', 'points', $this->integer()->defaultValue(NULL));
     $tournaments = UsersTournaments::find()->all();
     foreach ($tournaments as $one) {
         $games = ArrayHelper::getColumn(Result::find()->select('id_game')->where(['id_tournament' => $one->id_tournament])->all(), 'id_game');
         $points = Forecasts::find()->select(['sum(points) as points'])->joinWith('idUser')->where(['in', 'id_game', $games])->andWhere(['id_user' => $one->id_user])->scalar();
         $one->points = $points;
         $one->save(false);
     }
 }
Пример #3
0
 public static function sendTourResults($tour, $tournament)
 {
     $trn = Tournaments::findOne($tournament);
     $recipientsUT = UsersTournaments::find()->joinWith('idUser')->where(['and', ['id_tournament' => $tournament], ['notification' => UsersTournaments::NOTIFICATION_ENABLED], ['sf_users.active' => Users::STATUS_ACTIVE]])->all();
     $recipients = ArrayHelper::getColumn($recipientsUT, 'idUser');
     //if not last tour - just send notifications
     if ($tour != $trn->num_tours) {
         $subject = "Результаты {$tour} тура - " . $trn->tournament_name;
         $thisTourForecastStanding = new ArrayDataProvider(['allModels' => Forecasts::getTopFiveForecastersWithPoints($tournament, $tour)]);
         //creating news for the tour
         $news = new News();
         $news->subject = "Результаты {$tour} тура";
         $news->id_tournament = $tournament;
         $news->body = self::generateTourNews($tournament, $tour);
         $news->save();
         foreach ($recipients as $one) {
             $content = new ArrayDataProvider(['allModels' => Forecasts::getForecastResultUserTourTournament($one->id, $tour, $tournament)]);
             $leaderAndUser = new ArrayDataProvider(['allModels' => Forecasts::getLeaderAndUserPosition($one->id, $tournament)]);
             $messages[] = Yii::$app->mailer->compose('forecastResult', ['content' => $content, 'standings' => $leaderAndUser, 'user' => $one, 'tournament' => $trn->tournament_name, 'tour' => $tour, 'tourForecasts' => $thisTourForecastStanding])->setFrom([Yii::$app->params['adminEmail'] => 'Sportforecast'])->setTo($one->email)->setSubject($subject);
         }
         if (!empty($messages)) {
             Yii::$app->mailer->sendMultiple($messages);
         }
     } else {
         //todo add additional points info and tournament standings into the personal email
         $news = new News();
         $news->subject = 'Закончен турнир ' . $trn->tournament_name;
         $news->body = Tournaments::generateFinalNews($tournament);
         $news->id_tournament = $tournament;
         $news->save();
         //sending personal emails
         $standings = new ActiveDataProvider(['query' => UsersTournaments::find()->forecastersStandings($tournament), 'pagination' => false]);
         $subject = "Закончен турнир {$trn->tournament_name}";
         foreach ($recipientsUT as $one) {
             $position = $one->position;
             $points = $one->totalPoints;
             if ($position == 1) {
                 $message = "Поздравляем!!! Набрав {$points} очков, Вы стали победителем турнира!";
             } else {
                 $message = "Вы заняли {$position} место, набрав {$points} очков";
             }
             $messages[] = Yii::$app->mailer->compose('tournamentResult', ['standings' => $standings, 'user' => $one, 'message' => $message, 'tournament' => $trn])->setFrom([Yii::$app->params['adminEmail'] => 'Sportforecast'])->setTo($one->idUser->email)->setSubject($subject);
         }
         if (!empty($messages)) {
             Yii::$app->mailer->sendMultiple($messages);
         }
     }
 }
Пример #4
0
 public static function getLeaderAndUserPosition($user, $tournament)
 {
     $forecasters = self::getForecastersWithPoints($tournament);
     if (empty($forecasters)) {
         $result[0]['leader'] = '-';
         $result[0]['leaderPoints'] = '-';
         $result[0]['userPoints'] = '-';
         $result[0]['userPosition'] = '-';
     } else {
         $result[0]['leader'] = $forecasters[0]['idUser']['username'];
         $result[0]['leaderPoints'] = $forecasters[0]['points'];
         foreach ($forecasters as $k => $one) {
             if ($one['id_user'] == $user) {
                 $result[0]['userPoints'] = $one['points'];
                 $result[0]['userPosition'] = $k + 1;
                 break;
             } else {
                 $result[0]['userPoints'] = '-';
                 $result[0]['userPosition'] = '-';
             }
         }
     }
     $result[0]['user'] = $user;
     $result[0]['count'] = UsersTournaments::find()->where(['id_tournament' => $tournament])->count();
     return $result;
 }
 public function actionUser($user, $tournament)
 {
     $userModel = Users::findOne($user);
     $forecastStatus = Forecasts::getUserForecastStatus($tournament, $user);
     $forecast = new ArrayDataProvider(['allModels' => $forecastStatus, 'pagination' => false]);
     $winnersForecast = Top3TeamsForecast::find()->where(['id_tournament' => $tournament])->andWhere(['id_user' => $user])->with('team.idTeam')->orderBy(['forecasted_position' => SORT_ASC])->asArray()->all();
     $isFinished = Tournaments::findOne($tournament)->is_active == Tournaments::FINISHED;
     $winnersForecastDataProvider = new ArrayDataProvider(['allModels' => $winnersForecast, 'pagination' => false]);
     $data = ['forecast' => $forecast, 'user' => $userModel, 'winnersForecast' => $winnersForecastDataProvider, 'isFinished' => $isFinished];
     if ($isFinished) {
         $userTournamentModel = UsersTournaments::find()->where(['id_user' => $user])->andWhere(['id_tournament' => $tournament])->with('winnersForecast')->one();
         $data['winnersForecastDetails'] = implode('</br>', Top3TeamsForecast::getClarifications($user, $tournament));
         $data['totalAdditionalPoints'] = $userTournamentModel->calculateAdditionalPoints();
     }
     return $this->renderAjax('user', $data);
 }
Пример #6
0
 public static function generateFinalNews($tournament)
 {
     $trn = self::findOne($tournament);
     $forecasters = new ArrayDataProvider(['allModels' => UsersTournaments::topThreeForecastersForTournament($tournament)]);
     $standings = new ArrayDataProvider(['allModels' => Result::getStandings($tournament)]);
     return Yii::$app->controller->renderPartial('@app/mail/_tournamentFinishedNews', ['trn' => $trn, 'forecasters' => $forecasters, 'standings' => $standings]);
 }
 public function actionDelete($id)
 {
     $model = UsersTournaments::findOne(['id_tournament' => $id, 'id_user' => Yii::$app->user->id]);
     //deleting forecasts
     if ($model) {
         $model->deleteForecasts();
         $model->delete();
         Yii::$app->session->setFlash('success', 'Участие отменено, все прогнозы удалены');
     }
     return $this->goBack();
 }
Пример #8
0
                </div>
            </div>
        <?php 
ActiveForm::end();
?>
        <hr>
        <h2>Ваши законченные турниры</h2>
        <h4>Кликните на название турнира, чтобы посмотреть результаты</h4>
        <div class="row">
            <?php 
echo extendedGridView::widget(['dataProvider' => $userFinishedTournaments, 'bordered' => false, 'summary' => false, 'options' => ['class' => 'col-xs-12 col-lg-9'], 'resizableColumns' => false, 'columns' => [['header' => 'Название турнира', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-3 col-lg-5'], 'content' => function ($model) {
    return Html::a($model->tournament_name, ['tournaments/details', 'id' => $model->id_tournament]);
}, 'format' => 'url'], ['header' => 'Страна', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'attribute' => 'country0.country', 'options' => ['class' => 'col-xs-2 col-lg-1']], ['header' => 'Место', 'contentOptions' => ['style' => 'vertical-align:middle', 'align' => 'center'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {
    return \app\models\users\UsersTournaments::find()->findModel($model->id_tournament, Yii::$app->user->id)->one()->position;
}], ['header' => 'Очки', 'contentOptions' => ['style' => 'vertical-align:middle', 'align' => 'center'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {
    return \app\models\users\UsersTournaments::find()->findModel($model->id_tournament, Yii::$app->user->id)->one()->totalPoints;
}], ['header' => 'Победитель', 'contentOptions' => ['style' => 'vertical-align:middle', 'align' => 'center'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-2'], 'content' => function ($model) {
    return isset($model->usersTournaments[0]->idUser->username) ? $model->usersTournaments[0]->idUser->username : '******';
}], ['header' => 'Очки победителя', 'contentOptions' => ['style' => 'vertical-align:middle', 'align' => 'center'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {
    return isset($model->usersTournaments[0]->points) ? $model->usersTournaments[0]->points : '-';
}]]]);
?>
        </div>

        <hr>
        <h2>Турниры без вашего участия</h2>
        <h4>Кликните на название турнира, чтобы посмотреть результаты</h4>
        <div class="row">
            <?php 
echo extendedGridView::widget(['dataProvider' => $notUserTournaments, 'bordered' => false, 'summary' => false, 'options' => ['class' => 'col-xs-12 col-sm-10 col-lg-8'], 'resizableColumns' => false, 'columns' => [['header' => 'Название турнира', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-3'], 'content' => function ($model) {
    return Html::a($model->tournament_name, ['tournaments/details', 'id' => $model->id_tournament]);
Пример #9
0
        </div>

        <div class="form-group">
            <?php 
echo Html::submitButton('Сохранить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        </div>

        <?php 
ActiveForm::end();
?>

    </div>
</div>
<hr>
<h2>Статистика участия</h2>
<div class="row">

    <?php 
echo GridView::widget(['dataProvider' => $tournaments, 'options' => ['class' => 'col-xs-12 col-md-10'], 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['class' => 'col-xs-1'], 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center']], ['attribute' => 'tournament_name', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'filter' => false, 'options' => ['class' => 'col-xs-3']], ['attribute' => 'country0.country', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'filter' => false, 'options' => ['class' => 'col-xs-2']], ['attribute' => 'status', 'header' => 'Статус', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'filter' => false, 'options' => ['class' => 'col-xs-2']], ['header' => 'Место', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'content' => function ($model1) use($model) {
    return \app\models\users\UsersTournaments::find()->findModel($model1->id_tournament, $model->id)->one()->position;
}, 'filter' => false, 'options' => ['class' => 'col-xs-1']], ['attribute' => 'userPoints', 'header' => 'Очки', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'content' => function ($model1) use($model) {
    return \app\models\users\UsersTournaments::find()->findModel($model1->id_tournament, $model->id)->one()->totalPoints;
}, 'filter' => false, 'options' => ['class' => 'col-xs-1']], ['attribute' => 'notification', 'header' => 'Уведомления', 'contentOptions' => ['align' => 'center', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'content' => function ($model1) use($model) {
    return \app\models\users\UsersTournaments::find()->findModel($model1->id_tournament, $model->id)->one()->getSubscriptionStatus();
}, 'filter' => false, 'options' => ['class' => 'col-xs-1']]]]);
?>

</div>
Пример #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsersTournaments()
 {
     return $this->hasMany(UsersTournaments::className(), ['id_user' => 'id']);
 }
Пример #11
0
 private function removeAdditionalPoints()
 {
     $userTournamentsModels = UsersTournaments::find()->with('winnersForecast')->where(['id_tournament' => $this->id_tournament])->all();
     foreach ($userTournamentsModels as $one) {
         $one->points -= $one->calculateAdditionalPoints();
         $one->save(false);
     }
 }
Пример #12
0
echo frontPageGames::widget(['type' => 'recent']);
?>
        </div>

        <div class = "col-xs-8 col-xs-offset-0 col-md-3" id = 'right'>

            <div class = "text-center">
                <div class ="row">
                    <?php 
echo extendedGridView::widget(['dataProvider' => $userTournaments, 'emptyText' => 'Нет текущих турниров', 'condensed' => true, 'caption' => 'Ваши текущие турниры', 'captionOptions' => ['bordered' => false, 'class' => 'text-center', 'style' => 'font-size: 1.5em;'], 'bordered' => false, 'summary' => '', 'columns' => [['header' => 'Турнир', 'contentOptions' => ['class' => 'text-left', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-7'], 'content' => function ($model) {
    return Html::a($model->tournament_name, ['tournaments/details', 'id' => $model->id_tournament]);
}, 'format' => 'url'], ['header' => 'Ваши очки', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-4'], 'content' => function ($model) {
    $points = UsersTournaments::find()->findModel($model->id_tournament, Yii::$app->user->id)->one()->totalPoints;
    return $points === NULL ? '-' : $points;
}], ['header' => 'Место', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {
    return UsersTournaments::find()->findModel($model->id_tournament, Yii::$app->user->id)->one()->position;
}]]]);
?>
                </div>
            </div>

            <div class = "text-center">
                <div class ="row">
                    <?php 
echo extendedGridView::widget(['dataProvider' => $tournaments, 'showOnEmpty' => false, 'emptyText' => '', 'caption' => 'Остальные текущие турниры', 'captionOptions' => ['bordered' => false, 'class' => 'text-center', 'style' => 'font-size: 1.5em;'], 'condensed' => true, 'bordered' => false, 'summary' => '', 'columns' => [['header' => 'Турнир', 'contentOptions' => ['class' => 'text-left', 'style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-6'], 'content' => function ($model) {
    return Html::a($model->tournament_name, ['tournaments/details', 'id' => $model->id_tournament]);
}, 'format' => 'url'], ['header' => 'Лидер прогноза', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-4'], 'content' => function ($model) {
    return isset($model->usersTournaments[0]->idUser->username) ? $model->usersTournaments[0]->idUser->username : '******';
}], ['header' => 'Очки лидера', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {
    return isset($model->usersTournaments[0]->points) ? $model->usersTournaments[0]->points : '-';
}], ['header' => 'Участвовать', 'contentOptions' => ['style' => 'vertical-align:middle'], 'headerOptions' => ['style' => 'text-align:center'], 'options' => ['class' => 'col-xs-1'], 'content' => function ($model) {