ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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  $this->presets['email'] = array($lng->txt('email'));
51 
52  $lng->loadLanguageModule('crs');
53 
54  // roles
55  $roles = $this->participants->getRoles();
56  foreach($roles as $role_id)
57  {
58  $title = ilObject::_lookupTitle($role_id);
59  switch(substr($title, 0, 8))
60  {
61  case 'il_crs_a':
62  case 'il_grp_a':
63  $this->addRole($role_id, $lng->txt('event_tbl_admins'), 'admin');
64  break;
65 
66  case 'il_crs_t':
67  $this->addRole($role_id, $lng->txt('event_tbl_tutors'), 'tutor');
68  break;
69 
70  case 'il_crs_m':
71  case 'il_grp_m':
72  $this->addRole($role_id, $lng->txt('event_tbl_members'), 'member');
73  break;
74 
75  // local
76  default:
77  $this->has_local_role = true;
78  $this->addRole($role_id, $title, 'local');
79  break;
80  }
81  }
82  }
83 
91  function addPreset($a_id, $a_caption, $a_selected = false)
92  {
93  $this->presets[$a_id] = array($a_caption, $a_selected);
94  }
95 
101  function addBlank($a_caption)
102  {
103  $this->pre_blanks[] = $a_caption;
104  }
105 
112  function setTitle($a_title, $a_description = null)
113  {
114  $this->title = $a_title;
115  $this->description = $a_description;
116  }
117 
125  protected function addRole($a_id, $a_caption, $a_type)
126  {
127  $this->role_data[$a_id] = array($a_caption, $a_type);
128  }
129 
135  protected function setRoleSelection($a_role_ids)
136  {
137  $this->roles = $a_role_ids;
138  }
139 
147  function addUserFilter($a_id, $a_caption, $a_checked = false)
148  {
149  $this->user_filters[$a_id] = array($a_caption, $a_checked);
150  }
151 
157  function getNonMemberUserData(array &$a_res)
158  {
159  global $lng;
160 
161  $subscriber_ids = $this->participants->getSubscribers();
162 
163  $user_ids = $subscriber_ids;
164 
165  if($this->waiting_list)
166  {
167  $user_ids = array_merge($user_ids, $this->waiting_list->getUserIds());
168  }
169 
170  if(sizeof($user_ids))
171  {
172  foreach(array_unique($user_ids) as $user_id)
173  {
174  if(!isset($a_res[$user_id]))
175  {
176  if($tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false))
177  {
178  $a_res[$user_id]['login'] = $tmp_obj->getLogin();
179  $a_res[$user_id]['name'] = $tmp_obj->getLastname().', '.$tmp_obj->getFirstname();
180  $a_res[$user_id]['email'] = $tmp_obj->getEmail();
181 
182  if(in_array($user_id, $subscriber_ids))
183  {
184  $a_res[$user_id]['status'] = $lng->txt('crs_subscriber');
185  }
186  else
187  {
188  $a_res[$user_id]['status'] = $lng->txt('crs_waiting_list');
189  }
190  }
191  }
192  }
193  }
194  }
195 
201  function setBlankColumns(array $a_values)
202  {
203  if(!implode("", $a_values))
204  {
205  $a_values = array();
206  }
207  else
208  {
209  foreach($a_values as $idx => $value)
210  {
211  $a_values[$idx] = trim($value);
212  if($a_values[$idx] == "")
213  {
214  unset($a_values[$idx]);
215  }
216  }
217  }
218  $this->blank_columns = $a_values;
219  }
220 
226  function setCallback($a_callback)
227  {
228  $this->callback = $a_callback;
229  }
230 
236  function setId($a_value)
237  {
238  $this->id = (string)$a_value;
239  }
240 
247  public function initForm($a_cmd = "")
248  {
249  global $ilCtrl, $lng;
250 
251  $lng->loadLanguageModule('crs');
252 
253  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
254  $form = new ilPropertyFormGUI();
255  $form->setFormAction($ilCtrl->getFormAction($this->parent_obj,$a_cmd));
256  $form->setTarget('_blank');
257  $form->setTitle($lng->txt('sess_gen_attendance_list'));
258 
259  $title = new ilTextInputGUI($lng->txt('title'), 'title');
260  $title->setValue($this->title);
261  $form->addItem($title);
262 
263  $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
264  $desc->setValue($this->description);
265  $form->addItem($desc);
266 
267  if(sizeof($this->presets))
268  {
269  $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
270  $preset_value = array();
271  foreach($this->presets as $id => $item)
272  {
273  $preset->addOption(new ilCheckboxOption($item[0], $id));
274  if($item[1])
275  {
276  $preset_value[] = $id;
277  }
278  }
279  $preset->setValue($preset_value);
280  $form->addItem($preset);
281  }
282 
283  $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
284  $blank->setMulti(true);
285  $form->addItem($blank);
286 
287  if($this->pre_blanks)
288  {
289  $blank->setValue($this->pre_blanks);
290  }
291 
292  $part = new ilFormSectionHeaderGUI();
293  $part->setTitle($lng->txt('event_participant_selection'));
294  $form->addItem($part);
295 
296  // participants by roles
297  foreach($this->role_data as $role_id => $role_data)
298  {
299  $chk = new ilCheckboxInputGUI($role_data[0], 'role_'.$role_id);
300  $chk->setValue(1);
301  $chk->setChecked(1);
302  $form->addItem($chk);
303  }
304 
305  // not in sessions
306  if($this->waiting_list)
307  {
308  $chk = new ilCheckboxInputGUI($lng->txt('group_new_registrations'), 'subscr');
309  $chk->setValue(1);
310  $form->addItem($chk);
311 
312  $chk = new ilCheckboxInputGUI($lng->txt('crs_waiting_list'), 'wlist');
313  $chk->setValue(1);
314  $form->addItem($chk);
315  }
316 
317  if($this->user_filters)
318  {
319  foreach($this->user_filters as $sub_id => $sub_item)
320  {
321  $sub = new ilCheckboxInputGUI($sub_item[0], 'members_'.$sub_id);
322  if($sub_item[1])
323  {
324  $sub->setChecked(true);
325  }
326  $form->addItem($sub);
327  }
328  }
329 
330  $form->addCommandButton($a_cmd,$lng->txt('sess_print_attendance_list'));
331 
332  if($this->id && $a_cmd)
333  {
334  include_once "Services/User/classes/class.ilUserFormSettings.php";
335  $settings = new ilUserFormSettings($this->id);
336  $settings->deleteValue('desc'); // #11340
337  $settings->exportToForm($form);
338  }
339 
340  return $form;
341  }
342 
346  public function initFromForm()
347  {
348  $form = $this->initForm();
349  if($form->checkInput())
350  {
351  foreach(array_keys($this->presets) as $id)
352  {
353  $this->presets[$id][1] = false;
354  }
355  foreach($form->getInput('preset') as $value)
356  {
357  if(isset($this->presets[$value]))
358  {
359  $this->presets[$value][1] = true;
360  }
361  else
362  {
363  $this->addPreset($value, $value, true);
364  }
365  }
366 
367  $this->setTitle($form->getInput('title'), $form->getInput('desc'));
368  $this->setBlankColumns($form->getInput('blank'));
369 
370  $roles = array();
371  foreach(array_keys($this->role_data) as $role_id)
372  {
373  if($form->getInput('role_'.$role_id))
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)$form->getInput('subscr');
384  $this->include_waiting_list = (bool)$form->getInput('wlist');
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] = $form->getInput("members_".$msub_id);
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 "email":
575  if(!$user_data[$id])
576  {
577  $value = ilObjUser::_lookupEmail($user_id);
578  break;
579  }
580 
581 
582  case "login":
583  if(!$user_data[$id])
584  {
585  $value = ilObjUser::_lookupLogin($user_id);
586  break;
587  }
588 
589  default:
590  $value = (string)$user_data[$id];
591  break;
592  }
593  $tpl->setVariable("TXT_PRESET", $value);
594  $tpl->parseCurrentBlock();
595  }
596  }
597  }
598 
599  if($this->blank_columns)
600  {
601  for($loop = 0; $loop < sizeof($this->blank_columns); $loop++)
602  {
603  $tpl->touchBlock('row_blank');
604  }
605  }
606 
607  $tpl->touchBlock("member_row");
608  }
609 
610  return $tpl->get();
611  }
612 }
613 
614 ?>
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
This class represents a section header in a property form.
getFullscreenHTML()
render list in fullscreen mode
This class represents a checkbox property in a property form.
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 $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.
setValue($a_value)
Set Value.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
formatUnixTime($ut, $with_time=false)
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
addRole($a_id, $a_caption, $a_type)
Add role.
_lookupLogin($a_user_id)
lookup login
_lookupEmail($a_user_id)
Lookup email.
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.