ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPCMediaObjectEditorGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
26 {
27  public function getEditorElements(
28  UIWrapper $ui_wrapper,
29  string $page_type,
30  ilPageObjectGUI $page_gui,
31  int $style_id
32  ): array {
33  global $DIC;
34  $lng = $DIC->language();
35  $lng->loadLanguageModule("content");
36 
37  $acc = new ilAccordionGUI();
38  $acc->addItem($lng->txt("cont_upload_file"), $this->getRenderedUploadForm($ui_wrapper, $lng));
39  $acc->addItem($lng->txt("cont_add_url"), $this->getRenderedUrlForm($ui_wrapper, $lng));
40  $acc->addItem($lng->txt("cont_choose_from_pool"), $this->getRenderedPoolBar($ui_wrapper, $lng));
41  $acc->addItem($lng->txt("cont_choose_from_clipboard"), $this->getRenderedClipboardBar($ui_wrapper, $lng, $page_gui));
42  $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
43 
44  return [
45  "creation_form" => $acc->getHTML(true),
46  "icon" => $ui_wrapper->getRenderedIcon("pemed")
47  ];
48  }
49 
50  public function getEditComponentForm(
51  UIWrapper $ui_wrapper,
52  string $page_type,
53  \ilPageObjectGUI $page_gui,
54  int $style_id,
55  string $pcid
56  ): string {
57  global $DIC;
58  $lng = $DIC->language();
59  $lng->loadLanguageModule("content");
60 
61  $media_type = $DIC->mediaObjects()
62  ->internal()
63  ->domain()
64  ->mediaType();
65 
66  $form = new ilPropertyFormGUI();
67  $form->setShowTopButtons(false);
68  $form->setTitle($lng->txt("cont_edit_mob"));
69 
71  $pc_media = $page_gui->getPageObject()->getContentObjectForPcId($pcid);
72 
73  $quick_edit = new ilPCMediaObjectQuickEdit($pc_media);
74 
75  $pc_media_gui = new ilPCMediaObjectGUI(
76  $page_gui->getPageObject(),
77  $pc_media,
78  $page_gui->getPageObject()->getHierIdForPcId($pcid),
79  $pcid
80  );
81  $pc_media_gui->setStyleId($style_id);
82  $pc_media_gui->getCharacteristicsOfCurrentStyle(["media_cont"]);
83 
84  if (is_null($pc_media->getMediaObject())) {
85  return "<div id='copg-top-actions'>" . $ui_wrapper->getRenderedInfoBox($lng->txt("copg_pc_mob_does_not_exist")) .
86  $ui_wrapper->getRenderedButton($lng->txt("cancel"), "form-button", "component.cancel", null, "Page") . "</div>";
87  }
88  $media = $pc_media->getMediaObject()->getMediaItem("Standard");
89 
90  // title
91  $title = new ilTextInputGUI($lng->txt("title"), "standard_title");
92  $title->setSize(40);
93  $title->setMaxLength(120);
94  $title->setValue($quick_edit->getTitle());
95  $form->addItem($title);
96 
97  // style
98  if ($pc_media_gui->checkStyleSelection()) {
99  $style_input = $pc_media_gui->getStyleInput();
100  $form->addItem($style_input);
101  }
102 
103  // horizonal align
104  $align_prop = new ilSelectInputGUI(
105  $lng->txt("cont_align"),
106  "horizontal_align"
107  );
108  $options = array(
109  "Left" => $lng->txt("cont_left"),
110  "Center" => $lng->txt("cont_center"),
111  "Right" => $lng->txt("cont_right"),
112  "LeftFloat" => $lng->txt("cont_left_float"),
113  "RightFloat" => $lng->txt("cont_right_float"));
114  $align_prop->setOptions($options);
115  $align_prop->setValue($quick_edit->getHorizontalAlign());
116  $form->addItem($align_prop);
117 
118  // fullscreen
119  if ($media_type->isImage($media->getFormat())) {
120  $cb = new ilCheckboxInputGUI($lng->txt("cont_show_fullscreen"), "fullscreen");
121  $cb->setChecked($quick_edit->getUseFullscreen());
122  $form->addItem($cb);
123  }
124 
125  // standard caption
126  $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "standard_caption");
127  $caption->setRows(2);
128  $caption->setValue($quick_edit->getCaption());
129  $form->addItem($caption);
130 
131  // text representation
132  if ($media_type->usesAltTextProperty($media->getFormat())) {
133  $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "text_representation");
134  $ta->setRows(2);
135  $ta->setInfo($lng->txt("text_repr_info"));
136  $ta->setValue($quick_edit->getTextRepresentation());
137  $form->addItem($ta);
138  }
139 
140  $html = $ui_wrapper->getRenderedForm(
141  $form,
142  [["Page", "component.update", $lng->txt("save")],
143  ["Page", "component.cancel", $lng->txt("cancel")]]
144  );
145 
146  $link = $ui_wrapper->getRenderedLink($lng->txt("cont_advanced_settings"), "Page", "link", "component.settings");
147 
148  return $html . $link;
149  }
150 
151  public function getRenderedUploadForm(
152  UIWrapper $ui_wrapper,
154  ?ilPropertyFormGUI $form = null
155  ): string {
156  if (!$form) {
157  $form = $this->getUploadForm($lng);
158  }
159 
160  $html = $ui_wrapper->getRenderedForm(
161  $form,
162  [["Page", "component.save", $lng->txt("insert")],
163  ["Page", "component.cancel", $lng->txt("cancel")]]
164  );
165 
166  return $html;
167  }
168 
169  public function getUploadForm(
170  $lng
171  ): ilPropertyFormGUI {
172  global $DIC;
173  $media_types = $DIC->mediaObjects()->internal()->domain()->mediaType();
174 
175  $form = new ilPropertyFormGUI();
176  $form->setShowTopButtons(false);
177 
178  // standard type
179  $hi = new ilHiddenInputGUI("standard_type");
180  $hi->setValue("File");
181  $form->addItem($hi);
182 
183  // standard size
184  $hi2 = new ilHiddenInputGUI("standard_size");
185  $hi2->setValue("original");
186  $form->addItem($hi2);
187 
188  // standard size
189  $hi3 = new ilHiddenInputGUI("full_type");
190  $hi3->setValue("None");
191  $form->addItem($hi3);
192 
193  // standard file
194  $up = new ilFileInputGUI($lng->txt("cont_file"), "standard_file");
195  $up->setSuffixes(iterator_to_array($media_types->getAllowedSuffixes()));
196  //$up->setForbiddenSuffixes(ilObjMediaObject::getForbiddenFileTypes());
197  $up->setRequired(true);
198  $form->addItem($up);
199 
200  return $form;
201  }
202 
203  public function getRenderedUrlForm(
204  UIWrapper $ui_wrapper,
206  ?ilPropertyFormGUI $form = null
207  ): string {
208  if (!$form) {
209  $form = $this->getUrlForm($lng);
210  }
211 
212  $html = $ui_wrapper->getRenderedForm(
213  $form,
214  [["Page", "component.save", $lng->txt("insert")],
215  ["Page", "component.cancel", $lng->txt("cancel")]]
216  );
217 
218  return $html;
219  }
220 
221  public function getUrlForm(
223  ): ilPropertyFormGUI {
224  $form = new ilPropertyFormGUI();
225  $form->setShowTopButtons(false);
226 
227  // standard type
228  $hi = new ilHiddenInputGUI("standard_type");
229  $hi->setValue("Reference");
230  $form->addItem($hi);
231 
232  // standard size
233  $hi2 = new ilHiddenInputGUI("standard_size");
234  $hi2->setValue("original");
235  $form->addItem($hi2);
236 
237  // standard size
238  $hi3 = new ilHiddenInputGUI("full_type");
239  $hi3->setValue("None");
240  $form->addItem($hi3);
241 
242  // standard reference
243  $ti = new ilTextInputGUI($lng->txt("url"), "standard_reference");
244  $ti->setInfo($lng->txt("cont_url_info"));
245  $ti->setRequired(true);
246  $form->addItem($ti);
247 
248  return $form;
249  }
250 
251  protected function getRenderedPoolBar(
252  UIWrapper $ui_wrapper,
254  ): string {
255  global $DIC;
256 
257  $ui = $DIC->ui();
258  $ctrl = $DIC->ctrl();
259  $lng = $DIC->language();
260 
261  $buttons = [];
262 
263  $ctrl->setParameterByClass("ilpcmediaobjectgui", "subCmd", "poolSelection");
264  $buttons[] = $ui_wrapper->getButton(
265  $lng->txt("cont_choose_media_pool"),
266  "media-action",
267  "select.pool",
268  [
269  "url" => $ctrl->getLinkTargetByClass("ilpcmediaobjectgui", "insert")
270  ],
271  "MediaObject"
272  );
273  $buttons[] = $ui_wrapper->getButton(
274  $lng->txt("cancel"),
275  "form-button",
276  "component.cancel",
277  [
278  ],
279  "Page"
280  );
281  $ctrl->setParameterByClass("ilpcmediaobjectgui", "subCmd", "poolSelection");
282 
283  return $ui_wrapper->getRenderedFormFooter($buttons);
284  }
285 
286  protected function getRenderedClipboardBar(
287  UIWrapper $ui_wrapper,
289  ilPageObjectGUI $page_gui
290  ): string {
291  global $DIC;
292 
293  $ctrl = $DIC->ctrl();
294 
295  $return_cmd = $ctrl->getLinkTargetByClass("ilpageeditorgui", "insertFromClipboard");
296 
297  $ctrl->setParameterByClass("ileditclipboardgui", "returnCommand", rawurlencode($return_cmd));
298 
299  $buttons = [];
300 
301  $buttons[] = $ui_wrapper->getButton(
302  $lng->txt("cont_open_clipboard"),
303  "media-action",
304  "open.clipboard",
305  ["url" => $ctrl->getLinkTargetByClass([get_class($page_gui), "ileditclipboardgui"], "getObject")],
306  "MediaObject"
307  );
308 
309  $buttons[] = $ui_wrapper->getButton(
310  $lng->txt("cancel"),
311  "form-button",
312  "component.cancel",
313  [
314  ],
315  "Page"
316  );
317 
318  return $ui_wrapper->getRenderedFormFooter($buttons);
319  }
320 }
getRenderedUrlForm(UIWrapper $ui_wrapper, ilLanguage $lng, ?ilPropertyFormGUI $form=null)
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a file property in a property form.
Class ilPageObjectGUI.
setSuffixes(array $a_suffixes)
setOptions(array $a_options)
getButton(string $content, string $type, string $action, ?array $data=null, string $component="", bool $primary=false, string $aria_label="")
getRenderedButton(string $content, string $type, string $action, ?array $data=null, string $component="", bool $primary=false, string $aria_label="")
getRenderedUploadForm(UIWrapper $ui_wrapper, ilLanguage $lng, ?ilPropertyFormGUI $form=null)
getRenderedPoolBar(UIWrapper $ui_wrapper, ilLanguage $lng)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getEditorElements(UIWrapper $ui_wrapper, string $page_type, ilPageObjectGUI $page_gui, int $style_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a hidden form property in a property form.
getRenderedClipboardBar(UIWrapper $ui_wrapper, ilLanguage $lng, ilPageObjectGUI $page_gui)
getEditComponentForm(UIWrapper $ui_wrapper, string $page_type, \ilPageObjectGUI $page_gui, int $style_id, string $pcid)
Get rendered editor elements.
getRenderedForm(\ilPropertyFormGUI $form, array $buttons)
getRenderedInfoBox(string $text, array $buttons=[])
global $DIC
Definition: shib_login.php:26
setStyleId(int $a_styleid)
getRenderedLink(string $content, string $component, string $type, string $action, ?array $data=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...