ILIAS  release_4-3 Revision
 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  $a_show_lp_status_sync = false)
63  {
64  global $lng, $ilCtrl;
65 
66  $this->show_learning_progress = $a_show_learning_progress;
67  $this->show_timings = $a_show_timings;
68  $this->show_edit_link = $a_show_edit_link;
69  $this->show_lp_status_sync = $a_show_lp_status_sync;
70 
71  // #13208
72  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
74  {
75  $this->show_lp_status_sync = false;
76  }
77 
78  $this->lng = $lng;
79  $this->lng->loadLanguageModule('crs');
80  $this->lng->loadLanguageModule('trac');
81  $this->ctrl = $ilCtrl;
82 
83  $this->type = $a_type;
84  $this->setRoleId($a_role_id);
85 
86  include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
87  $this->privacy = ilPrivacySettings::_getInstance();
88 
89  // required before constructor for columns
90  $this->setId('crs_' . $a_type . '_' . $a_role_id.'_'. $a_parent_obj->object->getId());
91  parent::__construct($a_parent_obj, 'members');
92 
93  $this->initAcceptedAgreements();
94 
95  $this->setFormName('participants');
96 
97  $this->addColumn('', 'f', "1");
98  $this->addColumn($this->lng->txt('name'), 'lastname', '20%');
99 
100  $all_cols = $this->getSelectableColumns();
101  foreach($this->getSelectedColumns() as $col)
102  {
103  $this->addColumn($all_cols[$col]['txt'], $col);
104  }
105 
106  if($this->show_learning_progress)
107  {
108  $this->addColumn($this->lng->txt('learning_progress'), 'progress');
109  }
110 
111  if($this->privacy->enabledCourseAccessTimes())
112  {
113  $this->addColumn($this->lng->txt('last_access'), 'access_ut', '16em');
114  }
115 
116  $this->addColumn($this->lng->txt('crs_member_passed'), 'passed');
117  if($this->show_lp_status_sync)
118  {
119  $this->addColumn($this->lng->txt('crs_member_passed_status_changed'), 'passed_info');
120  }
121 
122  if($this->type == 'admin')
123  {
124  $this->setSelectAllCheckbox('admins');
125  $this->addColumn($this->lng->txt('crs_notification_list_title'), 'notification');
126  $this->addCommandButton('updateAdminStatus', $this->lng->txt('save'));
127  }
128  elseif($this->type == 'tutor')
129  {
130  $this->setSelectAllCheckbox('tutors');
131  $this->addColumn($this->lng->txt('crs_notification_list_title'), 'notification');
132  $this->addCommandButton('updateTutorStatus', $this->lng->txt('save'));
133  }
134  elseif($this->type == 'member')
135  {
136  $this->setSelectAllCheckbox('members');
137  $this->addColumn($this->lng->txt('crs_blocked'), 'blocked');
138  $this->addCommandButton('updateMemberStatus', $this->lng->txt('save'));
139  }
140  else
141  {
142  $this->setSelectAllCheckbox('roles');
143  $this->addColumn($this->lng->txt('crs_blocked'), 'blocked');
144  $this->addCommandButton('updateRoleStatus', $this->lng->txt('save'));
145 
146  }
147  $this->addColumn($this->lng->txt(''), 'optional');
148 
149  $this->setRowTemplate("tpl.show_participants_row.html", "Modules/Course");
150 
151  if($show_content)
152  {
153  $this->setDefaultOrderField('lastname');
154  $this->enable('sort');
155  $this->enable('header');
156  $this->enable('numinfo');
157  $this->enable('select_all');
158  }
159  else
160  {
161  $this->disable('content');
162  $this->disable('header');
163  $this->disable('footer');
164  $this->disable('numinfo');
165  $this->disable('select_all');
166  }
167 
168  $this->setEnableNumInfo(true);
169  $this->setExternalSegmentation(true);
170 
171  $this->getItems();
172  $this->setTopCommands(true);
173  $this->setEnableHeader(true);
174  $this->setEnableTitle(true);
175  $this->initFilter();
176 
177  include_once "Services/Certificate/classes/class.ilCertificate.php";
178  $this->enable_certificates = ilCertificate::isActive();
179  if($this->enable_certificates)
180  {
181  $this->enable_certificates = ilCertificate::isObjectActive($a_parent_obj->object->getId());
182  }
183  if($this->enable_certificates)
184  {
185  $lng->loadLanguageModule('certificate');
186  }
187  }
188 
192  public function setRoleId($a_role_id)
193  {
194  $this->role_id = $a_role_id;
195  }
196 
201  public function getRoleId()
202  {
203  return $this->role_id;
204  }
205 
206  public function getItems()
207  {
208 
209  }
210 
215  public function getSelectableColumns()
216  {
217  if(self::$all_columns)
218  {
219  return self::$all_columns;
220  }
221 
222  include_once './Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php';
223  $ef = ilExportFieldsInfo::_getInstanceByType($this->getParentObject()->object->getType());
224  self::$all_columns = $ef->getSelectableFieldsInfo($this->getParentObject()->object->getId());
225  return self::$all_columns;
226  }
227 
235  public function fillRow($a_set)
236  {
237  global $ilAccess;
238 
239  $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
240  $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
241 
242  if(!$ilAccess->checkAccessOfUser($a_set['usr_id'], 'read', '', $this->getParentObject()->object->getRefId()) and
243  is_array($info = $ilAccess->getInfo()))
244  {
245  $this->tpl->setCurrentBlock('access_warning');
246  $this->tpl->setVariable('PARENT_ACCESS', $info[0]['text']);
247  $this->tpl->parseCurrentBlock();
248  }
249 
250  if(!ilObjUser::_lookupActive($a_set['usr_id']))
251  {
252  $this->tpl->setCurrentBlock('access_warning');
253  $this->tpl->setVariable('PARENT_ACCESS', $this->lng->txt('usr_account_inactive'));
254  $this->tpl->parseCurrentBlock();
255  }
256 
257 
258  foreach($this->getSelectedColumns() as $field)
259  {
260  switch($field)
261  {
262  case 'gender':
263  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
264  $this->tpl->setCurrentBlock('custom_fields');
265  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
266  $this->tpl->parseCurrentBlock();
267  break;
268 
269  case 'birthday':
270  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
271  $this->tpl->setCurrentBlock('custom_fields');
272  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
273  $this->tpl->parseCurrentBlock();
274  break;
275 
276  default:
277  $this->tpl->setCurrentBlock('custom_fields');
278  $this->tpl->setVariable('VAL_CUST', isset($a_set[$field]) ? (string) $a_set[$field] : '');
279  $this->tpl->parseCurrentBlock();
280  break;
281  }
282  }
283 
284  if($this->privacy->enabledCourseAccessTimes())
285  {
286  $this->tpl->setVariable('VAL_ACCESS', $a_set['access_time']);
287  }
288  if($this->show_learning_progress)
289  {
290  $this->tpl->setCurrentBlock('lp');
291  switch($a_set['progress'])
292  {
293  case LP_STATUS_COMPLETED:
294  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
295  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/complete.png'));
296  break;
297 
299  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
300  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/incomplete.png'));
301  break;
302 
304  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
305  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/not_attempted.png'));
306  break;
307 
308  case LP_STATUS_FAILED:
309  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt($a_set['progress']));
310  $this->tpl->setVariable('LP_STATUS_PATH', ilUtil::getImagePath('scorm/failed.png'));
311  break;
312  }
313  $this->tpl->parseCurrentBlock();
314  }
315  if($this->type == 'admin')
316  {
317  $this->tpl->setVariable('VAL_POSTNAME', 'admins');
318  $this->tpl->setVariable('VAL_NOTIFICATION_ID', $a_set['usr_id']);
319  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED', ($a_set['notification'] ? 'checked="checked"' : ''));
320  }
321  elseif($this->type == 'tutor')
322  {
323  $this->tpl->setVariable('VAL_POSTNAME', 'tutors');
324  $this->tpl->setVariable('VAL_NOTIFICATION_ID', $a_set['usr_id']);
325  $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED', ($a_set['notification'] ? 'checked="checked"' : ''));
326  }
327  elseif($this->type == 'member')
328  {
329  $this->tpl->setCurrentBlock('blocked');
330  $this->tpl->setVariable('VAL_POSTNAME','members');
331  $this->tpl->setVariable('VAL_BLOCKED_ID',$a_set['usr_id']);
332  $this->tpl->setVariable('VAL_BLOCKED_CHECKED',($a_set['blocked'] ? 'checked="checked"' : ''));
333  $this->tpl->parseCurrentBlock();
334  }
335  else
336  {
337  $this->tpl->setCurrentBlock('blocked');
338  $this->tpl->setVariable('VAL_BLOCKED_ID', $a_set['usr_id']);
339  $this->tpl->setVariable('VAL_BLOCKED_CHECKED', ($a_set['blocked'] ? 'checked="checked"' : ''));
340  $this->tpl->parseCurrentBlock();
341 
342  $this->tpl->setVariable('VAL_POSTNAME','roles');
343  }
344 
345  $this->tpl->setVariable('VAL_PASSED_ID',$a_set['usr_id']);
346  $this->tpl->setVariable('VAL_PASSED_CHECKED',($a_set['passed'] ? 'checked="checked"' : ''));
347 
348  if($this->show_lp_status_sync)
349  {
350  $this->tpl->setVariable('PASSED_INFO', $a_set["passed_info"]);
351  }
352 
353  $this->ctrl->setParameter($this->parent_obj, 'member_id', $a_set['usr_id']);
354  if($this->show_edit_link)
355  {
356  $this->tpl->setCurrentBlock('link');
357  $this->tpl->setVariable('LINK_NAME', $this->ctrl->getLinkTarget($this->parent_obj, 'editMember'));
358  $this->tpl->setVariable('LINK_TXT', $this->lng->txt('edit'));
359  $this->tpl->parseCurrentBlock();
360  }
361  if($a_set['passed'] && $this->enable_certificates)
362  {
363  $this->tpl->setCurrentBlock('link');
364  $this->tpl->setVariable('LINK_NAME', $this->ctrl->getLinkTarget($this->parent_obj, 'deliverCertificate'));
365  $this->tpl->setVariable('LINK_TXT', $this->lng->txt('download_certificate'));
366  $this->tpl->parseCurrentBlock();
367  }
368  $this->ctrl->clearParameters($this->parent_obj);
369 
370  if($this->show_timings)
371  {
372  $this->ctrl->setParameterByClass('ilcoursecontentgui', 'member_id', $a_set['usr_id']);
373  $this->tpl->setCurrentBlock('link');
374  $this->tpl->setVariable('LINK_NAME', $this->ctrl->getLinkTargetByClass('ilcoursecontentgui', 'showUserTimings'));
375  $this->tpl->setVariable('LINK_TXT', $this->lng->txt('timings_timings'));
376  $this->tpl->parseCurrentBlock();
377  }
378  }
379 
386  public function parse()
387  {
388  global $rbacreview;
389 
390  $this->determineOffsetAndOrder();
391 
392  include_once './Services/User/classes/class.ilUserQuery.php';
393 
394  $additional_fields = $this->getSelectedColumns();
395  unset($additional_fields["firstname"]);
396  unset($additional_fields["lastname"]);
397  unset($additional_fields["last_login"]);
398  unset($additional_fields["access_until"]);
399 
400  $udf_ids = $usr_data_fields = $odf_ids = array();
401  foreach($additional_fields as $field)
402  {
403  if(substr($field, 0, 3) == 'udf')
404  {
405  $udf_ids[] = substr($field, 4);
406  continue;
407  }
408  if(substr($field, 0, 3) == 'odf')
409  {
410  $odf_ids[] = substr($field, 4);
411  continue;
412  }
413 
414  $usr_data_fields[] = $field;
415  }
416 
417  $usr_data = ilUserQuery::getUserListData(
418  $this->getOrderField(),
419  $this->getOrderDirection(),
420  $this->getOffset(),
421  $this->getLimit(),
422  '',
423  '',
424  null,
425  false,
426  false,
427  0,
428  $this->getRoleId(),
429  null,
430  $usr_data_fields,
431  $part
432  );
433  foreach((array) $usr_data['set'] as $user)
434  {
435  $usr_ids[] = $user['usr_id'];
436  }
437 
438  // merge course data
439  $course_user_data = $this->getParentObject()->readMemberData($usr_ids,$this->type == 'admin');
440  $a_user_data = array();
441  foreach((array) $usr_data['set'] as $ud)
442  {
443  $a_user_data[$ud['usr_id']] = array_merge($ud,$course_user_data[$ud['usr_id']]);
444 
445  if($this->show_lp_status_sync)
446  {
447  // #9912 / #13208
448  $passed_info = "";
449  if($a_user_data[$ud['usr_id']]["passed_info"])
450  {
451  $pinfo = $a_user_data[$ud['usr_id']]["passed_info"];
452  if($pinfo["user_id"])
453  {
454  if($pinfo["user_id"] < 0)
455  {
456  $passed_info = $this->lng->txt("crs_passed_status_system");
457  }
458  else if($pinfo["user_id"] > 0)
459  {
460  $name = ilObjUser::_lookupName($pinfo["user_id"]);
461  $passed_info = $this->lng->txt("crs_passed_status_manual_by").": ".$name["login"];
462  }
463  }
464  if($pinfo["timestamp"])
465  {
466  $passed_info .= "<br />".ilDatePresentation::formatDate($pinfo["timestamp"]);
467  }
468  }
469  $a_user_data[$ud['usr_id']]["passed_info"] = $passed_info;
470  }
471  }
472 
473  // Custom user data fields
474  if($udf_ids)
475  {
476  include_once './Services/User/classes/class.ilUserDefinedData.php';
477  $data = ilUserDefinedData::lookupData($usr_ids, $udf_ids);
478  foreach($data as $usr_id => $fields)
479  {
480  if(!$this->checkAcceptance($usr_id))
481  {
482  continue;
483  }
484 
485  foreach($fields as $field_id => $value)
486  {
487  $a_user_data[$usr_id]['udf_' . $field_id] = $value;
488  }
489  }
490  }
491  // Object specific user data fields
492  if($odf_ids)
493  {
494  include_once './Modules/Course/classes/Export/class.ilCourseUserData.php';
495  $data = ilCourseUserData::_getValuesByObjId($this->getParentObject()->object->getId());
496  foreach($data as $usr_id => $fields)
497  {
498  // #7264: as we get data for all course members filter against user data
499  if(!$this->checkAcceptance($usr_id) || !in_array($usr_id, $usr_ids))
500  {
501  continue;
502  }
503 
504  foreach($fields as $field_id => $value)
505  {
506  $a_user_data[$usr_id]['odf_' . $field_id] = $value;
507  }
508  }
509  }
510 
511  foreach($usr_data['set'] as $user)
512  {
513  // Check acceptance
514  if(!$this->checkAcceptance($user['usr_id']))
515  {
516  continue;
517  }
518  // DONE: accepted
519  foreach($usr_data_fields as $field)
520  {
521  $a_user_data[$user['usr_id']][$field] = $user[$field] ? $user[$field] : '';
522  }
523  }
524  $this->setMaxCount($usr_data['cnt'] ? $usr_data['cnt'] : 0);
525  return $this->setData($a_user_data);
526  }
527 
528  public function checkAcceptance($a_usr_id)
529  {
530  if(!self::$confirmation_required)
531  {
532  return true;
533  }
534  if(!self::$export_allowed)
535  {
536  return false;
537  }
538  return in_array($a_usr_id, self::$accepted_ids);
539  }
540 
545  public function initAcceptedAgreements()
546  {
547  if(self::$accepted_ids !== NULL)
548  {
549  return true;
550  }
551 
552  self::$export_allowed = ilPrivacySettings::_getInstance()->checkExportAccess($this->getParentObject()->object->getRefId());
553  self::$confirmation_required = ilPrivacySettings::_getInstance()->courseConfirmationRequired();
554 
555  include_once 'Services/Membership/classes/class.ilMemberAgreement.php';
556  self::$accepted_ids = ilMemberAgreement::lookupAcceptedAgreements($this->getParentObject()->object->getId());
557  }
558 
559 }
560 ?>