ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
EditableDocumentTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use Closure;
31 
32 class EditableDocumentTable implements Table
33 {
34  public function __construct(
35  private readonly DocumentTable $table,
36  private readonly EditLinks $edit_links
37  ) {
38  }
39 
40  public function columns(): array
41  {
42  return [
43  'delete' => [' ', '', '1%', true],
44  ...$this->table->columns(),
45  'actions' => [$this->table->ui()->txt('actions'), '', '10%'],
46  ];
47  }
48 
49  public function config(TableConfig $config): void
50  {
51  $config->addMultiCommand('deleteDocuments', $this->table->ui()->txt('delete'));
52  $config->addCommandButton('saveOrder', $this->table->ui()->txt('sorting_save'));
53  $this->table->config($config);
54  }
55 
56  public function rows(TableSelection $select): array
57  {
58  return $this->table->mapSelection($this->row(...), $select);
59  }
60 
61  public function row(Document $document, int $sorting): array
62  {
63  $link = $this->table->ui()->create()->link()->standard(...);
64 
65  return [
66  'delete' => fn() => ilLegacyFormElementsUtil::formCheckbox(false, 'ids[]', (string) $document->id()),
67  'order' => $this->orderInputGui($document, $sorting),
68  ...array_slice($this->table->row($document, $sorting), 1),
69  'criteria' => $this->table->showCriteria($document, $this->willShowCriterion($document)),
70  'actions' => $this->table->ui()->create()->dropdown()->standard([
71  $link($this->table->ui()->txt('edit'), $this->edit_links->editDocument($document)),
72  $link($this->table->ui()->txt('tbl_docs_action_add_criterion'), $this->edit_links->addCriterion($document)),
73  $link($this->table->ui()->txt('delete'), $this->edit_links->deleteDocument($document)),
74  ]),
75  ];
76  }
77 
78  public function name(): string
79  {
80  return self::class;
81  }
82 
83  private function willShowCriterion(Document $document): Closure
84  {
85  return function (Criterion $criterion) use ($document) {
86  $modal = $this->table->ui()->create()->modal()->interruptive(
87  $this->table->ui()->txt('doc_detach_crit_confirm_title'),
88  $this->table->ui()->txt('doc_sure_detach_crit'),
89  $this->edit_links->deleteCriterion($document, $criterion)
90  );
91 
92  return [
93  $this->table->ui()->create()->legacy('<div style="display: flex">'),
94  $this->table->criterionName($criterion),
95  $this->table->ui()->create()->legacy('&nbsp;'),
96  $modal,
97  $this->table->ui()->create()->dropdown()->standard([
98  $this->table->ui()->create()->link()->standard($this->table->ui()->txt('edit'), $this->edit_links->editCriterion($document, $criterion)),
99  $this->table->ui()->create()->button()->shy($this->table->ui()->txt('delete'), '')->withOnClick($modal->getShowSignal()),
100  ]),
101  $this->table->ui()->create()->legacy('</div>'),
102  ];
103  };
104  }
105 
106  private function orderInputGui(Document $document, int $step): Closure
107  {
108  $input = $this->table->orderInputGui($document, $step);
109  $input->setDisabled(false);
110 
111  return $input->render(...);
112  }
113 }
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(private readonly DocumentTable $table, private readonly EditLinks $edit_links)
addMultiCommand(string $a_cmd, string $a_text)