Exemplo n.º 1
0
 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'));
 }
 /**
  * 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]);
 }
 /**
  * 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]);
 }
 /**
  * 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]);
 }
 public function postCode(Request $request)
 {
     //validate input
     $this->validate($request, ['code' => 'required|size:10']);
     // search for code
     $code = WinningCode::withTrashed()->where('code', $request->code)->first();
     $user = Auth::user();
     $username = $user->name;
     $userPoints = $user->points;
     $rewards = Reward::orderBy('created_at', 'desc')->take(8)->get();
     //check if code is a bonus code
     if ($code && $code->used == 0 && $code->deleted_at == null) {
         $title = 'Dashboard';
         $usedCode = new UsedCode();
         $winner = new Winner();
         $codeValue = $code->value;
         //check if user used bonus code
         if ($code->bonus == 1) {
             if ($user->bonus == 0) {
                 // add points to account + save that user used bonus code
                 $userPoints = $userPoints + $codeValue;
                 $user->points = $userPoints;
                 $user->bonus = 1;
                 $usedCode->code = $code->code;
                 $usedCode->value = $code->value;
                 $usedCode->user()->associate($user);
                 // new winner
                 $winner->name = $user->name;
                 $winner->value = $code->value;
                 $winner->period = Period::where('running', 1)->first()->id;
                 $winner->user()->associate($user);
                 $winner->save();
                 $user->save();
                 $usedCode->save();
                 $success = true;
                 return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'success', 'codeValue'));
             } else {
                 $success = false;
                 $codeError = 'You have already used your free code.';
                 return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'codeError', 'success'));
             }
         }
         // add points to account + save that code is used
         $code->used = 1;
         $code->save();
         $userPoints = $userPoints + $codeValue;
         $user->points = $userPoints;
         $usedCode->code = $code->code;
         $usedCode->value = $code->value;
         $usedCode->user()->associate($user);
         // new winner
         $winner->name = $user->name;
         $winner->value = $code->value;
         $winner->period = Period::where('running', 1)->first()->id;
         $winner->user()->associate($user);
         $winner->save();
         $user->save();
         $usedCode->save();
         $success = true;
         return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'success', 'codeValue'));
     } else {
         //check if code is used before
         if ($code && $code->used == 1 && $code->deleted_at == null) {
             $success = false;
             $codeError = 'This code is alreay used and can only be used once';
             return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'codeError', 'success'));
             //check if code is deleted
         } elseif ($code && $code->deleted_at != null) {
             $success = false;
             $codeError = 'This code is suspended';
             return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'codeError', 'success'));
             // code does not exist
         } else {
             $success = false;
             $codeError = 'This code does not exist, did you make a mistake?';
             return view('dashboard.code.result', compact('title', 'username', 'userPoints', 'rewards', 'codeError', 'success'));
         }
     }
 }
 /**
  * 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);
                 }
             }
         }
     });
 }
 /**
  * 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');
 }