ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 require_once("./Services/COPage/classes/class.ilPCPlaceHolder.php");
6 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
7 
21 {
22  public $pg_obj;
23  public $content_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  $this->pg_obj = $a_pg_obj;
40  $this->content_obj = $a_content_obj;
41  $this->hier_id = $a_hier_id;
42  $this->pc_id = $a_pc_id;
43 
44  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
45  }
46 
50  public function executeCommand()
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  {
59  case 'ilpcmediaobjectgui': //special handling
60  include_once("./Services/COPage/classes/class.ilPCMediaObjectGUI.php");
61  $media_gui = new ilPCMediaObjectGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
62  $ret = $this->ctrl->forwardCommand($media_gui);
63  break;
64 
65  default:
66  $ret = $this->$cmd();
67  break;
68  }
69 
70  return $ret;
71  }
72 
76  protected function insert()
77  {
78  $this->propertyGUI("create", self::TYPE_TEXT, "100px", "insert");
79  }
80 
84  protected function create()
85  {
86  if ($_POST["plach_height"]=="" ||
87  !preg_match("/[0-9]+/",$_POST["plach_height"]))
88  {
89  return $this->insert();
90  }
91 
92  $this->content_obj = new ilPCPlaceHolder($this->getPage());
93  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
94  $this->content_obj->setHeight($_POST["plach_height"]."px");
95  $this->content_obj->setContentClass($_POST['plach_type']);
96  $this->updated = $this->pg_obj->update();
97  if ($this->updated === true)
98  {
99  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
100  }
101  else
102  {
103  $this->insert();
104  }
105  }
106 
110  public function edit()
111  {
112  if($this->getPageConfig()->getEnablePCType("PlaceHolder"))
113  {
114  $this->edit_object();
115  }
116  else
117  {
118  $this->forward_edit();
119  }
120  }
121 
127  public function setStyleId($a_styleid)
128  {
129  $this->styleid = $a_styleid;
130  }
131 
137  public function getStyleId()
138  {
139  return $this->styleid;
140  }
141 
145  protected function edit_object()
146  {
147  $this->propertyGUI("saveProperties",
148  $this->content_obj->getContentClass(),
149  $this->content_obj->getHeight(),
150  "save");
151  }
152 
153  protected function forward_edit()
154  {
155  switch ($this->content_obj->getContentClass())
156  {
157  case self::TYPE_MEDIA:
158  include_once("./Services/COPage/classes/class.ilPCMediaObjectGUI.php");
159  $this->ctrl->setCmdClass("ilpcmediaobjectgui");
160  $this->ctrl->setCmd("insert");
161  $media_gui = new ilPCMediaObjectGUI($this->pg_obj, null);
162  $this->ctrl->forwardCommand($media_gui);
163  break;
164 
165  case self::TYPE_TEXT:
166  $this->textCOSelectionGUI();
167  break;
168 
169  case self::TYPE_QUESTION:
170  include_once("./Services/COPage/classes/class.ilPCQuestionGUI.php");
171  $this->ctrl->setCmdClass("ilpcquestiongui");
172  $this->ctrl->setCmd("insert");
173  $question_gui = new ilPCQuestionGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
174  $question_gui->setSelfAssessmentMode(true);
175  $this->ctrl->forwardCommand($question_gui);
176  break;
177 
178  case self::TYPE_VERIFICATION:
179  include_once("./Services/COPage/classes/class.ilPCVerificationGUI.php");
180  $this->ctrl->setCmdClass("ilpcverificationgui");
181  $this->ctrl->setCmd("insert");
182  $cert_gui = new ilPCVerificationGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
183  $this->ctrl->forwardCommand($cert_gui);
184  break;
185 
186  default:
187  break;
188  }
189  }
190 
191 
195  protected function saveProperties()
196  {
197  if ($_POST["plach_height"]=="" ||
198  !preg_match("/[0-9]+/",$_POST["plach_height"])) {
199  return $this->edit_object();
200  }
201 
202  $this->content_obj->setContentClass($_POST['plach_type']);
203  $this->content_obj->setHeight($_POST["plach_height"]."px");
204 
205  $this->updated = $this->pg_obj->update();
206  if ($this->updated === true)
207  {
208  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
209  }
210  else
211  {
212  $this->pg_obj->addHierIDs();
213  $this->edit();
214  }
215  }
216 
220  protected function propertyGUI($a_action,$a_type,$a_height,$a_mode)
221  {
222  global $lng;
223 
224  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
225  $this->form_gui = new ilPropertyFormGUI();
226  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
227  $this->form_gui->setTitle($lng->txt("cont_ed_plachprop"));
228 
229  $ttype_input = new ilRadioGroupInputGUI($lng->txt("type"), "plach_type");
230  $type_captions = $this->getTypeCaptions();
231  foreach($this->getAvailableTypes() as $type)
232  {
233  $ttype_input->addOption(new ilRadioOption($type_captions[$type], $type));
234  }
235  $ttype_input->setRequired(true);
236  $this->form_gui->addItem($ttype_input);
237 
238  $theight_input = new ilTextInputGUI($lng->txt("height"),"plach_height");
239  $theight_input->setSize(4);
240  $theight_input->setMaxLength(3);
241  $theight_input->setTitle($lng->txt("height")." (px)");
242  $theight_input->setRequired(true);
243  $this->form_gui->addItem($theight_input);
244 
245  $theight_input->setValue(preg_replace("/px/","",$a_height));
246  $ttype_input->setValue($a_type);
247 
248  $this->form_gui->addCommandButton($a_action, $lng->txt($a_mode));
249  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
250  $this->tpl->setContent($this->form_gui->getHTML());
251  }
252 
256  protected function textCOSelectionGUI()
257  {
258  global $lng;
259 
260  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
261  $this->form_gui = new ilPropertyFormGUI();
262  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
263  $this->form_gui->setTitle($lng->txt("cont_ed_select_pctext"));
264 
265  // Select Question Type
266  $ttype_input = new ilRadioGroupInputGUI($lng->txt("cont_ed_textitem"), "pctext_type");
267  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_par"), 0));
268  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_dtable"), 1));
269  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_atable"), 2));
270  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_list"), 3));
271  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_ed_flist"), 4));
272  $ttype_input->addOption(new ilRadioOption($lng->txt("cont_tabs"), 5));
273  $this->form_gui->addItem($ttype_input);
274 
275  $this->form_gui->addCommandButton("insertPCText", $lng->txt("insert"));
276  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
277  $this->tpl->setContent($this->form_gui->getHTML());
278  }
279 
283  protected function insertPCText()
284  {
285  switch ($_POST['pctext_type'])
286  {
287  case 0: //Paragraph / Text
288 
289  // js editing? -> redirect to js page editor
290  // if ($ilSetting->get("enable_js_edit", 1) && ilPageEditorGUI::_doJSEditing())
292  {
293  $ret_class = $this->ctrl->getReturnClass($this);
294  $this->ctrl->setParameterByClass($ret_class, "pl_hier_id", $this->hier_id);
295  $this->ctrl->setParameterByClass($ret_class, "pl_pc_id", $this->pc_id);
296  $this->ctrl->redirectByClass($ret_class,
297  "insertJSAtPlaceholder");
298  }
299 
300  include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
301  $this->ctrl->setCmdClass("ilpcparagraphgui");
302  $this->ctrl->setCmd("insert");
303  $paragraph_gui = new ilPCParagraphGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
304  $paragraph_gui->setStyleId($this->getStyleId());
305  $paragraph_gui->setPageConfig($this->getPageConfig());
306  $this->ctrl->forwardCommand($paragraph_gui);
307  break;
308 
309  case 1: //DataTable
310  include_once("./Services/COPage/classes/class.ilPCDataTableGUI.php");
311  $this->ctrl->setCmdClass("ilpcdatatablegui");
312  $this->ctrl->setCmd("insert");
313  $dtable_gui = new ilPCDataTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
314  $this->ctrl->forwardCommand($dtable_gui);
315  break;
316 
317  case 2: //Advanced Table
318  include_once("./Services/COPage/classes/class.ilPCTableGUI.php");
319  $this->ctrl->setCmdClass("ilpctablegui");
320  $this->ctrl->setCmd("insert");
321  $atable_gui = new ilPCTableGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
322  $this->ctrl->forwardCommand($atable_gui);
323  break;
324 
325  case 3: //Advanced List
326  include_once("./Services/COPage/classes/class.ilPCListGUI.php");
327  $this->ctrl->setCmdClass("ilpclistgui");
328  $this->ctrl->setCmd("insert");
329  $list_gui = new ilPCListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
330  $this->ctrl->forwardCommand($list_gui);
331  break;
332 
333  case 4: //File List
334  include_once ("./Services/COPage/classes/class.ilPCFileListGUI.php");
335  $this->ctrl->setCmdClass("ilpcfilelistgui");
336  $this->ctrl->setCmd("insert");
337  $file_list_gui = new ilPCFileListGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
338  $file_list_gui->setStyleId($this->getStyleId());
339  $this->ctrl->forwardCommand($file_list_gui);
340  break;
341 
342  case 5: //Tabs
343  include_once ("./Services/COPage/classes/class.ilPCTabsGUI.php");
344  $this->ctrl->setCmdClass("ilpctabsgui");
345  $this->ctrl->setCmd("insert");
346  $tabs_gui = new ilPCTabsGUI($this->pg_obj, $this->content_obj, $this->hier_id, $this->pc_id);
347  $tabs_gui->setStyleId($this->getStyleId());
348  $this->ctrl->forwardCommand($tabs_gui);
349  break;
350 
351  default:
352  break;
353  }
354  }
355 
359  public function cancel()
360  {
361  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
362  }
363 
364  protected function getAvailableTypes()
365  {
366  // custom config?
367  if(method_exists($this->getPageConfig(), "getAvailablePlaceholderTypes"))
368  {
369  return $this->getPageConfig()->getAvailablePlaceholderTypes();
370  }
371 
372  // default
373  return array(self::TYPE_TEXT, self::TYPE_MEDIA, self::TYPE_QUESTION);
374  }
375 
376  protected function getTypeCaptions()
377  {
378  global $lng;
379 
380  return array(
381  self::TYPE_TEXT => $lng->txt("cont_ed_plachtext"),
382  self::TYPE_MEDIA => $lng->txt("cont_ed_plachmedia"),
383  self::TYPE_QUESTION => $lng->txt("cont_ed_plachquestion"),
384  self::TYPE_VERIFICATION => $lng->txt("cont_ed_plachverification")
385  );
386  }
387 }