ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMDCopyrightTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
29 {
33 
34  protected bool $has_write;
35 
41  protected array $edit_modal_signals = [];
42 
43  public function __construct(
45  string $parent_cmd = '',
46  bool $has_write = false
47  ) {
48  global $DIC;
49 
50  $this->ui_factory = $DIC->ui()->factory();
51  $this->ui_renderer = $DIC->ui()->renderer();
52  $this->modal_service = new ilMDSettingsModalService(
53  $this->ui_factory
54  );
55 
56  $this->has_write = $has_write;
57 
58  parent::__construct($parent_obj, $parent_cmd);
59 
60  if ($this->has_write) {
61  $this->addColumn('', 'f', '1');
62  $this->addColumn($this->lng->txt("position"), "order");
63  $this->addCommandButton("saveCopyrightPosition", $this->lng->txt("meta_save_order"));
64  }
65  $this->addColumn($this->lng->txt('title'), 'title', "30%");
66  $this->addColumn($this->lng->txt('md_used'), 'used', "5%");
67  $this->addColumn($this->lng->txt('md_copyright_preview'), 'preview', "50%");
68  $this->addColumn($this->lng->txt('meta_copyright_status'), 'status', "10%");
69 
70  if ($this->has_write) {
71  $this->addColumn('', 'edit', "10%");
72  }
73 
74  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
75  $this->setRowTemplate("tpl.show_copyright_row.html", "Services/MetaData");
76  $this->setDefaultOrderField("order");
77  $this->setDefaultOrderDirection("asc");
78  }
79 
80  protected function fillRow(array $a_set): void
81  {
82  if ($this->has_write) {
83  if ($a_set['default']) {
84  $this->tpl->setVariable('DISABLED', "disabled");
85  }
86  $this->tpl->setVariable('VAL_ID', $a_set['id']);
87 
88  // order
89  $this->tpl->setCurrentBlock('order_by_position');
90  if ($a_set['default']) {
91  $this->tpl->setVariable('ORDER_DISABLED', 'disabled="disabled"');
92  }
93  $this->tpl->setVariable('ORDER_ID', $a_set['id']);
94  $this->tpl->setVariable('ORDER_VALUE', $a_set['position']);
95  $this->tpl->parseCurrentBlock();
96  }
97  $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
98  if ($a_set['description'] !== '') {
99  $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
100  }
101  $this->tpl->setVariable('VAL_USAGE', $a_set['used']);
102  $this->tpl->setVariable('VAL_PREVIEW', $a_set['preview']);
103 
104  $status = [];
105  if ($a_set['status']) {
106  $status[] = $this->lng->txt('meta_copyright_outdated');
107  } else {
108  $status[] = $this->lng->txt('meta_copyright_in_use');
109  }
110  if ($a_set['default']) {
111  $status[] = $this->lng->txt('md_copyright_default');
112  }
113 
114  $this->tpl->setVariable('VAL_STATUS', implode(', ', $status));
115 
116  if ($this->has_write) {
117  $this->tpl->setVariable('ACTIONS', $this->getActionsForEntry(
118  (int) $a_set['id'],
119  (int) $a_set['used'] > 0
120  ));
121  }
122  }
123 
124  public function setEditModalSignal(int $entry_id, Signal $signal): void
125  {
126  $this->edit_modal_signals[$entry_id] = $signal;
127  }
128 
129  public function parseSelections(): void
130  {
131  // These entries are ordered by 1. is_default, 2. position
133 
134  $position = -10;
135  $entry_arr = [];
136  foreach ($entries as $entry) {
137  $tmp_arr['id'] = $entry->getEntryId();
138  $tmp_arr['title'] = $entry->getTitle();
139  $tmp_arr['description'] = $entry->getDescription();
140  $tmp_arr['used'] = $entry->getUsage();
141  $tmp_arr['preview'] = $entry->getCopyright();
142  $tmp_arr['default'] = $entry->getIsDefault();
143  $tmp_arr['status'] = $entry->getOutdated();
144  $tmp_arr['position'] = ($position += 10);
145 
146  $entry_arr[] = $tmp_arr;
147  }
148 
149  $this->setData($entry_arr);
150  }
151 
152  protected function getActionsForEntry(int $id, bool $with_usages): string
153  {
154  $buttons = [];
155 
156  $buttons[] = $this->ui_factory->button()->shy(
157  $this->lng->txt('edit'),
158  $this->edit_modal_signals[$id]
159  );
160 
161  if ($with_usages) {
162  $this->ctrl->setParameterByClass(
163  ilMDCopyrightUsageGUI::class,
164  'entry_id',
165  $id
166  );
167  $usage_link = $this->ctrl->getLinkTargetByClass(
168  'ilMDCopyrightUsageGUI',
169  ''
170  );
171  $this->ctrl->clearParametersByClass(ilMDCopyrightUsageGUI::class);
172  $buttons[] = $this->ui_factory->button()->shy(
173  $this->lng->txt('meta_copyright_show_usages'),
174  $usage_link
175  );
176  }
177 
178  $actions = $this->ui_factory
179  ->dropdown()
180  ->standard($buttons)
181  ->withLabel($this->lng->txt('actions'));
182  return $this->ui_renderer->render($actions);
183  }
184 }
setData(array $a_data)
setEditModalSignal(int $entry_id, Signal $signal)
ilMDCopyrightSelectionGUI: ilMDCopyrightUsageGUI
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(ilMDCopyrightSelectionGUI $parent_obj, string $parent_cmd='', bool $has_write=false)
global $DIC
Definition: feed.php:28
ilMDSettingsModalService $modal_service
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
getActionsForEntry(int $id, bool $with_usages)
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)