ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.PageQueryActionHandler.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\COPage\Page;
20 
26 
30 class PageQueryActionHandler implements Server\QueryActionHandler
31 {
32  protected \ILIAS\COPage\InternalGUIService $gui;
33  protected \ILIAS\COPage\PC\PCDefinition $pc_definition;
34  protected string $pc_id = "";
35  protected \ILIAS\DI\UIServices $ui;
36  protected \ilLanguage $lng;
37  protected \ilPageObjectGUI $page_gui;
38  protected \ilObjUser $user;
39  protected Server\UIWrapper $ui_wrapper;
40  protected \ilCtrl $ctrl;
41  protected \ilComponentFactory $component_factory;
42 
43  public function __construct(\ilPageObjectGUI $page_gui, string $pc_id = "")
44  {
45  global $DIC;
46 
47  $this->ui = $DIC->ui();
48  $this->lng = $DIC->language();
49  $this->page_gui = $page_gui;
50  $this->user = $DIC->user();
51  $this->ctrl = $DIC->ctrl();
52  $this->component_factory = $DIC["component.factory"];
53  $this->gui = $DIC->copage()->internal()->gui();
54  $this->pc_id = $pc_id;
55 
56  $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
57  $this->pc_definition = $DIC
58  ->copage()
59  ->internal()
60  ->domain()
61  ->pc()
62  ->definition();
63  }
64 
68  public function handle(array $query): Server\Response
69  {
70  switch ($query["action"]) {
71  case "ui.all":
72  return $this->allCommand();
73 
74  case "component.edit.form":
75  return $this->componentEditFormResponse($query);
76  }
77  throw new Exception("Unknown action " . $query["action"]);
78  }
79 
80  protected function allCommand(): Server\Response
81  {
82  $ctrl = $this->ctrl;
83  $f = $this->ui->factory();
84  $dd = $f->dropdown()->standard([
85  $f->link()->standard("label", "#")
86  ]);
87  $r = $this->ui->renderer();
88  $o = new \stdClass();
89  $o->dropdown = $r->render($dd);
90  $o->addCommands = $this->getAddCommands();
91  $o->pageEditHelp = $this->getPageEditHelp();
92  $o->multiEditHelp = $this->getMultiEditHelp();
93  $o->pageTopActions = $this->getTopActions();
94  $o->multiActions = $this->getMultiActions();
95  $o->pasteMessage = $this->getPasteMessage();
96  $o->errorMessage = $this->getErrorMessage();
97  $o->errorModalMessage = $this->getErrorModalMessage();
98  $o->config = $this->getConfig();
99  $o->components = $this->getComponentsEditorUI();
100  $o->pcModel = $this->getPCModel();
101  $o->pcDefinition = $this->getComponentsDefinitions();
102  $o->formatSelection = $this->getFormatSelection();
103  $o->modal = $this->getModalTemplate();
104  $o->confirmation = $this->getConfirmationTemplate();
105  $o->autoSaveInterval = $this->getAutoSaveInterval();
106  $o->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit");
107  $o->pasting = in_array(\ilEditClipboard::getAction(), ["copy", "cut"]) &&
108  count($this->user->getPCClipboardContent()) > 0;
109  $o->loaderUrl = \ilUtil::getImagePath("media/loader.svg");
110 
111  if ($this->pc_id !== "") {
112  $type = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id)->getType();
113  $def = $this->pc_definition->getPCDefinitionByType($type);
114  $o->initialComponent = $def["name"];
115  $o->initialPCId = $this->pc_id;
116  } else {
117  $o->initialComponent = "";
118  $o->initialPCId = "";
119  }
120 
121  return new Server\Response($o);
122  }
123 
124  protected function getConfig(): \stdClass
125  {
126  $config = new \stdClass();
127  $config->user = $this->user->getLogin();
128  $config->content_css =
129  \ilObjStyleSheet::getContentStylePath($this->page_gui->getStyleId()) . ", " .
131  "./Services/COPage/css/tiny_extra.css";
132  $config->text_formats = \ilPCParagraphGUI::_getTextCharacteristics($this->page_gui->getStyleId());
133  $config->text_block_formats = [];
134  foreach (["text_block", "heading1", "heading2", "heading3"] as $type) {
135  $dummy_pc = new \ilPCParagraphGUI($this->page_gui->getPageObject(), null, "");
136  $dummy_pc->setStyleId($this->page_gui->getStyleId());
137  $dummy_pc->getCharacteristicsOfCurrentStyle([$type]);
138  foreach ($dummy_pc->getCharacteristics() as $char => $txt) {
139  $config->text_block_formats[$char] = $txt;
140  }
141  }
142  $config->editPlaceholders = $this->page_gui->getPageConfig()->getEnablePCType("PlaceHolder");
143  $config->activatedProtection =
144  ($this->page_gui->getPageConfig()->getSectionProtection() == \ilPageConfig::SEC_PROTECT_PROTECTED);
145 
146  return $config;
147  }
148 
149  protected function getAddCommands(): array
150  {
151  $lng = $this->lng;
152 
153  $commands = [];
154 
155  // content types
156  $config = $this->page_gui->getPageConfig();
157  foreach ($config->getEnabledTopPCTypes() as $def) {
158  $commands[$def["pc_type"]] = $lng->txt("cont_ed_insert_" . $def["pc_type"]);
159  }
160 
161  // content templates
162  if (count($this->page_gui->getPageObject()->getContentTemplates()) > 0) {
163  $commands["templ"] = $lng->txt("cont_ed_insert_templ");
164  }
165 
166  // plugins
167  foreach ($this->component_factory->getActivePluginsInSlot("pgcp") as $plugin) {
168  if ($plugin->isValidParentType($this->page_gui->getPageObject()->getParentType())) {
169  $commands["plug_" . $plugin->getPluginName()] =
171  }
172  }
173  return $commands;
174  }
175 
179  protected function getPageEditHelp(): string
180  {
181  $lng = $this->lng;
182  $lng->loadLanguageModule("content");
183  $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
184  $tpl->setCurrentBlock("help");
185  $tpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
186  $tpl->setVariable("PLUS", $this->gui->symbol()->glyph("add")->render());
187  $tpl->setVariable("DRAG_ARROW", $this->gui->symbol()->glyph("next")->render());
188  $tpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
189  $tpl->setVariable("TXT_EDIT", $lng->txt("cont_click_edit"));
190  $tpl->setVariable("TXT_SEL", $lng->txt("cont_shift_click_to_select"));
191  $tpl->parseCurrentBlock();
192 
193  return $tpl->get();
194  }
195 
199  protected function getMultiEditHelp(): string
200  {
201  $lng = $this->lng;
202  $lng->loadLanguageModule("content");
203  $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "Services/COPage/Editor");
204  $tpl->setCurrentBlock("multi-help");
205  $tpl->setVariable("TXT_SEL", $lng->txt("cont_click_multi_select"));
206  $tpl->parseCurrentBlock();
207 
208  return $tpl->get();
209  }
210 
211  protected function getTopActions(): string
212  {
213  $ui = $this->ui;
214  $ctrl = $this->ctrl;
215  $lng = $this->lng;
216  $lng->loadLanguageModule("content");
217  $tpl = new \ilTemplate("tpl.top_actions.html", true, true, "Services/COPage/Editor");
218 
219  $dd = $this->getActionsDropDown();
220  $tpl->setVariable("DROPDOWN", $ui->renderer()->renderAsync($dd));
221 
222  if ($this->page_gui->getPageObject()->getEffectiveEditLockTime() > 0) {
223  $mess = $this->page_gui->getBlockingInfoMessage();
224  $tpl->setVariable("MESSAGE", $mess);
225  $b = $ui->factory()->button()->standard(
226  $lng->txt("cont_finish_editing"),
227  $ctrl->getLinkTarget($this->page_gui, "releasePageLock")
228  );
229  } else {
230  $b = $ui->factory()->button()->standard(
231  $lng->txt("cont_finish_editing"),
232  $ctrl->getLinkTarget($this->page_gui, "finishEditing")
233  );
234  }
235  $tpl->setVariable("MESSAGE2", $this->getMultiLangInfo());
236  $tpl->setVariable("QUIT_BUTTON", $ui->renderer()->renderAsync($b));
237 
238  $html = $this->ui_wrapper->getRenderedViewControl(
239  [
240  ["Page", "switch.single", $lng->txt("cont_edit_comp")],
241  ["Page", "switch.multi", $lng->txt("cont_edit_multi")]
242  ]
243  );
244  $tpl->setVariable("SWITCH", $html);
245  $tpl->setVariable("SRC_LOADER", \ilUtil::getImagePath("media/loader.svg"));
246 
247  return $tpl->get();
248  }
249 
250  public function getActionsDropDown(): \ILIAS\UI\Component\Dropdown\Standard
251  {
252  $ui = $this->ui;
253  $user = $this->user;
254  $config = $this->page_gui->getPageConfig();
255  $page = $this->page_gui->getPageObject();
256  $ctrl = $this->ctrl;
257  $lng = $this->lng;
258 
259  // determine media, html and javascript mode
260  $sel_media_mode = ($user->getPref("ilPageEditor_MediaMode") != "disable");
261  $sel_html_mode = ($user->getPref("ilPageEditor_HTMLMode") != "disable");
262  $items = [];
263 
264  // activate/deactivate
265  if ($config->getEnableActivation()) {
266  $captions = $this->page_gui->getActivationCaptions();
267 
268  if ($page->getActive()) {
269  $items[] = $ui->factory()->link()->standard(
270  $captions["deactivatePage"],
271  $ctrl->getLinkTarget($this->page_gui, "deactivatePage")
272  );
273  } else {
274  $items[] = $ui->factory()->link()->standard(
275  $captions["activatePage"],
276  $ctrl->getLinkTarget($this->page_gui, "activatePage")
277  );
278  }
279  }
280 
281  // initially opened content
282  if ($config->getUseAttachedContent()) {
283  $items[] = $ui->factory()->link()->standard(
284  $lng->txt("cont_initial_attached_content"),
285  $ctrl->getLinkTarget($this->page_gui, "initialOpenedContent")
286  );
287  }
288 
289  // multi-lang actions
290  foreach ($this->getMultiLangActions() as $item) {
291  $items[] = $item;
292  }
293 
294  $lng->loadLanguageModule("content");
295 
296  // media mode
297  if ($sel_media_mode) {
298  $ctrl->setParameter($this->page_gui, "media_mode", "disable");
299  $items[] = $ui->factory()->link()->standard(
300  $lng->txt("cont_deactivate_media"),
301  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
302  );
303  } else {
304  $ctrl->setParameter($this->page_gui, "media_mode", "enable");
305  $items[] = $ui->factory()->link()->standard(
306  $lng->txt("cont_activate_media"),
307  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
308  );
309  }
310  $ctrl->setParameter($this, "media_mode", "");
311 
312  // html mode
313  if (!$config->getPreventHTMLUnmasking()) {
314  if ($sel_html_mode) {
315  $ctrl->setParameter($this->page_gui, "html_mode", "disable");
316  $items[] = $ui->factory()->link()->standard(
317  $lng->txt("cont_deactivate_html"),
318  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
319  );
320  } else {
321  $ctrl->setParameter($this->page_gui, "html_mode", "enable");
322  $items[] = $ui->factory()->link()->standard(
323  $lng->txt("cont_activate_html"),
324  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
325  );
326  }
327  }
328  $ctrl->setParameter($this->page_gui, "html_mode", "");
329 
330  $lm_set = new \ilSetting("lm");
331  if ($this->page_gui->getEnableEditing() && $this->user->getId() != ANONYMOUS_USER_ID) {
332  // history
333  if ($lm_set->get("page_history", 1)) {
334  $items[] = $ui->factory()->link()->standard(
335  $lng->txt("history"),
336  $ctrl->getLinkTarget($this->page_gui, "history")
337  );
338  }
339 
340  if ($config->getEnableScheduledActivation()) {
341  $items[] = $ui->factory()->link()->standard(
342  $lng->txt("cont_activation"),
343  $ctrl->getLinkTarget($this->page_gui, "editActivation")
344  );
345  }
346 
347  // clipboard
348  $items[] = $ui->factory()->link()->standard(
349  $lng->txt("clipboard"),
350  $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilEditClipboardGUI"], "view")
351  );
352 
353  if ($this->page_gui->getEnabledNews()) {
354  $items[] = $ui->factory()->link()->standard(
355  $lng->txt("news"),
356  $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilnewsitemgui"], "editNews")
357  );
358  }
359 
360  if (($md_link = $this->page_gui->getMetaDataLink()) !== "") {
361  $items[] = $ui->factory()->link()->standard(
362  $lng->txt("meta_data"),
363  $md_link
364  );
365  }
366  }
367 
368  if ($this->page_gui->use_meta_data) {
369  $mdgui = new \ilObjectMetaDataGUI(
370  $this->page_gui->meta_data_rep_obj,
371  $this->page_gui->meta_data_type,
372  $this->page_gui->meta_data_sub_obj_id
373  );
374  $mdtab = $mdgui->getTab();
375  if ($mdtab) {
376  $items[] = $ui->factory()->link()->standard(
377  $lng->txt("meta_data"),
378  $mdtab
379  );
380  }
381  }
382 
383 
384  if ($this->page_gui->getEnabledNews()) {
385  $items[] = $ui->factory()->link()->standard(
386  $lng->txt("news"),
387  $ctrl->getLinkTargetByClass([get_class($this->page_gui), \ilNewsItemGUI::class], "editNews")
388  );
389  }
390 
391 
392  // additional page actions
393  foreach ($this->page_gui->getAdditionalPageActions() as $item) {
394  $items[] = $item;
395  }
396 
397  return $ui->factory()->dropdown()->standard($items);
398  }
399 
403  public function getMultiLangActions(): array
404  {
405  $config = $this->page_gui->getPageConfig();
406  $page = $this->page_gui->getPageObject();
407  $ctrl = $this->ctrl;
408  $ui = $this->ui;
409  $lng = $this->lng;
410 
411  $items = [];
412 
413 
414  // general multi lang support and single page mode?
415  if ($config->getMultiLangSupport()) {
416  $ot = \ilObjectTranslation::getInstance($page->getParentId());
417 
418  if ($ot->getContentActivated()) {
419  $lng->loadLanguageModule("meta");
420 
421  if ($page->getLanguage() != "-") {
422  $l = $ot->getMasterLanguage();
423  $items[] = $ui->factory()->link()->standard(
424  $lng->txt("cont_edit_language_version") . ": " .
425  $lng->txt("meta_l_" . $l),
426  $ctrl->getLinkTarget($this->page_gui, "editMasterLanguage")
427  );
428  }
429 
430  foreach ($ot->getLanguages() as $al => $lang) {
431  if ($page->getLanguage() != $al &&
432  $al != $ot->getMasterLanguage()) {
433  $ctrl->setParameter($this->page_gui, "totransl", $al);
434  $items[] = $ui->factory()->link()->standard(
435  $lng->txt("cont_edit_language_version") . ": " .
436  $lng->txt("meta_l_" . $al),
437  $ctrl->getLinkTarget($this->page_gui, "switchToLanguage")
438  );
439  $ctrl->setParameter($this->page_gui, "totransl", "");
440  }
441  }
442  }
443  }
444 
445  return $items;
446  }
447 
448  public function getMultiLangInfo(): string
449  {
450  $info = "";
451 
452  $config = $this->page_gui->getPageConfig();
453  $page = $this->page_gui->getPageObject();
454  $lng = $this->lng;
455  $ui = $this->ui;
456 
457  // general multi lang support and single page mode?
458  if ($config->getMultiLangSupport()) {
459  $ot = \ilObjectTranslation::getInstance($page->getParentId());
460 
461  if ($ot->getContentActivated()) {
462  $lng->loadLanguageModule("meta");
463 
464  $ml_gui = new \ilPageMultiLangGUI(
465  $page->getParentType(),
466  $page->getParentId()
467  );
468  $info = $ml_gui->getMultiLangInfo($page->getLanguage());
469  $info = $ui->renderer()->renderAsync($ui->factory()->messageBox()->info($info));
470  }
471  }
472 
473  return $info;
474  }
475 
476  protected function getMultiActions(): string
477  {
478  $groups = [
479  [
480  "cut" => "cut",
481  "copy" => "copy",
482  "delete" => "delete"
483  ],
484  [
485  "all" => "select_all",
486  "none" => "cont_select_none",
487  ],
488  [
489  "activate" => "cont_ed_enable",
490  "characteristic" => "cont_assign_characteristic"
491  ]
492  ];
493 
494  return $this->ui_wrapper->getRenderedButtonGroups($groups);
495  }
496 
500  protected function getPasteMessage(): string
501  {
502  $lng = $this->lng;
503 
504  $html = $this->ui_wrapper->getRenderedInfoBox($lng->txt("cont_sel_el_use_paste"));
505 
506  return $html;
507  }
508 
512  protected function getErrorMessage(): string
513  {
514  $html = $this->ui_wrapper->getRenderedFailureBox();
515 
516  return $html;
517  }
518 
519  protected function getErrorModalMessage(): string
520  {
521  $html = $this->ui_wrapper->getRenderedModalFailureBox();
522 
523  return $html;
524  }
525 
526  protected function getFormatSelection(): string
527  {
528  $lng = $this->lng;
529  $ui = $this->ui;
530  $tpl = new \ilTemplate("tpl.format_selection.html", true, true, "Services/COPage/Editor");
531  $tpl->setVariable("TXT_PAR", $lng->txt("cont_choose_characteristic_text"));
532  $tpl->setVariable("TXT_SECTION", $lng->txt("cont_choose_characteristic_section"));
533  $tpl->setVariable("TXT_MEDIA", $lng->txt("cont_media"));
534 
535  $par_sel = new ParagraphStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
536  $tpl->setVariable("PAR_SELECTOR", $ui->renderer()->renderAsync($par_sel->getStyleSelector("", "format", "format.paragraph", "format")));
537 
538  $sec_sel = new SectionStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
539  $tpl->setVariable("SEC_SELECTOR", $ui->renderer()->renderAsync($sec_sel->getStyleSelector("", "format", "format.section", "format")));
540 
541  $med_sel = new MediaObjectStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
542  $tpl->setVariable("MEDIA_SELECTOR", $ui->renderer()->renderAsync($med_sel->getStyleSelector("", "format", "format.media", "format")));
543 
544  $tpl->setVariable(
545  "SAVE_BUTTON",
546  $this->ui_wrapper->getRenderedButton(
547  $lng->txt("save"),
548  "format",
549  "format.save"
550  )
551  );
552  $tpl->setVariable(
553  "CANCEL_BUTTON",
554  $this->ui_wrapper->getRenderedButton(
555  $lng->txt("cancel"),
556  "format",
557  "format.cancel"
558  )
559  );
560  return $tpl->get();
561  }
562 
563 
567  protected function getPCModel(): array
568  {
569  return $this->page_gui->getPageObject()->getPCModel();
570  }
571 
572  protected function componentEditFormResponse(array $query): Server\Response
573  {
574  $pc_edit = $this->pc_definition->getPCEditorInstanceByName($query["cname"]);
575  $form = "";
576  if (!is_null($pc_edit)) {
577  $form = $pc_edit->getEditComponentForm(
578  $this->ui_wrapper,
579  $this->page_gui->getPageObject()->getParentType(),
581  $this->page_gui->getStyleId(),
582  $query["pcid"]
583  );
584  }
585  $o = new \stdClass();
586  $o->editForm = $form;
587  return new Server\Response($o);
588  }
589 
593  protected function getComponentsEditorUI(): array
594  {
595  $ui = [];
596  $config = $this->page_gui->getPageConfig();
597  foreach ($this->pc_definition->getPCDefinitions() as $def) {
598  $pc_edit = $this->pc_definition->getPCEditorInstanceByName($def["name"]);
599  if ($config->getEnablePCType($def["name"])) {
600  if (!is_null($pc_edit)) {
601  $ui[$def["name"]] = $pc_edit->getEditorElements(
602  $this->ui_wrapper,
603  $this->page_gui->getPageObject()->getParentType(),
605  $this->page_gui->getStyleId()
606  );
607  }
608  }
609  }
610  return $ui;
611  }
612 
613  protected function getComponentsDefinitions(): array
614  {
615  $pcdef = [];
616  foreach ($this->pc_definition->getPCDefinitions() as $def) {
617  $pcdef["types"][$def["name"]] = $def["pc_type"];
618  $pcdef["names"][$def["pc_type"]] = $def["name"];
619  $pcdef["txt"][$def["pc_type"]] = $this->lng->txt("cont_" . "pc_" . $def["pc_type"]);
620  }
621  return $pcdef;
622  }
623 
624  public function getModalTemplate(): array
625  {
626  $ui = $this->ui;
627  $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy('#content#'))
628  ->withActionButtons([
629  $ui->factory()->button()->standard('#button_title#', '#'),
630  ]);
631  $modalt["signal"] = $modal->getShowSignal()->getId();
632  $modalt["template"] = $ui->renderer()->renderAsync($modal);
633 
634  return $modalt;
635  }
636 
640  public function getConfirmationTemplate(): string
641  {
642  $ui = $this->ui;
643 
644  $confirmation = $ui->factory()->messageBox()->confirmation("#text#");
645 
646  return $ui->renderer()->renderAsync($confirmation);
647  }
648 
652  protected function getAutoSaveInterval(): int
653  {
654  $aset = new \ilSetting("adve");
655  return (int) $aset->get("autosave");
656  }
657 }
getPasteMessage()
Confirmation screen for cut/paste step.
const ANONYMOUS_USER_ID
Definition: constants.php:27
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...
Class ChatMainBarProvider .
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Class ilPageObjectGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMultiLangActions()
Add multi-language actions to menu.
loadLanguageModule(string $a_module)
Load language module.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Page editor json server.
static getInstance(int $obj_id)
$txt
Definition: error.php:14
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
$lang
Definition: xapiexit.php:26
$lm_set
getErrorMessage()
Confirmation screen for cut/paste step.
__construct(\ilPageObjectGUI $page_gui, string $pc_id="")
$r