ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceAcceptanceHistoryTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
30  protected Factory $uiFactory;
31  protected Renderer $uiRenderer;
32  protected int $numRenderedCriteria = 0;
34 
35  public function __construct(
37  string $command,
39  Factory $uiFactory,
40  Renderer $uiRenderer,
41  ilGlobalTemplateInterface $globalTemplate
42  ) {
43  $this->criterionTypeFactory = $criterionTypeFactory;
44  $this->uiFactory = $uiFactory;
45  $this->uiRenderer = $uiRenderer;
46 
47  $this->setId('tos_acceptance_history');
48  $this->setFormName('tos_acceptance_history');
49 
50  parent::__construct($controller, $command);
51 
52  $this->setTitle($this->lng->txt('tos_acceptance_history'));
53  $this->setFormAction($this->ctrl->getFormAction($controller, 'applyAcceptanceHistoryFilter'));
54 
55  $this->setDefaultOrderDirection('DESC');
56  $this->setDefaultOrderField('ts');
57  $this->setExternalSorting(true);
58  $this->setExternalSegmentation(true);
59 
60  iljQueryUtil::initjQuery($globalTemplate);
61  ilYuiUtil::initPanel(false, $globalTemplate);
62  ilYuiUtil::initOverlay($globalTemplate);
63  $globalTemplate->addJavaScript('./Services/Form/js/Form.js');
64 
65  $this->setShowRowsSelector(true);
66 
67  $this->setRowTemplate('tpl.tos_acceptance_history_table_row.html', 'Services/TermsOfService');
68 
69  $this->initFilter();
70  $this->setFilterCommand('applyAcceptanceHistoryFilter');
71  $this->setResetCommand('resetAcceptanceHistoryFilter');
72  }
73 
74  protected function getColumnDefinition(): array
75  {
76  $i = 0;
77 
78  return [
79  ++$i => [
80  'field' => 'ts',
81  'txt' => $this->lng->txt('tos_tbl_hist_head_acceptance_date'),
82  'default' => true,
83  'optional' => false,
84  'sortable' => true
85  ],
86  ++$i => [
87  'field' => 'login',
88  'txt' => $this->lng->txt('tos_tbl_hist_head_login'),
89  'default' => true,
90  'optional' => false,
91  'sortable' => true
92  ],
93  ++$i => [
94  'field' => 'firstname',
95  'txt' => $this->lng->txt('tos_tbl_hist_head_firstname'),
96  'default' => false,
97  'optional' => true,
98  'sortable' => true
99  ],
100  ++$i => [
101  'field' => 'lastname',
102  'txt' => $this->lng->txt('tos_tbl_hist_head_lastname'),
103  'default' => false,
104  'optional' => true,
105  'sortable' => true
106  ],
107  ++$i => [
108  'field' => 'title',
109  'txt' => $this->lng->txt('tos_tbl_hist_head_document'),
110  'default' => true,
111  'optional' => false,
112  'sortable' => true
113  ],
114  ++$i => [
115  'field' => 'criteria',
116  'txt' => $this->lng->txt('tos_tbl_hist_head_criteria'),
117  'default' => false,
118  'optional' => true,
119  'sortable' => false
120  ],
121  ];
122  }
123 
124  protected function formatCellValue(string $column, array $row): string
125  {
126  if ('ts' === $column) {
127  return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX));
128  } elseif ('title' === $column) {
129  return $this->formatTitle($column, $row);
130  } elseif ('criteria' === $column) {
131  return $this->formatCriterionAssignments($column, $row);
132  }
133 
134  return parent::formatCellValue($column, $row);
135  }
136 
137  protected function getUniqueCriterionListingAttribute(): string
138  {
139  return '<span class="ilNoDisplay">' . ($this->numRenderedCriteria++) . '</span>';
140  }
141 
142  protected function formatCriterionAssignments(string $column, array $row): string
143  {
144  $items = [];
145 
146  $criteria = new ilTermsOfServiceAcceptanceHistoryCriteriaBag($row['criteria']);
147 
148  if (0 === count($criteria)) {
149  return $this->lng->txt('tos_tbl_hist_cell_not_criterion');
150  }
151 
152  foreach ($criteria as $criterion) {
153  $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion['id'], true);
154  $typeGui = $criterionType->ui($this->lng);
155 
156  $items[$typeGui->getIdentPresentation() .
157  $this->getUniqueCriterionListingAttribute()] = $typeGui->getValuePresentation(
158  new ilTermsOfServiceCriterionConfig($criterion['value']),
159  $this->uiFactory
160  );
161  }
162 
163  $criteriaList = $this->uiFactory
164  ->listing()
165  ->descriptive($items);
166 
167  return $this->uiRenderer->render([
168  $criteriaList
169  ]);
170  }
171 
172  protected function formatTitle(string $column, array $row): string
173  {
174  $modal = $this->uiFactory
175  ->modal()
176  ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
177 
178  $titleLink = $this->uiFactory
179  ->button()
180  ->shy($row[$column], '#')
181  ->withOnClick($modal->getShowSignal());
182 
183  return $this->uiRenderer->render([$titleLink, $modal]);
184  }
185 
186  public function numericOrdering(string $a_field): bool
187  {
188  return 'ts' === $a_field;
189  }
190 
191  public function initFilter(): void
192  {
193  $ul = new ilTextInputGUI(
194  $this->lng->txt('login') . '/' . $this->lng->txt('email') . '/' . $this->lng->txt('name'),
195  'query'
196  );
197  $ul->setDataSource($this->ctrl->getLinkTarget($this->getParentObject(), 'addUserAutoComplete', '', true));
198  $ul->setSize(20);
199  $ul->setSubmitFormOnEnter(true);
200  $this->addFilterItem($ul);
201  $ul->readFromSession();
202  $this->filter['query'] = $ul->getValue();
203 
204  $duration = new ilDateDurationInputGUI($this->lng->txt('tos_period'), 'period');
205  $duration->setAllowOpenIntervals(true);
206  $duration->setShowTime(true);
207  $duration->setStartText($this->lng->txt('tos_period_from'));
208  $duration->setEndText($this->lng->txt('tos_period_until'));
209  $duration->setStart(new ilDateTime(null, IL_CAL_UNIX));
210  $duration->setEnd(new ilDateTime(null, IL_CAL_UNIX));
211  $this->addFilterItem($duration, true);
212  $duration->readFromSession();
213  $this->optional_filter['period'] = $duration->getValue();
214  }
215 }
An entity that renders components to a string output.
Definition: Renderer.php:30
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
__construct(ilTermsOfServiceControllerEnabled $controller, string $command, ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, Factory $uiFactory, Renderer $uiRenderer, ilGlobalTemplateInterface $globalTemplate)
setAllowOpenIntervals(bool $allowOpenInterval)
setResetCommand(string $a_val, string $a_caption="")
Interface ilTermsOfServiceControllerEnabled.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
setFormName(string $a_name="")
Class ilTermsOfServiceCriterionConfig.
setId(string $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setExternalSorting(bool $a_val)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
setDefaultOrderDirection(string $a_defaultorderdirection)
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
__construct(Container $dic, ilPlugin $plugin)
static initPanel(bool $a_resize=false, ?ilGlobalTemplateInterface $a_main_tpl=null)
Init yui panel used in Modules/Test, Services/TermsOfService (Jan 2022)
$i
Definition: metadata.php:41
static initOverlay(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Overlay module used in Modules/Test, Services/TermsOfService, Services/Tracking, Services/UIComponent.
setExternalSegmentation(bool $a_val)