1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
<?php
require_once __DIR__."/../model/SwagPostItem.php";
require_once __DIR__."/../utils/H5pUtil.php";
class H5pSwagifact extends SwagPostItem {
public function isCompleted($swagUser) {
$slug=$this->parameters["slug"];
$h5pId=H5pUtil::getH5pIdBy("slug",$slug);
$h5p=H5pUtil::getH5pById($h5pId);
$h5pParameters=json_decode($h5p["parameters"],TRUE);
$scoreElements=array(
"H5P.MultiChoice",
"H5P.SingleChoiceSet"
);
$requireComplete=FALSE;
if (!$h5pParameters)
throw new Exception("h5p not found or no parameters!");
$numSlides=0;
if (isset($h5pParameters["presentation"]["slides"])) {
$numSlides=sizeof($h5pParameters["presentation"]["slides"]);
foreach ($h5pParameters["presentation"]["slides"] as $slide) {
foreach ($slide["elements"] as $element) {
$library=$element["action"]["library"];
$parts=explode(" ",$library);
$libraryName=$parts[0];
if (in_array($libraryName,$scoreElements))
$requireComplete=TRUE;
}
}
}
$objectUrl=$this->getObjectUrl();
foreach ($this->swagPost->getRelatedStatements($swagUser) as $statement) {
if ($statement["object"]["id"]==$objectUrl) {
if ($statement["verb"]["id"]=="http://adlnet.gov/expapi/verbs/completed") {
if ($statement["result"]["score"]["scaled"]==1)
return TRUE;
}
if ($statement["verb"]["id"]=="http://adlnet.gov/expapi/verbs/progressed"
&& !$requireComplete) {
$ext=$statement["object"]["definition"]["extensions"];
$endingPoint=$ext["http://id.tincanapi.com/extension/ending-point"];
if ($endingPoint && $numSlides && $endingPoint>=$numSlides)
return TRUE;
}
}
}
return FALSE;
}
}