Fix issued badge page when using the default image - refs #8208

ofaj
Angel Fernando Quiroz Campos 9 years ago
parent acb9489140
commit 2234e74016
  1. 58
      main/badge/issued.php
  2. 2
      main/template/default/skill/issued.tpl

@ -113,37 +113,43 @@ if ($allowExport) {
$htmlHeadXtra[] = '<script src="' . $backpack . 'issuer.js"></script>';
}
$objSkill = new Skill();
$skills = $objSkill->get($skillId);
$unbakedBadge = api_get_path(SYS_UPLOAD_PATH) . "badges/".$skills['icon'];
$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 = $userSkills[0]->getId();
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 ($skill->getIcon()) {
$unbakedBadge = file_get_contents(
api_get_path(SYS_UPLOAD_PATH) . "badges/" . $skill->getIcon()
);
$png = new PNGImageBaker($unbakedBadge);
if ($png->checkChunks("tEXt", "openbadges")) {
$bakedInfo = $png->addChunk("tEXt", "openbadges", $assertionUrl);
$bakedBadge = UserManager::getUserPathById($userId, "system") . 'badges';
if (!file_exists($bakedBadge)) {
mkdir($bakedBadge, api_get_permissions_for_new_directories(), true);
}
$skillRelUserId = $userSkills[0]->getId();
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";
if (!$badgeInfoError) {
$personalBadge = UserManager::getUserPathById($userId, "web");
$personalBadge = $personalBadge."badges/badge_" . $skillRelUserId . ".png";
}
}
}

@ -22,7 +22,7 @@
</div>
{% if badge_error %}
<div class="alert alert-danger"> {{ 'BakedBadgeProblem'|get_lang }}</div>
{% else %}
{% elseif personal_badge is not empty %}
<p class="text-center">
<a href="{{ personal_badge }}" class="btn btn-primary" target="_new" download="badge">
<em class="fa fa-download fa-fw"></em> {{ 'DownloadBadge'|get_lang }}

Loading…
Cancel
Save