<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;
use App\Helpers\UserSystemInfoHelper;
use Session;

class ModuleGSController extends Controller
{
    public function index(Request $request)
    {
        $idEtablissement = 11;

        $etabli = DB::table('etablissement')
        ->where(['idEtablissement'=> $idEtablissement])->first();

        $matricule = '101021';

        $users = DB::table('users')
        ->where(['matricule'=> $matricule])->first();

        $geststudent_r = DB::table('geststudent_r')
        ->where(['matricule'=> $matricule])->first();
        $cheminPhoto 		= $geststudent_r->cheminPhoto;
        $nom 				= $geststudent_r->nom;
        $prenom 			= $geststudent_r->prenom;
        $nationalite 		= $geststudent_r->nationalite;
        $description 		= $geststudent_r->description;
        $listeFilieres		= $geststudent_r->idFiliere;

        $idUniversite = 4;

        $moduleseta = DB::table('etablissement')
        ->where(['idUniversite'=> $idUniversite])->first();

        //Selection de tous les modules de GestStudent
        $modulesgs = DB::table('modulesgs')
        ->orderBy('ordreAffichage', 'asc')
        ->get();

        $nb = $modulesgs->count();
        $nbligne = ceil($nb/3);
        $tabIdmodule = array();
        $tabTitre = array();
        $tabNom   = array();
        $tabLien  = array();
        $tabLongdescriptionModule = array();
        $i = 0;
        foreach ($modulesgs as $modules) {
            $tabIdmodule[$i]                = $modules->idModule;
            $tabTitre[$i]                   = $modules->titreModule;
            $tabNom[$i]                     = $modules->nomModule;
            $tabLien[$i]                    = $modules->lienModule;
            $tabLongdescriptionModule[$i]   = $modules->longdescriptionModule;
            $couleur[$i]   		            = $modules->couleur;
            $i++;
        }
        //dd($couleur);
        $mesModules = DB::table('etablissement')
        ->where(['idEtablissement'=> $idEtablissement])->first();

        $array = explode(',', $mesModules->mesModules);

        return view('modulegs.index')->with([
            'email1'=>$users->email, 'phone1'=>$users->phone,
            'nom'=>$nom,'prenom'=>$prenom,
            'cheminPhoto'=>'https://progiciel.geststudent.net/Admin/'.$cheminPhoto, 'tabIdmodule'=> $tabIdmodule,
            'array'=> $array, 'id'=>$idEtablissement,
            'nbligne'=> $nbligne, 'nb'=> $nb, 'tabTitre'=> $tabTitre,
            'tabNom'=> $tabNom, 'tabLien'=> $tabLien,
            'tabLongdescriptionModule'=> $tabLongdescriptionModule,
            'couleur'=> $couleur
        ]);
    }
}
