ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseReferencePathInfo.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
9{
13 private static $instances = [];
14
18 private $logger = null;
19
23 private $tree = null;
24
28 private $access = null;
29
33 private $ref_id = 0;
34
38 private $target_ref_id = 0;
39
40
44 private $has_parent_course = false;
45
50
51
55 private $member_update_enabled = false;
56
57
61 public function __construct(int $ref_id, int $target_ref_id = 0)
62 {
63 global $DIC;
64
65 $this->logger = $DIC->logger()->crsr();
66 $this->tree = $DIC->repositoryTree();
67 $this->access = $DIC->access();
68
69 $this->ref_id = $ref_id;
70 $this->target_ref_id = $target_ref_id;
71 $this->init();
72
73 $this->logger->info('ref_id: ' . $this->ref_id);
74 $this->logger->info('target_ref_id: ' . $this->target_ref_id);
75 $this->logger->info('parent course: ' . $this->parent_course_ref_id);
76 $this->logger->info('has parent course: ' . $this->has_parent_course);
77 }
78
85 {
86 if (!array_key_exists($ref_id, self::$instances)) {
87 self::$instances[$ref_id] = new self($ref_id, $target_ref_id);
88 }
89 return self::$instances[$ref_id];
90 }
91
92
98 public static function isReferenceMemberUpdateConfirmationRequired(int $course_ref_id, array $participants) : bool
99 {
100 global $DIC;
101
102 $tree = $DIC->repositoryTree();
103 $childs = $tree->getChildsByType($course_ref_id, 'crsr');
104 foreach ($childs as $tree_node) {
105 $path_info = self::getInstanceByRefId($tree_node['child']);
106 if (!$path_info->hasParentCourse()) {
107 continue;
108 }
109 if (!$path_info->isMemberUpdateEnabled()) {
110 continue;
111 }
112 if (!$path_info->checkManagmentAccess()) {
113 continue;
114 }
115 $part = ilParticipants::getInstance($path_info->getTargetId());
116 foreach ($participants as $part_id) {
117 if ($part->isMember($part_id)) {
118 return true;
119 }
120 }
121 }
122 return false;
123 }
124
128 public function getParentCourseRefId() : int
129 {
131 }
132
136 public function hasParentCourse() : bool
137 {
139 }
140
144 public function getTargetId() : int
145 {
147 }
148
152 public function isMemberUpdateEnabled() : bool
153 {
155 }
156
161 public function checkManagmentAccess()
162 {
163 if (!$this->hasParentCourse()) {
164 $this->logger->dump('Access failed: no parent course');
165 return false;
166 }
167 return
168 $this->access->checkAccess('manage_members', '', $this->target_ref_id) &&
169 $this->access->checkAccess('manage_members', '', $this->parent_course_ref_id);
170 }
171
172
176 protected function init()
177 {
178 if (!$this->target_ref_id) {
179 $target_obj_id = ilObjCourseReference::_lookupTargetId(ilObject::_lookupObjId($this->ref_id));
180 $target_ref_ids = ilObject::_getAllReferences($target_obj_id);
181 $this->target_ref_id = end($target_ref_ids);
182 }
183
184 $this->member_update_enabled = ilObjCourseReference::lookupMemberUpdateEnabled(ilObject::_lookupObjId($this->ref_id));
185 $this->parent_course_ref_id = $this->tree->checkForParentType($this->ref_id, 'crs');
186
187 if ($this->getParentCourseRefId() && !$this->tree->checkForParentType($this->ref_id, 'grp')) {
188 $this->has_parent_course = true;
189 }
190 }
191}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTargetId($a_obj_id)
lookup target id
Class ilCourseReferencePathInfo.
static getInstanceByRefId(int $ref_id, int $target_ref_id=0)
static isReferenceMemberUpdateConfirmationRequired(int $course_ref_id, array $participants)
checkManagmentAccess()
Check manage member for both target and parent course.
__construct(int $ref_id, int $target_ref_id=0)
ilCourseReferencePathInfo constructor.
static lookupMemberUpdateEnabled(int $obj_id)
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static getInstance($a_ref_id)
Get instance by ref_id.
global $DIC
Definition: goto.php:24