ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPortfolioRoleAssignmentGUI.php
Go to the documentation of this file.
1<?php
2
21
27{
29 protected ilCtrl $ctrl;
31 protected ilLanguage $lng;
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->toolbar = $DIC->toolbar();
40 $this->ctrl = $DIC->ctrl();
41 $this->lng = $DIC->language();
42 $this->main_tpl = $DIC->ui()->mainTemplate();
43 $this->manager = new PortfolioRoleAssignmentManager();
44 $this->port_request = $DIC->portfolio()
45 ->internal()
46 ->gui()
47 ->standardRequest();
48 }
49
50 public function executeCommand(): void
51 {
53
54 $next_class = $ctrl->getNextClass($this);
55 $cmd = $ctrl->getCmd("listAssignments");
56
57 switch ($next_class) {
58 case "ilpropertyformgui":
59 $form = $this->initAssignmentForm();
60 $ctrl->forwardCommand($form);
61 break;
62
63 default:
64 if (in_array($cmd, [
65 "listAssignments",
66 "addAssignment",
67 "saveAssignment",
68 "confirmAssignmentDeletion",
69 "deleteAssignments"
70 ])) {
71 $this->$cmd();
72 }
73 }
74 }
75
76 protected function listAssignments(): void
77 {
79 $this->toolbar->addButton(
80 $lng->txt("prtf_add_assignment"),
81 $this->ctrl->getLinkTarget($this, "addAssignment")
82 );
83
85 $this,
86 "listAssignments",
87 $this->manager
88 );
89 $this->main_tpl->setContent($table->getHTML());
90 }
91
92 protected function addAssignment(): void
93 {
95 $form = $this->initAssignmentForm();
96 $main_tpl->setContent($form->getHTML());
97 }
98
100 {
103
104 $form = new ilPropertyFormGUI();
105
106 $options = $this->manager->getAvailableRoles();
107 $si_roles = new ilSelectInputGUI($this->lng->txt("prtf_role_title"), 'role_id');
108 $si_roles->setRequired(true);
109 $si_roles->setOptions($options);
110 $form->addItem($si_roles);
111
112 $repo = new ilRepositorySelector2InputGUI($lng->txt("prtf_template_title"), "template_ref_id");
113 $repo->setRequired(true);
114 $repo->getExplorerGUI()->setSelectableTypes(array("prtt"));
115 $repo->getExplorerGUI()->setTypeWhiteList(array("root", "prtt", "cat", "crs", "grp", "fold"));
116 $form->addItem($repo);
117
118 // save and cancel commands
119 $form->addCommandButton("saveAssignment", $lng->txt("save"));
120 $form->addCommandButton("listAssignments", $lng->txt("cancel"));
121
122 $form->setTitle($lng->txt("prtf_add_assignment"));
123 $form->setFormAction($ctrl->getFormAction($this));
124
125 return $form;
126 }
127
128 public function saveAssignment(): void
129 {
133
134 $form = $this->initAssignmentForm();
135 if ($form->checkInput()) {
136 $this->manager->add(
137 (int) $form->getInput("template_ref_id"),
138 (int) $form->getInput("role_id")
139 );
140 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
141 $ctrl->redirect($this, "");
142 } else {
143 $form->setValuesByPost();
144 $main_tpl->setContent($form->getHTML());
145 }
146 }
147
148 protected function confirmAssignmentDeletion(): void
149 {
153
154 $template_ids = $this->port_request->getRoleTemplateIds();
155 if (count($template_ids) === 0) {
156 $this->main_tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
157 $ctrl->redirect($this, "listAssignments");
158 } else {
159 $cgui = new ilConfirmationGUI();
160 $cgui->setFormAction($ctrl->getFormAction($this));
161 $cgui->setHeaderText($lng->txt("prtf_delete_assignment_sure"));
162 $cgui->setCancel($lng->txt("cancel"), "listAssignments");
163 $cgui->setConfirm($lng->txt("delete"), "deleteAssignments");
164 foreach ($template_ids as $i) {
165 $id_arr = explode("_", $i);
166 $role_title = ilObject::_lookupTitle($id_arr[0]);
167 $template_title = ilObject::_lookupTitle(
168 ilObject::_lookupObjId($id_arr[1])
169 );
170 $cgui->addItem("role_template_ids[]", $i, $role_title .
171 " - " . $template_title);
172 }
173
174 $main_tpl->setContent($cgui->getHTML());
175 }
176 }
177
178 protected function deleteAssignments(): void
179 {
182 $template_ids = $this->port_request->getRoleTemplateIds();
183 foreach ($template_ids as $i) {
184 $id_arr = explode("_", $i);
185 $this->manager->delete((int) $id_arr[1], (int) $id_arr[0]);
186 }
187 $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
188 $ctrl->redirect($this, "listAssignments");
189 }
190}
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...
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
setContent(string $a_html)
Sets content for standard template.
global $DIC
Definition: shib_login.php:26