ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
68  protected $input_factory;
69 
73  protected $renderer;
74 
78  protected $request;
79 
83  protected $trafo_factory;
84 
85  public function __construct($a_parent_gui, $a_ref_id)
86  {
87  global $DIC;
88  $tpl = $DIC['tpl'];
89  $ilCtrl = $DIC['ilCtrl'];
90  $ilAccess = $DIC['ilAccess'];
91  $ilToolbar = $DIC['ilToolbar'];
92  $ilLocator = $DIC['ilLocator'];
93  $tree = $DIC['tree'];
94  $lng = $DIC['lng'];
95  $ilLog = $DIC['ilLog'];
96  $ilias = $DIC['ilias'];
97 
98  $this->parent_gui = $a_parent_gui;
99  $this->ref_id = $a_ref_id;
100  $this->parent_gui = $a_parent_gui;
101 
102  $this->tpl = $tpl;
103  $this->ctrl = $ilCtrl;
104  $this->ilAccess = $ilAccess;
105  $this->ilLocator = $ilLocator;
106  $this->tree = $tree;
107  $this->toolbar = $ilToolbar;
108  $this->ilLog = $ilLog;
109  $this->ilias = $ilias;
110  $this->lng = $lng;
111  $this->input_factory = $DIC->ui()->factory()->input();
112  $this->renderer = $DIC->ui()->renderer();
113  $this->request = $DIC->http()->request();
114  $this->trafo_factory = new \ILIAS\Transformation\Factory(); // TODO: replace this with the version from the DIC once available
115  $this->data = new \ILIAS\Data\Factory();
116  $this->validation = new \ILIAS\Validation\Factory($this->data, $this->lng);
117 
118  $this->object = null;
119 
120  $lng->loadLanguageModule("prg");
121  }
122 
123  public function executeCommand()
124  {
125  $cmd = $this->ctrl->getCmd();
126 
127 
128  if ($cmd == "") {
129  $cmd = "view";
130  }
131 
132  switch ($cmd) {
133  case "view":
134  case "update":
135  case "cancel":
136  $content = $this->$cmd();
137  break;
138  default:
139  throw new ilException("ilObjStudyProgrammeSettingsGUI: " .
140  "Command not supported: $cmd");
141  }
142 
143  if (!$this->ctrl->isAsynch()) {
144  $this->tpl->setContent($content);
145  } else {
146  $output_handler = new ilAsyncOutputHandler();
147  $heading = $this->lng->txt("prg_async_" . $this->ctrl->getCmd());
148  if (isset($this->tmp_heading)) {
149  $heading = $this->tmp_heading;
150  }
151  $output_handler->setHeading($heading);
152  $output_handler->setContent($content);
153  $output_handler->terminate();
154  }
155  }
156 
157  protected function view()
158  {
159  $this->buildModalHeading($this->lng->txt('prg_async_settings'), isset($_GET["currentNode"]));
160 
161  $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
162  return $this->renderer->render($form);
163  }
164 
165  protected function update()
166  {
167  $form = $this
168  ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
169  ->withRequest($this->request);
170  $content = $form->getData();
171  $prg = $this->getObject();
172 
173  // This could further improved by providing a new container for asynch-forms in the
174  // UI-Framework.
175  $update_possible = !is_null($content);
176  if ($update_possible) {
177  $this->updateWith($prg, $content);
178  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
179 
180  if ($this->ctrl->isAsynch()) {
181  $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success" => true, "message" => $this->lng->txt("msg_obj_modified")));
182  return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
183  } else {
184  $this->ctrl->redirect($this);
185  }
186  } else {
187  ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
188 
189  if ($this->ctrl->isAsynch()) {
190  $response = ilAsyncOutputHandler::encodeAsyncResponse(array("success" => false, "errors" => $form->getErrors()));
191  return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
192  } else {
193  return $this->renderer->render($form);
194  }
195  }
196  }
197 
198  protected function cancel()
199  {
201 
202  $this->ctrl->redirect($this->parent_gui);
203  }
204 
205  protected function buildModalHeading($label, $current_node)
206  {
207  if (!$current_node) {
208  $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
209  $heading_button = ilLinkButton::getInstance();
210  $heading_button->setCaption('prg_open_node');
211  $heading_button->setUrl($this->ctrl->getLinkTargetByClass('ilobjstudyprogrammetreegui', 'view'));
212 
213  $heading = "<div class=''>" . $label . "<div class='pull-right'>" . $heading_button->render() . "</div></div>";
214  $this->tmp_heading = $heading;
215  } else {
216  $this->tmp_heading = "<div class=''>" . $label . "</div>";
217  }
218  }
219 
220  const PROP_TITLE = "title";
221  const PROP_DESC = "desc";
222  const PROP_TYPE = "type";
223  const PROP_POINTS = "points";
224  const PROP_STATUS = "status";
225 
226  protected function buildForm(\ilObjStudyProgramme $prg, string $submit_action) : ILIAS\UI\Component\Input\Container\Form\Standard
227  {
228  $ff = $this->input_factory->field();
229  $tf = $this->trafo_factory;
230  $txt = function ($id) {
231  return $this->lng->txt($id);
232  };
234  $status_options = self::getStatusOptions();
235  return $this->input_factory->container()->form()->standard(
236  $submit_action,
237  [
238  $ff->section(
239  [
240  self::PROP_TITLE =>
241  $ff->text($txt("title"))
242  ->withValue($prg->getTitle())
243  ->withRequired(true),
244  self::PROP_DESC =>
245  $ff->textarea($txt("description"))
246  ->withValue($prg->getDescription() ?? "")
247  ],
248  $txt("prg_edit"),
249  ""
250  ),
251  $ff->section(
252  [
253  self::PROP_TYPE =>
254  $ff->select($txt("type"), $sp_types)
255  ->withValue($prg->getSubtypeId() == 0 ? "" : $prg->getSubtypeId())
256  ->withAdditionalTransformation($tf->custom(function ($v) {
257  if ($v == "") {
258  return 0;
259  }
260  return $v;
261  }))
262  ],
263  $txt("prg_type"),
264  ""
265  ),
266  $ff->section(
267  [
268  self::PROP_POINTS =>
269  $ff->numeric($txt("prg_points"))
270  ->withValue((string) $prg->getPoints())
271  ->withAdditionalConstraint($this->validation->greaterThan(-1)),
272  self::PROP_STATUS =>
273  $ff->select($txt("prg_status"), $status_options)
274  ->withValue((string) $prg->getStatus())
275  ->withRequired(true)
276  ],
277  $txt("prg_assessment"),
278  ""
279  )
280  ]
281  )
282  ->withAdditionalTransformation($tf->custom(function ($values) {
283  // values now contains the results of the single sections,
284  // i.e. a list of arrays that each contains keys according
285  // to the section they originated from.
286  return call_user_func_array("array_merge", $values);
287  }));
288  }
289 
290  protected function updateWith(\ilObjStudyProgramme $prg, array $data)
291  {
292  $prg->setTitle($data[self::PROP_TITLE]);
293  $prg->setDescription($data[self::PROP_DESC]);
294 
295  if ($prg->getSubtypeId() != $data[self::PROP_TYPE]) {
296  $prg->setSubtypeId($data[self::PROP_TYPE]);
297  $prg->updateCustomIcon();
298  $this->parent_gui->setTitleAndDescription();
299  }
300 
301  $prg->setPoints($data[self::PROP_POINTS]);
302  $prg->setStatus($data[self::PROP_STATUS]);
303 
304  $prg->update();
305  }
306 
307  protected function getObject()
308  {
309  if ($this->object === null) {
310  $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
311  }
312  return $this->object;
313  }
314 
315  protected static function getStatusOptions()
316  {
317  global $DIC;
318  $lng = $DIC['lng'];
319 
320  return array( ilStudyProgramme::STATUS_DRAFT
321  => $lng->txt("prg_status_draft")
323  => $lng->txt("prg_status_active")
325  => $lng->txt("prg_status_outdated")
326  );
327  }
328 }
Class ilAsyncOutputHandler Handles the output for async-requests.
Class Factory.
setPoints($a_points)
Set the amount of points.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
Class BaseForm.
setSubtypeId($a_subtype_id)
Sets the meta-data subtype id.
if(!array_key_exists('StateId', $_REQUEST)) $id
logging
Definition: class.ilLog.php:18
Class ilAccessHandler.
setStatus($a_status)
Set the status of the node.
setTitle($a_title)
set object title
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.
if(isset($_POST['submit'])) $form
$values
Class ilObjStudyProgramme.
getTitle()
get object title public
getDescription()
get object description
redirection script todo: (a better solution should control the processing via a xml file) ...
$txt
Definition: error.php:11
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
updateWith(\ilObjStudyProgramme $prg, array $data)
getSubtypeId()
Gets the meta-data subtype id (allows to add additional meta-data based on a type) ...
$this data['403_header']
setDescription($a_desc)
set object description
getPoints()
Get the amount of points.
$response
buildForm(\ilObjStudyProgramme $prg, string $submit_action)
Class ilObjStudyProgrammeSettingsGUI.
static handleAsyncOutput($normal_content, $async_content=null, $apply_to_tpl=true)
Handles async output.
$data
Definition: bench.php:6