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