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