19 declare(strict_types=0);
57 $this->tpl = $DIC->ui()->mainTemplate();
58 $this->
ctrl = $DIC->ctrl();
59 $this->
lng = $DIC->language();
60 $this->
access = $DIC->access();
61 $this->error = $DIC[
'ilErr'];
62 $this->
tabs = $DIC->tabs();
63 $this->
toolbar = $DIC->toolbar();
64 $this->
http = $DIC->http();
65 $this->ui_renderer = $DIC->ui()->renderer();
71 $this->
id = $a_obj_id;
72 $this->
ctrl->saveParameter($this,
'obj_id');
76 $this->grouping_table_handler =
new GroupingTableHandler(
77 $this->
ctrl->getLinkTarget($this,
'handleGroupingTableAction'),
78 $this->content_obj->getId(),
80 $DIC->ui()->factory(),
86 $this->assignment_table_handler =
new AssignmentTableHandler(
87 $this->
ctrl->getLinkTarget($this,
'handleAssignmentTableAction'),
88 $this->content_obj->getId(),
91 $DIC->ui()->factory(),
96 $DIC->repositoryTree()
102 $this->
tabs->setTabActive(
'crs_groupings');
103 $cmd = $this->
ctrl->getCmd();
104 if (!$cmd = $this->
ctrl->getCmd()) {
122 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
123 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
127 $this->
lng->txt(
'crs_add_grouping'),
128 $this->
ctrl->getLinkTarget($this,
'create')
131 $table = $this->grouping_table_handler->getTable();
132 $this->tpl->setContent($this->ui_renderer->render($table));
137 switch ($this->grouping_table_handler->getSelectedTableAction()) {
138 case GroupingTableHandler::ACTION_EDIT:
139 $selected = $this->grouping_table_handler->getSelectedGroupingIDs()[0] ?? 0;
140 $this->
ctrl->setParameter($this,
'obj_id', $selected);
141 $this->
ctrl->redirect($this,
'edit');
144 case GroupingTableHandler::ACTION_DELETE:
145 $this->
askDeleteGrouping(...$this->grouping_table_handler->getSelectedGroupingIDs());
152 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
153 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
156 if (!count($grouping_ids)) {
157 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'crs_grouping_select_one'));
164 $cgui->setFormAction($this->
ctrl->getFormAction($this));
165 $cgui->setHeaderText($this->
lng->txt(
"crs_grouping_delete_sure"));
166 $cgui->setCancel($this->
lng->txt(
"cancel"),
"listGroupings");
167 $cgui->setConfirm($this->
lng->txt(
"delete"),
"deleteGrouping");
170 foreach ($grouping_ids as $grouping_id) {
172 $cgui->addItem(
"grouping[]", $grouping_id, $tmp_obj->getTitle());
174 $this->tpl->setContent($cgui->getHTML());
179 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
180 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
183 if ($this->
http->wrapper()->post()->has(
'grouping')) {
184 $grouping = $this->
http->wrapper()->post()->retrieve(
186 $this->
refinery->kindlyTo()->listOf(
192 foreach ($grouping as $grouping_id) {
197 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'crs_grouping_deleted'),
true);
198 $this->
ctrl->redirect($this,
'listGroupings');
203 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
204 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
211 $this->tpl->setContent($a_form->getHTML());
217 $form->setFormAction($this->
ctrl->getFormAction($this));
220 $title->setRequired(
true);
221 $form->addItem($title);
224 $form->addItem($desc);
226 $options = array(
'login' =>
'login',
228 'matriculation' =>
'matriculation' 231 foreach ($options as $value => $caption) {
232 $options[$value] = $this->
lng->txt($caption);
236 $uniq->setOptions($options);
237 $form->addItem($uniq);
240 $form->setTitle($this->
lng->txt(
'crs_add_grouping'));
241 $form->addCommandButton(
'add', $this->
lng->txt(
'btn_add'));
244 $title->setValue($grouping->getTitle());
245 $desc->setValue($grouping->getDescription());
246 $uniq->setValue($grouping->getUniqueField());
248 $ass =
new ilCustomInputGUI($this->
lng->txt(
'groupings_assigned_obj_' . $this->getContentType()));
249 $form->addItem($ass);
253 foreach ($grouping->getAssignedItems() as $cond_data) {
257 $ass->setHtml(implode(
"<br />", $items));
259 $ass->setHtml($this->
lng->txt(
'crs_grp_no_courses_assigned'));
262 $form->setTitle($this->
lng->txt(
'edit_grouping'));
263 $form->addCommandButton(
'update', $this->
lng->txt(
'save'));
264 $form->addCommandButton(
'selectCourse', $this->
lng->txt(
'grouping_change_assignment'));
266 $form->addCommandButton(
'listGroupings', $this->
lng->txt(
'cancel'));
270 public function add(): void
273 if ($form->checkInput()) {
274 $this->grp_obj->setTitle($form->getInput(
'title'));
275 $this->grp_obj->setDescription($form->getInput(
'description'));
276 $this->grp_obj->setUniqueField($form->getInput(
'unique'));
278 $this->grp_obj->create($this->content_obj->getRefId(), $this->content_obj->getId());
279 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'crs_grp_added_grouping'),
true);
280 $this->
ctrl->redirect($this,
'listGroupings');
282 $form->setValuesByPost();
288 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
289 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
294 $this->tpl->setContent($a_form->getHTML());
299 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
300 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
304 if ($this->
http->wrapper()->query()->has(
'obj_id')) {
305 $obj_id = $this->
http->wrapper()->query()->retrieve(
311 if ($form->checkInput()) {
313 $tmp_grouping->setTitle($form->getInput(
'title'));
314 $tmp_grouping->setDescription($form->getInput(
'description'));
315 $tmp_grouping->setUniqueField($form->getInput(
'unique'));
316 $tmp_grouping->update();
318 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'settings_saved'),
true);
319 $this->
ctrl->redirect($this,
'listGroupings');
322 $form->setValuesByPost();
328 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
329 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
333 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'crs_grp_no_grouping_id_given'));
338 $this->
tabs->clearTargets();
339 $this->
tabs->setBackTarget(
340 $this->
lng->txt(
'back'),
341 $this->
ctrl->getLinkTarget($this,
'edit')
344 $table = $this->assignment_table_handler->getTable();
345 $this->tpl->setContent($this->ui_renderer->render($table));
350 switch ($this->assignment_table_handler->getSelectedTableAction()) {
351 case AssignmentTableHandler::ACTION_TOGGLE_ASSIGNMENT:
352 $this->
assignCourse(...$this->assignment_table_handler->getSelectedRefIDs());
359 if (!$this->
access->checkAccess(
'write',
'', $this->content_obj->getRefId())) {
360 $this->error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
371 $assigned = $grouping->getAssignedItems();
372 $old_assigned_ref_ids = [];
373 foreach ($assigned as $item) {
374 $old_assigned_ref_ids[] = $item[
'target_ref_id'];
376 $new_assigned_ref_ids = array_merge(
377 array_diff($old_assigned_ref_ids, $ref_ids),
378 array_diff($ref_ids, $old_assigned_ref_ids)
383 $condh->deleteByObjId($this->
id);
385 foreach ($new_assigned_ref_ids as
$ref_id) {
388 $tmp_condh->enableAutomaticValidation(
false);
390 $tmp_condh->setTargetRefId($ref_id);
391 $tmp_condh->setTargetObjId($tmp_crs->getId());
393 $tmp_condh->setTriggerRefId(0);
394 $tmp_condh->setTriggerObjId($this->
id);
395 $tmp_condh->setTriggerType(
'crsg');
396 $tmp_condh->setOperator(
'not_member');
397 $tmp_condh->setValue($this->grp_obj->getUniqueField());
399 if (!$tmp_condh->checkExists()) {
400 $tmp_condh->storeCondition();
404 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'settings_saved'),
true);
405 $this->
ctrl->redirect($this,
'edit');
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)
handleGroupingTableAction()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
static _lookupTitle(int $obj_id)
askDeleteGrouping(int ... $grouping_ids)
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
handleAssignmentTableAction()
Class ilObjCourseGroupingGUI.
assignCourse(int ... $ref_ids)
RefineryFactory $refinery
AssignmentTableHandler $assignment_table_handler
This class represents a text area property in a property form.
ilObjCourseGrouping $grp_obj
static _lookupType(int $id, bool $reference=false)
GroupingTableHandler $grouping_table_handler