ILIAS  release_7 Revision v7.30-3-g800a261c036
class.MediaObjectCommandActionHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
6 
9 
14 {
18  protected $ui;
19 
23  protected $lng;
24 
28  protected $page_gui;
29 
33  protected $user;
34 
38  protected $ui_wrapper;
39 
41  {
42  global $DIC;
43 
44  $this->ui = $DIC->ui();
45  $this->lng = $DIC->language();
46  $this->page_gui = $page_gui;
47  $this->user = $DIC->user();
48 
49  $this->ui_wrapper = new Server\UIWrapper($this->ui, $this->lng);
50  }
51 
57  public function handle($query, $body) : Server\Response
58  {
59  switch ($body["action"]) {
60  case "insert":
61  return $this->insertCommand($body);
62  break;
63 
64  case "update":
65  return $this->updateCommand($body);
66  break;
67 
68  default:
69  throw new Exception("Unknown action " . $body["action"]);
70  break;
71  }
72  }
73 
79  protected function insertCommand($body) : Server\Response
80  {
81  $page = $this->page_gui->getPageObject();
82 
83  $hier_id = "pg";
84  $pc_id = "";
85  if (!in_array($body["after_pcid"], ["", "pg"])) {
86  $hier_ids = $page->getHierIdsForPCIds([$body["after_pcid"]]);
87  $hier_id = $hier_ids[$body["after_pcid"]];
88  $pc_id = $body["after_pcid"];
89  }
90 
91 
92  // if (!$mob_gui->checkFormInput()) {
93  $pc_media = new \ilPCMediaObject($page);
94  $pc_media->createMediaObject();
95  $mob = $pc_media->getMediaObject();
97  $pc_media->createAlias($page, $hier_id, $pc_id);
98  $updated = $page->update();
99 
100  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
101  }
102 
108  protected function updateCommand($body) : Server\Response
109  {
110  $page = $this->page_gui->getPageObject();
111  $pc_media = $page->getContentObjectForPcId($body["pcid"]);
112 
113  $quick_edit = new \ilPCMediaObjectQuickEdit($pc_media);
114 
115  $quick_edit->setTitle(\ilUtil::stripSlashes($body["standard_title"]));
116  $quick_edit->setClass(\ilUtil::stripSlashes($body["characteristic"]));
117  $quick_edit->setHorizontalAlign(\ilUtil::stripSlashes($body["horizontal_align"]));
118 
119  $quick_edit->setUseFullscreen((bool) ($body["fullscreen"]));
120  $quick_edit->setCaption(\ilUtil::stripSlashes($body["standard_caption"]));
121  $quick_edit->setTextRepresentation(\ilUtil::stripSlashes($body["text_representation"]));
122 
123  $pc_media->getMediaObject()->update();
124  $updated = $page->update();
125 
126  return $this->ui_wrapper->sendPage($this->page_gui, $updated);
127  }
128 }
static setObjectPerCreationForm($a_mob)
Set media object values from creation form.
Class ilPageObjectGUI.
user()
Definition: user.php:4
Page editor json server.
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5
$query
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled