Explorar o código

Merge pull request #410 from AngelFQC/7358

Students can download their certificates in PDF file - refs #7358
Yannick Warnier %!s(int64=10) %!d(string=hai) anos
pai
achega
0f50ca16d7
Modificáronse 2 ficheiros con 42 adicións e 3 borrados
  1. 32 2
      certificates/index.php
  2. 10 1
      main/gradebook/lib/be/category.class.php

+ 32 - 2
certificates/index.php

@@ -14,7 +14,37 @@ $language_file= array('admin', 'gradebook', 'document');
 require_once '../main/inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'certificate.lib.php';
 
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+
 $certificate = new Certificate($_GET['id']);
 
-//Show certificate HTML
-$certificate->show();
+switch ($action) {
+    case 'export':
+        $certificate->generate(array('hide_print_button' => true));
+
+        if ($certificate->html_file_is_generated()) {
+            $certificatePathList[] = $certificate->html_file;
+
+            $pdfParams = array(
+                'orientation' => 'landscape',
+                'top' => 0,
+                'right' => 0,
+                'bottom' => 0,
+                'left' => 0
+            );
+
+            $pdfParams['orientation'] = 'landscape';
+            $pageFormat = $pdfParams['orientation'] == 'landscape' ? 'A4-L' : 'A4';
+
+            $userInfo = api_get_user_info($certificate->user_id);
+
+            $pdfName = replace_dangerous_char(get_lang('Certificate') . ' ' . $userInfo['username']);
+
+            $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);
+            $pdf->html_to_pdf($certificatePathList, $pdfName, null, false, false);
+        }
+        break;
+    default:
+        //Show certificate HTML
+        $certificate->show();
+}

+ 10 - 1
main/gradebook/lib/be/category.class.php

@@ -1633,8 +1633,17 @@ class Category implements GradebookItem
                         $url,
                         array('target' => '_blank')
                     );
+                    $exportToPDF = Display::url(
+                        Display::return_icon(
+                            'pdf.png',
+                            get_lang('ExportToPDF'),
+                            array(),
+                            32
+                        ),
+                        "$url&action=export"
+                    );
                     $html = '<div class="actions" align="right">';
-                    $html .= $certificates;
+                    $html .= $certificates . $exportToPDF;
                     $html .= '</div>';
                 }
                 return $html;