ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseReferencePathInfo.php
Go to the documentation of this file.
1<?php
2
23{
27 private static $instances = [];
28
32 private $logger = null;
33
37 private $tree = null;
38
42 private $access = null;
43
47 private $ref_id = 0;
48
52 private $target_ref_id = 0;
53
54
58 private $has_parent_course = false;
59
64
65
69 private $member_update_enabled = false;
70
71
75 public function __construct(int $ref_id, int $target_ref_id = 0)
76 {
77 global $DIC;
78
79 $this->logger = $DIC->logger()->crsr();
80 $this->tree = $DIC->repositoryTree();
81 $this->access = $DIC->access();
82
83 $this->ref_id = $ref_id;
84 $this->target_ref_id = $target_ref_id;
85 $this->init();
86
87 $this->logger->info('ref_id: ' . $this->ref_id);
88 $this->logger->info('target_ref_id: ' . $this->target_ref_id);
89 $this->logger->info('parent course: ' . $this->parent_course_ref_id);
90 $this->logger->info('has parent course: ' . $this->has_parent_course);
91 }
92
99 {
100 if (!array_key_exists($ref_id, self::$instances)) {
101 self::$instances[$ref_id] = new self($ref_id, $target_ref_id);
102 }
103 return self::$instances[$ref_id];
104 }
105
106
112 public static function isReferenceMemberUpdateConfirmationRequired(int $course_ref_id, array $participants): bool
113 {
114 global $DIC;
115
116 $tree = $DIC->repositoryTree();
117 $childs = $tree->getChildsByType($course_ref_id, 'crsr');
118 foreach ($childs as $tree_node) {
119 $path_info = self::getInstanceByRefId($tree_node['child']);
120 if (!$path_info->hasParentCourse()) {
121 continue;
122 }
123 if (!$path_info->isMemberUpdateEnabled()) {
124 continue;
125 }
126 if (!$path_info->checkManagmentAccess()) {
127 continue;
128 }
129 $part = ilParticipants::getInstance($path_info->getTargetId());
130 foreach ($participants as $part_id) {
131 if ($part->isMember($part_id)) {
132 return true;
133 }
134 }
135 }
136 return false;
137 }
138
142 public function getParentCourseRefId(): int
143 {
145 }
146
150 public function hasParentCourse(): bool
151 {
153 }
154
158 public function getTargetId(): int
159 {
161 }
162
166 public function isMemberUpdateEnabled(): bool
167 {
169 }
170
175 public function checkManagmentAccess()
176 {
177 if (!$this->hasParentCourse()) {
178 $this->logger->dump('Access failed: no parent course');
179 return false;
180 }
181 return
182 $this->access->checkAccess('manage_members', '', $this->target_ref_id) &&
183 $this->access->checkAccess('manage_members', '', $this->parent_course_ref_id);
184 }
185
186
190 protected function init()
191 {
192 if (!$this->target_ref_id) {
193 $target_obj_id = ilObjCourseReference::_lookupTargetId(ilObject::_lookupObjId($this->ref_id));
194 $target_ref_ids = ilObject::_getAllReferences($target_obj_id);
195 $this->target_ref_id = end($target_ref_ids);
196 }
197
198 $this->member_update_enabled = ilObjCourseReference::lookupMemberUpdateEnabled(ilObject::_lookupObjId($this->ref_id));
199 $this->parent_course_ref_id = $this->tree->checkForParentType($this->ref_id, 'crs');
200
201 if ($this->getParentCourseRefId() && !$this->tree->checkForParentType($this->ref_id, 'grp')) {
202 $this->has_parent_course = true;
203 }
204 }
205}
static _lookupTargetId(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static getInstance(int $a_ref_id)
global $DIC
Definition: shib_login.php:26