ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjCourseGroupingGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
23 
29 {
31  private int $id;
33  private string $content_type = '';
34 
37  protected ilLanguage $lng;
40  protected ilTabsGUI $tabs;
43  protected Factory $refinery;
44 
45  public function __construct(ilObject $content_obj, int $a_obj_id = 0)
46  {
47  global $DIC;
48 
49  $this->tpl = $DIC->ui()->mainTemplate();
50  $this->ctrl = $DIC->ctrl();
51  $this->lng = $DIC->language();
52  $this->access = $DIC->access();
53  $this->error = $DIC['ilErr'];
54  $this->tabs = $DIC->tabs();
55  $this->toolbar = $DIC->toolbar();
56  $this->http = $DIC->http();
57  $this->refinery = $DIC->refinery();
58 
59  $this->content_obj = $content_obj;
60  $this->content_type = ilObject::_lookupType($this->content_obj->getId());
61 
62  $this->id = $a_obj_id;
63  $this->ctrl->saveParameter($this, 'obj_id');
64  $this->__initGroupingObject();
65  }
66 
67  public function executeCommand(): void
68  {
69  $this->tabs->setTabActive('crs_groupings');
70  $cmd = $this->ctrl->getCmd();
71  if (!$cmd = $this->ctrl->getCmd()) {
72  $cmd = "edit";
73  }
74  $this->$cmd();
75  }
76 
77  public function __initGroupingObject(): void
78  {
79  $this->grp_obj = new ilObjCourseGrouping($this->id);
80  }
81 
82  public function getContentType(): string
83  {
84  return $this->content_type;
85  }
86 
87  public function listGroupings(): void
88  {
89  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
90  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
91  }
92 
93  $this->toolbar->addButton(
94  $this->lng->txt('crs_add_grouping'),
95  $this->ctrl->getLinkTarget($this, 'create')
96  );
97 
98  $table = new ilCourseGroupingTableGUI($this, 'listGroupings', $this->content_obj);
99  $this->tpl->setContent($table->getHTML());
100  }
101 
102  public function askDeleteGrouping(): void
103  {
104  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
105  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
106  }
107 
108  $grouping = [];
109  if ($this->http->wrapper()->post()->has('grouping')) {
110  $grouping = $this->http->wrapper()->post()->retrieve(
111  'grouping',
112  $this->refinery->kindlyTo()->listOf(
113  $this->refinery->kindlyTo()->int()
114  )
115  );
116  }
117 
118  if (!count($grouping)) {
119  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_grouping_select_one'));
120  $this->listGroupings();
121  return;
122  }
123 
124  // display confirmation message
125  $cgui = new ilConfirmationGUI();
126  $cgui->setFormAction($this->ctrl->getFormAction($this));
127  $cgui->setHeaderText($this->lng->txt("crs_grouping_delete_sure"));
128  $cgui->setCancel($this->lng->txt("cancel"), "listGroupings");
129  $cgui->setConfirm($this->lng->txt("delete"), "deleteGrouping");
130 
131  // list objects that should be deleted
132  foreach ($grouping as $grouping_id) {
133  $tmp_obj = new ilObjCourseGrouping($grouping_id);
134  $cgui->addItem("grouping[]", $grouping_id, $tmp_obj->getTitle());
135  }
136  $this->tpl->setContent($cgui->getHTML());
137  }
138 
139  public function deleteGrouping(): void
140  {
141  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
142  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
143  }
144  $grouping = [];
145  if ($this->http->wrapper()->post()->has('grouping')) {
146  $grouping = $this->http->wrapper()->post()->retrieve(
147  'grouping',
148  $this->refinery->kindlyTo()->listOf(
149  $this->refinery->kindlyTo()->int()
150  )
151  );
152  }
153 
154  foreach ($grouping as $grouping_id) {
155  $tmp_obj = new ilObjCourseGrouping((int) $grouping_id);
156  $tmp_obj->delete();
157  }
158 
159  $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_grouping_deleted'), true);
160  $this->ctrl->redirect($this, 'listGroupings');
161  }
162 
163  public function create(?ilPropertyFormGUI $a_form = null): void
164  {
165  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
166  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
167  }
168 
169  if (!$a_form) {
170  $a_form = $this->initForm(true);
171  }
172 
173  $this->tpl->setContent($a_form->getHTML());
174  }
175 
176  public function initForm(bool $a_create): ilPropertyFormGUI
177  {
178  $form = new ilPropertyFormGUI();
179  $form->setFormAction($this->ctrl->getFormAction($this));
180 
181  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
182  $title->setRequired(true);
183  $form->addItem($title);
184 
185  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
186  $form->addItem($desc);
187 
188  $options = array('login' => 'login',
189  'email' => 'email',
190  'matriculation' => 'matriculation'
191  );
192 
193  foreach ($options as $value => $caption) {
194  $options[$value] = $this->lng->txt($caption);
195  }
196  $uniq = new ilSelectInputGUI($this->lng->txt('unambiguousness'), 'unique');
197  $uniq->setRequired(true);
198  $uniq->setOptions($options);
199  $form->addItem($uniq);
200 
201  if ($a_create) {
202  $form->setTitle($this->lng->txt('crs_add_grouping'));
203  $form->addCommandButton('add', $this->lng->txt('btn_add'));
204  } else {
205  $grouping = new ilObjCourseGrouping($this->id);
206  $title->setValue($grouping->getTitle());
207  $desc->setValue($grouping->getDescription());
208  $uniq->setValue($grouping->getUniqueField());
209 
210  $ass = new ilCustomInputGUI($this->lng->txt('groupings_assigned_obj_' . $this->getContentType()));
211  $form->addItem($ass);
212 
213  // assignments
214  $items = array();
215  foreach ($grouping->getAssignedItems() as $cond_data) {
216  $items[] = ilObject::_lookupTitle($cond_data['target_obj_id']);
217  }
218  if ($items !== []) {
219  $ass->setHtml(implode("<br />", $items));
220  } else {
221  $ass->setHtml($this->lng->txt('crs_grp_no_courses_assigned'));
222  }
223 
224  $form->setTitle($this->lng->txt('edit_grouping'));
225  $form->addCommandButton('update', $this->lng->txt('save'));
226  $form->addCommandButton('selectCourse', $this->lng->txt('grouping_change_assignment'));
227  }
228  $form->addCommandButton('listGroupings', $this->lng->txt('cancel'));
229  return $form;
230  }
231 
232  public function add(): void
233  {
234  $form = $this->initForm(true);
235  if ($form->checkInput()) {
236  $this->grp_obj->setTitle($form->getInput('title'));
237  $this->grp_obj->setDescription($form->getInput('description'));
238  $this->grp_obj->setUniqueField($form->getInput('unique'));
239 
240  $this->grp_obj->create($this->content_obj->getRefId(), $this->content_obj->getId());
241  $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_grp_added_grouping'), true);
242  $this->ctrl->redirect($this, 'listGroupings');
243  }
244  $form->setValuesByPost();
245  $this->create($form);
246  }
247 
248  public function edit(?ilPropertyFormGUI $a_form = null): void
249  {
250  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
251  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
252  }
253  if (!$a_form) {
254  $a_form = $this->initForm(false);
255  }
256  $this->tpl->setContent($a_form->getHTML());
257  }
258 
259  public function update(): void
260  {
261  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
262  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
263  }
264 
265  $obj_id = 0;
266  if ($this->http->wrapper()->query()->has('obj_id')) {
267  $obj_id = $this->http->wrapper()->query()->retrieve(
268  'obj_id',
269  $this->refinery->kindlyTo()->int()
270  );
271  }
272  $form = $this->initForm(false);
273  if ($form->checkInput()) {
274  $tmp_grouping = new ilObjCourseGrouping($obj_id);
275  $tmp_grouping->setTitle($form->getInput('title'));
276  $tmp_grouping->setDescription($form->getInput('description'));
277  $tmp_grouping->setUniqueField($form->getInput('unique'));
278  $tmp_grouping->update();
279 
280  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
281  $this->ctrl->redirect($this, 'listGroupings');
282  }
283 
284  $form->setValuesByPost();
285  $this->edit($form);
286  }
287 
288  public function selectCourse(): void
289  {
290  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
291  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
292  }
293 
294  if (!$this->id) {
295  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('crs_grp_no_grouping_id_given'));
296  $this->listGroupings();
297  return;
298  }
299 
300  $this->tabs->clearTargets();
301  $this->tabs->setBackTarget(
302  $this->lng->txt('back'),
303  $this->ctrl->getLinkTarget($this, 'edit')
304  );
305  $tmp_grouping = new ilObjCourseGrouping($this->id);
306  $table = new ilCourseGroupingAssignmentTableGUI($this, 'selectCourse', $this->content_obj, $tmp_grouping);
307  $this->tpl->setContent($table->getHTML());
308  }
309 
310  public function assignCourse(): void
311  {
312  if (!$this->access->checkAccess('write', '', $this->content_obj->getRefId())) {
313  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
314  }
315 
316  if (!$this->id) {
317  $this->listGroupings();
318  return;
319  }
320 
321  // delete all existing conditions
322  $condh = new ilConditionHandler();
323  $condh->deleteByObjId($this->id);
324 
325  $added = 0;
326  $container_ids = [];
327  if ($this->http->wrapper()->post()->has('crs_ids')) {
328  $container_ids = $this->http->wrapper()->post()->retrieve(
329  'crs_ids',
330  $this->refinery->kindlyTo()->listOf(
331  $this->refinery->kindlyTo()->int()
332  )
333  );
334  }
335 
336  foreach ($container_ids as $course_ref_id) {
337  $tmp_crs = ilObjectFactory::getInstanceByRefId($course_ref_id);
338  $tmp_condh = new ilConditionHandler();
339  $tmp_condh->enableAutomaticValidation(false);
340 
341  $tmp_condh->setTargetRefId($course_ref_id);
342  $tmp_condh->setTargetObjId($tmp_crs->getId());
343  $tmp_condh->setTargetType($this->getContentType());
344  $tmp_condh->setTriggerRefId(0);
345  $tmp_condh->setTriggerObjId($this->id);
346  $tmp_condh->setTriggerType('crsg');
347  $tmp_condh->setOperator('not_member');
348  $tmp_condh->setValue($this->grp_obj->getUniqueField());
349 
350  if (!$tmp_condh->checkExists()) {
351  $tmp_condh->storeCondition();
352  ++$added;
353  }
354  }
355 
356  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
357  $this->ctrl->redirect($this, 'edit');
358  }
359 } // END class.ilObjCourseGrouping
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
edit(?ilPropertyFormGUI $a_form=null)
create(?ilPropertyFormGUI $a_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
__construct(ilObject $content_obj, int $a_obj_id=0)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
static _lookupTitle(int $obj_id)
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 getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObjCourseGroupingGUI.
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...
Error Handling & global info handling uses PEAR error class.
This class represents a text area property in a property form.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...