ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjLearningSequence.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public const OBJ_TYPE = 'lso';
24 
25  public const E_CREATE = 'create';
26  public const E_UPDATE = 'update';
27  public const E_DELETE = 'delete';
28 
29  protected ?ilLSItemsDB $items_db = null;
34  protected ?ilLSStateDB $state_db = null;
39  protected ?ArrayAccess $di = null;
40  protected ?ArrayAccess $local_di = null;
42  protected ArrayAccess $dic;
43  protected ilCtrl $ctrl;
46 
47 
48  public function __construct(int $id = 0, bool $call_by_reference = true)
49  {
50  global $DIC;
51  $this->dic = $DIC;
52 
53  $this->type = self::OBJ_TYPE;
54  $this->lng = $DIC['lng'];
55  $this->ctrl = $DIC['ilCtrl'];
56  $this->user = $DIC['ilUser'];
57  $this->tree = $DIC['tree'];
58  $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
59  $this->app_event_handler = $DIC['ilAppEventHandler'];
60  $this->il_news = $DIC->news();
61  $this->il_condition_handler = new ilConditionHandler();
62 
64 
65  $this->lng->loadLanguageModule('rbac');
66  }
67 
68  public static function getInstanceByRefId(int $ref_id): ?\ilObject
69  {
70  return ilObjectFactory::getInstanceByRefId($ref_id, false);
71  }
72 
73  public function read(): void
74  {
75  parent::read();
76  $this->getLSSettings();
77  if ($this->getRefId()) {
78  $this->getLSActivation();
79  }
80  }
81 
82  public function create(): int
83  {
84  $id = parent::create();
85  if (!$id) {
86  return 0;
87  }
88  $this->raiseEvent(self::E_CREATE);
89 
90  return $this->getId();
91  }
92 
93  public function update(): bool
94  {
95  if (!parent::update()) {
96  return false;
97  }
98  $this->raiseEvent(self::E_UPDATE);
99 
100  return true;
101  }
102 
103  public function delete(): bool
104  {
105  if (!parent::delete()) {
106  return false;
107  }
108 
110  $this->getSettingsDB()->delete($this->getId());
111  $this->getStateDB()->deleteFor($this->getRefId());
112  $this->getActivationDB()->deleteForRefId($this->getRefId());
113 
114  $this->raiseEvent(self::E_DELETE);
115 
116  return true;
117  }
118 
119  protected function raiseEvent(string $event_type): void
120  {
121  $this->app_event_handler->raise(
122  'Modules/LearningSequence',
123  $event_type,
124  array(
125  'obj_id' => $this->getId(),
126  'appointments' => null
127  )
128  );
129  }
130 
131  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
132  {
134  $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
135 
136  $this->cloneAutoGeneratedRoles($new_obj);
137  $this->cloneMetaData($new_obj);
138  $this->cloneSettings($new_obj);
139  $this->cloneLPSettings($new_obj->getId());
140  $this->cloneActivation($new_obj, $copy_id);
141  $this->cloneIntroAndExtroContentPages($new_obj, [self::CP_INTRO, self::CP_EXTRO]);
142 
143  $roles = $new_obj->getLSRoles();
144  $roles->addLSMember(
145  $this->user->getId(),
146  $roles->getDefaultAdminRole()
147  );
148  return $new_obj;
149  }
150 
151  protected function cloneIntroAndExtroContentPages(ilObjLearningSequence $new_obj, array $cp_types): void
152  {
153  foreach ($cp_types as $type) {
154  $old_intro_page_id = $this->getContentPageId($type);
156  "cont",
157  $old_intro_page_id
158  )) {
159  $new_obj->createContentPage($type);
160  $new_copg_id = $new_obj->getContentPageId($type);
161  $original_page = new \ilContainerPage($old_intro_page_id);
162  $original_page->copy($new_copg_id, "cont", $new_copg_id);
163  }
164  }
165  }
166 
167  protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj): bool
168  {
169  $admin = $this->getDefaultAdminRole();
170  $new_admin = $new_obj->getDefaultAdminRole();
171 
172  if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
173  $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
174  }
175 
176  $this->rbac_admin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
177  $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
178 
179  $member = $this->getDefaultMemberRole();
180  $new_member = $new_obj->getDefaultMemberRole();
181 
182  if (!$member || !$new_member) {
183  $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
184  }
185 
186  $this->rbac_admin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
187  $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
188 
189  return true;
190  }
191 
192  protected function cloneSettings(ilObjLearningSequence $new_obj): void
193  {
194  $source = $this->getLSSettings();
195  $target = $new_obj->getLSSettings();
196 
197  foreach ($source->getUploads() as $key => $upload_info) {
198  $target = $target->withUpload($upload_info, $key);
199  }
200 
201  foreach ($source->getDeletions() as $deletion) {
202  $target = $target->withDeletion($deletion);
203  }
204 
205  $target = $target
206  ->withAbstract($source->getAbstract())
207  ->withExtro($source->getExtro())
208  ->withAbstractImage($source->getAbstractImage())
209  ->withExtroImage($source->getExtroImage())
210  ;
211 
212  $new_obj->updateSettings($target);
213  }
214 
215  protected function cloneLPSettings(int $obj_id): void
216  {
217  $lp_settings = new ilLPObjSettings($this->getId());
218  $lp_settings->cloneSettings($obj_id);
219  }
220 
221  protected function cloneActivation(ilObjLearningSequence $new_obj, int $a_copy_id): void
222  {
223  // #14596
224  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
225  if ($cwo->isRootNode($this->getRefId())) {
226  $activation = $new_obj->getLSActivation()->withIsOnline(false);
227  } else {
228  $activation = $new_obj->getLSActivation()
229  ->withIsOnline($this->getLSActivation()->getIsOnline())
230  ->withActivationStart($this->getLSActivation()->getActivationStart())
231  ->withActivationEnd($this->getLSActivation()->getActivationEnd());
232  }
233 
234  $new_obj->getActivationDB()->store(
235  $activation
236  );
237  }
238 
239  protected function getDIC(): ArrayAccess
240  {
241  return $this->dic;
242  }
243 
244  public function getDI(): ArrayAccess
245  {
246  if (is_null($this->di)) {
247  $di = new ilLSDI();
248  $di->init($this->getDIC());
249  $this->di = $di;
250  }
251  return $this->di;
252  }
253 
254  public function getLocalDI(): ArrayAccess
255  {
256  if (is_null($this->local_di)) {
257  $di = new ilLSLocalDI();
258  $di->init(
259  $this->getDIC(),
260  $this->getDI(),
261  new \ILIAS\Data\Factory(),
262  $this
263  );
264  $this->local_di = $di;
265  }
266  return $this->local_di;
267  }
268 
270  {
271  if (!$this->settings_db) {
272  $this->settings_db = $this->getDI()['db.settings'];
273  }
274  return $this->settings_db;
275  }
276 
278  {
279  if (!$this->activation_db) {
280  $this->activation_db = $this->getDI()['db.activation'];
281  }
282  return $this->activation_db;
283  }
284 
286  {
287  if (!$this->ls_activation) {
288  $this->ls_activation = $this->getActivationDB()->getActivationForRefId($this->getRefId());
289  }
290 
291  return $this->ls_activation;
292  }
293 
295  {
296  $this->getActivationDB()->store($settings);
297  $this->ls_activation = $settings;
298  }
299 
301  {
302  if (!$this->ls_settings) {
303  $this->ls_settings = $this->getSettingsDB()->getSettingsFor($this->getId());
304  }
305 
306  return $this->ls_settings;
307  }
308 
310  {
311  $this->getSettingsDB()->store($settings);
312  $this->ls_settings = $settings;
313  }
314 
315  protected function getLSItemsDB(): ilLSItemsDB
316  {
317  if (!$this->items_db) {
318  $this->items_db = $this->getLocalDI()['db.lsitems'];
319  }
320  return $this->items_db;
321  }
322 
324  {
325  if (!$this->conditions_db) {
326  $this->conditions_db = $this->getDI()["db.postconditions"];
327  }
328  return $this->conditions_db;
329  }
330 
332  {
333  if (!$this->ls_participants) {
334  $this->ls_participants = $this->getLocalDI()['participants'];
335  }
336 
337  return $this->ls_participants;
338  }
339  public function getMembersObject(): \ilLearningSequenceParticipants //used by Services/Membership/classes/class.ilMembershipGUI.php
340  {
341  return $this->getLSParticipants();
342  }
343 
345  {
346  if (is_null($this->ls_access)) {
347  $this->ls_access = new ilObjLearningSequenceAccess();
348  }
349 
350  return $this->ls_access;
351  }
352 
356  public function getLSItems(): array
357  {
358  $db = $this->getLSItemsDB();
359  return $db->getLSItems($this->getRefId());
360  }
361 
366  public function storeLSItems(array $ls_items): void
367  {
368  $db = $this->getLSItemsDB();
369  $db->storeItems($ls_items);
370  }
371 
376  public function deletePostConditionsForSubObjects(array $ref_ids): void
377  {
378  $rep_utils = new ilRepUtil();
379  $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
380  $db = $this->getPostConditionDB();
381  $db->delete($ref_ids);
382  }
383 
387  public function getPossiblePostConditionsForType(string $type): array
388  {
389  $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
390  $conditions = [
391  $this->getPostConditionDB()::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
392  ];
393  foreach ($condition_types as $cond_type) {
394  $conditions[$cond_type] = $this->lng->txt('condition_' . $cond_type);
395  }
396  return $conditions;
397  }
398 
400  {
401  if (!$this->learner_progress_db) {
402  $this->learner_progress_db = $this->getLocalDI()['db.progress'];
403  }
405  }
406 
407  public function getStateDB(): ilLSStateDB
408  {
409  if (!$this->state_db) {
410  $this->state_db = $this->getDI()['db.states'];
411  }
412  return $this->state_db;
413  }
414 
418  public function getLSLearnerItems(int $usr_id): array
419  {
420  $db = $this->getLearnerProgressDB();
421  return $db->getLearnerItems($usr_id, $this->getRefId());
422  }
423 
425  {
426  if (!$this->ls_roles) {
427  $this->ls_roles = $this->getLocalDI()['roles'];
428  }
429  return $this->ls_roles;
430  }
431 
435  public function getMailToMembersType(): int
436  {
437  return 0;
438  }
439 
443  public static function _goto(int $target, string $add = ""): void
444  {
445  global $DIC;
446  $main_tpl = $DIC->ui()->mainTemplate();
447 
448  $ilAccess = $DIC['ilAccess'];
449  $ilErr = $DIC['ilErr'];
450  $lng = $DIC['lng'];
451  $ilUser = $DIC['ilUser'];
452  $request_wrapper = $DIC->http()->wrapper()->query();
453  $refinery = $DIC->refinery();
454 
455  if (substr($add, 0, 5) == 'rcode') {
456  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
457  $request_target = $request_wrapper->retrieve("target", $refinery->kindlyTo()->string());
458  // Redirect to login for anonymous
460  "login.php?target=" . $request_target . "&cmd=force_login&lang=" .
461  $ilUser->getCurrentLanguage()
462  );
463  }
464 
465  // Redirects to target location after assigning user to learning sequence
467  $target,
469  substr($add, 5)
470  );
471  }
472 
473  if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
474  ilObjectGUI::_gotoRepositoryNode($target, "members");
475  }
476 
477  if ($ilAccess->checkAccess("read", "", $target)) {
479  } else {
480  // to do: force flat view
481  if ($ilAccess->checkAccess("visible", "", $target)) {
482  ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
483  } else {
484  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
485  $main_tpl->setOnScreenMessage('failure', sprintf(
486  $lng->txt("msg_no_perm_read_item"),
488  ), true);
490  }
491  }
492  }
493 
494  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
495  }
496 
497  public function getShowMembers(): bool
498  {
499  return $this->getLSSettings()->getMembersGallery();
500  }
501 
502  public function announceLSOOnline(): void
503  {
504  $ns = $this->il_news;
505  $context = $ns->contextForRefId($this->getRefId());
506  $item = $ns->item($context);
507  $item->setContentIsLangVar(true);
508  $item->setContentTextIsLangVar(true);
509  $item->setTitle("lso_news_online_title");
510  $item->setContent("lso_news_online_txt");
511  $ns->data()->save($item);
512  }
513  public function announceLSOOffline(): void
514  {
515  //NYI
516  }
517 
518  public function setEffectiveOnlineStatus(bool $status): void
519  {
520  $act_db = $this->getActivationDB();
521  $act_db->setEffectiveOnlineStatus($this->getRefId(), $status);
522  }
523 
524  public function getCurrentUserCurriculum(): string
525  {
526  $dic = $this->getLocalDI();
527  $curriculum = $dic["player.curriculumbuilder"]->getLearnerCurriculum(false);
528  return $dic['ui.renderer']->render($curriculum);
529  }
530 
531  public function getCurrentUserLaunchButtons(): string
532  {
533  $dic = $this->getLocalDI();
534  $buttons = $dic["player.launchlinksbuilder"]->getLaunchbuttonsComponent();
535  return $dic['ui.renderer']->render($buttons);
536  }
537 
538 
539  /***************************************************************************
540  * Role Stuff
541  ***************************************************************************/
545  public function getLocalLearningSequenceRoles(bool $translate = false): array
546  {
547  return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
548  }
549 
550  public function getDefaultMemberRole(): int
551  {
552  return $this->getLSRoles()->getDefaultMemberRole();
553  }
554 
555  public function getDefaultAdminRole(): int
556  {
557  return $this->getLSRoles()->getDefaultAdminRole();
558  }
559 
563  public function getDefaultLearningSequenceRoles(string $a_grp_id = ""): array
564  {
565  return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
566  }
567 
568  public function initDefaultRoles(): void
569  {
570  $this->getLSRoles()->initDefaultRoles();
571  }
572 
578  public function readMemberData(array $user_ids, array $columns = null): array
579  {
580  return $this->getLsRoles()->readMemberData($user_ids, $columns);
581  }
582 
583  public function getParentObjectInfo(int $ref_id, array $search_types): ?array
584  {
585  foreach ($this->tree->getPathFull($ref_id) as $hop) {
586  if (in_array($hop['type'], $search_types)) {
587  return $hop;
588  }
589  }
590  return null;
591  }
592 
596  public function getLPCompletionStates(): array
597  {
598  return [
600  ];
601  }
602 
603  public const CP_INTRO = -1;
604  public const CP_EXTRO = -2;
605  public const CP_TYPE = 'cont';
606 
607  public function getContentPageId(int $factor): int
608  {
609  if (!in_array($factor, [self::CP_INTRO, self::CP_EXTRO])) {
610  throw new \InvalidArgumentException("not a valid modifier for page id: '$factor'");
611  }
612  return $this->getId() * $factor;
613  }
614 
615  public function hasContentPage(int $factor): bool
616  {
617  $page_id = $this->getContentPageId($factor);
618  return ilContainerPage::_exists(self::CP_TYPE, $page_id);
619  }
620 
621  public function createContentPage(int $factor): void
622  {
623  if ($this->hasContentPage($factor)) {
624  throw new \LogicException('will not create content page - it already exists.');
625  }
626  $page_id = $this->getContentPageId($factor);
627  $new_page_object = new \ilContainerPage();
628  $new_page_object->setId($page_id);
629  $new_page_object->setParentId($this->getId());
630  $new_page_object->createFromXML();
631  }
632 
633  public function getContentPageHTML(int $factor): string
634  {
635  if (!$this->hasContentPage($factor)) {
636  return '';
637  }
638  $page_id = $this->getContentPageId($factor);
640  self::CP_TYPE,
641  $page_id
642  );
643 
644  $gui->setPresentationTitle("");
645  $gui->setTemplateOutput(false);
646  $gui->setHeader("");
647  $ret = $gui->showPage();
648  return $ret;
649  }
650 }
const LP_STATUS_COMPLETED_NUM
static handleCode(int $a_ref_id, string $a_type, string $a_code)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $type
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLearningSequenceActivation $ls_activation
deletePostConditionsForSubObjects(array $ref_ids)
Delete post conditions for ref ids.
getMailToMembersType()
Get mail to members type.
updateSettings(ilLearningSequenceSettings $settings)
$context
Definition: webdav.php:29
const ANONYMOUS_USER_ID
Definition: constants.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLearningSequenceSettings $ls_settings
cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj)
getParentObjectInfo(int $ref_id, array $search_types)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ilLSItemsDB.php:24
cloneSettings(ilObjLearningSequence $new_obj)
const ROOT_FOLDER_ID
Definition: constants.php:32
Class ChatMainBarProvider .
getDefaultLearningSequenceRoles(string $a_grp_id="")
static _gotoRepositoryNode(int $ref_id, string $cmd="")
__construct(int $id=0, bool $call_by_reference=true)
$target_id
Definition: goto.php:52
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLearningSequenceSettingsDB $settings_db
$ilErr
Definition: raiseError.php:17
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
getLocalLearningSequenceRoles(bool $translate=false)
readMemberData(array $user_ids, array $columns=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
cloneMetaData(ilObject $target_obj)
Copy meta data.
ilLearningSequenceActivationDB $activation_db
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
ilLanguage $lng
bool $call_by_reference
ilDBInterface $db
static getInstanceByRefId(int $ref_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneIntroAndExtroContentPages(ilObjLearningSequence $new_obj, array $cp_types)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneActivation(ilObjLearningSequence $new_obj, int $a_copy_id)
ilLearningSequenceRoles $ls_roles
static _deleteAllEntries(int $a_obj_id)
Delete all entries Normally called in case of object deletion.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static redirect(string $a_script)
ilLearningSequenceParticipants $ls_participants
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
static _goto(int $target, string $add="")
Goto target learning sequence.
ilConditionHandler $il_condition_handler
$ilUser
Definition: imgupload.php:34
ilObjLearningSequenceAccess $ls_access
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLearnerProgressDB $learner_progress_db
static _getInstance(int $a_copy_id)
static _lookupType(int $id, bool $reference=false)
$source
Definition: metadata.php:93
updateActivation(ilLearningSequenceActivation $settings)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
storeLSItems(array $ls_items)
Update LSItems.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery