ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilEmployeeTalkTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
28 {
29  public const int STATUS_ALL = 0;
30  public const int STATUS_PENDING = 1;
31  public const int STATUS_COMPLETED = 2;
32 
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  ;
62  $this->setDefaultOrderDirection('desc');
63 
64  $this->setShowRowsSelector(true);
65 
66 
67  $this->setEnableTitle(true);
68  $this->setDisableFilterHiding(true);
69  $this->setEnableNumInfo(true);
70  $this->setExternalSegmentation(true);
71 
72  $this->addColumns();
73 
74  $this->initFilter();
75  $this->determineLimit();
76  $this->determineOffsetAndOrder();
77  }
78 
79  public function initFilter(): void
80  {
81  $this->setFilterCols(6);
82  $this->addFilterItemByMetaType('etal_title', self::FILTER_TEXT, false, $this->language->txt('title'));
83  $this->addFilterItemByMetaType('etal_template', self::FILTER_TEXT, false, $this->language->txt('type'));
84 
88  $dateSelectInput = $this->addFilterItemByMetaType('etal_date', self::FILTER_DATE, false, $this->language->txt('date_of_talk'));
89 
90  // Filter throws a null pointer error if not set
91  if ($dateSelectInput->getDate() === null) {
92  $dateSelectInput->setDate(new ilDateTime());
93  }
94  $this->addFilterItemByMetaType('etal_superior', self::FILTER_TEXT, false, $this->language->txt('superior'));
95  $this->addFilterItemByMetaType('etal_employee', self::FILTER_TEXT, false, $this->language->txt('employee'));
99  $ilSelectInput = $this->addFilterItemByMetaType('etal_status', self::FILTER_SELECT, false, $this->language->txt('status'));
100  $ilSelectInput->setOptions([
101  self::STATUS_ALL => $this->language->txt('etal_status_all'),
102  self::STATUS_PENDING => $this->language->txt('etal_status_pending'),
103  self::STATUS_COMPLETED => $this->language->txt('etal_status_completed')
104  ]);
105  }
106 
107  private function addColumns(): void
108  {
109  $this->addColumn(
110  $this->language->txt('title'),
111  "etal_title",
112  "auto"
113  );
114  $this->addColumn(
115  $this->language->txt('type'),
116  "etal_template",
117  "auto"
118  );
119  $this->addColumn(
120  $this->language->txt('date_of_talk'),
121  "etal_date",
122  "auto"
123  );
124  $this->addColumn(
125  $this->language->txt('superior'),
126  "etal_superior",
127  "auto"
128  );
129  $this->addColumn(
130  $this->language->txt('employee'),
131  "etal_employee",
132  "auto"
133  );
134  $this->addColumn(
135  $this->language->txt('status'),
136  "etal_status",
137  "auto"
138  );
139  $this->addColumn(
140  $this->language->txt('action'),
141  "",
142  "auto"
143  );
144 
145  $this->setDefaultFilterVisiblity(true);
146  $this->setDefaultOrderField("etal_date");
147  }
148 
149  protected function fillRow($a_set): void
150  {
151  $talk_class = strtolower(ilObjEmployeeTalkGUI::class);
152  $class_path = $this->getParentObject()->getClassPath();
153  $class_path[] = $talk_class;
154 
155  $ref_id = $a_set['ref_id'];
156  $this->ctrl->setParameterByClass($talk_class, 'ref_id', $ref_id);
157  $url = $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::DEFAULT);
158 
159  $buttons = [];
160  if ($this->talk_access->canEdit($ref_id)) {
161  $buttons[] = $this->ui_factory->link()->standard(
162  $this->language->txt('edit'),
163  $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::UPDATE)
164  );
165  } else {
166  $buttons[] = $this->ui_factory->link()->standard(
167  $this->language->txt('view'),
168  $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::INDEX)
169  );
170  }
171 
172  if ($this->talk_access->canDelete($ref_id)) {
173  $modal = $this->getConfirmationModal(
174  $a_set['etal_title'],
175  $ref_id,
176  $this->ctrl->getLinkTargetByClass($class_path, ControlFlowCommand::DELETE)
177  );
178  $buttons[] = $this->ui_factory->button()->shy(
179  $this->language->txt('delete'),
180  ''
181  )->withOnClick($modal->getShowSignal());
182  $this->delete_modals[] = $modal;
183  }
184  $this->ctrl->clearParametersByClass($talk_class);
185  $actions = $this->ui_factory->dropdown()->standard($buttons)->withLabel(
186  $this->language->txt('actions')
187  );
188 
189  $this->tpl->setVariable("HREF_ETAL_TITLE", $url);
190  $this->tpl->setVariable("VAL_ETAL_TITLE", $a_set['etal_title']);
191  $this->tpl->setVariable("VAL_ETAL_TEMPLATE", $a_set['etal_template']);
192  $this->tpl->setVariable("VAL_ETAL_DATE", ilDatePresentation::formatDate($a_set['etal_date']));
193  $this->tpl->setVariable("VAL_ETAL_SUPERIOR", $a_set['etal_superior']);
194  $this->tpl->setVariable("VAL_ETAL_EMPLOYEE", $a_set['etal_employee']);
195  $this->tpl->setVariable("VAL_ETAL_STATUS", $a_set['etal_status']);
196  $this->tpl->setVariable("ACTIONS", $this->ui_renderer->render($actions));
197  }
198 
199  public function setTalkData(array $talks): void
200  {
201  $filter = $this->getCurrentState()['filter_values'];
202 
203  $data = [];
204  foreach ($talks as $val) {
205  if (!ilObject::_hasUntrashedReference($val->getObjectId())) {
206  continue;
207  }
208 
209  if (trim($filter['etal_employee']) !== "") {
210  $filterUser = ilObjUser::getUserIdByLogin(trim($filter['etal_employee']));
211  if ($val->getEmployee() !== $filterUser) {
212  continue;
213  }
214  }
215 
216  $refIds = ilObjEmployeeTalk::_getAllReferences($val->getObjectId());
217  $talk = new ilObjEmployeeTalk(array_pop($refIds), true);
218  $talkData = $talk->getData();
219  $employeeName = $this->language->txt('etal_unknown_username');
220  $superiorName = $this->language->txt('etal_unknown_username');
221  $ownerId = $talk->getOwner();
222  if (ilObjUser::_exists($talk->getOwner())) {
223  $superiorName = ilObjUser::_lookupLogin($ownerId);
224  }
225  if (ilObjUser::_exists($talkData->getEmployee())) {
226  $employeeName = ilObjUser::_lookupLogin($talkData->getEmployee());
227  }
228 
229  if (trim($filter['etal_superior']) !== "") {
230  $filterUser = ilObjUser::getUserIdByLogin(trim($filter['etal_superior']));
231  if ($talk->getOwner() !== $filterUser) {
232  continue;
233  }
234  }
235 
236  if (trim($filter['etal_title']) !== "") {
237  if (strpos(strtolower($talk->getTitle()), strtolower(trim($filter['etal_title']))) === false) {
238  continue;
239  }
240  }
241 
242  if ($filter['etal_date'] !== false && $filter['etal_date'] !== null && $filter['etal_date'] !== '') {
243  $filterDate = new ilDateTime($filter['etal_date'], IL_CAL_DATE);
244  if (
245  !ilDateTime::_equals($filterDate, $val->getStartDate(), IL_CAL_DAY)
246  ) {
247  continue;
248  }
249  }
250  if ($filter['etal_status'] !== "" && intval($filter['etal_status'] !== 0)) {
251  $filterCompleted = intval($filter['etal_status']) === ilEmployeeTalkTableGUI::STATUS_COMPLETED;
252  if ($filterCompleted && !$val->isCompleted()) {
253  continue;
254  }
255 
256  if (!$filterCompleted && $val->isCompleted()) {
257  continue;
258  }
259  }
260 
261  $template_title = '';
262  if ($talkData->getTemplateId() > 0 && ilObject::_exists($talkData->getTemplateId())) {
263  $template = ilObjectFactory::getInstanceByObjId($talkData->getTemplateId());
264  $template_title = $template->getTitle();
265  }
266  if (trim($filter['etal_template']) !== "") {
267  if (strpos(strtolower($template_title), strtolower(trim($filter['etal_template']))) === false) {
268  continue;
269  }
270  }
271 
272  $data[] = [
273  "ref_id" => $talk->getRefId(),
274  "etal_title" => $talk->getTitle(),
275  "etal_template" => $template_title,
276  "etal_date" => $talkData->getStartDate(),
277  "etal_superior" => $superiorName,
278  "etal_employee" => $employeeName,
279  "etal_status" => $talkData->isCompleted() ? $this->language->txt('etal_status_completed') : $this->language->txt('etal_status_pending'),
280  "permission_write" => false,
281  "permission_delete" => false
282  ];
283  }
284 
285  $offset = $this->getOffset();
286  $limit = $this->getLimit();
287 
288  $this->setMaxCount(count($data));
289 
290  $dataSlice = array_slice($data, $offset, $limit, true);
291  $this->setData($dataSlice);
292  }
293 
294  protected function getConfirmationModal(
295  string $talk_title,
296  int $talk_ref_id,
297  string $action
298  ): InterruptiveModal {
299  $item = $this->ui_factory->modal()->interruptiveItem()->standard(
300  (string) $talk_ref_id,
301  $talk_title
302  );
303 
304  return $this->ui_factory->modal()->interruptive(
305  $this->language->txt('confirm'),
306  $this->language->txt('etal_delete_confirmation_msg'),
307  $action
308  )->withAffectedItems([$item]);
309  }
310 
311  public function getHTML(): string
312  {
313  return parent::getHTML() . $this->ui_renderer->render($this->delete_modals);
314  }
315 }
setData(array $a_data)
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
static _getAllReferences(int $id)
get all reference ids for object ID
setDisableFilterHiding(bool $a_val=true)
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
$url
Definition: shib_logout.php:66
setFormName(string $a_name="")
setId(string $a_val)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getUserIdByLogin(string $a_login)
const IL_CAL_DAY
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
$ref_id
Definition: ltiauth.php:65
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:22
getConfirmationModal(string $talk_title, int $talk_ref_id, string $action)
setDefaultOrderDirection(string $a_defaultorderdirection)
ilObjEmployeeTalkAccess $talk_access
array $delete_modals
InterruptiveModal[].
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const IL_CAL_DATE
setEnableNumInfo(bool $a_val)
__construct(Container $dic, ilPlugin $plugin)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
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)
getCurrentState()
get current settings for order, limit, columns and filter
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
__construct(ControlFlowCommandHandler $a_parent_obj, $a_parent_cmd='')
setDefaultFilterVisiblity(bool $a_status)
determineOffsetAndOrder(bool $a_omit_offset=false)
setMaxCount(int $a_max_count)
set max.
setFilterCols(int $a_val)
setExternalSegmentation(bool $a_val)
static _lookupLogin(int $a_user_id)
setPrefix(string $a_prefix)