Add pdf export button in LP result page see BT#13527

pull/2487/head
jmontoyaa 7 years ago
parent 7cd955b8d7
commit 5039c7b294
  1. 40
      main/lp/lp_report.php
  2. 6
      main/template/default/learnpath/report.tpl

@ -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();

@ -11,7 +11,9 @@
<th class="text-right">{{ 'Progress'|get_lang }}</th>
<th class="text-right">{{ 'ScormScore'|get_lang }}</th>
<th class="text-center">{{ 'LastConnection'|get_lang }}</th>
{% if not export %}
<th>{{ 'Actions'|get_lang }}</th>
{% endif %}
</tr>
</thead>
<tbody>
@ -26,9 +28,11 @@
<td class="text-right">{{ user.lp_progress }}</td>
<td class="text-right">{{ user.lp_score }}</td>
<td class="text-center">{{ user.lp_last_connection }}</td>
{% if not export %}
<td>
<button class="btn btn-primary btn-sm" data-id="{{ user.id }}">{{ 'Details'|get_lang }}</button>
</td>
{% endif %}
</tr>
<tr class="hide"></tr>
{% 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');
}
});

Loading…
Cancel
Save