ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPCPlaceHolderGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPCPlaceHolder.php");
6require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7
21{
22 public $pg_obj;
24 public $hier_id;
25 public $pc_id;
26 protected $styleid;
27
28 const TYPE_TEXT = "Text";
29 const TYPE_QUESTION = "Question";
30 const TYPE_MEDIA = "Media";
31 const TYPE_VERIFICATION = "Verification";
32
37 public function __construct($a_pg_obj, $a_content_obj, $a_hier_id, $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
53 public function executeCommand()
54 {
55 // get next class that processes or forwards current command
56 $next_class = $this->ctrl->getNextClass($this);
57 // get current command
58 $cmd = $this->ctrl->getCmd();
59
60 switch ($next_class) {
61 case 'ilpcmediaobjectgui': //special handling
62 include_once("./Services/COPage/classes/class.ilPCMediaObjectGUI.php");
63 $media_gui = new ilPCMediaObjectGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
64 $ret = $this->ctrl->forwardCommand($media_gui);
65 break;
66
67 default:
68 $ret = $this->$cmd();
69 break;
70 }
71
72 return $ret;
73 }
74
78 protected function insert()
79 {
80 $this->propertyGUI("create", self::TYPE_TEXT, "100px", "insert");
81 }
82
86 protected function create()
87 {
88 if ($_POST["plach_height"] == "" ||
89 !preg_match("/[0-9]+/", $_POST["plach_height"])) {
90 return $this->insert();
91 }
92
93 $this->content_obj = new ilPCPlaceHolder($this->getPage());
94 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
95 $this->content_obj->setHeight($_POST["plach_height"] . "px");
96 $this->content_obj->setContentClass($_POST['plach_type']);
97 $this->updated = $this->pg_obj->update();
98 if ($this->updated === true) {
99 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
100 } else {
101 $this->insert();
102 }
103 }
104
108 public function edit()
109 {
110 if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
111 $this->edit_object();
112 } else {
113 $this->forward_edit();
114 }
115 }
116
122 public function setStyleId($a_styleid)
123 {
124 $this->styleid = $a_styleid;
125 }
126
132 public function getStyleId()
133 {
134 return $this->styleid;
135 }
136
140 protected function edit_object()
141 {
142 $this->propertyGUI(
143 "saveProperties",
144 $this->content_obj->getContentClass(),
145 $this->content_obj->getHeight(),
146 "save"
147 );
148 }
149
150 protected function forward_edit()
151 {
152 switch ($this->content_obj->getContentClass()) {
153 case self::TYPE_MEDIA:
154 include_once("./Services/COPage/classes/class.ilPCMediaObjectGUI.php");
155 $this->ctrl->setCmdClass("ilpcmediaobjectgui");
156 $this->ctrl->setCmd("insert");
157 $media_gui = new ilPCMediaObjectGUI($this->pg_obj, null);
158 $this->ctrl->forwardCommand($media_gui);
159 break;
160
161 case self::TYPE_TEXT:
162 $this->textCOSelectionGUI();
163 break;
164
166 include_once("./Services/COPage/classes/class.ilPCQuestionGUI.php");
167 $this->ctrl->setCmdClass("ilpcquestiongui");
168 $this->ctrl->setCmd("insert");
169 $question_gui = new ilPCQuestionGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
170 $question_gui->setSelfAssessmentMode(true);
171 $this->ctrl->forwardCommand($question_gui);
172 break;
173
175 include_once("./Services/COPage/classes/class.ilPCVerificationGUI.php");
176 $this->ctrl->setCmdClass("ilpcverificationgui");
177 $this->ctrl->setCmd("insert");
178 $cert_gui = new ilPCVerificationGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
179 $this->ctrl->forwardCommand($cert_gui);
180 break;
181
182 default:
183 break;
184 }
185 }
186
187
191 protected function saveProperties()
192 {
193 if ($_POST["plach_height"] == "" ||
194 !preg_match("/[0-9]+/", $_POST["plach_height"])) {
195 return $this->edit_object();
196 }
197
198 $this->content_obj->setContentClass($_POST['plach_type']);
199 $this->content_obj->setHeight($_POST["plach_height"] . "px");
200
201 $this->updated = $this->pg_obj->update();
202 if ($this->updated === true) {
203 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
204 } else {
205 $this->pg_obj->addHierIDs();
206 $this->edit();
207 }
208 }
209
213 protected function propertyGUI($a_action, $a_type, $a_height, $a_mode)
214 {
216
217 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
218 $this->form_gui = new ilPropertyFormGUI();
219 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
220 $this->form_gui->setTitle($lng->txt("cont_ed_plachprop"));
221
222 $ttype_input = new ilRadioGroupInputGUI($lng->txt("type"), "plach_type");
223 $type_captions = $this->getTypeCaptions();
224 foreach ($this->getAvailableTypes($a_type) as $type) {
225 $ttype_input->addOption(new ilRadioOption($type_captions[$type], $type));
226 }
227 $ttype_input->setRequired(true);
228 $this->form_gui->addItem($ttype_input);
229
230 $theight_input = new ilTextInputGUI($lng->txt("height"), "plach_height");
231 $theight_input->setSize(4);
232 $theight_input->setMaxLength(3);
233 $theight_input->setTitle($lng->txt("height") . " (px)");
234 $theight_input->setRequired(true);
235 $this->form_gui->addItem($theight_input);
236
237 $theight_input->setValue(preg_replace("/px/", "", $a_height));
238 $ttype_input->setValue($a_type);
239
240 $this->form_gui->addCommandButton($a_action, $lng->txt($a_mode));
241 $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
242 $this->tpl->setContent($this->form_gui->getHTML());
243 }
244
248 protected function textCOSelectionGUI()
249 {
251
252 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
253 $this->form_gui = new ilPropertyFormGUI();
254 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
255 $this->form_gui->setTitle($lng->txt("cont_ed_select_pctext"));
256
257 // Select Question Type
258 $ttype_input = new ilRadioGroupInputGUI($lng->txt("cont_ed_textitem"), "pctext_type");
259 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_par"), 0));
260 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_dtable"), 1));
261 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_atable"), 2));
262 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_list"), 3));
263 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_flist"), 4));
264 $ttype_input->addOption(new ilRadioOption($lng->txt("cont_tabs"), 5));
265 $this->form_gui->addItem($ttype_input);
266
267 $this->form_gui->addCommandButton("insertPCText", $lng->txt("insert"));
268 $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
269 $this->tpl->setContent($this->form_gui->getHTML());
270 }
271
275 protected function insertPCText()
276 {
277 switch ($_POST['pctext_type']) {
278 case 0: //Paragraph / Text
279
280 // js editing? -> redirect to js page editor
281 // if ($ilSetting->get("enable_js_edit", 1) && ilPageEditorGUI::_doJSEditing())
283 $ret_class = $this->ctrl->getReturnClass($this);
284 $this->ctrl->setParameterByClass($ret_class, "pl_hier_id", $this->hier_id);
285 $this->ctrl->setParameterByClass($ret_class, "pl_pc_id", $this->pc_id);
286 $this->ctrl->redirectByClass(
287 $ret_class,
288 "insertJSAtPlaceholder"
289 );
290 }
291
292 include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
293 $this->ctrl->setCmdClass("ilpcparagraphgui");
294 $this->ctrl->setCmd("insert");
295 $paragraph_gui = new ilPCParagraphGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
296 $paragraph_gui->setStyleId($this->getStyleId());
297 $paragraph_gui->setPageConfig($this->getPageConfig());
298 $this->ctrl->forwardCommand($paragraph_gui);
299 break;
300
301 case 1: //DataTable
302 include_once("./Services/COPage/classes/class.ilPCDataTableGUI.php");
303 $this->ctrl->setCmdClass("ilpcdatatablegui");
304 $this->ctrl->setCmd("insert");
305 $dtable_gui = new ilPCDataTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
306 $this->ctrl->forwardCommand($dtable_gui);
307 break;
308
309 case 2: //Advanced Table
310 include_once("./Services/COPage/classes/class.ilPCTableGUI.php");
311 $this->ctrl->setCmdClass("ilpctablegui");
312 $this->ctrl->setCmd("insert");
313 $atable_gui = new ilPCTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
314 $this->ctrl->forwardCommand($atable_gui);
315 break;
316
317 case 3: //Advanced List
318 include_once("./Services/COPage/classes/class.ilPCListGUI.php");
319 $this->ctrl->setCmdClass("ilpclistgui");
320 $this->ctrl->setCmd("insert");
321 $list_gui = new ilPCListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
322 $this->ctrl->forwardCommand($list_gui);
323 break;
324
325 case 4: //File List
326 include_once("./Services/COPage/classes/class.ilPCFileListGUI.php");
327 $this->ctrl->setCmdClass("ilpcfilelistgui");
328 $this->ctrl->setCmd("insert");
329 $file_list_gui = new ilPCFileListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
330 $file_list_gui->setStyleId($this->getStyleId());
331 $this->ctrl->forwardCommand($file_list_gui);
332 break;
333
334 case 5: //Tabs
335 include_once("./Services/COPage/classes/class.ilPCTabsGUI.php");
336 $this->ctrl->setCmdClass("ilpctabsgui");
337 $this->ctrl->setCmd("insert");
338 $tabs_gui = new ilPCTabsGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
339 $tabs_gui->setStyleId($this->getStyleId());
340 $this->ctrl->forwardCommand($tabs_gui);
341 break;
342
343 default:
344 break;
345 }
346 }
347
351 public function cancel()
352 {
353 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
354 }
355
356 protected function getAvailableTypes($a_selected_type = "")
357 {
358 // custom config?
359 if (method_exists($this->getPageConfig(), "getAvailablePlaceholderTypes")) {
360 $types = $this->getPageConfig()->getAvailablePlaceholderTypes();
361 } else {
362 $types = array(self::TYPE_TEXT, self::TYPE_MEDIA, self::TYPE_QUESTION);
363 }
364
365 $validator = new ilCertificateActiveValidator();
366 if (true === $validator->validate()) {
367 // we remove type verification if certificates are deactivated and this
368 // is not the currently selected value
369 if (($key = array_search(self::TYPE_VERIFICATION, $types)) !== false &&
370 self::TYPE_VERIFICATION != $a_selected_type) {
371 unset($types[$key]);
372 }
373 }
374 return $types;
375 }
376
377 protected function getTypeCaptions()
378 {
380
381 return array(
382 self::TYPE_TEXT => $lng->txt("cont_ed_plachtext"),
383 self::TYPE_MEDIA => $lng->txt("cont_ed_plachmedia"),
384 self::TYPE_QUESTION => $lng->txt("cont_ed_plachquestion"),
385 self::TYPE_VERIFICATION => $lng->txt("cont_ed_plachverification")
386 );
387 }
388}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilPCTableGUI.
Class ilPCListGUI.
Class ilPCListGUI.
Class ilPCMediaObjectGUI.
Class ilPCParagraphGUI.
Class ilPCPlaceHolderGUI.
insertPCText()
Forwards Text Item Selection to GUI classes.
getAvailableTypes($a_selected_type="")
setStyleId($a_styleid)
Set Style Id.
saveProperties()
save placeholder properties in db and return to page edit screen
textCOSelectionGUI()
Text Item Selection.
edit_object()
Handle Editing Private Methods.
__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
create()
create new table in dom and update page in db
propertyGUI($a_action, $a_type, $a_height, $a_mode)
Object Property GUI.
executeCommand()
execute command
Class ilPlaceHolder.
Class ilPCQuestionGUI.
Class ilPCTableGUI.
Class ilPCTabsGUI.
Class ilPCVerificationGUI.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getPageConfig()
Get Page Config.
static _doJSEditing()
checks if current user has activated js editing and if browser is js capable
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$type
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46