public function get_UeUserList_csv($id)
 {
     if (!(Helpers::isProf() || Helpers::isSecr())) {
         return redirect('/');
     }
     $ue = Ue::FindOrFail($id);
     $parcours_ue = $ue->parcours_ues->first();
     $output = fopen('php://memory', 'w');
     $filename = $ue->intitule . '.csv';
     // output the column headings
     fputcsv($output, array($ue->intitule), ';');
     fputcsv($output, array('Nom', 'Prénom', '@mail', 'actif'), ';');
     // loop over the rows, outputting them
     foreach ($parcours_ue->choixes as $choix) {
         $user = $choix->user;
         fputcsv($output, array($user->nom, $user->prenom, $user->mail, $user->actif), ';');
     }
     // reset the file pointer to the start of the file
     fseek($output, 0);
     // tell the browser it's going to be a csv file
     header('Content-Type: application/csv');
     // tell the browser we want to save it instead of displaying it
     header('Content-Disposition: attachment; filename="' . $filename . '";');
     // make php send the generated csv lines to the browser
     fpassthru($output);
     return null;
 }
Beispiel #2
0
 public function index()
 {
     if (Helpers::isAdmin() || Helpers::isSecr()) {
         $ues = Ue::all();
         return response()->view('ues.show_all_ue', compact('ues'));
     } else {
         if (Helpers::isProf()) {
             $ues = Auth::user()->uesEnseignees()->get();
             return response()->view('ues.show_all_ue', compact('ues'));
         }
     }
     return redirect('/');
 }