ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjLearningSequence.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
10{
11 const OBJ_TYPE = 'lso';
12
13 const E_CREATE = 'create';
14 const E_UPDATE = 'update';
15 const E_DELETE = 'delete';
16
20 protected $items_db;
21
25 protected $conditions_db;
26
31
35 protected $ls_participant;
36
40 protected $ls_settings;
41
45 protected $ls_file_system;
46
50 protected $state_db;
51
55 protected $ls_roles;
56
57 /*
58 * @var ilLearningSequenceSettingsDB
59 */
60 protected $settings_db;
61
62 /*
63 * @var ilLearningSequenceSettingsDB
64 */
65 protected $activation_db;
66
67 /*
68 * @var ilLearningSequenceActivation
69 */
70 protected $ls_activation;
71
76
77 public function __construct(int $id = 0, bool $call_by_reference = true)
78 {
79 global $DIC;
80
81 $this->type = self::OBJ_TYPE;
82 $this->lng = $DIC['lng'];
83 $this->ctrl = $DIC['ilCtrl'];
84 $this->user = $DIC['ilUser'];
85 $this->tree = $DIC['tree'];
86 $this->kiosk_mode_service = $DIC['service.kiosk_mode'];
87 $this->template = $DIC['tpl'];
88 $this->database = $DIC['ilDB'];
89 $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
90 $this->rbacadmin = $DIC['rbacadmin'];
91 $this->rbacreview = $DIC['rbacreview'];
92 $this->app_event_handler = $DIC['ilAppEventHandler'];
93 $this->filesystem = $DIC['filesystem'];
94 $this->ilias = $DIC['ilias'];
95 $this->il_settings = $DIC['ilSetting'];
96 $this->il_news = $DIC->news();
97 $this->il_condition_handler = new ilConditionHandler();
98
99 $this->data_factory = new \ILIAS\Data\Factory();
100
101 parent::__construct($id, $call_by_reference);
102 }
103
104 public static function getInstanceByRefId(int $ref_id)
105 {
107 }
108
109 public function read()
110 {
111 $this->getLSSettings();
112 if ($this->getRefId()) {
113 $this->getLSActivation();
114 }
115 parent::read();
116 }
117
118 public function create() : int
119 {
120 $id = parent::create();
121 if (!$id) {
122 return 0;
123 }
124 $this->raiseEvent(self::E_CREATE);
125
126 return (int) $this->getId();
127 }
128
129 public function update() : bool
130 {
131 if (!parent::update()) {
132 return false;
133 }
134 $this->raiseEvent(self::E_UPDATE);
135
136 return true;
137 }
138
139 public function delete() : bool
140 {
141 if (!parent::delete()) {
142 return false;
143 }
144
146 $this->getSettingsDB()->delete((int) $this->getId());
147 $this->getStateDB()->deleteFor((int) $this->getRefId());
148 $this->getActivationDB()->deleteForRefId((int) $this->getRefId());
149
150 $this->raiseEvent(self::E_DELETE);
151
152 return true;
153 }
154
155 protected function raiseEvent(string $event_type)
156 {
157 $this->app_event_handler->raise(
158 'Modules/LearningSequence',
159 $event_type,
160 array(
161 'obj_id' => $this->getId(),
162 'appointments' => null
163 )
164 );
165 }
166
167 public function cloneObject($target_id, $copy_id = 0, $omit_tree = false)
168 {
169 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
170
171 $this->cloneAutoGeneratedRoles($new_obj);
172 $this->cloneMetaData($new_obj);
173 $this->cloneSettings($new_obj);
174 $this->cloneLPSettings((int) $new_obj->getId());
175
176 $new_obj->addMember((int) $this->user->getId(), $new_obj->getDefaultAdminRole());
177
178 return $new_obj;
179 }
180
181
182 protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj) : bool
183 {
184 $admin = $this->getDefaultAdminRole();
185 $new_admin = $new_obj->getDefaultAdminRole();
186
187 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
188 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
189 }
190
191 $this->rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
192 $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
193
194 $member = $this->getDefaultMemberRole();
195 $new_member = $new_obj->getDefaultMemberRole();
196
197 if (!$member || !$new_member) {
198 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
199 }
200
201 $this->rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
202 $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
203
204 return true;
205 }
206
207 protected function cloneSettings(ilObjLearningSequence $new_obj)
208 {
209 $source = $this->getLSSettings();
210 $target = $new_obj->getLSSettings();
211
212 foreach ($source->getUploads() as $key => $upload_info) {
213 $target = $target->withUpload($upload_info, $key);
214 }
215
216 foreach ($source->getDeletions() as $deletion) {
217 $target = $target->withDeletion($deletion);
218 }
219
221 ->withAbstract($source->getAbstract())
222 ->withExtro($source->getExtro())
223 ->withAbstractImage($source->getAbstractImage())
224 ->withExtroImage($source->getExtroImage())
225 ;
226
227 $new_obj->updateSettings($target);
228 }
229
230 protected function cloneLPSettings(int $obj_id)
231 {
232 $lp_settings = new ilLPObjSettings($this->getId());
233 $lp_settings->cloneSettings($obj_id);
234 }
235
237 {
238 if (!$this->settings_db) {
239 $fs = $this->getLSFileSystem();
240 $this->settings_db = new ilLearningSequenceSettingsDB(
241 $this->database,
242 $fs
243 );
244 }
245 return $this->settings_db;
246 }
247
249 {
250 if (!$this->activation_db) {
251 $this->activation_db = new ilLearningSequenceActivationDB(
252 $this->database
253 );
254 }
256 }
257
259 {
260 if (!$this->ls_activation) {
261 $this->ls_activation = $this->getActivationDB()->getActivationForRefId((int) $this->getRefId());
262 }
263
265 }
266
268 {
269 $this->getActivationDB()->store($settings);
270 $this->ls_activation = $settings;
271 }
272
273 public function getLSFileSystem()
274 {
275 if (!$this->ls_file_system) {
276 $this->ls_file_system = new ilLearningSequenceFilesystem();
277 }
279 }
280
282 {
283 if (!$this->ls_settings) {
284 $this->ls_settings = $this->getSettingsDB()->getSettingsFor((int) $this->getId());
285 }
286
287 return $this->ls_settings;
288 }
289
291 {
292 $this->getSettingsDB()->store($settings);
293 $this->ls_settings = $settings;
294 }
295
296 protected function getLSItemsDB() : ilLSItemsDB
297 {
298 if (!$this->items_db) {
299 $this->items_db = new ilLSItemsDB(
300 $this->tree,
302 $this->getPostConditionDB(),
303 $this->getLSItemOnlineStatus()
304 );
305 }
306
307 return $this->items_db;
308 }
309
311 {
312 if (!$this->conditions_db) {
313 $this->conditions_db = new ilLSPostConditionDB($this->database);
314 }
315
317 }
318
320 {
321 if (!$this->ls_item_online_status) {
322 $this->ls_item_online_status = new LSItemOnlineStatus();
323 }
324
326 }
327
329 {
330 if (!$this->ls_participant) {
331 $this->ls_participant = new ilLearningSequenceParticipants(
332 (int) $this->getId(),
333 $this->log,
334 $this->app_event_handler,
335 $this->il_settings
336 );
337 }
338
340 }
341
342
344 {
345 if (is_null($this->ls_access)) {
346 $this->ls_access = new ilObjLearningSequenceAccess();
347 }
348
349 return $this->ls_access;
350 }
351
355 public function getLSItems() : array
356 {
357 $db = $this->getLSItemsDB();
358 return $db->getLSItems((int) $this->getRefId());
359 }
360
365 public function storeLSItems(array $ls_items)
366 {
367 $db = $this->getLSItemsDB();
368 $db->storeItems($ls_items);
369 }
370
375 public function deletePostConditionsForSubObjects(array $ref_ids)
376 {
377 $rep_utils = new ilRepUtil();
378 $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
379 $db = $this->getPostConditionDB();
380 $db->delete($ref_ids);
381 }
382
386 public function getPossiblePostConditionsForType(string $type) : array
387 {
388 $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
389 $conditions = [
390 $this->conditions_db::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
391 ];
392 foreach ($condition_types as $cond_type) {
393 $conditions[$cond_type] = $this->lng->txt($cond_type);
394 }
395 return $conditions;
396 }
397
399 {
400 if (!$this->learner_progress_db) {
401 $state_db = $this->getStateDB();
402 $this->learner_progress_db = new ilLearnerProgressDB(
403 $state_db,
404 $this->access
405 );
406 }
407
409 }
410
411 public function getStateDB() : ilLSStateDB
412 {
413 if (!$this->state_db) {
414 $this->state_db = new ilLSStateDB($this->database);
415 }
416
417 return $this->state_db;
418 }
419
423 public function getLSLearnerItems(int $usr_id) : array
424 {
425 $db = $this->getLearnerProgressDB();
426 return $db->getLearnerItems($usr_id, $this->getRefId(), $this->getLSItems());
427 }
428
430 {
431 if (!$this->ls_roles) {
432 $this->ls_roles = new ilLearningSequenceRoles(
433 $this,
434 $this->getLSParticipants(),
435 $this->ctrl,
436 $this->rbacadmin,
437 $this->rbacreview,
438 $this->database,
439 $this->user
440 );
441 }
442 return $this->ls_roles;
443 }
444
448 public function getCurrentItemForLearner(int $usr_id) : int
449 {
450 $db = $this->getStateDB();
451 $current = $db->getCurrentItemsFor($this->getRefId(), [$usr_id]);
452 $ref_id = $current[$usr_id];
453
454 if ($ref_id < 0) {
455 $ref_id = 0;
456 }
457
458 return $ref_id;
459 }
460
464 public function getCurriculumBuilder(array $items, LSUrlBuilder $url_builder = null) : ilLSCurriculumBuilder
465 {
466 global $DIC;
467
468 return new ilLSCurriculumBuilder(
469 $items,
470 $DIC["ui.factory"],
471 $this->lng,
473 $url_builder
474 );
475 }
476
477 public function getUrlBuilder(string $player_url) : LSUrlBuilder
478 {
479 $player_url = $this->data_factory->uri(ILIAS_HTTP_PATH . '/' . $player_url);
480 return new LSUrlBuilder($player_url);
481 }
482
483 protected function getGlobalSettings() : LSGlobalSettings
484 {
485 $db = new ilLSGlobalSettingsDB($this->il_settings);
486 return $db->getSettings();
487 }
488
492 public function getSequencePlayer($gui, string $player_command, int $usr_id) : ilLSPlayer
493 {
494 global $DIC;
495
496 $lso_ref_id = $this->getRefId();
497 $lso_title = $this->getTitle();
498
499 $player_url = $this->ctrl->getLinkTarget($gui, $player_command, '', false, false);
500 $items = $this->getLSLearnerItems($usr_id);
501 $url_builder = $this->getUrlBuilder($player_url);
502
503 $curriculum_builder = $this->getCurriculumBuilder(
504 $items,
505 $url_builder
506 );
507
508 $global_settings = $this->getGlobalSettings();
509 $control_builder = new LSControlBuilder(
510 $DIC["ui.factory"],
511 $url_builder,
512 $this->lng,
513 $global_settings
514 );
515
516 $view_factory = new ilLSViewFactory(
517 $this->kiosk_mode_service,
518 $this->lng,
519 $this->access
520 );
521
522 $state_db = $this->getStateDB();
523 $kiosk_renderer = $this->getKioskRenderer($url_builder);
524
525 return new ilLSPlayer(
526 $lso_ref_id,
527 $lso_title,
528 $usr_id,
529 $items,
530 $state_db,
531 $control_builder,
532 $url_builder,
533 $curriculum_builder,
534 $view_factory,
535 $kiosk_renderer,
536 $DIC["ui.factory"]
537 );
538 }
539
540 protected function getKioskRenderer(LSUrlBuilder $url_builder)
541 {
542 if (!$this->kiosk_renderer) {
543 global $DIC;
544
545 $kiosk_template = new ilTemplate("tpl.kioskpage.html", true, true, 'Modules/LearningSequence');
546
547 $toc_gui = new ilLSTOCGUI($url_builder, $this->ctrl);
548 $loc_gui = new ilLSLocatorGUI($url_builder, $DIC["ui.factory"]);
549
550 $window_title = $this->il_settings->get('short_inst_name');
551 if ($window_title === false) {
552 $window_title = 'ILIAS';
553 }
554
555 $this->kiosk_renderer = new ilKioskPageRenderer(
556 $this->template,
557 $DIC["ui.renderer"],
558 $kiosk_template,
559 $toc_gui,
560 $loc_gui,
561 $window_title
562 );
563 }
564
565 return $this->kiosk_renderer;
566 }
567
572 public function getMailToMembersType()
573 {
574 return $this->mail_members;
575 }
576
583 public static function _goto($target, $add = "")
584 {
585 global $DIC;
586
587 $ilAccess = $DIC['ilAccess'];
588 $ilErr = $DIC['ilErr'];
589 $lng = $DIC['lng'];
590 $ilUser = $DIC['ilUser'];
591
592 if (substr($add, 0, 5) == 'rcode') {
593 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
594 // Redirect to login for anonymous
596 "login.php?target=" . $_GET["target"] . "&cmd=force_login&lang=" .
597 $ilUser->getCurrentLanguage()
598 );
599 }
600
601 // Redirects to target location after assigning user to learning sequence
603 $target,
605 substr($add, 5)
606 );
607 }
608
609 if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
611 }
612
613 if ($ilAccess->checkAccess("read", "", $target)) {
615 } else {
616 // to do: force flat view
617 if ($ilAccess->checkAccess("visible", "", $target)) {
618 ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
619 } else {
620 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
622 sprintf(
623 $lng->txt("msg_no_perm_read_item"),
625 ),
626 true
627 );
629 }
630 }
631 }
632
633 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
634 }
635
636 public function getMembersObject()
637 {
638 return $this->getLSParticipants();
639 }
640
641 public function isMember(int $usr_id)
642 {
643 $part = $this->getLSParticipants();
644 return $part->isMember($usr_id);
645 }
646
647 public function isCompletedByUser(int $usr_id) : bool
648 {
649 \ilLPStatusWrapper::_updateStatus($this->getId(), $usr_id);
651 $user_completion = ilLPStatus::_hasUserCompleted($this->getId(), $usr_id);
652 return ($tracking_active && $user_completion);
653 }
654
655 public function getShowMembers()
656 {
657 return $this->getLSSettings()->getMembersGallery();
658 }
659
660 public function userMayUnparticipate() : bool
661 {
662 return $this->access->checkAccess('unparticipate', '', $this->getRefId());
663 }
664
665 public function userMayJoin() : bool
666 {
667 return $this->access->checkAccess('participate', '', $this->getRefId());
668 }
669
670 public function announceLSOOnline()
671 {
672 $ns = $this->il_news;
673 $context = $ns->contextForRefId((int) $this->getRefId());
674 $item = $ns->item($context);
675 $item->setContentIsLangVar(true);
676 $item->setContentTextIsLangVar(true);
677 $item->setTitle("lso_news_online_title");
678 $item->setContent("lso_news_online_txt");
679 $news_id = $ns->data()->save($item);
680 }
681 public function announceLSOOffline()
682 {
683 //NYI
684 }
685
686 public function setEffectiveOnlineStatus(bool $status)
687 {
688 $act_db = $this->getActivationDB();
689 $act_db->setEffectiveOnlineStatus((int) $this->getRefId(), $status);
690 }
691
692
693
694 /***************************************************************************
695 * Role Stuff
696 ***************************************************************************/
697 public function getLocalLearningSequenceRoles(bool $translate = false) : array
698 {
699 return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
700 }
701
702 public function getDefaultMemberRole() : int
703 {
704 return $this->getLSRoles()->getDefaultMemberRole();
705 }
706
707 public function getDefaultAdminRole()
708 {
709 return $this->getLSRoles()->getDefaultAdminRole();
710 }
711
712 public function addMember($user_id, $mem_role) : bool
713 {
714 return $this->getLSRoles()->addLSMember($user_id, $mem_role);
715 }
716
717 public function join(int $user_id)
718 {
719 $member_role = $this->getDefaultMemberRole();
720 return $this->getLSRoles()->join($user_id, $member_role);
721 }
722
723 public function leaveLearningSequence()
724 {
725 return $this->getLSRoles()->leaveLearningSequence();
726 }
727
729 {
730 return $this->getLSRoles()->getLearningSequenceMemberIds();
731 }
732
733 public function leave($a_user_id)
734 {
735 return $this->getLSRoles()->leave($a_user_id);
736 }
737
738 public function getLearningSequenceMemberData($a_mem_ids, $active = 1)
739 {
740 return $this->getLSRoles()->getLearningSequenceMemberData($a_mem_ids, $active);
741 }
742
743 public function getLearningSequenceAdminIds($a_grpId = "")
744 {
745 return $this->getLSRoles()->getLearningSequenceAdminIds();
746 }
747
748 public function getDefaultLearningSequenceRoles($a_grp_id = "")
749 {
750 return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
751 }
752
753 public function initDefaultRoles()
754 {
755 return $this->getLSRoles()->initDefaultRoles();
756 }
757
758 public function readMemberData(array $user_ids, array $columns = null)
759 {
760 return $this->getLsRoles()->readMemberData($user_ids, $columns);
761 }
762
763 public function getParentObjectInfo(int $ref_id, array $search_types)
764 {
765 foreach ($this->tree->getPathFull($ref_id) as $hop) {
766 if (in_array($hop['type'], $search_types)) {
767 return $hop;
768 }
769 }
770 return null;
771 }
772
773 public function getLPCompletionStates() : array
774 {
775 return [
777 ];
778 }
779}
user()
Definition: user.php:4
if(! $in) $columns
Definition: Utf8Test.php:45
$source
Definition: linkback.php:22
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class LSControlBuilder.
Global Settings of the Learning Sequence.
Class LSUrlBuilder.
INTERNAL CLASS: Please do not use in consumer code.
static _getInstance($a_obj_id)
get instance by obj_id
Class ilContainer.
Class ilKioskPageRenderer.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
const LP_STATUS_COMPLETED_NUM
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
Builds the overview (curriculum) of a LearningSequence.
Repository for LSGlobalSettings over ILIAS global settings.
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:12
GUI for Locator element.
Implementation of KioskMode Player.
Storage for ilLSPostConditions.
Persistence for View-States.
Tree-GUI for ToC.
Get LearningProgress and availability of items in sequence.
Persistence for online/activation period.
Persistence for Settings (like abstract, extro)
Settings for an LSO (like abstract, extro)
static handleCode($a_ref_id, $a_type, $a_code)
Handle target parameter.
Class ilObjLearningSequenceAccess class.
Class ilObjLearningSequence.
getMailToMembersType()
Get mail to members type.
getLearningSequenceMemberData($a_mem_ids, $active=1)
updateSettings(ilLearningSequenceSettings $settings)
cloneObject($target_id, $copy_id=0, $omit_tree=false)
__construct(int $id=0, bool $call_by_reference=true)
deletePostConditionsForSubObjects(array $ref_ids)
Delete post conditions for ref ids.
readMemberData(array $user_ids, array $columns=null)
getLSItems()
Get a list of LSItems.
cloneSettings(ilObjLearningSequence $new_obj)
cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj)
updateActivation(ilLearningSequenceActivation $settings)
getCurrentItemForLearner(int $usr_id)
Get ref-id of the last item the user touched.
getLSLearnerItems(int $usr_id)
Get a list of LSLearnerItems.
getCurriculumBuilder(array $items, LSUrlBuilder $url_builder=null)
getParentObjectInfo(int $ref_id, array $search_types)
static _goto($target, $add="")
Goto target learning sequence.
static getInstanceByRefId(int $ref_id)
getKioskRenderer(LSUrlBuilder $url_builder)
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
getSequencePlayer($gui, string $player_command, int $usr_id)
factors the player
storeLSItems(array $ls_items)
Update LSItems.
getLocalLearningSequenceRoles(bool $translate=false)
static _enabledLearningProgress()
check wether learing progress is enabled or not
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
getRefId()
get reference id @access public
cloneMetaData($target_obj)
Copy meta data.
getId()
get object id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
getTitle()
get object title @access public
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI)
special template class to simplify handling of ITX/PEAR
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$key
Definition: croninfo.php:18
$target_id
Definition: goto.php:49
$target
Definition: test.php:19
update($pash, $contents, Config $config)
redirection script todo: (a better solution should control the processing via a xml file)
$ilErr
Definition: raiseError.php:18
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
$context
Definition: webdav.php:25