Tracking: Add achievement certificate see BT#17817

pull/3573/head
Julio Montoya 5 years ago
parent f9f0c3afb5
commit 88d8dfd2e1
  1. 99
      main/mySpace/myStudents.php
  2. 39
      main/template/default/my_space/certificate_achievement.tpl

@ -38,7 +38,6 @@ if (empty($student_id)) {
api_not_allowed(true); api_not_allowed(true);
} }
// user info
$user_info = api_get_user_info($student_id); $user_info = api_get_user_info($student_id);
if (empty($user_info)) { if (empty($user_info)) {
@ -241,6 +240,8 @@ switch ($action) {
break; break;
case 'export_to_pdf': case 'export_to_pdf':
$sessionToExport = $sId = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0; $sessionToExport = $sId = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0;
$type = isset($_GET['type']) ? $_GET['type'] : 'attendance';
$sessionInfo = api_get_session_info($sessionToExport); $sessionInfo = api_get_session_info($sessionToExport);
if (empty($sessionInfo)) { if (empty($sessionInfo)) {
api_not_allowed(true); api_not_allowed(true);
@ -276,39 +277,43 @@ switch ($action) {
$first = Tracking::get_first_connection_date($student_id); $first = Tracking::get_first_connection_date($student_id);
$last = Tracking::get_last_connection_date($student_id); $last = Tracking::get_last_connection_date($student_id);
$timeSpentContent = '';
$table = new HTML_Table(['class' => 'table table-hover table-striped data_table']); if ('attendance' === $type) {
$column = 0; $table = new HTML_Table(['class' => 'table table-hover table-striped data_table']);
$row = 0; $column = 0;
$headers = [ $row = 0;
get_lang('TimeSpent'), $headers = [
get_lang('NumberOfVisits'), get_lang('TimeSpent'),
get_lang('GlobalProgress'), get_lang('NumberOfVisits'),
get_lang('FirstLogin'), get_lang('GlobalProgress'),
get_lang('LastConnexionDate'), get_lang('FirstLogin'),
]; get_lang('LastConnexionDate'),
];
foreach ($headers as $header) { foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header); $table->setHeaderContents($row, $column, $header);
$column++; $column++;
}
$table->setCellContents(1, 0, api_time_to_hms($timeSpent));
$table->setCellContents(1, 1, $numberVisits);
$table->setCellContents(1, 2, $average);
$table->setCellContents(1, 3, $first);
$table->setCellContents(1, 4, $last);
$timeSpentContent = $table->toHtml();
} }
$table->setCellContents(1, 0, api_time_to_hms($timeSpent));
$table->setCellContents(1, 1, $numberVisits);
$table->setCellContents(1, 2, $average);
$table->setCellContents(1, 3, $first);
$table->setCellContents(1, 4, $last);
$courseTable = ''; $courseTable = '';
if (!empty($courses)) { if (!empty($courses)) {
$courseTable .= '<table class="table table-hover table-striped data_table">'; $courseTable .= '<table class="table table-hover table-striped data_table">';
$courseTable .= '<thead>'; $courseTable .= '<thead>';
$courseTable .= '<tr> $courseTable .= '<tr>
<th>'.get_lang('FormationUnit').'</th> <th>'.get_lang('FormationUnit').'</th>
<th>'.get_lang('ConnectionTime').'</th> <th>'.get_lang('ConnectionTime').'</th>
<th>'.get_lang('Progress').'</th> <th>'.get_lang('Progress').'</th>';
<th>'.get_lang('Score').'</th>
</tr>'; if ('attendance' === $type) {
$courseTable .= '<th>'.get_lang('Score').'</th>';
}
$courseTable .= '</tr>';
$courseTable .= '</thead>'; $courseTable .= '</thead>';
$courseTable .= '<tbody>'; $courseTable .= '<tbody>';
@ -364,8 +369,10 @@ switch ($action) {
$courseInfoItem['title'].'</a> $courseInfoItem['title'].'</a>
</td> </td>
<td >'.$time_spent_on_course.'</td> <td >'.$time_spent_on_course.'</td>
<td >'.$progress.'</td> <td >'.$progress.'</td>';
<td >'.$score.'</td>'; if ('attendance' === $type) {
$courseTable .= '<td >'.$score.'</td>';
}
$courseTable .= '</tr>'; $courseTable .= '</tr>';
} }
} }
@ -383,16 +390,33 @@ switch ($action) {
<th>'.get_lang('Total').'</th> <th>'.get_lang('Total').'</th>
<th>'.$totalTimeFormatted.'</th> <th>'.$totalTimeFormatted.'</th>
<th>'.$totalProgressFormatted.'</th> <th>'.$totalProgressFormatted.'</th>
<th>'.$totalScoreFormatted.'</th> ';
</tr>'; if ('attendance' === $type) {
$courseTable .= '<th>'.$totalScoreFormatted.'</th>';
}
$courseTable .= '</tr>';
$courseTable .= '</tbody></table>'; $courseTable .= '</tbody></table>';
} }
$tpl = new Template('', false, false, false, true, false, false); $tpl = new Template('', false, false, false, true, false, false);
$tpl->assign('title', get_lang('AttestationOfAttendance')); $tpl->assign('title', get_lang('AttestationOfAttendance'));
$tpl->assign('session_title', $sessionInfo['name']); $tpl->assign('session_title', $sessionInfo['name']);
$tpl->assign('session_info', $sessionInfo);
$sessionCategoryTitle = '';
if (isset($sessionInfo['session_category_id'])) {
$sessionCategory = SessionManager::get_session_category($sessionInfo['session_category_id']);
if ($sessionCategory) {
$sessionCategoryTitle = $sessionCategory['name'];
}
}
$dateData = SessionManager::parseSessionDates($sessionInfo, false);
$dateToString = $dateData['access'];
$tpl->assign('session_display_dates', $dateToString);
$tpl->assign('session_category_title', $sessionCategoryTitle);
$tpl->assign('student', $user_info['complete_name']); $tpl->assign('student', $user_info['complete_name']);
$tpl->assign('table_progress', $table->toHtml()); $tpl->assign('student_info', $user_info);
$tpl->assign('student_info_extra_fields', UserManager::get_extra_user_data($user_info['user_id']));
$tpl->assign('table_progress', $timeSpentContent);
$tpl->assign( $tpl->assign(
'subtitle', 'subtitle',
sprintf( sprintf(
@ -401,7 +425,11 @@ switch ($action) {
) )
); );
$tpl->assign('table_course', $courseTable); $tpl->assign('table_course', $courseTable);
$content = $tpl->fetch($tpl->get_template('my_space/pdf_export_student.tpl')); $template = 'pdf_export_student.tpl';
if ('achievement' === $type) {
$template = 'certificate_achievement.tpl';
}
$content = $tpl->fetch($tpl->get_template('my_space/'.$template));
$params = [ $params = [
'pdf_title' => get_lang('Resume'), 'pdf_title' => get_lang('Resume'),
@ -414,7 +442,7 @@ switch ($action) {
'show_teacher_as_myself' => false, 'show_teacher_as_myself' => false,
'orientation' => 'P', 'orientation' => 'P',
]; ];
$pdf = new PDF('A4', $params['orientation'], $params); @$pdf = new PDF('A4', $params['orientation'], $params);
try { try {
$pdf->setBackground($tpl->theme); $pdf->setBackground($tpl->theme);
@ -1453,7 +1481,12 @@ if (empty($details)) {
$sessionAction .= Display::url( $sessionAction .= Display::url(
Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM), Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM),
$currentUrl.'&' $currentUrl.'&'
.http_build_query(['action' => 'export_to_pdf', 'session_to_export' => $sId]) .http_build_query(['action' => 'export_to_pdf', 'type' => 'attendance', 'session_to_export' => $sId])
);
$sessionAction .= Display::url(
Display::return_icon('pdf.png', get_lang('CertificateOfAchievement'), [], ICON_SIZE_MEDIUM),
$currentUrl.'&'
.http_build_query(['action' => 'export_to_pdf', 'type' => 'achievement', 'session_to_export' => $sId])
); );
} }
echo $sessionAction; echo $sessionAction;

@ -0,0 +1,39 @@
<div style="position: absolute; top: 40px; right: 50px;">
{{ logo }}
</div>
{% if title %}
<h1 style="color:#084B8A; text-transform: uppercase; background-color:transparent;font-size: 24px; text-align: center; font-weight: bold; padding: 5px 10px; margin-bottom: 10px;">
{{ title }}
</h1>
{% endif %}
{% if session_title %}
<h1 style="color:#084B8A; font-size: 22px; text-align: center; font-weight: bold; padding: 5px 10px; margin-bottom: 10px;">
{{ session_title }}
</h1>
{% endif %}
{% if student_info %}
<div style="font-weight: bold; font-size: 14px; padding-bottom: 20px; margin-top: 20px;">
{{ 'NamesAndLastNames'|get_lang }} : {{ student_info.complete_name }}
</div>
{% endif %}
{% if table_progress %}
<div style="background: transparent; font-size: 12px;">
{{ table_progress }}
</div>
{% endif %}
{% if subtitle %}
<div style="padding-bottom: 20px; margin-top: 20px; font-weight: bold;">
{{ subtitle }}
</div>
{% endif %}
{% if table_course %}
<div style="background: #f1f6ff;">
{{ table_course }}
</div>
{% endif %}
Loading…
Cancel
Save