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