ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSessionParticipantsTableGUI.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
5include_once './Services/Table/classes/class.ilTable2GUI.php';
6
14{
15 protected static $all_columns = null;
16
20 private $rep_object = null;
21
22
27 private $parent_ref_id = 0;
28
33 private $member_ref_id = 0;
34
35
36
40 private $logger = null;
41
42
46 private $participants = null;
47
48
55 public function __construct($a_parent_gui, ilObjSession $a_parent_obj, $a_parent_cmd)
56 {
57 $this->logger = $GLOBALS['DIC']->logger()->sess();
58
59 $this->rep_object = $a_parent_obj;
60
61 include_once './Services/Membership/classes/class.ilParticipants.php';
62 $this->participants = ilParticipants::getInstance($this->getRepositoryObject()->getRefId());
63
64 $this->setId('session_part_' . $this->getRepositoryObject()->getId());
65 parent::__construct($a_parent_gui, $a_parent_cmd);
66
67 $this->parent_ref_id = $GLOBALS['DIC']->repositoryTree()->getParentId(
68 $this->getRepositoryObject()->getRefId()
69 );
70
71 $tree = $GLOBALS['DIC']->repositoryTree();
72 if ($member_ref = $tree->checkForParentType($this->parent_ref_id, 'grp')) {
73 $this->member_ref_id = $member_ref;
74 } elseif ($member_ref = $tree->checkForParentType($this->parent_ref_id, 'crs')) {
75 $this->member_ref_id = $member_ref;
76 } else {
77 throw new \InvalidArgumentException("Error in tree structure. Session has no parent course/group ref_id: " . $this->getRepositoryObject()->getRefId());
78 }
79 }
80
81
85 protected function getRepositoryObject()
86 {
87 return $this->rep_object;
88 }
89
94 protected function isRegistrationEnabled()
95 {
96 return $this->getRepositoryObject()->enabledRegistration();
97 }
98
99
104 protected function getParticipants()
105 {
106 return $this->participants;
107 }
108
109
113 public function init()
114 {
115 $this->lng->loadLanguageModule('sess');
116 $this->lng->loadLanguageModule('crs');
117 $this->lng->loadLanguageModule('trac');
118 $this->lng->loadLanguageModule('mmbr');
119
120 $this->setFormName('participants');
121
122 $this->initFilter();
123
124
125 $this->setSelectAllCheckbox('participants', true);
126 $this->setShowRowsSelector(true);
127
128 $this->enable('sort');
129 $this->enable('header');
130 $this->enable('numinfo');
131 $this->enable('select_all');
132
133
134 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $this->getParentCmd()));
135
136 $this->setRowTemplate("tpl.sess_members_row.html", "Modules/Session");
137
138 $this->addColumn('', 'f', '1', true);
139 $this->addColumn($this->lng->txt('name'), 'name', '20%');
140 $this->addColumn($this->lng->txt('login'), 'login', '10%');
141
142 $all_cols = $this->getSelectableColumns();
143 foreach ($this->getSelectedColumns() as $col) {
144 $this->addColumn($all_cols[$col]['txt'], $col);
145 }
146
147
148 if ($this->isRegistrationEnabled()) {
149 $this->addColumn($this->lng->txt('event_tbl_registered'), 'registered');
150 $this->setDefaultOrderField('registered');
151 $this->setDefaultOrderDirection('desc');
152 } else {
153 $this->setDefaultOrderField('name');
154 }
155
156 $this->addColumn($this->lng->txt('event_tbl_participated'), 'participated');
157
158 if ($this->isRegistrationEnabled()) {
159 $this->addColumn($this->lng->txt('sess_part_table_excused'), 'excused');
160 }
161
162 $this->addColumn($this->lng->txt('sess_contact'), 'contact');
163 if (true === $this->getRepositoryObject()->isRegistrationNotificationEnabled()) {
164 $this->addColumn($this->lng->txt('notification'), 'notification_checked');
165 }
166
167 $this->addColumn($this->lng->txt('trac_mark'), 'mark');
168 $this->addColumn($this->lng->txt('trac_comment'), 'comment');
169
170
171 $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('mmbr_btn_mail_selected_users'));
172 $this->lng->loadLanguageModule('user');
173 $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
174
175
176 $this->addCommandButton('updateMembers', $this->lng->txt('save'));
177 }
178
179 public function initFilter()
180 {
182 'login',
184 false,
185 $this->lng->txt('name')
186 );
187 $this->current_filter['login'] = $login->getValue();
188
189
190 if ($this->isColumnSelected('roles')) {
191 $role = $this->addFilterItemByMetaType(
192 'roles',
194 false,
195 $this->lng->txt('objs_' . ilObject::_lookupType(ilObject::_lookupObjId($this->member_ref_id)) . '_role')
196 );
197
198 $options = array();
199 $options[0] = $this->lng->txt('all_roles');
200 $role->setOptions($options + $this->getParentLocalRoles());
201 $this->current_filter['roles'] = $role->getValue();
202 }
203
204 if ($this->getRepositoryObject()->enabledRegistration()) {
205 $reg = $this->addFilterItemByMetaType(
206 'filter_registration',
208 false,
209 $this->lng->txt('sess_part_filter_registered')
210 );
211 $this->current_filter['filter_registration'] = (bool) $reg->getChecked();
212 }
213 $participated = $this->addFilterItemByMetaType(
214 'filter_participated',
216 false,
217 $this->lng->txt('sess_part_filter_participated')
218 );
219 $this->current_filter['filter_participated'] = (bool) $participated->getChecked();
220 }
221
226 public function getSelectableColumns()
227 {
228 global $DIC;
229
230 $ilSetting = $DIC['ilSetting'];
231
232
233 self::$all_columns['roles'] = array(
234 'txt' => $this->lng->txt('objs_role'),
235 'default' => true
236 );
237
238 return self::$all_columns;
239 }
240
241
248 public function parse()
249 {
250 $all_participants = [];
251 $all_possible_participants = $this->collectParticipants();
252 if ($all_possible_participants) {
253 // user filter
254 $user_query = new ilUserQuery();
255 $user_query->setLimit(50000);
256 $user_query->setUserFilter($all_possible_participants);
257 $user_query->setTextFilter((string) $this->current_filter['login']);
258 $res = $user_query->query();
259 $all_participants = $res['set'];
260 }
261
262 $part = [];
263 foreach ($all_participants as $counter => $participant) {
264 $usr_data = $this->getParticipants()->getEventParticipants()->getUser($participant['usr_id']);
265
266 $tmp_data = [];
267 $tmp_data['id'] = $participant['usr_id'];
268
269 $tmp_data['name'] = $participant['lastname'];
270 $tmp_data['lastname'] = $participant['lastname'];
271 $tmp_data['firstname'] = $participant['firstname'];
272 $tmp_data['login'] = $participant['login'];
273 $tmp_data['mark'] = $usr_data['mark'];
274 $tmp_data['comment'] = $usr_data['comment'];
275 $tmp_data['participated'] = $this->getParticipants()->getEventParticipants()->hasParticipated($participant['usr_id']);
276 $tmp_data['registered'] = $this->getParticipants()->getEventParticipants()->isRegistered($participant['usr_id']);
277 $tmp_data['excused'] = $this->getParticipants()->getEventParticipants()->isExcused((int) $participant['usr_id']);
278 $tmp_data['contact'] = $this->getParticipants()->isContact($participant['usr_id']);
279
280 $notificationShown = false;
281 if (true === $this->getRepositoryObject()->isRegistrationNotificationEnabled()) {
282 $notificationShown = true;
283
284 $notificationCheckboxEnabled = true;
285 if (ilSessionConstants::NOTIFICATION_INHERIT_OPTION === $this->getRepositoryObject()->getRegistrationNotificationOption()) {
286 $notificationCheckboxEnabled = false;
287 }
288 $tmp_data['notification_checkbox_enabled'] = $notificationCheckboxEnabled;
289 $tmp_data['notification_checked'] = $usr_data['notification_enabled'];
290 }
291 $tmp_data['show_notification'] = $notificationShown;
292
293 $roles = array();
294 $local_roles = $this->getParentLocalRoles();
295 foreach ($local_roles as $role_id => $role_name) {
296 // @todo fix performance
297 if ($GLOBALS['DIC']['rbacreview']->isAssigned($participant['usr_id'], $role_id)) {
298 $tmp_data['role_ids'][] = $role_id;
299 $roles[] = $role_name;
300 }
301 }
302 $tmp_data['roles'] = implode('<br />', $roles);
303
304 if ($this->matchesFilterCriteria($tmp_data)) {
305 $part[] = $tmp_data;
306 }
307 }
308 $this->setData($part);
309 }
310
315 protected function collectParticipants()
316 {
317 $part = ilParticipants::getInstance($this->member_ref_id);
318 if (!$part instanceof ilParticipants) {
319 return $this->getParticipants()->getParticipants();
320 }
321 return $part->getParticipants();
322 }
323
324
329 protected function matchesFilterCriteria($a_user_info)
330 {
331 foreach ($this->current_filter as $filter => $filter_value) {
332 if (!$filter_value) {
333 continue;
334 }
335 switch ($filter) {
336 case 'roles':
337 if (!in_array($filter_value, $a_user_info['role_ids'])) {
338 return false;
339 }
340 break;
341
342 case 'filter_participated':
343 if (!$a_user_info['participated']) {
344 return false;
345 }
346 break;
347
348 case 'filter_registration':
349 if (!$a_user_info['registered']) {
350 return false;
351 }
352 break;
353 }
354
355
356 $this->logger->info('Filter: ' . $filter . ' -> ' . $filter_value);
357 }
358 return true;
359 }
360
361
368 public function fillRow($a_set)
369 {
370 $this->tpl->setVariable('VAL_POSTNAME', 'participants');
371
372 if ($this->isRegistrationEnabled()) {
373 $this->tpl->setCurrentBlock('registered_col');
374 $this->tpl->setVariable('VAL_ID', $a_set['id']);
375 $this->tpl->setVariable('REG_CHECKED', $a_set['registered'] ? 'checked="checked"' : '');
376 $this->tpl->parseCurrentBlock();
377 }
378
379 foreach ($this->getSelectedColumns() as $field) {
380 switch ($field) {
381 case 'roles':
382 $this->tpl->setCurrentBlock('custom_fields');
383 $this->tpl->setVariable('VAL_CUST', (string) $a_set['roles']);
384 $this->tpl->parseCurrentBlock();
385 break;
386
387 }
388 }
389
390 if (true === $a_set['show_notification']) {
391 $this->tpl->setCurrentBlock('notification_column');
392 $this->tpl->setVariable('VAL_ID', $a_set['id']);
393 $this->tpl->setVariable('NOTIFICATION_CHECKED', $a_set['notification_checked'] ? 'checked="checked"' : '');
394
395 $enableCheckbox = $a_set['notification_checkbox_enabled'];
396
397 $this->tpl->setVariable('NOTIFICATION_ENABLED', $enableCheckbox ? '' : 'disabled');
398 $this->tpl->parseCurrentBlock();
399 }
400
401 $this->tpl->setVariable('VAL_ID', $a_set['id']);
402 $this->tpl->setVariable('LASTNAME', $a_set['lastname']);
403 $this->tpl->setVariable('FIRSTNAME', $a_set['firstname']);
404 $this->tpl->setVariable('LOGIN', $a_set['login']);
405 $this->tpl->setVariable('MARK', $a_set['mark']);
406 $this->tpl->setVariable('COMMENT', $a_set['comment']);
407 $this->tpl->setVariable('PART_CHECKED', $a_set['participated'] ? 'checked="checked"' : '');
408 $this->tpl->setVariable('CONTACT_CHECKED', $a_set['contact'] ? 'checked="checked"' : '');
409 $this->tpl->setVariable('PART_CHECKED', $a_set['participated'] ? 'checked="checked"' : '');
410 if ($this->isRegistrationEnabled()) {
411 $this->tpl->setVariable('EXCUSED_CHECKED', $a_set['excused'] ? 'checked="checked"' : '');
412 }
413 }
414
418 protected function getParentLocalRoles()
419 {
420 $part = null;
421 $type = ilObject::_lookupType($this->member_ref_id, true);
422 switch ($type) {
423 case 'crs':
424 case 'grp':
425 $part = ilParticipants::getInstance($this->member_ref_id);
426 // no break
427 default:
428
429 }
430 if (!$part instanceof ilParticipants) {
431 return [];
432 }
433
434 $review = $GLOBALS['DIC']->rbac()->review();
435
436 $local_parent_roles = $review->getLocalRoles($this->member_ref_id);
437 $this->logger->dump($local_parent_roles);
438
439 $local_roles_info = [];
440 foreach ($local_parent_roles as $index => $role_id) {
441 $local_roles_info[$role_id] = ilObjRole::_getTranslation(
442 ilObject::_lookupTitle($role_id)
443 );
444 }
445 return $local_roles_info;
446 }
447}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static _getTranslation($a_role_title)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance($a_ref_id)
Get instance by ref_id.
getParentLocalRoles()
Get local roles of parent object.
__construct($a_parent_gui, ilObjSession $a_parent_obj, $a_parent_cmd)
isRegistrationEnabled()
Check if registration is enabled.
matchesFilterCriteria($a_user_info)
Check if user is filtered.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
isColumnSelected($a_col)
Is given column selected?
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
enable($a_module_name)
enables particular modules of table
User query class.
$login
Definition: cron.php:13
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
$type
foreach($_POST as $key=> $value) $res
$DIC
Definition: xapitoken.php:46