ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPCSectionGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPCSection.php");
5require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6
20{
21
26 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
27 {
28 global $DIC;
29
30 $this->tpl = $DIC["tpl"];
31 $this->lng = $DIC->language();
32 $this->ctrl = $DIC->ctrl();
33 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
34
36 }
37
41 public static function _getStandardCharacteristics()
42 {
43 global $DIC;
44
45 $lng = $DIC->language();
46
47 return array("Block" => $lng->txt("cont_Block"),
48 "Mnemonic" => $lng->txt("cont_Mnemonic"),
49 "Remark" => $lng->txt("cont_Remark"),
50 "Example" => $lng->txt("cont_Example"),
51 "Additional" => $lng->txt("cont_Additional"),
52 "Special" => $lng->txt("cont_Special"),
53
54 "Attention" => $lng->txt("cont_Attention"),
55 "Background" => $lng->txt("cont_Background"),
56 "Confirmation" => $lng->txt("cont_Confirmation"),
57 "Information" => $lng->txt("cont_Information"),
58 "Interaction" => $lng->txt("cont_Interaction"),
59 "Link" => $lng->txt("cont_Link"),
60 "Literature" => $lng->txt("cont_Literature"),
61 "Separator" => $lng->txt("cont_Separator"),
62 "StandardCenter" => $lng->txt("cont_StandardCenter"),
63
64 "Excursus" => $lng->txt("cont_Excursus"),
65 "AdvancedKnowledge" => $lng->txt("cont_AdvancedKnowledge"));
66 }
67
71 public static function _getCharacteristics($a_style_id)
72 {
74
75 if ($a_style_id > 0 &&
76 ilObject::_lookupType($a_style_id) == "sty") {
77 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
78 $style = new ilObjStyleSheet($a_style_id);
79 $chars = $style->getCharacteristics("section");
80 $new_chars = array();
81 foreach ($chars as $char) {
82 if ($chars[$char] != "") { // keep lang vars for standard chars
83 $new_chars[$char] = $chars[$char];
84 } else {
85 $new_chars[$char] = $char;
86 }
87 asort($new_chars);
88 }
89 $chars = $new_chars;
90 }
91 return $chars;
92 }
93
97 public function executeCommand()
98 {
99 $this->getCharacteristicsOfCurrentStyle("section"); // scorm-2004
100
101 // get next class that processes or forwards current command
102 $next_class = $this->ctrl->getNextClass($this);
103
104 // get current command
105 $cmd = $this->ctrl->getCmd();
106
107 switch ($next_class) {
108 case "ilpropertyformgui":
109 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
110 $form = $this->initForm(true);
111 $this->ctrl->forwardCommand($form);
112 break;
113
114 default:
115 $ret = $this->$cmd();
116 break;
117 }
118
119 return $ret;
120 }
121
125 public function insert(ilPropertyFormGUI $a_form = null)
126 {
127 $this->edit(true, $a_form);
128 }
129
133 public function edit($a_insert = false, ilPropertyFormGUI $a_form = null)
134 {
136
137 $this->displayValidationError();
138
139 if (!$a_form) {
140 $a_form = $this->initForm($a_insert);
141 }
142
143 $tpl->setContent($a_form->getHTML());
144 }
145
149 public function initForm($a_insert = false)
150 {
153
154 // edit form
155 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
156 $form = new ilPropertyFormGUI();
157 $form->setFormAction($ilCtrl->getFormAction($this));
158 if ($a_insert) {
159 $form->setTitle($this->lng->txt("cont_insert_section"));
160 } else {
161 $form->setTitle($this->lng->txt("cont_update_section"));
162 }
163
164 // characteristic selection
165 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
166 $char_prop = new ilAdvSelectInputGUI(
167 $this->lng->txt("cont_characteristic"),
168 "characteristic"
169 );
170
171 $chars = $this->getCharacteristics();
172 if (is_object($this->content_obj)) {
173 if ($chars[$a_seleted_value] == "" && ($this->content_obj->getCharacteristic() != "")) {
174 $chars = array_merge(
175 array($this->content_obj->getCharacteristic() => $this->content_obj->getCharacteristic()),
176 $chars
177 );
178 }
179 }
180
181 $selected = ($a_insert)
182 ? "Block"
183 : $this->content_obj->getCharacteristic();
184
185 foreach ($chars as $k => $char) {
186 $html = '<div class="ilCOPgEditStyleSelectionItem"><div class="ilc_section_' . $k . '" style="' . self::$style_selector_reset . '">' .
187 $char . '</div></div>';
188 $char_prop->addOption($k, $char, $html);
189 }
190
191 $char_prop->setValue($selected);
192 $form->addItem($char_prop);
193
194 // link input
195 include_once 'Services/Form/classes/class.ilLinkInputGUI.php';
196 $ac = new ilLinkInputGUI($this->lng->txt('cont_link'), 'link');
197 if ($this->getPageConfig()->getEnableInternalLinks()) {
198 $ac->setAllowedLinkTypes(ilLinkInputGUI::BOTH);
199 } else {
200 $ac->setAllowedLinkTypes(ilLinkInputGUI::EXT);
201 }
202 $ac->setRequired(false);
203 $ac->setInfo($this->lng->txt("copg_sec_link_info"));
204 $ac->setInternalLinkDefault(
205 $this->getPageConfig()->getIntLinkHelpDefaultType(),
206 $this->getPageConfig()->getIntLinkHelpDefaultId()
207 );
208 $link_types = array();
209 foreach ($this->getPageConfig()->getIntLinkFilters() as $f) {
210 $link_types[] = $f;
211 }
212 $ac->setInternalLinkFilterTypes($link_types);
213 $ac->setFilterWhiteList(
214 $this->getPageConfig()->getIntLinkFilterWhiteList()
215 );
216
217 if (!$a_insert) {
218 $l = $this->content_obj->getLink();
219 if ($l["LinkType"] == "IntLink") {
220 $ac->setValueByIntLinkAttributes($l["Type"], $l["Target"], $l["TargetFrame"]);
221 }
222 if ($l["LinkType"] == "ExtLink") {
223 $ac->setValue($l["Href"]);
224 }
225 }
226 $form->addItem($ac);
227
228 // activation
229
230 // active from
231 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_from"), "active_from");
232 if (!$a_insert && ($from = $this->content_obj->getActiveFrom()) != "") {
233 $dt_prop->setDate(new ilDateTime($from, IL_CAL_UNIX));
234 }
235 $dt_prop->setShowTime(true);
236 $form->addItem($dt_prop);
237
238 // active to
239 $dt_prop = new ilDateTimeInputGUI($lng->txt("cont_active_to"), "active_to");
240 if (!$a_insert && ($to = $this->content_obj->getActiveTo()) != "") {
241 $dt_prop->setDate(new ilDateTime($to, IL_CAL_UNIX));
242 }
243 $dt_prop->setShowTime(true);
244 $form->addItem($dt_prop);
245
246 // rep selector
247 if ($this->getPageConfig()->getEnablePermissionChecks()) {
248 include_once("./Services/Form/classes/class.ilRepositorySelector2InputGUI.php");
249 $rs = new ilRepositorySelector2InputGUI($lng->txt("cont_permission_object"), "permission_ref_id");
250 $rs->setParent($this);
251 $form->addItem($rs);
252
253 // permission
254 $options = array(
255 "read" => $lng->txt("read"),
256 "write" => $lng->txt("write"),
257 "visible" => $lng->txt("visible"),
258 "no_read" => $lng->txt("cont_no_read")
259 );
260 $si = new ilSelectInputGUI($lng->txt("permission"), "permission");
261 $si->setInfo($lng->txt("cont_permission_object_desc"));
262 $si->setOptions($options);
263 $form->addItem($si);
264
265 if (!$a_insert) {
266 $si->setValue($this->content_obj->getPermission());
267 $rs->setValue($this->content_obj->getPermissionRefId());
268 }
269 }
270
271 // save/cancel buttons
272 if ($a_insert) {
273 $form->addCommandButton("create_section", $lng->txt("save"));
274 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
275 } else {
276 $form->addCommandButton("update", $lng->txt("save"));
277 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
278 }
279 return $form;
280 }
281
282
286 public function create()
287 {
288 $form = $this->initForm(true);
289 if ($form->checkInput()) {
290 $this->content_obj = new ilPCSection($this->getPage());
291 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
292
293 $this->setValuesFromForm($form);
294
295 $this->updated = $this->pg_obj->update();
296 if ($this->updated === true) {
297 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
298 }
299 }
300
301 $this->insert($form);
302 }
303
307 public function update()
308 {
309 $form = $this->initForm(false);
310 if ($form->checkInput()) {
311 $this->setValuesFromForm($form);
312
313 $this->updated = $this->pg_obj->update();
314 if ($this->updated === true) {
315 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
316 }
317 }
318
319 $this->pg_obj->addHierIDs();
320 $this->edit(false, $form);
321 }
322
328 public function setValuesFromForm($form)
329 {
330 $this->content_obj->setCharacteristic($_POST["characteristic"]);
331
332 $from = $form->getItemByPostVar("active_from")->getDate();
333 if ($from) {
334 $this->content_obj->setActiveFrom($from->get(IL_CAL_UNIX));
335 } else {
336 $this->content_obj->setActiveFrom(0);
337 }
338
339 $to = $form->getItemByPostVar("active_to")->getDate();
340 if ($to) {
341 $this->content_obj->setActiveTo($to->get(IL_CAL_UNIX));
342 } else {
343 $this->content_obj->setActiveTo(0);
344 }
345
346 if ($this->getPageConfig()->getEnablePermissionChecks()) {
347 $this->content_obj->setPermissionRefId($_POST["permission_ref_id"]);
348 $this->content_obj->setPermission($_POST["permission"]);
349 }
350
351 if ($_POST["link_mode"] == "ext" && $_POST["link"] != "") {
352 $this->content_obj->setExtLink($_POST["link"]);
353 } elseif ($_POST["link_mode"] == "int" && $_POST["link"] != "") {
354 // $_POST["link"] is "crs|96", "chap|2", "term|1", "wpage|1"
355 // var_dump($_POST);
356 $la = $form->getItemByPostVar("link")->getIntLinkAttributes();
357 // echo "<br>";
358 // var_dump($la); exit;
359 if ($la["Type"] != "") {
360 $this->content_obj->setIntLink($la["Type"], $la["Target"], $la["TargetFrame"]);
361 }
362 } else {
363 $this->content_obj->setNoLink();
364 }
365 }
366}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This class represents an advanced selection list property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a external and/or internal link in a property form.
Class ilObjStyleSheet.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCSectionGUI.
update()
Update Section.
create()
Create new Section.
initForm($a_insert=false)
Init editing form.
static _getCharacteristics($a_style_id)
Get characteristics.
edit($a_insert=false, ilPropertyFormGUI $a_form=null)
Edit section form.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
setValuesFromForm($form)
Set values from form.
static _getStandardCharacteristics()
Get standard characteristics.
executeCommand()
execute command
insert(ilPropertyFormGUI $a_form=null)
Insert new section form.
Class ilPCSection.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
getPageConfig()
Get Page Config.
displayValidationError()
display validation errors
getCharacteristics()
Get characteristics.
setCharacteristics($a_chars)
Set Characteristics.
This class represents a property form user interface.
This class represents a selection list property in a property form.
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46