<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use \App\Log;

class AdminController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        Log::saveLog('Affichage du tableau de bord');

        $futureEvent_to_filtered = \App\Event::all()->sortBy('date_begin');
        $futureEvent_to_filtered_pass_1 = collect();
        $futureEvent = collect();

        foreach ($futureEvent_to_filtered as $day) {
            if (date('U',strtotime($day->date_begin)) >= date('U')) {
                $futureEvent_to_filtered_pass_1->push($day);
            }
        }
        
        foreach ($futureEvent_to_filtered_pass_1 as $day) {
            if (date('U',strtotime($day->date_begin)) <= date('U',strtotime("+2 week"))) {
                $futureEvent->push($day);
            }
        }

        return view('admin.dashboard',['futureEvent' => $futureEvent->take(3),'userClasse' => \Auth::User()->getClasse()->forPage(1,6)]);
    }

    public function update()
    {
        Log::saveLog('Affichage des notes de mise a jour');

        return view('admin.update');
    }

}
