ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPageContentGUI.php
Go to the documentation of this file.
1<?php
2
22use ILIAS\Style;
23
30{
31 protected \ILIAS\COPage\Editor\GUIService $editor_gui;
32 protected \ILIAS\COPage\InternalGUIService $gui;
34 protected string $pc_id = "";
35 protected array $chars;
36 protected ?ilObjStyleSheet $style = null;
40 public ilCtrl $ctrl;
41 protected LOMServices $lom_services;
43 public string $hier_id = "";
44 public DOMDocument $dom;
46 public $updated;
47 public string $target_script = "";
48 public string $return_location = "";
49 public ?ilPageConfig $page_config = null;
50 protected ilLogger $log;
51 protected int $styleid = 0;
53 protected string $sub_command = "";
54 protected int $requested_ref_id = 0;
55
56 public static string $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;";
57
58 protected \ILIAS\GlobalScreen\ScreenContext\ContextServices $tool_context;
59
60 // common bb buttons (special ones are iln and wln)
61 protected static array $common_bb_buttons = array(
62 "str" => "Strong", "emp" => "Emph", "imp" => "Important",
63 "sup" => "Sup", "sub" => "Sub",
64 "com" => "Comment",
65 "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
66 "fn" => "Footnote", "xln" => "ExternalLink"
67 );
69
70 public function __construct(
71 ilPageObject $a_pg_obj,
72 ?ilPageContent $a_content_obj,
73 string $a_hier_id = "",
74 string $a_pc_id = "0"
75 ) {
76 global $DIC;
77
78 $lng = $DIC->language();
79 $ilCtrl = $DIC->ctrl();
80
81 $this->log = ilLoggerFactory::getLogger('copg');
82
83 $this->tpl = $DIC->ui()->mainTemplate();
84 $this->lng = $lng;
85 $this->pg_obj = $a_pg_obj;
86 $this->ctrl = $ilCtrl;
87 $this->lom_services = $DIC->learningObjectMetadata();
88 $this->content_obj = $a_content_obj;
89 $service = $DIC->copage()->internal();
90 $this->request = $service
91 ->gui()
92 ->pc()
93 ->editRequest();
94 $this->edit_repo = $service
95 ->repo()
96 ->edit();
97 $this->sub_command = $this->request->getSubCmd();
98 $this->requested_ref_id = $this->request->getRefId();
99 $this->gui = $service->gui();
100
101 if ($a_hier_id !== "0") {
102 $this->hier_id = $a_hier_id;
103 $this->pc_id = $a_pc_id;
104 //echo "-".$this->pc_id."-";
105 $this->dom = $a_pg_obj->getDomDoc();
106 }
107 $this->tool_context = $DIC->globalScreen()->tool()->context();
108 $this->editor_gui = $DIC->copage()->internal()->gui()->edit();
109 }
110
111 public function setContentObject(ilPageContent $a_val): void
112 {
113 $this->content_obj = $a_val;
114 }
115
116 public function getContentObject(): ?ilPageContent
117 {
118 return $this->content_obj;
119 }
120
121 public function setPage(ilPageObject $a_val): void
122 {
123 $this->pg_obj = $a_val;
124 }
125
126 public function getPage(): ilPageObject
127 {
128 return $this->pg_obj;
129 }
130
131 public function setPageConfig(ilPageConfig $a_val): void
132 {
133 $this->page_config = $a_val;
134 }
135
136 public function getPageConfig(): ilPageConfig
137 {
138 return $this->page_config;
139 }
140
141 public static function _getCommonBBButtons(): array
142 {
144 }
145
146 public function setStyleId(int $a_styleid): void
147 {
148 $this->styleid = $a_styleid;
149 }
150
151 public function getStyleId(): int
152 {
153 return $this->styleid;
154 }
155
156 public function getStyle(): ?ilObjStyleSheet
157 {
158 if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0) {
159 if (ilObject::_lookupType($this->getStyleId()) == "sty") {
160 $this->style = new ilObjStyleSheet($this->getStyleId());
161 }
162 }
163 return $this->style;
164 }
165
170 public function getCharacteristicsOfCurrentStyle(array $a_type): void
171 {
172 global $DIC;
173 $service = $DIC->contentStyle()->internal();
174 $access_manager = $service->domain()->access(
175 $this->requested_ref_id,
176 $DIC->user()->getId()
177 );
178
179 if ($this->getStyleId() > 0 &&
180 ilObject::_lookupType($this->getStyleId()) == "sty") {
181 $char_manager = $service->domain()->characteristic(
182 $this->getStyleId(),
183 $access_manager
184 );
185
186 if (!is_array($a_type)) {
187 $a_type = array($a_type);
188 }
189 $chars = $char_manager->getByTypes($a_type, false, false);
190 $new_chars = array();
191 foreach ($chars as $char) {
192 if (($this->chars[$char->getCharacteristic()] ?? "") != "") { // keep lang vars for standard chars
193 $title = $char_manager->getPresentationTitle(
194 $char->getType(),
195 $char->getCharacteristic()
196 );
197 if ($title == "") {
198 $title = $this->chars[$char->getCharacteristic()];
199 }
200 $new_chars[$char->getCharacteristic()] = $title;
201 } else {
202 $new_chars[$char->getCharacteristic()] = $char_manager->getPresentationTitle(
203 $char->getType(),
204 $char->getCharacteristic()
205 );
206 }
207 }
208 $this->setCharacteristics($new_chars);
209 }
210 }
211
212 public function setCharacteristics(array $a_chars): void
213 {
214 $this->chars = $a_chars;
215 }
216
217 public function getCharacteristics(): array
218 {
219 return $this->chars ?? [];
220 }
221
222 public function getHierId(): string
223 {
224 return $this->hier_id;
225 }
226
230 public function setHierId(string $a_hier_id): void
231 {
232 $this->hier_id = $a_hier_id;
233 }
234
235 // delete content element
236 public function delete(): void
237 {
238 $updated = $this->pg_obj->deleteContent($this->hier_id);
239 if ($updated !== true) {
240 $this->edit_repo->setPageError($updated);
241 } else {
242 $this->edit_repo->clearPageError();
243 }
244 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
245 }
246
247 public function displayValidationError(): void
248 {
249 if (is_array($this->updated)) {
250 $error_str = "<strong>Error(s):</strong><br>";
251 foreach ($this->updated as $error) {
252 $err_mess = implode(" - ", $error);
253 if (!is_int(strpos($err_mess, ":0:"))) {
254 $error_str .= htmlentities($err_mess) . "<br />";
255 }
256 }
257 $this->tpl->setOnScreenMessage('failure', $error_str);
258 } elseif ($this->updated != "" && $this->updated !== true) {
259 $this->tpl->setOnScreenMessage('failure', "<strong>Error(s):</strong><br />" .
260 $this->updated);
261 }
262 }
263
267 public function cancelCreate(): void
268 {
269 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
270 }
271
275 public function cancelUpdate(): void
276 {
277 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
278 }
279
283 public function cancel(): void
284 {
285 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
286 }
287
292 public function deactivate(): void
293 {
294 $obj = &$this->content_obj;
295
296 if ($obj->isEnabled()) {
297 $obj->disable();
298 } else {
299 $obj->enable();
300 }
301 $this->updateAndReturn();
302 }
303
307 public function cut(): void
308 {
309 $updated = $this->pg_obj->cutContents(array($this->hier_id . ":" . $this->pc_id));
310 if ($updated !== true) {
311 $this->edit_repo->setPageError($updated);
312 } else {
313 $this->edit_repo->clearPageError();
314 }
315
316 $this->log->debug("return to parent jump" . $this->hier_id);
317 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
318 }
319
323 public function copy(): void
324 {
325 $this->pg_obj->copyContents(array($this->hier_id . ":" . $this->pc_id));
326 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
327 }
328
329
333 public function getTemplateOptions(string $a_type = ""): array
334 {
335 $style = $this->getStyle();
336
337 if (is_object($style)) {
338 $ts = $style->getTemplates($a_type);
339 $options = array();
340 foreach ($ts as $t) {
341 $options["t:" . $t["id"] . ":" . $t["name"]] = $t["name"];
342 }
343 return $options;
344 }
345 return array();
346 }
347
348 protected function redirectToParent(string $hier_id = ""): void
349 {
350 $ilCtrl = $this->ctrl;
351 if ($hier_id == "") {
353 }
354 $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
355 $ilCtrl->returnToParent($this, "add" . $pcid);
356 }
357
358 protected function getParentReturn(string $hier_id = ""): string
359 {
360 if ($hier_id == "") {
362 }
363 $ilCtrl = $this->ctrl;
364 $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
365 return $ilCtrl->getParentReturn($this) . "#add" . $pcid;
366 }
367
368 protected function updateAndReturn(): void
369 {
370 $up = $this->pg_obj->update();
371 if ($up === true) {
372 $this->edit_repo->clearPageError();
373 } else {
374 $this->edit_repo->setPageError($this->pg_obj->update());
375 }
376 $this->redirectToParent();
377 }
378
379 protected function setCurrentTextLang(string $lang_key): void
380 {
381 $this->edit_repo->setTextLang($this->requested_ref_id, $lang_key);
382 }
383
384 protected function getCurrentTextLang(): string
385 {
386 return $this->edit_repo->getTextLang($this->requested_ref_id);
387 }
388
389 protected function setEditorToolContext(): void
390 {
391 $collection = $this->tool_context->current()->getAdditionalData();
392 if ($collection->exists(ilCOPageEditGSToolProvider::SHOW_EDITOR)) {
393 $collection->replace(ilCOPageEditGSToolProvider::SHOW_EDITOR, true);
394 } else {
395 $collection->add(ilCOPageEditGSToolProvider::SHOW_EDITOR, true);
396 }
397 }
398
399 protected function initEditor(): void
400 {
401 $this->setEditorToolContext();
402 $this->editor_gui->init()->initUI($this->tpl);
403 }
404
405 protected function getEditorScriptTag(string $form_pc_id = "", string $form_cname = ""): string
406 {
407 return $this->editor_gui->init()->getInitHtml("", $form_pc_id, $form_cname);
408 }
409
410}
Page component editing request.
Main business logic for characteristics.
Class ilCtrl provides processing control methods.
getParentReturn(object $a_gui_obj)
@inheritDoc
language handling
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilObjStyleSheet.
getTemplates(string $a_type)
Get table templates of style.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getParentReturn(string $hier_id="")
redirectToParent(string $hier_id="")
ILIAS COPage InternalGUIService $gui
deactivate()
gui function set enabled if is not enabled and vice versa
setHierId(string $a_hier_id)
set hierarchical id in dom object
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
ILIAS GlobalScreen ScreenContext ContextServices $tool_context
setCurrentTextLang(string $lang_key)
ilGlobalTemplateInterface $tpl
setStyleId(int $a_styleid)
Style Content CharacteristicManager $char_manager
getTemplateOptions(string $a_type="")
Get table templates.
ILIAS COPage Editor GUIService $editor_gui
setPage(ilPageObject $a_val)
EditSessionRepository $edit_repo
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id="", string $a_pc_id="0")
cut()
Cut single element.
setContentObject(ilPageContent $a_val)
getEditorScriptTag(string $form_pc_id="", string $form_cname="")
static array $common_bb_buttons
cancelCreate()
cancel creating page content
setCharacteristics(array $a_chars)
static string $style_selector_reset
copy()
Copy single element.
setPageConfig(ilPageConfig $a_val)
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getDomDoc()
Get dom doc (DOMDocument)
$service
Definition: ltiresult.php:36
global $DIC
Definition: shib_login.php:26