From 5039c7b294a15f1109308d2a0a2e53f043b5113b Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Tue, 10 Oct 2017 14:20:15 +0200 Subject: [PATCH] Add pdf export button in LP result page see BT#13527 --- main/lp/lp_report.php | 40 +++++++++++++++++++++- main/template/default/learnpath/report.tpl | 6 ++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/main/lp/lp_report.php b/main/lp/lp_report.php index a280012a89..abbb7e8137 100644 --- a/main/lp/lp_report.php +++ b/main/lp/lp_report.php @@ -16,6 +16,8 @@ if (!$isAllowedToEdit) { $lpTable = Database::get_course_table(TABLE_LP_MAIN); $lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : false; +$export = isset($_GET['export']) ? true : false; + if (empty($lpId)) { api_not_allowed(true); } @@ -105,6 +107,8 @@ if (!empty($users)) { 'lp_last_connection' => $lpLastConnection ]; } +} else { + Display::addFlash(Display::return_message(get_lang('NoUserAdded'), 'warning')); } // View @@ -123,12 +127,26 @@ $actions = Display::url( api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq() ); + +if (!empty($users)) { + $actions .= Display::url( + Display::return_icon( + 'pdf.png', + get_lang('ExportToPdf'), + array(), + ICON_SIZE_MEDIUM + ), + api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=report&export=pdf&lp_id='.$lpId + ); +} + $template = new Template(get_lang('StudentScore')); $template->assign('user_list', $userList); $template->assign('session_id', api_get_session_id()); $template->assign('course_code', api_get_course_id()); $template->assign('lp_id', $lpId); $template->assign('show_email', $showEmail === 'true'); +$template->assign('export', (int) $export); $layout = $template->get_template('learnpath/report.tpl'); @@ -137,5 +155,25 @@ $template->assign( 'actions', Display::toolbarAction('lp_actions', [$actions]) ); -$template->assign('content', $template->fetch($layout)); + +$result = $template->fetch($layout); +$template->assign('content', $result); + + +if ($export) { + $pdfParams = array( + 'filename' => get_lang('StudentScore').'_'.api_get_local_time(), + //'pdf_title' => $title, + //'course_code' => $course_code + ); + $pdf = new PDF('A4', 'P', $pdfParams); + $pdf->html_to_pdf_with_template( + $result, + false, + false, + true + ); + exit; +} + $template->display_one_col_template(); diff --git a/main/template/default/learnpath/report.tpl b/main/template/default/learnpath/report.tpl index bfa07191b6..f1d74d280e 100644 --- a/main/template/default/learnpath/report.tpl +++ b/main/template/default/learnpath/report.tpl @@ -11,7 +11,9 @@ {{ 'Progress'|get_lang }} {{ 'ScormScore'|get_lang }} {{ 'LastConnection'|get_lang }} + {% if not export %} {{ 'Actions'|get_lang }} + {% endif %} @@ -26,9 +28,11 @@ {{ user.lp_progress }} {{ user.lp_score }} {{ user.lp_last_connection }} + {% if not export %} + {% endif %} {% endfor %} @@ -46,7 +50,6 @@ $(document).on('ready', function () { var trDetail = trHead.next(); if (self.is('.active')) { self.removeClass('active'); - trDetail.html('').addClass('hide'); } else { self.addClass('active'); @@ -56,7 +59,6 @@ $(document).on('ready', function () { newTD.load('{{ _p.web_main ~ 'mySpace/lp_tracking.php?action=stats&extend_all=0&id_session=' ~ session_id ~ '&course=' ~ course_code ~ '&lp_id=' ~ lp_id ~ '&student_id=\' + userId + \'&origin=tracking_course&allow_extend=0' }} .table-responsive', function () { newTD.appendTo(trDetail); }); - trDetail.removeClass('hide'); } });