ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  {
63  $tpl = $this->tpl;
64 
65  $this->displayValidationError();
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  {
78  $tpl = $this->tpl;
79 
80  $this->displayValidationError();
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;
94  $ilUser = $this->user;
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  // begin-abandon ch_groups
115  $mode->setValue('auto');
116  /*
117  $opt_manual = new ilRadioOption($this->lng->txt("cont_cach_mode_manual"), "manual");
118  $opt_manual->setInfo($this->lng->txt("cont_cach_mode_manual_info"));
119  $mode->addOption($opt_manual);
120 
121  if (!$this->getPageConfig()->getEnablePCType("PlaceHolder")) {
122  $grp_ids = ilConsultationHourGroups::getGroupsOfUser($ilUser->getId());
123  if (count($grp_ids)) {
124  $this->lng->loadLanguageModule("dateplaner");
125  $groups = new ilCheckboxGroupInputGUI($this->lng->txt("cal_ch_app_grp"), "grp");
126  $groups->setRequired(true);
127  $opt_manual->addSubItem($groups);
128 
129  foreach ($grp_ids as $grp_obj) {
130  $groups->addOption(new ilCheckboxOption($grp_obj->getTitle(), $grp_obj->getGroupId()));
131  }
132  } else {
133  $opt_manual->setDisabled(true);
134  }
135  } else {
136  $opt_manual->setDisabled(true);
137  }
138  */
139  // end-abandon ch_groups
140 
141  if ($a_insert) {
142  $mode->setValue("auto");
143 
144  $form->addCommandButton("create_consultation_hours", $this->lng->txt("select"));
145  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
146  } else {
147  // begin-abandon ch_groups
148  // set values
149  /*
150  $grp_ids = $this->content_obj->getGroupIds();
151  if (count($grp_ids)) {
152  $mode->setValue("manual");
153  $groups->setValue($grp_ids);
154  } else {
155  $mode->setValue("auto");
156  }
157  */
158  // end-abandon ch_groups
159 
160  $form->addCommandButton("update", $this->lng->txt("select"));
161  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
162  }
163 
164  return $form;
165  }
166 
167  public function create_consultation_hours(): void
168  {
169  $this->create();
170  }
171 
172  public function create(): void
173  {
174  $form = $this->initForm(true);
175  if ($form->checkInput()) {
176  $grp_ids = null;
177  $mode = $form->getInput("mode");
178  if ($mode == "manual") {
179  $grp_ids = $form->getInput("grp");
180  }
181 
182  $this->content_obj = new ilPCConsultationHours($this->getPage());
183  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
184  $this->content_obj->setData($mode, (array) $grp_ids);
185  $this->updated = $this->pg_obj->update();
186  if ($this->updated === true) {
187  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
188  }
189  }
190 
191  $form->setValuesByPost();
192  $this->insert($form);
193  }
194 
195  public function update(): void
196  {
197  $form = $this->initForm();
198  if ($form->checkInput()) {
199  $grp_ids = array();
200  $mode = $form->getInput("mode");
201  if ($mode == "manual") {
202  $grp_ids = $form->getInput("grp");
203  }
204 
205  $this->content_obj->setData($mode, $grp_ids);
206  $this->updated = $this->pg_obj->update();
207  if ($this->updated === true) {
208  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
209  }
210  }
211 
212  $this->pg_obj->addHierIDs();
213  $form->setValuesByPost();
214  $this->edit($form);
215  }
216 }
This class represents an option in a radio group.
edit(?ilPropertyFormGUI $a_form=null)
Edit consultation hours form.
setInfo(string $a_info)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
Content object of ilPageObject (see ILIAS DTD).
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:22
ilGlobalTemplateInterface $tpl
setRequired(bool $a_required)
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.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
__construct(Container $dic, ilPlugin $plugin)
insert(?ilPropertyFormGUI $a_form=null)
Insert consultation hours form.