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