ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_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');
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");
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  $this->addColumn($this->lng->txt('event_tbl_participated'), 'participated');
156  $this->addColumn($this->lng->txt('trac_mark'), 'mark');
157  $this->addColumn($this->lng->txt('trac_comment'), 'comment');
158 
159 
160  $this->addMultiCommand('sendMailToSelectedUsers', $this->lng->txt('mmbr_btn_mail_selected_users'));
161  $this->lng->loadLanguageModule('user');
162  $this->addMultiCommand('addToClipboard', $this->lng->txt('clipboard_add_btn'));
163 
164 
165  $this->addCommandButton('updateMembers', $this->lng->txt('save'));
166  }
167 
168  public function initFilter()
169  {
170  $login = $this->addFilterItemByMetaType(
171  'login',
173  false,
174  $this->lng->txt('name')
175  );
176  $this->current_filter['login'] = $login->getValue();
177 
178 
179  if ($this->isColumnSelected('roles')) {
180  $role = $this->addFilterItemByMetaType(
181  'roles',
183  false,
184  $this->lng->txt('objs_' . ilObject::_lookupType(ilObject::_lookupObjId($this->member_ref_id)) . '_role')
185  );
186 
187  $options = array();
188  $options[0] = $this->lng->txt('all_roles');
189  $role->setOptions($options + $this->getParentLocalRoles());
190  $this->current_filter['roles'] = $role->getValue();
191  }
192 
193  if ($this->getRepositoryObject()->enabledRegistration()) {
194  $reg = $this->addFilterItemByMetaType(
195  'filter_registration',
197  false,
198  $this->lng->txt('sess_part_filter_registered')
199  );
200  $this->current_filter['filter_registration'] = (bool) $reg->getChecked();
201  }
202  $participated = $this->addFilterItemByMetaType(
203  'filter_participated',
205  false,
206  $this->lng->txt('sess_part_filter_participated')
207  );
208  $this->current_filter['filter_participated'] = (bool) $participated->getChecked();
209  }
210 
215  public function getSelectableColumns()
216  {
217  global $ilSetting;
218 
219 
220  self::$all_columns['roles'] = array(
221  'txt' => $this->lng->txt('objs_role'),
222  'default' => true
223  );
224 
225  return self::$all_columns;
226  }
227 
228 
235  public function parse()
236  {
237  $all_participants = [];
238  $all_possible_participants = $this->collectParticipants();
239  if ($all_possible_participants) {
240  // user filter
241  $user_query = new ilUserQuery();
242  $user_query->setLimit(50000);
243  $user_query->setUserFilter($all_possible_participants);
244  $user_query->setTextFilter((string) $this->current_filter['login']);
245  $res = $user_query->query();
246  $all_participants = $res['set'];
247  }
248 
249  foreach ($all_participants as $counter => $participant) {
250  $usr_data = $this->getParticipants()->getEventParticipants()->getUser($participant['usr_id']);
251 
252  $tmp_data = [];
253  $tmp_data['id'] = $participant['usr_id'];
254 
255  $tmp_data['name'] = $participant['lastname'];
256  $tmp_data['lastname'] = $participant['lastname'];
257  $tmp_data['firstname'] = $participant['firstname'];
258  $tmp_data['login'] = $participant['login'];
259  $tmp_data['mark'] = $usr_data['mark'];
260  $tmp_data['comment'] = $usr_data['comment'];
261  $tmp_data['participated'] = $this->getParticipants()->getEventParticipants()->hasParticipated($participant['usr_id']);
262  $tmp_data['registered'] = $this->getParticipants()->getEventParticipants()->isRegistered($participant['usr_id']);
263 
264  $roles = array();
265  $local_roles = $this->getParentLocalRoles();
266  foreach ($local_roles as $role_id => $role_name) {
267  // @todo fix performance
268  if ($GLOBALS['rbacreview']->isAssigned($participant['usr_id'], $role_id)) {
269  $tmp_data['role_ids'][] = $role_id;
270  $roles[] = $role_name;
271  }
272  }
273  $tmp_data['roles'] = implode('<br />', $roles);
274 
275  if ($this->matchesFilterCriteria($tmp_data)) {
276  $part[] = $tmp_data;
277  }
278  }
279  $this->setData($part ? $part : array());
280  }
281 
286  protected function collectParticipants()
287  {
288  $part = ilParticipants::getInstance($this->member_ref_id);
289  if (!$part instanceof ilParticipants) {
290  return $this->getParticipants()->getParticipants();
291  }
292  return $part->getParticipants();
293  }
294 
295 
300  protected function matchesFilterCriteria($a_user_info)
301  {
302  foreach ($this->current_filter as $filter => $filter_value) {
303  if (!$filter_value) {
304  continue;
305  }
306  switch ($filter) {
307  case 'roles':
308  if (!in_array($filter_value, $a_user_info['role_ids'])) {
309  return false;
310  }
311  break;
312 
313  case 'filter_participated':
314  if (!$a_user_info['participated']) {
315  return false;
316  }
317  break;
318 
319  case 'filter_registration':
320  if (!$a_user_info['registered']) {
321  return false;
322  }
323  break;
324  }
325 
326 
327  $this->logger->info('Filter: ' . $filter . ' -> ' . $filter_value);
328  }
329  return true;
330  }
331 
332 
339  public function fillRow($a_set)
340  {
341  $this->tpl->setVariable('VAL_POSTNAME', 'participants');
342 
343  if ($this->isRegistrationEnabled()) {
344  $this->tpl->setCurrentBlock('registered_col');
345  $this->tpl->setVariable('VAL_ID', $a_set['id']);
346  $this->tpl->setVariable('REG_CHECKED', $a_set['registered'] ? 'checked="checked"' : '');
347  $this->tpl->parseCurrentBlock();
348  }
349 
350  foreach ($this->getSelectedColumns() as $field) {
351  switch ($field) {
352  case 'roles':
353  $this->tpl->setCurrentBlock('custom_fields');
354  $this->tpl->setVariable('VAL_CUST', (string) $a_set['roles']);
355  $this->tpl->parseCurrentBlock();
356  break;
357 
358  }
359  }
360  $this->tpl->setVariable('VAL_ID', $a_set['id']);
361  $this->tpl->setVariable('LASTNAME', $a_set['lastname']);
362  $this->tpl->setVariable('FIRSTNAME', $a_set['firstname']);
363  $this->tpl->setVariable('LOGIN', $a_set['login']);
364  $this->tpl->setVariable('MARK', $a_set['mark']);
365  $this->tpl->setVariable('COMMENT', $a_set['comment']);
366  $this->tpl->setVariable('PART_CHECKED', $a_set['participated'] ? 'checked="checked"' : '');
367  }
368 
372  protected function getParentLocalRoles()
373  {
374  $part = null;
375  $type = ilObject::_lookupType($this->member_ref_id, true);
376  switch ($type) {
377  case 'crs':
378  case 'grp':
379  $part = ilParticipants::getInstance($this->member_ref_id);
380  // no break
381  default:
382 
383  }
384  if (!$part instanceof ilParticipants) {
385  return [];
386  }
387 
388  $review = $GLOBALS['DIC']->rbac()->review();
389 
390  $local_parent_roles = $review->getLocalRoles($this->member_ref_id);
391  $this->logger->dump($local_parent_roles);
392 
393  $local_roles_info = [];
394  foreach ($local_parent_roles as $index => $role_id) {
395  $local_roles_info[$role_id] = ilObjRole::_getTranslation(
396  ilObject::_lookupTitle($role_id)
397  );
398  }
399  return $local_roles_info;
400  }
401 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
User query class.
__construct($a_parent_gui, ilObjSession $a_parent_obj, $a_parent_cmd)
$type
matchesFilterCriteria($a_user_info)
Check if user is filtered.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getParentLocalRoles()
Get local roles of parent object.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.
static _lookupTitle($a_id)
lookup object title
$index
Definition: metadata.php:60
getParentCmd()
Get parent command.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static getInstance($a_ref_id)
Get instance by ref_id.
$counter
isRegistrationEnabled()
Check if registration is enabled.
Class ilTable2GUI.
foreach($_POST as $key=> $value) $res
static _lookupObjId($a_id)
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
getSelectedColumns()
Get selected columns.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
static _getTranslation($a_role_title)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
isColumnSelected($a_col)
Is given column selected?
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $ilSetting
Definition: privfeed.php:17
setFormName($a_formname="")
Set Form name.
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.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20