コード例 #1
0
 public function getIndex()
 {
     $user = Auth::user();
     $username = $user->name;
     $userPoints = $user->points;
     $title = 'Dashboard';
     // 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';
         }
     }
     // get 8 newest online rewards
     $rewards = Reward::orderBy('created_at', 'desc')->take(8)->get();
     return view('dashboard.home', compact('competition', 'title', 'username', 'rewards', 'userPoints'));
 }
コード例 #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
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $periods = Period::orderBy('id', 'desc')->paginate(10);
     return view('periods.index', compact('periods'));
 }