public static function getAutoReminderRecipients($tournament, $tour)
 {
     $candidates = self::find()->joinWith('idUser')->where(['id_tournament' => $tournament, 'notification' => self::NOTIFICATION_ENABLED, 'active' => Users::STATUS_ACTIVE])->all();
     $recipients = [];
     $tours = Games::getNumberOfGamesPerTour($tournament);
     foreach ($candidates as $one) {
         if (Forecasts::getUserForecastTour($one['id_user'], $tournament, $tours)[$tour] != '2' && Reminders::ifEligible($tournament, $tour, $one['id_user'])) {
             $recipients[] = Users::find()->where(['id' => $one['id_user']])->one();
         }
     }
     return $recipients;
 }
 public function actionReminder()
 {
     $tour = Yii::$app->request->post()['tour'];
     $tournament = Yii::$app->request->post()['tournament'];
     $sendReminders = Reminders::sendManualReminder($tour, $tournament);
     return $this->redirect(['tournaments/update', 'id' => $tournament]);
 }
Пример #3
0
 public function actionAutoreminder()
 {
     $tournaments = Tournaments::find()->where(['not', ['is_active' => Tournaments::FINISHED]])->all();
     foreach ($tournaments as &$tournament) {
         if ($tournament->is_active == Tournaments::NOT_STARTED && $tournament->startsOn - time() < 60 * 60 * 24 * 5) {
             $tournament->is_active = Tournaments::GOING;
             $tournament->save(false);
         }
         $nextTour = Tournaments::getNextTour($tournament->id_tournament);
         if ($nextTour != NULL) {
             $firstGameStarts = ArrayHelper::getValue(Result::find()->select(['min(dtime) as dtime'])->where(['id_tournament' => $tournament->id_tournament, 'tour' => $nextTour])->all()[0], 'dtime');
             if ($firstGameStarts > time() + 60 * 60 * 24 * 4 && $firstGameStarts < time() + 60 * 60 * 24 * 5 || $firstGameStarts > time() + 60 * 60 * 24 * 2 && $firstGameStarts < time() + 60 * 60 * 24 * 3) {
                 $sendReminders = Reminders::sendAutoReminder($nextTour, $tournament->id_tournament);
                 Yii::info("Task Autoreminder for {$tournament->tournament_name} {$nextTour} tour has been executed", 'console');
             }
         }
     }
     return 0;
 }