ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilEmployeeTalkTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\UI\Factory as UIFactory;
24use ILIAS\UI\Renderer as UIRenderer;
26
28{
29 public const int STATUS_ALL = 0;
30 public const int STATUS_PENDING = 1;
31 public const int STATUS_COMPLETED = 2;
32
33 private UIFactory $ui_factory;
34 private UIRenderer $ui_renderer;
37
41 private array $delete_modals = [];
42
43 public function __construct(ControlFlowCommandHandler $a_parent_obj, $a_parent_cmd = '')
44 {
45 global $DIC;
46
47 $this->talk_access = new ilObjEmployeeTalkAccess();
48 $this->ui_factory = $DIC->ui()->factory();
49 $this->ui_renderer = $DIC->ui()->renderer();
50 $this->language = $DIC->language();
51 $this->language->loadLanguageModule('etal');
52 $this->language->loadLanguageModule('orgu');
53
54 $this->setPrefix('myst_etal_list_');
55 $this->setFormName('myst_etal_list');
56 $this->setId('myst_etal_list');
57
58 parent::__construct($a_parent_obj, $a_parent_cmd, '');
59 $this->setRowTemplate('tpl.list_employee_talk_row.html', "components/ILIAS/EmployeeTalk");
60 $this->setFormAction($DIC->ctrl()->getFormAction($a_parent_obj));
61 $this->setDefaultOrderDirection('desc');
62
63 $this->setShowRowsSelector(true);
64
65
66 $this->setEnableTitle(true);
67 $this->setDisableFilterHiding(true);
68 $this->setEnableNumInfo(true);
69
70 $this->addColumns();
71 $this->initFilter();
72 }
73
74 public function initFilter(): void
75 {
76 $this->setFilterCols(6);
77 $this->addFilterItemByMetaType('etal_title', self::FILTER_TEXT, false, $this->language->txt('title'));
78 $this->addFilterItemByMetaType('etal_template', self::FILTER_TEXT, false, $this->language->txt('type'));
79
83 $dateSelectInput = $this->addFilterItemByMetaType('etal_date', self::FILTER_DATE, false, $this->language->txt('date_of_talk'));
84
85 // Filter throws a null pointer error if not set
86 if ($dateSelectInput->getDate() === null) {
87 $dateSelectInput->setDate(new ilDateTime());
88 }
89 $this->addFilterItemByMetaType('etal_superior', self::FILTER_TEXT, false, $this->language->txt('superior'));
90 $this->addFilterItemByMetaType('etal_employee', self::FILTER_TEXT, false, $this->language->txt('employee'));
94 $ilSelectInput = $this->addFilterItemByMetaType('etal_status', self::FILTER_SELECT, false, $this->language->txt('status'));
95 $ilSelectInput->setOptions([
96 self::STATUS_ALL => $this->language->txt('etal_status_all'),
97 self::STATUS_PENDING => $this->language->txt('etal_status_pending'),
98 self::STATUS_COMPLETED => $this->language->txt('etal_status_completed')
99 ]);
100 }
101
102 private function addColumns(): void
103 {
104 $this->addColumn(
105 $this->language->txt('title'),
106 "etal_title",
107 "auto"
108 );
109 $this->addColumn(
110 $this->language->txt('type'),
111 "etal_template",
112 "auto"
113 );
114 $this->addColumn(
115 $this->language->txt('date_of_talk'),
116 "etal_date",
117 "auto"
118 );
119 $this->addColumn(
120 $this->language->txt('superior'),
121 "etal_superior",
122 "auto"
123 );
124 $this->addColumn(
125 $this->language->txt('employee'),
126 "etal_employee",
127 "auto"
128 );
129 $this->addColumn(
130 $this->language->txt('status'),
131 "etal_status",
132 "auto"
133 );
134 $this->addColumn(
135 $this->language->txt('action'),
136 "",
137 "auto"
138 );
139
140 $this->setDefaultFilterVisiblity(true);
141 $this->setDefaultOrderField("etal_date");
142 }
143
144 protected function fillRow($a_set): void
145 {
146 $talk_class = strtolower(ilObjEmployeeTalkGUI::class);
147 $class_path = $this->getParentObject()->getClassPath();
148 $class_path[] = $talk_class;
149
150 $ref_id = $a_set['ref_id'];
151 $this->ctrl->setParameterByClass($talk_class, 'ref_id', $ref_id);
152 $url = $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::DEFAULT);
153
154 $buttons = [];
155 if ($this->talk_access->canEdit($ref_id)) {
156 $buttons[] = $this->ui_factory->link()->standard(
157 $this->language->txt('edit'),
158 $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::UPDATE)
159 );
160 } else {
161 $buttons[] = $this->ui_factory->link()->standard(
162 $this->language->txt('view'),
163 $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::INDEX)
164 );
165 }
166
167 if ($this->talk_access->canDelete($ref_id)) {
168 $modal = $this->getConfirmationModal(
169 $a_set['etal_title'],
170 $ref_id,
171 $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::DELETE)
172 );
173 $buttons[] = $this->ui_factory->button()->shy(
174 $this->language->txt('delete'),
175 ''
176 )->withOnClick($modal->getShowSignal());
177 $this->delete_modals[] = $modal;
178 }
179 $this->ctrl->clearParametersByClass($talk_class);
180 $actions = $this->ui_factory->dropdown()->standard($buttons)->withLabel(
181 $this->language->txt('actions')
182 );
183
184 $this->tpl->setVariable("HREF_ETAL_TITLE", $url);
185 $this->tpl->setVariable("VAL_ETAL_TITLE", $a_set['etal_title']);
186 $this->tpl->setVariable("VAL_ETAL_TEMPLATE", $a_set['etal_template']);
187 $this->tpl->setVariable("VAL_ETAL_DATE", ilDatePresentation::formatDate($a_set['etal_date']));
188 $this->tpl->setVariable("VAL_ETAL_SUPERIOR", $a_set['etal_superior']);
189 $this->tpl->setVariable("VAL_ETAL_EMPLOYEE", $a_set['etal_employee']);
190 $this->tpl->setVariable("VAL_ETAL_STATUS", $a_set['etal_status']);
191 $this->tpl->setVariable("ACTIONS", $this->ui_renderer->render($actions));
192 }
193
194 public function setTalkData(array $talks): void
195 {
196 $data = [];
197 foreach ($talks as $val) {
198 if (!ilObject::_hasUntrashedReference($val->getObjectId())) {
199 continue;
200 }
201
202 if (trim($employee_filter = $this->getFilterValueByPostVar('etal_employee')) !== "") {
203 $filterUser = ilObjUser::getUserIdByLogin(trim($employee_filter));
204 if ($val->getEmployee() !== $filterUser) {
205 continue;
206 }
207 }
208
209 $refIds = ilObjEmployeeTalk::_getAllReferences($val->getObjectId());
210 $talk = new ilObjEmployeeTalk(array_pop($refIds), true);
211 $talkData = $talk->getData();
212 $employeeName = $this->language->txt('etal_unknown_username');
213 $superiorName = $this->language->txt('etal_unknown_username');
214 $ownerId = $talk->getOwner();
215 if (ilObjUser::_exists($talk->getOwner())) {
216 $superiorName = ilObjUser::_lookupLogin($ownerId);
217 }
218 if (ilObjUser::_exists($talkData->getEmployee())) {
219 $employeeName = ilObjUser::_lookupLogin($talkData->getEmployee());
220 }
221
222 if (trim($superior_filter = $this->getFilterValueByPostVar('etal_superior')) !== "") {
223 $filterUser = ilObjUser::getUserIdByLogin(trim($superior_filter));
224 if ($talk->getOwner() !== $filterUser) {
225 continue;
226 }
227 }
228
229 if (trim($title_filter = $this->getFilterValueByPostVar('etal_title')) !== "") {
230 if (strpos(strtolower($talk->getTitle()), strtolower(trim($title_filter))) === false) {
231 continue;
232 }
233 }
234
235 if (($date_filter = $this->getFilterValueByPostVar('etal_date')) !== '') {
236 $filterDate = new ilDateTime($date_filter, IL_CAL_DATE);
237 if (
238 !ilDateTime::_equals($filterDate, $val->getStartDate(), IL_CAL_DAY)
239 ) {
240 continue;
241 }
242 }
243 if (
244 ($status_filter = $this->getFilterValueByPostVar('etal_status')) !== "" &&
245 $status_filter !== '0'
246 ) {
247 $filterCompleted = ((int) $status_filter === ilEmployeeTalkTableGUI::STATUS_COMPLETED);
248 if ($filterCompleted && !$val->isCompleted()) {
249 continue;
250 }
251
252 if (!$filterCompleted && $val->isCompleted()) {
253 continue;
254 }
255 }
256
257 $template_title = '';
258 if ($talkData->getTemplateId() > 0 && ilObject::_exists($talkData->getTemplateId())) {
259 $template = ilObjectFactory::getInstanceByObjId($talkData->getTemplateId());
260 $template_title = $template->getTitle();
261 }
262 if (trim($template_filter = $this->getFilterValueByPostVar('etal_template')) !== "") {
263 if (strpos(strtolower($template_title), strtolower(trim($template_filter))) === false) {
264 continue;
265 }
266 }
267
268 $data[] = [
269 "ref_id" => $talk->getRefId(),
270 "etal_title" => $talk->getTitle(),
271 "etal_template" => $template_title,
272 "etal_date" => $talkData->getStartDate(),
273 "etal_superior" => $superiorName,
274 "etal_employee" => $employeeName,
275 "etal_status" => $talkData->isCompleted() ? $this->language->txt('etal_status_completed') : $this->language->txt('etal_status_pending'),
276 "permission_write" => false,
277 "permission_delete" => false
278 ];
279 }
280 $this->setData($data);
281 }
282
283 protected function getFilterValueByPostVar(string $post_var): string
284 {
285 $item = $this->getFilterItemByPostVar($post_var);
286 if ($item === null) {
287 return '';
288 }
289 return (string) $this->getFilterValue($item);
290 }
291
292 protected function getConfirmationModal(
293 string $talk_title,
294 int $talk_ref_id,
295 string $action
296 ): InterruptiveModal {
297 $item = $this->ui_factory->modal()->interruptiveItem()->standard(
298 (string) $talk_ref_id,
299 $talk_title
300 );
301
302 return $this->ui_factory->modal()->interruptive(
303 $this->language->txt('confirm'),
304 $this->language->txt('etal_delete_confirmation_msg'),
305 $action
306 )->withAffectedItems([$item]);
307 }
308
309 public function getHTML(): string
310 {
311 return parent::getHTML() . $this->ui_renderer->render($this->delete_modals);
312 }
313}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_DATE
const IL_CAL_DAY
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
array $delete_modals
InterruptiveModal[].
getConfirmationModal(string $talk_title, int $talk_ref_id, string $action)
__construct(ControlFlowCommandHandler $a_parent_obj, $a_parent_cmd='')
ilObjEmployeeTalkAccess $talk_access
language handling
static getUserIdByLogin(string $a_login)
static _lookupLogin(int $a_user_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _getAllReferences(int $id)
get all reference ids for object ID
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
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.
getFilterItemByPostVar(string $a_post_var)
setEnableNumInfo(bool $a_val)
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
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)
setDisableFilterHiding(bool $a_val=true)
getFilterValue(ilTableFilterItem $a_item)
Get current filter value.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setFilterCols(int $a_val)
setDefaultFilterVisiblity(bool $a_status)
setData(array $a_data)
Set table data.
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
modal(string $title="", string $cancel_label="")
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68