1717 *********************************************************************/
1818
1919use ILIAS \Portfolio \Administration \PortfolioRoleAssignmentManager ;
20+ use ILIAS \Portfolio \InternalGUIService ;
2021use ILIAS \Portfolio \StandardGUIRequest ;
22+ use ILIAS \Repository \Table \TableAdapterGUI ;
2123
2224/**
2325 * @ilCtrl_Calls ilPortfolioRoleAssignmentGUI: ilPropertyFormGUI
@@ -33,6 +35,7 @@ class ilPortfolioRoleAssignmentGUI
3335 protected ilLanguage $ lng ;
3436 protected ilGlobalTemplateInterface $ main_tpl ;
3537 protected PortfolioRoleAssignmentManager $ manager ;
38+ protected InternalGUIService $ portfolio_gui ;
3639
3740 public function __construct ()
3841 {
@@ -43,6 +46,7 @@ public function __construct()
4346 $ this ->lng = $ DIC ->language ();
4447 $ this ->main_tpl = $ DIC ->ui ()->mainTemplate ();
4548 $ this ->manager = new PortfolioRoleAssignmentManager ();
49+ $ this ->portfolio_gui = $ DIC ->portfolio ()->internal ()->gui ();
4650 $ this ->port_request = $ DIC ->portfolio ()
4751 ->internal ()
4852 ->gui ()
@@ -70,7 +74,7 @@ public function executeCommand(): void
7074 "addAssignment " ,
7175 "saveAssignment " ,
7276 "confirmAssignmentDeletion " ,
73- "deleteAssignments "
77+ "deleteAssignment "
7478 ])) {
7579 $ this ->$ cmd ();
7680 }
@@ -87,13 +91,22 @@ protected function listAssignments(): void
8791 );
8892 }
8993
90- $ table = new ilPortfolioRoleAssignmentTableGUI (
91- $ this ,
92- "listAssignments " ,
93- $ this ->manager ,
94- $ this ->checkWrite ()
95- );
96- $ this ->main_tpl ->setContent ($ table ->getHTML ());
94+ $ table = $ this ->getRoleAssignmentTable ();
95+ if ($ table ->handleCommand ()) {
96+ return ;
97+ }
98+ $ this ->main_tpl ->setContent ($ table ->render ());
99+ }
100+
101+ protected function getRoleAssignmentTable (): TableAdapterGUI
102+ {
103+ return $ this ->portfolio_gui
104+ ->portfolioRoleAssignmentTableBuilder (
105+ $ this ->checkWrite (),
106+ $ this ,
107+ "listAssignments "
108+ )
109+ ->getTable ();
97110 }
98111
99112 protected function addAssignment (): void
@@ -170,47 +183,64 @@ public function saveAssignment(): void
170183 }
171184 }
172185
173- protected function confirmAssignmentDeletion (): void
186+ public function confirmAssignmentDeletion (string $ assignment_id ): void
174187 {
175- $ ctrl = $ this ->ctrl ;
176- $ lng = $ this ->lng ;
177- $ main_tpl = $ this ->main_tpl ;
178188 $ 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 ());
189+ $ assignment = $ this ->getAssignment ($ assignment_id );
190+ if ($ assignment === null ) {
191+ $ this ->main_tpl ->setOnScreenMessage ('info ' , $ this ->lng ->txt ("no_checkbox " ), true );
192+ $ this ->ctrl ->redirect ($ this , "listAssignments " );
200193 }
194+
195+ $ this ->getRoleAssignmentTable ()->renderDeletionConfirmation (
196+ $ this ->lng ->txt ("prtf_delete_assignment_sure " ),
197+ $ this ->lng ->txt ("prtf_delete_assignment_sure " ),
198+ "deleteAssignment " ,
199+ [
200+ $ assignment_id => $ assignment ["role_title " ] . " - " . $ assignment ["template_title " ]
201+ ]
202+ );
201203 }
202204
203- protected function deleteAssignments (): void
205+ protected function deleteAssignment (): void
204206 {
205207 $ this ->checkWrite (true );
206- $ ctrl = $ this ->ctrl ;
207- $ lng = $ this ->lng ;
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 ]);
208+ $ template_ids = $ this ->getRoleAssignmentTable ()->getItemIds ();
209+ $ assignment = $ this ->getAssignment ($ template_ids [0 ] ?? "" );
210+ if ($ assignment === null ) {
211+ $ this ->main_tpl ->setOnScreenMessage ('info ' , $ this ->lng ->txt ("no_checkbox " ), true );
212+ $ this ->ctrl ->redirect ($ this , "listAssignments " );
213+ }
214+
215+ $ this ->manager ->delete (
216+ $ assignment ["template_ref_id " ],
217+ $ assignment ["role_id " ]
218+ );
219+ $ this ->main_tpl ->setOnScreenMessage ('success ' , $ this ->lng ->txt ("msg_obj_modified " ), true );
220+ $ this ->ctrl ->redirect ($ this , "listAssignments " );
221+ }
222+
223+ protected function getAssignment (string $ assignment_id ): ?array
224+ {
225+ $ parts = explode ("_ " , $ assignment_id );
226+ if (count ($ parts ) !== 2 || !ctype_digit ($ parts [0 ]) || !ctype_digit ($ parts [1 ])) {
227+ return null ;
228+ }
229+
230+ $ role_id = (int ) $ parts [0 ];
231+ $ template_ref_id = (int ) $ parts [1 ];
232+ foreach ($ this ->manager ->getAllAssignmentData () as $ assignment ) {
233+ if ((int ) $ assignment ["role_id " ] === $ role_id
234+ && (int ) $ assignment ["template_ref_id " ] === $ template_ref_id ) {
235+ return [
236+ "role_id " => $ role_id ,
237+ "template_ref_id " => $ template_ref_id ,
238+ "role_title " => $ assignment ["role_title " ],
239+ "template_title " => $ assignment ["template_title " ]
240+ ];
241+ }
212242 }
213- $ this -> main_tpl -> setOnScreenMessage ( ' success ' , $ lng -> txt ( " msg_obj_modified " ), true );
214- $ ctrl -> redirect ( $ this , " listAssignments " ) ;
243+
244+ return null ;
215245 }
216246}
0 commit comments