ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilConsultationHoursTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\UI\Renderer as UIRenderer;
23
30{
31 private int $user_id = 0;
32 private UIRenderer $renderer;
33 private UIFactory $uiFactory;
34
35 public function __construct(object $a_gui, string $a_cmd, int $a_user_id)
36 {
37 $this->user_id = $a_user_id;
38
39 $this->setId('chtg_' . $this->getUserId());
40 parent::__construct($a_gui, $a_cmd);
41
42 global $DIC;
43 $this->renderer = $DIC->ui()->renderer();
44 $this->uiFactory = $DIC->ui()->factory();
45
46 $this->addColumn('', 'f', '1');
47 $this->addColumn($this->lng->txt('appointment'), 'start');
48
49 $this->addColumn($this->lng->txt('title'), 'title');
50 $this->addColumn($this->lng->txt('cal_ch_num_bookings'), 'num_bookings');
51 $this->addColumn($this->lng->txt('cal_ch_bookings'), 'participants');
52 $this->addColumn($this->lng->txt('cal_ch_target_object'), 'target');
53 $this->addColumn('');
54
55 $this->setRowTemplate('tpl.ch_upcoming_row.html', 'components/ILIAS/Calendar');
56 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $this->getParentCmd()));
57 $this->setTitle($this->lng->txt('cal_ch_ch'));
58
59 $this->enable('sort');
60 $this->enable('header');
61 $this->enable('numinfo');
62
63 $this->setDefaultOrderField('start');
64 $this->setSelectAllCheckbox('apps');
65 $this->setShowRowsSelector(true);
66 $this->addMultiCommand('edit', $this->lng->txt('edit'));
67 $this->addMultiCommand('searchUsersForAppointments', $this->lng->txt('cal_ch_assign_participants'));
68 $this->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
69 }
70
71 public function getUserId(): int
72 {
73 return $this->user_id;
74 }
75
79 protected function fillRow(array $a_set): void
80 {
81 $this->tpl->setVariable('VAL_ID', $a_set['id']);
82 $this->tpl->setVariable('START', $a_set['start_p']);
83 $this->tpl->setVariable('TITLE', $a_set['title']);
84 $this->tpl->setVariable('NUM_BOOKINGS', $a_set['num_bookings']);
85
86 foreach ((array) ($a_set['target_links'] ?? []) as $link) {
87 $this->tpl->setCurrentBlock('links');
88 $this->tpl->setVariable('TARGET', $link['title']);
89 $this->tpl->setVariable('URL_TARGET', $link['link']);
90 $this->tpl->parseCurrentBlock();
91 }
92 if ($a_set['bookings']) {
93 foreach ($a_set['bookings'] as $user_id => $name) {
94 $user_profile_prefs = ilObjUser::_getPreferences($user_id);
95 if (($user_profile_prefs["public_profile"] ?? '') == "y") {
96 $this->tpl->setCurrentBlock('booking_with_link');
97 $this->ctrl->setParameter($this->getParentObject(), 'user', $user_id);
98 $this->tpl->setVariable(
99 'URL_BOOKING',
100 $this->ctrl->getLinkTarget($this->getParentObject(), 'showprofile')
101 );
102 } else {
103 $this->tpl->setCurrentBlock('booking_without_link');
104 }
105 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
106 $this->tpl->setVariable('TXT_BOOKING', $name);
107 $this->tpl->parseCurrentBlock();
108 }
109 }
110
111 $this->tpl->setVariable('BOOKINGS', implode(', ', $a_set['bookings']));
112 $this->ctrl->setParameter($this->getParentObject(), 'apps', $a_set['id']);
113
114 $dropDownItems = array(
115 $this->uiFactory->button()->shy(
116 $this->lng->txt('edit'),
117 $this->ctrl->getLinkTarget($this->getParentObject(), 'edit')
118 ),
119 $this->uiFactory->button()->shy(
120 $this->lng->txt('cal_ch_assign_participants'),
121 $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', '')
122 ),
123 $this->uiFactory->button()->shy(
124 $this->lng->txt('delete'),
125 $this->ctrl->getLinkTarget($this->getParentObject(), 'confirmDelete')
126 )
127 );
128 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
129 ->withLabel($this->lng->txt('actions'));
130 $this->tpl->setVariable('ACTIONS', $this->renderer->render($dropDown));
131 }
132
133 public function parse()
134 {
135 $data = array();
136 $counter = 0;
138 $data[$counter]['id'] = $app->getEntryId();
139 $data[$counter]['title'] = $app->getTitle();
140 $data[$counter]['description'] = $app->getDescription();
141 $data[$counter]['start'] = $app->getStart()->get(IL_CAL_UNIX);
142 $data[$counter]['start_p'] = ilDatePresentation::formatPeriod($app->getStart(), $app->getEnd());
143
144 $booking = new ilBookingEntry($app->getContextId());
145
146 $booked_user_ids = $booking->getCurrentBookings($app->getEntryId());
147 $booked_user_ids = array_map('intval', ilUtil::_sortIds($booked_user_ids, 'usr_data', 'lastname', 'usr_id'));
148 $users = array();
149 $data[$counter]['participants'] = '';
150 $user_counter = 0;
151 foreach ($booked_user_ids as $user_id) {
152 if (!$user_counter) {
154 $data[$counter]['participants'] = $name['lastname'];
155 }
157 $user_counter++;
158 }
159 $data[$counter]['bookings'] = $users;
160 $data[$counter]['num_bookings'] = $booking->getNumberOfBookings();
161
162 $data[$counter]['group'] = '';
163
164 // obj assignments
165 $refs_counter = 0;
166 $obj_ids = array_map(
167 'intval',
168 ilUtil::_sortIds($booking->getTargetObjIds(), 'object_data', 'title', 'obj_id')
169 );
170 foreach ($obj_ids as $obj_id) {
171 if ($refs_counter) {
172 $data[$counter]['target'] = ilObject::_lookupTitle($obj_id);
173 }
174
175 $refs = ilObject::_getAllReferences($obj_id);
176 $data[$counter]['target_links'][$refs_counter]['title'] = ilObject::_lookupTitle($obj_id);
177 $data[$counter]['target_links'][$refs_counter]['link'] = ilLink::_getLink(end($refs));
178 ++$refs_counter;
179 }
180 $counter++;
181 }
182 $this->setData($data);
183 }
184}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_UNIX
Booking definition.
static getAppointments(int $a_user_id)
Get all appointments.
Consultation hours administration.
__construct(object $a_gui, string $a_cmd, int $a_user_id)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
static _lookupFullname(int $a_user_id)
static _lookupName(int $a_user_id)
static _getPreferences(int $user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
enable(string $a_module_name)
static _sortIds(array $a_ids, string $a_table, string $a_field, string $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$counter