ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPageContentGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
22 use ILIAS\Style;
23 
30 {
32  protected string $pc_id = "";
33  protected array $chars;
34  protected ?ilObjStyleSheet $style = null;
37  public ilLanguage $lng;
38  public ilCtrl $ctrl;
40  public string $hier_id = "";
43  public $updated;
44  public string $target_script = "";
45  public string $return_location = "";
46  public ?ilPageConfig $page_config = null;
47  protected ilLogger $log;
48  protected int $styleid = 0;
50  protected string $sub_command = "";
51  protected int $requested_ref_id = 0;
52 
53  public static string $style_selector_reset = "margin-top:2px; margin-bottom:2px; text-indent:0px; position:static; float:none; width: auto;";
54 
55  // common bb buttons (special ones are iln and wln)
56  protected static array $common_bb_buttons = array(
57  "str" => "Strong", "emp" => "Emph", "imp" => "Important",
58  "sup" => "Sup", "sub" => "Sub",
59  "com" => "Comment",
60  "quot" => "Quotation", "acc" => "Accent", "code" => "Code", "tex" => "Tex",
61  "fn" => "Footnote", "xln" => "ExternalLink"
62  );
63  protected Style\Content\CharacteristicManager $char_manager;
64 
65  public function __construct(
66  ilPageObject $a_pg_obj,
67  ?ilPageContent $a_content_obj,
68  string $a_hier_id = "",
69  string $a_pc_id = "0"
70  ) {
71  global $DIC;
72 
73  $lng = $DIC->language();
74  $ilCtrl = $DIC->ctrl();
75 
76  $this->log = ilLoggerFactory::getLogger('copg');
77 
78  $this->tpl = $DIC->ui()->mainTemplate();
79  $this->lng = $lng;
80  $this->pg_obj = $a_pg_obj;
81  $this->ctrl = $ilCtrl;
82  $this->content_obj = $a_content_obj;
83  $service = $DIC->copage()->internal();
84  $this->request = $service
85  ->gui()
86  ->pc()
87  ->editRequest();
88  $this->edit_repo = $service
89  ->repo()
90  ->edit();
91  $this->sub_command = $this->request->getSubCmd();
92  $this->requested_ref_id = $this->request->getRefId();
93 
94  if ($a_hier_id !== "0") {
95  $this->hier_id = $a_hier_id;
96  $this->pc_id = $a_pc_id;
97  //echo "-".$this->pc_id."-";
98  $this->dom = $a_pg_obj->getDom();
99  }
100  }
101 
102  public function setContentObject(ilPageContent $a_val): void
103  {
104  $this->content_obj = $a_val;
105  }
106 
107  public function getContentObject(): ?ilPageContent
108  {
109  return $this->content_obj;
110  }
111 
112  public function setPage(ilPageObject $a_val): void
113  {
114  $this->pg_obj = $a_val;
115  }
116 
117  public function getPage(): ilPageObject
118  {
119  return $this->pg_obj;
120  }
121 
122  public function setPageConfig(ilPageConfig $a_val): void
123  {
124  $this->page_config = $a_val;
125  }
126 
127  public function getPageConfig(): ilPageConfig
128  {
129  return $this->page_config;
130  }
131 
132  public static function _getCommonBBButtons(): array
133  {
134  return self::$common_bb_buttons;
135  }
136 
137  public function setStyleId(int $a_styleid): void
138  {
139  $this->styleid = $a_styleid;
140  }
141 
142  public function getStyleId(): int
143  {
144  return $this->styleid;
145  }
146 
147  public function getStyle(): ?ilObjStyleSheet
148  {
149  if ((!is_object($this->style) || $this->getStyleId() != $this->style->getId()) && $this->getStyleId() > 0) {
150  if (ilObject::_lookupType($this->getStyleId()) == "sty") {
151  $this->style = new ilObjStyleSheet($this->getStyleId());
152  }
153  }
154  return $this->style;
155  }
156 
161  public function getCharacteristicsOfCurrentStyle(array $a_type): void
162  {
163  global $DIC;
164  $service = $DIC->contentStyle()->internal();
165  $access_manager = $service->domain()->access(
166  $this->requested_ref_id,
167  $DIC->user()->getId()
168  );
169 
170  if ($this->getStyleId() > 0 &&
171  ilObject::_lookupType($this->getStyleId()) == "sty") {
172  $char_manager = $service->domain()->characteristic(
173  $this->getStyleId(),
174  $access_manager
175  );
176 
177  if (!is_array($a_type)) {
178  $a_type = array($a_type);
179  }
180  $chars = $char_manager->getByTypes($a_type, false, false);
181  $new_chars = array();
182  foreach ($chars as $char) {
183  if (($this->chars[$char->getCharacteristic()] ?? "") != "") { // keep lang vars for standard chars
184  $title = $char_manager->getPresentationTitle(
185  $char->getType(),
186  $char->getCharacteristic()
187  );
188  if ($title == "") {
189  $title = $this->chars[$char->getCharacteristic()];
190  }
191  $new_chars[$char->getCharacteristic()] = $title;
192  } else {
193  $new_chars[$char->getCharacteristic()] = $char_manager->getPresentationTitle(
194  $char->getType(),
195  $char->getCharacteristic()
196  );
197  }
198  }
199  $this->setCharacteristics($new_chars);
200  }
201  }
202 
203  public function setCharacteristics(array $a_chars): void
204  {
205  $this->chars = $a_chars;
206  }
207 
208  public function getCharacteristics(): array
209  {
210  return $this->chars ?? [];
211  }
212 
213  public function getHierId(): string
214  {
215  return $this->hier_id;
216  }
217 
221  public function setHierId(string $a_hier_id): void
222  {
223  $this->hier_id = $a_hier_id;
224  }
225 
226  // delete content element
227  public function delete(): void
228  {
229  $updated = $this->pg_obj->deleteContent($this->hier_id);
230  if ($updated !== true) {
231  $this->edit_repo->setPageError($updated);
232  } else {
233  $this->edit_repo->clearPageError();
234  }
235  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
236  }
237 
242  public function moveAfter(): void
243  {
244  $target = $this->request->getStringArray("target");
245  // check if a target is selected
246  if (count($target) == 0) {
247  throw new ilCOPagePCEditException(
248  $this->lng->txt("no_checkbox")
249  );
250  }
251 
252  // check if only one target is selected
253  if (count($target) > 1) {
254  throw new ilCOPagePCEditException(
255  $this->lng->txt("only_one_target")
256  );
257  }
258 
259  $a_hid = explode(":", $target[0]);
260  //echo "-".$a_hid[0]."-".$a_hid[1]."-";
261 
262  // check if target is within source
263  if ($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id))) {
264  throw new ilCOPagePCEditException($this->lng->txt("cont_target_within_source"));
265  }
266 
267  // check whether target is allowed
268  $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
269  if (is_object($curr_node) && $curr_node->node_name() == "FileItem") {
270  throw new ilCOPagePCEditException($this->lng->txt("cont_operation_not_allowed"));
271  }
272 
273  // strip "c" "r" of table ids from hierarchical id
274  $first_hier_character = substr($a_hid[0], 0, 1);
275  if ($first_hier_character == "c" ||
276  $first_hier_character == "r" ||
277  $first_hier_character == "i") {
278  $a_hid[0] = substr($a_hid[0], 1);
279  }
280 
281  // move
282  $updated = $this->pg_obj->moveContentAfter(
283  $this->hier_id,
284  $a_hid[0],
285  $this->content_obj->getPCId(),
286  $a_hid[1]
287  );
288  if ($updated !== true) {
289  $this->edit_repo->setPageError($updated);
290  } else {
291  $this->edit_repo->clearPageError();
292  }
293  $this->log->debug("return to parent jump" . $this->hier_id);
294  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
295  }
296 
301  public function moveBefore(): void
302  {
303  $target = $this->request->getStringArray("target");
304  // check if a target is selected
305  if (count($target) == 0) {
306  throw new ilCOPagePCEditException($this->lng->txt("no_checkbox"));
307  }
308 
309  // check if target is within source
310  if (count($target) > 1) {
311  throw new ilCOPagePCEditException($this->lng->txt("only_one_target"));
312  }
313 
314  $a_hid = explode(":", $target[0]);
315 
316  // check if target is within source
317  if ($this->hier_id == substr($a_hid[0], 0, strlen($this->hier_id))) {
318  throw new ilCOPagePCEditException($this->lng->txt("cont_target_within_source"));
319  }
320 
321  // check whether target is allowed
322  $curr_node = $this->pg_obj->getContentNode($a_hid[0], $a_hid[1]);
323  if (is_object($curr_node) && $curr_node->node_name() == "FileItem") {
324  throw new ilCOPagePCEditException($this->lng->txt("cont_operation_not_allowed"));
325  }
326 
327  // strip "c" "r" of table ids from hierarchical id
328  $first_hier_character = substr($a_hid[0], 0, 1);
329  if ($first_hier_character == "c" ||
330  $first_hier_character == "r" ||
331  $first_hier_character == "i") {
332  $a_hid[0] = substr($a_hid[0], 1);
333  }
334 
335  // move
336  $updated = $this->pg_obj->moveContentBefore(
337  $this->hier_id,
338  $a_hid[0],
339  $this->content_obj->getPCId(),
340  $a_hid[1]
341  );
342  if ($updated !== true) {
343  $this->edit_repo->setPageError($updated);
344  } else {
345  $this->edit_repo->clearPageError();
346  }
347  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
348  }
349 
350 
355  public function splitPage(): void
356  {
357  if ($this->pg_obj->getParentType() != "lm") {
358  throw new ilCOPagePCEditException("Split method called for wrong parent type (" .
359  $this->pg_obj->getParentType() . ")");
360  } else {
361  $lm_page = ilLMPageObject::_splitPage(
362  $this->pg_obj->getId(),
363  $this->pg_obj->getParentType(),
365  );
366 
367  // jump to new page
368  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $lm_page->getId());
369  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
370  }
371 
372  $this->ctrl->returnToParent($this, "jump" . ($this->hier_id - 1));
373  }
374 
379  public function splitPageNext(): void
380  {
381  if ($this->pg_obj->getParentType() != "lm") {
382  throw new ilCOPagePCEditException("Split method called for wrong parent type (" .
383  $this->pg_obj->getParentType() . ")");
384  } else {
386  $this->pg_obj->getId(),
387  $this->pg_obj->getParentType(),
389  );
390 
391  // jump to successor page
392  if ($succ_id > 0) {
393  $this->ctrl->setParameterByClass("illmpageobjectgui", "obj_id", $succ_id);
394  $this->ctrl->redirectByClass("illmpageobjectgui", "edit");
395  }
396  }
397  $this->ctrl->returnToParent($this, "jump" . ($this->hier_id - 1));
398  }
399 
400  public function displayValidationError(): void
401  {
402  if (is_array($this->updated)) {
403  $error_str = "<b>Error(s):</b><br>";
404  foreach ($this->updated as $error) {
405  $err_mess = implode(" - ", $error);
406  if (!is_int(strpos($err_mess, ":0:"))) {
407  $error_str .= htmlentities($err_mess) . "<br />";
408  }
409  }
410  $this->tpl->setOnScreenMessage('failure', $error_str);
411  } elseif ($this->updated != "" && $this->updated !== true) {
412  $this->tpl->setOnScreenMessage('failure', "<b>Error(s):</b><br />" .
413  $this->updated);
414  }
415  }
416 
420  public function cancelCreate(): void
421  {
422  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
423  }
424 
428  public function cancelUpdate(): void
429  {
430  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
431  }
432 
436  public function cancel(): void
437  {
438  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
439  }
440 
445  public function deactivate(): void
446  {
447  $obj = &$this->content_obj;
448 
449  if ($obj->isEnabled()) {
450  $obj->disable();
451  } else {
452  $obj->enable();
453  }
454  $this->updateAndReturn();
455  }
456 
460  public function cut(): void
461  {
462  $updated = $this->pg_obj->cutContents(array($this->hier_id . ":" . $this->pc_id));
463  if ($updated !== true) {
464  $this->edit_repo->setPageError($updated);
465  } else {
466  $this->edit_repo->clearPageError();
467  }
468 
469  $this->log->debug("return to parent jump" . $this->hier_id);
470  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
471  }
472 
476  public function copy(): void
477  {
478  $this->pg_obj->copyContents(array($this->hier_id . ":" . $this->pc_id));
479  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
480  }
481 
482 
486  public function getTemplateOptions(string $a_type = ""): array
487  {
488  $style = $this->getStyle();
489 
490  if (is_object($style)) {
491  $ts = $style->getTemplates($a_type);
492  $options = array();
493  foreach ($ts as $t) {
494  $options["t:" . $t["id"] . ":" . $t["name"]] = $t["name"];
495  }
496  return $options;
497  }
498  return array();
499  }
500 
501  protected function redirectToParent(string $hier_id = ""): void
502  {
503  $ilCtrl = $this->ctrl;
504  if ($hier_id == "") {
505  $hier_id = $this->hier_id;
506  }
507  $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
508  $ilCtrl->returnToParent($this, "add" . $pcid);
509  }
510 
511  protected function getParentReturn(string $hier_id = ""): string
512  {
513  if ($hier_id == "") {
514  $hier_id = $this->hier_id;
515  }
516  $ilCtrl = $this->ctrl;
517  $pcid = $this->pg_obj->getPCIdForHierId($hier_id);
518  return $ilCtrl->getParentReturn($this) . "#add" . $pcid;
519  }
520 
521  protected function updateAndReturn(): void
522  {
523  $up = $this->pg_obj->update();
524  if ($up === true) {
525  $this->edit_repo->clearPageError();
526  } else {
527  $this->edit_repo->setPageError($this->pg_obj->update());
528  }
529  $this->redirectToParent();
530  }
531 
532  protected function setCurrentTextLang(string $lang_key): void
533  {
534  $this->edit_repo->setTextLang($this->requested_ref_id, $lang_key);
535  }
536 
537  protected function getCurrentTextLang(): string
538  {
539  return $this->edit_repo->getTextLang($this->requested_ref_id);
540  }
541 }
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.
splitPage()
split page to new page at specified position
setHierId(string $a_hier_id)
set hierarchical id in dom object
redirectToParent(string $hier_id="")
setCharacteristics(array $a_chars)
cancelCreate()
cancel creating page content
cancelUpdate()
cancel update
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
splitPageNext()
split page to next page at specified position
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContentObject(ilPageContent $a_val)
static _splitPage(int $a_page_id, string $a_pg_parent_type, string $a_hier_id)
split page at hierarchical id the main reason for this method being static is that a lm page object i...
getParentReturn(string $hier_id="")
moveAfter()
move content element after another element
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)
moveBefore()
move content element before another element
setCurrentTextLang(string $lang_key)
static array $common_bb_buttons
__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.
static _splitPageNext(int $a_page_id, string $a_pg_parent_type, string $a_hier_id)
split page to next page at hierarchical id
setPageConfig(ilPageConfig $a_val)
cut()
Cut single element.