ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjStudyProgrammeSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
6/* Copyright (c) 2020 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
7
8use GuzzleHttp\Psr7\ServerRequest;
12
18{
19 const TAB_SETTINGS = 'settings';
20 const TAB_COMMON_SETTINGS = 'commonSettings';
21
22 const PROP_TITLE = "title";
23 const PROP_DESC = "desc";
24 const PROP_DEADLINE = "deadline";
25 const PROP_VALIDITY_OF_QUALIFICATION = "validity_qualification";
26 const PROP_ACCESS_CONTROL_BY_ORGU_POSITION = "access_ctr_by_orgu_position";
27
28 const OPT_NO_DEADLINE = 'opt_no_deadline';
29 const OPT_DEADLINE_PERIOD = "opt_deadline_period";
30 const OPT_DEADLINE_DATE = "opt_deadline_date";
31
32 const OPT_NO_VALIDITY_OF_QUALIFICATION = 'opt_no_validity_qualification';
33 const OPT_VALIDITY_OF_QUALIFICATION_PERIOD = "opt_validity_qualification_period";
34 const OPT_VALIDITY_OF_QUALIFICATION_DATE = "opt_validity_qualification_date";
35
36
40 public $ctrl;
41
45 public $tpl;
46
50 public $object;
51
55 public $lng;
56
60 protected $tmp_heading;
61
65 protected $input_factory;
66
70 protected $renderer;
71
75 protected $request;
76
81
85 protected $ref_id;
86
90 protected $data_factory;
91
96
101
105 protected $tabs;
106
107 public function __construct(
109 \ilCtrl $ilCtrl,
113 ServerRequest $request,
119 ) {
120 $this->tpl = $tpl;
121 $this->ctrl = $ilCtrl;
122 $this->lng = $lng;
123 $this->input_factory = $input_factory;
124 $this->renderer = $renderer;
125 $this->request = $request;
126 $this->refinery_factory = $refinery_factory;
127 $this->data_factory = $data_factory;
128 $this->type_repository = $type_repository;
129 $this->object = null;
130 $this->common_settings_gui = $common_settings_gui;
131 $this->tabs = $tabs;
132
133 $lng->loadLanguageModule("prg");
134 }
135
136 public function setRefId($a_ref_id)
137 {
138 $this->ref_id = $a_ref_id;
139 }
140
141 public function executeCommand()
142 {
143 $next_class = $this->ctrl->getNextClass();
144 switch ($next_class) {
145 case 'ilstudyprogrammecommonsettingsgui':
146 $this->tabs->activateSubTab(self::TAB_COMMON_SETTINGS);
147 $this->common_settings_gui->setObject($this->getObject());
148 $content = $this->ctrl->forwardCommand($this->common_settings_gui);
149 break;
150 default:
151 $cmd = $this->ctrl->getCmd();
152 if ($cmd == "") {
153 $cmd = "view";
154 }
155 switch ($cmd) {
156 case "view":
157 $content = $this->view();
158 break;
159 case "update":
160 $content = $this->$cmd();
161 break;
162 default:
163 throw new ilException(
164 "ilObjStudyProgrammeSettingsGUI: " . "Command not supported: $cmd"
165 );
166 }
167 }
168
169 if (!$this->ctrl->isAsynch()) {
170 $this->tpl->setContent($content);
171 } else {
172 $output_handler = new ilAsyncOutputHandler();
173 $heading = $this->lng->txt("prg_async_" . $this->ctrl->getCmd());
174 if (isset($this->tmp_heading)) {
175 $heading = $this->tmp_heading;
176 }
177 $output_handler->setHeading($heading);
178 $output_handler->setContent($content);
179 $output_handler->terminate();
180 }
181 }
182
183 protected function view()
184 {
185 $this->buildModalHeading($this->lng->txt('prg_async_settings'), isset($_GET["currentNode"]));
186
187 $form = $this->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"));
188 return $this->renderer->render($form);
189 }
190
191 protected function update()
192 {
193 $form = $this
194 ->buildForm($this->getObject(), $this->ctrl->getFormAction($this, "update"))
195 ->withRequest($this->request);
196
197 $result = $form->getInputGroup()->getContent();
198
199 // This could further improved by providing a new container for asynch-forms in the
200 // UI-Framework.
201
202 if ($result->isOK()) {
203 $result->value()->update();
204 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
205
206 if ($this->ctrl->isAsynch()) {
208 array(
209 "success" => true,
210 "message" => $this->lng->txt("msg_obj_modified"))
211 );
212 return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
213 } else {
214 $this->ctrl->redirect($this);
215 }
216 } else {
217 ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
218
219 if ($this->ctrl->isAsynch()) {
221 array(
222 "success" => false,
223 "errors" => $form->getErrors())
224 );
225 return ilAsyncOutputHandler::handleAsyncOutput($form->getHTML(), $response, false);
226 } else {
227 return $this->renderer->render($form);
228 }
229 }
230 }
231
232 protected function buildModalHeading($label, $current_node)
233 {
234 if (!$current_node) {
235 $this->ctrl->saveParameterByClass('ilobjstudyprogrammesettingsgui', 'ref_id');
236 $heading_button = ilLinkButton::getInstance();
237 $heading_button->setCaption('prg_open_node');
238 $heading_button->setUrl(
239 $this->ctrl->getLinkTargetByClass(
240 'ilobjstudyprogrammetreegui',
241 'view'
242 )
243 );
244
245 $heading =
246 "<div class=''>" .
247 $label .
248 "<div class='pull-right'>" .
249 $heading_button->render() .
250 "</div></div>"
251 ;
252 $this->tmp_heading = $heading;
253 } else {
254 $this->tmp_heading = "<div class=''>" . $label . "</div>";
255 }
256 }
257
258 protected function buildForm(
260 string $submit_action
261 ) : ILIAS\UI\Component\Input\Container\Form\Form {
262 $trans = $prg->getObjectTranslation();
263 $ff = $this->input_factory->field();
264 $sp_types = $this->type_repository->getAllTypesArray();
265 $settings = $prg->getSettings();
266
267 return $this->input_factory->container()->form()->standard(
268 $submit_action,
269 $this->buildFormElements(
270 $ff,
271 $trans,
272 $sp_types,
273 $settings
274 )
275 )->withAdditionalTransformation(
276 $this->refinery_factory->custom()->transformation(
277 function ($values) use ($prg) {
278 $object_data = $values[0];
279 $prg->setTitle($object_data[self::PROP_TITLE]);
280 $prg->setDescription($object_data[self::PROP_DESC]);
281
282 $settings = $prg->getSettings()
283 ->withAssessmentSettings($values['prg_assessment'])
284 ->withDeadlineSettings($values['prg_deadline'])
285 ->withValidityOfQualificationSettings($values['prg_validity_of_qualification'])
286 ->withAutoMailSettings($values['automail_settings'])
287 ->withTypeSettings($values['prg_type']);
288
289 $prg->updateSettings($settings);
290 $prg->updateCustomIcon();
291 return $prg;
292 }
293 )
294 );
295 }
296
297 protected function buildFormElements(
298 InputFieldFactory $ff,
299 ilObjectTranslation $trans,
300 array $sp_types,
302 ) : array {
303 global $DIC;
304 $ilLng = $DIC->language();
305 $refinery = $DIC["refinery"];
306
307 $return = [
308 $this->getEditSection($ff, $trans),
309 "prg_type" => $settings
311 ->toFormInput($ff, $ilLng, $refinery, $sp_types)
312 ,
313 "prg_assessment" => $settings
315 ->toFormInput($ff, $ilLng, $refinery)
316 ,
317 "prg_deadline" => $settings
319 ->toFormInput($ff, $ilLng, $refinery, $this->data_factory)
320 ,
321 "prg_validity_of_qualification" => $settings
323 ->toFormInput($ff, $ilLng, $refinery, $this->data_factory)
324 ,
325 "automail_settings" => $settings
327 ->toFormInput($ff, $ilLng, $refinery)
328 ];
329
330 return $return;
331 }
332
333 protected function getEditSection(
334 InputFieldFactory $ff,
336 ) {
337 $languages = ilMDLanguageItem::_getLanguages();
338 return $ff->section(
339 [
340 self::PROP_TITLE =>
341 $ff->text($this->txt("title"))
342 ->withValue($trans->getDefaultTitle())
343 ->withRequired(true),
344 self::PROP_DESC =>
345 $ff->textarea($this->txt("description"))
346 ->withValue($trans->getDefaultDescription() ?? "")
347 ],
348 $this->txt("prg_edit"),
349 $this->txt("language") . ": " . $languages[$trans->getDefaultLanguage()] .
350 ' <a href="' . $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "") .
351 '">&raquo; ' . $this->txt("obj_more_translations") . '</a>'
352 );
353 }
354
355 protected function getObject() : ilObjStudyProgramme
356 {
357 if ($this->object === null) {
358 $this->object = ilObjStudyProgramme::getInstanceByRefId($this->ref_id);
359 }
360 return $this->object;
361 }
362
363 protected function txt(string $code) : string
364 {
365 return $this->lng->txt($code);
366 }
367}
$result
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
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.
This class provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static getInstance()
Factory.
@ilCtrl_Calls ilObjStudyProgrammeSettingsGUI: ilStudyProgrammeCommonSettingsGUI
__construct(\ilGlobalTemplateInterface $tpl, \ilCtrl $ilCtrl, \ilLanguage $lng, Factory $input_factory, Renderer $renderer, ServerRequest $request, \ILIAS\Refinery\Factory $refinery_factory, \ILIAS\Data\Factory $data_factory, ilStudyProgrammeTypeRepository $type_repository, ilStudyProgrammeCommonSettingsGUI $common_settings_gui, ilTabsGUI $tabs)
buildForm(\ilObjStudyProgramme $prg, string $submit_action)
buildFormElements(InputFieldFactory $ff, ilObjectTranslation $trans, array $sp_types, ilStudyProgrammeSettings $settings)
getEditSection(InputFieldFactory $ff, ilObjectTranslation $trans)
updateSettings(ilStudyProgrammeSettings $settings)
static getInstanceByRefId($a_ref_id)
Class handles translation mode for an object.
getDefaultTitle()
Get default title.
getDefaultDescription()
Get default description.
getDefaultLanguage()
Get default language.
setTitle($a_title)
set object title
setDescription($a_desc)
set object description
Tabs GUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
This is how a factory for inputs looks like.
Definition: Factory.php:11
An entity that renders components to a string output.
Definition: Renderer.php:15
Covers the persistence of sp-type related information.
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$response