ILIAS  Release_4_2_x_branch Revision 61807
 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/Table/classes/class.ilTable2GUI.php');
5 
15 {
16  protected $type = 'admin';
17  protected $role = 0;
18  protected $show_learning_progress = false;
19 
20  protected static $export_allowed = false;
21  protected static $confirmation_required = true;
22  protected static $accepted_ids = null;
23 
24  protected static $all_columns = null;
25 
33  public function __construct(
34  $a_parent_obj,$a_type = 'admin',
35  $show_content = true,
37  $a_role_id = 0
38  )
39  {
40  global $lng,$ilCtrl;
41 
42  $this->show_learning_progress = $show_learning_progress;
43 
44  $this->lng = $lng;
45  $this->lng->loadLanguageModule('grp');
46  $this->lng->loadLanguageModule('trac');
47  $this->ctrl = $ilCtrl;
48 
49  $this->type = $a_type;
50  $this->role = $a_role_id;
51 
52  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
53  $this->privacy = ilPrivacySettings::_getInstance();
54 
55  $this->setId('grp_'.$a_type.'_'.$this->getRole().'_'.$a_parent_obj->object->getId());
56  parent::__construct($a_parent_obj,'members');
57 
58  $this->initAcceptedAgreements();
59 
60  $this->setFormName('participants');
61 
62  $this->addColumn('','f',"1");
63  $this->addColumn($this->lng->txt('name'),'lastname','20%');
64 
65  $all_cols = $this->getSelectableColumns();
66  foreach($this->getSelectedColumns() as $col)
67  {
68  $this->addColumn($all_cols[$col]['txt'],$col);
69  }
70 
71  if($this->show_learning_progress)
72  {
73  $this->addColumn($this->lng->txt('learning_progress'),'progress');
74  }
75 
76  if($this->privacy->enabledGroupAccessTimes())
77  {
78  $this->addColumn($this->lng->txt('last_access'),'access_time_unix');
79  }
80  if($this->type == 'admin')
81  {
82  $this->setPrefix('admin');
83  $this->setSelectAllCheckbox('admins');
84  $this->addColumn($this->lng->txt('grp_notification'),'notification');
85  $this->addCommandButton('updateStatus',$this->lng->txt('save'));
86  }
87  elseif($this->type == 'member')
88  {
89  $this->setPrefix('member');
90  $this->setSelectAllCheckbox('members');
91  }
92  else
93  {
94  $this->setPrefix('role');
95  $this->setSelectAllCheckbox('roles');
96  }
97  $this->addColumn($this->lng->txt(''),'optional');
98  $this->setDefaultOrderField('lastname');
99 
100  $this->setRowTemplate("tpl.show_participants_row.html","Modules/Group");
101 
102  if($show_content)
103  {
104  $this->enable('sort');
105  $this->enable('header');
106  $this->enable('numinfo');
107  $this->enable('select_all');
108  }
109  else
110  {
111  $this->disable('content');
112  $this->disable('header');
113  $this->disable('footer');
114  $this->disable('numinfo');
115  $this->disable('select_all');
116  }
117  }
118 
123  public function getRole()
124  {
125  return $this->role;
126  }
127 
132  public function getSelectableColumns()
133  {
134  if(self::$all_columns)
135  {
136  return self::$all_columns;
137  }
138 
139  include_once './Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php';
140  $ef = ilExportFieldsInfo::_getInstanceByType($this->getParentObject()->object->getType());
141  self::$all_columns = $ef->getSelectableFieldsInfo($this->getParentObject()->object->getId());
142  return self::$all_columns;
143  }
144 
145 
153  public function fillRow($a_set)
154  {
155  global $ilUser,$ilAccess;
156 
157  $this->tpl->setVariable('VAL_ID',$a_set['usr_id']);
158  $this->tpl->setVariable('VAL_NAME',$a_set['lastname'].', '.$a_set['firstname']);
159  if(!$ilAccess->checkAccessOfUser($a_set['usr_id'],'read','',$this->getParentObject()->object->getRefId()) and
160  is_array($info = $ilAccess->getInfo()))
161  {
162  $this->tpl->setCurrentBlock('access_warning');
163  $this->tpl->setVariable('PARENT_ACCESS',$info[0]['text']);
164  $this->tpl->parseCurrentBlock();
165  }
166 
167  if(!ilObjUser::_lookupActive($a_set['usr_id']))
168  {
169  $this->tpl->setCurrentBlock('access_warning');
170  $this->tpl->setVariable('PARENT_ACCESS',$this->lng->txt('usr_account_inactive'));
171  $this->tpl->parseCurrentBlock();
172  }
173 
174 
175  foreach($this->getSelectedColumns() as $field)
176  {
177  switch($field)
178  {
179  case 'gender':
180  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_'.$a_set['gender']) : '';
181  $this->tpl->setCurrentBlock('custom_fields');
182  $this->tpl->setVariable('VAL_CUST',$a_set[$field]);
183  $this->tpl->parseCurrentBlock();
184  break;
185 
186  case 'birthday':
187  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'],IL_CAL_DATE)) : $this->lng->txt('no_date');
188  $this->tpl->setCurrentBlock('custom_fields');
189  $this->tpl->setVariable('VAL_CUST',$a_set[$field]);
190  $this->tpl->parseCurrentBlock();
191  break;
192 
193  default:
194  $this->tpl->setCurrentBlock('custom_fields');
195  $this->tpl->setVariable('VAL_CUST',isset($a_set[$field]) ? (string) $a_set[$field] : '');
196  $this->tpl->parseCurrentBlock();
197  break;
198  }
199  }
200 
201  if($this->privacy->enabledGroupAccessTimes())
202  {
203  $this->tpl->setVariable('VAL_ACCESS',$a_set['access_time']);
204  }
205 
206  if($this->show_learning_progress)
207  {
208  $this->tpl->setCurrentBlock('lp');
209  switch($a_set['progress'])
210  {
211  case LP_STATUS_COMPLETED:
212  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
213  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/complete.gif'));
214  break;
215 
217  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
218  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/incomplete.gif'));
219  break;
220 
222  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
223  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/not_attempted.gif'));
224  break;
225 
226  case LP_STATUS_FAILED:
227  $this->tpl->setVariable('LP_STATUS_ALT',$this->lng->txt($a_set['progress']));
228  $this->tpl->setVariable('LP_STATUS_PATH',ilUtil::getImagePath('scorm/failed.gif'));
229  break;
230 
231  }
232  $this->tpl->parseCurrentBlock();
233  }
234 
235 
236  if($this->type == 'admin')
237  {
238  $this->tpl->setVariable('VAL_POSTNAME','admins');
239  $this->tpl->setVariable('VAL_NOTIFICATION_ID',$a_set['usr_id']);
240  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED',$a_set['notification'] ? 'checked="checked"' : '');
241  }
242  elseif($this->type == 'member')
243  {
244  $this->tpl->setVariable('VAL_POSTNAME','members');
245  }
246  else
247  {
248  $this->tpl->setVariable('VAL_POSTNAME','roles');
249  }
250 
251  $this->ctrl->setParameter($this->parent_obj,'member_id',$a_set['usr_id']);
252  $this->tpl->setVariable('LINK_NAME',$this->ctrl->getLinkTarget($this->parent_obj,'editMember'));
253  $this->tpl->setVariable('LINK_TXT',$this->lng->txt('edit'));
254  $this->ctrl->clearParameters($this->parent_obj);
255 
256  $this->tpl->setVariable('VAL_LOGIN',$a_set['login']);
257  }
258 
264  public function parse($a_user_data)
265  {
266  include_once './Services/User/classes/class.ilUserQuery.php';
267 
268  $additional_fields = $this->getSelectedColumns();
269  unset($additional_fields["firstname"]);
270  unset($additional_fields["lastname"]);
271  unset($additional_fields["last_login"]);
272  unset($additional_fields["access_until"]);
273 
274  switch($this->type)
275  {
276  case 'admin':
277  $part = ilGroupParticipants::_getInstanceByObjId($this->getParentObject()->object->getId())->getAdmins();
278  break;
279  case 'member':
280  $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole());
281  break;
282  case 'role':
283  $part = $GLOBALS['rbacreview']->assignedUsers($this->getRole());
284  break;
285  }
286 
287  $udf_ids = $usr_data_fields = $odf_ids = array();
288  foreach($additional_fields as $field)
289  {
290  if(substr($field,0,3) == 'udf')
291  {
292  $udf_ids[] = substr($field,4);
293  continue;
294  }
295  if(substr($field,0,3) == 'odf')
296  {
297  $odf_ids[] = substr($field,4);
298  continue;
299  }
300 
301  $usr_data_fields[] = $field;
302  }
303 
304  $usr_data = ilUserQuery::getUserListData(
305  'login',
306  'ASC',
307  0,
308  9999,
309  '',
310  '',
311  null,
312  false,
313  false,
314  0,
315  0,
316  null,
317  $usr_data_fields,
318  $part
319  );
320  // Custom user data fields
321  if($udf_ids)
322  {
323  include_once './Services/User/classes/class.ilUserDefinedData.php';
324  $data = ilUserDefinedData::lookupData($part, $udf_ids);
325  foreach($data as $usr_id => $fields)
326  {
327  if(!$this->checkAcceptance($usr_id))
328  {
329  continue;
330  }
331 
332  foreach($fields as $field_id => $value)
333  {
334  $a_user_data[$usr_id]['udf_'.$field_id] = $value;
335  }
336  }
337  }
338  // Object specific user data fields
339  if($odf_ids)
340  {
341  include_once './Modules/Course/classes/Export/class.ilCourseUserData.php';
342  $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId());
343  foreach($data as $usr_id => $fields)
344  {
345  if(!$this->checkAcceptance($usr_id))
346  {
347  continue;
348  }
349 
350  foreach($fields as $field_id => $value)
351  {
352  if($a_user_data[$usr_id])
353  {
354  $a_user_data[$usr_id]['odf_'.$field_id] = $value;
355  }
356  }
357  }
358  }
359 
360  foreach($usr_data['set'] as $user)
361  {
362  // Check acceptance
363  if(!$this->checkAcceptance($user['usr_id']))
364  {
365  continue;
366  }
367  // DONE: accepted
368  foreach($usr_data_fields as $field)
369  {
370  $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : '';
371  }
372  }
373  return $this->setData($a_user_data);
374  }
375 
381  public function checkAcceptance($a_usr_id)
382  {
383  if(!self::$confirmation_required)
384  {
385  return true;
386  }
387  if(!self::$export_allowed)
388  {
389  return false;
390  }
391  return in_array($a_usr_id,self::$accepted_ids);
392  }
393 
394 
399  public function initAcceptedAgreements()
400  {
401  if(self::$accepted_ids !== NULL)
402  {
403  return true;
404  }
405 
406  self::$export_allowed = ilPrivacySettings::_getInstance()->checkExportAccess($this->getParentObject()->object->getRefId());
407  self::$confirmation_required = ilPrivacySettings::_getInstance()->groupConfirmationRequired();
408 
409  include_once 'Services/Membership/classes/class.ilMemberAgreement.php';
410  self::$accepted_ids = ilMemberAgreement::lookupAcceptedAgreements($this->getParentObject()->object->getId());
411  }
412 
413 }
414 ?>