ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLearningSequenceMembershipGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 {
34  public function __construct(
36  protected ilObject $obj,
37  protected ilObjUserTracking $obj_user_tracking,
38  protected ilPrivacySettings $privacy_settings,
39  protected ilRbacReview $rbac_review,
40  protected ilSetting $settings,
41  protected ilToolbarGUI $toolbar,
42  protected ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper,
43  protected ArrayBasedRequestWrapper $post_wrapper,
44  protected ILIAS\Refinery\Factory $refinery,
45  protected ILIAS\UI\Factory $ui_factory
46  ) {
47  parent::__construct($repository_gui, $obj);
48  }
49 
50  protected function members(): void
51  {
52  $may_manage_members = $this->checkRbacOrPositionAccessBool(
53  'manage_members',
54  'manage_members',
55  $this->getParentObject()->getRefId()
56  );
57 
58  if ($may_manage_members) {
59  $this->participants();
60  } else {
61  $this->jump2UsersGallery();
62  }
63  }
64 
65  protected function printMembers(): void
66  {
67  $this->checkPermission('read');
68  if ($this->checkRbacOrPositionAccessBool('manage_members', 'manage_members')) {
69  $back_cmd = 'participants';
70  } else {
71  $back_cmd = 'jump2UsersGallery';
72  }
73 
74  global $DIC;
75  $ilTabs = $DIC['ilTabs'];
76  $ilTabs->clearTargets();
77  $ilTabs->setBackTarget(
78  $this->lng->txt('back'),
79  $this->ctrl->getLinkTarget($this, $back_cmd)
80  );
81 
82  $list = $this->initAttendanceList();
83  $form = $list->initForm('printMembersOutput');
84  $this->tpl->setContent($form->getHTML());
85  }
86 
87  protected function getDefaultCommand(): string
88  {
90  return $this->request_wrapper->retrieve("back_cmd", $r->byTrying([$r->kindlyTo()->string(), $r->always("members")]));
91  }
92 
98  public function filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids): array
99  {
100  return $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
101  'manage_members',
102  'manage_members',
103  $this->getParentObject()->getRefId(),
104  $a_user_ids
105  );
106  }
107 
111  public function assignMembers(array $user_ids, string $type): bool
112  {
113  $object = $this->getParentObject();
114  $members = $this->getParentObject()->getLSParticipants();
115 
116  if (count($user_ids) == 0) {
117  $this->lng->loadLanguageModule('search');
118  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('search_err_user_not_exist'), true);
119  return false;
120  }
121 
122  $assigned = false;
123  foreach ($user_ids as $new_member) {
124  $new_member = (int) $new_member;
125 
126  if ($members->isAssigned($new_member)) {
127  continue;
128  }
129 
130  switch ($type) {
131  case $object->getDefaultAdminRole():
132  $members->add($new_member, ilParticipants::IL_LSO_ADMIN);
133  $members->sendNotification(
135  $new_member
136  );
137  $assigned = true;
138  break;
139  case $object->getDefaultMemberRole():
140  $members->add($new_member, ilParticipants::IL_LSO_MEMBER);
141  $members->sendNotification(
143  $new_member
144  );
145  $assigned = true;
146  break;
147  default:
148  if (in_array($type, $object->getLocalLearningSequenceRoles(true))) {
149  $members->add($new_member, ilParticipants::IL_LSO_MEMBER);
150  $members->updateRoleAssignments($new_member, array($type));
151  } else {
152  ilLoggerFactory::getLogger('lso')->notice(
153  'Can not find role with id .' . $type . ' to assign users.'
154  );
155  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("lso_cannot_find_role"), true);
156  return false;
157  }
158 
159  $members->sendNotification(
161  $new_member
162  );
163  $assigned = true;
164  break;
165  }
166  }
167 
168  if ($assigned) {
169  $this->tpl->setOnScreenMessage('success', $this->lng->txt("lso_msg_member_assigned"), true);
170  } else {
171  $this->tpl->setOnScreenMessage('success', $this->lng->txt('lso_users_already_assigned'), true);
172  }
173 
174  $this->ctrl->redirect($this, 'participants');
175  return $assigned;
176  }
177 
181  protected function updateParticipantsStatus(): void
182  {
183  $members = $this->getParentObject()->getLSParticipants();
184 
185  $participants = $this->post_wrapper->retrieve(
186  "visible_member_ids",
187  $this->refinery->byTrying([
188  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
189  $this->refinery->always([])
190  ])
191  );
192 
193 
194 
195 
196  $notification = [];
197  if ($this->post_wrapper->has('notification')) {
198  $notification = $this->post_wrapper->retrieve(
199  "notification",
200  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
201  );
202  }
203 
204  foreach ($participants as $participant) {
205  if ($members->isAdmin($participant)) {
206  $members->updateNotification($participant, in_array($participant, $notification));
207  continue;
208  }
209  $members->updateNotification($participant, false);
210  }
211 
212  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
213  $this->ctrl->redirect($this, 'participants');
214  }
215 
217  {
219  $this,
220  $this->getParentObject(),
221  $this->obj_user_tracking,
222  $this->privacy_settings,
223  $this->lng,
224  $this->access,
225  $this->rbac_review,
226  $this->settings
227  );
228  }
229 
231  {
232  $obj = parent::getParentObject();
233  if (!$obj instanceof ilObjLearningSequence) {
234  throw new Exception('Invalid class type ' . get_class($obj) . ". Expected ilObjLearningSequence.");
235  }
236  return $obj;
237  }
238 
240  {
242  $this,
243  $this->getParentObject(),
244  $this->getParentObject()->getLSParticipants(),
245  $this->privacy_settings
246  );
247 
248  $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
249  $table->setData($this->readMemberData($participants));
250 
251  return $table;
252  }
253 
257  protected function initParticipantTemplate(): void
258  {
259  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.lso_edit_members.html', 'components/ILIAS/LearningSequence');
260  }
261 
265  public function getLocalTypeRole(bool $translation = false): array
266  {
267  return $this->getParentObject()->getLocalLearningSequenceRoles($translation);
268  }
269 
275  public function readMemberData(array $usr_ids, ?array $columns = null): array
276  {
277  return $this->getParentObject()->readMemberData($usr_ids, $columns);
278  }
279 
280 
282  {
283  return new ilLearningSequenceWaitingList($this->getParentObject()->getId());
284  }
285 
286  protected function getDefaultRole(): ?int
287  {
288  return $this->getParentObject()->getDefaultMemberRole();
289  }
290 
294  public function getPrintMemberData(array $members): array
295  {
296  $member_data = $this->readMemberData($members, array());
297 
298  return $this->getParentGUI()->addCustomData($member_data);
299  }
300 
304  public function getAttendanceListUserData(int $user_id, array $filters = []): array
305  {
306  $data = array();
307 
308  if ($this->filterUserIdsByRbacOrPositionOfCurrentUser([$user_id])) {
309  $data = $this->member_data[$user_id];
310  if (array_key_exists('access_time', $data)) {
311  $data['access'] = $data['access_time'];
312  }
313  $data['progress'] = $this->lng->txt($data['progress']);
314  }
315 
316  return $data;
317  }
318 
320  {
322  }
323 
324  protected function setSubTabs(ilTabsGUI $tabs): void
325  {
327  'manage_members',
328  'manage_members',
329  $this->getParentObject()->getRefId()
330  );
331 
332  if ($access) {
333  $tabs->addSubTabTarget(
334  $this->getParentObject()->getType() . "_member_administration",
335  $this->ctrl->getLinkTarget($this, 'participants'),
336  "members",
337  get_class($this)
338  );
339 
340  $tabs->addSubTabTarget(
341  $this->getParentObject()->getType() . '_members_gallery',
342  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilUsersGalleryGUI')),
343  'view',
344  'ilUsersGalleryGUI'
345  );
346  } elseif ($this->getParentObject()->getShowMembers()) {
347  $tabs->addSubTabTarget(
348  $this->getParentObject()->getType() . '_members_gallery',
349  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilUsersGalleryGUI')),
350  'view',
351  'ilUsersGalleryGUI'
352  );
353  }
354  }
355 
356  protected function showParticipantsToolbar(): void
357  {
358  $toolbar_entries = [
359  'auto_complete_name' => $this->lng->txt('user'),
360  'user_type' => $this->getParentGUI()->getLocalRoles(),
361  'user_type_default' => $this->getDefaultRole(),
362  'submit_name' => $this->lng->txt('add'),
363  'add_search' => true
364  ];
365 
366  $search_params = ['crs', 'grp'];
367  $parent_container = $this->obj->getParentObjectInfo(
368  $this->obj->getRefId(),
369  $search_params
370  );
371  if (!is_null($parent_container)) {
372  $container_id = $parent_container['ref_id'];
373  $toolbar_entries['add_from_container'] = $container_id;
374  }
375 
377  $this,
378  $this->toolbar,
379  $toolbar_entries
380  );
381 
382  $this->toolbar->addSeparator();
383 
384  $this->toolbar->addComponent(
385  $this->ui_factory->button()->standard(
386  $this->lng->txt($this->getParentObject()->getType() . "_print_list"),
387  $this->ctrl->getLinkTarget($this, 'printMembers')
388  )
389  );
390 
391  $this->showMailToMemberToolbarButton($this->toolbar, 'participants');
392  }
393 }
updateNotification(int $a_usr_id, bool $a_notification)
Update notification status.
Base class for member tab content.
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer Contains several chained tasks and infos about them.
checkPermission(string $a_permission, string $a_cmd="")
Check permission If not granted redirect to parent gui.
addSubTabTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
getAttendanceListUserData(int $user_id, array $filters=[])
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Singleton class that stores all privacy settings.
Class ilObjectGUI Basic methods of all Output classes.
initParticipantTemplate()
Init participant view template.
initAttendanceList(bool $a_for_members=false)
global $DIC
Definition: shib_login.php:26
ilParticipants $participants
showMailToMemberToolbarButton(ilToolbarGUI $toolbar, ?string $a_back_cmd=null, bool $a_separator=false)
Show mail to member toolbar button.
__construct(ilObjectGUI $repository_gui, protected ilObject $obj, protected ilObjUserTracking $obj_user_tracking, protected ilPrivacySettings $privacy_settings, protected ilRbacReview $rbac_review, protected ilSetting $settings, protected ilToolbarGUI $toolbar, protected ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper, protected ArrayBasedRequestWrapper $post_wrapper, protected ILIAS\Refinery\Factory $refinery, protected ILIAS\UI\Factory $ui_factory)
filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids)
Filter user ids by access.
readMemberData(array $usr_ids, ?array $columns=null)
static fillAutoCompleteToolbar(object $parent_object, ?ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt(&#39;user&#39;), auto_complete_size = 15, user_type = array(ilCoursePar...
__construct(Container $dic, ilPlugin $plugin)
participants()
Show participant table, subscriber table, wating list table;.
ilAccessHandler $access
checkRbacOrPositionAccessBool(string $a_rbac_perm, string $a_pos_perm, int $a_ref_id=0)
Class ilAbstractMailMemberRoles.
GUI class for learning sequence membership features.
$r