ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilAttendanceList.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
15  protected $parent_obj; // [object]
16  protected $participants; // [object]
17  protected $waiting_list; // [object]
18  protected $callback; // [string|array]
19  protected $presets; // [array]
20  protected $role_data; // [array]
21  protected $roles; // [array]
22  protected $has_local_role; // [bool]
23  protected $blank_columns; // [array]
24  protected $title; // [string]
25  protected $description; // [string]
26  protected $pre_blanks; // [array]
27  protected $id; // [string]
28  protected $include_waiting_list; // [bool]
29  protected $include_subscribers; // [bool]
30  protected $user_filters; // [array]
31 
39  function __construct($a_parent_obj, ilParticipants $a_participants_object = null, ilWaitingList $a_waiting_list = null)
40  {
41  global $lng;
42 
43  $this->parent_obj = $a_parent_obj;
44  $this->participants = $a_participants_object;
45  $this->waiting_list = $a_waiting_list;
46 
47  // always available
48  $this->presets['name'] = array($lng->txt('name'), true);
49  $this->presets['login'] = array($lng->txt('login'), true);
50 
51  $lng->loadLanguageModule('crs');
52 
53  // roles
54  $roles = $this->participants->getRoles();
55  foreach($roles as $role_id)
56  {
57  $title = ilObject::_lookupTitle($role_id);
58  switch(substr($title, 0, 8))
59  {
60  case 'il_crs_a':
61  case 'il_grp_a':
62  $this->addRole($role_id, $lng->txt('event_tbl_admin'), 'admin');
63  break;
64 
65  case 'il_crs_t':
66  $this->addRole($role_id, $lng->txt('event_tbl_tutor'), 'tutor');
67  break;
68 
69  case 'il_crs_m':
70  case 'il_grp_m':
71  $this->addRole($role_id, $lng->txt('event_tbl_member'), 'member');
72  break;
73 
74  // local
75  default:
76  $this->has_local_role = true;
77  $this->addRole($role_id, $title, 'local');
78  break;
79  }
80  }
81  }
82 
90  function addPreset($a_id, $a_caption, $a_selected = false)
91  {
92  $this->presets[$a_id] = array($a_caption, $a_selected);
93  }
94 
100  function addBlank($a_caption)
101  {
102  $this->pre_blanks[] = $a_caption;
103  }
104 
111  function setTitle($a_title, $a_description = null)
112  {
113  $this->title = $a_title;
114  $this->description = $a_description;
115  }
116 
124  protected function addRole($a_id, $a_caption, $a_type)
125  {
126  $this->role_data[$a_id] = array($a_caption, $a_type);
127  }
128 
134  protected function setRoleSelection($a_role_ids)
135  {
136  $this->roles = $a_role_ids;
137  }
138 
146  function addUserFilter($a_id, $a_caption, $a_checked = false)
147  {
148  $this->user_filters[$a_id] = array($a_caption, $a_checked);
149  }
150 
156  function getNonMemberUserData(array &$a_res)
157  {
158  global $lng;
159 
160  $subscriber_ids = $this->participants->getSubscribers();
161 
162  $user_ids = $subscriber_ids;
163 
164  if($this->waiting_list)
165  {
166  $user_ids = array_merge($user_ids, $this->waiting_list->getUserIds());
167  }
168 
169  if(sizeof($user_ids))
170  {
171  foreach(array_unique($user_ids) as $user_id)
172  {
173  if(!isset($a_res[$user_id]))
174  {
175  if($tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false))
176  {
177  $a_res[$user_id]['login'] = $tmp_obj->getLogin();
178  $a_res[$user_id]['name'] = $tmp_obj->getLastname().', '.$tmp_obj->getFirstname();
179 
180  if(in_array($user_id, $subscriber_ids))
181  {
182  $a_res[$user_id]['status'] = $lng->txt('crs_subscriber');
183  }
184  else
185  {
186  $a_res[$user_id]['status'] = $lng->txt('crs_waiting_list');
187  }
188  }
189  }
190  }
191  }
192  }
193 
199  function setBlankColumns(array $a_values)
200  {
201  if(!implode("", $a_values))
202  {
203  $a_values = array();
204  }
205  else
206  {
207  foreach($a_values as $idx => $value)
208  {
209  $a_values[$idx] = trim($value);
210  if($a_values[$idx] == "")
211  {
212  unset($a_values[$idx]);
213  }
214  }
215  }
216  $this->blank_columns = $a_values;
217  }
218 
224  function setCallback($a_callback)
225  {
226  $this->callback = $a_callback;
227  }
228 
234  function setId($a_value)
235  {
236  $this->id = (string)$a_value;
237  }
238 
245  public function initForm($a_cmd = "")
246  {
247  global $ilCtrl, $lng;
248 
249  $lng->loadLanguageModule('crs');
250 
251  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
252  $form = new ilPropertyFormGUI();
253  $form->setFormAction($ilCtrl->getFormAction($this->parent_obj,$a_cmd));
254  $form->setTarget('_blank');
255  $form->setPreventDoubleSubmission(false);
256  $form->setTitle($lng->txt('sess_gen_attendance_list'));
257 
258  $title = new ilTextInputGUI($lng->txt('title'), 'title');
259  $title->setValue($this->title);
260  $form->addItem($title);
261 
262  $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
263  $desc->setValue($this->description);
264  $form->addItem($desc);
265 
266  if(sizeof($this->presets))
267  {
268  $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
269  $preset_value = array();
270  foreach($this->presets as $id => $item)
271  {
272  $preset->addOption(new ilCheckboxOption($item[0], $id));
273  if($item[1])
274  {
275  $preset_value[] = $id;
276  }
277  }
278  $preset->setValue($preset_value);
279  $form->addItem($preset);
280  }
281 
282  $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
283  $blank->setMulti(true);
284  $form->addItem($blank);
285 
286  if($this->pre_blanks)
287  {
288  $blank->setValue($this->pre_blanks);
289  }
290 
291  $checked = array();
292 
293  $chk_grp = new ilCheckboxGroupInputGUI($lng->txt('event_user_selection'), 'selection_of_users');
294 
295  // participants by roles
296  foreach($this->role_data as $role_id => $role_data)
297  {
298  $chk = new ilCheckboxOption(sprintf($lng->txt('event_user_selection_include_role'),$role_data[0]), 'role_'.$role_id);
299  $checked[] = 'role_'.$role_id;
300  $chk_grp->addOption($chk);
301  }
302 
303  if($this->waiting_list)
304  {
305  $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_requests'), 'subscr');
306  $chk_grp->addOption($chk);
307 
308  $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_waiting_list'), 'wlist');
309  $chk_grp->addOption($chk);
310  }
311 
312  if($this->user_filters)
313  {
314  foreach($this->user_filters as $sub_id => $sub_item)
315  {
316  $chk = new ilCheckboxOption(sprintf($lng->txt('event_user_selection_include_filter'),$sub_item[0]),
317  'members_'.$sub_id);
318  if($sub_item[1])
319  {
320  $checked[] = 'members_'.$sub_id;
321  }
322  $chk_grp->addOption($chk);
323  }
324  }
325  $chk_grp->setValue($checked);
326  $form->addItem($chk_grp);
327 
328  $form->addCommandButton($a_cmd,$lng->txt('sess_print_attendance_list'));
329 
330  if($this->id && $a_cmd)
331  {
332  include_once "Services/User/classes/class.ilUserFormSettings.php";
333  $settings = new ilUserFormSettings($this->id);
334  $settings->deleteValue('desc'); // #11340
335  $settings->exportToForm($form);
336  }
337 
338  return $form;
339  }
340 
344  public function initFromForm()
345  {
346  $form = $this->initForm();
347  if($form->checkInput())
348  {
349  foreach(array_keys($this->presets) as $id)
350  {
351  $this->presets[$id][1] = false;
352  }
353  foreach($form->getInput('preset') as $value)
354  {
355  if(isset($this->presets[$value]))
356  {
357  $this->presets[$value][1] = true;
358  }
359  else
360  {
361  $this->addPreset($value, $value, true);
362  }
363  }
364 
365  $this->setTitle($form->getInput('title'), $form->getInput('desc'));
366  $this->setBlankColumns($form->getInput('blank'));
367 
368  $selection_of_users = (array)$form->getInput('selection_of_users'); // #18238
369 
370  $roles = array();
371  foreach(array_keys($this->role_data) as $role_id)
372  {
373  if(in_array('role_'.$role_id, $selection_of_users))
374  {
375  $roles[] = $role_id;
376  }
377  }
378  $this->setRoleSelection($roles);
379 
380  // not in sessions
381  if($this->waiting_list)
382  {
383  $this->include_subscribers = (bool)in_array('subscr', $selection_of_users);
384  $this->include_waiting_list = (bool)in_array('wlist', $selection_of_users);
385  }
386 
387  if($this->user_filters)
388  {
389  foreach(array_keys($this->user_filters) as $msub_id)
390  {
391  $this->user_filters[$msub_id][2] = (bool)in_array("members_".$msub_id, $selection_of_users);
392  }
393  }
394 
395  if($this->id)
396  {
397  $form->setValuesByPost();
398 
399  include_once "Services/User/classes/class.ilUserFormSettings.php";
400  $settings = new ilUserFormSettings($this->id);
401  $settings->deleteValue('desc'); // #11340
402  $settings->importFromForm($form);
403  $settings->store();
404  }
405 
406  }
407  }
408 
414  public function getFullscreenHTML()
415  {
416  $tpl = new ilTemplate('tpl.main.html',true,true);
417  $tpl->setBodyClass("ilBodyPrint");
418 
419  // load style sheet depending on user's settings
420  $location_stylesheet = ilUtil::getStyleSheetLocation();
421  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
422 
423  $tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
424  $tpl->setVariable("CONTENT", $this->getHTML());
425 
426  return $tpl->show();
427  }
428 
434  public function getHTML()
435  {
436  $tpl = new ilTemplate('tpl.attendance_list_print.html',true,true,'Services/Membership');
437 
438 
439  // title
440 
441  $time = ilFormat::formatUnixTime(time(),true);
442 
443  $tpl->setVariable('TXT_TITLE', $this->title);
444  if($this->description)
445  {
446  $tpl->setVariable('TXT_DESCRIPTION', $this->description." (".$time.")");
447  }
448  else
449  {
450  $tpl->setVariable('TXT_DESCRIPTION', $time);
451  }
452 
453 
454  // header
455 
456  $tpl->setCurrentBlock('head_item');
457  foreach($this->presets as $id => $item)
458  {
459  if($item[1])
460  {
461  $tpl->setVariable('TXT_HEAD', $item[0]);
462  $tpl->parseCurrentBlock();
463  }
464  }
465 
466  if($this->blank_columns)
467  {
468  foreach($this->blank_columns as $blank)
469  {
470  $tpl->setVariable('TXT_HEAD', $blank);
471  $tpl->parseCurrentBlock();
472  }
473  }
474 
475 
476  // handle members
477 
478  $valid_user_ids = $filters = array();
479 
480  if($this->roles)
481  {
482  if($this->has_local_role)
483  {
484  $members = array();
485  foreach($this->participants->getMembers() as $member_id)
486  {
487  foreach($this->participants->getAssignedRoles($member_id) as $role_id)
488  {
489  $members[$role_id][] = $member_id;
490  }
491  }
492  }
493  else
494  {
495  $members = $this->participants->getMembers();
496  }
497 
498  foreach($this->roles as $role_id)
499  {
500  switch($this->role_data[$role_id][1])
501  {
502  case "admin":
503  $valid_user_ids = array_merge($valid_user_ids, $this->participants->getAdmins());
504  break;
505 
506  case "tutor":
507  $valid_user_ids = array_merge($valid_user_ids, $this->participants->getTutors());
508  break;
509 
510  // member/local
511  default:
512  if(!$this->has_local_role)
513  {
514  $valid_user_ids = array_merge($valid_user_ids, (array)$members);
515  }
516  else
517  {
518  $valid_user_ids = array_merge($valid_user_ids, (array)$members[$role_id]);
519  }
520  break;
521  }
522  }
523  }
524 
525  if($this->include_subscribers)
526  {
527  $valid_user_ids = array_merge($valid_user_ids, $this->participants->getSubscribers());
528  }
529 
530  if($this->include_waiting_list)
531  {
532  $valid_user_ids = array_merge($valid_user_ids, $this->waiting_list->getUserIds());
533  }
534 
535  if($this->user_filters)
536  {
537  foreach($this->user_filters as $sub_id => $sub_item)
538  {
539  $filters[$sub_id] = (bool)$sub_item[2];
540  }
541  }
542 
543  $valid_user_ids = ilUtil::_sortIds(array_unique($valid_user_ids),'usr_data','lastname','usr_id');
544 
545 
546  // rows
547 
548  foreach($valid_user_ids as $user_id)
549  {
550  if($this->callback)
551  {
552  $user_data = call_user_func_array($this->callback, array($user_id, $filters));
553  if(!$user_data)
554  {
555  continue;
556  }
557 
558  $tpl->setCurrentBlock("row_preset");
559  foreach($this->presets as $id => $item)
560  {
561  if($item[1])
562  {
563  switch($id)
564  {
565  case "name":
566  if(!$user_data[$id])
567  {
568  $name = ilObjUser::_lookupName($user_id);
569  $value = $name["lastname"].", ".$name["firstname"];
570  break;
571  }
572 
573 
574  case "login":
575  if(!$user_data[$id])
576  {
577  $value = ilObjUser::_lookupLogin($user_id);
578  break;
579  }
580 
581  default:
582  $value = (string)$user_data[$id];
583  break;
584  }
585  $tpl->setVariable("TXT_PRESET", $value);
586  $tpl->parseCurrentBlock();
587  }
588  }
589  }
590 
591  if($this->blank_columns)
592  {
593  for($loop = 0; $loop < sizeof($this->blank_columns); $loop++)
594  {
595  $tpl->touchBlock('row_blank');
596  }
597  }
598 
599  $tpl->touchBlock("member_row");
600  }
601 
602  return $tpl->get();
603  }
604 }
605 
606 ?>
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
This class represents an option in a checkbox group.
Base class for course and group waiting lists.
setId($a_value)
Set id (used for user form settings)
__construct($a_parent_obj, ilParticipants $a_participants_object=null, ilWaitingList $a_waiting_list=null)
Constructor.
This class represents a property form user interface.
setTitle($a_title, $a_description=null)
Set titles.
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
getFullscreenHTML()
render list in fullscreen mode
static _lookupTitle($a_id)
lookup object title
getNonMemberUserData(array &$a_res)
Get user data for subscribers and waiting list.
addBlank($a_caption)
Add blank column preset.
initForm($a_cmd="")
Init form.
Base class for attendance lists.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
addPreset($a_id, $a_caption, $a_selected=false)
Add user field.
static _sortIds($a_ids, $a_table, $a_field, $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,7),&#39;usr_data&#39;,&#39;lastname&#39;,&#39;usr_id&#39;) => sorts by lastname.
setBlankColumns(array $a_values)
Add blank columns.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
formatUnixTime($ut, $with_time=false)
addRole($a_id, $a_caption, $a_type)
Add role.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
This class represents a property in a property form.
setCallback($a_callback)
Set participant detail callback.
setMulti($a_multi, $a_sortable=false, $a_addremove=true)
Set Multi.
setRoleSelection($a_role_ids)
Set role selection.
global $lng
Definition: privfeed.php:40
setValue($a_value)
Set Value.
getHTML()
render attendance list
addUserFilter($a_id, $a_caption, $a_checked=false)
Add user filter.
initFromForm()
Set list attributes from post values.