19 declare(strict_types=1);
46 bool $isEditable =
false 53 $this->
setId(
'tos_documents');
58 $this->
setTitle($this->
lng->txt(
'tos_tbl_docs_title'));
59 $this->
setFormAction($this->
ctrl->getFormAction($this->getParentObject(), $command));
67 $this->
setRowTemplate(
'tpl.tos_documents_row.html',
'Services/TermsOfService');
69 if ($this->isEditable) {
82 if ($this->isEditable) {
89 'is_checkbox' =>
true,
96 'txt' => $this->
lng->txt(
'tos_tbl_docs_head_sorting'),
105 'txt' => $this->
lng->txt(
'tos_tbl_docs_head_title'),
113 'field' =>
'creation_ts',
114 'txt' => $this->
lng->txt(
'tos_tbl_docs_head_created'),
121 'field' =>
'modification_ts',
122 'txt' => $this->
lng->txt(
'tos_tbl_docs_head_last_change'),
129 'field' =>
'criteria',
130 'txt' => $this->
lng->txt(
'tos_tbl_docs_head_criteria'),
136 if ($this->isEditable) {
138 'field' =>
'actions',
139 'txt' => $this->
lng->txt(
'actions'),
152 foreach ($data[
'items'] as
$key => $document) {
155 $data[
'items'][
$key] = [
156 'id' => $document->getId(),
157 'title' => $document->getTitle(),
158 'creation_ts' => $document->getCreationTs(),
159 'modification_ts' => $document->getModificationTs(),
160 'text' => $document->getText(),
162 'criteriaAssignments' => $document->criteria()
169 if (in_array($column, [
'creation_ts',
'modification_ts'])) {
171 } elseif (
'sorting' === $column) {
173 } elseif (
'title' === $column) {
175 } elseif (
'actions' === $column) {
177 } elseif (
'chb' === $column) {
179 } elseif (
'criteria' === $column) {
180 return $this->formatCriterionAssignments($column, $row);
183 return parent::formatCellValue($column, $row);
188 if (!$this->isEditable) {
194 $editBtn = $this->uiFactory
197 $this->
lng->txt(
'edit'),
201 $deleteModal = $this->uiFactory
204 $this->
lng->txt(
'tos_doc_delete'),
205 $this->
lng->txt(
'tos_sure_delete_documents_s'),
208 ->withActionButtonLabel(
'deleteDocument');
210 $deleteBtn = $this->uiFactory
212 ->shy($this->
lng->txt(
'delete'),
'#')
213 ->withOnClick($deleteModal->getShowSignal());
215 $this->uiComponents[] = $deleteModal;
217 $attachCriterionBtn = $this->uiFactory
220 $this->
lng->txt(
'tos_tbl_docs_action_add_criterion'),
226 $dropDown = $this->uiFactory
228 ->standard([$editBtn, $deleteBtn, $attachCriterionBtn])
229 ->withLabel($this->
lng->txt(
'actions'));
231 return $this->uiRenderer->render([$dropDown]);
234 protected function formatCriterionAssignments(
string $column, array $row):
string 238 if (0 === count($row[
'criteriaAssignments'])) {
239 return $this->
lng->txt(
'tos_tbl_docs_cell_not_criterion');
242 foreach ($row[
'criteriaAssignments'] as $criterion) {
248 $editBtn = $this->uiFactory
251 $this->
lng->txt(
'edit'),
255 $deleteModal = $this->uiFactory
258 $this->
lng->txt(
'tos_doc_detach_crit_confirm_title'),
259 $this->
lng->txt(
'tos_doc_sure_detach_crit'),
262 ->withActionButtonLabel(
'detachCriterionAssignment');
264 $deleteBtn = $this->uiFactory
266 ->shy($this->
lng->txt(
'delete'),
'#')
267 ->withOnClick($deleteModal->getShowSignal());
269 $dropDown = $this->uiFactory
271 ->standard([$editBtn, $deleteBtn]);
273 $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterion->getCriterionId(),
true);
274 $typeGui = $criterionType->ui($this->
lng);
276 $items[implode(
' ', [
277 $typeGui->getIdentPresentation(),
278 ($this->isEditable ? $this->uiRenderer->render($dropDown) :
'')
280 $this->uiFactory->legacy(
281 $this->uiRenderer->render(
282 $typeGui->getValuePresentation(
283 $criterion->getCriterionValue(),
289 if ($this->isEditable) {
290 $this->uiComponents[] = $deleteModal;
297 $criteriaList = $this->uiFactory
299 ->descriptive($items);
301 return $this->uiRenderer->render([
306 protected function formatTitle(
string $column, array $row): string
308 $modal = $this->uiFactory
310 ->lightbox([$this->uiFactory->modal()->lightboxTextPage($row[
'text'], $row[
'title'])]);
312 $titleLink = $this->uiFactory
314 ->shy($row[$column],
'#')
315 ->withOnClick($modal->getShowSignal());
317 return $this->uiRenderer->render([$titleLink, $modal]);
322 $value = ($this->i++) * $this->factor;
323 if (!$this->isEditable) {
324 return (
string) $value;
328 $sortingField->setValue((
string) $value);
329 $sortingField->setMaxLength(4);
330 $sortingField->setSize(2);
332 return $sortingField->render();
337 return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
Class ilTermsOfServiceDocumentTableGUI.
An entity that renders components to a string output.
setFormAction(string $a_form_action, bool $a_multipart=false)
formatActionsDropDown(string $column, array $row)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
Interface ilTermsOfServiceControllerEnabled.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
setFormName(string $a_name="")
formatSorting(array $row)
__construct(ilTermsOfServiceControllerEnabled $a_parent_obj, string $command, ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, Factory $uiFactory, Renderer $uiRenderer, bool $isEditable=false)
setExternalSorting(bool $a_val)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
formatCellValue(string $column, array $row)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
formatTitle(string $column, array $row)
preProcessData(array &$data)
This method can be used to process the array of all fetched data.
addMultiCommand(string $a_cmd, string $a_text)
ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory
setExternalSegmentation(bool $a_val)
Interface ilTermsOfServiceCriterionTypeFactoryInterface.