ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $DIC;
66 $tpl = $DIC['tpl'];
67 $ilCtrl = $DIC['ilCtrl'];
68 $ilAccess = $DIC['ilAccess'];
69 $ilToolbar = $DIC['ilToolbar'];
70 $ilLocator = $DIC['ilLocator'];
71 $tree = $DIC['tree'];
72 $lng = $DIC['lng'];
73 $ilLog = $DIC['ilLog'];
74 $ilias = $DIC['ilias'];
75
76 $this->parent_gui = $a_parent_gui;
77 $this->ref_id = $a_ref_id;
78 $this->parent_gui = $a_parent_gui;
79
80 $this->tpl = $tpl;
81 $this->ctrl = $ilCtrl;
82 $this->ilAccess = $ilAccess;
83 $this->ilLocator = $ilLocator;
84 $this->tree = $tree;
85 $this->toolbar = $ilToolbar;
86 $this->ilLog = $ilLog;
87 $this->ilias = $ilias;
88 $this->lng = $lng;
89
90 $this->object = null;
91
92 $lng->loadLanguageModule("prg");
93 }
94
95 public function executeCommand() {
96 $cmd = $this->ctrl->getCmd();
97
98
99 if ($cmd == "") {
100 $cmd = "view";
101 }
102
103 switch ($cmd) {
104 case "view":
105 case "update":
106 case "cancel":
107 $content = $this->$cmd();
108 break;
109 default:
110 throw new ilException("ilObjStudyProgrammeSettingsGUI: ".
111 "Command not supported: $cmd");
112 }
113
114 if(!$this->ctrl->isAsynch()) {
115 $this->tpl->setContent($content);
116 } else {
117 $output_handler = new ilAsyncOutputHandler();
118 $heading = $this->lng->txt("prg_async_".$this->ctrl->getCmd());
119 if(isset($this->tmp_heading)) {
120 $heading = $this->tmp_heading;
121 }
122 $output_handler->setHeading($heading);
123 $output_handler->setContent($content);
124 $output_handler->terminate();
125 }
126 }
127
128 protected function view() {
129 $this->buildModalHeading($this->lng->txt('prg_async_settings'),isset($_GET["currentNode"]));
130
131 $form = $this->buildForm();
132 $this->fillForm($form);
133 return $form->getHTML();
134 }
135
136 /*protected function cancel() {
137 $this->ctrl->redirect($this->parent_gui);
138 }*/
139
140 protected function update() {
141
142 $form = $this->buildForm();
143 $form->setValuesByPost();
144 $update_possible = $this->checkForm($form);
145
146 if ($update_possible) {
147 $this->updateFromFrom($form);
148 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
149 $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>true, "message"=>$this->lng->txt("msg_obj_modified")));
150 } else {
151 // TODO:
152 ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
153 $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success"=>false, "errors"=>$form->getErrors()));
154 }
155
156 if($this->ctrl->isAsynch()) {
157 return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
158 } else {
159 if($update_possible) {
160 $this->ctrl->redirect($this);
161 } else {
162 return $form->getHTML();
163 }
164 }
165 }
166
167 protected function cancel() {
169
170 $this->ctrl->redirect($this->parent_gui);
171 }
172
173 protected function buildModalHeading($label, $current_node) {
174 if(!$current_node) {
175 $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
176 $heading_button = ilLinkButton::getInstance();
177 $heading_button->setCaption('prg_open_node');
178 $heading_button->setUrl($this->ctrl->getLinkTargetByClass('ilobjstudyprogrammetreegui', 'view'));
179
180 $heading = "<div class=''>".$label."<div class='pull-right'>".$heading_button->render()."</div></div>";
181 $this->tmp_heading = $heading;
182 } else {
183 $this->tmp_heading = "<div class=''>".$label."</div>";
184 }
185
186 }
187
188 const PROP_TITLE = "title";
189 const PROP_DESC = "desc";
190 const PROP_TYPE = "type";
191 const PROP_POINTS = "points";
192 const PROP_STATUS = "status";
193
194 protected function buildForm() {
195 $form = new ilAsyncPropertyFormGUI();
196
197 if(!$this->ctrl->isAsynch()) {
198 $form->setAsync(false);
199 }
200
201 $form->setFormAction($this->ctrl->getFormAction($this));
202
204 $header->setTitle($this->lng->txt("prg_edit"));
205 $form->addItem($header);
206
207 $item = new ilTextInputGUI($this->lng->txt("title"), self::PROP_TITLE);
208 $item->setRequired(true);
209 $form->addItem($item);
210
211 $item = new ilTextAreaInputGUI($this->lng->txt("description"), self::PROP_DESC);
212 $form->addItem($item);
213
215 $header->setTitle($this->lng->txt("prg_type"));
216 $form->addItem($header);
217
218 $item = new ilSelectInputGUI($this->lng->txt("type"), self::PROP_TYPE);
219 $item->setOptions(ilStudyProgrammeType::getAllTypesArray());
220 $form->addItem($item);
221
223 $header->setTitle($this->lng->txt("prg_assessment"));
224 $form->addItem($header);
225
226 $item = new ilNumberInputGUI($this->lng->txt("prg_points"), self::PROP_POINTS);
227 $item->setMinValue(0);
228 $form->addItem($item);
229
230 $item = new ilSelectInputGUI($this->lng->txt("prg_status"), self::PROP_STATUS);
231 $item->setOptions(self::getStatusOptions());
232 $form->addItem($item);
233
234 $form->addCommandButton("update", $this->lng->txt("save"));
235 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
236
237 return $form;
238 }
239
240 protected function getObject() {
241 if ($this->object === null) {
242 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
243 }
244 return $this->object;
245 }
246
247 protected function fillForm($a_form) {
248 $obj = $this->getObject();
249
250 $a_form->setValuesByArray(array
251 ( self::PROP_TITLE => $obj->getTitle()
252 , self::PROP_DESC => $obj->getDescription()
253 , self::PROP_TYPE => $obj->getSubtypeId()
254 , self::PROP_POINTS => $obj->getPoints()
255 , self::PROP_STATUS => $obj->getStatus()
256 ));
257 }
258
259 protected function checkForm($a_form) {
260 if (!$a_form->checkInput()) {
261 return false;
262 }
263 return true;
264 }
265
266 protected function updateFromFrom($a_form) {
267 $obj = $this->getObject();
268
269 $obj->setTitle($a_form->getItemByPostVar(self::PROP_TITLE)->getValue());
270 $obj->setDescription($a_form->getItemByPostVar(self::PROP_DESC)->getValue());
271
272 if($obj->getSubtypeId() != $a_form->getItemByPostVar(self::PROP_TYPE)->getValue()) {
273 $obj->setSubtypeId($a_form->getItemByPostVar(self::PROP_TYPE)->getValue());
274 $obj->updateCustomIcon();
275 $this->parent_gui->setTitleAndDescription();
276 }
277
278 $obj->setPoints($a_form->getItemByPostVar(self::PROP_POINTS)->getValue());
279 $obj->setStatus($a_form->getItemByPostVar(self::PROP_STATUS)->getValue());
280 }
281
282 static protected function getStatusOptions() {
283 global $DIC;
284 $lng = $DIC['lng'];
285
286 return array( ilStudyProgramme::STATUS_DRAFT
287 => $lng->txt("prg_status_draft")
289 => $lng->txt("prg_status_active")
291 => $lng->txt("prg_status_outdated")
292 );
293 }
294}
295
296?>
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
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
global $DIC