Exemplo n.º 1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset($changedAttributes['is_active']) && $changedAttributes['is_active'] != self::FINISHED && $this->is_active == self::FINISHED) {
         News::updateAll(['archive' => News::ARCHIVE_TRUE], ['id_tournament' => $this->id_tournament]);
         //assigning Events for winners forecast
         Top3TeamsForecast::setEventForTournament($this->id_tournament);
         //adding additional points to the total points field of UserTournaments model
         $this->assignAdditionalPoints();
     }
     //if setting tournament back to active from finished, need to remove calculated additional points and clean additional forecast events
     if (isset($changedAttributes['is_active']) && $changedAttributes['is_active'] == self::FINISHED && $this->is_active == self::GOING) {
         //removing additional points to the total points field of UserTournaments model
         $this->removeAdditionalPoints();
         //assigning Events for winners forecast to NULL
         Top3TeamsForecast::clearEventForTournament($this->id_tournament);
     }
     if ($insert) {
         $news = new News();
         $news->scenario = 'send';
         $news->id_tournament = 0;
         $news->subject = 'Добавлен новый турнир';
         $news->body = "<p>Для прогноза доступен новый турнир {$this->tournament_name}, первый тур которого состоится " . date('d.m.y', $this->startsOn) . " </p>" . "<p>Вы также можете попробовать угадать призеров турнира и заработать дополнительные очки! Прогноз на призеров принимается до " . date('d.m.y', $this->wfDueTo) . " </p>" . "<p>Спешите принять участие! Зайдите в <strong>Профиль->Мои турниры</strong> чтобы начать делать прогнозы</p>";
         $news->save();
     }
 }
Exemplo n.º 2
0
 protected function findModel($id)
 {
     if (($model = News::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = News::find()->with(['author0', 'tournament']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date' => $this->date, 'author' => $this->author, 'id_tournament' => $this->id_tournament, 'archive' => $this->archive]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 public function store(Request $request)
 {
     $rules = array('image' => 'required|image|mimes:jpeg,jpg,png,bmp,gif,svg', 'title' => 'required', 'content' => 'required', 'category' => 'required_without:newCategory', 'newCategory' => 'required_without:category');
     $validator = \Validator::make(\Input::all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withInput()->withErrors($validator);
     }
     if ($request->has('newCategory') && !Category::where('title', '=', $request->input('title'))->first()) {
         $category = new Category(["title" => $request->input('newCategory')]);
         $category->save();
     } else {
         if (Category::find($request->input('category'))) {
             $category = Category::find($request->input('category'));
         } else {
             return redirect()->back()->withInput()->withErrors([trans('news.category')]);
         }
     }
     $newFilename = $this->saveNewsImage($request->file('image'));
     $news = new \App\Models\News\News(["title" => $request->input('title'), "content" => $request->input('content'), "author_id" => \Auth::user()->id, "image" => $newFilename]);
     $news->save();
     $news->categories()->save($category);
     return redirect('/news/' . $news->id . '-' . sluggify($news->title));
 }
Exemplo n.º 5
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);
         }
     }
 }
Exemplo n.º 6
0
 public function destroy(Request $request, $id)
 {
     News::find($id)->categories()->detach();
     News::destroy($id);
     return \Redirect::back();
 }
Exemplo n.º 7
0
 public function home()
 {
     return view('home', ['news' => News::orderBy('created_at', 'DESC')->limit(4)->get()]);
 }
Exemplo n.º 8
0
 public function run()
 {
     $title = $this->title;
     $news = \app\models\news\News::getTopActiveNews();
     return $this->render('news', compact('news', 'title'));
 }