ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSessionMembershipGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
33 {
34  protected array $requested_visible_participants = [];
35  protected array $requested_participated = [];
36  protected array $requested_registered = [];
37  protected array $requested_contact = [];
38  protected array $requested_excused = [];
39  protected array $requested_mark = [];
40  protected array $requested_comment = [];
41  protected array $requested_notification = [];
42  protected array $requested_participants = [];
43 
44  public function __construct(ilObjectGUI $repository_gui, ilObject $repository_obj)
45  {
46  parent::__construct($repository_gui, $repository_obj);
47 
48  if ($this->http->wrapper()->post()->has('visible_participants')) {
49  $this->requested_visible_participants = (array) $this->http->wrapper()->post()->retrieve(
50  'visible_participants',
51  $this->refinery->custom()->transformation(function ($v) {
52  return $v;
53  })
54  );
55  } elseif ($this->http->wrapper()->query()->has('visible_participants')) {
56  $this->requested_visible_participants = (array) $this->http->wrapper()->query()->retrieve(
57  'visible_participants',
58  $this->refinery->custom()->transformation(function ($v) {
59  return $v;
60  })
61  );
62  }
63 
64  if ($this->http->wrapper()->post()->has('participated')) {
65  $this->requested_participated = (array) $this->http->wrapper()->post()->retrieve(
66  'participated',
67  $this->refinery->custom()->transformation(function ($v) {
68  return $v;
69  })
70  );
71  }
72 
73  if ($this->http->wrapper()->post()->has('registered')) {
74  $this->requested_registered = (array) $this->http->wrapper()->post()->retrieve(
75  'registered',
76  $this->refinery->custom()->transformation(function ($v) {
77  return $v;
78  })
79  );
80  }
81 
82  if ($this->http->wrapper()->post()->has('contact')) {
83  $this->requested_contact = (array) $this->http->wrapper()->post()->retrieve(
84  'contact',
85  $this->refinery->custom()->transformation(function ($v) {
86  return $v;
87  })
88  );
89  }
90 
91  if ($this->http->wrapper()->post()->has('excused')) {
92  $this->requested_excused = (array) $this->http->wrapper()->post()->retrieve(
93  'excused',
94  $this->refinery->custom()->transformation(function ($v) {
95  return $v;
96  })
97  );
98  }
99 
100  if ($this->http->wrapper()->post()->has('mark')) {
101  $this->requested_mark = (array) $this->http->wrapper()->post()->retrieve(
102  'mark',
103  $this->refinery->custom()->transformation(function ($v) {
104  return $v;
105  })
106  );
107  }
108 
109  if ($this->http->wrapper()->post()->has('comment')) {
110  $this->requested_comment = (array) $this->http->wrapper()->post()->retrieve(
111  'comment',
112  $this->refinery->custom()->transformation(function ($v) {
113  return $v;
114  })
115  );
116  }
117 
118  if ($this->http->wrapper()->post()->has('notification')) {
119  $this->requested_notification = (array) $this->http->wrapper()->post()->retrieve(
120  'notification',
121  $this->refinery->custom()->transformation(function ($v) {
122  return $v;
123  })
124  );
125  }
126 
127  if ($this->http->wrapper()->post()->has('participants')) {
128  $this->requested_participants = (array) $this->http->wrapper()->post()->retrieve(
129  'participants',
130  $this->refinery->custom()->transformation(function ($v) {
131  return $v;
132  })
133  );
134  }
135  }
136 
138  {
139  return new ilMailMemberSessionRoles();
140  }
141 
146  protected function checkRbacOrPositionAccessBool(string $a_rbac_perm, string $a_pos_perm, int $a_ref_id = 0): bool
147  {
148  if (!$a_ref_id) {
149  $a_ref_id = $this->getParentObject()->getRefId();
150  }
151  return $this->checkPermissionBool($a_rbac_perm, "", "", $a_ref_id);
152  }
153 
154  protected function initParticipantTemplate(): void
155  {
156  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.sess_edit_members.html', 'Modules/Session');
157  }
158 
159  protected function initWaitingList(): ilSessionWaitingList
160  {
161  $wait = new ilSessionWaitingList($this->getParentObject()->getId());
162  return $wait;
163  }
164 
165  public function getParentObject(): ilObjSession
166  {
170  $parent_object = parent::getParentObject();
171  return $parent_object;
172  }
173 
175  {
176  $table = new ilSessionParticipantsTableGUI(
177  $this,
178  $this->getParentObject(),
179  'participants'
180  );
181  $table->init();
182  return $table;
183  }
184 
185  protected function getParticipantTableTitle(): string
186  {
187  /*
188  * TODO this exact logic is also in ilSessionParticipantsTableGUI and ilMembershipGUI,
189  * should be centralized.
190  */
191  if ($member_ref = $this->tree->checkForParentType(
192  $this->getParentObject()->getRefId(),
193  'grp'
194  )) {
195  $member_ref_id = $member_ref;
196  } elseif ($member_ref = $this->tree->checkForParentType(
197  $this->getParentObject()->getRefId(),
198  'crs'
199  )) {
200  $member_ref_id = $member_ref;
201  } else {
202  $this->logger->warning('Cannot find parent course or group for ref_id: ' . $this->getParentObject()->getRefId());
203  $member_ref_id = $this->getParentObject()->getRefId();
204  }
205 
206  return sprintf(
207  $this->lng->txt('sess_mem_tbl_header'),
208  ilObjectFactory::getInstanceByRefId($member_ref_id)->getTitle(),
209  );
210  }
211 
213  {
214  $subscriber = new ilSubscriberTableGUI($this, $this->getParentObject(), true, false);
215  $subscriber->setTitle($this->lng->txt('group_new_registrations'));
216  return $subscriber;
217  }
218 
219  protected function updateMembers(): void
220  {
221  $this->checkPermission('manage_members');
222 
223  $part = ilParticipants::getInstance($this->getParentObject()->getRefId());
224 
225 
226  $wait = new ilSessionWaitingList($this->getParentObject()->getId());
227  $waiting = $wait->getUserIds();
228 
229  foreach ($this->requested_visible_participants as $part_id) {
230  if (in_array($part_id, $waiting)) {
231  // so not update users on waiting list
232  continue;
233  }
234 
235  $participated = (bool) ($this->requested_participated[$part_id] ?? false);
236  $registered = (bool) ($this->requested_registered[$part_id] ?? false);
237  $contact = (bool) ($this->requested_contact[$part_id] ?? false);
238  $excused = (bool) ($this->requested_excused[$part_id] ?? false);
239 
240  $part_id = (int) $part_id;
241 
242  if ($part->isAssigned($part_id) && !$participated && !$registered) {
243  $part->delete($part_id);
244  }
245  if (!$part->isAssigned($part_id) && ($participated || $registered)) {
246  $part->add($part_id, ilParticipants::IL_SESS_MEMBER);
247  }
248  $event_part = new ilEventParticipants($this->getParentObject()->getId());
249  $event_part->setUserId($part_id);
250  $event_part->setMark(ilUtil::stripSlashes($this->requested_mark[$part_id]));
251  $event_part->setComment(ilUtil::stripSlashes($this->requested_comment[$part_id]));
252  $event_part->setNotificationEnabled((bool) ($this->requested_notification[$part_id] ?? false));
253  $event_part->setParticipated($participated);
254  $event_part->setRegistered($registered);
255  $event_part->setContact($contact);
256  $event_part->setExcused($excused);
257  $event_part->updateUser();
258  }
259 
260  $this->tpl->setOnScreenMessage('success', $this->getLanguage()->txt('settings_saved'), true);
261  $this->getCtrl()->redirect($this, 'participants');
262  }
263 
264  protected function confirmDeleteParticipants(): void
265  {
267 
268  if (!count($participants)) {
269  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_checkbox'), true);
270  $this->ctrl->redirect($this, 'participants');
271  }
272 
273  $confirm = new ilConfirmationGUI();
274  $confirm->setFormAction($this->ctrl->getFormAction($this, 'confirmDeleteParticipants'));
275  $confirm->setHeaderText($this->lng->txt($this->getParentObject()->getType() . '_header_delete_members'));
276  $confirm->setConfirm($this->lng->txt('confirm'), 'deleteParticipants');
277  $confirm->setCancel($this->lng->txt('cancel'), 'participants');
278 
279  foreach ($participants as $usr_id) {
280  $name = ilObjUser::_lookupName($usr_id);
281 
282  $confirm->addItem(
283  'participants[]',
284  $name['user_id'],
285  $name['lastname'] . ', ' . $name['firstname'] . ' [' . $name['login'] . ']',
286  ilUtil::getImagePath('standard/icon_usr.svg')
287  );
288  }
289 
290  $this->tpl->setContent($confirm->getHTML());
291  }
292 
293  protected function deleteParticipants(): void
294  {
295  $this->checkPermission('manage_members');
296 
298 
299  if (!is_array($participants) || !count($participants)) {
300  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
301  $this->ctrl->redirect($this, 'participants');
302  }
303 
304  foreach ($participants as $part_id) {
305  // delete role assignment
306  $this->getMembersObject()->delete($part_id);
307  // delete further settings
308  $event_part = new ilEventParticipants($this->getParentObject()->getId());
309  $event_part->setUserId($part_id);
310  $event_part->setParticipated(false);
311  $event_part->setRegistered(false);
312  $event_part->setMark('');
313  $event_part->setComment('');
314  $event_part->updateUser();
315  }
316 
317  $this->tpl->setOnScreenMessage('success', $this->lng->txt($this->getParentObject()->getType() . "_members_deleted"), true);
318  $this->ctrl->redirect($this, "participants");
319  }
320 
321  public function getPrintMemberData(array $a_members): array
322  {
323  return $a_members;
324  }
325 
329  protected function canAddOrSearchUsers(): bool
330  {
331  return false;
332  }
333 
334  public function getAttendanceListUserData(int $user_id, array $filters = []): array
335  {
336  $data = $this->getMembersObject()->getEventParticipants()->getUser($user_id);
337  $data['registered'] = (bool) ($data['registered'] ?? false);
338  $data['participated'] = (bool) ($data['participated'] ?? false);
339 
340  if ($filters && $filters["registered"] && !$data["registered"]) {
341  return [];
342  }
343 
344 
345  $data['registered'] = $data['registered'] ?
346  $this->lng->txt('yes') :
347  $this->lng->txt('no');
348  $data['participated'] = $data['participated'] ?
349  $this->lng->txt('yes') :
350  $this->lng->txt('no');
351 
352  return $data;
353  }
354 
355  protected function getMemberTabName(): string
356  {
357  return $this->lng->txt($this->getParentObject()->getType() . '_members');
358  }
359 
360  protected function getMailButtonLabel(): string
361  {
362  return $this->lng->txt("sess_mail_type");
363  }
364 
365  protected function getMailContextOptions(): array
366  {
367  $context_options = [
369  'ref_id' => $this->getParentObject()->getRefId(),
370  'ts' => time()
371  ];
372 
373  return $context_options;
374  }
375 }
Base class for member tab content.
checkPermissionBool(string $a_permission, string $a_cmd='', string $a_type='', int $a_ref_id=0)
checkRbacOrPositionAccessBool(string $a_rbac_perm, string $a_pos_perm, int $a_ref_id=0)
No support for positions in sessions Check if rbac or position access is granted. ...
Class ilMailMemberSessionRoles.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
checkPermission(string $a_permission, string $a_cmd="")
Check permission If not granted redirect to parent gui.
static getInstance(int $a_ref_id)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupName(int $a_user_id)
lookup user name
getAttendanceListUserData(int $user_id, array $filters=[])
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjectGUI Basic methods of all Output classes.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
GUI class for course/group subscriptions.
ilParticipants $participants
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjectGUI $repository_gui, ilObject $repository_obj)
Class ilAbstractMailMemberRoles.