21 public function __construct($a_badge_id = null, $a_user_id = null)
29 $this->
read($a_badge_id, $a_user_id);
39 $set = $ilDB->query(
"SELECT * FROM badge_user_badge".
40 " WHERE user_id = ".$ilDB->quote($a_user_id,
"integer").
42 while(
$row = $ilDB->fetchAssoc($set))
45 $obj->importDBRow(
$row);
58 $set = $ilDB->query(
"SELECT * FROM badge_user_badge".
59 " WHERE badge_id = ".$ilDB->quote($a_badge_id,
"integer"));
60 while(
$row = $ilDB->fetchAssoc($set))
63 $obj->importDBRow(
$row);
79 $badge_ids[] = $badge->getId();
81 if(
sizeof($badge_ids))
83 $set = $ilDB->query(
"SELECT * FROM badge_user_badge".
84 " WHERE ".$ilDB->in(
"badge_id", $badge_ids,
"",
"integer"));
85 while(
$row = $ilDB->fetchAssoc($set))
88 $obj->importDBRow(
$row);
100 foreach(self::getInstancesByBadgeId($a_badge_id) as $ass)
102 $res[] = $ass->getUserId();
108 public static function exists($a_badge_id, $a_user_id)
110 $obj =
new self($a_badge_id, $a_user_id);
121 $this->badge_id = (int)$a_value;
131 $this->user_id = (int)$a_value;
141 $this->tstamp = (int)$a_value;
151 $this->awarded_by = (int)$a_id;
161 if($a_value !== null)
163 $a_value = (int)$a_value;
165 $this->pos = $a_value;
180 $this->stored =
true;
188 protected function read($a_badge_id, $a_user_id)
192 $set = $ilDB->query(
"SELECT * FROM badge_user_badge".
193 " WHERE badge_id = ".$ilDB->quote($a_badge_id,
"integer").
194 " AND user_id = ".$ilDB->quote($a_user_id,
"integer"));
195 $row = $ilDB->fetchAssoc($set);
227 if(!(
bool)$this->stored)
229 $ilDB->insert(
"badge_user_badge", $fields + $keys);
233 $ilDB->update(
"badge_user_badge", $fields, $keys);
237 public function delete()
249 $ilDB->manipulate(
"DELETE FROM badge_user_badge".
250 " WHERE badge_id = ".$ilDB->quote($this->getBadgeId(),
"integer").
251 " AND user_id = ".$ilDB->quote($this->getUserId(),
"integer"));
256 foreach(self::getInstancesByUserId($a_user_id) as $ass)
264 foreach(self::getInstancesByBadgeId($a_badge_id) as $ass)
272 foreach(self::getInstancesByParentId($a_parent_obj_id) as $ass)
281 include_once
"Services/Badge/classes/class.ilBadge.php";
282 foreach(self::getInstancesByUserId($a_user_id) as $ass)
284 $badge =
new ilBadge($ass->getBadgeId());
285 $existing[$badge->getId()] =
array($badge->getTitle(), $ass);
289 foreach($a_positions as
$title)
291 foreach($existing as $id => $item)
293 if($title == $item[0])
295 $item[1]->setPosition(++$new_pos);
297 unset($existing[$id]);
310 $verify =
new stdClass();
311 $verify->type =
"hosted";
312 $verify->url = $a_url;
314 $recipient =
new stdClass();
315 $recipient->type =
"email";
316 $recipient->hashed =
true;
320 include_once
"Services/Badge/classes/class.ilBadgeProfileGUI.php";
325 $mail = $user->getEmail();
327 $recipient->identity =
'sha256$'.hash(
'sha256', $mail.$recipient->salt);
332 $json =
new stdClass();
333 $json->{
"@context"} =
"https://w3id.org/openbadges/v1";
334 $json->type =
"Assertion";
336 $json->uid = $unique_id;
337 $json->recipient = $recipient;
339 include_once
"Services/Badge/classes/class.ilBadge.php";
341 $badge_url = $badge->getStaticUrl();
345 if($this->
bakeImage($baked_image, $badge->getImagePath(), $a_url))
348 $parts = explode(
"/", $a_url);
350 $parts[] = basename($baked_image);
351 $json->image = implode(
"/", $parts);
355 $json->badge = $badge_url;
356 $json->verify = $verify;
364 $baked_path = dirname($json_path);
365 $baked_file = array_shift(explode(
".", basename($json_path)));
368 $suffix = strtolower(array_pop(explode(
".", basename($a_badge->
getImagePath()))));
369 return $baked_path.
"/".$baked_file.
".".$suffix;
372 protected function bakeImage($a_baked_image_path, $a_badge_image_path, $a_assertion_url)
374 $suffix = strtolower(array_pop(explode(
".", basename($a_badge_image_path))));
378 include_once
"Services/Badge/lib/baker.lib.php";
379 $png =
new PNGImageBaker(file_get_contents($a_badge_image_path));
382 if($png->checkChunks(
"tEXt",
"openbadges"))
384 $baked = $png->addChunk(
"tEXt",
"openbadges", $a_assertion_url);
388 if(!file_exists($a_baked_image_path))
390 file_put_contents($a_baked_image_path, $baked);
394 $verify = $png->extractBadgeInfo(file_get_contents($a_baked_image_path));
395 if(is_array($verify))
400 else if($suffix ==
"svg")
403 $svg = simplexml_load_file($a_badge_image_path);
404 $ass = $svg->addChild(
"openbadges:assertion",
"",
"http://openbadges.org");
405 $ass->addAttribute(
"verify", $a_assertion_url);
406 $baked = $svg->asXML();
409 if(!file_exists($a_baked_image_path))
411 file_put_contents($a_baked_image_path, $baked);
422 include_once(
"./Services/Badge/classes/class.ilBadgeHandler.php");
427 if(!file_exists(
$path))
430 file_put_contents(
$path, $json);
439 include_once(
"./Services/Badge/classes/class.ilBadgeHandler.php");
442 array_map(
"unlink", glob(
$path));
447 foreach(self::getInstancesByUserId($a_user_id) as $ass)
449 $ass->deleteStaticFiles();
getImagePath($a_full_path=true)
static exists($a_badge_id, $a_user_id)
static getAssignedUsers($a_badge_id)
__construct($a_badge_id=null, $a_user_id=null)
static deleteByParentId($a_parent_obj_id)
Php library to Bake the PNG Images.
getImagePath(ilBadge $a_badge)
static getInstancesByParentId($a_parent_id, array $a_filter=null)
getPropertiesForStorage()
static deleteByBadgeId($a_badge_id)
Create styles array
The data for the language used.
static updatePositions($a_user_id, array $a_positions)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
bakeImage($a_baked_image_path, $a_badge_image_path, $a_assertion_url)
read($a_badge_id, $a_user_id)
static deleteByUserId($a_user_id)
static getInstancesByBadgeId($a_badge_id)
static clearBadgeCache($a_user_id)
static getInstancesByUserId($a_user_id)
static getInstance()
Constructor.
importDBRow(array $a_row)
static getInstancesByParentId($a_parent_obj_id)