ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
18 protected $logger = null;
19
20 protected $parent_gui;
21 protected $parent_obj; // [object]
22 protected $participants; // [object]
23 protected $waiting_list; // [object]
24 protected $callback; // [string|array]
25 protected $presets; // [array]
26 protected $role_data; // [array]
27 protected $roles; // [array]
28 protected $has_local_role; // [bool]
29 protected $blank_columns; // [array]
30 protected $title; // [string]
31 protected $description; // [string]
32 protected $pre_blanks; // [array]
33 protected $id; // [string]
34 protected $include_waiting_list; // [bool]
35 protected $include_subscribers; // [bool]
36 protected $user_filters; // [array]
37
46 public function __construct($a_parent_gui, $a_parent_obj, ilParticipants $a_participants_object = null, ilWaitingList $a_waiting_list = null)
47 {
48 global $DIC;
49
50 $this->logger = $DIC->logger()->mmbr();
51
52 $this->parent_gui = $a_parent_gui;
53 $this->parent_obj = $a_parent_obj;
54 $this->participants = $a_participants_object;
55 $this->waiting_list = $a_waiting_list;
56
57 // always available
58 $this->presets['name'] = array($DIC->language()->txt('name'), true);
59 $this->presets['login'] = array($DIC->language()->txt('login'), true);
60
61
62 // add exportable fields
64
65 $DIC->language()->loadLanguageModule('crs');
66
67 // roles
68 $roles = $this->participants->getRoles();
69
70 foreach ($roles as $role_id) {
72 switch (substr($title, 0, 8)) {
73 case 'il_crs_a':
74 case 'il_grp_a':
75 case 'il_lso_a':
76 $this->addRole($role_id, $DIC->language()->txt('event_tbl_admin'), 'admin');
77 break;
78
79 case 'il_crs_t':
80 $this->addRole($role_id, $DIC->language()->txt('event_tbl_tutor'), 'tutor');
81 break;
82
83 case 'il_crs_m':
84 case 'il_grp_m':
85 case 'il_lso_m':
86 $this->addRole($role_id, $DIC->language()->txt('event_tbl_member'), 'member');
87 break;
88
89 case 'il_sess_':
90 $this->addRole($role_id, $DIC->language()->txt('event_tbl_member'), 'member');
91 break;
92
93 // local
94 default:
95 $this->has_local_role = true;
96 $this->addRole($role_id, $title, 'local');
97 break;
98 }
99 }
100 }
101
106 protected function readOrderedExportableFields()
107 {
108 include_once('Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
109 include_once('Services/PrivacySecurity/classes/class.ilExportFieldsInfo.php');
110 include_once('Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php');
111 include_once('Services/User/classes/class.ilUserDefinedFields.php');
112
113 $field_info = ilExportFieldsInfo::_getInstanceByType($this->parent_obj->getType());
114 $field_info->sortExportFields();
115
116 foreach ($field_info->getExportableFields() as $field) {
117 switch ($field) {
118 case 'username':
119 case 'firstname':
120 case 'lastname':
121 continue 2;
122 }
123
124 ilLoggerFactory::getLogger('mmbr')->dump($field, ilLogLevel::DEBUG);
125 // Check if default enabled
126 $this->presets[$field] = array(
127 $GLOBALS['DIC']['lng']->txt($field),
128 false
129 );
130 }
131
132 // add udf fields
134 foreach ($udf->getExportableFields($this->parent_obj->getId()) as $field_id => $udf_data) {
135 $this->presets['udf_' . $field_id] = array(
136 $udf_data['field_name'],
137 false
138 );
139 }
140
141 // add cdf fields
142 include_once './Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php';
143 foreach (ilCourseDefinedFieldDefinition::_getFields($this->parent_obj->getId()) as $field_obj) {
144 $this->presets['cdf_' . $field_obj->getId()] = array(
145 $field_obj->getName(),
146 false
147 );
148 }
149 return true;
150 }
151
159 public function addPreset($a_id, $a_caption, $a_selected = false)
160 {
161 $this->presets[$a_id] = array($a_caption, $a_selected);
162 }
163
169 public function addBlank($a_caption)
170 {
171 $this->pre_blanks[] = $a_caption;
172 }
173
180 public function setTitle($a_title, $a_description = null)
181 {
182 $this->title = $a_title;
183 $this->description = $a_description;
184 }
185
193 protected function addRole($a_id, $a_caption, $a_type)
194 {
195 $this->role_data[$a_id] = array($a_caption, $a_type);
196 }
197
198
199
205 protected function setRoleSelection($a_role_ids)
206 {
207 $this->roles = $a_role_ids;
208 }
209
217 public function addUserFilter($a_id, $a_caption, $a_checked = false)
218 {
219 $this->user_filters[$a_id] = array($a_caption, $a_checked);
220 }
221
227 public function getNonMemberUserData(array &$a_res)
228 {
229 global $DIC;
230
231 $lng = $DIC['lng'];
232
233 $subscriber_ids = $this->participants->getSubscribers();
234
235 $user_ids = $subscriber_ids;
236
237 if ($this->waiting_list) {
238 $user_ids = array_merge($user_ids, $this->waiting_list->getUserIds());
239 }
240
241 // Finally read user profile data
242 $profile_data = ilObjUser::_readUsersProfileData($user_ids);
243 foreach ($profile_data as $user_id => $fields) {
244 foreach ((array) $fields as $field => $value) {
245 $a_res[$user_id][$field] = $value;
246 }
247 }
248
249 include_once './Services/User/classes/class.ilUserDefinedFields.php';
251
252 foreach ($udf->getExportableFields($this->parent_obj->getId()) as $field_id => $udf_data) {
253 foreach ($profile_data as $user_id => $field) {
254 include_once './Services/User/classes/class.ilUserDefinedData.php';
255 $udf_data = new ilUserDefinedData($user_id);
256 $a_res[$user_id]['udf_' . $field_id] = (string) $udf_data->get('f_' . $field_id);
257 }
258 }
259
260 if (sizeof($user_ids)) {
261 // object specific user data
262 include_once 'Modules/Course/classes/Export/class.ilCourseUserData.php';
263 $cdfs = ilCourseUserData::_getValuesByObjId($this->parent_obj->getId());
264
265 foreach (array_unique($user_ids) as $user_id) {
266 if ($tmp_obj = ilObjectFactory::getInstanceByObjId($user_id, false)) {
267 $a_res[$user_id]['login'] = $tmp_obj->getLogin();
268 $a_res[$user_id]['name'] = $tmp_obj->getLastname() . ', ' . $tmp_obj->getFirstname();
269
270 if (in_array($user_id, $subscriber_ids)) {
271 $a_res[$user_id]['status'] = $lng->txt('crs_subscriber');
272 } else {
273 $a_res[$user_id]['status'] = $lng->txt('crs_waiting_list');
274 }
275
276 foreach ((array) $cdfs[$user_id] as $field_id => $value) {
277 $a_res[$user_id]['cdf_' . $field_id] = (string) $value;
278 }
279 }
280 }
281 }
282 }
283
289 public function setBlankColumns(array $a_values)
290 {
291 if (!implode("", $a_values)) {
292 $a_values = array();
293 } else {
294 foreach ($a_values as $idx => $value) {
295 $a_values[$idx] = trim($value);
296 if ($a_values[$idx] == "") {
297 unset($a_values[$idx]);
298 }
299 }
300 }
301 $this->blank_columns = $a_values;
302 }
303
309 public function setCallback($a_callback)
310 {
311 $this->callback = $a_callback;
312 }
313
319 public function setId($a_value)
320 {
321 $this->id = (string) $a_value;
322 }
323
330 public function initForm($a_cmd = "")
331 {
332 global $DIC;
333
334 $ilCtrl = $DIC['ilCtrl'];
335 $lng = $DIC['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->setPreventDoubleSubmission(false);
343 $form->setTitle($lng->txt('sess_gen_attendance_list'));
344
345 $title = new ilTextInputGUI($lng->txt('title'), 'title');
346 $title->setValue($this->title);
347 $form->addItem($title);
348
349 $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
350 $desc->setValue($this->description);
351 $form->addItem($desc);
352
353 if (sizeof($this->presets)) {
354 $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
355 $preset_value = array();
356 foreach ($this->presets as $id => $item) {
357 $preset->addOption(new ilCheckboxOption($item[0], $id));
358 if ($item[1]) {
359 $preset_value[] = $id;
360 }
361 }
362 $preset->setValue($preset_value);
363 $form->addItem($preset);
364 }
365
366 $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
367 $blank->setMulti(true);
368 $form->addItem($blank);
369
370 if ($this->pre_blanks) {
371 $blank->setValue($this->pre_blanks);
372 }
373
374 $checked = array();
375
376 $chk_grp = new ilCheckboxGroupInputGUI($lng->txt('event_user_selection'), 'selection_of_users');
377
378 // participants by roles
379 foreach ($this->role_data as $role_id => $role_data) {
380 $title = ilObject::_lookupTitle($role_id);
381
382 $role_name = $role_id;
383 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_adm') {
384 $role_name = 'adm';
385 }
386 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_mem') {
387 $role_name = 'mem';
388 }
389 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_tut') {
390 $role_name = 'tut';
391 }
392
393 $chk = new ilCheckboxOption(sprintf($lng->txt('event_user_selection_include_role'), $role_data[0]), 'role_' . $role_name);
394 $checked[] = 'role_' . $role_name;
395 $chk_grp->addOption($chk);
396 }
397
398 if ($this->waiting_list) {
399 $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_requests'), 'subscr');
400 $chk_grp->addOption($chk);
401
402 $chk = new ilCheckboxOption($lng->txt('event_user_selection_include_waiting_list'), 'wlist');
403 $chk_grp->addOption($chk);
404 }
405
406 if ($this->user_filters) {
407 foreach ($this->user_filters as $sub_id => $sub_item) {
408 $chk = new ilCheckboxOption(
409 sprintf($lng->txt('event_user_selection_include_filter'), $sub_item[0]),
410 'members_' . $sub_id
411 );
412 if ($sub_item[1]) {
413 $checked[] = 'members_' . $sub_id;
414 }
415 $chk_grp->addOption($chk);
416 }
417 }
418 $chk_grp->setValue($checked);
419 $form->addItem($chk_grp);
420
421 $form->addCommandButton($a_cmd, $lng->txt('sess_print_attendance_list'));
422
423 if ($this->id && $a_cmd) {
424 include_once "Services/User/classes/class.ilUserFormSettings.php";
425 $settings = new ilUserFormSettings($this->id);
426 if (!$settings->hasStoredEntry()) {
427 $settings = new ilUserFormSettings($this->parent_obj->getType() . 's_pview', -1);
428 }
429
430 $settings->deleteValue('desc'); // #11340
431 $settings->exportToForm($form);
432 } elseif ($a_cmd == 'printForMembersOutput') {
433 include_once "Services/User/classes/class.ilUserFormSettings.php";
434 $settings = new ilUserFormSettings($this->parent_obj->getType() . 's_pview_' . $this->parent_obj->getId(), -1);
435 if (!$settings->hasStoredEntry()) {
436 // init from global defaults
437 $settings = new ilUserFormSettings($this->parent_obj->getType() . 's_pview', -1);
438 }
439
440 $settings->deleteValue('desc'); // #11340
441 $settings->exportToForm($form, true);
442 }
443
444 return $form;
445 }
446
450 public function initFromForm()
451 {
452 $form = $this->initForm();
453 if ($form->checkInput()) {
454 foreach (array_keys($this->presets) as $id) {
455 $this->presets[$id][1] = false;
456 }
457 foreach ((array) $form->getInput('preset') as $value) {
458 if (isset($this->presets[$value])) {
459 $this->presets[$value][1] = true;
460 } else {
461 $this->addPreset($value, $value, true);
462 }
463 }
464
465 $this->setTitle($form->getInput('title'), $form->getInput('desc'));
466 $this->setBlankColumns($form->getInput('blank'));
467
468 $selection_of_users = (array) $form->getInput('selection_of_users'); // #18238
469
470 $roles = array();
471 foreach (array_keys($this->role_data) as $role_id) {
472 $title = ilObject::_lookupTitle($role_id);
473 $role_name = $role_id;
474 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_adm') {
475 $role_name = 'adm';
476 }
477 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_mem') {
478 $role_name = 'mem';
479 }
480 if (substr($title, 0, 10) == 'il_' . $this->parent_obj->getType() . '_tut') {
481 $role_name = 'tut';
482 }
483
484
485 if (in_array('role_' . $role_name, (array) $selection_of_users)) {
486 $roles[] = $role_id;
487 }
488 }
489 $this->setRoleSelection($roles);
490
491 // not in sessions
492 if ($this->waiting_list) {
493 $this->include_subscribers = (bool) in_array('subscr', $selection_of_users);
494 $this->include_waiting_list = (bool) in_array('wlist', $selection_of_users);
495 }
496
497 if ($this->user_filters) {
498 foreach (array_keys($this->user_filters) as $msub_id) {
499 $this->user_filters[$msub_id][2] = (bool) in_array("members_" . $msub_id, $selection_of_users);
500 }
501 }
502
503 if ($this->id) {
504 #$form->setValuesByPost();
505
506 #include_once "Services/User/classes/class.ilUserFormSettings.php";
507 #$settings = new ilUserFormSettings($this->id);
508 #$settings->deleteValue('desc'); // #11340
509 #$settings->importFromForm($form);
510 #$settings->store();
511 }
512 }
513 }
514
520 public function getFullscreenHTML()
521 {
522 global $DIC;
523
524
525 $tpl = $DIC->ui()->mainTemplate();
526 $tpl->setContent($this->getHTML());
527 //$tpl->setVariable("CONTENT", $this->getHTML());
528 //$tpl->setContent($this->getHTML());
529 }
530
536 public function getHTML()
537 {
538 $tpl = new ilTemplate('tpl.attendance_list_print.html', true, true, 'Services/Membership');
539
540
541 // title
542
545
546 $tpl->setVariable('TXT_TITLE', $this->title);
547 if ($this->description) {
548 $tpl->setVariable('TXT_DESCRIPTION', $this->description . " (" . $time . ")");
549 } else {
550 $tpl->setVariable('TXT_DESCRIPTION', $time);
551 }
552
553 ilLoggerFactory::getLogger('mmbr')->dump($this->presets, ilLogLevel::DEBUG);
554 // header
555
556 $tpl->setCurrentBlock('head_item');
557 foreach ($this->presets as $id => $item) {
558 if ($item[1]) {
559 $tpl->setVariable('TXT_HEAD', $item[0]);
560 $tpl->parseCurrentBlock();
561 }
562 }
563
564 if ($this->blank_columns) {
565 foreach ($this->blank_columns as $blank) {
566 $tpl->setVariable('TXT_HEAD', $blank);
567 $tpl->parseCurrentBlock();
568 }
569 }
570
571
572 // handle members
573
574 $valid_user_ids = $filters = array();
575
576 if ($this->roles) {
577 if ($this->has_local_role) {
578 $members = array();
579 foreach ($this->participants->getMembers() as $member_id) {
580 foreach ($this->participants->getAssignedRoles($member_id) as $role_id) {
581 $members[$role_id][] = $member_id;
582 }
583 }
584 } else {
585 $members = $this->participants->getMembers();
586 }
587
588 foreach ($this->roles as $role_id) {
589 switch ($this->role_data[$role_id][1]) {
590 case "admin":
591 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getAdmins());
592 break;
593
594 case "tutor":
595 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getTutors());
596 break;
597
598 // member/local
599 default:
600 if (!$this->has_local_role) {
601 $valid_user_ids = array_merge($valid_user_ids, (array) $members);
602 } else {
603 $valid_user_ids = array_merge($valid_user_ids, (array) $members[$role_id]);
604 }
605 break;
606 }
607 }
608 }
609
610 if ($this->include_subscribers) {
611 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getSubscribers());
612 }
613
614 if ($this->include_waiting_list) {
615 $valid_user_ids = array_merge($valid_user_ids, $this->waiting_list->getUserIds());
616 }
617
618 if ($this->user_filters) {
619 foreach ($this->user_filters as $sub_id => $sub_item) {
620 $filters[$sub_id] = (bool) $sub_item[2];
621 }
622 }
623
624 $valid_user_ids = ilUtil::_sortIds(array_unique($valid_user_ids), 'usr_data', 'lastname', 'usr_id');
625 foreach ($valid_user_ids as $user_id) {
626 if ($this->callback) {
627 $user_data = call_user_func_array($this->callback, array($user_id, $filters));
628 if (!$user_data) {
629 continue;
630 }
631
632 $tpl->setCurrentBlock("row_preset");
633 foreach ($this->presets as $id => $item) {
634 if ($item[1]) {
635 switch ($id) {
636 case 'org_units':
637 $value = (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
638 break;
639
640 case "name":
641 if (!$user_data[$id]) {
642 $name = ilObjUser::_lookupName($user_id);
643 $value = $name["lastname"] . ", " . $name["firstname"];
644 break;
645 }
646
647
648 // no break
649 case "login":
650 if (!$user_data[$id]) {
651 $value = ilObjUser::_lookupLogin($user_id);
652 break;
653 }
654
655 // no break
656 default:
657 $value = (string) $user_data[$id];
658 break;
659 }
660 $tpl->setVariable("TXT_PRESET", (string) $value);
661 $tpl->parseCurrentBlock();
662 }
663 }
664 }
665
666 if ($this->blank_columns) {
667 for ($loop = 0; $loop < sizeof($this->blank_columns); $loop++) {
668 $tpl->touchBlock('row_blank');
669 }
670 }
671
672 $tpl->touchBlock("member_row");
673 }
674
675 return $tpl->get();
676 }
677}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
@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,...
Base class for course and group waiting lists.
global $ilCtrl
Definition: ilias.php:18
if($format !==null) $name
Definition: metadata.php:230
$lng
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46