/**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $period = new Period();
     $period->start_date = $request->input("start_date");
     $period->end_date = $request->input("end_date");
     $period->year = $request->input("year");
     $period->save();
     return redirect()->route('periods.index')->with('message', 'Item created successfully.');
 }
Пример #2
0
 public function postCompetition(Request $request)
 {
     // validate inputs
     $this->validate($request, ['start' => 'required|date|after:today', 'number' => 'required|integer', 'length' => 'required|integer']);
     // if correct -> get all periods of the competition
     $periods = Period::all();
     // delete all periods
     foreach ($periods as $period) {
         $period->delete();
     }
     // determine start of period 1 and the competition
     $date = new DateTime($request->start);
     // number of periods
     $number = $request->number;
     // length of 1 period
     $length = $request->length;
     // create periods based on information from above
     for ($i = 1; $i <= $number; $i++) {
         $period = new Period();
         $period->id = $i;
         $period->start = $date;
         $period->save();
         // add the period length to the datetime variable
         $period->end = $date->add(new DateInterval('P' . $length . 'D'));
         $period->save();
     }
     $title = 'admin competition';
     // get competition information
     $numberOfCodes = WinningCode::all()->count();
     $numberOfRewards = Reward::all()->count();
     $numberOfUsers = User::all()->count();
     $numberOfWinners = Winner::all()->count();
     // general start of the competition
     $start = Period::orderBy('start', 'asc')->get()->first()->start;
     // general end of the competition
     $end = Period::orderBy('end', 'desc')->get()->first()->end;
     // number of periods in the competition
     $periodCount = Period::all()->count();
     return view('admin.home', compact('title', 'numberOfCodes', 'numberOfRewards', 'numberOfUsers', 'numberOfWinners', 'start', 'end', 'periodCount'));
 }
Пример #3
0
 /**
  * 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');
 }