ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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_gui;
16 protected $parent_obj; // [object]
17 protected $participants; // [object]
18 protected $waiting_list; // [object]
19 protected $callback; // [string|array]
20 protected $presets; // [array]
21 protected $role_data; // [array]
22 protected $roles; // [array]
23 protected $has_local_role; // [bool]
24 protected $blank_columns; // [array]
25 protected $title; // [string]
26 protected $description; // [string]
27 protected $pre_blanks; // [array]
28 protected $id; // [string]
29 protected $include_waiting_list; // [bool]
30 protected $include_subscribers; // [bool]
31 protected $user_filters; // [array]
32
40 function __construct($a_parent_gui, $a_parent_obj, ilParticipants $a_participants_object = null, ilWaitingList $a_waiting_list = null)
41 {
42 global $lng;
43
44 $this->parent_gui = $a_parent_gui;
45 $this->parent_obj = $a_parent_obj;
46 $this->participants = $a_participants_object;
47 $this->waiting_list = $a_waiting_list;
48
49 // always available
50 $this->presets['name'] = array($lng->txt('name'), true);
51 $this->presets['login'] = array($lng->txt('login'), true);
52
53 // add exportable fields
55
56 $lng->loadLanguageModule('crs');
57
58 // roles
59 $roles = $this->participants->getRoles();
60 foreach($roles as $role_id)
61 {
63 switch(substr($title, 0, 8))
64 {
65 case 'il_crs_a':
66 case 'il_grp_a':
67 $this->addRole($role_id, $lng->txt('event_tbl_admin'), 'admin');
68 break;
69
70 case 'il_crs_t':
71 $this->addRole($role_id, $lng->txt('event_tbl_tutor'), 'tutor');
72 break;
73
74 case 'il_crs_m':
75 case 'il_grp_m':
76 $this->addRole($role_id, $lng->txt('event_tbl_member'), 'member');
77 break;
78
79 // local
80 default:
81 $this->has_local_role = true;
82 $this->addRole($role_id, $title, 'local');
83 break;
84 }
85 }
86 }
87
92 protected function readOrderedExportableFields()
93 {
94 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
95 include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
96 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
97 include_once('Services/User/classes/class.ilUserDefinedFields.php');
98
99 $field_info = ilExportFieldsInfo::_getInstanceByType($this->parent_obj->getType());
100 $field_info->sortExportFields();
101
102 foreach($field_info->getExportableFields() as $field)
103 {
104 switch($field)
105 {
106 case 'username':
107 case 'firstname':
108 case 'lastname':
109 continue 2;
110 }
111
112 ilLoggerFactory::getLogger('mem')->dump($field, ilLogLevel::DEBUG);
113 // Check if default enabled
114 $this->presets[$field] = array(
115 $GLOBALS['lng']->txt($field),
116 false
117 );
118 }
119
120 // add udf fields
122 foreach($udf->getExportableFields($this->parent_obj->getId()) as $field_id => $udf_data)
123 {
124 $this->presets['udf_'.$field_id] = array(
125 $udf_data['field_name'],
126 false
127 );
128 }
129
130 // add cdf fields
131 include_once './Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php';
132 foreach(ilCourseDefinedFieldDefinition::_getFields($this->parent_obj->getId()) as $field_obj)
133 {
134 $this->presets['cdf_'.$field_obj->getId()] = array(
135 $field_obj->getName(),
136 false
137 );
138 }
139 return true;
140 }
141
149 function addPreset($a_id, $a_caption, $a_selected = false)
150 {
151 $this->presets[$a_id] = array($a_caption, $a_selected);
152 }
153
159 function addBlank($a_caption)
160 {
161 $this->pre_blanks[] = $a_caption;
162 }
163
170 function setTitle($a_title, $a_description = null)
171 {
172 $this->title = $a_title;
173 $this->description = $a_description;
174 }
175
183 protected function addRole($a_id, $a_caption, $a_type)
184 {
185 $this->role_data[$a_id] = array($a_caption, $a_type);
186 }
187
193 protected function setRoleSelection($a_role_ids)
194 {
195 $this->roles = $a_role_ids;
196 }
197
205 function addUserFilter($a_id, $a_caption, $a_checked = false)
206 {
207 $this->user_filters[$a_id] = array($a_caption, $a_checked);
208 }
209
215 function getNonMemberUserData(array &$a_res)
216 {
217 global $lng;
218
219 $subscriber_ids = $this->participants->getSubscribers();
220
221 $user_ids = $subscriber_ids;
222
223 if($this->waiting_list)
224 {
225 $user_ids = array_merge($user_ids, $this->waiting_list->getUserIds());
226 }
227
228 // Finally read user profile data
229 $profile_data = ilObjUser::_readUsersProfileData($user_ids);
230 foreach($profile_data as $user_id => $fields)
231 {
232 foreach((array) $fields as $field => $value)
233 {
234 $a_res[$user_id][$field] = $value;
235 }
236 }
237
238 include_once './Services/User/classes/class.ilUserDefinedFields.php';
240
241 foreach($udf->getExportableFields($this->parent_obj->getId()) as $field_id => $udf_data)
242 {
243 foreach($profile_data as $user_id => $field)
244 {
245 include_once './Services/User/classes/class.ilUserDefinedData.php';
246 $udf_data = new ilUserDefinedData($user_id);
247 $a_res[$user_id]['udf_'.$field_id] = (string) $udf_data->get('f_'.$field_id);
248 }
249 }
250
251 if(sizeof($user_ids))
252 {
253 // object specific user data
254 include_once 'Modules/Course/classes/Export/class.ilCourseUserData.php';
255 $cdfs = ilCourseUserData::_getValuesByObjId($this->parent_obj->getId());
256
257 foreach(array_unique($user_ids) as $user_id)
258 {
259 if($tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false))
260 {
261 $a_res[$user_id]['name'] = $tmp_obj->getLastname().', '.$tmp_obj->getFirstname();
262 $a_res[$user_id]['email'] = $tmp_obj->getEmail();
263
264 if(in_array($user_id, $subscriber_ids))
265 {
266 $a_res[$user_id]['status'] = $lng->txt('crs_subscriber');
267 }
268 else
269 {
270 $a_res[$user_id]['status'] = $lng->txt('crs_waiting_list');
271 }
272
273 foreach((array) $cdfs[$user_id] as $field_id => $value)
274 {
275 $a_res[$user_id]['cdf_'.$field_id] = (string) $value;
276 }
277 }
278 }
279 }
280 }
281
287 function setBlankColumns(array $a_values)
288 {
289 if(!implode("", $a_values))
290 {
291 $a_values = array();
292 }
293 else
294 {
295 foreach($a_values as $idx => $value)
296 {
297 $a_values[$idx] = trim($value);
298 if($a_values[$idx] == "")
299 {
300 unset($a_values[$idx]);
301 }
302 }
303 }
304 $this->blank_columns = $a_values;
305 }
306
312 function setCallback($a_callback)
313 {
314 $this->callback = $a_callback;
315 }
316
322 function setId($a_value)
323 {
324 $this->id = (string)$a_value;
325 }
326
333 public function initForm($a_cmd = "")
334 {
335 global $ilCtrl, $lng;
336
337 $lng->loadLanguageModule('crs');
338
339 include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
340 $form = new ilPropertyFormGUI();
341 $form->setFormAction($ilCtrl->getFormAction($this->parent_gui,$a_cmd));
342 $form->setTarget('_blank');
343 $form->setPreventDoubleSubmission(false);
344 $form->setTitle($lng->txt('sess_gen_attendance_list'));
345
346 $title = new ilTextInputGUI($lng->txt('title'), 'title');
347 $title->setValue($this->title);
348 $form->addItem($title);
349
350 $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
351 $desc->setValue($this->description);
352 $form->addItem($desc);
353
354 if(sizeof($this->presets))
355 {
356 $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
357 $preset_value = array();
358 foreach($this->presets as $id => $item)
359 {
360 $preset->addOption(new ilCheckboxOption($item[0], $id));
361 if($item[1])
362 {
363 $preset_value[] = $id;
364 }
365 }
366 $preset->setValue($preset_value);
367 $form->addItem($preset);
368 }
369
370 $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
371 $blank->setMulti(true);
372 $form->addItem($blank);
373
374 if($this->pre_blanks)
375 {
376 $blank->setValue($this->pre_blanks);
377 }
378
379 $checked = array();
380
381 $chk_grp = new ilCheckboxGroupInputGUI($lng->txt('event_user_selection'), 'selection_of_users');
382
383 // participants by roles
384 foreach($this->role_data as $role_id => $role_data)
385 {
386 $title = ilObject::_lookupTitle($role_id);
387
388 $role_name = $role_id;
389 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_adm')
390 {
391 $role_name = 'adm';
392 }
393 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_mem')
394 {
395 $role_name = 'mem';
396 }
397 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_tut')
398 {
399 $role_name = 'tut';
400 }
401
402 $chk = new ilCheckboxOption(sprintf($lng->txt('event_user_selection_include_role'),$role_data[0]), 'role_'.$role_name);
403 $checked[] = 'role_'.$role_name;
404 $chk_grp->addOption($chk);
405 }
406
407 if($this->waiting_list)
408 {
409 $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_requests'), 'subscr');
410 $chk_grp->addOption($chk);
411
412 $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_waiting_list'), 'wlist');
413 $chk_grp->addOption($chk);
414 }
415
416 if($this->user_filters)
417 {
418 foreach($this->user_filters as $sub_id => $sub_item)
419 {
420 $chk = new ilCheckboxOption(sprintf($lng->txt('event_user_selection_include_filter'),$sub_item[0]),
421 'members_'.$sub_id);
422 if($sub_item[1])
423 {
424 $checked[] = 'members_'.$sub_id;
425 }
426 $chk_grp->addOption($chk);
427 }
428 }
429 $chk_grp->setValue($checked);
430 $form->addItem($chk_grp);
431
432 $form->addCommandButton($a_cmd,$lng->txt('sess_print_attendance_list'));
433
434 if($this->id && $a_cmd)
435 {
436 include_once "Services/User/classes/class.ilUserFormSettings.php";
437 $settings = new ilUserFormSettings($this->id);
438 if(!$settings->hasStoredEntry())
439 {
440 $settings = new ilUserFormSettings($this->parent_obj->getType().'s_pview', -1);
441 }
442
443 $settings->deleteValue('desc'); // #11340
444 $settings->exportToForm($form);
445 }
446
447 return $form;
448 }
449
453 public function initFromForm()
454 {
455 $form = $this->initForm();
456 if($form->checkInput())
457 {
458 foreach(array_keys($this->presets) as $id)
459 {
460 $this->presets[$id][1] = false;
461 }
462 foreach($form->getInput('preset') as $value)
463 {
464 if(isset($this->presets[$value]))
465 {
466 $this->presets[$value][1] = true;
467 }
468 else
469 {
470 $this->addPreset($value, $value, true);
471 }
472 }
473
474 $this->setTitle($form->getInput('title'), $form->getInput('desc'));
475 $this->setBlankColumns($form->getInput('blank'));
476
477 $selection_of_users = (array)$form->getInput('selection_of_users'); // #18238
478
479 $roles = array();
480 foreach(array_keys($this->role_data) as $role_id)
481 {
482 $title = ilObject::_lookupTitle($role_id);
483 $role_name = $role_id;
484 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_adm')
485 {
486 $role_name = 'adm';
487 }
488 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_mem')
489 {
490 $role_name = 'mem';
491 }
492 if(substr($title, 0, 10) == 'il_'.$this->parent_obj->getType().'_tut')
493 {
494 $role_name = 'tut';
495 }
496
497
498 if(in_array('role_'.$role_name, (array) $selection_of_users))
499 {
500 $roles[] = $role_id;
501 }
502 }
503 $this->setRoleSelection($roles);
504
505 // not in sessions
506 if($this->waiting_list)
507 {
508 $this->include_subscribers = (bool)in_array('subscr', $selection_of_users);
509 $this->include_waiting_list = (bool)in_array('wlist', $selection_of_users);
510 }
511
512 if($this->user_filters)
513 {
514 foreach(array_keys($this->user_filters) as $msub_id)
515 {
516 $this->user_filters[$msub_id][2] = (bool)in_array("members_".$msub_id, $selection_of_users);
517 }
518 }
519
520 if($this->id)
521 {
522 $form->setValuesByPost();
523
524 include_once "Services/User/classes/class.ilUserFormSettings.php";
525 $settings = new ilUserFormSettings($this->id);
526 $settings->deleteValue('desc'); // #11340
527 $settings->importFromForm($form);
528 $settings->store();
529 }
530
531 }
532 }
533
539 public function getFullscreenHTML()
540 {
541 $tpl = new ilTemplate('tpl.main.html',true,true);
542 $tpl->setBodyClass("ilBodyPrint");
543
544 // load style sheet depending on user's settings
545 $location_stylesheet = ilUtil::getStyleSheetLocation();
546 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
547
548 $tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
549 $tpl->setVariable("CONTENT", $this->getHTML());
550
551 return $tpl->show();
552 }
553
559 public function getHTML()
560 {
561 $tpl = new ilTemplate('tpl.attendance_list_print.html',true,true,'Services/Membership');
562
563
564 // title
565
568
569 $tpl->setVariable('TXT_TITLE', $this->title);
570 if($this->description)
571 {
572 $tpl->setVariable('TXT_DESCRIPTION', $this->description." (".$time.")");
573 }
574 else
575 {
576 $tpl->setVariable('TXT_DESCRIPTION', $time);
577 }
578
579
580 // header
581
582 $tpl->setCurrentBlock('head_item');
583 foreach($this->presets as $id => $item)
584 {
585 if($item[1])
586 {
587 $tpl->setVariable('TXT_HEAD', $item[0]);
588 $tpl->parseCurrentBlock();
589 }
590 }
591
592 if($this->blank_columns)
593 {
594 foreach($this->blank_columns as $blank)
595 {
596 $tpl->setVariable('TXT_HEAD', $blank);
597 $tpl->parseCurrentBlock();
598 }
599 }
600
601
602 // handle members
603
604 $valid_user_ids = $filters = array();
605
606 if($this->roles)
607 {
608 if($this->has_local_role)
609 {
610 $members = array();
611 foreach($this->participants->getMembers() as $member_id)
612 {
613 foreach($this->participants->getAssignedRoles($member_id) as $role_id)
614 {
615 $members[$role_id][] = $member_id;
616 }
617 }
618 }
619 else
620 {
621 $members = $this->participants->getMembers();
622 }
623
624 foreach($this->roles as $role_id)
625 {
626 switch($this->role_data[$role_id][1])
627 {
628 case "admin":
629 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getAdmins());
630 break;
631
632 case "tutor":
633 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getTutors());
634 break;
635
636 // member/local
637 default:
638 if(!$this->has_local_role)
639 {
640 $valid_user_ids = array_merge($valid_user_ids, (array)$members);
641 }
642 else
643 {
644 $valid_user_ids = array_merge($valid_user_ids, (array)$members[$role_id]);
645 }
646 break;
647 }
648 }
649 }
650
651 if($this->include_subscribers)
652 {
653 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getSubscribers());
654 }
655
656 if($this->include_waiting_list)
657 {
658 $valid_user_ids = array_merge($valid_user_ids, $this->waiting_list->getUserIds());
659 }
660
661 if($this->user_filters)
662 {
663 foreach($this->user_filters as $sub_id => $sub_item)
664 {
665 $filters[$sub_id] = (bool)$sub_item[2];
666 }
667 }
668
669 $valid_user_ids = ilUtil::_sortIds(array_unique($valid_user_ids),'usr_data','lastname','usr_id');
670
671
672 // rows
673
674 foreach($valid_user_ids as $user_id)
675 {
676 if($this->callback)
677 {
678 $user_data = call_user_func_array($this->callback, array($user_id, $filters));
679 if(!$user_data)
680 {
681 continue;
682 }
683
684 $tpl->setCurrentBlock("row_preset");
685 foreach($this->presets as $id => $item)
686 {
687 if($item[1])
688 {
689 switch($id)
690 {
691 case "name":
692 if(!$user_data[$id])
693 {
694 $name = ilObjUser::_lookupName($user_id);
695 $value = $name["lastname"].", ".$name["firstname"];
696 break;
697 }
698
699
700 case "login":
701 if(!$user_data[$id])
702 {
703 $value = ilObjUser::_lookupLogin($user_id);
704 break;
705 }
706
707 default:
708 $value = (string) $user_data[$id];
709 break;
710 }
711 $tpl->setVariable("TXT_PRESET", (string) $value);
712 $tpl->parseCurrentBlock();
713 }
714 }
715 }
716
717 if($this->blank_columns)
718 {
719 for($loop = 0; $loop < sizeof($this->blank_columns); $loop++)
720 {
721 $tpl->touchBlock('row_blank');
722 }
723 }
724
725 $tpl->touchBlock("member_row");
726 }
727
728 return $tpl->get();
729 }
730}
731
732?>
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
Base class for attendance lists.
setCallback($a_callback)
Set participant detail callback.
getHTML()
render attendance list
initForm($a_cmd="")
Init form.
addRole($a_id, $a_caption, $a_type)
Add role.
addPreset($a_id, $a_caption, $a_selected=false)
Add user field.
setRoleSelection($a_role_ids)
Set role selection.
addBlank($a_caption)
Add blank column preset.
__construct($a_parent_gui, $a_parent_obj, ilParticipants $a_participants_object=null, ilWaitingList $a_waiting_list=null)
Constructor.
setTitle($a_title, $a_description=null)
Set titles.
getFullscreenHTML()
render list in fullscreen mode
getNonMemberUserData(array &$a_res)
Get user data for subscribers and waiting list.
readOrderedExportableFields()
read object export fields
addUserFilter($a_id, $a_caption, $a_checked=false)
Add user filter.
setBlankColumns(array $a_values)
Add blank columns.
setId($a_value)
Set id (used for user form settings)
initFromForm()
Set list attributes from post values.
This class represents a property in a property form.
This class represents an option in a checkbox group.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
static _getValuesByObjId($a_obj_id)
Get values by obj_id (for all users)
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
static _getInstanceByType($a_type)
Get Singleton Instance.
static getLogger($a_component_id)
Get component logger.
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
Class ilUserDefinedData.
static _getInstance()
Get instance.
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,...
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
Base class for course and group waiting lists.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$a_type
Definition: workflow.php:93