diff --git a/build/api/module/professor/pdfController.php b/build/api/module/professor/pdfController.php new file mode 100644 index 0000000..48c64a0 --- /dev/null +++ b/build/api/module/professor/pdfController.php @@ -0,0 +1,431 @@ + 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 */ + $headers = [ + 'Content-Description' => 'File Transfer', + 'Content-Transfer-Encoding' => 'binary', + '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éeValeur
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 UENom UEPrestationvolume horaireformations
'.$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'); + } + +} \ No newline at end of file diff --git a/config/modules.json b/config/modules.json index 4a29550..ec5aa3d 100644 --- a/config/modules.json +++ b/config/modules.json @@ -224,6 +224,19 @@ "matches": { "des": "Matching professor UID(s)", "typ": "array" } } } + }, + + "pdf": { + + "GET": { + "des": "Get a professor's fiche", + "per": [["cas_admin"]], + "par": { + "URL0": { "des": "Optional professor UID.", "typ": "id", "ren": "prof_id" } + }, + "opt": { "download": true } + } + } diff --git a/public_html/pdf.php b/public_html/pdf.php deleted file mode 100644 index fb8453d..0000000 --- a/public_html/pdf.php +++ /dev/null @@ -1,231 +0,0 @@ -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('Some PDF title'); - - /* (5) Store SVG */ - $svg_warning = ' - - '; - - - - - /* (2) Set Header|Footer - ---------------------------------------------------------*/ - /* (1) Set Header content (Left, Right) */ - $header_content = [ - 'C' => [ 'color' => '#aaa', 'content' => 'Fiche enseignant Sophie Gouardères (sgouarde)' ], - '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_création' ], - 'R' => [ 'color' => '#aaa', 'content' => 'Page {PAGENO} sur {nbpg}' ], - 'line' => 1 - ]; - - /* (2) Apply Footer */ - $pdf->setFooter([ - 'odd' => $footer_content, - 'even' => $footer_content - ]); - - - - - - /* (3) Page 1 - Récapitulatif - ---------------------------------------------------------*/ - /* (1) Initialize page */ - $pdf->AddPage(); - - /* (2) Write content */ - $pdf->WriteHTML('
-

1. Récapitulatif

-
- -
-

- Mollitia quo ullam voluptas quia delectus nihil ab. (cliquer ici) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -

- -
- Mollitia quo ullam voluptas quia delectus nihil ab. Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -
- -

- Mollitia quo ullam voluptas quia delectus nihil ab. (cliquer ici) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DonnéeValeur
Heures à faire192 h
Equivalents TD241.41 h
Heures programmées217.5 h
Heures manquantes'.$svg_warning.' 10 h
Heures sup.0
-
- - '); - - - - /* (4) Page 2 - Enseignements - ---------------------------------------------------------*/ - /* (1) Initialize page */ - $pdf->AddPage(); - - /* (2) Write content */ - $pdf->WriteHTML('
-

2. Enseignements

-
- -
-

- Mollitia quo ullam voluptas quia delectus nihil ab. (cliquer ici) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -

- -
- Mollitia quo ullam voluptas quia delectus nihil ab. Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -
- -

- Mollitia quo ullam voluptas quia delectus nihil ab. (cliquer ici) Temporibus voluptatum et adipisci dolores aut ut. Aliquid et non quaerat ipsa accusantium quis doloribus minus. Omnis cupiditate iste id a quisquam sunt officia. Architecto ut id non et deleniti et. Veritatis in consectetur ut -

- -


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Liste des enseignements programmés
Code UENom UEPrestationvolume horaireformations
T0XALA2VAlgorithmique avancéeCours13.5 heures
    -
  • MIASHS
  • -
  • L1 INFO (S2)
  • -
T0XALA2VAlgorithmique avancéeTD22 heures
    -
  • L1 INFO (S2)
  • -
T0XALA2VAlgorithmique avancéeTP5 heures
    -
  • MIASHS
  • -
  • L1 INFO (S2)
  • -
  • L2 INFO (S2)
  • -
T0MSAP3UAlgorithmique et programmation avancéeTP12 heures
    -
  • MIASHS
  • -
  • L1 INFO (S2)
  • -
  • L2 INFO (S2)
  • -
-
- - - '); - - - - - /* (N) Print out PDF file - ---------------------------------------------------------*/ - - $pdf->Output(); - -