upgrade
This commit is contained in:
61
main/badge/assertion.php
Normal file
61
main/badge/assertion.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about a new assertion.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$userId = isset($_GET['user']) ? (int) $_GET['user'] : 0;
|
||||
$skillId = isset($_GET['skill']) ? (int) $_GET['skill'] : 0;
|
||||
$courseId = isset($_GET['course']) ? (int) $_GET['course'] : 0;
|
||||
$sessionId = isset($_GET['session']) ? (int) $_GET['session'] : 0;
|
||||
|
||||
if (0 === $userId || 0 === $skillId) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$objSkill = new Skill();
|
||||
if (!$objSkill->userHasSkill($userId, $skillId, $courseId, $sessionId)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$objSkillRelUser = new SkillRelUser();
|
||||
$userSkill = $objSkillRelUser->getByUserAndSkill(
|
||||
$userId,
|
||||
$skillId,
|
||||
$courseId,
|
||||
$sessionId
|
||||
);
|
||||
|
||||
if (false == $userSkill) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = api_get_user_info($userSkill['user_id']);
|
||||
|
||||
$json = [
|
||||
'uid' => $userSkill['id'],
|
||||
'recipient' => [
|
||||
'type' => 'email',
|
||||
'hashed' => false,
|
||||
'identity' => $user['email'],
|
||||
],
|
||||
'issuedOn' => strtotime($userSkill['acquired_skill_at']),
|
||||
'badge' => api_get_path(WEB_CODE_PATH)."badge/class.php?id=$skillId",
|
||||
'verify' => [
|
||||
'type' => 'hosted',
|
||||
'url' => api_get_path(WEB_CODE_PATH)."badge/assertion.php?".http_build_query([
|
||||
'user' => $userId,
|
||||
'skill' => $skillId,
|
||||
'course' => $courseId,
|
||||
'session' => $sessionId,
|
||||
]),
|
||||
],
|
||||
];
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo json_encode($json);
|
||||
432
main/badge/assign.php
Normal file
432
main/badge/assign.php
Normal file
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\Skill;
|
||||
use Skill as SkillManager;
|
||||
|
||||
/**
|
||||
* Page for assign skills to a user.
|
||||
*
|
||||
* @author: Jose Loguercio <jose.loguercio@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$userId = isset($_REQUEST['user']) ? (int) $_REQUEST['user'] : 0;
|
||||
|
||||
if (empty($userId)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
SkillManager::isAllowed($userId);
|
||||
|
||||
$user = api_get_user_entity($userId);
|
||||
|
||||
if (!$user) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
$skillManager = new SkillManager();
|
||||
$skillRepo = $entityManager->getRepository('ChamiloCoreBundle:Skill');
|
||||
$skillRelSkill = $entityManager->getRepository('ChamiloCoreBundle:SkillRelSkill');
|
||||
$skillLevelRepo = $entityManager->getRepository('ChamiloSkillBundle:Level');
|
||||
$skillUserRepo = $entityManager->getRepository('ChamiloCoreBundle:SkillRelUser');
|
||||
|
||||
$skillLevels = api_get_configuration_value('skill_levels_names');
|
||||
|
||||
$skillsOptions = ['' => get_lang('Select')];
|
||||
$acquiredLevel = ['' => get_lang('None')];
|
||||
$formDefaultValues = [];
|
||||
|
||||
if (empty($skillLevels)) {
|
||||
$skills = $skillRepo->findBy([
|
||||
'status' => Skill::STATUS_ENABLED,
|
||||
]);
|
||||
/** @var Skill $skill */
|
||||
foreach ($skills as $skill) {
|
||||
$skillsOptions[$skill->getId()] = $skill->getName();
|
||||
}
|
||||
} else {
|
||||
// Get only root elements
|
||||
$skills = $skillManager->getChildren(1);
|
||||
foreach ($skills as $skill) {
|
||||
$skillsOptions[$skill['data']['id']] = $skill['data']['name'];
|
||||
}
|
||||
}
|
||||
$skillIdFromGet = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
|
||||
$currentValue = isset($_REQUEST['current_value']) ? (int) $_REQUEST['current_value'] : 0;
|
||||
$currentLevel = isset($_REQUEST['current']) ? (int) str_replace('sub_skill_id_', '', $_REQUEST['current']) : 0;
|
||||
|
||||
$subSkillList = isset($_REQUEST['sub_skill_list']) ? explode(',', $_REQUEST['sub_skill_list']) : [];
|
||||
$subSkillList = array_unique($subSkillList);
|
||||
|
||||
if (!empty($subSkillList)) {
|
||||
// Compare asked skill with current level
|
||||
$correctLevel = false;
|
||||
if (isset($subSkillList[$currentLevel]) && $subSkillList[$currentLevel] == $currentValue) {
|
||||
$correctLevel = true;
|
||||
}
|
||||
|
||||
// Level is wrong probably user change the level. Fix the subSkillList array
|
||||
if (!$correctLevel) {
|
||||
$newSubSkillList = [];
|
||||
$counter = 0;
|
||||
foreach ($subSkillList as $subSkillId) {
|
||||
if ($counter == $currentLevel) {
|
||||
$subSkillId = $currentValue;
|
||||
}
|
||||
$newSubSkillList[$counter] = $subSkillId;
|
||||
if ($counter == $currentLevel) {
|
||||
break;
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
$subSkillList = $newSubSkillList;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($currentLevel)) {
|
||||
$level = $currentLevel + 1;
|
||||
if ($level < count($subSkillList)) {
|
||||
$remove = count($subSkillList) - $currentLevel;
|
||||
$newSubSkillList = array_slice($subSkillList, 0, count($subSkillList) - $level);
|
||||
$subSkillList = $newSubSkillList;
|
||||
}
|
||||
}
|
||||
|
||||
$skillId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : key($skillsOptions);
|
||||
$skill = $skillRepo->find($skillId);
|
||||
$profile = false;
|
||||
if ($skill) {
|
||||
$profile = $skill->getProfile();
|
||||
}
|
||||
|
||||
if (!empty($subSkillList)) {
|
||||
$skillFromLastSkill = $skillRepo->find(end($subSkillList));
|
||||
if ($skillFromLastSkill) {
|
||||
$profile = $skillFromLastSkill->getProfile();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$profile) {
|
||||
$skillRelSkill = new SkillRelSkill();
|
||||
$parents = $skillRelSkill->getSkillParents($skillId);
|
||||
krsort($parents);
|
||||
foreach ($parents as $parent) {
|
||||
$skillParentId = $parent['skill_id'];
|
||||
$profile = $skillRepo->find($skillParentId)->getProfile();
|
||||
|
||||
if ($profile) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$profile && $parent['parent_id'] == 0) {
|
||||
$profile = $skillLevelRepo->findAll();
|
||||
$profile = isset($profile[0]) ? $profile[0] : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($profile) {
|
||||
$profileId = $profile->getId();
|
||||
$levels = $skillLevelRepo->findBy([
|
||||
'profile' => $profileId,
|
||||
]);
|
||||
$profileLevels = [];
|
||||
foreach ($levels as $level) {
|
||||
$profileLevels[$level->getPosition()][$level->getId()] = $level->getName();
|
||||
}
|
||||
|
||||
ksort($profileLevels); // Sort the array by Position.
|
||||
|
||||
foreach ($profileLevels as $profileLevel) {
|
||||
$profileId = key($profileLevel);
|
||||
$acquiredLevel[$profileId] = $profileLevel[$profileId];
|
||||
}
|
||||
}
|
||||
|
||||
$formDefaultValues = ['skill' => $skillId];
|
||||
$newSubSkillList = [];
|
||||
$disableList = [];
|
||||
|
||||
$currentUrl = api_get_self().'?user='.$userId.'¤t='.$currentLevel;
|
||||
|
||||
$form = new FormValidator('assign_skill', 'POST', $currentUrl);
|
||||
$form->addHeader(get_lang('AssignSkill'));
|
||||
$form->addText('user_name', get_lang('UserName'), false);
|
||||
|
||||
$levelName = get_lang('Skill');
|
||||
if (!empty($skillLevels)) {
|
||||
if (isset($skillLevels['levels'][1])) {
|
||||
$levelName = get_lang($skillLevels['levels'][1]);
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelect('skill', $levelName, $skillsOptions, ['id' => 'skill']);
|
||||
|
||||
if (!empty($skillIdFromGet)) {
|
||||
if (empty($subSkillList)) {
|
||||
$subSkillList[] = $skillIdFromGet;
|
||||
}
|
||||
$oldSkill = $skillRepo->find($skillIdFromGet);
|
||||
$counter = 0;
|
||||
foreach ($subSkillList as $subSkillId) {
|
||||
$children = $skillManager->getChildren($subSkillId);
|
||||
|
||||
if (isset($subSkillList[$counter - 1])) {
|
||||
$oldSkill = $skillRepo->find($subSkillList[$counter]);
|
||||
}
|
||||
$skillsOptions = [];
|
||||
if ($oldSkill) {
|
||||
$skillsOptions = [$oldSkill->getId() => ' -- '.$oldSkill->getName()];
|
||||
}
|
||||
|
||||
if ($counter < count($subSkillList) - 1) {
|
||||
$disableList[] = 'sub_skill_id_'.($counter + 1);
|
||||
}
|
||||
|
||||
foreach ($children as $child) {
|
||||
$skillsOptions[$child['id']] = $child['data']['name'];
|
||||
}
|
||||
|
||||
$levelName = get_lang('SubSkill');
|
||||
if (!empty($skillLevels)) {
|
||||
if (isset($skillLevels['levels'][$counter + 2])) {
|
||||
$levelName = get_lang($skillLevels['levels'][$counter + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
$form->addSelect(
|
||||
'sub_skill_id_'.($counter + 1),
|
||||
$levelName,
|
||||
$skillsOptions,
|
||||
[
|
||||
'id' => 'sub_skill_id_'.($counter + 1),
|
||||
'class' => 'sub_skill',
|
||||
]
|
||||
);
|
||||
|
||||
if (isset($subSkillList[$counter + 1])) {
|
||||
$nextSkill = $skillRepo->find($subSkillList[$counter + 1]);
|
||||
if ($nextSkill) {
|
||||
$formDefaultValues['sub_skill_id_'.($counter + 1)] = $nextSkill->getId();
|
||||
}
|
||||
}
|
||||
$newSubSkillList[] = $subSkillId;
|
||||
$counter++;
|
||||
}
|
||||
$subSkillList = $newSubSkillList;
|
||||
}
|
||||
|
||||
$subSkillListToString = implode(',', $subSkillList);
|
||||
|
||||
$currentUrl = api_get_self().'?user='.$userId.'¤t='.$currentLevel.'&sub_skill_list='.$subSkillListToString;
|
||||
|
||||
$form->addHidden('sub_skill_list', $subSkillListToString);
|
||||
$form->addHidden('user', $user->getId());
|
||||
$form->addHidden('id', $skillId);
|
||||
$form->addRule('skill', get_lang('ThisFieldIsRequired'), 'required');
|
||||
|
||||
$showLevels = api_get_configuration_value('hide_skill_levels') === false;
|
||||
|
||||
if ($showLevels) {
|
||||
$form->addSelect('acquired_level', get_lang('AcquiredLevel'), $acquiredLevel);
|
||||
//$form->addRule('acquired_level', get_lang('ThisFieldIsRequired'), 'required');
|
||||
}
|
||||
|
||||
$form->addTextarea('argumentation', get_lang('Argumentation'), ['rows' => 6]);
|
||||
$form->addRule('argumentation', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addRule(
|
||||
'argumentation',
|
||||
sprintf(get_lang('ThisTextShouldBeAtLeastXCharsLong'), 10),
|
||||
'mintext',
|
||||
10
|
||||
);
|
||||
$form->applyFilter('argumentation', 'trim');
|
||||
$form->addButtonSave(get_lang('Save'));
|
||||
$form->setDefaults($formDefaultValues);
|
||||
|
||||
if ($form->validate()) {
|
||||
$values = $form->exportValues();
|
||||
$skillToProcess = $values['id'];
|
||||
if (!empty($subSkillList)) {
|
||||
$counter = 1;
|
||||
foreach ($subSkillList as $subSkill) {
|
||||
if (isset($values["sub_skill_id_$counter"])) {
|
||||
$skillToProcess = $values["sub_skill_id_$counter"];
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$skill = $skillRepo->find($skillToProcess);
|
||||
|
||||
if (!$skill) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('SkillNotFound'), 'error')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_self().'?'.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($user->hasSkill($skill)) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('TheUserXHasAlreadyAchievedTheSkillY'),
|
||||
UserManager::formatUserFullName($user),
|
||||
$skill->getName()
|
||||
),
|
||||
'warning'
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.$currentUrl);
|
||||
exit;
|
||||
}
|
||||
|
||||
$skillUser = $skillManager->addSkillToUserBadge(
|
||||
$user,
|
||||
$skill,
|
||||
$values['acquired_level'],
|
||||
$values['argumentation'],
|
||||
api_get_user_id()
|
||||
);
|
||||
|
||||
// Send email depending of children_auto_threshold
|
||||
$skillRelSkill = new SkillRelSkill();
|
||||
$skillModel = new \Skill();
|
||||
$parents = $skillModel->getDirectParents($skillToProcess);
|
||||
|
||||
$extraFieldValue = new ExtraFieldValue('skill');
|
||||
foreach ($parents as $parentInfo) {
|
||||
$parentId = $parentInfo['skill_id'];
|
||||
$parentData = $skillModel->get($parentId);
|
||||
|
||||
$data = $extraFieldValue->get_values_by_handler_and_field_variable($parentId, 'children_auto_threshold');
|
||||
if (!empty($data) && !empty($data['value'])) {
|
||||
// Search X children
|
||||
$requiredSkills = $data['value'];
|
||||
$children = $skillRelSkill->getChildren($parentId);
|
||||
$counter = 0;
|
||||
foreach ($children as $child) {
|
||||
if ($skillModel->userHasSkill($userId, $child['id'])) {
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($counter >= $requiredSkills) {
|
||||
$bossList = UserManager::getStudentBossList($userId);
|
||||
if (!empty($bossList)) {
|
||||
Display::addFlash(Display::return_message(get_lang('MessageSent')));
|
||||
$url = api_get_path(WEB_CODE_PATH).'badge/assign.php?user='.$userId.'&id='.$parentId;
|
||||
$link = Display::url($url, $url);
|
||||
$subject = get_lang('StudentHadEnoughSkills');
|
||||
$message = sprintf(
|
||||
get_lang('StudentXHadEnoughSkillsToGetSkillXToAssignClickHereX'),
|
||||
UserManager::formatUserFullName($user),
|
||||
$parentData['name'],
|
||||
$link
|
||||
);
|
||||
foreach ($bossList as $boss) {
|
||||
MessageManager::send_message_simple(
|
||||
$boss['boss_id'],
|
||||
$subject,
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('SkillXAssignedToUserY'),
|
||||
$skill->getName(),
|
||||
UserManager::formatUserFullName($user)
|
||||
),
|
||||
'success'
|
||||
)
|
||||
);
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
sprintf(
|
||||
get_lang('ToAssignNewSkillToUserClickLinkX'),
|
||||
api_get_self().'?'.http_build_query(['user' => $user->getId()])
|
||||
),
|
||||
'info',
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PATH)."badge/{$skillUser->getId()}");
|
||||
exit;
|
||||
}
|
||||
|
||||
$form->setDefaults(['user_name' => UserManager::formatUserFullName($user, true)]);
|
||||
$form->freeze(['user_name']);
|
||||
|
||||
if (api_is_drh()) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'mySpace/index.php',
|
||||
"name" => get_lang('MySpace'),
|
||||
];
|
||||
if ($user->getStatus() == COURSEMANAGER) {
|
||||
$interbreadcrumb[] = [
|
||||
"url" => api_get_path(WEB_CODE_PATH).'mySpace/teachers.php',
|
||||
'name' => get_lang('Teachers'),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
"url" => api_get_path(WEB_CODE_PATH).'mySpace/student.php',
|
||||
'name' => get_lang('MyStudents'),
|
||||
];
|
||||
}
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userId,
|
||||
'name' => UserManager::formatUserFullName($user),
|
||||
];
|
||||
} else {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
|
||||
'name' => get_lang('PlatformAdmin'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/user_list.php',
|
||||
'name' => get_lang('UserList'),
|
||||
];
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$userId,
|
||||
'name' => UserManager::formatUserFullName($user),
|
||||
];
|
||||
}
|
||||
|
||||
$url = api_get_path(WEB_CODE_PATH).'badge/assign.php?user='.$userId;
|
||||
|
||||
$disableSelect = '';
|
||||
if ($disableList) {
|
||||
foreach ($disableList as $name) {
|
||||
//$disableSelect .= "$('#".$name."').prop('disabled', true);";
|
||||
//$disableSelect .= "$('#".$name."').selectpicker('refresh');";
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '<script>
|
||||
$(function() {
|
||||
$("#skill").on("change", function() {
|
||||
$(location).attr("href", "'.$url.'&id="+$(this).val());
|
||||
});
|
||||
$(".sub_skill").on("change", function() {
|
||||
$(location).attr("href", "'.$url.'&id='.$skillIdFromGet.'¤t_value="+$(this).val()+"¤t="+$(this).attr("id")+"&sub_skill_list='.$subSkillListToString.',"+$(this).val());
|
||||
});
|
||||
'.$disableSelect.'
|
||||
});
|
||||
</script>';
|
||||
|
||||
$template = new Template(get_lang('AddSkill'));
|
||||
$template->assign('content', $form->returnForm());
|
||||
$template->display_one_col_template();
|
||||
28
main/badge/class.php
Normal file
28
main/badge/class.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about the OpenBadge class.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$skillId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
$objSkill = new Skill();
|
||||
$skill = $objSkill->get($skillId);
|
||||
$json = [];
|
||||
|
||||
if ($skill) {
|
||||
$json = [
|
||||
'name' => $skill['name'],
|
||||
'description' => $skill['description'],
|
||||
'image' => api_get_path(WEB_UPLOAD_PATH)."badges/{$skill['icon']}",
|
||||
'criteria' => api_get_path(WEB_CODE_PATH)."badge/criteria.php?id=$skillId",
|
||||
'issuer' => api_get_path(WEB_CODE_PATH).'badge/issuer.php',
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo json_encode($json);
|
||||
47
main/badge/criteria.php
Normal file
47
main/badge/criteria.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about OpenBadge criteria.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$skillId = isset($_GET['id']) ? $_GET['id'] : 0;
|
||||
|
||||
if (empty($skillId)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
/** @var \Chamilo\CoreBundle\Entity\Skill $skill */
|
||||
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $_GET['id']);
|
||||
|
||||
if ($skill) {
|
||||
$skillInfo = [
|
||||
'name' => $skill->getName(),
|
||||
'short_code' => $skill->getShortCode(),
|
||||
'description' => $skill->getDescription(),
|
||||
'criteria' => $skill->getCriteria(),
|
||||
'badge_image' => Skill::getWebIconPath($skill),
|
||||
];
|
||||
|
||||
$template = new Template();
|
||||
$template->assign('skill_info', $skillInfo);
|
||||
|
||||
$content = $template->fetch(
|
||||
$template->get_template('skill/criteria.tpl')
|
||||
);
|
||||
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
exit;
|
||||
}
|
||||
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('SkillNotFound'), 'error')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PATH));
|
||||
exit;
|
||||
311
main/badge/issued.php
Normal file
311
main/badge/issued.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\SkillRelUser;
|
||||
use Chamilo\CoreBundle\Entity\SkillRelUserComment;
|
||||
use SkillRelUser as SkillRelUserManager;
|
||||
|
||||
/**
|
||||
* Show information about the issued badge.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$issue = isset($_REQUEST['issue']) ? (int) $_REQUEST['issue'] : 0;
|
||||
|
||||
if (empty($issue)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$entityManager = Database::getManager();
|
||||
/** @var SkillRelUser $skillIssue */
|
||||
$skillIssue = $entityManager->find('ChamiloCoreBundle:SkillRelUser', $issue);
|
||||
|
||||
if (!$skillIssue) {
|
||||
Display::addFlash(
|
||||
Display::return_message(
|
||||
get_lang('SkillNotFound'),
|
||||
'warning'
|
||||
)
|
||||
);
|
||||
header('Location: '.api_get_path(WEB_PATH));
|
||||
exit;
|
||||
}
|
||||
|
||||
$skillRepo = $entityManager->getRepository('ChamiloCoreBundle:Skill');
|
||||
$skillLevelRepo = $entityManager->getRepository('ChamiloSkillBundle:Level');
|
||||
|
||||
$user = $skillIssue->getUser();
|
||||
$skill = $skillIssue->getSkill();
|
||||
|
||||
if (!$user || !$skill) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('NoResults'), 'warning')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PATH));
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!Skill::isToolAvailable()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$showLevels = api_get_configuration_value('hide_skill_levels') === false;
|
||||
|
||||
$skillInfo = [
|
||||
'id' => $skill->getId(),
|
||||
'name' => $skill->getName(),
|
||||
'short_code' => $skill->getShortCode(),
|
||||
'description' => $skill->getDescription(),
|
||||
'criteria' => $skill->getCriteria(),
|
||||
'badge_image' => Skill::getWebIconPath($skill),
|
||||
'courses' => [],
|
||||
];
|
||||
|
||||
$titleContent = sprintf(get_lang('IHaveObtainedSkillXOnY'), $skillInfo['name'], api_get_setting('siteName'));
|
||||
|
||||
// Open Graph Markup
|
||||
$htmlHeadXtra[] = "
|
||||
<meta property='og:type' content='article' />
|
||||
<meta property='og:title' content='".$titleContent."' />
|
||||
<meta property='og:url' content='".api_get_path(WEB_PATH)."badge/".$issue."' />
|
||||
<meta property='og:description' content='".$skillInfo['description']."' />
|
||||
<meta property='og:image' content='".$skillInfo['badge_image']."' />
|
||||
";
|
||||
|
||||
$currentUserId = api_get_user_id();
|
||||
$currentUser = api_get_user_entity($currentUserId);
|
||||
$allowExport = $currentUser ? $currentUser->getId() === $user->getId() : false;
|
||||
|
||||
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $user) : false;
|
||||
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
|
||||
$currentSkillLevel = get_lang('NoLevelAcquiredYet');
|
||||
if ($skillIssue->getAcquiredLevel()) {
|
||||
$currentSkillLevel = $skillLevelRepo->find(['id' => $skillIssue->getAcquiredLevel()])->getName();
|
||||
}
|
||||
|
||||
$author = api_get_user_info($skillIssue->getArgumentationAuthorId());
|
||||
$tempDate = DateTime::createFromFormat('Y-m-d H:i:s', $skillIssueDate);
|
||||
$linkedinOrganizationId = api_get_configuration_value('linkedin_organization_id');
|
||||
if (($linkedinOrganizationId === false)) {
|
||||
$linkedinOrganizationId = null;
|
||||
}
|
||||
|
||||
$skillIssueInfo = [
|
||||
'id' => $skillIssue->getId(),
|
||||
'datetime' => api_format_date($skillIssueDate, DATE_TIME_FORMAT_SHORT),
|
||||
'year' => $tempDate->format('Y'),
|
||||
'month' => $tempDate->format('m'),
|
||||
'linkedin_organization_id' => $linkedinOrganizationId,
|
||||
'acquired_level' => $currentSkillLevel,
|
||||
'argumentation_author_id' => $skillIssue->getArgumentationAuthorId(),
|
||||
'argumentation_author_name' => $author['complete_name'],
|
||||
'argumentation' => $skillIssue->getArgumentation(),
|
||||
'source_name' => $skillIssue->getSourceName(),
|
||||
'user_id' => $skillIssue->getUser()->getId(),
|
||||
'user_complete_name' => UserManager::formatUserFullName($skillIssue->getUser()),
|
||||
'skill_id' => $skillIssue->getSkill()->getId(),
|
||||
'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()),
|
||||
'skill_name' => $skillIssue->getSkill()->getName(),
|
||||
'skill_short_code' => $skillIssue->getSkill()->getShortCode(),
|
||||
'skill_description' => $skillIssue->getSkill()->getDescription(),
|
||||
'skill_criteria' => $skillIssue->getSkill()->getCriteria(),
|
||||
'badge_assertion' => SkillRelUserManager::getAssertionUrl($skillIssue),
|
||||
'comments' => [],
|
||||
'feedback_average' => $skillIssue->getAverage(),
|
||||
];
|
||||
|
||||
$skillIssueComments = $skillIssue->getComments(true);
|
||||
|
||||
$userId = $skillIssueInfo['user_id'];
|
||||
$skillId = $skillIssueInfo['skill_id'];
|
||||
|
||||
/** @var SkillRelUserComment $comment */
|
||||
foreach ($skillIssueComments as $comment) {
|
||||
$commentDate = api_get_local_time($comment->getFeedbackDateTime());
|
||||
$skillIssueInfo['comments'][] = [
|
||||
'text' => $comment->getFeedbackText(),
|
||||
'value' => $comment->getFeedbackValue(),
|
||||
'giver_complete_name' => UserManager::formatUserFullName($comment->getFeedbackGiver()),
|
||||
'datetime' => api_format_date($commentDate, DATE_TIME_FORMAT_SHORT),
|
||||
];
|
||||
}
|
||||
|
||||
$acquiredLevel = [];
|
||||
$profile = $skillRepo->find($skillId)->getProfile();
|
||||
|
||||
if (!$profile) {
|
||||
$skillRelSkill = new SkillRelSkill();
|
||||
$parents = $skillRelSkill->getSkillParents($skillId);
|
||||
|
||||
krsort($parents);
|
||||
|
||||
foreach ($parents as $parent) {
|
||||
$skillParentId = $parent['skill_id'];
|
||||
$profile = $skillRepo->find($skillParentId)->getProfile();
|
||||
|
||||
if ($profile) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$profile && $parent['parent_id'] == 0) {
|
||||
$profile = $skillLevelRepo->findAll();
|
||||
if ($profile) {
|
||||
$profile = $profile[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($profile) {
|
||||
$profileId = $profile->getId();
|
||||
$levels = $skillLevelRepo->findBy([
|
||||
'profile' => $profileId,
|
||||
]);
|
||||
|
||||
$profileLevels = [];
|
||||
foreach ($levels as $level) {
|
||||
$profileLevels[$level->getPosition()][$level->getId()] = $level->getName();
|
||||
}
|
||||
|
||||
ksort($profileLevels); // Sort the array by Position.
|
||||
foreach ($profileLevels as $profileLevel) {
|
||||
$profileId = key($profileLevel);
|
||||
$acquiredLevel[$profileId] = $profileLevel[$profileId];
|
||||
}
|
||||
}
|
||||
|
||||
$allowToEdit = Skill::isAllowed($user->getId(), false);
|
||||
|
||||
if ($showLevels && $allowToEdit) {
|
||||
$formAcquiredLevel = new FormValidator('acquired_level');
|
||||
$formAcquiredLevel->addSelect('acquired_level', get_lang('AcquiredLevel'), $acquiredLevel);
|
||||
$formAcquiredLevel->addHidden('user', $skillIssue->getUser()->getId());
|
||||
$formAcquiredLevel->addHidden('issue', $skillIssue->getId());
|
||||
$formAcquiredLevel->addButtonSave(get_lang('Save'));
|
||||
|
||||
if ($formAcquiredLevel->validate() && $allowComment) {
|
||||
$values = $formAcquiredLevel->exportValues();
|
||||
$level = $skillLevelRepo->find($values['acquired_level']);
|
||||
$skillIssue->setAcquiredLevel($level);
|
||||
|
||||
$entityManager->persist($skillIssue);
|
||||
$entityManager->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Saved')));
|
||||
|
||||
header('Location: '.SkillRelUserManager::getIssueUrl($skillIssue));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$form = new FormValidator('comment');
|
||||
$form->addTextarea('comment', get_lang('NewComment'), ['rows' => 4]);
|
||||
$form->applyFilter('comment', 'trim');
|
||||
$form->addRule('comment', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addSelect(
|
||||
'value',
|
||||
[get_lang('Value'), get_lang('RateTheSkillInPractice')],
|
||||
['-', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
$form->addHidden('user', $skillIssue->getUser()->getId());
|
||||
$form->addHidden('issue', $skillIssue->getId());
|
||||
$form->addButtonSend(get_lang('Send'));
|
||||
|
||||
if ($form->validate() && $allowComment && $allowToEdit) {
|
||||
$values = $form->exportValues();
|
||||
$skillUserComment = new SkillRelUserComment();
|
||||
$skillUserComment
|
||||
->setFeedbackDateTime(new DateTime())
|
||||
->setFeedbackGiver($currentUser)
|
||||
->setFeedbackText($values['comment'])
|
||||
->setFeedbackValue($values['value'] ? $values['value'] : null)
|
||||
->setSkillRelUser($skillIssue)
|
||||
;
|
||||
|
||||
$entityManager->persist($skillUserComment);
|
||||
$entityManager->flush();
|
||||
Display::addFlash(Display::return_message(get_lang('Added')));
|
||||
|
||||
header('Location: '.SkillRelUserManager::getIssueUrl($skillIssue));
|
||||
exit;
|
||||
}
|
||||
|
||||
$badgeInfoError = '';
|
||||
$personalBadge = '';
|
||||
if ($allowExport) {
|
||||
$backpack = 'https://backpack.openbadges.org/';
|
||||
$configBackpack = api_get_setting('openbadges_backpack');
|
||||
|
||||
if (0 !== strcmp($backpack, $configBackpack)) {
|
||||
$backpack = $configBackpack;
|
||||
if (substr($backpack, -1) !== '/') {
|
||||
$backpack .= '/';
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '<script src="'.$backpack.'issuer.js"></script>';
|
||||
$objSkill = new Skill();
|
||||
$assertionUrl = $skillIssueInfo['badge_assertion'];
|
||||
$skills = $objSkill->get($skillId);
|
||||
$unbakedBadge = api_get_path(SYS_UPLOAD_PATH).'badges/'.$skills['icon'];
|
||||
if (!is_file($unbakedBadge)) {
|
||||
$unbakedBadge = api_get_path(SYS_CODE_PATH).'img/icons/128/badges-default.png';
|
||||
}
|
||||
|
||||
$unbakedBadge = file_get_contents($unbakedBadge);
|
||||
$badgeInfoError = false;
|
||||
$personalBadge = '';
|
||||
$png = new PNGImageBaker($unbakedBadge);
|
||||
|
||||
if ($png->checkChunks("tEXt", "openbadges")) {
|
||||
$bakedInfo = $png->addChunk("tEXt", "openbadges", $assertionUrl);
|
||||
$bakedBadge = UserManager::getUserPathById($userId, "system");
|
||||
$bakedBadge = $bakedBadge.'badges';
|
||||
if (!file_exists($bakedBadge)) {
|
||||
mkdir($bakedBadge, api_get_permissions_for_new_directories(), true);
|
||||
}
|
||||
$skillRelUserId = $skillIssueInfo['id'];
|
||||
if (!file_exists($bakedBadge."/badge_".$skillRelUserId)) {
|
||||
file_put_contents($bakedBadge."/badge_".$skillRelUserId.".png", $bakedInfo);
|
||||
}
|
||||
|
||||
// Process to validate a baked badge
|
||||
$badgeContent = file_get_contents($bakedBadge."/badge_".$skillRelUserId.".png");
|
||||
$verifyBakedBadge = $png->extractBadgeInfo($badgeContent);
|
||||
if (!is_array($verifyBakedBadge)) {
|
||||
$badgeInfoError = true;
|
||||
}
|
||||
|
||||
if (!$badgeInfoError) {
|
||||
$personalBadge = UserManager::getUserPathById($userId, 'web');
|
||||
$personalBadge = $personalBadge."badges/badge_".$skillRelUserId.".png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$template = new Template(get_lang('IssuedBadgeInformation'));
|
||||
$template->assign('issue_info', $skillIssueInfo);
|
||||
$template->assign('allow_comment', $allowComment);
|
||||
$template->assign('allow_export', $allowExport);
|
||||
|
||||
$commentForm = '';
|
||||
if ($allowComment && $allowToEdit) {
|
||||
$commentForm = $form->returnForm();
|
||||
}
|
||||
$template->assign('comment_form', $commentForm);
|
||||
|
||||
$levelForm = '';
|
||||
if ($showLevels && $allowToEdit) {
|
||||
$levelForm = $formAcquiredLevel->returnForm();
|
||||
}
|
||||
$template->assign('acquired_level_form', $levelForm);
|
||||
$template->assign('badge_error', $badgeInfoError);
|
||||
$template->assign('personal_badge', $personalBadge);
|
||||
$template->assign('show_level', $showLevels);
|
||||
$content = $template->fetch($template->get_template('skill/issued.tpl'));
|
||||
$template->assign('header', get_lang('IssuedBadgeInformation'));
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
296
main/badge/issued_all.php
Normal file
296
main/badge/issued_all.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\CoreBundle\Entity\SkillRelUser;
|
||||
use Chamilo\CoreBundle\Entity\SkillRelUserComment;
|
||||
use SkillRelUser as SkillRelUserManager;
|
||||
|
||||
/**
|
||||
* Show information about all issued badges with same skill by user.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$userId = isset($_GET['user']) ? (int) $_GET['user'] : 0;
|
||||
$skillId = isset($_GET['skill']) ? (int) $_GET['skill'] : 0;
|
||||
|
||||
if (!$userId || !$skillId) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
Skill::isAllowed($userId);
|
||||
|
||||
$em = Database::getManager();
|
||||
$user = api_get_user_entity($userId);
|
||||
$skill = $em->find('ChamiloCoreBundle:Skill', $skillId);
|
||||
$currentUserId = api_get_user_id();
|
||||
|
||||
if (!$user || !$skill) {
|
||||
Display::addFlash(
|
||||
Display::return_message(get_lang('NoResults'), 'error')
|
||||
);
|
||||
|
||||
header('Location: '.api_get_path(WEB_PATH));
|
||||
exit;
|
||||
}
|
||||
|
||||
$skillRepo = $em->getRepository('ChamiloCoreBundle:Skill');
|
||||
$skillUserRepo = $em->getRepository('ChamiloCoreBundle:SkillRelUser');
|
||||
$skillLevelRepo = $em->getRepository('ChamiloSkillBundle:Level');
|
||||
|
||||
$userSkills = $skillUserRepo->findBy([
|
||||
'user' => $user,
|
||||
'skill' => $skill,
|
||||
]);
|
||||
|
||||
$userInfo = [
|
||||
'id' => $user->getId(),
|
||||
'complete_name' => UserManager::formatUserFullName($user),
|
||||
];
|
||||
|
||||
$skillInfo = [
|
||||
'id' => $skill->getId(),
|
||||
'name' => $skill->getName(),
|
||||
'short_code' => $skill->getShortCode(),
|
||||
'description' => $skill->getDescription(),
|
||||
'criteria' => $skill->getCriteria(),
|
||||
'badge_image' => Skill::getWebIconPath($skill),
|
||||
'courses' => [],
|
||||
];
|
||||
|
||||
$allUserBadges = [];
|
||||
/** @var SkillRelUser $skillIssue */
|
||||
foreach ($userSkills as $index => $skillIssue) {
|
||||
$currentUser = api_get_user_entity($currentUserId);
|
||||
$allowDownloadExport = $currentUser ? $currentUser->getId() === $user->getId() : false;
|
||||
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $user) : false;
|
||||
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
|
||||
$currentSkillLevel = get_lang('NoLevelAcquiredYet');
|
||||
if ($skillIssue->getAcquiredLevel()) {
|
||||
$currentSkillLevel = $skillLevelRepo->find(['id' => $skillIssue->getAcquiredLevel()])->getName();
|
||||
}
|
||||
$argumentationAuthor = api_get_user_info($skillIssue->getArgumentationAuthorId());
|
||||
|
||||
$tempDate = DateTime::createFromFormat('Y-m-d H:i:s', $skillIssueDate);
|
||||
$linkedinOrganizationId = api_get_configuration_value('linkedin_organization_id');
|
||||
if (($linkedinOrganizationId === false)) {
|
||||
$linkedinOrganizationId = null;
|
||||
}
|
||||
|
||||
$skillIssueInfo = [
|
||||
'id' => $skillIssue->getId(),
|
||||
'datetime' => api_format_date($skillIssueDate, DATE_TIME_FORMAT_SHORT),
|
||||
'year' => $tempDate->format('Y'),
|
||||
'month' => $tempDate->format('m'),
|
||||
'linkedin_organization_id' => $linkedinOrganizationId,
|
||||
'acquired_level' => $currentSkillLevel,
|
||||
'argumentation_author_id' => $skillIssue->getArgumentationAuthorId(),
|
||||
'argumentation_author_name' => api_get_person_name(
|
||||
$argumentationAuthor['firstname'],
|
||||
$argumentationAuthor['lastname']
|
||||
),
|
||||
'argumentation' => $skillIssue->getArgumentation(),
|
||||
'source_name' => $skillIssue->getSourceName(),
|
||||
'user_id' => $skillIssue->getUser()->getId(),
|
||||
'user_complete_name' => UserManager::formatUserFullName($skillIssue->getUser()),
|
||||
'skill_id' => $skillIssue->getSkill()->getId(),
|
||||
'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()),
|
||||
'skill_name' => $skillIssue->getSkill()->getName(),
|
||||
'skill_short_code' => $skillIssue->getSkill()->getShortCode(),
|
||||
'skill_description' => $skillIssue->getSkill()->getDescription(),
|
||||
'skill_criteria' => $skillIssue->getSkill()->getCriteria(),
|
||||
'badge_assertion' => SkillRelUserManager::getAssertionUrl($skillIssue),
|
||||
'comments' => [],
|
||||
'feedback_average' => $skillIssue->getAverage(),
|
||||
];
|
||||
|
||||
$skillIssueComments = $skillIssue->getComments(true);
|
||||
|
||||
$userId = $skillIssueInfo['user_id'];
|
||||
$skillId = $skillIssueInfo['skill_id'];
|
||||
|
||||
foreach ($skillIssueComments as $comment) {
|
||||
$commentDate = api_get_local_time($comment->getFeedbackDateTime());
|
||||
$skillIssueInfo['comments'][] = [
|
||||
'text' => $comment->getFeedbackText(),
|
||||
'value' => $comment->getFeedbackValue(),
|
||||
'giver_complete_name' => UserManager::formatUserFullName($comment->getFeedbackGiver()),
|
||||
'datetime' => api_format_date($commentDate, DATE_TIME_FORMAT_SHORT),
|
||||
];
|
||||
}
|
||||
|
||||
$acquiredLevel = [];
|
||||
$profile = $skillRepo->find($skillId)->getProfile();
|
||||
|
||||
if (!$profile) {
|
||||
$skillRelSkill = new SkillRelSkill();
|
||||
$parents = $skillRelSkill->getSkillParents($skillId);
|
||||
|
||||
krsort($parents);
|
||||
|
||||
foreach ($parents as $parent) {
|
||||
$skillParentId = $parent['skill_id'];
|
||||
$profile = $skillRepo->find($skillParentId)->getProfile();
|
||||
|
||||
if ($profile) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$profile && $parent['parent_id'] == 0) {
|
||||
$profile = $skillLevelRepo->findAll();
|
||||
$profile = !empty($profile) ? $profile[0] : [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($profile) {
|
||||
$profileId = $profile->getId();
|
||||
$levels = $skillLevelRepo->findBy([
|
||||
'profile' => $profileId,
|
||||
]);
|
||||
|
||||
foreach ($levels as $level) {
|
||||
$profileLevels[$level->getPosition()][$level->getId()] = $level->getName();
|
||||
}
|
||||
|
||||
ksort($profileLevels); // Sort the array by Position.
|
||||
|
||||
foreach ($profileLevels as $profileLevel) {
|
||||
$profileId = key($profileLevel);
|
||||
$acquiredLevel[$profileId] = $profileLevel[$profileId];
|
||||
}
|
||||
}
|
||||
|
||||
$formAcquiredLevel = new FormValidator(
|
||||
'acquired_level'.$skillIssue->getId(),
|
||||
'post',
|
||||
SkillRelUserManager::getIssueUrlAll($skillIssue)
|
||||
);
|
||||
$formAcquiredLevel->addSelect('acquired_level', get_lang('AcquiredLevel'), $acquiredLevel);
|
||||
$formAcquiredLevel->addHidden('user', $skillIssue->getUser()->getId());
|
||||
$formAcquiredLevel->addHidden('issue', $skillIssue->getId());
|
||||
$formAcquiredLevel->addButtonSend(get_lang('Save'));
|
||||
|
||||
if ($formAcquiredLevel->validate() && $allowComment) {
|
||||
$values = $formAcquiredLevel->exportValues();
|
||||
|
||||
$level = $skillLevelRepo->find($values['acquired_level']);
|
||||
$skillIssue->setAcquiredLevel($level);
|
||||
|
||||
$em->persist($skillIssue);
|
||||
$em->flush();
|
||||
|
||||
header('Location: '.SkillRelUserManager::getIssueUrlAll($skillIssue));
|
||||
exit;
|
||||
}
|
||||
|
||||
$form = new FormValidator(
|
||||
'comment'.$skillIssue->getId(),
|
||||
'post',
|
||||
SkillRelUserManager::getIssueUrlAll($skillIssue)
|
||||
);
|
||||
$form->addTextarea('comment', get_lang('NewComment'), ['rows' => 4]);
|
||||
$form->applyFilter('comment', 'trim');
|
||||
$form->addRule('comment', get_lang('ThisFieldIsRequired'), 'required');
|
||||
$form->addSelect(
|
||||
'value',
|
||||
[get_lang('Value'), get_lang('RateTheSkillInPractice')],
|
||||
['-', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
);
|
||||
$form->addHidden('user', $skillIssue->getUser()->getId());
|
||||
$form->addHidden('issue', $skillIssue->getId());
|
||||
$form->addButtonSend(get_lang('Send'));
|
||||
|
||||
if ($form->validate() && $allowComment) {
|
||||
$values = $form->exportValues();
|
||||
|
||||
$skillUserComment = new SkillRelUserComment();
|
||||
$skillUserComment
|
||||
->setFeedbackDateTime(new DateTime())
|
||||
->setFeedbackGiver($currentUser)
|
||||
->setFeedbackText($values['comment'])
|
||||
->setFeedbackValue($values['value'] ? $values['value'] : null)
|
||||
->setSkillRelUser($skillIssue);
|
||||
|
||||
$em->persist($skillUserComment);
|
||||
$em->flush();
|
||||
|
||||
header('Location: '.SkillRelUserManager::getIssueUrlAll($skillIssue));
|
||||
exit;
|
||||
}
|
||||
|
||||
$badgeInfoError = '';
|
||||
$personalBadge = '';
|
||||
|
||||
if ($allowDownloadExport) {
|
||||
$backpack = 'https://backpack.openbadges.org/';
|
||||
$configBackpack = api_get_setting('openbadges_backpack');
|
||||
|
||||
if (0 !== strcmp($backpack, $configBackpack)) {
|
||||
$backpack = $configBackpack;
|
||||
if (substr($backpack, -1) !== '/') {
|
||||
$backpack .= '/';
|
||||
}
|
||||
}
|
||||
|
||||
$htmlHeadXtra[] = '<script src="'.$backpack.'issuer.js"></script>';
|
||||
$objSkill = new Skill();
|
||||
$assertionUrl = $skillIssueInfo['badge_assertion'];
|
||||
$skills = $objSkill->get($skillId);
|
||||
$unbakedBadge = api_get_path(SYS_UPLOAD_PATH)."badges/".$skills['icon'];
|
||||
if (!is_file($unbakedBadge)) {
|
||||
$unbakedBadge = api_get_path(WEB_CODE_PATH).'img/icons/128/badges-default.png';
|
||||
}
|
||||
|
||||
$unbakedBadge = file_get_contents($unbakedBadge);
|
||||
$badgeInfoError = false;
|
||||
$personalBadge = "";
|
||||
$png = new PNGImageBaker($unbakedBadge);
|
||||
|
||||
if ($png->checkChunks("tEXt", "openbadges")) {
|
||||
$bakedInfo = $png->addChunk("tEXt", "openbadges", $assertionUrl);
|
||||
$bakedBadge = UserManager::getUserPathById($userId, "system");
|
||||
$bakedBadge = $bakedBadge.'badges';
|
||||
if (!file_exists($bakedBadge)) {
|
||||
mkdir($bakedBadge, api_get_permissions_for_new_directories(), true);
|
||||
}
|
||||
$skillRelUserId = $skillIssueInfo['id'];
|
||||
if (!file_exists($bakedBadge."/badge_".$skillRelUserId)) {
|
||||
file_put_contents($bakedBadge."/badge_".$skillRelUserId.".png", $bakedInfo);
|
||||
}
|
||||
|
||||
//Process to validate a baked badge
|
||||
$badgeContent = file_get_contents($bakedBadge."/badge_".$skillRelUserId.".png");
|
||||
$verifyBakedBadge = $png->extractBadgeInfo($badgeContent);
|
||||
if (!is_array($verifyBakedBadge)) {
|
||||
$badgeInfoError = true;
|
||||
}
|
||||
|
||||
if (!$badgeInfoError) {
|
||||
$personalBadge = UserManager::getUserPathById($userId, "web");
|
||||
$personalBadge = $personalBadge."badges/badge_".$skillRelUserId.".png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$allUserBadges[$index]['issue_info'] = $skillIssueInfo;
|
||||
$allUserBadges[$index]['allow_comment'] = $allowComment;
|
||||
$allUserBadges[$index]['allow_download_export'] = $allowDownloadExport;
|
||||
$allUserBadges[$index]['comment_form'] = $form->returnForm();
|
||||
$allUserBadges[$index]['acquired_level_form'] = $formAcquiredLevel->returnForm();
|
||||
$allUserBadges[$index]['badge_error'] = $badgeInfoError;
|
||||
$allUserBadges[$index]['personal_badge'] = $personalBadge;
|
||||
}
|
||||
|
||||
$template = new Template(get_lang('IssuedBadgeInformation'));
|
||||
$template->assign('user_badges', $allUserBadges);
|
||||
$template->assign('show_level', api_get_configuration_value('hide_skill_levels') == false);
|
||||
|
||||
$content = $template->fetch(
|
||||
$template->get_template('skill/issued_all.tpl')
|
||||
);
|
||||
|
||||
$template->assign('header', get_lang('IssuedBadgeInformation'));
|
||||
$template->assign('content', $content);
|
||||
$template->display_one_col_template();
|
||||
18
main/badge/issuer.php
Normal file
18
main/badge/issuer.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Show information about the OpenBadge issuer.
|
||||
*
|
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$json = [
|
||||
'name' => api_get_setting('Institution'),
|
||||
'url' => api_get_path(WEB_PATH),
|
||||
];
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo json_encode($json);
|
||||
Reference in New Issue
Block a user