ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStudyProgrammeCommonSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private const CMD_EDIT = 'editSettings';
24 private const CMD_SAVE = 'saveSettings';
25
26 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
30
31 protected ?ilObjStudyProgramme $object = null;
32
33 public function __construct(
38 ) {
39 $this->ctrl = $ctrl;
40 $this->tpl = $tpl;
41 $this->lng = $lng;
42 $this->object_service = $object_service;
43 }
44
49 public function executeCommand()
50 {
51 if (is_null($this->object)) {
52 throw new Exception('Object of ilObjStudyProgramme is not set');
53 }
54
55 $cmd = $this->ctrl->getCmd();
56 switch ($cmd) {
57 case self::CMD_EDIT:
58 return $this->editSettings();
59 case self::CMD_SAVE:
60 $this->saveSettings();
61 break;
62 default:
63 throw new Exception('Unknown command ' . $cmd);
64 }
65 }
66
67 public function setObject(ilObjStudyProgramme $object): void
68 {
69 $this->object = $object;
70 }
71
72 protected function editSettings(?ilPropertyFormGUI $form = null): string
73 {
74 if (is_null($form)) {
75 $form = $this->buildForm();
76 }
77 return $form->getHTML();
78 }
79
80 protected function buildForm(): ilPropertyFormGUI
81 {
82 $form = new ilPropertyFormGUI();
83 $form->setFormAction($this->ctrl->getFormAction($this));
84 $form->setTitle($this->txt('obj_features'));
85 $form->addCommandButton(self::CMD_SAVE, $this->txt('save'));
86 $form->addCommandButton(self::CMD_EDIT, $this->txt('cancel'));
87
88 $this->addServiceSettingsToForm($form);
89
90 return $form;
91 }
92
93 protected function addServiceSettingsToForm(ilPropertyFormGUI $form): void
94 {
96 $this->object->getId(),
97 $form,
98 [
100 ]
101 );
102 }
103
104 protected function saveSettings(): void
105 {
106 $form = $this->buildForm();
107
108 if (!$form->checkInput()) {
109 $form->setValuesByPost();
110 $this->editSettings($form);
111 return;
112 }
113
115 $this->object->getId(),
116 $form,
117 [
119 ]
120 );
121
122 $this->tpl->setOnScreenMessage("success", $this->lng->txt('msg_obj_modified'), true);
123 $this->ctrl->redirect($this, self::CMD_EDIT);
124 }
125
126 protected function txt(string $code): string
127 {
128 return $this->lng->txt($code);
129 }
130}
Class ilCtrl provides processing control methods.
language handling
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
This class represents a property form user interface.
__construct(ilCtrl $ctrl, ilGlobalTemplateInterface $tpl, ilLanguage $lng, ilObjectService $object_service)