ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSCORMPresentationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32{
36 protected int $refId;
38
39 public function __construct()
40 {
41 global $DIC;
42 $ilCtrl = $DIC->ctrl();
43 // $this->tpl = $DIC['tpl'];
44 $this->lng = $DIC->language();
45 $this->ctrl = $ilCtrl;
46
47 $this->lng->loadLanguageModule('cert');
48
49 // Todo: check lm id
50 $this->refId = $DIC->http()->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int());
51 $this->slm = new ilObjSCORMLearningModule($this->refId, true);
52 }
53
58 public function executeCommand(): void
59 {
60 global $DIC;
61 $ilAccess = $DIC->access();
62 $ilLog = ilLoggerFactory::getLogger('sahs');
63 $lng = $DIC->language();
64 $ilErr = $DIC["ilErr"];
65
66 $next_class = $this->ctrl->getNextClass($this);
67 $cmd = $this->ctrl->getCmd("frameset");
68
69 if (!$ilAccess->checkAccess("write", "", $this->refId) &&
70 (!$ilAccess->checkAccess("read", "", $this->refId) ||
71 $this->slm->getOfflineStatus())) {
72 $ilErr->raiseError($lng->txt("permission_denied"), $ilErr->WARNING);
73 }
74
75 // switch ($next_class) {
76 // default:
77 $this->$cmd();
78 // }
79 }
80
84 public function attrib2arr(?array $a_attributes): array
85 {
86 $attr = array();
87
88 if (!is_array($a_attributes)) {
89 return $attr;
90 }
91 foreach ($a_attributes as $attribute) {
92 $attr[$attribute->name()] = $attribute->value();
93 }
94
95 return $attr;
96 }
97
103 public function frameset(): void
104 {
105 global $DIC;
106 $lng = $DIC->language();
107 $javascriptAPI = true;
108 $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
109
110 //check for max_attempts and raise error if max_attempts is exceeded
111 // if ($this->get_max_attempts() != 0) {
112 // if ($this->get_actual_attempts() >= $this->get_max_attempts()) {
113 // header('Content-Type: text/html; charset=utf-8');
114 // echo($lng->txt("cont_sc_max_attempt_exceed"));
115 // exit;
116 // }
117 // }
118
120 ilWACSignedPath::signFolderOfStartFile($this->slm->getDataDirectory() . '/imsmanifest.xml');
121
122 $debug = $this->slm->getDebug();
123 if (count($items) > 1) {
124 $this->ctrl->setParameter($this, "expand", "1");
125 $this->ctrl->setParameter($this, "jsApi", "1");
126 $exp_link = $this->ctrl->getLinkTarget($this, "explorer");
127
128 // should be able to grep templates
129 if ($debug) {
130 $this->tpl = new ilGlobalTemplate("tpl.sahs_pres_frameset_js_debug.html", false, false, "components/ILIAS/ScormAicc");
131 } else {
132 $this->tpl = new ilGlobalTemplate("tpl.sahs_pres_frameset_js.html", false, false, "components/ILIAS/ScormAicc");
133 }
134
135 $this->tpl->setVariable("EXPLORER_LINK", $exp_link);
136 $pres_link = $this->ctrl->getLinkTarget($this, "contentSelect");
137 $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
138 } else {
139 if ($debug) {
140 $this->tpl = new ilGlobalTemplate("tpl.sahs_pres_frameset_js_debug_one_page.html", false, false, "components/ILIAS/ScormAicc");
141 } else {
142 $this->tpl = new ilGlobalTemplate("tpl.sahs_pres_frameset_js_one_page.html", false, false, "components/ILIAS/ScormAicc");
143 }
144
145 $this->ctrl->setParameter($this, "autolaunch", $items[0] ?? "");
146 }
147 $api_link = $this->ctrl->getLinkTarget($this, "apiInitData");
148 $this->tpl->setVariable("TITLE", $this->slm->getTitle());
149 $this->tpl->setVariable("ICON", ilUtil::getImagePath("favicon.ico", ""));
150 $this->tpl->setVariable("API_LINK", $api_link);
151 $this->tpl->printToStdout("DEFAULT", false, true);
152
153
154 exit;
155 }
156
157 // /**
158 // * Get max. number of attempts allowed for this package
159 // */
160 // public function get_max_attempts() : int
161 // {
162 // return ilObjSCORMInitData::get_max_attempts($this->slm->getId());
163 // }
164
168 public function get_actual_attempts(): int
169 {
170 global $DIC;
171 $ilDB = $DIC->database();
172 $ilUser = $DIC->user();
173 $val_set = $ilDB->queryF(
174 'SELECT package_attempts FROM sahs_user WHERE obj_id = %s AND user_id = %s',
175 array('integer','integer'),
176 array($this->slm->getId(),$ilUser->getId())
177 );
178 $val_rec = $ilDB->fetchAssoc($val_set);
179 $attempts = $val_rec["package_attempts"];
180 if ($attempts == null) {
181 $attempts = 0;
182 }
183 return $attempts;
184 }
185 // function get_actual_attempts() {
186 // global $DIC;
187 // $ilDB = $DIC->database();
188 // $ilUser = $DIC->user();
189 // $val_set = $ilDB->queryF('
190 // SELECT * FROM scorm_tracking
191 // WHERE user_id = %s
192 // AND sco_id = %s
193 // AND lvalue= %s
194 // AND obj_id = %s',
195 // array('integer','integer','text','integer'),
196 // array($ilUser->getId(),0,'package_attempts',$this->slm->getId())
197 // );
198 // $val_rec = $ilDB->fetchAssoc($val_set);
199
200 // $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
201 // if ($val_rec["rvalue"] == null) {
202 // $val_rec["rvalue"]=0;
203 // }
204
205 // return $val_rec["rvalue"];
206 // }
207
211 // function increase_attempt() {
212 // global $DIC;
213 // $ilDB = $DIC->database();
214 // $ilUser = $DIC->user();
215
216 // //get existing account - sco id is always 0
217 // $val_set = $ilDB->queryF('
218 // SELECT * FROM scorm_tracking
219 // WHERE user_id = %s
220 // AND sco_id = %s
221 // AND lvalue= %s
222 // AND obj_id = %s',
223 // array('integer','integer','text','integer'),
224 // array($ilUser->getId(),0,'package_attempts',$this->slm->getId())
225 // );
226
227 // $val_rec = $ilDB->fetchAssoc($val_set);
228
229 // $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
230 // if ($val_rec["rvalue"] == null) {
231 // $val_rec["rvalue"]=0;
232 // }
233 // $new_rec = $val_rec["rvalue"]+1;
234 // //increase attempt by 1
235 // //TODO: do not set c_timestamp because of last_access
236 // if($ilDB->numRows($val_set) > 0)
237 // {
238 // $ilDB->update('scorm_tracking',
239 // array(
240 // 'rvalue' => array('clob', $new_rec),
241 // 'c_timestamp' => array('timestamp', ilUtil::now())
242 // ),
243 // array(
244 // 'user_id' => array('integer', $ilUser->getId()),
245 // 'sco_id' => array('integer', 0),
246 // 'lvalue' => array('text', 'package_attempts'),
247 // 'obj_id' => array('integer', $this->slm->getId())
248 // )
249 // );
250 // }
251 // else
252 // {
253 // $ilDB->insert('scorm_tracking', array(
254 // 'obj_id' => array('integer', $this->slm->getId()),
255 // 'user_id' => array('integer', $ilUser->getId()),
256 // 'sco_id' => array('integer', 0),
257 // 'lvalue' => array('text', 'package_attempts'),
258 // 'rvalue' => array('clob', $new_rec),
259 // 'c_timestamp' => array('timestamp', ilUtil::now())
260 // ));
261 // }
262
263 // include_once("../components/ILIAS/Tracking/classes/class.ilLPStatusWrapper.php");
264 // ilLPStatusWrapper::_updateStatus($this->slm->getId(), $ilUser->getId());
265
266 // }
267
272 {
273 global $DIC;
274 $ilDB = $DIC->database();
275 $ilUser = $DIC->user();
276 $res = $ilDB->queryF(
277 'SELECT package_attempts,count(*) cnt FROM sahs_user WHERE obj_id = %s AND user_id = %s GROUP BY package_attempts',
278 array('integer','integer'),
279 array($this->slm->getId(),$ilUser->getId())
280 );
281 $val_rec = $ilDB->fetchAssoc($res);
282 if (!is_array($val_rec)) {
283 $attempts = 1;
284 $ilDB->manipulateF(
285 'INSERT INTO sahs_user (obj_id,user_id,package_attempts,module_version,last_access) VALUES(%s,%s,%s,%s,%s)',
286 array('integer', 'integer', 'integer', 'integer', 'timestamp'),
287 array($this->slm->getId(), $ilUser->getId(), $attempts, $this->slm->getModuleVersion(), date('Y-m-d H:i:s'))
288 );
289 } else {
290 $attempts = $val_rec["package_attempts"];
291 if ($attempts == null) {
292 $attempts = 0;
293 }
294 $attempts++;
295 $ilDB->manipulateF(
296 'UPDATE sahs_user SET package_attempts = %s, module_version = %s, last_access=%s WHERE obj_id = %s AND user_id = %s ',
297 array('integer', 'integer', 'timestamp', 'integer', 'integer'),
298 array($attempts, $this->slm->getModuleVersion(), date('Y-m-d H:i:s'), $this->slm->getId(), $ilUser->getId())
299 );
300 }
301 ilLPStatusWrapper::_updateStatus($this->slm->getId(), $ilUser->getId());
302 }
303
307 // function save_module_version() {
308 // global $DIC;
309 // $ilDB = $DIC->database();
310 // $ilUser = $DIC->user();
311
312 // $val_set = $ilDB->queryF('
313 // SELECT * FROM scorm_tracking
314 // WHERE user_id = %s
315 // AND sco_id = %s
316 // AND lvalue= %s
317 // AND obj_id = %s',
318 // array('integer','integer','text','integer'),
319 // array($ilUser->getId(),0,'module_version',$this->slm->getId())
320
321 // );
322
323 // if($ilDB->numRows($val_set) > 0)
324 // {
325 // $ilDB->update('scorm_tracking',
326 // array(
327 // 'rvalue' => array('clob', $this->slm->getModuleVersion()),
328 // 'c_timestamp' => array('timestamp', ilUtil::now())
329 // ),
330 // array(
331 // 'user_id' => array('integer', $ilUser->getId()),
332 // 'sco_id' => array('integer', 0),
333 // 'lvalue' => array('text', 'module_version'),
334 // 'obj_id' => array('integer', $this->slm->getId())
335 // )
336 // );
337 // }
338 // else
339 // {
340 // $ilDB->insert('scorm_tracking', array(
341 // 'obj_id' => array('integer', $this->slm->getId()),
342 // 'user_id' => array('integer', $ilUser->getId()),
343 // 'sco_id' => array('integer', 0),
344 // 'lvalue' => array('text', 'module_version'),
345 // 'rvalue' => array('clob', $this->slm->getModuleVersion()),
346 // 'c_timestamp' => array('timestamp', ilUtil::now())
347 // ));
348 // }
349
350 // include_once("../components/ILIAS/Tracking/classes/class.ilLPStatusWrapper.php");
351 // ilLPStatusWrapper::_updateStatus($this->slm->getId(), $ilUser->getId());
352
353 // }
354
360 public function explorer(string $a_target = "sahs_content"): void
361 {
362 global $DIC;
363 $ilBench = $DIC['ilBench'];
364 $ilLog = ilLoggerFactory::getLogger('sahs');
365
366 $ilBench->start("SCORMExplorer", "initExplorer");
367
368 $this->tpl = new ilGlobalTemplate("tpl.sahs_exp_main.html", true, true, "components/ILIAS/ScormAicc");
369 // $this->tpl = new ilTemplate("tpl.sahs_exp_main.html", true, true, "components/ILIAS/ScormAicc");
370 $exp = new ilSCORMExplorer($this->ctrl->getLinkTarget($this, "view"), $this->slm);
371 $exp->setTargetGet("obj_id");
372 $exp->setFrameTarget($a_target);
373
374 //$exp->setFiltered(true);
375 $jsApi = true;
376
377 $expanded = "";
378 if ($DIC->http()->wrapper()->query()->has('scexpand')) {
379 $expanded = $DIC->http()->wrapper()->query()->retrieve('scexpand', $DIC->refinery()->kindlyTo()->string());
380 }
381 if ($expanded == "") {
382 $mtree = new ilSCORMTree($this->slm->getId());
383 $expanded = $mtree->readRootId();
384 }
385 $exp->setExpand($expanded);
386
387 $exp->forceExpandAll(true, false);
388 $ilBench->stop("SCORMExplorer", "initExplorer");
389
390 // build html-output
391 $ilBench->start("SCORMExplorer", "setOutput");
392 $exp->setOutput(0);
393 $ilBench->stop("SCORMExplorer", "setOutput");
394
395 $ilBench->start("SCORMExplorer", "getOutput");
396 $output = $exp->getOutput($jsApi);
397 $ilBench->stop("SCORMExplorer", "getOutput");
398
399 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
400 $this->tpl->addBlockFile("CONTENT", "content", "tpl.sahs_explorer.html", "components/ILIAS/ScormAicc");
401 //$this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_content"));
402 $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
403 $this->tpl->setVariable("EXPLORER", $output);
404
405 $cmd = "";
406 if ($DIC->http()->wrapper()->query()->has('cmd')) {
407 $cmd = $DIC->http()->wrapper()->query()->retrieve('cmd', $DIC->refinery()->kindlyTo()->string());
408 }
409 $frame = "";
410 if ($DIC->http()->wrapper()->query()->has('frame')) {
411 $frame = $DIC->http()->wrapper()->query()->retrieve('frame', $DIC->refinery()->kindlyTo()->string());
412 }
413 $this->tpl->setVariable("ACTION", "ilias.php?baseClass=ilSAHSPresentationGUI&cmd=" . $cmd . "&frame=" . $frame .
414 "&ref_id=" . $this->slm->getRefId() . "&scexpand=" . $expanded);
415 $this->tpl->parseCurrentBlock();
416 //BUG 16794? $this->tpl->show();
417 // $this->tpl->show();
418 $this->tpl->printToStdout("DEFAULT", false);
419 }
420
421
425 public function view(): void
426 {
427 global $DIC;
428 $objId = $DIC->http()->wrapper()->query()->retrieve('obj_id', $DIC->refinery()->kindlyTo()->int());
429 $sc_gui_object = ilSCORMObjectGUI::getInstance($objId);
430
431 if (is_object($sc_gui_object)) {
432 $sc_gui_object->view();
433 }
434
435 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
436 $this->tpl->printToStdout('DEFAULT', false);
437 }
438
439 public function contentSelect(): void
440 {
441 global $DIC;
442 $lng = $DIC->language();
443 $this->tpl = new ilGlobalTemplate("tpl.scorm_content_select.html", true, true, "components/ILIAS/ScormAicc");
444 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
445 $this->tpl->setVariable('TXT_SPECIALPAGE', $lng->txt("seq_toc"));
446 $this->tpl->printToStdout("DEFAULT", false);
447 }
448
452 public function apiInitData(): void
453 {
454 global $DIC;
455
456 if (!($DIC->http()->wrapper()->query()->has('ref_id'))) {
457 print('alert("no start without ref_id");');
458 die;
459 }
460
461 header('Content-Type: text/javascript; charset=UTF-8');
462 print("function iliasApi() {\r\n");
463 $js_data = file_get_contents("../components/ILIAS/ScormAicc/scripts/basisAPI.js");
464 echo $js_data;
465 $js_data = file_get_contents("../components/ILIAS/ScormAicc/scripts/SCORM1_2standard.js");//want to give opportunities to different files (Uwe Kohnle)
466 echo $js_data;
467 print("}\r\n");
468
469 print("IliasScormVars=" . ilObjSCORMInitData::getIliasScormVars($this->slm) . ";\r\n");
470
471 //Resources
472 print("IliasScormResources=" . ilObjSCORMInitData::getIliasScormResources($this->slm->getId()) . ";\r\n");
473
474 //Tree
475 print("IliasScormTree=" . ilObjSCORMInitData::getIliasScormTree($this->slm->getId()) . ";\r\n");
476
477 //prevdata
478 print("IliasScormData=" . ilObjSCORMInitData::getIliasScormData($this->slm->getId()) . ";\r\n");
479
480 // set alternative API name - not necessary for scorm
481 if ($this->slm->getAPIAdapterName() !== "API") {
482 print('var ' . $this->slm->getAPIAdapterName() . '=new iliasApi();');
483 } else {
484 print('var API=new iliasApi();');
485 }
486 }
487
488 public function pingSession(): bool
489 {
490 ilWACSignedPath::signFolderOfStartFile($this->slm->getDataDirectory() . '/imsmanifest.xml');
491 return true;
492 }
493
498 public function downloadCertificate(): void
499 {
500 global $DIC;
501
502 $ilUser = $DIC->user();
503 $tree = $DIC['tree'];
504 $ilCtrl = $DIC->ctrl();
505 $refId = $DIC->http()->wrapper()->query()->retrieve('ref_id', $DIC->refinery()->kindlyTo()->int());
507
508 $certValidator = new ilCertificateDownloadValidator();
509 $allowed = $certValidator->isCertificateDownloadable($ilUser->getId(), $obj_id);
510 if ($allowed) {
511 $certificateLogger = $DIC->logger()->root();
512
513 $ilUserCertificateRepository = new ilUserCertificateRepository();
514 $pdfGenerator = new ilPdfGenerator($ilUserCertificateRepository);
515 $pdfAction = new ilCertificatePdfAction(
516 $pdfGenerator,
518 $this->lng->txt('error_creating_certificate_pdf')
519 );
520
521 $pdfAction->downloadPdf($ilUser->getId(), $obj_id);
522 exit;
523 }
524 // redirect to parent category if certificate is not accessible
525 $parent = $tree->getParentId($refId);
526 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
527 $ilCtrl->redirectByClass("ilrepositorygui", "");
528 }
529}
Validates if an active certificate is stored in the database and can be downloaded by the user.
Just a wrapper class to create Unit Test for other classes.
special template class to simplify handling of ITX/PEAR
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getLogger(string $a_component_id)
Get component logger.
static getIliasScormResources(int $a_packageId)
static getIliasScormTree(int $a_packageId)
static getIliasScormVars(ilObjSCORMLearningModule $slm_obj)
static getIliasScormData(int $a_packageId)
Class ilObjSCORMLearningModule.
static _lookupObjId(int $ref_id)
static _lookupPresentableItems(int $a_slm_id)
Count number of presentable SCOs/Assets of SCORM learning module.
Class ilSCORMPresentationGUI.
apiInitData()
SCORM Data for Javascript-API.
get_actual_attempts()
Get number of actual attempts for the user.
explorer(string $a_target="sahs_content")
save the active module version to scorm_tracking
increase_attemptAndsave_module_version()
Increases attempts by one for this package.
downloadCertificate()
Download the certificate for the active user.
SCORM Object Tree.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
static signFolderOfStartFile(string $start_file_path)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
$ilErr
Definition: raiseError.php:33
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57