Example #1
0
 public function checkCode(Request $request)
 {
     $code = $request->input('code');
     $currentPeriod = $this->period->checkPeriod();
     $user = Auth::User();
     $this->validate($request, ['code' => 'required|min:6|alpha_num|unique:keycodes,code,' . $code . ',id,used,1']);
     if ($this->user->checkIfParticipated($user)) {
         $this->user->hasParticipated($user);
         if ($this->validateCode->checkIfCodeIsValid($code)) {
             $result = $this->validateCode->checkIfCodeIsValid($code);
             if ($this->winner->checkWinner($code)) {
                 $this->validateCode->changeStateOfCode($result);
                 Mail::send('mails.winner', ['user' => $user], function ($ms) use($user) {
                     $ms->to($user->email, $user->name)->subject('U hebt gewonnen!');
                 });
                 $alreadyplayed = false;
                 $win = true;
                 return view('code/result', compact('win', 'alreadyplayed', 'currentPeriod'));
             }
         } else {
             $win = false;
             $alreadyplayed = false;
             return view('code/result', compact('win', 'alreadyplayed'));
         }
     } else {
         $win = false;
         $alreadyplayed = true;
         return view('code/result', compact('win', 'alreadyplayed'));
     }
 }
Example #2
0
 public function index()
 {
     $winners = $this->winner->getWinnersOfPreviousPeriods();
     $currentPeriod = $this->period->checkPeriod();
     $periods = $this->period->all();
     return view('index', compact('winners', 'currentPeriod', 'periods'));
 }
Example #3
0
 public function checkIfCodeIsValid($code)
 {
     $currentPeriod = $this->period->checkPeriod();
     $result = Keycode::where('code', '=', $code)->where('used', '=', '0')->where('period_id', '=', $currentPeriod->id)->first();
     if ($result) {
         return $result;
     } else {
         return false;
     }
 }
 public function periods()
 {
     if (Auth::check()) {
         $periods = Period::all();
         $currentPeriod = $this->period->checkPeriod();
         $codes = Keycode::all();
         return view('admin/periods', compact('currentPeriod', 'periods', 'codes'));
     } else {
         return view('errors/404');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get the time of now
     $time = Carbon::now()->toDateTimeString();
     $periods = Period::all();
     // Check if time is between start and end of a period
     foreach ($periods as $period) {
         if ($time >= $period->start && $time <= $period->end) {
             if (!$period->running) {
                 $period->running = 1;
                 $period->save();
             }
         } elseif ($period->running) {
             // Last period ends here + a mail of all the winners of that period is send to the admin
             $period->running = 0;
             $period->save();
             $winners = Winner::where('period', $period->id)->get();
             $data = ['title' => 'Winners of period ' . $period->id, 'content' => '', 'winners' => $winners];
             Mail::send('emails.winners', $data, function ($message) {
                 $message->to('*****@*****.**', 'Oscar');
                 $message->subject('Winners');
             });
         }
     }
 }
 public function store(Request $request)
 {
     $rules = ['period_id' => 'required|exists:periods,id', 'start' => 'required|date', 'end' => 'required|date'];
     $messages = ['start.required' => 'Es necesario definir la fecha de inicio.', 'end.required' => 'Es necesario definir la fecha de fin.'];
     $v = Validator::make($request->all(), $rules, $messages);
     if ($v->fails()) {
         return back()->withErrors($v)->withInput();
     }
     // Custom validations
     if ($request->get('start') > $request->get('end')) {
         $errors['range'] = 'Las fechas son inconsistentes.';
     }
     $period = Period::find($request->get('period_id'));
     // Exist an automatic cast from string to carbon
     // But the comparison for "2016-01-15" < $period->start
     // is evaluated as TRUE when they have the same date
     $start = Carbon::createFromFormat("Y-m-d", $request->get('start'));
     $end = Carbon::createFromFormat("Y-m-d", $request->get('end'));
     if ($start < $period->start) {
         $errors['start'] = 'La fecha de inicio debe ser posterior al inicio del periodo.';
     }
     if ($end > $period->end) {
         $errors['end'] = 'La fecha de fin debe ser anterior al fin del periodo.';
     }
     if (isset($errors)) {
         return back()->withErrors($errors)->withInput();
     }
     Unit::create($request->all());
     return back()->with('success', 'Unidad registrada exitosamente.');
 }
 public function getIndex()
 {
     $title = 'public';
     // get 8 most popular online rewards
     $rewards = Reward::orderBy('claimed', 'desc')->take(8)->get();
     // get last 5 winners
     $winners = Winner::orderBy('created_at', 'desc')->take(5)->get();
     // check if competition is running, has yet to start or has ended
     $time = Carbon::now()->toDateTimeString();
     $runningPeriod = Period::where('running', 1)->get();
     $firstPeriod = Period::orderBy('id', 'asc')->first();
     if (count($runningPeriod) == 1) {
         $competition['running'] = true;
         $competition['message'] = 'Enter your codes here to get your well-deserved points';
     } else {
         $competition['running'] = false;
         if ($time < $firstPeriod->start) {
             $competition['message'] = 'The competition has yet to start';
         } else {
             $competition['message'] = 'The competition has ended';
         }
     }
     // if logged in go to dashboard
     if (Auth::check()) {
         $user = Auth::user();
         $username = $user->name;
         $userPoints = $user->points;
         $title = 'Dashboard';
         $rewards = Reward::all();
         return view('dashboard.home', compact('competition', 'title', 'username', 'rewards', 'userPoints'));
     }
     return view('public.home', compact('competition', 'title', 'rewards', 'winners'));
 }
Example #8
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     $periods = \App\Period::all();
     return view('Admin.Period.period', compact('periods', $periods));
     //return view('Admin.Period.Project.project');
 }
Example #9
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $plan = Plan::find($id);
     $rubros = Rubro::lists('nombre', 'id');
     $periodos = Period::lists('nombre', 'id');
     return view('plan.edit', compact('plan', 'rubros', 'periodos'));
 }
 public function run()
 {
     DB::table('periods')->delete();
     Period::create(['id' => 1, 'start' => '2015-11-10 12:35:00', 'end' => '2015-11-11 12:36:00']);
     Period::create(['id' => 2, 'start' => '2015-11-11 12:36:00', 'end' => '2015-11-11 12:37:00']);
     Period::create(['id' => 3, 'start' => '2015-11-11 12:37:00', 'end' => '2015-11-11 12:38:00']);
     Period::create(['id' => 4, 'start' => '2015-11-11 12:38:00', 'end' => '2015-11-11 12:39:00']);
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //return view('Email.welcome');
     //
     $companies = \App\Company::where('active', 1)->get();
     $periods = \App\Period::where('active', 1)->get();
     return view('Admin.Registry.Company.company', ['companies' => $companies, 'periods' => $periods]);
 }
 public function getAll()
 {
     $period = new Period();
     $current_period = $period->active()->first();
     $img = new Image();
     $periods = $period->all();
     $winners = [];
     $pp_images = !is_null($current_period) ? $img->pastperiod($current_period)->get() : null;
     $rules = ['Hi everyone! Welcome to the Zeal Optics Ski Goggles Game!', 'The game goes on for 4 periods.', 'The photo with the most votes wins!', 'Every period a new winner is selected!', 'The rules are simple: register, post the most amazing and unique photo from your last ski vacation.', 'Sit back, relax and wait until the end of the period!', 'After every period the winners will be published on this page.', 'You can only post once!', 'You can als vote, but also only once for each photo!'];
     $past_periods = $period->past()->get();
     if ($past_periods) {
         foreach ($past_periods as $key => $p) {
             $winners['Period ' . ($key + 1)] = Votes::winners($p);
         }
     }
     $images = $current_period != null ? $img->with('author')->active($current_period)->get() : null;
     return view('home', compact('images', 'winners', 'rules', 'pp_images', 'periods'));
 }
 public function destroy($id)
 {
     $period = Period::find($id);
     $units = $period->units;
     if ($units->count() > 0) {
         return back()->with('error', 'No es posible eliminar un periodo asociado a unidades.');
     }
     $period->delete();
     return back();
 }
Example #14
0
 public function checkPeriod()
 {
     $currentDate = Carbon::now();
     $periods = Period::all();
     foreach ($periods as $period) {
         if ($currentDate > $period->start_date && $currentDate < $period->end_date) {
             return $period;
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $carbon = Carbon::now('America/Lima');
     // Current year
     $year = $carbon->year;
     // Getting the current school year
     $schoolYear = SchoolYear::all()->last();
     // Calculating the middle date
     $middle = clone $schoolYear->start;
     $middle->addMonths(6);
     // First period of the current school year
     Period::create(['school_year_id' => $schoolYear->id, 'name' => $year . '-I', 'start' => $schoolYear->start, 'end' => $middle]);
     // Last period of the current school year
     Period::create(['school_year_id' => $schoolYear->id, 'name' => $year . '-II', 'start' => $middle->addDay(), 'end' => $schoolYear->end]);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::where('role', 0)->first();
     $past_period = Period::past()->latest('end')->first();
     //        dd(Carbon::now('Europe/Brussels')->format('Y-m-d H'));
     //        dd($isTrue = $past_period->end->format('Y-m-d H'));
     //        dd($isTrue = $past_period->end->format('Y-m-d H') == Carbon::now('Europe/Brussels')->format('Y-m-d H'));
     $isTrue = $past_period->end->format('Y-m-d H') == Carbon::now('Europe/Brussels')->format('Y-m-d H');
     if ($isTrue) {
         $winners['Period ' . $past_period->id . ' (' . $past_period->start . ' - ' . $past_period->end . ')'] = Votes::winners($past_period);
         $data = ['winners' => $winners, 'user' => $user];
         Mail::send('emails.notification', $data, function ($m) use($user) {
             $m->from('*****@*****.**', 'Zeal Optics')->to($user->email, $user->username)->subject('Ski Goggles Game Winners!');
         });
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     /*	$teachersWhitout =  \App\User::leftJoin('registry_teachers', function($join) {
           $join->on('users.id', '=', 'registry_teachers.id_teacher');
         })
         ->whereNull('registry_teachers.id_teacher')
     		->Where('users.active',1)
     		->Where('users.type','<>','Student')
     		->select('users.id','users.first_name','users.last_name','users.type')
     		->get();
     */
     $periods = \App\Period::where('active', 1)->get();
     /*$teachersWhit =  \App\RegistryTeacher::Join('users','users.id','=','registry_teachers.id_teacher')
     		->select('registry_teachers.id as rm','users.id','users.first_name','users.last_name','users.type')->get();*/
     //dd($teachersWhit);
     return view('Admin.Registry.Teacher.teacher', ['periods' => $periods]);
 }
 /**
  * This method will be creating an application row in the database and fill
  * it upp with the visitors information. It will also create the required
  * foreign key linked tables and save all of them in the database
  * @return view
  */
 private function submitForm()
 {
     DB::transaction(function () {
         $application_form = new \App\Application_form();
         $application_form->user_id = Auth::user()->id;
         $application_form->status = 'pending';
         $application_form->date = date('Y-m-d');
         $application_form->save();
         $application_id = $application_form->id;
         foreach (Session::pull('competenceArray') as $comp) {
             $competence_profile = new \App\Competence_profile();
             $competence_profile->application_id = $application_id;
             $competence_profile->competence_id = \App\Competence::where('name', $comp->competence)->value('id');
             $competence_profile->years_of_experience = $comp->years;
             $competence_profile->save();
         }
         foreach (Session::pull('periodArray') as $comp) {
             $periods = new \App\Period();
             $periods->application_id = $application_id;
             $periods->from_date = $comp->from_date;
             $periods->to_date = $comp->to_date;
             $periods->save();
         }
     });
     return view('submit_success');
 }
 /**
  * This method will fetch all the competences and period of work for a
  * specific person. This person will be the person that has the application
  * id that is entered by the visitor. The information will then be saved
  * in their corresponding arrays in the session array
  * @param Request $request
  * @return view
  */
 public function fetchData(Request $request)
 {
     $this->validate($request, ['appId' => 'required|max:2']);
     Session::forget('periodArray');
     Session::forget('competenceArray');
     Session::forget('listArray');
     DB::transaction(function () {
         $currentId = Req::get('appId');
         $competence_profile = \App\Competence_profile::where('application_id', $currentId)->get();
         foreach ($competence_profile as $profile) {
             $competence = \App\Competence::where('id', $profile->competence_id)->value('name');
             $competenceObj = new \App\CompetenceObj($competence, $profile->years_of_experience);
             Session::push('competenceArray', $competenceObj);
         }
         $periods = \App\Period::where('application_id', $currentId)->get();
         foreach ($periods as $period) {
             $periodObj = new \App\PeriodObj($period->from_date, $period->to_date);
             Session::push('periodArray', $periodObj);
         }
         $applications = \App\Application_form::where('id', $currentId)->get();
         foreach ($applications as $application) {
             $first_name = \App\User::where('id', $application->user_id)->value('first_name');
             $last_name = \App\User::where('id', $application->user_id)->value('last_name');
             $ssn = \App\User::where('id', $application->user_id)->value('ssn');
             $email = \App\User::where('id', $application->user_id)->value('email');
             $applicationDTO = new \App\ApplicationDTO($application->id, $first_name, $last_name, $ssn, $email, $application->date, $application->status);
             Session::push('listArray', $applicationDTO);
         }
     });
     return view('status_application');
 }
 public function getWinners()
 {
     if (Auth::user()->admin) {
         $title = 'admin winners';
         $periods = Period::all();
         // get all the winners for every period
         foreach ($periods as $period) {
             $winners[] = Winner::where('period', $period->id)->get();
         }
         return view('admin.winners', compact('title', 'periods', 'winners'));
     } else {
         return redirect('dashboard');
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     $periods = \App\Period::where('active', 1)->get();
     return view('Admin.Registry.Student.student', ['periods' => $periods]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $periods = Period::all();
     $admin_email = $this->getEmail();
     return view('admin.index', compact('admin_email', 'periods'))->withTitle('Admin');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $period = Period::findOrFail($id);
     $period->delete();
     return redirect()->route('periods.index')->with('message', 'Item deleted successfully.');
 }
 /**
  * This method fetches the visitors search period and then tryes to match it
  * with all of the applicants available work periods. If it matches the 
  * applicants application information will be put in a DTO and stored in 
  * the array currently stored in the session array
  * @param Request $request
  */
 private function fetchPeriod(Request $request)
 {
     $this->validate($request, ['dateFrom' => 'required|date_format:Y-m-d', 'dateTo' => 'required|date_format:Y-m-d|after:dateFrom']);
     Session::forget('listArray');
     DB::transaction(function () {
         $fromDate = new \DateTime(Req::get('dateFrom'));
         $toDate = new \DateTime(Req::get('dateTo'));
         $allApplications = \App\Application_form::all();
         foreach ($allApplications as $application) {
             $periods = \App\Period::where('application_id', $application->id)->get();
             foreach ($periods as $period) {
                 if ($this->periodCheck(new \DateTime($period->from_date), new \DateTime($period->to_date), $fromDate, $toDate) == 1) {
                     $first_name = \App\User::where('id', $application->user_id)->value('first_name');
                     $last_name = \App\User::where('id', $application->user_id)->value('last_name');
                     $ssn = \App\User::where('id', $application->user_id)->value('ssn');
                     $email = \App\User::where('id', $application->user_id)->value('email');
                     $applicationDTO = new \App\ApplicationDTO($application->id, $first_name, $last_name, $ssn, $email, $application->date, $application->status);
                     Session::push('listArray', $applicationDTO);
                 }
             }
         }
     });
 }
 public function getWinners()
 {
     $user = Auth::user();
     $username = $user->name;
     $userPoints = $user->points;
     $title = 'Dashboard winners';
     // get all periods to see how many exist
     $periods = Period::all();
     // get all winners of every period
     foreach ($periods as $period) {
         $winners[] = Winner::where('period', $period->id)->get();
     }
     return view('dashboard.winner.all', compact('title', 'username', 'userPoints', 'winners', 'periods'));
 }