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