ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $state_db;
46
50 protected $ls_roles;
51
52 /*
53 * @var ilLearningSequenceSettingsDB
54 */
55 protected $settings_db;
56
57 /*
58 * @var ilLearningSequenceSettingsDB
59 */
60 protected $activation_db;
61
62 /*
63 * @var ilLearningSequenceActivation
64 */
65 protected $ls_activation;
66
67
68 public function __construct(int $id = 0, bool $call_by_reference = true)
69 {
70 global $DIC;
71 $this->dic = $DIC;
72
73 $this->type = self::OBJ_TYPE;
74 $this->lng = $DIC['lng'];
75 $this->ctrl = $DIC['ilCtrl'];
76 $this->user = $DIC['ilUser'];
77 $this->tree = $DIC['tree'];
78 $this->log = $DIC["ilLoggerFactory"]->getRootLogger();
79 $this->rbacadmin = $DIC['rbacadmin'];
80 $this->app_event_handler = $DIC['ilAppEventHandler'];
81 $this->il_news = $DIC->news();
82 $this->il_condition_handler = new ilConditionHandler();
83
84 parent::__construct($id, $call_by_reference);
85
86 $this->lng->loadLanguageModule('rbac');
87 }
88
89 public static function getInstanceByRefId(int $ref_id)
90 {
92 }
93
94 public function read()
95 {
96 $this->getLSSettings();
97 if ($this->getRefId()) {
98 $this->getLSActivation();
99 }
100 parent::read();
101 }
102
103 public function create() : int
104 {
105 $id = parent::create();
106 if (!$id) {
107 return 0;
108 }
109 $this->raiseEvent(self::E_CREATE);
110
111 return (int) $this->getId();
112 }
113
114 public function update() : bool
115 {
116 if (!parent::update()) {
117 return false;
118 }
119 $this->raiseEvent(self::E_UPDATE);
120
121 return true;
122 }
123
124 public function delete() : bool
125 {
126 if (!parent::delete()) {
127 return false;
128 }
129
131 $this->getSettingsDB()->delete((int) $this->getId());
132 $this->getStateDB()->deleteFor((int) $this->getRefId());
133 $this->getActivationDB()->deleteForRefId((int) $this->getRefId());
134
135 $this->raiseEvent(self::E_DELETE);
136
137 return true;
138 }
139
140 protected function raiseEvent(string $event_type)
141 {
142 $this->app_event_handler->raise(
143 'Modules/LearningSequence',
144 $event_type,
145 array(
146 'obj_id' => $this->getId(),
147 'appointments' => null
148 )
149 );
150 }
151
152 public function cloneObject($target_id, $copy_id = 0, $omit_tree = false)
153 {
154 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
155
156 $this->cloneAutoGeneratedRoles($new_obj);
157 $this->cloneMetaData($new_obj);
158 $this->cloneSettings($new_obj);
159 $this->cloneLPSettings((int) $new_obj->getId());
160 $this->cloneActivation($new_obj, (int) $copy_id);
161
162 $roles = $new_obj->getLSRoles();
163 $roles->addLSMember(
164 (int) $this->user->getId(),
165 $roles->getDefaultAdminRole()
166 );
167 return $new_obj;
168 }
169
170
171 protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj) : bool
172 {
173 $admin = $this->getDefaultAdminRole();
174 $new_admin = $new_obj->getDefaultAdminRole();
175
176 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
177 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
178 }
179
180 $this->rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
181 $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
182
183 $member = $this->getDefaultMemberRole();
184 $new_member = $new_obj->getDefaultMemberRole();
185
186 if (!$member || !$new_member) {
187 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
188 }
189
190 $this->rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
191 $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
192
193 return true;
194 }
195
196 protected function cloneSettings(ilObjLearningSequence $new_obj)
197 {
198 $source = $this->getLSSettings();
199 $target = $new_obj->getLSSettings();
200
201 foreach ($source->getUploads() as $key => $upload_info) {
202 $target = $target->withUpload($upload_info, $key);
203 }
204
205 foreach ($source->getDeletions() as $deletion) {
206 $target = $target->withDeletion($deletion);
207 }
208
209 $target = $target
210 ->withAbstract($source->getAbstract())
211 ->withExtro($source->getExtro())
212 ->withAbstractImage($source->getAbstractImage())
213 ->withExtroImage($source->getExtroImage())
214 ;
215
216 $new_obj->updateSettings($target);
217 }
218
219 protected function cloneLPSettings(int $obj_id)
220 {
221 $lp_settings = new ilLPObjSettings($this->getId());
222 $lp_settings->cloneSettings($obj_id);
223 }
224
225 protected function cloneActivation(ilObjLearningSequence $new_obj, int $a_copy_id) : void
226 {
227 // #14596
228 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
229 if ($cwo->isRootNode($this->getRefId())) {
230 $activation = $new_obj->getLSActivation()->withIsOnline(false);
231 } else {
232 $activation = $new_obj->getLSActivation()
233 ->withIsOnline($this->getLSActivation()->getIsOnline())
234 ->withActivationStart($this->getLSActivation()->getActivationStart())
235 ->withActivationEnd($this->getLSActivation()->getActivationEnd());
236 }
237
238 $new_obj->getActivationDB()->store(
239 $activation
240 );
241 }
242
243 protected function getDIC() : \ArrayAccess
244 {
245 return $this->dic;
246 }
247
248 public function getDI() : \ArrayAccess
249 {
250 if (is_null($this->di)) {
251 $di = new ilLSDI();
252 $di->init($this->getDIC());
253 $this->di = $di;
254 }
255 return $this->di;
256 }
257
258 public function getLocalDI() : \ArrayAccess
259 {
260 if (is_null($this->local_di)) {
261 $di = new ilLSLocalDI();
262 $di->init(
263 $this->getDIC(),
264 $this->getDI(),
265 new \ILIAS\Data\Factory(),
266 $this
267 );
268 $this->local_di = $di;
269 }
270 return $this->local_di;
271 }
272
274 {
275 if (!$this->settings_db) {
276 $this->settings_db = $this->getDI()['db.settings'];
277 }
278 return $this->settings_db;
279 }
280
282 {
283 if (!$this->activation_db) {
284 $this->activation_db = $this->getDI()['db.activation'];
285 }
287 }
288
290 {
291 if (!$this->ls_activation) {
292 $this->ls_activation = $this->getActivationDB()->getActivationForRefId((int) $this->getRefId());
293 }
294
296 }
297
299 {
300 $this->getActivationDB()->store($settings);
301 $this->ls_activation = $settings;
302 }
303
305 {
306 if (!$this->ls_settings) {
307 $this->ls_settings = $this->getSettingsDB()->getSettingsFor((int) $this->getId());
308 }
309
310 return $this->ls_settings;
311 }
312
314 {
315 $this->getSettingsDB()->store($settings);
316 $this->ls_settings = $settings;
317 }
318
319 protected function getLSItemsDB() : ilLSItemsDB
320 {
321 if (!$this->items_db) {
322 $this->items_db = $this->getLocalDI()['db.lsitems'];
323 }
324 return $this->items_db;
325 }
326
328 {
329 if (!$this->conditions_db) {
330 $this->conditions_db = $this->getDI()["db.postconditions"];
331 }
333 }
334
336 {
337 if (!$this->ls_participant) {
338 $this->ls_participant = $this->getLocalDI()['participants'];
339 }
340
342 }
343 public function getMembersObject() //used by Services/Membership/classes/class.ilMembershipGUI.php
344 {
345 return $this->getLSParticipants();
346 }
347
349 {
350 if (is_null($this->ls_access)) {
351 $this->ls_access = new ilObjLearningSequenceAccess();
352 }
353
354 return $this->ls_access;
355 }
356
360 public function getLSItems() : array
361 {
362 $db = $this->getLSItemsDB();
363 return $db->getLSItems((int) $this->getRefId());
364 }
365
370 public function storeLSItems(array $ls_items)
371 {
372 $db = $this->getLSItemsDB();
373 $db->storeItems($ls_items);
374 }
375
380 public function deletePostConditionsForSubObjects(array $ref_ids)
381 {
382 $rep_utils = new ilRepUtil();
383 $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
384 $db = $this->getPostConditionDB();
385 $db->delete($ref_ids);
386 }
387
391 public function getPossiblePostConditionsForType(string $type) : array
392 {
393 $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
394 $conditions = [
395 $this->getPostConditionDB()::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
396 ];
397 foreach ($condition_types as $cond_type) {
398 $conditions[$cond_type] = $this->lng->txt('condition_' . $cond_type);
399 }
400 return $conditions;
401 }
402
404 {
405 if (!$this->learner_progress_db) {
406 $this->learner_progress_db = $this->getLocalDI()['db.progress'];
407 }
409 }
410
411 //protected function getStateDB(): ilLSStateDB
412 public function getStateDB() : ilLSStateDB
413 {
414 if (!$this->state_db) {
415 $this->state_db = $this->getDI()['db.states'];
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());
427 }
428
430 {
431 if (!$this->ls_roles) {
432 $this->ls_roles = $this->getLocalDI()['roles'];
433 }
434 return $this->ls_roles;
435 }
436
441 public function getMailToMembersType()
442 {
443 return $this->mail_members;
444 }
445
452 public static function _goto($target, $add = "")
453 {
454 global $DIC;
455
456 $ilAccess = $DIC['ilAccess'];
457 $ilErr = $DIC['ilErr'];
458 $lng = $DIC['lng'];
459 $ilUser = $DIC['ilUser'];
460
461 if (substr($add, 0, 5) == 'rcode') {
462 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
463 // Redirect to login for anonymous
465 "login.php?target=" . $_GET["target"] . "&cmd=force_login&lang=" .
466 $ilUser->getCurrentLanguage()
467 );
468 }
469
470 // Redirects to target location after assigning user to learning sequence
472 $target,
474 substr($add, 5)
475 );
476 }
477
478 if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
479 ilObjectGUI::_gotoRepositoryNode($target, "members");
480 }
481
482 if ($ilAccess->checkAccess("read", "", $target)) {
484 } else {
485 // to do: force flat view
486 if ($ilAccess->checkAccess("visible", "", $target)) {
487 ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
488 } else {
489 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
491 sprintf(
492 $lng->txt("msg_no_perm_read_item"),
494 ),
495 true
496 );
498 }
499 }
500 }
501
502 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
503 }
504
505 public function getShowMembers()
506 {
507 return $this->getLSSettings()->getMembersGallery();
508 }
509
510 public function announceLSOOnline()
511 {
512 $ns = $this->il_news;
513 $context = $ns->contextForRefId((int) $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 $news_id = $ns->data()->save($item);
520 }
521 public function announceLSOOffline()
522 {
523 //NYI
524 }
525
526 public function setEffectiveOnlineStatus(bool $status)
527 {
528 $act_db = $this->getActivationDB();
529 $act_db->setEffectiveOnlineStatus((int) $this->getRefId(), $status);
530 }
531
532 /***************************************************************************
533 * Role Stuff
534 ***************************************************************************/
535 public function getLocalLearningSequenceRoles(bool $translate = false) : array
536 {
537 return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
538 }
539
540 public function getDefaultMemberRole() : int
541 {
542 return $this->getLSRoles()->getDefaultMemberRole();
543 }
544
545 public function getDefaultAdminRole()
546 {
547 return $this->getLSRoles()->getDefaultAdminRole();
548 }
549
550 public function getLearningSequenceMemberData($a_mem_ids, $active = 1)
551 {
552 return $this->getLSRoles()->getLearningSequenceMemberData($a_mem_ids, $active);
553 }
554
555 public function getDefaultLearningSequenceRoles($a_grp_id = "")
556 {
557 return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
558 }
559
560 public function initDefaultRoles()
561 {
562 return $this->getLSRoles()->initDefaultRoles();
563 }
564
565 public function readMemberData(array $user_ids, array $columns = null)
566 {
567 return $this->getLsRoles()->readMemberData($user_ids, $columns);
568 }
569
570 public function getParentObjectInfo(int $ref_id, array $search_types)
571 {
572 foreach ($this->tree->getPathFull($ref_id) as $hop) {
573 if (in_array($hop['type'], $search_types)) {
574 return $hop;
575 }
576 }
577 return null;
578 }
579
580 public function getLPCompletionStates() : array
581 {
582 return [
584 ];
585 }
586}
user()
Definition: user.php:4
if(! $in) $columns
Definition: Utf8Test.php:45
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
INTERNAL CLASS: Please do not use in consumer code.
Class ilContainer.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
const LP_STATUS_COMPLETED_NUM
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:12
Storage for ilLSPostConditions.
Persistence for View-States.
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)
cloneActivation(ilObjLearningSequence $new_obj, int $a_copy_id)
getLSLearnerItems(int $usr_id)
Get a list of LSLearnerItems.
getParentObjectInfo(int $ref_id, array $search_types)
static _goto($target, $add="")
Goto target learning sequence.
static getInstanceByRefId(int $ref_id)
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
storeLSItems(array $ls_items)
Update LSItems.
getLocalLearningSequenceRoles(bool $translate=false)
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
static _deleteAllEntries($a_obj_id)
Delete all entries Normally called for course deletion.
Repository Utilities (application layer, put GUI related stuff into ilRepUtilGUI)
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const ANONYMOUS_USER_ID
Definition: constants.php:25
const ROOT_FOLDER_ID
Definition: constants.php:30
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
$ilUser
Definition: imgupload.php:18
$source
Definition: metadata.php:76
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$ilErr
Definition: raiseError.php:18
$dic
Definition: result.php:13
$context
Definition: webdav.php:26