ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilGroupParticipantsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Membership/classes/class.ilParticipantsTableGUI.php';
14 {
15  protected $type = 'admin';
16  protected $role = 0;
17  protected $show_learning_progress = false;
18  protected $show_edit_link = TRUE;
19 
20 
28  public function __construct(
29  $a_parent_obj,$a_type = 'admin',
30  $show_content = true,
32  $a_role_id = 0
33  )
34  {
35  global $lng,$ilCtrl;
36 
37  $this->show_learning_progress = $show_learning_progress;
38 
39  $this->lng = $lng;
40  $this->lng->loadLanguageModule('grp');
41  $this->lng->loadLanguageModule('trac');
42  $this->ctrl = $ilCtrl;
43 
44  $this->type = $a_type;
45  $this->role = $a_role_id;
46 
47  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
48  $this->privacy = ilPrivacySettings::_getInstance();
49 
50  switch($this->type)
51  {
52  case 'admin':
53  $this->setPrefix('admin');
54  break;
55  case 'member':
56  $this->setPrefix('member');
57  break;
58  default:
59  $this->setPrefix('role');
60  break;
61  }
62 
63  $this->setId('grp_'.$a_type.'_'.$this->getRole().'_'.$a_parent_obj->object->getId());
64  parent::__construct($a_parent_obj,'members');
65 
66  $this->initSettings();
67 
68  $this->setFormName('participants');
69 
70  $this->addColumn('','f',"1");
71  $this->addColumn($this->lng->txt('name'),'lastname','20%');
72 
73  $all_cols = $this->getSelectableColumns();
74  foreach($this->getSelectedColumns() as $col)
75  {
76  $this->addColumn($all_cols[$col]['txt'],$col);
77  }
78 
79  if($this->show_learning_progress)
80  {
81  $this->addColumn($this->lng->txt('learning_progress'),'progress');
82  }
83 
84  if($this->privacy->enabledGroupAccessTimes())
85  {
86  $this->addColumn($this->lng->txt('last_access'),'access_time_unix');
87  }
88  if($this->type == 'admin')
89  {
90  $this->setSelectAllCheckbox('admins');
91  $this->addColumn($this->lng->txt('grp_notification'),'notification');
92  $this->addCommandButton('updateStatus',$this->lng->txt('save'));
93  }
94  elseif($this->type == 'member')
95  {
96  $this->setSelectAllCheckbox('members');
97  }
98  else
99  {
100  $this->setSelectAllCheckbox('roles');
101  }
102  $this->addColumn($this->lng->txt(''),'optional');
103  $this->setDefaultOrderField('lastname');
104 
105  $this->setRowTemplate("tpl.show_participants_row.html","Modules/Group");
106 
107  $this->setShowRowsSelector(true);
108 
109  if($show_content)
110  {
111  $this->enable('sort');
112  $this->enable('header');
113  $this->enable('numinfo');
114  $this->enable('select_all');
115  }
116  else
117  {
118  $this->disable('content');
119  $this->disable('header');
120  $this->disable('footer');
121  $this->disable('numinfo');
122  $this->disable('select_all');
123  }
124  }
125 
130  public function getRole()
131  {
132  return $this->role;
133  }
134 
135 
136 
144  public function fillRow($a_set)
145  {
146  global $ilUser,$ilAccess;
147 
148  $this->tpl->setVariable('VAL_ID',$a_set['usr_id']);
149  $this->tpl->setVariable('VAL_NAME',$a_set['lastname'].', '.$a_set['firstname']);
150  if(!$ilAccess->checkAccessOfUser($a_set['usr_id'],'read','',$this->getParentObject()->object->getRefId()) and
151  is_array($info = $ilAccess->getInfo()))
152  {
153  $this->tpl->setCurrentBlock('access_warning');
154  $this->tpl->setVariable('PARENT_ACCESS',$info[0]['text']);
155  $this->tpl->parseCurrentBlock();
156  }
157 
158  if(!ilObjUser::_lookupActive($a_set['usr_id']))
159  {
160  $this->tpl->setCurrentBlock('access_warning');
161  $this->tpl->setVariable('PARENT_ACCESS',$this->lng->txt('usr_account_inactive'));
162  $this->tpl->parseCurrentBlock();
163  }
164 
165 
166  foreach($this->getSelectedColumns() as $field)
167  {
168  switch($field)
169  {
170  case 'gender':
171  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_'.$a_set['gender']) : '';
172  $this->tpl->setCurrentBlock('custom_fields');
173  $this->tpl->setVariable('VAL_CUST',$a_set[$field]);
174  $this->tpl->parseCurrentBlock();
175  break;
176 
177  case 'birthday':
178  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'],IL_CAL_DATE)) : $this->lng->txt('no_date');
179  $this->tpl->setCurrentBlock('custom_fields');
180  $this->tpl->setVariable('VAL_CUST',$a_set[$field]);
181  $this->tpl->parseCurrentBlock();
182  break;
183 
184  case 'consultation_hour':
185  $this->tpl->setCurrentBlock('custom_field');
186  $dts = array();
187  foreach((array) $a_set['consultation_hours'] as $ch)
188  {
190  new ilDateTime($ch['dt'],IL_CAL_UNIX),
191  new ilDateTime($ch['dtend'],IL_CAL_UNIX)
192  );
193  if($ch['explanation'])
194  {
195  $tmp .= ' ' . $ch['explanation'];
196  }
197  $dts[] = $tmp;
198  }
199  $dt_string = implode('<br />', $dts);
200  $this->tpl->setVariable('VAL_CUST',$dt_string) ;
201  $this->tpl->parseCurrentBlock();
202  break;
203 
204  case 'prtf':
205  $tmp = array();
206  if(is_array($a_set['prtf']))
207  {
208  foreach($a_set['prtf'] as $prtf_url => $prtf_txt)
209  {
210  $tmp[] = '<a href="'.$prtf_url.'">'.$prtf_txt.'</a>';
211  }
212  }
213  $this->tpl->setVariable('VAL_CUST', implode('<br />', $tmp)) ;
214  break;
215 
216  case 'odf_last_update':
217  $this->tpl->setVariable('VAL_EDIT_INFO',(string) $a_set['odf_info_txt']);
218  break;
219 
220  default:
221  $this->tpl->setCurrentBlock('custom_fields');
222  $this->tpl->setVariable('VAL_CUST',isset($a_set[$field]) ? (string) $a_set[$field] : '');
223  $this->tpl->parseCurrentBlock();
224  break;
225  }
226  }
227 
228  if($this->privacy->enabledGroupAccessTimes())
229  {
230  $this->tpl->setVariable('VAL_ACCESS',$a_set['access_time']);
231  }
232 
233  if($this->show_learning_progress)
234  {
235  $this->tpl->setCurrentBlock('lp');
236  switch($a_set['progress'])
237  {
239  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
240  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/complete.svg'));
241  break;
242 
244  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
245  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/incomplete.svg'));
246  break;
247 
249  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
250  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/not_attempted.svg'));
251  break;
252 
254  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
255  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/failed.svg'));
256  break;
257 
258  }
259  $this->tpl->parseCurrentBlock();
260  }
261 
262 
263  if($this->type == 'admin')
264  {
265  $this->tpl->setVariable('VAL_POSTNAME','admins');
266  $this->tpl->setVariable('VAL_NOTIFICATION_ID',$a_set['usr_id']);
267  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED',$a_set['notification'] ? 'checked="checked"' : '');
268  }
269  elseif($this->type == 'member')
270  {
271  $this->tpl->setVariable('VAL_POSTNAME','members');
272  }
273  else
274  {
275  $this->tpl->setVariable('VAL_POSTNAME','roles');
276  }
277 
278  $this->showActionLinks($a_set);
279 
280 
281  $this->tpl->setVariable('VAL_LOGIN',$a_set['login']);
282  }
283 
289  public function parse($a_user_data)
290  {
291  include_once './Services/User/classes/class.ilUserQuery.php';
292 
293  $additional_fields = $this->getSelectedColumns();
294  unset($additional_fields["firstname"]);
295  unset($additional_fields["lastname"]);
296  unset($additional_fields["last_login"]);
297  unset($additional_fields["access_until"]);
298  unset($additional_fields['consultation_hour']);
299  unset($additional_fields['prtf']);
300 
301  switch($this->type)
302  {
303  case 'admin':
304  $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getAdmins();
305  break;
306  case 'member':
307  $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole());
308  break;
309  case 'role':
310  $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole());
311  break;
312  }
313 
314  $udf_ids = $usr_data_fields = $odf_ids = array();
315  foreach($additional_fields as $field)
316  {
317  if(substr($field,0,3) == 'udf')
318  {
319  $udf_ids[] = substr($field,4);
320  continue;
321  }
322  if(substr($field,0,3) == 'odf')
323  {
324  $odf_ids[] = substr($field,4);
325  continue;
326  }
327 
328  $usr_data_fields[] = $field;
329  }
330 
331  $usr_data = ilUserQuery::getUserListData(
332  'login',
333  'ASC',
334  0,
335  9999,
336  '',
337  '',
338  null,
339  false,
340  false,
341  0,
342  0,
343  null,
344  $usr_data_fields,
345  $part
346  );
347  // Custom user data fields
348  if($udf_ids)
349  {
350  include_once './Services/User/classes/class.ilUserDefinedData.php';
351  $data = ilUserDefinedData::lookupData($part, $udf_ids);
352  foreach($data as $usr_id => $fields)
353  {
354  if(!$this->checkAcceptance($usr_id))
355  {
356  continue;
357  }
358 
359  foreach($fields as $field_id => $value)
360  {
361  $a_user_data[$usr_id]['udf_'.$field_id] = $value;
362  }
363  }
364  }
365  // Object specific user data fields
366  if($odf_ids)
367  {
368  include_once './Modules/Course/classes/Export/class.ilCourseUserData.php';
369  $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId());
370  foreach($data as $usr_id => $fields)
371  {
372  if(!$this->checkAcceptance($usr_id))
373  {
374  continue;
375  }
376 
377  foreach($fields as $field_id => $value)
378  {
379  if($a_user_data[$usr_id])
380  {
381  $a_user_data[$usr_id]['odf_'.$field_id] = $value;
382  }
383  }
384  }
385  // add last edit date
386  include_once './Services/Membership/classes/class.ilObjectCustomUserFieldHistory.php';
387  foreach(ilObjectCustomUserFieldHistory::lookupEntriesByObjectId($this->getParentObject()->object->getId()) as $usr_id => $edit_info)
388  {
389  if(!isset($a_user_data[$usr_id]))
390  {
391  continue;
392  }
393 
394  include_once './Services/PrivacySecurity/classes/class.ilPrivacySettings.php';
395  if($usr_id == $edit_info['update_user'])
396  {
397  $a_user_data[$usr_id]['odf_last_update'] = '';
398  $a_user_data[$usr_id]['odf_info_txt'] = $GLOBALS['lng']->txt('cdf_edited_by_self');
399  if(ilPrivacySettings::_getInstance()->enabledAccessTimesByType($this->getParentObject()->object->getType()))
400  {
401  $a_user_data[$usr_id]['odf_last_update'] .= ('_'.$edit_info['editing_time']->get(IL_CAL_UNIX));
402  $a_user_data[$usr_id]['odf_info_txt'] .= (', '.ilDatePresentation::formatDate($edit_info['editing_time']));
403  }
404  }
405  else
406  {
407  $a_user_data[$usr_id]['odf_last_update'] = $edit_info['edit_user'];
408  $a_user_data[$usr_id]['odf_last_update'] .= ('_'.$edit_info['editing_time']->get(IL_CAL_UNIX));
409 
410  $name = ilObjUser::_lookupName($edit_info['update_user']);
411  $a_user_data[$usr_id]['odf_info_txt'] = ($name['firstname'].' '.$name['lastname'].', '.ilDatePresentation::formatDate($edit_info['editing_time']));
412  }
413  }
414  }
415  foreach($usr_data['set'] as $user)
416  {
417  // Check acceptance
418  if(!$this->checkAcceptance($user['usr_id']))
419  {
420  continue;
421  }
422  // DONE: accepted
423  foreach($usr_data_fields as $field)
424  {
425  $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : '';
426  }
427  }
428  // consultation hours
429  if($this->isColumnSelected('consultation_hour'))
430  {
431  include_once './Services/Booking/classes/class.ilBookingEntry.php';
432  foreach(ilBookingEntry::lookupManagedBookingsForObject($this->getParentObject()->object->getId(), $GLOBALS['ilUser']->getId()) as $buser => $booking)
433  {
434  if(isset($a_user_data[$buser]))
435  {
436  $a_user_data[$buser]['consultation_hour'] = $booking[0]['dt'];
437  $a_user_data[$buser]['consultation_hour_end'] = $booking[0]['dtend'];
438  $a_user_data[$buser]['consultation_hours'] = $booking;
439  }
440  }
441  }
442 
443  return $this->setData($a_user_data);
444  }
445 }
446 ?>