ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaPoolPageGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected \ILIAS\Style\Content\GUIService $cs_gui;
31 protected ilTabsGUI $tabs;
32 protected ?ilObjMediaPoolGUI $pool_gui = null;
33 protected ?ilObjMediaPool $pool = null;
34
35 public function __construct(
36 int $a_id = 0,
37 int $a_old_nr = 0,
38 bool $a_prevent_get_id = false,
39 string $a_lang = ""
40 ) {
41 global $DIC;
42
43 $this->tpl = $DIC["tpl"];
44 $this->ctrl = $DIC->ctrl();
45 $this->tabs = $DIC->tabs();
46 $this->access = $DIC->access();
47 $this->lng = $DIC->language();
48
49 if (in_array($this->ctrl->getCmd(), ["createMediaPoolPage", "saveMediaPoolPage", "cancelSaveNewMediaPoolPage"])) {
50 $a_id = 0;
51 }
52
53 parent::__construct("mep", $a_id, $a_old_nr, $a_prevent_get_id, $a_lang);
54
55 $cs = $DIC->contentStyle()
56 ->domain()
57 ->styleForObjId($this->getPageObject()->getParentId());
58 $this->setStyleId($cs->getEffectiveStyleId());
59 $this->cs_gui = $DIC->contentStyle()->gui();
60
61 $this->setEditPreview(true);
62 $this->mep_request = $DIC->mediaPool()
63 ->internal()
64 ->gui()
65 ->standardRequest();
66 }
67
68 public function setMediaPoolPage(
69 ilMediaPoolPage $a_media_pool_page
70 ): void {
71 $this->setPageObject($a_media_pool_page);
72 }
73
74 public function getMediaPoolPage(): ilMediaPoolPage
75 {
77 $p = $this->getPageObject();
78 return $p;
79 }
80
81 public function setPoolGUI(ilObjMediaPoolGUI $pool_gui): void
82 {
83 $this->pool_gui = $pool_gui;
85 $pool = $pool_gui->getObject();
86 $this->pool = $pool;
87
88 $this->getMediaPoolPage()->setPool($this->pool);
89
90 $this->activateMetaDataEditor(
91 $this->pool,
92 "mpg",
93 $this->getId(),
94 $this->getMediaPoolPage(),
95 "MDUpdateListener"
96 );
97 }
98
99 public function showPage(
100 bool $a_no_title = false
101 ): string {
102 $tpl = $this->tpl;
103
104 // get raw page content is used for including into other pages
105 if (!$this->getRawPageContent()) {
106 $this->cs_gui->addCss($tpl, $this->requested_ref_id);
107 }
108
109 $this->setTemplateOutput(false);
110 if (!$a_no_title) {
111 $this->setPresentationTitle(ilMediaPoolItem::lookupTitle($this->getMediaPoolPage()->getId()));
112 }
113
114 return parent::showPage();
115 }
116
117 public function getTabs(string $a_activate = ""): void
118 {
119 $this->setMediaPoolPageTabs();
120 }
121
122 public function getRawContent(): string
123 {
124 $this->setRawPageContent(true);
125 $this->setLinkXml("");
126 return $this->showPage(true);
127 }
128
129 public function setTemplate(ilGlobalTemplateInterface $tpl): void
130 {
131 $this->tpl = $tpl;
132 }
133
134 public function createMediaPoolPage(): void
135 {
136 $tpl = $this->tpl;
137
138 $form = $this->initMediaPoolPageForm("create");
139 $tpl->setContent($form->getHTML());
140 $this->tabs->clearTargets();
141 }
142
143 public function editMediaPoolPage(): void
144 {
145 $tpl = $this->tpl;
146 $form = $this->initMediaPoolPageForm("edit");
147 $this->getMediaPoolPageValues($form);
148 $tpl->setContent($form->getHTML());
149 }
150
151 public function saveMediaPoolPage(): void
152 {
153 $tpl = $this->tpl;
155 $ilCtrl = $this->ctrl;
156
157 $form = $this->initMediaPoolPageForm("create");
158 if ($form->checkInput()) {
159 // create media pool item
160 $item = new ilMediaPoolItem();
161 $item->setTitle($form->getInput("title"));
162 $item->setType("pg");
163 $item->create();
164
165 if ($item->getId() > 0) {
166 // put in tree
167 $tree = $this->pool->getTree();
168 $parent = $this->mep_request->getItemId() > 0
169 ? $this->mep_request->getItemId()
170 : $tree->getRootId();
171 $this->pool->insertInTree($item->getId(), $parent);
172
173 // create page
174 $page = new ilMediaPoolPage();
175 $page->setId($item->getId());
176 $page->setParentId($this->pool->getId());
177 $page->create();
178 $page->createMetaData($this->pool->getId());
179
180 $ilCtrl->setParameterByClass("ilmediapoolpagegui", "mepitem_id", $item->getId());
181 $ilCtrl->redirectByClass("ilmediapoolpagegui", "edit");
182 }
183 $ilCtrl->returnToParent($this);
184 }
185
186 $form->setValuesByPost();
187 $tpl->setContent($form->getHtml());
188 }
189
190 public function updateMediaPoolPage(): void
191 {
193 $ilCtrl = $this->ctrl;
194 $tpl = $this->tpl;
195
196 $form = $this->initMediaPoolPageForm("edit");
197 if ($form->checkInput()) {
198 $item = new ilMediaPoolItem($this->mep_request->getItemId());
199 $item->setTitle($form->getInput("title"));
200 $item->update();
201 $this->getMediaPoolPage()->updateMetaData();
202 $tpl->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
203 $ilCtrl->redirect($this, "editMediaPoolPage");
204 }
205
206 $form->setValuesByPost();
207 $tpl->setContent($form->getHtml());
208 }
209
210 public function initMediaPoolPageForm(string $a_mode = "edit"): ilPropertyFormGUI
211 {
213 $ilCtrl = $this->ctrl;
214
215 $form = new ilPropertyFormGUI();
216
217 // title
218 $ti = new ilTextInputGUI($lng->txt("title"), "title");
219 $ti->setMaxLength(128);
220 $ti->setRequired(true);
221 $form->addItem($ti);
222
223 // save and cancel commands
224 if ($a_mode === "create") {
225 $form->addCommandButton("saveMediaPoolPage", $lng->txt("save"));
226 $form->addCommandButton("cancelSaveNewMediaPoolPage", $lng->txt("cancel"));
227 $form->setTitle($lng->txt("mep_new_content_snippet"));
228 } else {
229 $form->addCommandButton("updateMediaPoolPage", $lng->txt("save"));
230 $form->setTitle($lng->txt("mep_edit_content_snippet"));
231 }
232
233 $form->setFormAction($ilCtrl->getFormAction($this));
234
235 return $form;
236 }
237
238 protected function cancelSaveNewMediaPoolPage(): void
239 {
240 $ctrl = $this->ctrl;
241 $ctrl->returnToParent($this);
242 }
243
244 public function getMediaPoolPageValues(ilPropertyFormGUI $form): void
245 {
246 $values = array();
247
248 $values["title"] = ilMediaPoolItem::lookupTitle($this->mep_request->getItemId());
249
250 $form->setValuesByArray($values);
251 }
252
253 public function setMediaPoolPageTabs(): void
254 {
255 $ilTabs = $this->tabs;
256 $ilCtrl = $this->ctrl;
258
259 if ($this->use_meta_data) {
260 $mdgui = new ilObjectMetaDataGUI(
261 $this->meta_data_rep_obj,
262 $this->meta_data_type,
263 $this->meta_data_sub_obj_id
264 );
265 $mdtab = $mdgui->getTab();
266 if ($mdtab) {
267 $this->tabs_gui->addTarget(
268 "meta_data",
269 $mdtab,
270 "",
271 "ilobjectmetadatagui"
272 );
273 }
274 }
275
276 $ilTabs->addTarget(
277 "cont_usage",
278 $ilCtrl->getLinkTarget($this, "showMediaPoolPageUsages"),
279 array("showMediaPoolPageUsages", "showAllMediaPoolPageUsages"),
280 get_class($this)
281 );
282 $ilTabs->addTarget(
283 "settings",
284 $ilCtrl->getLinkTarget($this, "editMediaPoolPage"),
285 "editMediaPoolPage",
286 get_class($this)
287 );
288 $ilCtrl->setParameter($this, "mepitem_id", $this->pool->getPoolTree()->getParentId($this->mep_request->getItemId()));
289 $ilTabs->setBackTarget($lng->txt("mep_folder"), $ilCtrl->getLinkTargetByClass(
290 ilObjMediaPoolGUI::class,
291 "returnFromItem"
292 ));
293 $ilCtrl->setParameter($this, "mepitem_id", $this->mep_request->getItemId());
294 }
295
296 public function showAllMediaPoolPageUsages(): void
297 {
298 $this->showMediaPoolPageUsages(true);
299 }
300
301
305 public function showMediaPoolPageUsages(bool $a_all = false): void
306 {
307 $ilTabs = $this->tabs;
308 $ilCtrl = $this->ctrl;
310 $tpl = $this->tpl;
311
312 $ilTabs->clearTargets();
313
314 $ilTabs->addSubTab(
315 "current_usages",
316 $lng->txt("cont_current_usages"),
317 $ilCtrl->getLinkTarget($this, "showMediaPoolPageUsages")
318 );
319
320 $ilTabs->addSubTab(
321 "all_usages",
322 $lng->txt("cont_all_usages"),
323 $ilCtrl->getLinkTarget($this, "showAllMediaPoolPageUsages")
324 );
325
326 if ($a_all) {
327 $ilTabs->activateSubTab("all_usages");
328 $cmd = "showAllMediaPoolPageUsages";
329 } else {
330 $ilTabs->activateSubTab("current_usages");
331 $cmd = "showMediaPoolPageUsages";
332 }
333
334 $this->getTabs();
335 $page = new ilMediaPoolPage($this->mep_request->getItemId());
336 $table = new ilMediaPoolPageUsagesTableGUI($this, $cmd, $page, $a_all);
337
338 $tpl->setContent($table->getHTML());
339 }
340
341 public function finishEditing(): void
342 {
343 $this->ctrl->returnToParent($this);
344 }
345
346 public function getAdditionalPageActions(): array
347 {
348 $tabs = [];
349
350 $mdgui = new ilObjectMetaDataGUI(
351 $this->meta_data_rep_obj,
352 $this->meta_data_type,
353 $this->meta_data_sub_obj_id
354 );
355 $mdtab = $mdgui->getTab();
356 if ($mdtab) {
357 $tabs[] = $this->ui->factory()->link()->standard(
358 $this->lng->txt('meta_data'),
359 $mdtab
360 );
361 }
362
363 $tabs[] =
364 $this->ui->factory()->link()->standard(
365 $this->lng->txt('cont_usage'),
366 $this->ctrl->getLinkTargetByClass([
367 self::class
368 ], 'showMediaPoolPageUsages')
369 );
370 $tabs[] =
371 $this->ui->factory()->link()->standard(
372 $this->lng->txt('settings'),
373 $this->ctrl->getLinkTargetByClass([
374 self::class
375 ], 'editMediaPoolPage')
376 );
377 return $tabs;
378 }
379
380 public function getProfileBackUrl(): string
381 {
382 return "#";
383 }
384}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_id)
Class ilMediaPoolPage GUI class.
__construct(int $a_id=0, int $a_old_nr=0, bool $a_prevent_get_id=false, string $a_lang="")
getTabs(string $a_activate="")
setMediaPoolPage(ilMediaPoolPage $a_media_pool_page)
showMediaPoolPageUsages(bool $a_all=false)
List usages of the contnet snippet.
MediaPool StandardGUIRequest $mep_request
showPage(bool $a_no_title=false)
setTemplate(ilGlobalTemplateInterface $tpl)
getMediaPoolPageValues(ilPropertyFormGUI $form)
ILIAS Style Content GUIService $cs_gui
initMediaPoolPageForm(string $a_mode="edit")
getAdditionalPageActions()
Get additional page actions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface class for media pool objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjectMetaDataGUI.
Class ilPageObjectGUI.
setStyleId(int $a_styleid)
setPageObject(ilPageObject $a_pg_obj)
setEditPreview(bool $a_editpreview)
Set Display first Edit tab, then Preview tab, instead of Page and Edit.
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26