Add My Certificates page - refs #7363

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent af1f821066
commit ccbc30fe48
  1. 101
      main/gradebook/my_certificates.php
  2. 63
      main/template/default/gradebook/my_certificates.tpl

@ -0,0 +1,101 @@
<?php
/* For licensing terms, see /license.txt */
/**
* List of achieved certificates by the current user
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.gradebook
*/
$cidReset = true;
require_once '../inc/global.inc.php';
if (api_is_anonymous()) {
api_not_allowed(true);
}
$userId = api_get_user_id();
$courses = CourseManager::get_courses_list_by_user_id($userId);
$sessions = SessionManager::get_sessions_by_user($userId);
$courseList = $sessionList = [];
foreach ($courses as $course) {
$courseGradebookCategory = Category::load(null, null, $course['code']);
if (empty($courseGradebookCategory)) {
continue;
}
$courseGradebookId = $courseGradebookCategory[0]->get_id();
$certificateInfo = GradebookUtils::get_certificate_by_user_id($courseGradebookId, $userId);
if (empty($certificateInfo)) {
continue;
}
$courseInfo = api_get_course_info($course['code']);
$courseList[] = [
'course' => $courseInfo['title'],
'score' => $certificateInfo['score_certificate'],
'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
];
}
foreach ($sessions as $session) {
if (empty($session['courses'])) {
continue;
}
$sessionCourses = SessionManager::get_course_list_by_session_id($session['session_id']);
foreach ($sessionCourses as $sessionCourse) {
$courseGradebookCategory = Category::load(
null,
null,
$sessionCourse['code'],
null,
null,
$session['session_id']
);
if (empty($courseGradebookCategory)) {
continue;
}
$courseGradebookId = $courseGradebookCategory[0]->get_id();
$certificateInfo = GradebookUtils::get_certificate_by_user_id($courseGradebookId, $userId);
if (empty($certificateInfo)) {
continue;
}
$sessionList[] = [
'session' => $session['session_name'],
'course' => $sessionCourse['title'],
'score' => $certificateInfo['score_certificate'],
'date' => api_format_date($certificateInfo['created_at'], DATE_FORMAT_SHORT),
'link' => api_get_path(WEB_PATH) . "certificates/index.php?id={$certificateInfo['id']}"
];
}
}
$template = new Template(get_lang('MyCertificates'));
$template->assign('course_list', $courseList);
$template->assign('session_list', $sessionList);
$content = $template->fetch('default/gradebook/my_certificates.tpl');
if (empty($courseList) || empty($sessionList)) {
$template->assign(
'message',
Display::return_message(get_lang('YouNotYetAchievedCertificates'), 'warning')
);
}
$template->assign('content', $content);
$template->display_one_col_template();

@ -0,0 +1,63 @@
{% if course_list is not empty %}
<h1 class="page-header">{{ "Courses"|get_lang }}</h1>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ "Course"|get_lang }}</th>
<th class="text-right">{{ "Score"|get_lang }}</th>
<th class="text-center">{{ "Fecha"|get_lang }}</th>
<th class="text-right">&nbsp;</th>
</tr>
</thead>
<tbody>
{% for row in course_list %}
<tr>
<td>{{ row.course }}</td>
<td class="text-right">{{ row.score }}</td>
<td class="text-center">{{ row.date }}</td>
<td class="text-right">
<a href="{{ row.link }}" target="_blank" class="btn btn-default">
<i class="fa fa-external-link"></i> {{ 'Certificate'|get_lang }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% if session_list is not empty %}
<h1 class="page-header">{{ "Sessions"|get_lang }}</h1>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ "Session"|get_lang }}</th>
<th>{{ "Course"|get_lang }}</th>
<th class="text-right">{{ "Score"|get_lang }}</th>
<th class="text-center">{{ "Fecha"|get_lang }}</th>
<th class="text-right">&nbsp;</th>
</tr>
</thead>
<tbody>
{% for row in session_list %}
<tr>
<td>{{ row.session }}</td>
<td>{{ row.course }}</td>
<td class="text-right">{{ row.score }}</td>
<td class="text-center">{{ row.date }}</td>
<td class="text-right">
<a href="{{ row.link }}" target="_blank" class="btn btn-default">
<i class="fa fa-external-link"></i> {{ 'Certificate'|get_lang }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
Loading…
Cancel
Save