ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDCopyrightTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
31 {
34  protected ilDBInterface $db;
37 
38  protected bool $has_write;
39 
45  protected array $edit_modal_signals = [];
46 
47  public function __construct(
48  RepositoryInterface $repository,
49  RendererInterface $renderer,
51  string $parent_cmd = '',
52  bool $has_write = false
53  ) {
54  global $DIC;
55 
56  $this->ui_factory = $DIC->ui()->factory();
57  $this->ui_renderer = $DIC->ui()->renderer();
58  $this->db = $DIC->database();
59  $this->repository = $repository;
60  $this->renderer = $renderer;
61 
62  $this->has_write = $has_write;
63 
64  parent::__construct($parent_obj, $parent_cmd);
65 
66  if ($this->has_write) {
67  $this->addColumn('', 'f', '1');
68  $this->addColumn($this->lng->txt("position"), "order");
69  $this->addCommandButton("saveCopyrightPosition", $this->lng->txt("meta_save_order"));
70  }
71  $this->addColumn($this->lng->txt('title'), 'title', "30%");
72  $this->addColumn($this->lng->txt('md_used'), 'used', "5%");
73  $this->addColumn($this->lng->txt('md_copyright_preview'), 'preview', "50%");
74  $this->addColumn($this->lng->txt('meta_copyright_status'), 'status', "10%");
75 
76  if ($this->has_write) {
77  $this->addColumn('', 'edit', "10%");
78  }
79 
80  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
81  $this->setRowTemplate("tpl.show_copyright_row.html", "components/ILIAS/MetaData");
82  $this->setDefaultOrderField("order");
83  $this->setDefaultOrderDirection("asc");
84  }
85 
86  protected function fillRow(array $a_set): void
87  {
88  if ($this->has_write) {
89  if ($a_set['default']) {
90  $this->tpl->setVariable('DISABLED', "disabled");
91  }
92  $this->tpl->setVariable('VAL_ID', $a_set['id']);
93 
94  // order
95  $this->tpl->setCurrentBlock('order_by_position');
96  if ($a_set['default']) {
97  $this->tpl->setVariable('ORDER_DISABLED', 'disabled="disabled"');
98  }
99  $this->tpl->setVariable('ORDER_ID', $a_set['id']);
100  $this->tpl->setVariable('ORDER_VALUE', $a_set['position']);
101  $this->tpl->parseCurrentBlock();
102  }
103  $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
104  if ($a_set['description'] !== '') {
105  $this->tpl->setVariable('VAL_DESCRIPTION', $a_set['description']);
106  }
107  $this->tpl->setVariable('VAL_USAGE', $a_set['used']);
108  $this->tpl->setVariable('VAL_PREVIEW', $a_set['preview']);
109 
110  $status = [];
111  if ($a_set['status']) {
112  $status[] = $this->lng->txt('meta_copyright_outdated');
113  } else {
114  $status[] = $this->lng->txt('meta_copyright_in_use');
115  }
116  if ($a_set['default']) {
117  $status[] = $this->lng->txt('md_copyright_default');
118  }
119 
120  $this->tpl->setVariable('VAL_STATUS', implode(', ', $status));
121 
122  if ($this->has_write) {
123  $this->tpl->setVariable('ACTIONS', $this->getActionsForEntry(
124  (int) $a_set['id'],
125  (int) $a_set['used'] > 0
126  ));
127  }
128  }
129 
130  public function setEditModalSignal(int $entry_id, Signal $signal): void
131  {
132  $this->edit_modal_signals[$entry_id] = $signal;
133  }
134 
135  public function parseSelections(): void
136  {
137  // These entries are ordered by 1. is_default, 2. position
138  $entries = $this->repository->getAllEntries();
139 
140  $position = -10;
141  $entry_arr = [];
142  foreach ($entries as $entry) {
143  $tmp_arr['id'] = $entry->id();
144  $tmp_arr['title'] = $entry->title();
145  $tmp_arr['description'] = $entry->description();
146  $tmp_arr['used'] = $this->countUsagesForEntry($entry->id());
147  $tmp_arr['preview'] = $this->ui_renderer->render(
148  $this->renderer->toUIComponents($entry->copyrightData())
149  );
150  $tmp_arr['default'] = $entry->isDefault();
151  $tmp_arr['status'] = $entry->isOutdated();
152  $tmp_arr['position'] = ($position += 10);
153 
154  $entry_arr[] = $tmp_arr;
155  }
156 
157  $this->setData($entry_arr);
158  }
159 
160  protected function getActionsForEntry(int $id, bool $with_usages): string
161  {
162  $buttons = [];
163 
164  $buttons[] = $this->ui_factory->button()->shy(
165  $this->lng->txt('edit'),
166  $this->edit_modal_signals[$id]
167  );
168 
169  if ($with_usages) {
170  $this->ctrl->setParameterByClass(
171  ilMDCopyrightUsageGUI::class,
172  'entry_id',
173  $id
174  );
175  $usage_link = $this->ctrl->getLinkTargetByClass(
176  'ilMDCopyrightUsageGUI',
177  ''
178  );
179  $this->ctrl->clearParametersByClass(ilMDCopyrightUsageGUI::class);
180  $buttons[] = $this->ui_factory->button()->shy(
181  $this->lng->txt('meta_copyright_show_usages'),
182  $usage_link
183  );
184  }
185 
186  $actions = $this->ui_factory
187  ->dropdown()
188  ->standard($buttons)
189  ->withLabel($this->lng->txt('actions'));
190  return $this->ui_renderer->render($actions);
191  }
192 
193  private function countUsagesForEntry(int $entry_id): int
194  {
195  $query = "SELECT count(meta_rights_id) used FROM il_meta_rights " .
196  "WHERE description = " . $this->db->quote(
197  'il_copyright_entry__' . IL_INST_ID . '__' . $entry_id,
198  'text'
199  );
200 
201  $res = $this->db->query($query);
202  $row = $this->db->fetchObject($res);
203  return (int) $row->used;
204  }
205 }
setData(array $a_data)
$res
Definition: ltiservices.php:66
setEditModalSignal(int $entry_id, Signal $signal)
const IL_INST_ID
Definition: constants.php:40
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="")
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
renderer()
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:22
setDefaultOrderDirection(string $a_defaultorderdirection)
getActionsForEntry(int $id, bool $with_usages)
__construct(RepositoryInterface $repository, RendererInterface $renderer, ilMDCopyrightConfigurationGUI $parent_obj, string $parent_cmd='', bool $has_write=false)
__construct(Container $dic, ilPlugin $plugin)
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)
ilMDCopyrightConfigurationGUI: ilMDCopyrightUsageGUI, ilMDCopyrightImageUploadHandlerGUI ...