ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
6require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
7require_once("./Modules/StudyProgramme/classes/helpers/class.ilAsyncOutputHandler.php");
8require_once("./Modules/StudyProgramme/classes/helpers/class.ilAsyncPropertyFormGUI.php");
9require_once("./Services/UIComponent/Button/classes/class.ilLinkButton.php");
10
22 public $ctrl;
23
27 public $tpl;
28
32 protected $ilAccess;
33
37 public $object;
38
42 protected $ilLog;
43
47 public $ilias;
48
52 public $lng;
53
57 protected $parent_gui;
58
62 protected $tmp_heading;
63
64 public function __construct($a_parent_gui, $a_ref_id) {
65 global $tpl, $ilCtrl, $ilAccess, $ilToolbar, $ilLocator, $tree, $lng, $ilLog, $ilias;
66
67 $this->parent_gui = $a_parent_gui;
68 $this->ref_id = $a_ref_id;
69 $this->parent_gui = $a_parent_gui;
70
71 $this->tpl = $tpl;
72 $this->ctrl = $ilCtrl;
73 $this->ilAccess = $ilAccess;
74 $this->ilLocator = $ilLocator;
75 $this->tree = $tree;
76 $this->toolbar = $ilToolbar;
77 $this->ilLog = $ilLog;
78 $this->ilias = $ilias;
79 $this->lng = $lng;
80
81 $this->object = null;
82
83 $lng->loadLanguageModule("prg");
84 }
85
86 public function executeCommand() {
87 $cmd = $this->ctrl->getCmd();
88
89
90 if ($cmd == "") {
91 $cmd = "view";
92 }
93
94 switch ($cmd) {
95 case "view":
96 case "update":
97 case "cancel":
98 $content = $this->$cmd();
99 break;
100 default:
101 throw new ilException("ilObjStudyProgrammeSettingsGUI: ".
102 "Command not supported: $cmd");
103 }
104
105 if(!$this->ctrl->isAsynch()) {
106 $this->tpl->setContent($content);
107 } else {
108 $output_handler = new ilAsyncOutputHandler();
109 $heading = $this->lng->txt("prg_async_".$this->ctrl->getCmd());
110 if(isset($this->tmp_heading)) {
111 $heading = $this->tmp_heading;
112 }
113 $output_handler->setHeading($heading);
114 $output_handler->setContent($content);
115 $output_handler->terminate();
116 }
117 }
118
119 protected function view() {
120 $this->buildModalHeading($this->lng->txt('prg_async_settings'),isset($_GET["currentNode"]));
121
122 $form = $this->buildForm();
123 $this->fillForm($form);
124 return $form->getHTML();
125 }
126
127 /*protected function cancel() {
128 $this->ctrl->redirect($this->parent_gui);
129 }*/
130
131 protected function update() {
132
133 $form = $this->buildForm();
134 $form->setValuesByPost();
135 $update_possible = $this->checkForm($form);
136
137 if ($update_possible) {
138 $this->updateFromFrom($form);
139 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
140 $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>true, "message"=>$this->lng->txt("msg_obj_modified")));
141 } else {
142 // TODO:
143 ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
144 $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>false, "errors"=>$form->getErrors()));
145 }
146
147 if($this->ctrl->isAsynch()) {
148 return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
149 } else {
150 if($update_possible) {
151 $this->ctrl->redirect($this);
152 } else {
153 return $form->getHTML();
154 }
155 }
156 }
157
158 protected function cancel() {
160
161 $this->ctrl->redirect($this->parent_gui);
162 }
163
164 protected function buildModalHeading($label, $current_node) {
165 if(!$current_node) {
166 $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
167 $heading_button = ilLinkButton::getInstance();
168 $heading_button->setCaption('prg_open_node');
169 $heading_button->setUrl($this->ctrl->getLinkTargetByClass('ilobjstudyprogrammetreegui', 'view'));
170
171 $heading = "<div class=''>".$label."<div class='pull-right'>".$heading_button->render()."</div></div>";
172 $this->tmp_heading = $heading;
173 } else {
174 $this->tmp_heading = "<div class=''>".$label."</div>";
175 }
176
177 }
178
179 const PROP_TITLE = "title";
180 const PROP_DESC = "desc";
181 const PROP_TYPE = "type";
182 const PROP_POINTS = "points";
183 const PROP_STATUS = "status";
184
185 protected function buildForm() {
186 $form = new ilAsyncPropertyFormGUI();
187
188 if(!$this->ctrl->isAsynch()) {
189 $form->setAsync(false);
190 }
191
192 $form->setFormAction($this->ctrl->getFormAction($this));
193
195 $header->setTitle($this->lng->txt("prg_edit"));
196 $form->addItem($header);
197
198 $item = new ilTextInputGUI($this->lng->txt("title"), self::PROP_TITLE);
199 $item->setRequired(true);
200 $form->addItem($item);
201
202 $item = new ilTextAreaInputGUI($this->lng->txt("description"), self::PROP_DESC);
203 $form->addItem($item);
204
206 $header->setTitle($this->lng->txt("prg_type"));
207 $form->addItem($header);
208
209 $item = new ilSelectInputGUI($this->lng->txt("type"), self::PROP_TYPE);
210 $item->setOptions(ilStudyProgrammeType::getAllTypesArray());
211 $form->addItem($item);
212
214 $header->setTitle($this->lng->txt("prg_assessment"));
215 $form->addItem($header);
216
217 $item = new ilNumberInputGUI($this->lng->txt("prg_points"), self::PROP_POINTS);
218 $item->setMinValue(0);
219 $form->addItem($item);
220
221 $item = new ilSelectInputGUI($this->lng->txt("prg_status"), self::PROP_STATUS);
222 $item->setOptions(self::getStatusOptions());
223 $form->addItem($item);
224
225 $form->addCommandButton("update", $this->lng->txt("save"));
226 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
227
228 return $form;
229 }
230
231 protected function getObject() {
232 if ($this->object === null) {
233 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
234 }
235 return $this->object;
236 }
237
238 protected function fillForm($a_form) {
239 $obj = $this->getObject();
240
241 $a_form->setValuesByArray(array
242 ( self::PROP_TITLE => $obj->getTitle()
243 , self::PROP_DESC => $obj->getDescription()
244 , self::PROP_TYPE => $obj->getSubtypeId()
245 , self::PROP_POINTS => $obj->getPoints()
246 , self::PROP_STATUS => $obj->getStatus()
247 ));
248 }
249
250 protected function checkForm($a_form) {
251 if (!$a_form->checkInput()) {
252 return false;
253 }
254 return true;
255 }
256
257 protected function updateFromFrom($a_form) {
258 $obj = $this->getObject();
259
260 $obj->setTitle($a_form->getItemByPostVar(self::PROP_TITLE)->getValue());
261 $obj->setDescription($a_form->getItemByPostVar(self::PROP_DESC)->getValue());
262
263 if($obj->getSubtypeId() != $a_form->getItemByPostVar(self::PROP_TYPE)->getValue()) {
264 $obj->setSubtypeId($a_form->getItemByPostVar(self::PROP_TYPE)->getValue());
265 $obj->updateCustomIcon();
266 $this->parent_gui->setTitleAndDescription();
267 }
268
269 $obj->setPoints($a_form->getItemByPostVar(self::PROP_POINTS)->getValue());
270 $obj->setStatus($a_form->getItemByPostVar(self::PROP_STATUS)->getValue());
271 }
272
273 static protected function getStatusOptions() {
274 global $lng;
275
276 return array( ilStudyProgramme::STATUS_DRAFT
277 => $lng->txt("prg_status_draft")
279 => $lng->txt("prg_status_active")
281 => $lng->txt("prg_status_outdated")
282 );
283 }
284}
285
286?>
$_GET["client_id"]
Class ilAsyncOutputHandler Handles the output for async-requests.
static handleAsyncOutput($normal_content, $async_content=null, $apply_to_tpl=true)
Handles async output.
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
Class ilAsyncPropertyFormGUI.
Base class for ILIAS Exception handling.
This class represents a section header in a property form.
static getInstance()
Factory.
logging
Definition: class.ilLog.php:19
This class represents a number property in a property form.
Class ilObjStudyProgrammeSettingsGUI.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
This class represents a selection list property in a property form.
static getAllTypesArray($add_empty_on_begin=true)
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$header
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
$cmd
Definition: sahs_server.php:35