ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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;
23use ILIAS\User\Settings\Settings as UserSettings;
24
31{
32 private int $user_id = 0;
33 private UIRenderer $renderer;
34 private UIFactory $uiFactory;
35 private UserSettings $user_settings;
36
37 public function __construct(object $a_gui, string $a_cmd, int $a_user_id)
38 {
39 $this->user_id = $a_user_id;
40
41 $this->setId('chtg_' . $this->getUserId());
42 parent::__construct($a_gui, $a_cmd);
43
44 global $DIC;
45 $this->renderer = $DIC->ui()->renderer();
46 $this->uiFactory = $DIC->ui()->factory();
47 $this->user_settings = $DIC['user']->getSettings();
48
49 $this->addColumn('', 'f', '1');
50 $this->addColumn($this->lng->txt('appointment'), 'start');
51
52 $this->addColumn($this->lng->txt('title'), 'title');
53 $this->addColumn($this->lng->txt('cal_ch_num_bookings'), 'num_bookings');
54 $this->addColumn($this->lng->txt('cal_ch_bookings'), 'participants');
55 $this->addColumn($this->lng->txt('cal_ch_target_object'), 'target');
56 $this->addColumn('');
57
58 $this->setRowTemplate('tpl.ch_upcoming_row.html', 'components/ILIAS/Calendar');
59 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $this->getParentCmd()));
60 $this->setTitle($this->lng->txt('cal_ch_ch'));
61
62 $this->enable('sort');
63 $this->enable('header');
64 $this->enable('numinfo');
65
66 $this->setDefaultOrderField('start');
67 $this->setSelectAllCheckbox('apps');
68 $this->setShowRowsSelector(true);
69 $this->addMultiCommand('edit', $this->lng->txt('edit'));
70 $this->addMultiCommand('searchUsersForAppointments', $this->lng->txt('cal_ch_assign_participants'));
71 $this->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
72 }
73
74 public function getUserId(): int
75 {
76 return $this->user_id;
77 }
78
82 protected function fillRow(array $a_set): void
83 {
84 $this->tpl->setVariable('VAL_ID', $a_set['id']);
85 $this->tpl->setVariable('START', $a_set['start_p']);
86 $this->tpl->setVariable('TITLE', $a_set['title']);
87 $this->tpl->setVariable('NUM_BOOKINGS', $a_set['num_bookings']);
88
89 foreach ((array) ($a_set['target_links'] ?? []) as $link) {
90 $this->tpl->setCurrentBlock('links');
91 $this->tpl->setVariable('TARGET', $link['title']);
92 $this->tpl->setVariable('URL_TARGET', $link['link']);
93 $this->tpl->parseCurrentBlock();
94 }
95 if ($a_set['bookings']) {
96 foreach ($a_set['bookings'] as $user_id => $name) {
97 $public_profile = $this->user_settings->getSettingValueFor($user_id, 'public_profile') ?? '';
98 if ($public_profile == "y") {
99 $this->tpl->setCurrentBlock('booking_with_link');
100 $this->ctrl->setParameter($this->getParentObject(), 'user', $user_id);
101 $this->tpl->setVariable(
102 'URL_BOOKING',
103 $this->ctrl->getLinkTarget($this->getParentObject(), 'showprofile')
104 );
105 } else {
106 $this->tpl->setCurrentBlock('booking_without_link');
107 }
108 $this->ctrl->setParameter($this->getParentObject(), 'user', '');
109 $this->tpl->setVariable('TXT_BOOKING', $name);
110 $this->tpl->parseCurrentBlock();
111 }
112 }
113
114 $this->tpl->setVariable('BOOKINGS', implode(', ', $a_set['bookings']));
115 $this->ctrl->setParameter($this->getParentObject(), 'apps', $a_set['id']);
116
117 $dropDownItems = array(
118 $this->uiFactory->button()->shy(
119 $this->lng->txt('edit'),
120 $this->ctrl->getLinkTarget($this->getParentObject(), 'edit')
121 ),
122 $this->uiFactory->button()->shy(
123 $this->lng->txt('cal_ch_assign_participants'),
124 $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', '')
125 ),
126 $this->uiFactory->button()->shy(
127 $this->lng->txt('delete'),
128 $this->ctrl->getLinkTarget($this->getParentObject(), 'confirmDelete')
129 )
130 );
131 $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
132 ->withLabel($this->lng->txt('actions'));
133 $this->tpl->setVariable('ACTIONS', $this->renderer->render($dropDown));
134 }
135
136 public function parse()
137 {
138 $data = array();
139 $counter = 0;
141 $data[$counter]['id'] = $app->getEntryId();
142 $data[$counter]['title'] = $app->getTitle();
143 $data[$counter]['description'] = $app->getDescription();
144 $data[$counter]['start'] = $app->getStart()->get(IL_CAL_UNIX);
145 $data[$counter]['start_p'] = ilDatePresentation::formatPeriod($app->getStart(), $app->getEnd());
146
147 $booking = new ilBookingEntry($app->getContextId());
148
149 $booked_user_ids = $booking->getCurrentBookings($app->getEntryId());
150 $booked_user_ids = array_map('intval', ilUtil::_sortIds($booked_user_ids, 'usr_data', 'lastname', 'usr_id'));
151 $users = array();
152 $data[$counter]['participants'] = '';
153 $user_counter = 0;
154 foreach ($booked_user_ids as $user_id) {
155 if (!$user_counter) {
157 $data[$counter]['participants'] = $name['lastname'];
158 }
160 $user_counter++;
161 }
162 $data[$counter]['bookings'] = $users;
163 $data[$counter]['num_bookings'] = $booking->getNumberOfBookings();
164
165 $data[$counter]['group'] = '';
166
167 // obj assignments
168 $refs_counter = 0;
169 $obj_ids = array_map(
170 'intval',
171 ilUtil::_sortIds($booking->getTargetObjIds(), 'object_data', 'title', 'obj_id')
172 );
173 foreach ($obj_ids as $obj_id) {
174 if ($refs_counter) {
175 $data[$counter]['target'] = ilObject::_lookupTitle($obj_id);
176 }
177
178 $refs = ilObject::_getAllReferences($obj_id);
179 $data[$counter]['target_links'][$refs_counter]['title'] = ilObject::_lookupTitle($obj_id);
180 $data[$counter]['target_links'][$refs_counter]['link'] = ilLink::_getLink(end($refs));
181 ++$refs_counter;
182 }
183 $counter++;
184 }
185 $this->setData($data);
186 }
187}
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 _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