ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilGroupMembershipGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
22 
35 {
37  protected Factory $refinery;
38 
39  public function __construct(ilObjectGUI $repository_gui, ilObject $repository_obj)
40  {
41  global $DIC;
42 
43  parent::__construct($repository_gui, $repository_obj);
44  $this->refinery = $DIC->refinery();
45  $this->http = $DIC->http();
46  }
47 
52  {
53  return new ilMailMemberGroupRoles();
54  }
55 
56 
62  public function filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids): array
63  {
64  return $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
65  'manage_members',
66  'manage_members',
67  $this->getParentObject()->getRefId(),
68  $a_user_ids
69  );
70  }
71 
72  public function assignMembers(array $user_ids, string $a_type): bool
73  {
74  $a_type = (int) $a_type;
75  if (!count($user_ids)) {
76  $this->lng->loadLanguageModule('search');
77  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('search_err_user_not_exist'), true);
78  return false;
79  }
80 
81  $assigned = false;
82  foreach ($user_ids as $new_member) {
83  $new_member = (int) $new_member;
84  if ($this->getMembersObject()->isAssigned($new_member)) {
85  continue;
86  }
87  switch ($a_type) {
88  case $this->getParentObject()->getDefaultAdminRole():
89  $this->getMembersObject()->add($new_member, ilParticipants::IL_GRP_ADMIN);
90  $this->getMembersObject()->sendNotification(
92  $new_member
93  );
94  $assigned = true;
95  break;
96 
97  case $this->getParentObject()->getDefaultMemberRole():
98  $this->getMembersObject()->add($new_member, ilParticipants::IL_GRP_MEMBER);
99  $this->getMembersObject()->sendNotification(
101  $new_member
102  );
103  $assigned = true;
104  break;
105 
106  default:
107  if (in_array($a_type, $this->getParentObject()->getLocalGroupRoles(true))) {
108  $this->getMembersObject()->add($new_member, ilParticipants::IL_GRP_MEMBER);
109  $this->getMembersObject()->updateRoleAssignments($new_member, (array) $a_type);
110  } else {
111  ilLoggerFactory::getLogger('crs')->notice('Can not find role with id .' . $a_type . ' to assign users.');
112  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_cannot_find_role"), true);
113  return false;
114  }
115  $this->getMembersObject()->sendNotification(
117  $new_member
118  );
119  $assigned = true;
120  break;
121  }
122  }
123 
124  if ($assigned) {
125  $this->tpl->setOnScreenMessage('success', $this->lng->txt("grp_msg_member_assigned"), true);
126  } else {
127  $this->tpl->setOnScreenMessage('success', $this->lng->txt('grp_users_already_assigned'), true);
128  }
129  $this->ctrl->redirect($this, 'participants');
130  return true;
131  }
132 
136  protected function updateParticipantsStatus(): void
137  {
138  $participants = [];
139  if ($this->http->wrapper()->post()->has('visible_member_ids')) {
140  $participants = $this->http->wrapper()->post()->retrieve(
141  'visible_member_ids',
142  $this->refinery->kindlyTo()->listOf(
143  $this->refinery->kindlyTo()->int()
144  )
145  );
146  }
147  $notification = [];
148  if ($this->http->wrapper()->post()->has('notification')) {
149  $notification = $this->http->wrapper()->post()->retrieve(
150  'notification',
151  $this->refinery->kindlyTo()->listOf(
152  $this->refinery->kindlyTo()->int()
153  )
154  );
155  }
156  $contact = [];
157  if ($this->http->wrapper()->post()->has('contact')) {
158  $contact = $this->http->wrapper()->post()->retrieve(
159  'contact',
160  $this->refinery->kindlyTo()->listOf(
161  $this->refinery->kindlyTo()->int()
162  )
163  );
164  }
165  foreach ($participants as $mem_id) {
166  if ($this->getMembersObject()->isAdmin($mem_id)) {
167  $this->getMembersObject()->updateContact($mem_id, in_array($mem_id, $contact));
168  $this->getMembersObject()->updateNotification($mem_id, in_array($mem_id, $notification));
169  } else {
170  $this->getMembersObject()->updateContact($mem_id, false);
171  $this->getMembersObject()->updateNotification($mem_id, false);
172  }
173  }
174  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
175  $this->ctrl->redirect($this, 'participants');
176  }
177 
178 
180  {
181  $show_tracking =
183  ;
184  if ($show_tracking) {
185  $olp = ilObjectLP::getInstance($this->getParentObject()->getId());
186  $show_tracking = $olp->isActive();
187  }
188 
189  return new ilGroupParticipantsTableGUI(
190  $this,
191  $this->getParentObject(),
192  $show_tracking
193  );
194  }
195 
197  {
198  $table = new ilGroupEditParticipantsTableGUI($this, $this->getParentObject());
199  $table->setTitle($this->lng->txt($this->getParentObject()->getType() . '_header_edit_members'));
200  $table->setData($this->getParentGUI()->readMemberData($participants));
201 
202  return $table;
203  }
204 
205 
206 
210  protected function initParticipantTemplate(): void
211  {
212  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.grp_edit_members.html', 'components/ILIAS/Group');
213  }
214 
215  public function getLocalTypeRole(bool $a_translation = false): array
216  {
217  return $this->getParentObject()->getLocalGroupRoles($a_translation);
218  }
219 
220 
221  protected function initWaitingList(): ilGroupWaitingList
222  {
223  return new ilGroupWaitingList($this->getParentObject()->getId());
224  }
225 
229  protected function getDefaultRole(): ?int
230  {
231  return $this->getParentGUI()->getObject()->getDefaultMemberRole();
232  }
233 
234  public function getPrintMemberData(array $a_members): array
235  {
236  $member_data = $this->readMemberData($a_members, array());
237  $member_data = $this->getParentGUI()->addCustomData($member_data);
238  return $member_data;
239  }
240 
244  public function getAttendanceListUserData(int $user_id, array $filters = []): array
245  {
246  if (is_array($this->member_data) && array_key_exists($user_id, $this->member_data)) {
247  $user_data = $this->member_data[$user_id];
248  if (isset($user_data['access_time_unix'])) {
250  $user_data['access'] = ilDatePresentation::formatDate(
251  new ilDateTime($user_data['access_time_unix'], IL_CAL_UNIX)
252  );
254  }
255  if (isset($this->member_data['progress'])) {
256  $user_data['progress'] = $this->lng->txt($this->member_data['progress']);
257  }
258  return $user_data;
259  }
260  return [];
261  }
262 
266  protected function getMailContextOptions(): array
267  {
268  $context_options = [
270  $this->getParentObject()->getId(),
272  ''
273  ),
274  ];
275 
276  return $context_options;
277  }
278 }
readMemberData(array $usr_ids, array $columns)
Required for member table guis.
static array static setUseRelativeDates(bool $a_status)
set use relative dates
Base class for member tab content.
static getLogger(string $a_component_id)
Get component logger.
getAttendanceListUserData(int $user_id, array $filters=[])
Callback from attendance list.
const PROP_CONTEXT_SUBJECT_PREFIX
initParticipantTemplate()
Init participant view template.
const IL_CAL_UNIX
Class ilMailMemberCourseRoles.
static http()
Fetches the global http state from ILIAS.
Class ilObjectGUI Basic methods of all Output classes.
updateParticipantsStatus()
save in participants table
global $DIC
Definition: shib_login.php:22
Waiting list for groups.
ilParticipants $participants
initEditParticipantTableGUI(array $participants)
GUI class for membership features.
filterUserIdsByRbacOrPositionOfCurrentUser(array $a_user_ids)
Filter user ids by access.
__construct(ilObjectGUI $repository_gui, ilObject $repository_obj)
__construct(Container $dic, ilPlugin $plugin)
getLocalTypeRole(bool $a_translation=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
assignMembers(array $user_ids, string $a_type)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static getInstance(int $obj_id)
Class ilAbstractMailMemberRoles.