ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPCPlaceHolderGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  public const TYPE_TEXT = "Text";
28  public const TYPE_QUESTION = "Question";
29  public const TYPE_MEDIA = "Media";
30  public const TYPE_VERIFICATION = "Verification";
32 
33  public function __construct(
34  ilPageObject $a_pg_obj,
35  ?ilPageContent $a_content_obj,
36  string $a_hier_id,
37  string $a_pc_id = ""
38  ) {
39  global $DIC;
40 
41  $this->lng = $DIC->language();
42  $this->pg_obj = $a_pg_obj;
43  $this->content_obj = $a_content_obj;
44  $this->hier_id = $a_hier_id;
45  $this->pc_id = $a_pc_id;
46 
47  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
48  }
49 
50  public function executeCommand(): void
51  {
52  // get next class that processes or forwards current command
53  $next_class = $this->ctrl->getNextClass($this);
54  // get current command
55  $cmd = $this->ctrl->getCmd();
56 
57  switch ($next_class) {
58  case 'ilpcmediaobjectgui': //special handling
59  $media_gui = new ilPCMediaObjectGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
60  $ret = $this->ctrl->forwardCommand($media_gui);
61  break;
62 
63  default:
64  $this->$cmd();
65  break;
66  }
67  }
68 
69  protected function insert(): void
70  {
71  $this->propertyGUI("create", self::TYPE_TEXT, "100px", "insert");
72  }
73 
74  protected function create(): void
75  {
76  $plach_height = $this->request->getString("plach_height");
77  if ($plach_height == "" ||
78  !preg_match("/[0-9]+/", $plach_height)) {
79  $this->insert();
80  return;
81  }
82 
83  $this->content_obj = new ilPCPlaceHolder($this->getPage());
84  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
85  $this->content_obj->setHeight($plach_height . "px");
86  $this->content_obj->setContentClass(
87  $this->request->getString("plach_type")
88  );
89  $this->updated = $this->pg_obj->update();
90  if ($this->updated === true) {
91  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
92  } else {
93  $this->insert();
94  }
95  }
96 
97  public function edit(): void
98  {
99  if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
100  $this->edit_object();
101  } else {
102  $this->forward_edit();
103  }
104  }
105 
106  public function setStyleId(int $a_styleid): void
107  {
108  $this->styleid = $a_styleid;
109  }
110 
111  public function getStyleId(): int
112  {
113  return $this->styleid;
114  }
115 
116  protected function edit_object(): void
117  {
118  $this->propertyGUI(
119  "saveProperties",
120  $this->content_obj->getContentClass(),
121  $this->content_obj->getHeight(),
122  "save"
123  );
124  }
125 
126  protected function forward_edit(): void
127  {
128  switch ($this->content_obj->getContentClass()) {
129  case self::TYPE_MEDIA:
130  $this->ctrl->setCmdClass("ilpcmediaobjectgui");
131  $this->ctrl->setCmd("insert");
132  $media_gui = new ilPCMediaObjectGUI($this->pg_obj, null, "");
133  $this->ctrl->forwardCommand($media_gui);
134  break;
135 
136  case self::TYPE_TEXT:
137  $this->textCOSelectionGUI();
138  break;
139 
140  case self::TYPE_QUESTION:
141  $this->ctrl->setCmdClass("ilpcquestiongui");
142  $this->ctrl->setCmd("insert");
143  $question_gui = new ilPCQuestionGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
144  $question_gui->setSelfAssessmentMode(true);
145  $this->ctrl->forwardCommand($question_gui);
146  break;
147 
148  case self::TYPE_VERIFICATION:
149  $this->ctrl->setCmdClass("ilpcverificationgui");
150  $this->ctrl->setCmd("insert");
152  $ver = $this->content_obj;
153  $cert_gui = new ilPCVerificationGUI($this->pg_obj, $ver, $this->hier_id, $this->pc_id);
154  $this->ctrl->forwardCommand($cert_gui);
155  break;
156 
157  default:
158  break;
159  }
160  }
161 
162 
166  protected function saveProperties(): void
167  {
168  $plach_height = $this->request->getString("plach_height");
169  if ($plach_height == "" ||
170  !preg_match("/[0-9]+/", $plach_height)) {
171  $this->edit_object();
172  return;
173  }
174 
175  $this->content_obj->setContentClass($this->request->getString("plach_type"));
176  $this->content_obj->setHeight($plach_height . "px");
177 
178  $this->updated = $this->pg_obj->update();
179  if ($this->updated === true) {
180  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
181  } else {
182  $this->pg_obj->addHierIDs();
183  $this->edit();
184  }
185  }
186 
191  {
192  $lng = $this->lng;
193 
194  $this->form_gui = new ilPropertyFormGUI();
195  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
196  $this->form_gui->setTitle($lng->txt("cont_ed_plachprop"));
197 
198  $ttype_input = new ilRadioGroupInputGUI($lng->txt("type"), "plach_type");
199  $type_captions = $this->getTypeCaptions();
200  foreach ($this->getAvailableTypes("") as $type) {
201  $ttype_input->addOption(new ilRadioOption($type_captions[$type], $type));
202  }
203  $ttype_input->setValue("Text");
204  $ttype_input->setRequired(true);
205  $this->form_gui->addItem($ttype_input);
206 
207  /*
208  $theight_input = new ilTextInputGUI($lng->txt("height"), "plach_height");
209  $theight_input->setSize(4);
210  $theight_input->setMaxLength(3);
211  $theight_input->setTitle($lng->txt("height") . " (px)");
212  $theight_input->setRequired(true);
213  $this->form_gui->addItem($theight_input);
214 
215  $theight_input->setValue(preg_replace("/px/", "", $a_height));*/
216  if ($this->content_obj) {
217  $ttype_input->setValue($this->content_obj->getContentClass());
218  }
219 
220  $this->form_gui->addCommandButton("insert", $lng->txt("insert"));
221  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
222  return $this->form_gui;
223  }
224 
228  protected function insertPCText(): void
229  {
230  switch ($this->request->getString("pctext_type")) {
231  case 0: //Paragraph / Text
232 
233  $ret_class = strtolower(get_class($this->getPage()) . "gui");
234  $this->ctrl->setParameterByClass($ret_class, "pl_hier_id", $this->hier_id);
235  $this->ctrl->setParameterByClass($ret_class, "pl_pc_id", $this->pc_id);
236  $this->ctrl->redirectByClass(
237  $ret_class,
238  "insertJSAtPlaceholder"
239  );
240 
241  $this->ctrl->setCmdClass("ilpcparagraphgui");
242  $this->ctrl->setCmd("insert");
243  $paragraph_gui = new ilPCParagraphGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
244  $paragraph_gui->setStyleId($this->getStyleId());
245  $paragraph_gui->setPageConfig($this->getPageConfig());
246  $this->ctrl->forwardCommand($paragraph_gui);
247  break;
248 
249  case 1: //DataTable
250  $this->ctrl->setCmdClass("ilpcdatatablegui");
251  $this->ctrl->setCmd("insert");
252  $dtable_gui = new ilPCDataTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
253  $this->ctrl->forwardCommand($dtable_gui);
254  break;
255 
256  case 2: //Advanced Table
257  $this->ctrl->setCmdClass("ilpctablegui");
258  $this->ctrl->setCmd("insert");
259  $atable_gui = new ilPCTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
260  $this->ctrl->forwardCommand($atable_gui);
261  break;
262 
263  case 3: //Advanced List
264  $this->ctrl->setCmdClass("ilpclistgui");
265  $this->ctrl->setCmd("insert");
266  $list_gui = new ilPCListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
267  $this->ctrl->forwardCommand($list_gui);
268  break;
269 
270  case 4: //File List
271  $this->ctrl->setCmdClass("ilpcfilelistgui");
272  $this->ctrl->setCmd("insert");
273  $file_list_gui = new ilPCFileListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
274  $file_list_gui->setStyleId($this->getStyleId());
275  $this->ctrl->forwardCommand($file_list_gui);
276  break;
277 
278  case 5: //Tabs
279  $this->ctrl->setCmdClass("ilpctabsgui");
280  $this->ctrl->setCmd("insert");
281  $tabs_gui = new ilPCTabsGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
282  $tabs_gui->setStyleId($this->getStyleId());
283  $this->ctrl->forwardCommand($tabs_gui);
284  break;
285 
286  default:
287  break;
288  }
289  }
290 
291  public function cancel(): void
292  {
293  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
294  }
295 
296  protected function getAvailableTypes(
297  string $a_selected_type = ""
298  ): array {
299  // custom config?
300  if (method_exists($this->getPage()->getPageConfig(), "getAvailablePlaceholderTypes")) {
301  $types = $this->getPage()->getPageConfig()->getAvailablePlaceholderTypes();
302  } else {
303  $types = array(self::TYPE_TEXT, self::TYPE_MEDIA, self::TYPE_QUESTION);
304  }
305  return $types;
306  }
307 
308  protected function getTypeCaptions(): array
309  {
310  $lng = $this->lng;
311 
312  return array(
313  self::TYPE_TEXT => $lng->txt("cont_ed_plachtext"),
314  self::TYPE_MEDIA => $lng->txt("cont_ed_plachmedia"),
315  self::TYPE_QUESTION => $lng->txt("cont_ed_plachquestion"),
316  self::TYPE_VERIFICATION => $lng->txt("cont_ed_plachverification")
317  );
318  }
319 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAvailableTypes(string $a_selected_type="")
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...
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Content object of ilPageObject (see ILIAS DTD).
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
saveProperties()
save placeholder properties in db and return to page edit screen
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertPCText()
Forwards Text Item Selection to GUI classes.
initCreationForm()
Property Form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPCParagraphGUI User Interface for Paragraph Editing.