ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
class.ilPortfolioRoleAssignmentGUI.php
Go to the documentation of this file.
1<?php
2
21
27{
29 protected int $ref_id;
31 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
36
37 public function __construct()
38 {
39 global $DIC;
40
41 $this->toolbar = $DIC->toolbar();
42 $this->ctrl = $DIC->ctrl();
43 $this->lng = $DIC->language();
44 $this->main_tpl = $DIC->ui()->mainTemplate();
45 $this->manager = new PortfolioRoleAssignmentManager();
46 $this->port_request = $DIC->portfolio()
47 ->internal()
48 ->gui()
49 ->standardRequest();
50 $this->ref_id = $this->port_request->getRefId();
51 $this->access = $DIC->access();
52 }
53
54 public function executeCommand(): void
55 {
57
58 $next_class = $ctrl->getNextClass($this);
59 $cmd = $ctrl->getCmd("listAssignments");
60
61 switch ($next_class) {
62 case "ilpropertyformgui":
63 $form = $this->initAssignmentForm();
64 $ctrl->forwardCommand($form);
65 break;
66
67 default:
68 if (in_array($cmd, [
69 "listAssignments",
70 "addAssignment",
71 "saveAssignment",
72 "confirmAssignmentDeletion",
73 "deleteAssignments"
74 ])) {
75 $this->$cmd();
76 }
77 }
78 }
79
80 protected function listAssignments(): void
81 {
83 if ($this->checkWrite()) {
84 $this->toolbar->addButton(
85 $lng->txt("prtf_add_assignment"),
86 $this->ctrl->getLinkTarget($this, "addAssignment")
87 );
88 }
89
91 $this,
92 "listAssignments",
93 $this->manager,
94 $this->checkWrite()
95 );
96 $this->main_tpl->setContent($table->getHTML());
97 }
98
99 protected function addAssignment(): void
100 {
102 $form = $this->initAssignmentForm();
103 $main_tpl->setContent($form->getHTML());
104 }
105
107 {
110
111 $form = new ilPropertyFormGUI();
112
113 $options = $this->manager->getAvailableRoles();
114 $si_roles = new ilSelectInputGUI($this->lng->txt("prtf_role_title"), 'role_id');
115 $si_roles->setRequired(true);
116 $si_roles->setOptions($options);
117 $form->addItem($si_roles);
118
119 $repo = new ilRepositorySelector2InputGUI($lng->txt("prtf_template_title"), "template_ref_id");
120 $repo->setRequired(true);
121 $repo->getExplorerGUI()->setSelectableTypes(array("prtt"));
122 $repo->getExplorerGUI()->setTypeWhiteList(array("root", "prtt", "cat", "crs", "grp", "fold"));
123 $form->addItem($repo);
124
125 // save and cancel commands
126 $form->addCommandButton("saveAssignment", $lng->txt("save"));
127 $form->addCommandButton("listAssignments", $lng->txt("cancel"));
128
129 $form->setTitle($lng->txt("prtf_add_assignment"));
130 $form->setFormAction($ctrl->getFormAction($this));
131
132 return $form;
133 }
134
135 protected function checkWrite(bool $return = false): bool
136 {
139 $has_perm = $this->access->checkAccess(
140 "write",
141 "",
142 $this->ref_id
143 );
144 if ($return && !$has_perm) {
145 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("no_permission"), true);
146 $ctrl->redirect($this, "");
147
148 }
149
150 return $has_perm;
151 }
152
153 public function saveAssignment(): void
154 {
158 $this->checkWrite(true);
159 $form = $this->initAssignmentForm();
160 if ($form->checkInput()) {
161 $this->manager->add(
162 (int) $form->getInput("template_ref_id"),
163 (int) $form->getInput("role_id")
164 );
165 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
166 $ctrl->redirect($this, "");
167 } else {
168 $form->setValuesByPost();
169 $main_tpl->setContent($form->getHTML());
170 }
171 }
172
173 protected function confirmAssignmentDeletion(): void
174 {
178 $this->checkWrite(true);
179 $template_ids = $this->port_request->getRoleTemplateIds();
180 if (count($template_ids) === 0) {
181 $this->main_tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
182 $ctrl->redirect($this, "listAssignments");
183 } else {
184 $cgui = new ilConfirmationGUI();
185 $cgui->setFormAction($ctrl->getFormAction($this));
186 $cgui->setHeaderText($lng->txt("prtf_delete_assignment_sure"));
187 $cgui->setCancel($lng->txt("cancel"), "listAssignments");
188 $cgui->setConfirm($lng->txt("delete"), "deleteAssignments");
189 foreach ($template_ids as $i) {
190 $id_arr = explode("_", $i);
191 $role_title = ilObject::_lookupTitle($id_arr[0]);
192 $template_title = ilObject::_lookupTitle(
193 ilObject::_lookupObjId($id_arr[1])
194 );
195 $cgui->addItem("role_template_ids[]", $i, $role_title .
196 " - " . $template_title);
197 }
198
199 $main_tpl->setContent($cgui->getHTML());
200 }
201 }
202
203 protected function deleteAssignments(): void
204 {
205 $this->checkWrite(true);
206 $ctrl = $this->ctrl;
208 $template_ids = $this->port_request->getRoleTemplateIds();
209 foreach ($template_ids as $i) {
210 $id_arr = explode("_", $i);
211 $this->manager->delete((int) $id_arr[1], (int) $id_arr[0]);
212 }
213 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
214 $ctrl->redirect($this, "listAssignments");
215 }
216}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
forwardCommand(object $a_gui_object)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
@ilCtrl_Calls ilPortfolioRoleAssignmentGUI: ilPropertyFormGUI
This class represents a property form user interface.
This class represents a selection list property in a property form.
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.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
global $DIC
Definition: shib_login.php:26