/**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Validator::extend('quiz_already_created', function ($attribute, $value, $parameters, $validator) {
         $date = explode('/', $value);
         $questions = Question::where('year', $date[2])->where('month', $date[1])->where('day', $date[0])->get()->count();
         if ($questions) {
             return false;
         } else {
             return true;
         }
     });
     Validator::extend('league_already_created', function ($attribute, $value, $parameters, $validator) {
         $date = explode('/', $value);
         $league = League::where('year', $date[1])->where('month', $date[0])->where('leaguename_id', $validator->getData()['league'])->get()->count();
         if ($league) {
             return false;
         } else {
             return true;
         }
     });
     Validator::extend('specialquiz_already_created', function ($attribute, $value, $parameters, $validator) {
         $date = explode('/', $value);
         $quiz = Specialquiz::where('year', $date[2])->where('month', $date[1])->where('day', $date[0])->get()->count();
         if ($quiz) {
             return false;
         } else {
             return true;
         }
     });
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $specialquiz = Specialquiz::where('year', $year)->where('month', $month)->where('day', $day)->first();
     $globalSpecialQuiz = null;
     if (count($specialquiz)) {
         $globalSpecialQuiz = $specialquiz;
     }
     view()->share('global_specialquiz', $globalSpecialQuiz);
     $quiz = Question::where('year', $year)->where('month', $month)->where('day', $day)->first();
     if (count($quiz)) {
         view()->share('global_leaguequiz', true);
     } else {
         view()->share('global_leaguequiz', false);
     }
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $question = Question::where('year', $year)->where('month', $month)->where('day', $day)->first();
     if (count($question)) {
         $leagues = League::where('year', $question->leagueYear())->where('month', $question->leagueMonth())->get();
         foreach ($leagues as $key => $league) {
             $players = json_decode($league->users);
             foreach ($players as $key => $player) {
                 $user = User::find($player);
                 if ($user->daily_reminder && $user->active) {
                     Mail::send('emails.dailyreminder', [], function ($message) use($user) {
                         $message->from('*****@*****.**', 'Liga Quiz Portugal');
                         $message->to($user->email, $user->fullName())->subject('Novo quiz já disponível');
                     });
                 }
             }
         }
     }
     $specialquiz = Specialquiz::where('year', $year)->where('month', $month)->where('day', $day)->first();
     if (count($specialquiz)) {
         $users = User::all();
         if ($specialquiz->user_id) {
             $author = User::find($specialquiz->user_id)->fullName();
         } else {
             $author = 'Quiz Portugal';
         }
         foreach ($users as $key => $user) {
             if (strtotime("+1 day", strtotime($user->subscription)) > time() || $user->isAdmin()) {
                 if ($user->daily_reminder && $user->active) {
                     $data = array('specialquiz' => $specialquiz, 'author' => $author);
                     Mail::send('emails.specialquiz', $data, function ($message) use($user) {
                         $message->from('*****@*****.**', 'Liga Quiz Portugal');
                         $message->to($user->email, $user->fullName())->subject('Quiz especial disponível');
                     });
                 }
             }
         }
     }
 }
Пример #3
0
 public function correctSpecialQuiz($id)
 {
     $specialquiz = Specialquiz::find($id);
     $date = sprintf('%02d', $specialquiz->day) . '/' . sprintf('%02d', $specialquiz->month) . '/' . $specialquiz->year;
     $specialquestions = Specialquestion::where('quiz_id', $id)->get();
     $answers = [];
     foreach ($specialquestions as $key => $specialquestion) {
         $answers[$specialquestion->id] = Specialanswer::where('question_id', $specialquestion->id)->where('submitted', 1)->get();
     }
     return view('admin/correctSpecialQuiz')->with(['questions' => $specialquestions, 'answers' => $answers, 'date' => $date]);
 }
Пример #4
0
 public function submitSpecialQuiz(Request $request)
 {
     $input = $request->all();
     $inputs = [];
     foreach ($input as $key => $value) {
         if (substr($key, 0, strlen('answer')) === 'answer') {
             $inputs[$key] = 'required';
             $question_id = explode('_', $key)[1];
         }
     }
     $inputs['banker'] = ['max:5'];
     $this->validate($request, $inputs);
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $user_id = Auth::user()->id;
     foreach ($inputs as $key => $validation) {
         if (substr($key, 0, strlen('answer')) === 'answer') {
             $question_id = explode('_', $key)[1];
             $specialquestion = Specialquestion::find($question_id);
             $specialquiz = Specialquiz::find($specialquestion->quiz_id);
             if (!($specialquiz->year == $year && $specialquiz->month == $month && $specialquiz->day == $day)) {
                 return redirect()->route('specialquiz');
             }
             $answer = Specialanswer::where('question_id', $question_id)->where('user_id', $user_id)->where('submitted', 1)->get();
             if (isset($input['banker']) && in_array($question_id, $input['banker'])) {
                 $banker = 1;
             } else {
                 $banker = 0;
             }
             if (!count($answer)) {
                 Specialanswer::create(['question_id' => $question_id, 'user_id' => $user_id, 'answer' => $input[$key], 'banker' => $banker, 'submitted' => 1]);
             }
         }
     }
     return redirect()->route('specialquiz');
 }