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