ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 {
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->setPreventDoubleSubmission(false);
258 $form->setTitle($lng->txt('sess_gen_attendance_list'));
259
260 $title = new ilTextInputGUI($lng->txt('title'), 'title');
261 $title->setValue($this->title);
262 $form->addItem($title);
263
264 $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
265 $desc->setValue($this->description);
266 $form->addItem($desc);
267
268 if(sizeof($this->presets))
269 {
270 $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
271 $preset_value = array();
272 foreach($this->presets as $id => $item)
273 {
274 $preset->addOption(new ilCheckboxOption($item[0], $id));
275 if($item[1])
276 {
277 $preset_value[] = $id;
278 }
279 }
280 $preset->setValue($preset_value);
281 $form->addItem($preset);
282 }
283
284 $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
285 $blank->setMulti(true);
286 $form->addItem($blank);
287
288 if($this->pre_blanks)
289 {
290 $blank->setValue($this->pre_blanks);
291 }
292
293 $part = new ilFormSectionHeaderGUI();
294 $part->setTitle($lng->txt('event_participant_selection'));
295 $form->addItem($part);
296
297 // participants by roles
298 foreach($this->role_data as $role_id => $role_data)
299 {
300 $chk = new ilCheckboxInputGUI($role_data[0], 'role_'.$role_id);
301 $chk->setValue(1);
302 $chk->setChecked(1);
303 $form->addItem($chk);
304 }
305
306 // not in sessions
307 if($this->waiting_list)
308 {
309 $chk = new ilCheckboxInputGUI($lng->txt('group_new_registrations'), 'subscr');
310 $chk->setValue(1);
311 $form->addItem($chk);
312
313 $chk = new ilCheckboxInputGUI($lng->txt('crs_waiting_list'), 'wlist');
314 $chk->setValue(1);
315 $form->addItem($chk);
316 }
317
318 if($this->user_filters)
319 {
320 foreach($this->user_filters as $sub_id => $sub_item)
321 {
322 $sub = new ilCheckboxInputGUI($sub_item[0], 'members_'.$sub_id);
323 if($sub_item[1])
324 {
325 $sub->setChecked(true);
326 }
327 $form->addItem($sub);
328 }
329 }
330
331 $form->addCommandButton($a_cmd,$lng->txt('sess_print_attendance_list'));
332
333 if($this->id && $a_cmd)
334 {
335 include_once "Services/User/classes/class.ilUserFormSettings.php";
336 $settings = new ilUserFormSettings($this->id);
337 $settings->deleteValue('desc'); // #11340
338 $settings->exportToForm($form);
339 }
340
341 return $form;
342 }
343
347 public function initFromForm()
348 {
349 $form = $this->initForm();
350 if($form->checkInput())
351 {
352 foreach(array_keys($this->presets) as $id)
353 {
354 $this->presets[$id][1] = false;
355 }
356 foreach($form->getInput('preset') as $value)
357 {
358 if(isset($this->presets[$value]))
359 {
360 $this->presets[$value][1] = true;
361 }
362 else
363 {
364 $this->addPreset($value, $value, true);
365 }
366 }
367
368 $this->setTitle($form->getInput('title'), $form->getInput('desc'));
369 $this->setBlankColumns($form->getInput('blank'));
370
371 $roles = array();
372 foreach(array_keys($this->role_data) as $role_id)
373 {
374 if($form->getInput('role_'.$role_id))
375 {
376 $roles[] = $role_id;
377 }
378 }
379 $this->setRoleSelection($roles);
380
381 // not in sessions
382 if($this->waiting_list)
383 {
384 $this->include_subscribers = (bool)$form->getInput('subscr');
385 $this->include_waiting_list = (bool)$form->getInput('wlist');
386 }
387
388 if($this->user_filters)
389 {
390 foreach(array_keys($this->user_filters) as $msub_id)
391 {
392 $this->user_filters[$msub_id][2] = $form->getInput("members_".$msub_id);
393 }
394 }
395
396 if($this->id)
397 {
398 $form->setValuesByPost();
399
400 include_once "Services/User/classes/class.ilUserFormSettings.php";
401 $settings = new ilUserFormSettings($this->id);
402 $settings->deleteValue('desc'); // #11340
403 $settings->importFromForm($form);
404 $settings->store();
405 }
406
407 }
408 }
409
415 public function getFullscreenHTML()
416 {
417 $tpl = new ilTemplate('tpl.main.html',true,true);
418 $tpl->setBodyClass("ilBodyPrint");
419
420 // load style sheet depending on user's settings
421 $location_stylesheet = ilUtil::getStyleSheetLocation();
422 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
423
424 $tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
425 $tpl->setVariable("CONTENT", $this->getHTML());
426
427 return $tpl->show();
428 }
429
435 public function getHTML()
436 {
437 $tpl = new ilTemplate('tpl.attendance_list_print.html',true,true,'Services/Membership');
438
439
440 // title
441
442 $time = ilFormat::formatUnixTime(time(),true);
443
444 $tpl->setVariable('TXT_TITLE', $this->title);
445 if($this->description)
446 {
447 $tpl->setVariable('TXT_DESCRIPTION', $this->description." (".$time.")");
448 }
449 else
450 {
451 $tpl->setVariable('TXT_DESCRIPTION', $time);
452 }
453
454
455 // header
456
457 $tpl->setCurrentBlock('head_item');
458 foreach($this->presets as $id => $item)
459 {
460 if($item[1])
461 {
462 $tpl->setVariable('TXT_HEAD', $item[0]);
463 $tpl->parseCurrentBlock();
464 }
465 }
466
467 if($this->blank_columns)
468 {
469 foreach($this->blank_columns as $blank)
470 {
471 $tpl->setVariable('TXT_HEAD', $blank);
472 $tpl->parseCurrentBlock();
473 }
474 }
475
476
477 // handle members
478
479 $valid_user_ids = $filters = array();
480
481 if($this->roles)
482 {
483 if($this->has_local_role)
484 {
485 $members = array();
486 foreach($this->participants->getMembers() as $member_id)
487 {
488 foreach($this->participants->getAssignedRoles($member_id) as $role_id)
489 {
490 $members[$role_id][] = $member_id;
491 }
492 }
493 }
494 else
495 {
496 $members = $this->participants->getMembers();
497 }
498
499 foreach($this->roles as $role_id)
500 {
501 switch($this->role_data[$role_id][1])
502 {
503 case "admin":
504 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getAdmins());
505 break;
506
507 case "tutor":
508 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getTutors());
509 break;
510
511 // member/local
512 default:
513 if(!$this->has_local_role)
514 {
515 $valid_user_ids = array_merge($valid_user_ids, (array)$members);
516 }
517 else
518 {
519 $valid_user_ids = array_merge($valid_user_ids, (array)$members[$role_id]);
520 }
521 break;
522 }
523 }
524 }
525
526 if($this->include_subscribers)
527 {
528 $valid_user_ids = array_merge($valid_user_ids, $this->participants->getSubscribers());
529 }
530
531 if($this->include_waiting_list)
532 {
533 $valid_user_ids = array_merge($valid_user_ids, $this->waiting_list->getUserIds());
534 }
535
536 if($this->user_filters)
537 {
538 foreach($this->user_filters as $sub_id => $sub_item)
539 {
540 $filters[$sub_id] = (bool)$sub_item[2];
541 }
542 }
543
544 $valid_user_ids = ilUtil::_sortIds(array_unique($valid_user_ids),'usr_data','lastname','usr_id');
545
546
547 // rows
548
549 foreach($valid_user_ids as $user_id)
550 {
551 if($this->callback)
552 {
553 $user_data = call_user_func_array($this->callback, array($user_id, $filters));
554 if(!$user_data)
555 {
556 continue;
557 }
558
559 $tpl->setCurrentBlock("row_preset");
560 foreach($this->presets as $id => $item)
561 {
562 if($item[1])
563 {
564 switch($id)
565 {
566 case "name":
567 if(!$user_data[$id])
568 {
569 $name = ilObjUser::_lookupName($user_id);
570 $value = $name["lastname"].", ".$name["firstname"];
571 break;
572 }
573
574
575 case "email":
576 if(!$user_data[$id])
577 {
578 $value = ilObjUser::_lookupEmail($user_id);
579 break;
580 }
581
582
583 case "login":
584 if(!$user_data[$id])
585 {
586 $value = ilObjUser::_lookupLogin($user_id);
587 break;
588 }
589
590 default:
591 $value = (string)$user_data[$id];
592 break;
593 }
594 $tpl->setVariable("TXT_PRESET", $value);
595 $tpl->parseCurrentBlock();
596 }
597 }
598 }
599
600 if($this->blank_columns)
601 {
602 for($loop = 0; $loop < sizeof($this->blank_columns); $loop++)
603 {
604 $tpl->touchBlock('row_blank');
605 }
606 }
607
608 $tpl->touchBlock("member_row");
609 }
610
611 return $tpl->get();
612 }
613}
614
615?>
global $tpl
Definition: ilias.php:8
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.
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.
__construct($a_parent_obj, ilParticipants $a_participants_object=null, ilWaitingList $a_waiting_list=null)
Constructor.
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 a checkbox property in a property form.
This class represents an option in a checkbox group.
This class represents a section header in a property form.
formatUnixTime($ut, $with_time=false)
_lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
_lookupEmail($a_user_id)
Lookup email.
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.
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.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40