ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  $dd_html = preg_replace('/\s*id="[^"]*"/', '', $r->render($dd));
90  $r->renderAsync($dd); // this prevents further buttons to get the dd JS attached
91  $o->dropdown = $dd_html;
92  $o->addCommands = $this->getAddCommands();
93  $o->pageEditHelp = $this->getPageEditHelp();
94  $o->multiEditHelp = $this->getMultiEditHelp();
95  $o->pageTopActions = $this->getTopActions();
96  $o->multiActions = $this->getMultiActions();
97  $o->pasteMessage = $this->getPasteMessage();
98  $o->errorMessage = $this->getErrorMessage();
99  $o->errorModalMessage = $this->getErrorModalMessage();
100  $o->config = $this->getConfig();
101  $o->components = $this->getComponentsEditorUI();
102  $o->pcModel = $this->getPCModel();
103  $o->pcDefinition = $this->getComponentsDefinitions();
104  $o->formatSelection = $this->getFormatSelection();
105  $o->modal = $this->getModalTemplate();
106  $o->confirmation = $this->getConfirmationTemplate();
107  $o->autoSaveInterval = $this->getAutoSaveInterval();
108  $o->backUrl = $ctrl->getLinkTarget($this->page_gui, "edit");
109  $o->pasting = in_array(\ilEditClipboard::getAction(), ["copy", "cut"]) &&
110  count($this->user->getPCClipboardContent()) > 0;
111  $o->loaderUrl = \ilUtil::getImagePath("media/loader.svg");
112 
113  if ($this->pc_id !== "") {
114  $type = $this->page_gui->getPageObject()->getContentObjectForPcId($this->pc_id)->getType();
115  $def = $this->pc_definition->getPCDefinitionByType($type);
116  $o->initialComponent = $def["name"];
117  $o->initialPCId = $this->pc_id;
118  } else {
119  $o->initialComponent = "";
120  $o->initialPCId = "";
121  }
122 
123  return new Server\Response($o);
124  }
125 
126  protected function getConfig(): \stdClass
127  {
128  $config = new \stdClass();
129  $config->user = $this->user->getLogin();
130  $config->content_css =
131  \ilObjStyleSheet::getContentStylePath($this->page_gui->getStyleId()) . ", " .
133  "./components/ILIAS/COPage/css/tiny_extra.css";
134  $config->text_formats = \ilPCParagraphGUI::_getTextCharacteristics($this->page_gui->getStyleId());
135  $config->text_block_formats = [];
136  foreach (["text_block", "heading1", "heading2", "heading3"] as $type) {
137  $dummy_pc = new \ilPCParagraphGUI($this->page_gui->getPageObject(), null, "");
138  $dummy_pc->setStyleId($this->page_gui->getStyleId());
139  $dummy_pc->getCharacteristicsOfCurrentStyle([$type]);
140  foreach ($dummy_pc->getCharacteristics() as $char => $txt) {
141  $config->text_block_formats[$char] = $txt;
142  }
143  }
144  $config->editPlaceholders = $this->page_gui->getPageConfig()->getEnablePCType("PlaceHolder");
145  $config->activatedProtection =
146  ($this->page_gui->getPageConfig()->getSectionProtection() == \ilPageConfig::SEC_PROTECT_PROTECTED);
147 
148  return $config;
149  }
150 
151  protected function getAddCommands(): array
152  {
153  $lng = $this->lng;
154 
155  $commands = [];
156 
157  // content types
158  $config = $this->page_gui->getPageConfig();
159  foreach ($config->getEnabledTopPCTypes() as $def) {
160  $commands[$def["pc_type"]] = $lng->txt("cont_ed_insert_" . $def["pc_type"]);
161  }
162 
163  // content templates
164  if (count($this->page_gui->getPageObject()->getContentTemplates()) > 0) {
165  $commands["templ"] = $lng->txt("cont_ed_insert_templ");
166  }
167 
168  // plugins
169  foreach ($this->component_factory->getActivePluginsInSlot("pgcp") as $plugin) {
170  if ($plugin->isValidParentType($this->page_gui->getPageObject()->getParentType())) {
171  $commands["plug_" . $plugin->getPluginName()] =
173  }
174  }
175  return $commands;
176  }
177 
181  protected function getPageEditHelp(): string
182  {
183  $lng = $this->lng;
184  $lng->loadLanguageModule("content");
185  $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "components/ILIAS/COPage/Editor");
186  $tpl->setCurrentBlock("help");
187  $tpl->setVariable("TXT_ADD_EL", $lng->txt("cont_add_elements"));
188  $tpl->setVariable("PLUS", $this->gui->symbol()->glyph("add")->render());
189  $tpl->setVariable("DRAG_ARROW", $this->gui->symbol()->glyph("next")->render());
190  $tpl->setVariable("TXT_DRAG", $lng->txt("cont_drag_and_drop_elements"));
191  $tpl->setVariable("TXT_EDIT", $lng->txt("cont_click_edit"));
192  $tpl->setVariable("TXT_SEL", $lng->txt("cont_shift_click_to_select"));
193  $tpl->parseCurrentBlock();
194 
195  return $tpl->get();
196  }
197 
201  protected function getMultiEditHelp(): string
202  {
203  $lng = $this->lng;
204  $lng->loadLanguageModule("content");
205  $tpl = new \ilTemplate("tpl.page_edit_help.html", true, true, "components/ILIAS/COPage/Editor");
206  $tpl->setCurrentBlock("multi-help");
207  $tpl->setVariable("TXT_SEL", $lng->txt("cont_click_multi_select"));
208  $tpl->parseCurrentBlock();
209 
210  return $tpl->get();
211  }
212 
213  protected function getTopActions(): string
214  {
215  $ui = $this->ui;
216  $ctrl = $this->ctrl;
217  $lng = $this->lng;
218  $lng->loadLanguageModule("content");
219  $tpl = new \ilTemplate("tpl.top_actions.html", true, true, "components/ILIAS/COPage/Editor");
220 
221  $dd = $this->getActionsDropDown();
222  $tpl->setVariable("DROPDOWN", $ui->renderer()->renderAsync($dd));
223 
224  if ($this->page_gui->getPageObject()->getEffectiveEditLockTime() > 0) {
225  $mess = $this->page_gui->getBlockingInfoMessage();
226  $tpl->setVariable("MESSAGE", $mess);
227  $b = $ui->factory()->button()->standard(
228  $lng->txt("cont_finish_editing"),
229  $ctrl->getLinkTarget($this->page_gui, "releasePageLock")
230  );
231  } else {
232  $b = $ui->factory()->button()->standard(
233  $lng->txt("cont_finish_editing"),
234  $ctrl->getLinkTarget($this->page_gui, "finishEditing")
235  );
236  }
237  $tpl->setVariable("MESSAGE2", $this->getMultiLangInfo());
238  $tpl->setVariable("QUIT_BUTTON", $ui->renderer()->renderAsync($b));
239 
240  $html = $this->ui_wrapper->getRenderedViewControl(
241  [
242  ["Page", "switch.single", $lng->txt("cont_edit_comp")],
243  ["Page", "switch.multi", $lng->txt("cont_edit_multi")]
244  ]
245  );
246  $tpl->setVariable("SWITCH", $html);
247  $tpl->setVariable("SRC_LOADER", \ilUtil::getImagePath("media/loader.svg"));
248 
249  return $tpl->get();
250  }
251 
252  public function getActionsDropDown(): \ILIAS\UI\Component\Dropdown\Standard
253  {
254  $ui = $this->ui;
255  $user = $this->user;
256  $config = $this->page_gui->getPageConfig();
257  $page = $this->page_gui->getPageObject();
258  $ctrl = $this->ctrl;
259  $lng = $this->lng;
260 
261  // determine media, html and javascript mode
262  $sel_media_mode = ($user->getPref("ilPageEditor_MediaMode") != "disable");
263  $sel_html_mode = ($user->getPref("ilPageEditor_HTMLMode") != "disable");
264  $items = [];
265 
266  // activate/deactivate
267  if ($config->getEnableActivation()) {
268  $captions = $this->page_gui->getActivationCaptions();
269 
270  if ($page->getActive()) {
271  $items[] = $ui->factory()->link()->standard(
272  $captions["deactivatePage"],
273  $ctrl->getLinkTarget($this->page_gui, "deactivatePage")
274  );
275  } else {
276  $items[] = $ui->factory()->link()->standard(
277  $captions["activatePage"],
278  $ctrl->getLinkTarget($this->page_gui, "activatePage")
279  );
280  }
281  }
282 
283  // initially opened content
284  if ($config->getUseAttachedContent()) {
285  $items[] = $ui->factory()->link()->standard(
286  $lng->txt("cont_initial_attached_content"),
287  $ctrl->getLinkTarget($this->page_gui, "initialOpenedContent")
288  );
289  }
290 
291  // multi-lang actions
292  foreach ($this->getMultiLangActions() as $item) {
293  $items[] = $item;
294  }
295 
296  $lng->loadLanguageModule("content");
297 
298  // media mode
299  if ($sel_media_mode) {
300  $ctrl->setParameter($this->page_gui, "media_mode", "disable");
301  $items[] = $ui->factory()->link()->standard(
302  $lng->txt("cont_deactivate_media"),
303  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
304  );
305  } else {
306  $ctrl->setParameter($this->page_gui, "media_mode", "enable");
307  $items[] = $ui->factory()->link()->standard(
308  $lng->txt("cont_activate_media"),
309  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
310  );
311  }
312  $ctrl->setParameter($this, "media_mode", "");
313 
314  // html mode
315  if (!$config->getPreventHTMLUnmasking()) {
316  if ($sel_html_mode) {
317  $ctrl->setParameter($this->page_gui, "html_mode", "disable");
318  $items[] = $ui->factory()->link()->standard(
319  $lng->txt("cont_deactivate_html"),
320  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
321  );
322  } else {
323  $ctrl->setParameter($this->page_gui, "html_mode", "enable");
324  $items[] = $ui->factory()->link()->standard(
325  $lng->txt("cont_activate_html"),
326  $ctrl->getLinkTarget($this->page_gui, "setEditMode")
327  );
328  }
329  }
330  $ctrl->setParameter($this->page_gui, "html_mode", "");
331 
332  $lm_set = new \ilSetting("lm");
333  if ($this->page_gui->getEnableEditing() && $this->user->getId() != ANONYMOUS_USER_ID) {
334  // history
335  if ($lm_set->get("page_history", 1)) {
336  $items[] = $ui->factory()->link()->standard(
337  $lng->txt("history"),
338  $ctrl->getLinkTarget($this->page_gui, "history")
339  );
340  }
341 
342  if ($config->getEnableScheduledActivation()) {
343  $items[] = $ui->factory()->link()->standard(
344  $lng->txt("cont_activation"),
345  $ctrl->getLinkTarget($this->page_gui, "editActivation")
346  );
347  }
348 
349  // clipboard
350  $items[] = $ui->factory()->link()->standard(
351  $lng->txt("clipboard"),
352  $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilEditClipboardGUI"], "view")
353  );
354 
355  if ($this->page_gui->getEnabledNews()) {
356  $items[] = $ui->factory()->link()->standard(
357  $lng->txt("news"),
358  $ctrl->getLinkTargetByClass([get_class($this->page_gui), "ilnewsitemgui"], "editNews")
359  );
360  }
361 
362  if (($md_link = $this->page_gui->getMetaDataLink()) !== "") {
363  $items[] = $ui->factory()->link()->standard(
364  $lng->txt("meta_data"),
365  $md_link
366  );
367  }
368  }
369 
370  if ($this->page_gui->use_meta_data) {
371  $mdgui = new \ilObjectMetaDataGUI(
372  $this->page_gui->meta_data_rep_obj,
373  $this->page_gui->meta_data_type,
374  $this->page_gui->meta_data_sub_obj_id
375  );
376  $mdtab = $mdgui->getTab();
377  if ($mdtab) {
378  $items[] = $ui->factory()->link()->standard(
379  $lng->txt("meta_data"),
380  $mdtab
381  );
382  }
383  }
384 
385 
386  if ($this->page_gui->getEnabledNews()) {
387  $items[] = $ui->factory()->link()->standard(
388  $lng->txt("news"),
389  $ctrl->getLinkTargetByClass([get_class($this->page_gui), \ilNewsItemGUI::class], "editNews")
390  );
391  }
392 
393 
394  // additional page actions
395  foreach ($this->page_gui->getAdditionalPageActions() as $item) {
396  $items[] = $item;
397  }
398 
399  return $ui->factory()->dropdown()->standard($items);
400  }
401 
405  public function getMultiLangActions(): array
406  {
407  $config = $this->page_gui->getPageConfig();
408  $page = $this->page_gui->getPageObject();
409  $ctrl = $this->ctrl;
410  $ui = $this->ui;
411  $lng = $this->lng;
412 
413  $items = [];
414 
415 
416  // general multi lang support and single page mode?
417  if ($config->getMultiLangSupport()) {
418  $ot = \ilObjectTranslation::getInstance($page->getParentId());
419 
420  if ($ot->getContentActivated()) {
421  $lng->loadLanguageModule("meta");
422 
423  if ($page->getLanguage() != "-") {
424  $l = $ot->getMasterLanguage();
425  $items[] = $ui->factory()->link()->standard(
426  $lng->txt("cont_edit_language_version") . ": " .
427  $lng->txt("meta_l_" . $l),
428  $ctrl->getLinkTarget($this->page_gui, "editMasterLanguage")
429  );
430  }
431 
432  foreach ($ot->getLanguages() as $al => $lang) {
433  if ($page->getLanguage() != $al &&
434  $al != $ot->getMasterLanguage()) {
435  $ctrl->setParameter($this->page_gui, "totransl", $al);
436  $items[] = $ui->factory()->link()->standard(
437  $lng->txt("cont_edit_language_version") . ": " .
438  $lng->txt("meta_l_" . $al),
439  $ctrl->getLinkTarget($this->page_gui, "switchToLanguage")
440  );
441  $ctrl->setParameter($this->page_gui, "totransl", "");
442  }
443  }
444  }
445  }
446 
447  return $items;
448  }
449 
450  public function getMultiLangInfo(): string
451  {
452  $info = "";
453 
454  $config = $this->page_gui->getPageConfig();
455  $page = $this->page_gui->getPageObject();
456  $lng = $this->lng;
457  $ui = $this->ui;
458 
459  // general multi lang support and single page mode?
460  if ($config->getMultiLangSupport()) {
461  $ot = \ilObjectTranslation::getInstance($page->getParentId());
462 
463  if ($ot->getContentActivated()) {
464  $lng->loadLanguageModule("meta");
465 
466  $ml_gui = new \ilPageMultiLangGUI(
467  $page->getParentType(),
468  $page->getParentId()
469  );
470  $info = $ml_gui->getMultiLangInfo($page->getLanguage());
471  $info = $ui->renderer()->renderAsync($ui->factory()->messageBox()->info($info));
472  }
473  }
474 
475  return $info;
476  }
477 
478  protected function getMultiActions(): string
479  {
480  $groups = [
481  [
482  "cut" => "cut",
483  "copy" => "copy",
484  "delete" => "delete"
485  ],
486  [
487  "all" => "select_all",
488  "none" => "cont_select_none",
489  ],
490  [
491  "activate" => "cont_ed_enable",
492  "characteristic" => "cont_assign_characteristic"
493  ]
494  ];
495 
496  return $this->ui_wrapper->getRenderedButtonGroups($groups);
497  }
498 
502  protected function getPasteMessage(): string
503  {
504  $lng = $this->lng;
505 
506  $html = $this->ui_wrapper->getRenderedInfoBox($lng->txt("cont_sel_el_use_paste"));
507 
508  return $html;
509  }
510 
514  protected function getErrorMessage(): string
515  {
516  $html = $this->ui_wrapper->getRenderedFailureBox();
517 
518  return $html;
519  }
520 
521  protected function getErrorModalMessage(): string
522  {
523  $html = $this->ui_wrapper->getRenderedModalFailureBox();
524 
525  return $html;
526  }
527 
528  protected function getFormatSelection(): string
529  {
530  $lng = $this->lng;
531  $ui = $this->ui;
532  $tpl = new \ilTemplate("tpl.format_selection.html", true, true, "components/ILIAS/COPage/Editor");
533  $tpl->setVariable("TXT_PAR", $lng->txt("cont_choose_characteristic_text"));
534  $tpl->setVariable("TXT_SECTION", $lng->txt("cont_choose_characteristic_section"));
535  $tpl->setVariable("TXT_MEDIA", $lng->txt("cont_media"));
536 
537  $par_sel = new ParagraphStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
538  $tpl->setVariable("PAR_SELECTOR", $ui->renderer()->renderAsync($par_sel->getStyleSelector("", "format", "format.paragraph", "format")));
539 
540  $sec_sel = new SectionStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
541  $tpl->setVariable("SEC_SELECTOR", $ui->renderer()->renderAsync($sec_sel->getStyleSelector("", "format", "format.section", "format")));
542 
543  $med_sel = new MediaObjectStyleSelector($this->ui_wrapper, $this->page_gui->getStyleId());
544  $tpl->setVariable("MEDIA_SELECTOR", $ui->renderer()->renderAsync($med_sel->getStyleSelector("", "format", "format.media", "format")));
545 
546  $tpl->setVariable(
547  "SAVE_BUTTON",
548  $this->ui_wrapper->getRenderedButton(
549  $lng->txt("save"),
550  "format",
551  "format.save"
552  )
553  );
554  $tpl->setVariable(
555  "CANCEL_BUTTON",
556  $this->ui_wrapper->getRenderedButton(
557  $lng->txt("cancel"),
558  "format",
559  "format.cancel"
560  )
561  );
562  return $tpl->get();
563  }
564 
565 
569  protected function getPCModel(): array
570  {
571  return $this->page_gui->getPageObject()->getPCModel();
572  }
573 
574  protected function componentEditFormResponse(array $query): Server\Response
575  {
576  $pc_edit = $this->pc_definition->getPCEditorInstanceByName($query["cname"]);
577  $form = "";
578  if (!is_null($pc_edit)) {
579  $form = $pc_edit->getEditComponentForm(
580  $this->ui_wrapper,
581  $this->page_gui->getPageObject()->getParentType(),
583  $this->page_gui->getStyleId(),
584  $query["pcid"]
585  );
586  }
587  $o = new \stdClass();
588  $o->editForm = $form;
589  return new Server\Response($o);
590  }
591 
595  protected function getComponentsEditorUI(): array
596  {
597  $ui = [];
598  $config = $this->page_gui->getPageConfig();
599  foreach ($this->pc_definition->getPCDefinitions() as $def) {
600  $pc_edit = $this->pc_definition->getPCEditorInstanceByName($def["name"]);
601  if ($config->getEnablePCType($def["name"])) {
602  if (!is_null($pc_edit)) {
603  $ui[$def["name"]] = $pc_edit->getEditorElements(
604  $this->ui_wrapper,
605  $this->page_gui->getPageObject()->getParentType(),
607  $this->page_gui->getStyleId()
608  );
609  }
610  }
611  }
612  return $ui;
613  }
614 
615  protected function getComponentsDefinitions(): array
616  {
617  $pcdef = [];
618  foreach ($this->pc_definition->getPCDefinitions() as $def) {
619  $pcdef["types"][$def["name"]] = $def["pc_type"];
620  $pcdef["names"][$def["pc_type"]] = $def["name"];
621  $pcdef["txt"][$def["pc_type"]] = $this->lng->txt("cont_" . "pc_" . $def["pc_type"]);
622  }
623  return $pcdef;
624  }
625 
626  public function getModalTemplate(): array
627  {
628  $ui = $this->ui;
629  $modal = $ui->factory()->modal()->roundtrip('#title#', $ui->factory()->legacy()->content('#content#'))
630  ->withActionButtons([
631  $ui->factory()->button()->standard('#button_title#', '#'),
632  ]);
633  $modalt["signal"] = $modal->getShowSignal()->getId();
634  $modalt["closeSignal"] = $modal->getCloseSignal()->getId();
635  $modalt["template"] = $ui->renderer()->renderAsync($modal);
636 
637  return $modalt;
638  }
639 
643  public function getConfirmationTemplate(): string
644  {
645  $ui = $this->ui;
646 
647  $confirmation = $ui->factory()->messageBox()->confirmation("#text#");
648 
649  return $ui->renderer()->renderAsync($confirmation);
650  }
651 
655  protected function getAutoSaveInterval(): int
656  {
657  $aset = new \ilSetting("adve");
658  return (int) $aset->get("autosave");
659  }
660 }
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...
static getInstance(int $obj_id)
global $DIC
Definition: shib_login.php:22
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
$r