ILIAS  release_8 Revision v8.24
class.ilPCConsultationHoursGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilObjUser $user;
27
28 public function __construct(
29 ilPageObject $a_pg_obj,
30 ?ilPageContent $a_content_obj,
31 string $a_hier_id,
32 string $a_pc_id = ""
33 ) {
34 global $DIC;
35
36 $this->tpl = $DIC["tpl"];
37 $this->ctrl = $DIC->ctrl();
38 $this->user = $DIC->user();
39 $this->lng = $DIC->language();
40 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
41 }
42
43 public function executeCommand(): void
44 {
45 // get next class that processes or forwards current command
46 $next_class = $this->ctrl->getNextClass($this);
47
48 // get current command
49 $cmd = $this->ctrl->getCmd();
50
51 switch ($next_class) {
52 default:
53 $this->$cmd();
54 break;
55 }
56 }
57
61 public function insert(ilPropertyFormGUI $a_form = null): void
62 {
64
66
67 if (!$a_form) {
68 $a_form = $this->initForm(true);
69 }
70 $tpl->setContent($a_form->getHTML());
71 }
72
76 public function edit(ilPropertyFormGUI $a_form = null): void
77 {
79
81
82 if (!$a_form) {
83 $a_form = $this->initForm();
84 }
85 $tpl->setContent($a_form->getHTML());
86 }
87
91 protected function initForm(bool $a_insert = false): ilPropertyFormGUI
92 {
93 $ilCtrl = $this->ctrl;
95
96 $groups = null;
97
98 $form = new ilPropertyFormGUI();
99 $form->setFormAction($ilCtrl->getFormAction($this));
100 if ($a_insert) {
101 $form->setTitle($this->lng->txt("cont_insert_consultation_hours"));
102 } else {
103 $form->setTitle($this->lng->txt("cont_update_consultation_hours"));
104 }
105
106 $mode = new ilRadioGroupInputGUI($this->lng->txt("cont_cach_mode"), "mode");
107 $mode->setRequired(true);
108 $form->addItem($mode);
109
110 $opt_auto = new ilRadioOption($this->lng->txt("cont_cach_mode_automatic"), "auto");
111 $opt_auto->setInfo($this->lng->txt("cont_cach_mode_automatic_info"));
112 $mode->addOption($opt_auto);
113
114 $opt_manual = new ilRadioOption($this->lng->txt("cont_cach_mode_manual"), "manual");
115 $opt_manual->setInfo($this->lng->txt("cont_cach_mode_manual_info"));
116 $mode->addOption($opt_manual);
117
118 if (!$this->getPageConfig()->getEnablePCType("PlaceHolder")) {
120 if (count($grp_ids)) {
121 $this->lng->loadLanguageModule("dateplaner");
122 $groups = new ilCheckboxGroupInputGUI($this->lng->txt("cal_ch_app_grp"), "grp");
123 $groups->setRequired(true);
124 $opt_manual->addSubItem($groups);
125
126 foreach ($grp_ids as $grp_obj) {
127 $groups->addOption(new ilCheckboxOption($grp_obj->getTitle(), $grp_obj->getGroupId()));
128 }
129 } else {
130 $opt_manual->setDisabled(true);
131 }
132 } else {
133 $opt_manual->setDisabled(true);
134 }
135
136 if ($a_insert) {
137 $mode->setValue("auto");
138
139 $form->addCommandButton("create_consultation_hours", $this->lng->txt("select"));
140 $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
141 } else {
142 // set values
143 $grp_ids = $this->content_obj->getGroupIds();
144 if (count($grp_ids)) {
145 $mode->setValue("manual");
146 $groups->setValue($grp_ids);
147 } else {
148 $mode->setValue("auto");
149 }
150
151 $form->addCommandButton("update", $this->lng->txt("select"));
152 $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
153 }
154
155 return $form;
156 }
157
158 public function create(): void
159 {
160 $form = $this->initForm(true);
161 if ($form->checkInput()) {
162 $grp_ids = null;
163 $mode = $form->getInput("mode");
164 if ($mode == "manual") {
165 $grp_ids = $form->getInput("grp");
166 }
167
168 $this->content_obj = new ilPCConsultationHours($this->getPage());
169 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
170 $this->content_obj->setData($mode, (array) $grp_ids);
171 $this->updated = $this->pg_obj->update();
172 if ($this->updated === true) {
173 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
174 }
175 }
176
177 $form->setValuesByPost();
178 $this->insert($form);
179 }
180
181 public function update(): void
182 {
183 $form = $this->initForm();
184 if ($form->checkInput()) {
185 $grp_ids = array();
186 $mode = $form->getInput("mode");
187 if ($mode == "manual") {
188 $grp_ids = $form->getInput("grp");
189 }
190
191 $this->content_obj->setData($mode, $grp_ids);
192 $this->updated = $this->pg_obj->update();
193 if ($this->updated === true) {
194 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
195 }
196 }
197
198 $this->pg_obj->addHierIDs();
199 $form->setValuesByPost();
200 $this->edit($form);
201 }
202}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getGroupsOfUser(int $a_user_id)
Get a all groups of an user.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initForm(bool $a_insert=false)
Init consultation hours form.
insert(ilPropertyFormGUI $a_form=null)
Insert consultation hours form.
edit(ilPropertyFormGUI $a_form=null)
Edit consultation hours form.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
setContent(string $a_html)
Sets content for standard template.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc