ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceAcceptanceHistoryTableGUI.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
6 
12 {
14  protected $uiFactory;
15 
17  protected $uiRenderer;
18 
20  protected $numRenderedCriteria = 0;
21 
24 
34  public function __construct(
36  string $command,
40  ilGlobalPageTemplate $globalTemplate
41  ) {
42  $this->criterionTypeFactory = $criterionTypeFactory;
43  $this->uiFactory = $uiFactory;
44  $this->uiRenderer = $uiRenderer;
45 
46  $this->setId('tos_acceptance_history');
47  $this->setFormName('tos_acceptance_history');
48 
49  parent::__construct($controller, $command);
50 
51  $this->setTitle($this->lng->txt('tos_acceptance_history'));
52  $this->setFormAction($this->ctrl->getFormAction($controller, 'applyAcceptanceHistoryFilter'));
53 
54  $this->setDefaultOrderDirection('DESC');
55  $this->setDefaultOrderField('ts');
56  $this->setExternalSorting(true);
57  $this->setExternalSegmentation(true);
58 
59  iljQueryUtil::initjQuery($globalTemplate);
60  ilYuiUtil::initPanel($globalTemplate);
61  ilYuiUtil::initOverlay($globalTemplate);
62  $globalTemplate->addJavaScript("./Services/Form/js/Form.js");
63 
64  $this->setShowRowsSelector(true);
65 
66  $this->setRowTemplate('tpl.tos_acceptance_history_table_row.html', 'Services/TermsOfService');
67 
68  $this->initFilter();
69  $this->setFilterCommand('applyAcceptanceHistoryFilter');
70  $this->setResetCommand('resetAcceptanceHistoryFilter');
71  }
72 
76  protected function getColumnDefinition() : array
77  {
78  $i = 0;
79 
80  return [
81  ++$i => [
82  'field' => 'ts',
83  'txt' => $this->lng->txt('tos_tbl_hist_head_acceptance_date'),
84  'default' => true,
85  'optional' => false,
86  'sortable' => true
87  ],
88  ++$i => [
89  'field' => 'login',
90  'txt' => $this->lng->txt('tos_tbl_hist_head_login'),
91  'default' => true,
92  'optional' => false,
93  'sortable' => true
94  ],
95  ++$i => [
96  'field' => 'firstname',
97  'txt' => $this->lng->txt('tos_tbl_hist_head_firstname'),
98  'default' => false,
99  'optional' => true,
100  'sortable' => true
101  ],
102  ++$i => [
103  'field' => 'lastname',
104  'txt' => $this->lng->txt('tos_tbl_hist_head_lastname'),
105  'default' => false,
106  'optional' => true,
107  'sortable' => true
108  ],
109  ++$i => [
110  'field' => 'title',
111  'txt' => $this->lng->txt('tos_tbl_hist_head_document'),
112  'default' => true,
113  'optional' => false,
114  'sortable' => true
115  ],
116  ++$i => [
117  'field' => 'criteria',
118  'txt' => $this->lng->txt('tos_tbl_hist_head_criteria'),
119  'default' => false,
120  'optional' => true,
121  'sortable' => false
122  ],
123  ];
124  }
125 
132  protected function formatCellValue(string $column, array $row) : string
133  {
134  if ('ts' === $column) {
135  return \ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX));
136  } elseif ('title' === $column) {
137  return $this->formatTitle($column, $row);
138  } elseif ('criteria' === $column) {
139  return $this->formatCriterionAssignments($column, $row);
140  }
141 
142  return parent::formatCellValue($column, $row);
143  }
144 
148  protected function getUniqueCriterionListingAttribute() : string
149  {
150  return '<span class="ilNoDisplay">' . ($this->numRenderedCriteria++) . '</span>';
151  }
152 
160  protected function formatCriterionAssignments(string $column, array $row) : string
161  {
162  $items = [];
163 
164  $criteria = new ilTermsOfServiceAcceptanceHistoryCriteriaBag($row['criteria']);
165 
166  if (0 === count($criteria)) {
167  return $this->lng->txt('tos_tbl_hist_cell_not_criterion');
168  }
169 
170  foreach ($criteria as $criterion) {
171  $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion['id'], true);
172  $typeGui = $criterionType->ui($this->lng);
173 
174  $items[$typeGui->getIdentPresentation() .
175  $this->getUniqueCriterionListingAttribute()] = $typeGui->getValuePresentation(
176  new ilTermsOfServiceCriterionConfig($criterion['value']),
177  $this->uiFactory
178  );
179  }
180 
181  $criteriaList = $this->uiFactory
182  ->listing()
183  ->descriptive($items);
184 
185  return $this->uiRenderer->render([
186  $criteriaList
187  ]);
188  }
189 
195  protected function formatTitle(string $column, array $row) : string
196  {
197  $modal = $this->uiFactory
198  ->modal()
199  ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row['text'], $row['title'])]);
200 
201  $titleLink = $this->uiFactory
202  ->button()
203  ->shy($row[$column], '#')
204  ->withOnClick($modal->getShowSignal());
205 
206  return $this->uiRenderer->render([$titleLink, $modal]);
207  }
208 
212  public function numericOrdering($column)
213  {
214  if ('ts' === $column) {
215  return true;
216  }
217 
218  return false;
219  }
220 
224  public function initFilter()
225  {
226  $ul = new ilTextInputGUI(
227  $this->lng->txt('login') . '/' . $this->lng->txt('email') . '/' . $this->lng->txt('name'),
228  'query'
229  );
230  $ul->setDataSource($this->ctrl->getLinkTarget($this->getParentObject(), 'addUserAutoComplete', '', true));
231  $ul->setSize(20);
232  $ul->setSubmitFormOnEnter(true);
233  $this->addFilterItem($ul);
234  $ul->readFromSession();
235  $this->filter['query'] = $ul->getValue();
236 
237  $duration = new ilDateDurationInputGUI($this->lng->txt('tos_period'), 'period');
238  $duration->setAllowOpenIntervals(true);
239  $duration->setShowTime(true);
240  $duration->setStartText($this->lng->txt('tos_period_from'));
241  $duration->setEndText($this->lng->txt('tos_period_until'));
242  $duration->setStart(new \ilDateTime(null, IL_CAL_UNIX));
243  $duration->setEnd(new \ilDateTime(null, IL_CAL_UNIX));
244  $this->addFilterItem($duration, true);
245  $duration->readFromSession();
246  $this->optional_filter['period'] = $duration->getValue();
247  }
248 }
addJavaScript($a_js_file, $a_add_version_parameter=true, $a_batch=2)
An entity that renders components to a string output.
Definition: Renderer.php:14
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setAllowOpenIntervals(bool $allowOpenInterval)
Interface ilTermsOfServiceControllerEnabled.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
const IL_CAL_UNIX
static initPanel($a_resize=false, ilGlobalTemplateInterface $a_main_tpl=null)
Init yui panel.
Class ilTermsOfServiceCriterionConfig.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
input GUI for a time span (start and end date)
Class ilGlobalPageTemplate.
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
This is how the factory for UI elements looks.
Definition: Factory.php:17
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static initOverlay(ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Overlay module.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
setFormName($a_formname="")
Set Form name.
__construct(Container $dic, ilPlugin $plugin)
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
__construct(ilTermsOfServiceControllerEnabled $controller, string $command, ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, Factory $uiFactory, Renderer $uiRenderer, ilGlobalPageTemplate $globalTemplate)
ilTermsOfServiceAcceptanceHistoryTableGUI constructor.
$i
Definition: metadata.php:24
setFilterCommand($a_val, $a_caption=null)
Set filter command.