ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.ilObjLearningSequence.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
27{
28 public const OBJ_TYPE = 'lso';
29
30 public const E_CREATE = 'create';
31 public const E_UPDATE = 'update';
32 public const E_DELETE = 'delete';
33
34 protected ?ilLSItemsDB $items_db = null;
39 protected ?ilLSStateDB $state_db = null;
42 protected ?ilLearningSequenceActivationDB $activation_db = null;
43 protected ?ilLearningSequenceActivation $ls_activation = null;
44 protected ?ArrayAccess $di = null;
45 protected ?ArrayAccess $local_di = null;
47 protected ArrayAccess $dic;
48 protected ilCtrl $ctrl;
49 protected \ILIAS\News\Service $il_news;
51 protected ReferencePropertiesRepository $repo_ref_props;
53
54 public function __construct(int $id = 0, bool $call_by_reference = true)
55 {
56 global $DIC;
57 $this->dic = $DIC;
58
59 $this->type = self::OBJ_TYPE;
60 $this->lng = $DIC['lng'];
61 $this->ctrl = $DIC['ilCtrl'];
62 $this->user = $DIC['ilUser'];
63 $this->tree = $DIC['tree'];
64 $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
65 $this->app_event_handler = $DIC['ilAppEventHandler'];
66 $this->il_news = $DIC->news();
67 $this->il_condition_handler = new ilConditionHandler();
68 $this->repo_ref_props = LocalDIC::dic()['properties.object_reference.repositoy'];
70
71 $this->lng->loadLanguageModule('rbac');
72 }
73
74 public static function getInstanceByRefId(int $ref_id): ?\ilObject
75 {
77 }
78
79 public function read(): void
80 {
81 parent::read();
82 $this->getLSSettings();
83 try {
84 $this->ref_props = $this->repo_ref_props->getFor($this->getRefId());
85 } catch (\Exception $e) {
86 $this->ref_props = $this->repo_ref_props->getFor(null);
87 $this->repo_ref_props->storePropertyAvailabilityPeriod(
88 $this->ref_props->getPropertyAvailabilityPeriod()
89 ->withObjectReferenceId($this->getRefId())
90 );
91 }
92 }
93
94 public function create(): int
95 {
96 $id = parent::create();
97 if (!$id) {
98 return 0;
99 }
100 $this->ref_props = $this->repo_ref_props->getFor(null);
101 $this->raiseEvent(self::E_CREATE);
102
103 return $this->getId();
104 }
105
106 public function update(): bool
107 {
108 if (!parent::update()) {
109 return false;
110 }
111 $this->raiseEvent(self::E_UPDATE);
112
113 return true;
114 }
115
116 public function delete(): bool
117 {
118 if (!parent::delete()) {
119 return false;
120 }
121
123 $this->getSettingsDB()->delete($this->getId());
124 $this->getStateDB()->deleteFor($this->getRefId());
125
126 $this->raiseEvent(self::E_DELETE);
127
128 return true;
129 }
130
131 protected function raiseEvent(string $event_type): void
132 {
133 $this->app_event_handler->raise(
134 'components/ILIAS/LearningSequence',
135 $event_type,
136 array(
137 'obj_id' => $this->getId(),
138 'appointments' => null
139 )
140 );
141 }
142
144 {
145 return $this->ref_props;
146 }
147
148 public function storeAvailabilityPeriod(AvailabilityPeriod $period): void
149 {
150 $this->repo_ref_props->storePropertyAvailabilityPeriod($period);
151 }
152
153 public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
154 {
156 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
157
158 $this->cloneAutoGeneratedRoles($new_obj);
159 $this->cloneMetaData($new_obj);
160 $this->cloneSettings($new_obj);
161 $this->cloneLPSettings($new_obj->getId());
162 $this->cloneIntroAndExtroContentPages($new_obj, [LSOPageType::INTRO, LSOPageType::EXTRO]);
163
164 $online = $this->getObjectProperties()->getPropertyIsOnline();
165 $cwo = ilCopyWizardOptions::_getInstance($copy_id);
166 if ($cwo->isRootNode($this->getRefId())) {
167 $online = $online->withOffline();
168 }
169 $new_obj->getObjectProperties()->storePropertyIsOnline($online);
170
171 $new_obj->repo_ref_props->storePropertyAvailabilityPeriod(
172 $this->ref_props->getPropertyAvailabilityPeriod()
173 ->withObjectReferenceId($new_obj->getRefId())
174 );
175
176 $roles = $new_obj->getLSRoles();
177 $roles->addLSMember(
178 $this->user->getId(),
179 $roles->getDefaultAdminRole()
180 );
181 return $new_obj;
182 }
183
187 protected function cloneIntroAndExtroContentPages(ilObjLearningSequence $new_obj, array $cp_types): void
188 {
189 foreach ($cp_types as $type) {
190 $new_obj->createContentPage($type);
191 if ($this->hasContentPage($type)) {
192 $target_page_id = $new_obj->getContentPageId();
193 $source_page_id = $this->getContentPageId();
194
195 if ($type === LSOPageType::INTRO) {
196 $source_page = new ilLSOIntroPage($source_page_id);
197 } else {
198 $source_page = new ilLSOExtroPage($source_page_id);
199 }
200 $source_page->copy($target_page_id, $type->value, $target_page_id);
201 }
202 }
203 }
204
205 protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj): bool
206 {
207 $admin = $this->getDefaultAdminRole();
208 $new_admin = $new_obj->getDefaultAdminRole();
209
210 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
211 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
212 }
213
214 $this->rbac_admin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
215 $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
216
217 $member = $this->getDefaultMemberRole();
218 $new_member = $new_obj->getDefaultMemberRole();
219
220 if (!$member || !$new_member) {
221 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
222 }
223
224 $this->rbac_admin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
225 $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
226
227 return true;
228 }
229
230 protected function cloneSettings(ilObjLearningSequence $new_obj): void
231 {
232 $source = $this->getLSSettings();
233 $target = $new_obj->getLSSettings();
234
235 foreach ($source->getUploads() as $key => $upload_info) {
236 $target = $target->withUpload($upload_info, $key);
237 }
238
239 foreach ($source->getDeletions() as $deletion) {
240 $target = $target->withDeletion($deletion);
241 }
242
243 $target = $target
244 ->withAbstract($source->getAbstract())
245 ->withExtro($source->getExtro())
246 ->withAbstractImage($source->getAbstractImage())
247 ->withExtroImage($source->getExtroImage())
248 ;
249
250 $new_obj->updateSettings($target);
251 }
252
253 protected function cloneLPSettings(int $obj_id): void
254 {
255 $lp_settings = new ilLPObjSettings($this->getId());
256 $lp_settings->cloneSettings($obj_id);
257 }
258
259 protected function getDIC(): ArrayAccess
260 {
261 return $this->dic;
262 }
263
264 public function getDI(): ArrayAccess
265 {
266 if (is_null($this->di)) {
267 $di = new ilLSDI();
268 $di->init($this->getDIC());
269 $this->di = $di;
270 }
271 return $this->di;
272 }
273
274 public function getLocalDI(): ArrayAccess
275 {
276 if (is_null($this->local_di)) {
277 $di = new ilLSLocalDI();
278 $di->init(
279 $this->getDIC(),
280 $this->getDI(),
281 new \ILIAS\Data\Factory(),
282 $this
283 );
284 $this->local_di = $di;
285 }
286 return $this->local_di;
287 }
288
290 {
291 if (!$this->settings_db) {
292 $this->settings_db = $this->getDI()['db.settings'];
293 }
294 return $this->settings_db;
295 }
296
298 {
299 if (!$this->ls_settings) {
300 $this->ls_settings = $this->getSettingsDB()->getSettingsFor($this->getId());
301 }
302
303 return $this->ls_settings;
304 }
305
306 public function updateSettings(ilLearningSequenceSettings $settings): void
307 {
308 $this->getSettingsDB()->store($settings);
309 $this->ls_settings = $settings;
310 }
311
312 protected function getLSItemsDB(): ilLSItemsDB
313 {
314 if (!$this->items_db) {
315 $this->items_db = $this->getLocalDI()['db.lsitems'];
316 }
317 return $this->items_db;
318 }
319
321 {
322 if (!$this->conditions_db) {
323 $this->conditions_db = $this->getDI()["db.postconditions"];
324 }
326 }
327
329 {
330 if (!$this->ls_participants) {
331 $this->ls_participants = $this->getLocalDI()['participants'];
332 }
333
335 }
336 public function getMembersObject(): \ilLearningSequenceParticipants //used by Services/Membership/classes/class.ilMembershipGUI.php
337 {
338 return $this->getLSParticipants();
339 }
340
342 {
343 if (is_null($this->ls_access)) {
344 $this->ls_access = new ilObjLearningSequenceAccess();
345 }
346
347 return $this->ls_access;
348 }
349
353 public function getLSItems(): array
354 {
355 $db = $this->getLSItemsDB();
356 return $db->getLSItems($this->getRefId());
357 }
358
363 public function storeLSItems(array $ls_items): void
364 {
365 $db = $this->getLSItemsDB();
366 $db->storeItems($ls_items);
367 }
368
373 public function deletePostConditionsForSubObjects(array $ref_ids): void
374 {
375 $rep_utils = new ilRepUtil();
376 $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
377 $db = $this->getPostConditionDB();
378 $db->delete($ref_ids);
379 }
380
384 public function getPossiblePostConditionsForType(string $type): array
385 {
386 $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
387 $conditions = [
388 $this->getPostConditionDB()::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
389 ];
390 foreach ($condition_types as $cond_type) {
391 $conditions[$cond_type] = $this->lng->txt('condition_' . $cond_type);
392 }
393 return $conditions;
394 }
395
397 {
398 if (!$this->learner_progress_db) {
399 $this->learner_progress_db = $this->getLocalDI()['db.progress'];
400 }
402 }
403
404 public function getStateDB(): ilLSStateDB
405 {
406 if (!$this->state_db) {
407 $this->state_db = $this->getDI()['db.states'];
408 }
409 return $this->state_db;
410 }
411
415 public function getLSLearnerItems(int $usr_id): array
416 {
417 $db = $this->getLearnerProgressDB();
418 return $db->getLearnerItems($usr_id, $this->getRefId());
419 }
420
422 {
423 if (!$this->ls_roles) {
424 $this->ls_roles = $this->getLocalDI()['roles'];
425 }
426 return $this->ls_roles;
427 }
428
432 public function getMailToMembersType(): int
433 {
434 return 0;
435 }
436
440 public static function _goto(string $target, string $add = ""): void
441 {
442 global $DIC;
443 $main_tpl = $DIC->ui()->mainTemplate();
444
445 $ilAccess = $DIC['ilAccess'];
446 $ilErr = $DIC['ilErr'];
447 $lng = $DIC['lng'];
448 $ilUser = $DIC['ilUser'];
449 $request_wrapper = $DIC->http()->wrapper()->query();
450 $refinery = $DIC->refinery();
451
452 if (substr($add, 0, 5) == 'rcode') {
453 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
454 $request_target = $request_wrapper->retrieve("target", $refinery->kindlyTo()->string());
455 // Redirect to login for anonymous
457 "login.php?target=" . $request_target . "&cmd=force_login&lang=" .
458 $ilUser->getCurrentLanguage()
459 );
460 }
461
462 // Redirects to target location after assigning user to learning sequence
464 $target,
466 substr($add, 5)
467 );
468 }
469
470 if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
471 ilObjectGUI::_gotoRepositoryNode($target, "members");
472 }
473
474 if ($ilAccess->checkAccess("read", "", $target)) {
476 } else {
477 // to do: force flat view
478 if ($ilAccess->checkAccess("visible", "", $target)) {
479 ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
480 } else {
481 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
482 $main_tpl->setOnScreenMessage('failure', sprintf(
483 $lng->txt("msg_no_perm_read_item"),
485 ), true);
487 }
488 }
489 }
490
491 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
492 }
493
494 public function getShowMembers(): bool
495 {
496 return $this->getLSSettings()->getMembersGallery();
497 }
498
499 public function announceLSOOnline(): void
500 {
501 $ns = $this->il_news;
502 $context = $ns->contextForRefId($this->getRefId());
503 $item = $ns->item($context);
504 $item->setContentIsLangVar(true);
505 $item->setContentTextIsLangVar(true);
506 $item->setTitle("lso_news_online_title");
507 $item->setContent("lso_news_online_txt");
508 $ns->data()->save($item);
509 }
510 public function announceLSOOffline(): void
511 {
512 //NYI
513 }
514
515 public function setEffectiveOnlineStatus(bool $status): void
516 {
517 $act_db = $this->getActivationDB();
518 $act_db->setEffectiveOnlineStatus($this->getRefId(), $status);
519 }
520
521 public function getCurrentUserCurriculum(): string
522 {
523 $dic = $this->getLocalDI();
524 $curriculum = $dic["player.curriculumbuilder"]->getLearnerCurriculum(false);
525 return $dic['ui.renderer']->render($curriculum);
526 }
527
528 public function getCurrentUserLaunchButtons(): string
529 {
530 $dic = $this->getLocalDI();
531 $buttons = $dic["player.launchlinksbuilder"]->getLaunchbuttonsComponent();
532 return $dic['ui.renderer']->render($buttons);
533 }
534
535
536 /***************************************************************************
537 * Role Stuff
538 ***************************************************************************/
542 public function getLocalLearningSequenceRoles(bool $translate = false): array
543 {
544 return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
545 }
546
547 public function getDefaultMemberRole(): int
548 {
549 return $this->getLSRoles()->getDefaultMemberRole();
550 }
551
552 public function getDefaultAdminRole(): int
553 {
554 return $this->getLSRoles()->getDefaultAdminRole();
555 }
556
560 public function getDefaultLearningSequenceRoles(string $a_grp_id = ""): array
561 {
562 return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
563 }
564
565 public function initDefaultRoles(): void
566 {
567 $this->getLSRoles()->initDefaultRoles();
568 }
569
575 public function readMemberData(array $user_ids, ?array $columns = null): array
576 {
577 return $this->getLsRoles()->readMemberData($user_ids, $columns);
578 }
579
580 public function getParentObjectInfo(int $ref_id, array $search_types): ?array
581 {
582 foreach ($this->tree->getPathFull($ref_id) as $hop) {
583 if (in_array($hop['type'], $search_types)) {
584 return $hop;
585 }
586 }
587 return null;
588 }
589
593 public function getLPCompletionStates(): array
594 {
595 return [
597 ];
598 }
599
600 public function getContentPageId(): int
601 {
602 return $this->getId();
603 }
604
605 public function hasContentPage(LSOPageType $page_type): bool
606 {
607 return ilContainerPage::_exists($page_type->value, $this->getContentPageId());
608 }
609
610 public function createContentPage(LSOPageType $page_type): void
611 {
612 if ($this->hasContentPage($page_type)) {
613 throw new \LogicException('will not create content page - it already exists.');
614 }
615 $new_page_object = $page_type === LSOPageType::INTRO ? new ilLSOIntroPage() : new ilLSOExtroPage();
616 $new_page_object->setId($this->getContentPageId());
617 $new_page_object->setParentId($this->getId());
618 $new_page_object->createFromXML();
619 }
620
621 public function getContentPageHTML(LSOPageType $page_type): string
622 {
623 if (!$this->hasContentPage($page_type)) {
624 return '';
625 }
626
627 $gui = $page_type === LSOPageType::INTRO ?
628 new ilObjLearningSequenceEditIntroGUI(LSOPageType::INTRO->value, $this->getContentPageId()) :
630
631 $gui->setPresentationTitle("");
632 $gui->setTemplateOutput(false);
633 $gui->setHeader("");
634 $ret = $gui->showPage();
635 return $ret;
636 }
637}
$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 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.
ReferencePropertiesRepository $repo_ref_props
cloneSettings(ilObjLearningSequence $new_obj)
cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj)
ilLearnerProgressDB $learner_progress_db
getDefaultLearningSequenceRoles(string $a_grp_id="")
readMemberData(array $user_ids, ?array $columns=null)
getParentObjectInfo(int $ref_id, array $search_types)
storeAvailabilityPeriod(AvailabilityPeriod $period)
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.
ObjectReferenceProperties $ref_props
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