Allow send OpenBadges to backpack - refs BT#9082

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent ec87d31ac3
commit 2e96584422
  1. 49
      main/badge/assertion.php
  2. 25
      main/badge/class.php
  3. 17
      main/badge/criteria.php
  4. 17
      main/badge/issuer.php
  5. 48
      main/gradebook/get_badges.php
  6. 9
      main/gradebook/lib/be/category.class.php
  7. 11
      main/gradebook/lib/fe/displaygradebook.php
  8. 18
      main/inc/lib/skill.lib.php
  9. 2
      main/install/configuration.dist.php

@ -0,0 +1,49 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show information about a new assertion
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.badge
*/
header('Content-Type: application/json');
require_once '../inc/global.inc.php';
$userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
if ($userId === 0 || $skillId === 0) {
exit;
}
$objSkill = new Skill();
if (!$objSkill->user_has_skill($userId, $skillId)) {
exit;
}
$objSkillRelUser = new SkillRelUser();
$userSkill = $objSkillRelUser->getByUserAndSkill($userId, $skillId);
if ($userSkill == false) {
exit;
}
$user = api_get_user_info($userSkill['user_id']);
$json = array(
'uid' => $userSkill['id'],
'recipient' => array(
'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' => array(
'type' => 'hosted',
'url' => api_get_path(WEB_CODE_PATH) . "badge/assertion.php?user=$userId&skill=$skillId"
)
);
echo json_encode($json);

@ -0,0 +1,25 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show information about the OpenBadge class
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.badge
*/
header('Content-Type: application/json');
require_once '../inc/global.inc.php';
$skillId = isset($_GET['id']) ? intval($_GET['id']) : 0;
$objSkill = new Skill();
$skill = $objSkill->get($skillId);
$json = array(
'name' => $skill['name'],
'description' => $skill['description'],
'image' => api_get_path(WEB_CODE_PATH) . $skill['icon'],
'criteria' => api_get_path(WEB_CODE_PATH) . "badge/criteria.php?id=$skillId",
'issuer' => api_get_path(WEB_CODE_PATH) . "badge/issuer.php",
);
echo json_encode($json);

@ -0,0 +1,17 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show information about OpenBadge citeria
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.badge
*/
header('Content-Type: text/plain');
require_once '../inc/global.inc.php';
$skillId = isset($_GET['id']) ? intval($_GET['id']) : 0;
$objSkill = new Skill();
$skill = $objSkill->get($skillId);
echo $skill['criteria'];

@ -0,0 +1,17 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show information about the OpenBadge issuer
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.badge
*/
require_once '../inc/global.inc.php';
header('Content-Type: application/json');
$json = array(
'name' => api_get_setting('Institution'),
'url' => api_get_path(WEB_PATH)
);
echo json_encode($json);

@ -0,0 +1,48 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show the achieved badges by an user
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.badge
*/
$cidReset = true;
require_once '../inc/global.inc.php';
$userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
if ($userId === 0) {
exit;
}
$objSkillRelUser = new SkillRelUser();
$userSkills = $objSkillRelUser->get_user_skills($userId);
if (empty($userSkills)) {
exit;
}
$assertions = array();
foreach ($userSkills as $skill) {
$skillId = current($skill);
$assertions[] = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?user=$userId&skill=$skillId";
}
$backpack = 'https://backpack.openbadges.org/';
if (array_key_exists('openbadges_backpack', $_configuration)) {
$backpack = $_configuration['openbadges_backpack'];
}
$htmlHeadXtra[] = '<script src="' . $backpack . 'issuer.js"></script>';
$tpl = new Template(get_lang('Badges'), false, false);
$tpl->assign(
'content',
"<script>OpenBadges.issue_no_modal(" . json_encode($assertions) . ");</script>"
);
$tpl->display_one_col_template();

@ -1638,6 +1638,14 @@ class Category implements GradebookItem
'class' => 'btn'
)
);
$badges = Display::url(
get_lang('DownloadBadges'),
api_get_path(WEB_CODE_PATH) . "gradebook/get_badges.php?user=$user_id",
array(
'target' => '_blank',
'class' => 'btn'
)
);
$exportToPDF = Display::url(
Display::return_icon(
'pdf.png',
@ -1648,6 +1656,7 @@ class Category implements GradebookItem
"$url&action=export"
);
$html = array(
'badge_link' => $badges,
'certificate_link' => $certificates,
'pdf_link' => $exportToPDF
);

@ -451,11 +451,14 @@ class DisplayGradebook
$total_score = array($item_value_total, $item_total);
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
$certificateLink = null;
if (!empty($certificateLinkInfo) && isset($certificateLinkInfo['certificate_link'])) {
$certificateLink .= '<span style="float:right"> ' . $certificateLinkInfo['certificate_link']."</span>";
$aditionalButtons = null;
if (!empty($certificateLinkInfo)) {
$aditionalButtons = '<div class="btn-group pull-right">';
$aditionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : '';
$aditionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : '';
$aditionalButtons .= '</div>';
}
$scoreinfo .= '<h4>' . get_lang('Total') . ' : ' . $scorecourse_display . $certificateLink. '</h4>';
$scoreinfo .= '<h4>' . get_lang('Total') . ' : ' . $scorecourse_display . $aditionalButtons. '</h4>';
}
Display :: display_normal_message($scoreinfo, false);

@ -371,6 +371,24 @@ class SkillRelUser extends Model
);
return $result;
}
/**
* Get the relation data between user and skill
* @param int $userId The user id
* @param int $skillId The skill id
* @return array The relation data. Otherwise return false
*/
public function getByUserAndSkill($userId, $skillId)
{
$where = array(
'user_id = ? AND skill_id = ?' => array($userId, $skillId)
);
return Database::select('*', $this->table, array(
'where' => $where
), 'first');
}
}

@ -278,3 +278,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
//$_configuration['exercise_max_fckeditors_in_page'] = 0;
// Default upload option
//$_configuration['document_if_file_exists_option'] = 'rename'; // overwrite
// Which OpenBadges backpack send the badges
//$_configuration['openbadges_backpack'] = 'https://backpack.openbadges.org/';
Loading…
Cancel
Save