commit
57eec79af4
@ -0,0 +1,120 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Show information about the issued badge |
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> |
||||
* @package chamilo.badge |
||||
*/ |
||||
require_once '../inc/global.inc.php'; |
||||
|
||||
$userId = isset($_GET['user']) ? intval($_GET['user']) : 0; |
||||
$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0; |
||||
|
||||
if (!isset($_GET['user'], $_GET['skill'])) { |
||||
header('Location: ' . api_get_path(WEB_PATH)); |
||||
exit; |
||||
} |
||||
|
||||
$entityManager = Database::getManager(); |
||||
$user = $entityManager->find('ChamiloUserBundle:User', $_GET['user']); |
||||
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $_GET['skill']); |
||||
|
||||
if (!$user || !$skill) { |
||||
Display::addFlash( |
||||
Display::return_message(get_lang('NoResults'), 'error') |
||||
); |
||||
|
||||
header('Location: ' . api_get_path(WEB_PATH)); |
||||
exit; |
||||
} |
||||
|
||||
$skillUserRepo = $entityManager->getRepository('ChamiloCoreBundle:SkillRelUser'); |
||||
$userSkills = $skillUserRepo->findBy([ |
||||
'userId' => $user->getId(), |
||||
'skillId' => $skill->getId() |
||||
]); |
||||
|
||||
if (!$userSkills) { |
||||
Display::addFlash( |
||||
Display::return_message(get_lang('TheUserXNotYetAchievedTheSkillX'), 'error') |
||||
); |
||||
|
||||
header('Location: ' . api_get_path(WEB_PATH)); |
||||
exit; |
||||
} |
||||
|
||||
$userInfo = [ |
||||
'id' => $user->getId(), |
||||
'complete_name' => $user->getCompleteName() |
||||
]; |
||||
|
||||
$skillInfo = [ |
||||
'id' => $skill->getId(), |
||||
'name' => $skill->getName(), |
||||
'short_code' => $skill->getShortCode(), |
||||
'description' => $skill->getDescription(), |
||||
'criteria' => $skill->getCriteria(), |
||||
'badge_image' => $skill->getWebIconPath(), |
||||
'courses' => [] |
||||
]; |
||||
|
||||
$badgeAssertions = []; |
||||
|
||||
foreach ($userSkills as $userSkill) { |
||||
$sessionId = 0; |
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $userSkill->getCourseId()); |
||||
$courseName = $course->getTitle(); |
||||
|
||||
if ($userSkill->getSessionId()) { |
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $userSkill->getSessionId()); |
||||
$sessionId = $session->getId(); |
||||
$courseName = "[{$session->getName()}] {$course->getTitle()}"; |
||||
} |
||||
|
||||
$userSkillDate = api_get_local_time($userSkill->getAcquiredSkillAt()); |
||||
$skillInfo['courses'][] = [ |
||||
'name' => $courseName, |
||||
'date_issued' => api_format_date($userSkillDate, DATE_TIME_FORMAT_LONG) |
||||
]; |
||||
|
||||
$assertionUrl = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?"; |
||||
$assertionUrl .= http_build_query(array( |
||||
'user' => $user->getId(), |
||||
'skill' => $skill->getId(), |
||||
'course' => $userSkill->getCourseId(), |
||||
'session' => $userSkill->getSessionId() |
||||
)); |
||||
|
||||
$badgeAssertions[] = $assertionUrl; |
||||
} |
||||
|
||||
$allowExport = api_get_user_id() == $user->getId(); |
||||
|
||||
if ($allowExport) { |
||||
$backpack = 'https://backpack.openbadges.org/'; |
||||
|
||||
$configBackpack = api_get_setting('openbadges_backpack'); |
||||
|
||||
if (strcmp($backpack, $configBackpack) !== 0) { |
||||
$backpack = $configBackpack; |
||||
} |
||||
|
||||
$htmlHeadXtra[] = '<script src="' . $backpack . 'issuer.js"></script>'; |
||||
} |
||||
|
||||
$template = new Template(''); |
||||
$template->assign('skill_info', $skillInfo); |
||||
$template->assign('user_info', $userInfo); |
||||
$template->assign('allow_export', $allowExport); |
||||
|
||||
if ($allowExport) { |
||||
$template->assign('assertions', $badgeAssertions); |
||||
} |
||||
|
||||
$content = $template->fetch( |
||||
$template->get_template('skill/issued.tpl') |
||||
); |
||||
|
||||
$template->assign('header', get_lang('IssuedBadgeInformation')); |
||||
$template->assign('content', $content); |
||||
$template->display_one_col_template(); |
||||
@ -0,0 +1,53 @@ |
||||
<div class="row"> |
||||
<div class="col-md-4"> |
||||
<figure class="thumbnail"> |
||||
<img class="img-responsive" src="{{ skill_info.badge_image }}" alt="{{ skill_info.name }}"> |
||||
<figcaption class="caption text-center"> |
||||
<p class="lead">{{ skill_info.name }}</p> |
||||
</figcaption> |
||||
</figure> |
||||
<h3>{{ 'SkillAcquiredAt'|get_lang }}</h3> |
||||
<ul class="fa-ul"> |
||||
{% for course in skill_info.courses %} |
||||
<li> |
||||
<p> |
||||
<em class="fa fa-clock-o fa-fw"></em> {{ 'TimeXThroughCourseY'|get_lang|format(course.date_issued, course.name) }} |
||||
</p> |
||||
</li> |
||||
{% endfor %} |
||||
</ul> |
||||
{% if allow_export %} |
||||
<p class="text-center"> |
||||
<a href="#" class="btn btn-success" id="badge-export-button"> |
||||
<i class="fa fa-external-link-square fa-fw"></i> {{ 'ExportBadge'|get_lang }} |
||||
</a> |
||||
</p> |
||||
{% endif %} |
||||
</div> |
||||
<div class="col-md-8"> |
||||
<h3>{{ 'RecipientDetails'|get_lang }}</h3> |
||||
<p class="lead">{{ user_info.complete_name }}</p> |
||||
<h3>{{ 'BadgeDetails'|get_lang }}</h3> |
||||
<h3>{{ 'Name'|get_lang }}</h3> |
||||
<p>{{ skill_info.name }}</p> |
||||
{% if skill_info.short_code %} |
||||
<h3>{{ 'ShortCode'|get_lang }}</h3> |
||||
<p>{{ skill_info.short_code }}</p> |
||||
{% endif %} |
||||
<h3>{{ 'Description'|get_lang }}</h3> |
||||
<p>{{ skill_info.description }}</p> |
||||
<h3>{{ 'CriteriaToEarnTheBadge'|get_lang }}</h3> |
||||
<p>{{ skill_info.criteria }}</p> |
||||
</div> |
||||
</div> |
||||
{% if allow_export %} |
||||
<script> |
||||
$(document).on('ready', function () { |
||||
$('#badge-export-button').on('click', function (e) { |
||||
e.preventDefault(); |
||||
|
||||
OpenBadges.issue({{ assertions|json_encode() }}); |
||||
}); |
||||
}); |
||||
</script> |
||||
{% endif %} |
||||
Loading…
Reference in new issue