ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseParticipantsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23  */
24 
25 include_once('./Services/Table/classes/class.ilTable2GUI.php');
26 
35 {
36  protected $type = 'admin';
37  protected $show_learning_progress = false;
38  protected $show_timings = false;
39  protected $show_edit_link = true;
40  protected static $export_allowed = false;
41  protected static $confirmation_required = true;
42  protected static $accepted_ids = null;
43  protected static $all_columns = null;
44 
45  protected $role_id = 0;
46 
54  public function __construct(
55  $a_parent_obj,
56  $a_type = 'admin',
57  $show_content = true,
58  $a_show_learning_progress = false,
59  $a_show_timings = false,
60  $a_show_edit_link= true,
61  $a_role_id = 0)
62  {
63  global $lng, $ilCtrl;
64 
65  $this->show_learning_progress = $a_show_learning_progress;
66  $this->show_timings = $a_show_timings;
67  $this->show_edit_link = $a_show_edit_link;
68 
69  $this->lng = $lng;
70  $this->lng->loadLanguageModule('crs');
71  $this->lng->loadLanguageModule('trac');
72  $this->ctrl = $ilCtrl;
73 
74  $this->type = $a_type;
75  $this->setRoleId($a_role_id);
76 
77  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
78  $this->privacy = ilPrivacySettings::_getInstance();
79 
80  // required before constructor for columns
81  $this->setId('crs_' . $a_type . '_' . $a_role_id.'_'. $a_parent_obj->object->getId());
82  parent::__construct($a_parent_obj, 'members');
83 
84  $this->initAcceptedAgreements();
85 
86  $this->setFormName('participants');
87 
88  $this->addColumn('', 'f', "1");
89  $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
90 
91  $all_cols = $this->getSelectableColumns();
92  foreach($this->getSelectedColumns() as $col)
93  {
94  $this->addColumn($all_cols[$col]['txt'], $col);
95  }
96 
97  if($this->show_learning_progress)
98  {
99  $this->addColumn($this->lng->txt('learning_progress'), 'progress');
100  }
101 
102  if($this->privacy->enabledCourseAccessTimes())
103  {
104  $this->addColumn($this->lng->txt('last_access'), 'access_ut', '16em');
105  }
106  $this->addColumn($this->lng->txt('crs_member_passed'), 'passed');
107  if($this->type == 'admin')
108  {
109  $this->setSelectAllCheckbox('admins');
110  $this->addColumn($this->lng->txt('crs_notification'), 'notification');
111  $this->addCommandButton('updateAdminStatus', $this->lng->txt('save'));
112  }
113  elseif($this->type == 'tutor')
114  {
115  $this->setSelectAllCheckbox('tutors');
116  $this->addColumn($this->lng->txt('crs_notification'), 'notification');
117  $this->addCommandButton('updateTutorStatus', $this->lng->txt('save'));
118  }
119  elseif($this->type == 'member')
120  {
121  $this->setSelectAllCheckbox('members');
122  $this->addColumn($this->lng->txt('crs_blocked'), 'blocked');
123  $this->addCommandButton('updateMemberStatus', $this->lng->txt('save'));
124  }
125  else
126  {
127  $this->setSelectAllCheckbox('roles');
128  $this->addColumn($this->lng->txt('crs_blocked'), 'blocked');
129  $this->addCommandButton('updateRoleStatus', $this->lng->txt('save'));
130 
131  }
132  $this->addColumn($this->lng->txt(''), 'optional');
133 
134  $this->setRowTemplate("tpl.show_participants_row.html", "Modules/Course");
135 
136  if($show_content)
137  {
138  $this->setDefaultOrderField('lastname');
139  $this->enable('sort');
140  $this->enable('header');
141  $this->enable('numinfo');
142  $this->enable('select_all');
143  }
144  else
145  {
146  $this->disable('content');
147  $this->disable('header');
148  $this->disable('footer');
149  $this->disable('numinfo');
150  $this->disable('select_all');
151  }
152 
153  $this->setEnableNumInfo(true);
154  $this->setExternalSegmentation(true);
155 
156  $this->getItems();
157  $this->setTopCommands(true);
158  $this->setEnableHeader(true);
159  $this->setEnableTitle(true);
160  $this->initFilter();
161  }
162 
166  public function setRoleId($a_role_id)
167  {
168  $this->role_id = $a_role_id;
169  }
170 
175  public function getRoleId()
176  {
177  return $this->role_id;
178  }
179 
180  public function getItems()
181  {
182 
183  }
184 
189  public function getSelectableColumns()
190  {
191  if(self::$all_columns)
192  {
193  return self::$all_columns;
194  }
195 
196  include_once './Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php';
197  $ef = ilExportFieldsInfo::_getInstanceByType($this->getParentObject()->object->getType());
198  self::$all_columns = $ef->getSelectableFieldsInfo($this->getParentObject()->object->getId());
199  return self::$all_columns;
200  }
201 
209  public function fillRow($a_set)
210  {
211  global $ilUser, $ilAccess;
212 
213  $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
214  $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
215 
216  if(!$ilAccess->checkAccessOfUser($a_set['usr_id'], 'read', '', $this->getParentObject()->object->getRefId()) and
217  is_array($info = $ilAccess->getInfo()))
218  {
219  $this->tpl->setCurrentBlock('access_warning');
220  $this->tpl->setVariable('PARENT_ACCESS', $info[0]['text']);
221  $this->tpl->parseCurrentBlock();
222  }
223 
224  if(!ilObjUser::_lookupActive($a_set['usr_id']))
225  {
226  $this->tpl->setCurrentBlock('access_warning');
227  $this->tpl->setVariable('PARENT_ACCESS', $this->lng->txt('usr_account_inactive'));
228  $this->tpl->parseCurrentBlock();
229  }
230 
231 
232  foreach($this->getSelectedColumns() as $field)
233  {
234  switch($field)
235  {
236  case 'gender':
237  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
238  $this->tpl->setCurrentBlock('custom_fields');
239  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
240  $this->tpl->parseCurrentBlock();
241  break;
242 
243  case 'birthday':
244  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
245  $this->tpl->setCurrentBlock('custom_fields');
246  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
247  $this->tpl->parseCurrentBlock();
248  break;
249 
250  default:
251  $this->tpl->setCurrentBlock('custom_fields');
252  $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
253  $this->tpl->parseCurrentBlock();
254  break;
255  }
256  }
257 
258  if($this->privacy->enabledCourseAccessTimes())
259  {
260  $this->tpl->setVariable('VAL_ACCESS', $a_set['access_time']);
261  }
262  if($this->show_learning_progress)
263  {
264  $this->tpl->setCurrentBlock('lp');
265  switch($a_set['progress'])
266  {
267  case LP_STATUS_COMPLETED:
268  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
269  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/complete.gif'));
270  break;
271 
273  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
274  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/incomplete.gif'));
275  break;
276 
278  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
279  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/not_attempted.gif'));
280  break;
281 
282  case LP_STATUS_FAILED:
283  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
284  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/failed.gif'));
285  break;
286  }
287  $this->tpl->parseCurrentBlock();
288  }
289 
290  if($this->type == 'admin')
291  {
292  $this->tpl->setVariable('VAL_POSTNAME', 'admins');
293  $this->tpl->setVariable('VAL_NOTIFICATION_ID', $a_set['usr_id']);
294  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED', ($a_set['notification'] ? 'checked="checked"' : ''));
295  }
296  elseif($this->type == 'tutor')
297  {
298  $this->tpl->setVariable('VAL_POSTNAME', 'tutors');
299  $this->tpl->setVariable('VAL_NOTIFICATION_ID', $a_set['usr_id']);
300  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED', ($a_set['notification'] ? 'checked="checked"' : ''));
301  }
302  elseif($this->type == 'member')
303  {
304  $this->tpl->setCurrentBlock('blocked');
305  $this->tpl->setVariable('VAL_POSTNAME','members');
306  $this->tpl->setVariable('VAL_BLOCKED_ID',$a_set['usr_id']);
307  $this->tpl->setVariable('VAL_BLOCKED_CHECKED',($a_set['blocked'] ? 'checked="checked"' : ''));
308  $this->tpl->parseCurrentBlock();
309  }
310  else
311  {
312  $this->tpl->setCurrentBlock('blocked');
313  $this->tpl->setVariable('VAL_BLOCKED_ID', $a_set['usr_id']);
314  $this->tpl->setVariable('VAL_BLOCKED_CHECKED', ($a_set['blocked'] ? 'checked="checked"' : ''));
315  $this->tpl->parseCurrentBlock();
316 
317  $this->tpl->setVariable('VAL_POSTNAME','roles');
318  }
319 
320  $this->tpl->setVariable('VAL_PASSED_ID',$a_set['usr_id']);
321  $this->tpl->setVariable('VAL_PASSED_CHECKED',($a_set['passed'] ? 'checked="checked"' : ''));
322 
323  $this->ctrl->setParameter($this->parent_obj, 'member_id', $a_set['usr_id']);
324  if($this->show_edit_link)
325  {
326  $this->tpl->setCurrentBlock('link');
327  $this->tpl->setVariable('LINK_NAME', $this->ctrl->getLinkTarget($this->parent_obj, 'editMember'));
328  $this->tpl->setVariable('LINK_TXT', $this->lng->txt('edit'));
329  $this->tpl->parseCurrentBlock();
330  }
331  $this->ctrl->clearParameters($this->parent_obj);
332 
333  if($this->show_timings)
334  {
335  $this->ctrl->setParameterByClass('ilcoursecontentgui', 'member_id', $a_set['usr_id']);
336  $this->tpl->setCurrentBlock('link');
337  $this->tpl->setVariable('LINK_NAME', $this->ctrl->getLinkTargetByClass('ilcoursecontentgui', 'showUserTimings'));
338  $this->tpl->setVariable('LINK_TXT', $this->lng->txt('timings_timings'));
339  $this->tpl->parseCurrentBlock();
340  }
341  }
342 
349  public function parse()
350  {
351  global $rbacreview;
352 
353  $this->determineOffsetAndOrder();
354 
355  include_once './Services/User/classes/class.ilUserQuery.php';
356 
357  $additional_fields = $this->getSelectedColumns();
358  unset($additional_fields["firstname"]);
359  unset($additional_fields["lastname"]);
360  unset($additional_fields["last_login"]);
361  unset($additional_fields["access_until"]);
362 
363  $udf_ids = $usr_data_fields = $odf_ids = array();
364  foreach($additional_fields as $field)
365  {
366  if(substr($field, 0, 3) == 'udf')
367  {
368  $udf_ids[] = substr($field, 4);
369  continue;
370  }
371  if(substr($field, 0, 3) == 'odf')
372  {
373  $odf_ids[] = substr($field, 4);
374  continue;
375  }
376 
377  $usr_data_fields[] = $field;
378  }
379 
380  $usr_data = ilUserQuery::getUserListData(
381  $this->getOrderField(),
382  $this->getOrderDirection(),
383  $this->getOffset(),
384  $this->getLimit(),
385  '',
386  '',
387  null,
388  false,
389  false,
390  0,
391  $this->getRoleId(),
392  null,
393  $usr_data_fields,
394  $part
395  );
396  foreach((array) $usr_data['set'] as $user)
397  {
398  $usr_ids[] = $user['usr_id'];
399  }
400 
401  // merge course data
402  $course_user_data = $this->getParentObject()->readMemberData($usr_ids,$this->type == 'admin');
403  $a_user_data = array();
404  foreach((array) $usr_data['set'] as $ud)
405  {
406  $a_user_data[$ud['usr_id']] = array_merge($ud,$course_user_data[$ud['usr_id']]);
407  }
408 
409  // Custom user data fields
410  if($udf_ids)
411  {
412  include_once './Services/User/classes/class.ilUserDefinedData.php';
413  $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids);
414  foreach($data as $usr_id => $fields)
415  {
416  if(!$this->checkAcceptance($usr_id))
417  {
418  continue;
419  }
420 
421  foreach($fields as $field_id => $value)
422  {
423  $a_user_data[$usr_id]['udf_' . $field_id] = $value;
424  }
425  }
426  }
427  // Object specific user data fields
428  if($odf_ids)
429  {
430  include_once './Modules/Course/classes/Export/class.ilCourseUserData.php';
431  $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId());
432  foreach($data as $usr_id => $fields)
433  {
434  // #7264: as we get data for all course members filter against user data
435  if(!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids))
436  {
437  continue;
438  }
439 
440  foreach($fields as $field_id => $value)
441  {
442  $a_user_data[$usr_id]['odf_' . $field_id] = $value;
443  }
444  }
445  }
446 
447  foreach($usr_data['set'] as $user)
448  {
449  // Check acceptance
450  if(!$this->checkAcceptance($user['usr_id']))
451  {
452  continue;
453  }
454  // DONE: accepted
455  foreach($usr_data_fields as $field)
456  {
457  $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : '';
458  }
459  }
460  $this->setMaxCount($usr_data['cnt'] ? $usr_data['cnt'] : 0);
461  return $this->setData($a_user_data);
462  }
463 
464  public function checkAcceptance($a_usr_id)
465  {
466  if(!self::$confirmation_required)
467  {
468  return true;
469  }
470  if(!self::$export_allowed)
471  {
472  return false;
473  }
474  return in_array($a_usr_id, self::$accepted_ids);
475  }
476 
481  public function initAcceptedAgreements()
482  {
483  if(self::$accepted_ids !== NULL)
484  {
485  return true;
486  }
487 
488  self::$export_allowed = ilPrivacySettings::_getInstance()->checkExportAccess($this->getParentObject()->object->getRefId());
489  self::$confirmation_required = ilPrivacySettings::_getInstance()->courseConfirmationRequired();
490 
491  include_once 'Services/Membership/classes/class.ilMemberAgreement.php';
492  self::$accepted_ids = ilMemberAgreement::lookupAcceptedAgreements($this->getParentObject()->object->getId());
493  }
494 
495 }
496 ?>