Professor ID * * @return download The PDF fiche ---------------------------------------------------------*/ public static function get($args){ $prof_id = -1; extract($args); /* (0) Initialize ---------------------------------------------------------*/ /* (1) Initialize data structure */ $data = [ 'prof' => [], 'cours' => [], 'td' => [], 'tp' => [], 'form' => [] ]; /* (2) Get repositories */ /** @var professor $prof_repo */ $prof_repo = Repo::getRepo('professor'); /** @var formation $form_repo */ $form_repo = Repo::getRepo('formation'); /** @var cours $cours_repo */ $cours_repo = Repo::getRepo('cours'); /** @var td $td_repo */ $td_repo = Repo::getRepo('td'); /** @var tp $tp_repo */ $tp_repo = Repo::getRepo('tp'); /* (1) Get professor data ---------------------------------------------------------*/ /* (1) Request */ $fetched = $prof_repo->getWithVH($prof_id); /* (2) Error */ if( count($fetched) < 1 ) return ['error' => new Error(Err::NoMatchFound)]; /* (3) Extract data */ $data['prof'] = $fetched[0]; /* (2) Get each Cours ---------------------------------------------------------*/ /* (1) Request */ $fetched = $cours_repo->getForProfessor($prof_id); /* (2) Store data if no error */ if( !is_null($fetched) ) $data['cours'] = $fetched; /* (3) For each Cours -> parse formation list */ foreach($data['cours'] as $kcours=>$cours) $data['cours'][$kcours]['formations'] = json_decode($cours['formations']); /* (3) get each TD ---------------------------------------------------------*/ /* (1) Request */ $fetched = $td_repo->getForProfessor($prof_id); /* (2) Store data if no error */ if( !is_null($fetched) ) $data['td'] = $fetched; /* (3) For each TD -> parse formation list */ foreach($data['td'] as $ktd=>$td) $data['td'][$ktd]['formations'] = json_decode($td['formations']); /* (4) get each TP ---------------------------------------------------------*/ /* (1) Request */ $fetched = $tp_repo->getForProfessor($prof_id); /* (2) Store data if no error */ if( !is_null($fetched) ) $data['tp'] = $fetched; /* (3) For each TP -> parse formation list */ foreach($data['tp'] as $ktp=>$tp) $data['tp'][$ktp]['formations'] = json_decode($tp['formations']); /* (5) Get formations (id => label) ---------------------------------------------------------*/ /* (1) Request */ $fetched = $form_repo->get(null); /* (2) Error: no formation found */ if( count($fetched) < 1 ) return ['error' => new Error(Err::RepoError)]; /* (3) Reference formations by key = idForm */ foreach($fetched as $form) $data['form'][intval($form['idForm'])] = $form; /* (6) Render PDF ---------------------------------------------------------*/ /* (1) Generate body */ $body = self::generate_pdf_body($data); /* (2) Set headers */ $fullname = $data['prof']['firstName'].' '.$data['prof']['lastName']; $date = date('d-m-Y'); $title = "Fiche enseignant - $fullname ($date)"; $headers = [ // 'Content-Description' => 'File Transfer', 'Content-Transfer-Encoding' => 'binary', 'Content-Disposition' => 'attachment; filename="'.$title.'"', 'Cache-Control' => 'public, must-revalidate, max-age=0', 'Pragma' => 'public', 'X-Generator' => 'mPDF', 'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT', 'Last-Modified' => gmdate('D, d M Y H:i:s').' GMT', 'Content-Type' => 'application/pdf' ]; /* (3) Generate download */ return [ 'headers' => $headers, 'body' => $body ]; } private static function generate_pdf_body($data){ /* (1) Format data ---------------------------------------------------------*/ /* (1) Get fullname */ $fullname = $data['prof']['firstName'].' '.$data['prof']['lastName']; /* (2) Get formatted date */ $date = date('d-m-Y'); /* (3) Total horaire */ $total_h = floatval($data['prof']['VHCours']) + floatval($data['prof']['VHTd']) + floatval($data['prof']['VHTp']); $equiTD = floatval($data['prof']['equiTD']); /* (4) Heures manquantes */ // TOTAL_H or equiTD ??? $missing_h = floatval($data['prof']['hoursToDo']) - $equiTD; $missing_h = $missing_h < 0 ? 0 : $missing_h; /* (5) Heures sup */ $sup_h = $equiTD > floatval($data['prof']['hoursToDo']) ? $equiTD - floatval($data['prof']['hoursToDo']) : 0; /* (2) Initialize PDF ---------------------------------------------------------*/ /* (1) Get Font default directory */ $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; /* (2) Get Font data */ $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; /* (3) Create PDF file */ $pdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'defaultCssFile' => __PUBLIC__.'/css/pdf.css', 'tempDir' => __ROOT__.'/tmp', 'fontDir' => array_merge($fontDirs, [ __PUBLIC__.'/font/' ]), 'fontdata' => $fontData + [ 'Fira Sans' => [ 'R' => 'FiraSans-Regular.ttf' ] ], 'default_font' => 'Fira Sans' ]); /* (4) Set PDF title */ $pdf->SetTitle("Fiche enseignant - $fullname ($date)"); /* (5) Store SVG */ $svg_warning = ' '; /* (3) Set Header|Footer ---------------------------------------------------------*/ /* (1) Set Header content (Left, Right) */ $header_content = [ 'C' => [ 'color' => '#aaa', 'content' => "Fiche enseignant $fullname" ], 'line' => 1 ]; /* (2) Apply Header */ $pdf->setHeader([ 'odd' => $header_content, 'even' => $header_content ]); /* (1) Set Footer content (Left, Right) */ $footer_content = [ 'L' => [ 'color' => '#aaa', 'content' => "Généré le $date" ], 'R' => [ 'color' => '#aaa', 'content' => 'Page {PAGENO} sur {nbpg}' ], 'line' => 1 ]; /* (2) Apply Footer */ $pdf->setFooter([ 'odd' => $footer_content, 'even' => $footer_content ]); /* (4) Page 1 - Récapitulatif ---------------------------------------------------------*/ /* (1) Initialize page */ $pdf->AddPage(); /* (2) Write content */ $pdf->WriteHTML('

1. Récapitulatif


La liste des informations récapitulative est basée sur les données de tous les enseignants enregistrés à ce jour.

Il est à noter qu\'elle contient les données générées au '.$date.'. Elle peut ne plus être à jour.

Si un problème persiste veuillez contacter les responsables à l\'addresse mail suivante <mail_display_error>.




Donnée Valeur
Heures à faire '.$data['prof']['hoursToDo'].' h
Equivalents TD '.$data['prof']['equiTD'].' h
Heures programmées '.$total_h.' h
Heures manquantes '.( $missing_h>0 ? "$svg_warning $missing_h" : $missing_h).' h
Heures sup. '.$sup_h.' h
'); /* (5) Page 2 - Enseignements ---------------------------------------------------------*/ /* (1) Initialize page */ $pdf->AddPage(); /* (2) Write content */ $pdf->WriteHTML('

2. Enseignements


La liste des enseignements générée dans le tableau ci-dessous est uniquement à titre informatif et n\'est pas contractuelle.

Il est à noter qu\'elle contient les données générées au '.$date.'. Elle peut ne plus être à jour.

Si un problème persiste veuillez contacter les responsables à l\'addresse mail suivante <mail_display_error>.




'); /* (3) List Cours */ foreach($data['cours'] as $kc=>$c){ $pdf->WriteHTML(''); } /* (4) List TD */ foreach($data['td'] as $kc=>$c){ $pdf->WriteHTML(''); } /* (5) List TP */ foreach($data['tp'] as $kc=>$c){ $pdf->WriteHTML(''); } /* (6) End HTML */ $pdf->WriteHTML('
Liste des enseignements programmés
Code UE Nom UE Prestation volume horaire formations
'.$c['code'].' '.$c['label'].' Cours '.$c['volume'].' heures
    '); // print formations foreach($c['formations'] as $f) if( isset($data['form'][$f]) ) $pdf->WriteHTML('
  • '.$data['form'][$f]['labelForm'].'
  • '); $pdf->WriteHTML('
'.$c['code'].' '.$c['label'].' TD '.$c['volume'].' heures
    '); // print formations foreach($c['formations'] as $f) if( isset($data['form'][$f]) ) $pdf->WriteHTML('
  • '.$data['form'][$f]['labelForm'].'
  • '); $pdf->WriteHTML('
'.$c['code'].' '.$c['label'].' TP '.$c['volume'].' heures
    '); // print formations foreach($c['formations'] as $f) if( isset($data['form'][$f]) ) $pdf->WriteHTML('
  • '.$data['form'][$f]['labelForm'].'
  • '); $pdf->WriteHTML('
'); /* (N) Print out PDF file ---------------------------------------------------------*/ return $pdf->Output("Fiche enseignant - $fullname ($date)", 'S'); } }