ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
87 public static function getInstanceByRefId(int $ref_id)
88 {
90 }
91
92 public function read()
93 {
94 $this->getLSSettings();
95 if ($this->getRefId()) {
96 $this->getLSActivation();
97 }
98 parent::read();
99 }
100
101 public function create() : int
102 {
103 $id = parent::create();
104 if (!$id) {
105 return 0;
106 }
107 $this->raiseEvent(self::E_CREATE);
108
109 return (int) $this->getId();
110 }
111
112 public function update() : bool
113 {
114 if (!parent::update()) {
115 return false;
116 }
117 $this->raiseEvent(self::E_UPDATE);
118
119 return true;
120 }
121
122 public function delete() : bool
123 {
124 if (!parent::delete()) {
125 return false;
126 }
127
129 $this->getSettingsDB()->delete((int) $this->getId());
130 $this->getStateDB()->deleteFor((int) $this->getRefId());
131 $this->getActivationDB()->deleteForRefId((int) $this->getRefId());
132
133 $this->raiseEvent(self::E_DELETE);
134
135 return true;
136 }
137
138 protected function raiseEvent(string $event_type)
139 {
140 $this->app_event_handler->raise(
141 'Modules/LearningSequence',
142 $event_type,
143 array(
144 'obj_id' => $this->getId(),
145 'appointments' => null
146 )
147 );
148 }
149
150 public function cloneObject($target_id, $copy_id = 0, $omit_tree = false)
151 {
152 $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
153
154 $this->cloneAutoGeneratedRoles($new_obj);
155 $this->cloneMetaData($new_obj);
156 $this->cloneSettings($new_obj);
157 $this->cloneLPSettings((int) $new_obj->getId());
158
159 $roles = $new_obj->getLSRoles();
160 $roles->addLSMember(
161 (int) $this->user->getId(),
162 $roles->getDefaultAdminRole()
163 );
164 return $new_obj;
165 }
166
167
168 protected function cloneAutoGeneratedRoles(ilObjLearningSequence $new_obj) : bool
169 {
170 $admin = $this->getDefaultAdminRole();
171 $new_admin = $new_obj->getDefaultAdminRole();
172
173 if (!$admin || !$new_admin || !$this->getRefId() || !$new_obj->getRefId()) {
174 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_admin');
175 }
176
177 $this->rbacadmin->copyRolePermissions($admin, $this->getRefId(), $new_obj->getRefId(), $new_admin, true);
178 $this->log->write(__METHOD__ . ' : Finished copying of role lso_admin.');
179
180 $member = $this->getDefaultMemberRole();
181 $new_member = $new_obj->getDefaultMemberRole();
182
183 if (!$member || !$new_member) {
184 $this->log->write(__METHOD__ . ' : Error cloning auto generated role: il_lso_member');
185 }
186
187 $this->rbacadmin->copyRolePermissions($member, $this->getRefId(), $new_obj->getRefId(), $new_member, true);
188 $this->log->write(__METHOD__ . ' : Finished copying of role lso_member.');
189
190 return true;
191 }
192
193 protected function cloneSettings(ilObjLearningSequence $new_obj)
194 {
195 $source = $this->getLSSettings();
196 $target = $new_obj->getLSSettings();
197
198 foreach ($source->getUploads() as $key => $upload_info) {
199 $target = $target->withUpload($upload_info, $key);
200 }
201
202 foreach ($source->getDeletions() as $deletion) {
203 $target = $target->withDeletion($deletion);
204 }
205
206 $target = $target
207 ->withAbstract($source->getAbstract())
208 ->withExtro($source->getExtro())
209 ->withAbstractImage($source->getAbstractImage())
210 ->withExtroImage($source->getExtroImage())
211 ;
212
213 $new_obj->updateSettings($target);
214 }
215
216 protected function cloneLPSettings(int $obj_id)
217 {
218 $lp_settings = new ilLPObjSettings($this->getId());
219 $lp_settings->cloneSettings($obj_id);
220 }
221
222
223 protected function getDIC() : \ArrayAccess
224 {
225 return $this->dic;
226 }
227
228 public function getDI() : \ArrayAccess
229 {
230 if (is_null($this->di)) {
231 $di = new ilLSDI();
232 $di->init($this->getDIC());
233 $this->di = $di;
234 }
235 return $this->di;
236 }
237
238 public function getLocalDI() : \ArrayAccess
239 {
240 if (is_null($this->local_di)) {
241 $di = new ilLSLocalDI();
242 $di->init(
243 $this->getDIC(),
244 $this->getDI(),
245 new \ILIAS\Data\Factory(),
246 $this
247 );
248 $this->local_di = $di;
249 }
250 return $this->local_di;
251 }
252
254 {
255 if (!$this->settings_db) {
256 $this->settings_db = $this->getDI()['db.settings'];
257 }
258 return $this->settings_db;
259 }
260
262 {
263 if (!$this->activation_db) {
264 $this->activation_db = $this->getDI()['db.activation'];
265 }
267 }
268
270 {
271 if (!$this->ls_activation) {
272 $this->ls_activation = $this->getActivationDB()->getActivationForRefId((int) $this->getRefId());
273 }
274
276 }
277
279 {
280 $this->getActivationDB()->store($settings);
281 $this->ls_activation = $settings;
282 }
283
285 {
286 if (!$this->ls_settings) {
287 $this->ls_settings = $this->getSettingsDB()->getSettingsFor((int) $this->getId());
288 }
289
290 return $this->ls_settings;
291 }
292
294 {
295 $this->getSettingsDB()->store($settings);
296 $this->ls_settings = $settings;
297 }
298
299 protected function getLSItemsDB() : ilLSItemsDB
300 {
301 if (!$this->items_db) {
302 $this->items_db = $this->getLocalDI()['db.lsitems'];
303 }
304 return $this->items_db;
305 }
306
308 {
309 if (!$this->conditions_db) {
310 $this->conditions_db = $this->getDI()["db.postconditions"];
311 }
313 }
314
316 {
317 if (!$this->ls_participant) {
318 $this->ls_participant = $this->getLocalDI()['participants'];
319 }
320
322 }
323 public function getMembersObject() //used by Services/Membership/classes/class.ilMembershipGUI.php
324 {
325 return $this->getLSParticipants();
326 }
327
329 {
330 if (is_null($this->ls_access)) {
331 $this->ls_access = new ilObjLearningSequenceAccess();
332 }
333
334 return $this->ls_access;
335 }
336
340 public function getLSItems() : array
341 {
342 $db = $this->getLSItemsDB();
343 return $db->getLSItems((int) $this->getRefId());
344 }
345
350 public function storeLSItems(array $ls_items)
351 {
352 $db = $this->getLSItemsDB();
353 $db->storeItems($ls_items);
354 }
355
360 public function deletePostConditionsForSubObjects(array $ref_ids)
361 {
362 $rep_utils = new ilRepUtil();
363 $rep_utils->deleteObjects($this->getRefId(), $ref_ids);
364 $db = $this->getPostConditionDB();
365 $db->delete($ref_ids);
366 }
367
371 public function getPossiblePostConditionsForType(string $type) : array
372 {
373 $condition_types = $this->il_condition_handler->getOperatorsByTriggerType($type);
374 $conditions = [
375 $this->getPostConditionDB()::STD_ALWAYS_OPERATOR => $this->lng->txt('condition_always')
376 ];
377 foreach ($condition_types as $cond_type) {
378 $conditions[$cond_type] = $this->lng->txt($cond_type);
379 }
380 return $conditions;
381 }
382
384 {
385 if (!$this->learner_progress_db) {
386 $this->learner_progress_db = $this->getLocalDI()['db.progress'];
387 }
389 }
390
391 //protected function getStateDB(): ilLSStateDB
392 public function getStateDB() : ilLSStateDB
393 {
394 if (!$this->state_db) {
395 $this->state_db = $this->getDI()['db.states'];
396 }
397 return $this->state_db;
398 }
399
403 public function getLSLearnerItems(int $usr_id) : array
404 {
405 $db = $this->getLearnerProgressDB();
406 return $db->getLearnerItems($usr_id, $this->getRefId());
407 }
408
410 {
411 if (!$this->ls_roles) {
412 $this->ls_roles = $this->getLocalDI()['roles'];
413 }
414 return $this->ls_roles;
415 }
416
421 public function getMailToMembersType()
422 {
423 return $this->mail_members;
424 }
425
432 public static function _goto($target, $add = "")
433 {
434 global $DIC;
435
436 $ilAccess = $DIC['ilAccess'];
437 $ilErr = $DIC['ilErr'];
438 $lng = $DIC['lng'];
439 $ilUser = $DIC['ilUser'];
440
441 if (substr($add, 0, 5) == 'rcode') {
442 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
443 // Redirect to login for anonymous
445 "login.php?target=" . $_GET["target"] . "&cmd=force_login&lang=" .
446 $ilUser->getCurrentLanguage()
447 );
448 }
449
450 // Redirects to target location after assigning user to learning sequence
452 $target,
454 substr($add, 5)
455 );
456 }
457
458 if ($add == "mem" && $ilAccess->checkAccess("manage_members", "", $target)) {
459 ilObjectGUI::_gotoRepositoryNode($target, "members");
460 }
461
462 if ($ilAccess->checkAccess("read", "", $target)) {
464 } else {
465 // to do: force flat view
466 if ($ilAccess->checkAccess("visible", "", $target)) {
467 ilObjectGUI::_gotoRepositoryNode($target, "infoScreenGoto");
468 } else {
469 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
471 sprintf(
472 $lng->txt("msg_no_perm_read_item"),
474 ),
475 true
476 );
478 }
479 }
480 }
481
482 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
483 }
484
485 public function getShowMembers()
486 {
487 return $this->getLSSettings()->getMembersGallery();
488 }
489
490 public function announceLSOOnline()
491 {
492 $ns = $this->il_news;
493 $context = $ns->contextForRefId((int) $this->getRefId());
494 $item = $ns->item($context);
495 $item->setContentIsLangVar(true);
496 $item->setContentTextIsLangVar(true);
497 $item->setTitle("lso_news_online_title");
498 $item->setContent("lso_news_online_txt");
499 $news_id = $ns->data()->save($item);
500 }
501 public function announceLSOOffline()
502 {
503 //NYI
504 }
505
506 public function setEffectiveOnlineStatus(bool $status)
507 {
508 $act_db = $this->getActivationDB();
509 $act_db->setEffectiveOnlineStatus((int) $this->getRefId(), $status);
510 }
511
512 /***************************************************************************
513 * Role Stuff
514 ***************************************************************************/
515 public function getLocalLearningSequenceRoles(bool $translate = false) : array
516 {
517 return $this->getLSRoles()->getLocalLearningSequenceRoles($translate);
518 }
519
520 public function getDefaultMemberRole() : int
521 {
522 return $this->getLSRoles()->getDefaultMemberRole();
523 }
524
525 public function getDefaultAdminRole()
526 {
527 return $this->getLSRoles()->getDefaultAdminRole();
528 }
529
530 public function getLearningSequenceMemberData($a_mem_ids, $active = 1)
531 {
532 return $this->getLSRoles()->getLearningSequenceMemberData($a_mem_ids, $active);
533 }
534
535 public function getDefaultLearningSequenceRoles($a_grp_id = "")
536 {
537 return $this->getLSRoles()->getDefaultLearningSequenceRoles($a_grp_id);
538 }
539
540 public function initDefaultRoles()
541 {
542 return $this->getLSRoles()->initDefaultRoles();
543 }
544
545 public function readMemberData(array $user_ids, array $columns = null)
546 {
547 return $this->getLsRoles()->readMemberData($user_ids, $columns);
548 }
549
550 public function getParentObjectInfo(int $ref_id, array $search_types)
551 {
552 foreach ($this->tree->getPathFull($ref_id) as $hop) {
553 if (in_array($hop['type'], $search_types)) {
554 return $hop;
555 }
556 }
557 return null;
558 }
559
560 public function getLPCompletionStates() : array
561 {
562 return [
564 ];
565 }
566}
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.
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)
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.
$target_id
Definition: goto.php:49
$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
$ilUser
Definition: imgupload.php:18
$context
Definition: webdav.php:26
$DIC
Definition: xapitoken.php:46