ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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;
44  protected \ILIAS\News\Service $il_news;
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  'components/ILIAS/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, [LSOPageType::INTRO->value, LSOPageType::EXTRO->value]);
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();
155  if ($type === 'lsoi') {
156  $new_obj->createContentPage(LSOPageType::INTRO);
157  $new_copg_id = $new_obj->getContentPageId();
158  $original_page = new \ilLSOIntroPage($old_intro_page_id);
159  $original_page->copy($new_copg_id, $type, $new_copg_id);
160  }
161  if ($type === 'lsoe') {
163  $new_copg_id = $new_obj->getContentPageId();
164  $original_page = new ilLSOExtroPage($old_intro_page_id);
165  $original_page->copy($new_copg_id, $type, $new_copg_id);
166  }
167  }
168  }
169 
170  protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj): bool
171  {
172  $admin = $this->getDefaultAdminRole();
173  $new_admin = $new_obj->getDefaultAdminRole();
174 
175  if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
176  $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
177  }
178 
179  $this->rbac_admin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
180  $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
181 
182  $member = $this->getDefaultMemberRole();
183  $new_member = $new_obj->getDefaultMemberRole();
184 
185  if (!$member || !$new_member) {
186  $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
187  }
188 
189  $this->rbac_admin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
190  $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
191 
192  return true;
193  }
194 
195  protected function cloneSettings(ilObjLearningSequence $new_obj): void
196  {
197  $source = $this->getLSSettings();
198  $target = $new_obj->getLSSettings();
199 
200  foreach ($source->getUploads() as $key => $upload_info) {
201  $target = $target->withUpload($upload_info, $key);
202  }
203 
204  foreach ($source->getDeletions() as $deletion) {
205  $target = $target->withDeletion($deletion);
206  }
207 
208  $target = $target
209  ->withAbstract($source->getAbstract())
210  ->withExtro($source->getExtro())
211  ->withAbstractImage($source->getAbstractImage())
212  ->withExtroImage($source->getExtroImage())
213  ;
214 
215  $new_obj->updateSettings($target);
216  }
217 
218  protected function cloneLPSettings(int $obj_id): void
219  {
220  $lp_settings = new ilLPObjSettings($this->getId());
221  $lp_settings->cloneSettings($obj_id);
222  }
223 
224  protected function cloneActivation(ilObjLearningSequence $new_obj, int $a_copy_id): void
225  {
226  // #14596
227  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
228  if ($cwo->isRootNode($this->getRefId())) {
229  $activation = $new_obj->getLSActivation()->withIsOnline(false);
230  } else {
231  $activation = $new_obj->getLSActivation()
232  ->withIsOnline($this->getLSActivation()->getIsOnline())
233  ->withActivationStart($this->getLSActivation()->getActivationStart())
234  ->withActivationEnd($this->getLSActivation()->getActivationEnd());
235  }
236 
237  $new_status = ($new_obj->getLSActivation()->getEffectiveOnlineStatus())
238  ? $new_obj->getObjectProperties()->getPropertyIsOnline()->withOnline()
239  : $new_obj->getObjectProperties()->getPropertyIsOnline()->withOffline();
240  $new_obj->getObjectProperties()->storePropertyIsOnline($new_status);
241 
242  $new_obj->getActivationDB()->store(
243  $activation
244  );
245  }
246 
247  protected function getDIC(): ArrayAccess
248  {
249  return $this->dic;
250  }
251 
252  public function getDI(): ArrayAccess
253  {
254  if (is_null($this->di)) {
255  $di = new ilLSDI();
256  $di->init($this->getDIC());
257  $this->di = $di;
258  }
259  return $this->di;
260  }
261 
262  public function getLocalDI(): ArrayAccess
263  {
264  if (is_null($this->local_di)) {
265  $di = new ilLSLocalDI();
266  $di->init(
267  $this->getDIC(),
268  $this->getDI(),
269  new \ILIAS\Data\Factory(),
270  $this
271  );
272  $this->local_di = $di;
273  }
274  return $this->local_di;
275  }
276 
278  {
279  if (!$this->settings_db) {
280  $this->settings_db = $this->getDI()['db.settings'];
281  }
282  return $this->settings_db;
283  }
284 
286  {
287  if (!$this->activation_db) {
288  $this->activation_db = $this->getDI()['db.activation'];
289  }
290  return $this->activation_db;
291  }
292 
294  {
295  if (!$this->ls_activation) {
296  $this->ls_activation = $this->getActivationDB()->getActivationForRefId($this->getRefId());
297  }
298 
299  return $this->ls_activation;
300  }
301 
302  public function updateActivation(ilLearningSequenceActivation $settings): void
303  {
304  $this->getActivationDB()->store($settings);
305  $this->ls_activation = $settings;
306  }
307 
309  {
310  if (!$this->ls_settings) {
311  $this->ls_settings = $this->getSettingsDB()->getSettingsFor($this->getId());
312  }
313 
314  return $this->ls_settings;
315  }
316 
317  public function updateSettings(ilLearningSequenceSettings $settings): void
318  {
319  $this->getSettingsDB()->store($settings);
320  $this->ls_settings = $settings;
321  }
322 
323  protected function getLSItemsDB(): ilLSItemsDB
324  {
325  if (!$this->items_db) {
326  $this->items_db = $this->getLocalDI()['db.lsitems'];
327  }
328  return $this->items_db;
329  }
330 
332  {
333  if (!$this->conditions_db) {
334  $this->conditions_db = $this->getDI()["db.postconditions"];
335  }
336  return $this->conditions_db;
337  }
338 
340  {
341  if (!$this->ls_participants) {
342  $this->ls_participants = $this->getLocalDI()['participants'];
343  }
344 
345  return $this->ls_participants;
346  }
347  public function getMembersObject(): \ilLearningSequenceParticipants //used by Services/Membership/classes/class.ilMembershipGUI.php
348  {
349  return $this->getLSParticipants();
350  }
351 
353  {
354  if (is_null($this->ls_access)) {
355  $this->ls_access = new ilObjLearningSequenceAccess();
356  }
357 
358  return $this->ls_access;
359  }
360 
364  public function getLSItems(): array
365  {
366  $db = $this->getLSItemsDB();
367  return $db->getLSItems($this->getRefId());
368  }
369 
374  public function storeLSItems(array $ls_items): void
375  {
376  $db = $this->getLSItemsDB();
377  $db->storeItems($ls_items);
378  }
379 
384  public function deletePostConditionsForSubObjects(array $ref_ids): void
385  {
386  $rep_utils = new ilRepUtil();
387  $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
388  $db = $this->getPostConditionDB();
389  $db->delete($ref_ids);
390  }
391 
395  public function getPossiblePostConditionsForType(string $type): array
396  {
397  $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
398  $conditions = [
399  $this->getPostConditionDB()::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
400  ];
401  foreach ($condition_types as $cond_type) {
402  $conditions[$cond_type] = $this->lng->txt('condition_' . $cond_type);
403  }
404  return $conditions;
405  }
406 
408  {
409  if (!$this->learner_progress_db) {
410  $this->learner_progress_db = $this->getLocalDI()['db.progress'];
411  }
413  }
414 
415  public function getStateDB(): ilLSStateDB
416  {
417  if (!$this->state_db) {
418  $this->state_db = $this->getDI()['db.states'];
419  }
420  return $this->state_db;
421  }
422 
426  public function getLSLearnerItems(int $usr_id): array
427  {
428  $db = $this->getLearnerProgressDB();
429  return $db->getLearnerItems($usr_id, $this->getRefId());
430  }
431 
433  {
434  if (!$this->ls_roles) {
435  $this->ls_roles = $this->getLocalDI()['roles'];
436  }
437  return $this->ls_roles;
438  }
439 
443  public function getMailToMembersType(): int
444  {
445  return 0;
446  }
447 
451  public static function _goto(string $target, string $add = ""): void
452  {
453  global $DIC;
454  $main_tpl = $DIC->ui()->mainTemplate();
455 
456  $ilAccess = $DIC['ilAccess'];
457  $ilErr = $DIC['ilErr'];
458  $lng = $DIC['lng'];
459  $ilUser = $DIC['ilUser'];
460  $request_wrapper = $DIC->http()->wrapper()->query();
461  $refinery = $DIC->refinery();
462 
463  if (substr($add, 0, 5) == 'rcode') {
464  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
465  $request_target = $request_wrapper->retrieve("target", $refinery->kindlyTo()->string());
466  // Redirect to login for anonymous
468  "login.php?target=" . $request_target . "&cmd=force_login&lang=" .
469  $ilUser->getCurrentLanguage()
470  );
471  }
472 
473  // Redirects to target location after assigning user to learning sequence
475  $target,
477  substr($add, 5)
478  );
479  }
480 
481  if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
482  ilObjectGUI::_gotoRepositoryNode($target, "members");
483  }
484 
485  if ($ilAccess->checkAccess("read", "", $target)) {
487  } else {
488  // to do: force flat view
489  if ($ilAccess->checkAccess("visible", "", $target)) {
490  ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
491  } else {
492  if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
493  $main_tpl->setOnScreenMessage('failure', sprintf(
494  $lng->txt("msg_no_perm_read_item"),
496  ), true);
498  }
499  }
500  }
501 
502  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
503  }
504 
505  public function getShowMembers(): bool
506  {
507  return $this->getLSSettings()->getMembersGallery();
508  }
509 
510  public function announceLSOOnline(): void
511  {
512  $ns = $this->il_news;
513  $context = $ns->contextForRefId($this->getRefId());
514  $item = $ns->item($context);
515  $item->setContentIsLangVar(true);
516  $item->setContentTextIsLangVar(true);
517  $item->setTitle("lso_news_online_title");
518  $item->setContent("lso_news_online_txt");
519  $ns->data()->save($item);
520  }
521  public function announceLSOOffline(): void
522  {
523  //NYI
524  }
525 
526  public function setEffectiveOnlineStatus(bool $status): void
527  {
528  $act_db = $this->getActivationDB();
529  $act_db->setEffectiveOnlineStatus($this->getRefId(), $status);
530  }
531 
532  public function getCurrentUserCurriculum(): string
533  {
534  $dic = $this->getLocalDI();
535  $curriculum = $dic["player.curriculumbuilder"]->getLearnerCurriculum(false);
536  return $dic['ui.renderer']->render($curriculum);
537  }
538 
539  public function getCurrentUserLaunchButtons(): string
540  {
541  $dic = $this->getLocalDI();
542  $buttons = $dic["player.launchlinksbuilder"]->getLaunchbuttonsComponent();
543  return $dic['ui.renderer']->render($buttons);
544  }
545 
546 
547  /***************************************************************************
548  * Role Stuff
549  ***************************************************************************/
553  public function getLocalLearningSequenceRoles(bool $translate = false): array
554  {
555  return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
556  }
557 
558  public function getDefaultMemberRole(): int
559  {
560  return $this->getLSRoles()->getDefaultMemberRole();
561  }
562 
563  public function getDefaultAdminRole(): int
564  {
565  return $this->getLSRoles()->getDefaultAdminRole();
566  }
567 
571  public function getDefaultLearningSequenceRoles(string $a_grp_id = ""): array
572  {
573  return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
574  }
575 
576  public function initDefaultRoles(): void
577  {
578  $this->getLSRoles()->initDefaultRoles();
579  }
580 
586  public function readMemberData(array $user_ids, ?array $columns = null): array
587  {
588  return $this->getLsRoles()->readMemberData($user_ids, $columns);
589  }
590 
591  public function getParentObjectInfo(int $ref_id, array $search_types): ?array
592  {
593  foreach ($this->tree->getPathFull($ref_id) as $hop) {
594  if (in_array($hop['type'], $search_types)) {
595  return $hop;
596  }
597  }
598  return null;
599  }
600 
604  public function getLPCompletionStates(): array
605  {
606  return [
608  ];
609  }
610 
611  public function getContentPageId(): int
612  {
613  return $this->getId();
614  }
615 
616  public function hasContentPage(LSOPageType $page_type): bool
617  {
618  return ilContainerPage::_exists($page_type->value, $this->getContentPageId());
619  }
620 
621  public function createContentPage(LSOPageType $page_type): void
622  {
623  if ($this->hasContentPage($page_type)) {
624  throw new \LogicException('will not create content page - it already exists.');
625  }
626  $new_page_object = $page_type === LSOPageType::INTRO ? new ilLSOIntroPage() : new ilLSOExtroPage();
627  $new_page_object->setId($this->getContentPageId());
628  $new_page_object->setParentId($this->getId());
629  $new_page_object->createFromXML();
630  }
631 
632  public function getContentPageHTML(LSOPageType $page_type): string
633  {
634  if (!$this->hasContentPage($page_type)) {
635  return '';
636  }
637 
638  $gui = $page_type === LSOPageType::INTRO ?
639  new ilObjLearningSequenceEditIntroGUI(LSOPageType::INTRO->value, $this->getContentPageId()) :
641 
642  $gui->setPresentationTitle("");
643  $gui->setTemplateOutput(false);
644  $gui->setHeader("");
645  $ret = $gui->showPage();
646  return $ret;
647  }
648 }
const LP_STATUS_COMPLETED_NUM
static handleCode(int $a_ref_id, string $a_type, string $a_code)
Storage for ilLSPostConditions.
string $type
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:31
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...
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:24
cloneSettings(ilObjLearningSequence $new_obj)
const ROOT_FOLDER_ID
Definition: constants.php:32
Interface Observer Contains several chained tasks and infos about them.
getDefaultLearningSequenceRoles(string $a_grp_id="")
static _gotoRepositoryNode(int $ref_id, string $cmd="")
__construct(int $id=0, bool $call_by_reference=true)
Class ilObjLearningSequenceEditExtroGUI ilObjLearningSequenceEditExtroGUI: ilPageEditorGUI, ilEditClipboardGUI.
Class ilObjLearningSequenceEditIntroGUI ilObjLearningSequenceEditIntroGUI: ilPageEditorGUI, ilEditClipboardGUI.
ilLearningSequenceSettingsDB $settings_db
hasContentPage(LSOPageType $page_type)
createContentPage(LSOPageType $page_type)
$ilErr
Definition: raiseError.php:33
static _lookupObjId(int $ref_id)
getLocalLearningSequenceRoles(bool $translate=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
cloneMetaData(ilObject $target_obj)
Copy meta data.
ilLearningSequenceActivationDB $activation_db
static _lookupTitle(int $obj_id)
Settings for an LSO (like abstract, extro)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
ilLanguage $lng
LSOPageType
Definition: LSOPageType.php:21
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
global $DIC
Definition: shib_login.php:26
Persistence for View-States.
cloneIntroAndExtroContentPages(ilObjLearningSequence $new_obj, array $cp_types)
Class ilContainer.
Persistence for Settings (like abstract, extro)
readMemberData(array $user_ids, ?array $columns=null)
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.
getContentPageHTML(LSOPageType $page_type)
static redirect(string $a_script)
ilLearningSequenceParticipants $ls_participants
Get LearningProgress and availability of items in sequence.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
ilConditionHandler $il_condition_handler
static _goto(string $target, string $add="")
Goto target learning sequence.
ilObjLearningSequenceAccess $ls_access
Persistence for online/activation period.
ilLearnerProgressDB $learner_progress_db
static _getInstance(int $a_copy_id)
static _lookupType(int $id, bool $reference=false)
updateActivation(ilLearningSequenceActivation $settings)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
storeLSItems(array $ls_items)
Update LSItems.