@@ -55,7 +55,6 @@ class ilObjectBadgeTableGUI
55
55
private readonly ilLanguage $ lng ;
56
56
private readonly ilGlobalTemplateInterface $ tpl ;
57
57
private ilObjBadgeAdministrationGUI $ parent_obj ;
58
- private ?bool $ user_has_write_permission = null ;
59
58
private ilAccess $ access ;
60
59
61
60
public function __construct (ilObjBadgeAdministrationGUI $ parentObj )
@@ -74,20 +73,6 @@ public function __construct(ilObjBadgeAdministrationGUI $parentObj)
74
73
75
74
}
76
75
77
- private function userHasWritePermission (int $ parent_id ): bool
78
- {
79
- if ($ this ->user_has_write_permission === null ) {
80
- $ parent_ref_id = ilObject::_getAllReferences ($ parent_id );
81
- if (\count ($ parent_ref_id ) > 0 ) {
82
- $ parent_ref_id = array_pop ($ parent_ref_id );
83
- }
84
- $ this ->user_has_write_permission = $ this ->access ->checkAccess ('write ' , '' , $ parent_ref_id );
85
- }
86
-
87
- return $ this ->user_has_write_permission ;
88
- }
89
-
90
-
91
76
private function buildDataRetrievalObject (
92
77
Factory $ f ,
93
78
Renderer $ r ,
@@ -100,7 +85,6 @@ private function buildDataRetrievalObject(
100
85
private \ilCtrlInterface $ ctrl ;
101
86
private ilLanguage $ lng ;
102
87
private \ilAccessHandler $ access ;
103
- private ?bool $ user_has_write_permission = null ;
104
88
105
89
public function __construct (
106
90
private Factory $ ui_factory ,
@@ -148,93 +132,119 @@ public function getTotalRowCount(
148
132
* id: int,
149
133
* active: bool,
150
134
* type: string,
151
- * image_rid: string,
135
+ * image: string,
136
+ * image_sortable: string,
152
137
* title: string,
138
+ * title_sortable: string,
153
139
* container: string,
154
- * container_icon: string,
155
- * container_url: string,
156
- * container_deleted: bool,
157
- * container_id: int,
158
- * container_type: string}>
140
+ * container_sortable: string
141
+ * }>
159
142
*/
160
143
private function getRecords (Range $ range = null , Order $ order = null ): array
161
144
{
162
- $ data = [];
163
- $ image_html = '' ;
164
- $ badge_img_large = '' ;
165
- $ container_icon = '' ;
145
+ $ container_deleted_title_part = '<span class="il_ItemAlertProperty"> ' . $ this ->lng ->txt ('deleted ' ) . '</span> ' ;
166
146
$ modal_container = new ModalBuilder ();
167
147
148
+ // A filter is not implemented, yet
149
+ $ filter = [
150
+ 'type ' => '' ,
151
+ 'title ' => '' ,
152
+ 'object ' => ''
153
+ ];
154
+
168
155
$ types = ilBadgeHandler::getInstance ()->getAvailableTypes (false );
169
- $ filter = [' type ' => '' , ' title ' => '' , ' object ' => '' ];
156
+ $ rows = [];
170
157
foreach (ilBadge::getObjectInstances ($ filter ) as $ badge_item ) {
171
158
$ type_caption = ilBadge::getExtendedTypeCaption ($ types [$ badge_item ['type_id ' ]]);
172
- $ badge_rid = $ badge_item ['image_rid ' ];
173
- $ image_src = $ this ->badge_image_service ->getImageFromResourceId ($ badge_item , $ badge_rid );
174
- if ($ badge_rid ) {
175
- $ badge_template_image = $ image_src ;
176
- if ($ badge_template_image !== '' ) {
177
- $ badge_img = $ this ->factory ->image ()->responsive (
178
- $ badge_template_image ,
159
+
160
+ $ images = [
161
+ 'rendered ' => '' ,
162
+ 'rendered_large ' => '' ,
163
+ ];
164
+ $ image_src = $ this ->badge_image_service ->getImageFromResourceId (
165
+ $ badge_item ,
166
+ $ badge_item ['image_rid ' ]
167
+ );
168
+ if ($ image_src !== '' ) {
169
+ $ images ['rendered ' ] = $ this ->renderer ->render (
170
+ $ this ->factory ->image ()->responsive (
171
+ $ image_src ,
179
172
$ badge_item ['title ' ]
180
- );
181
- $ image_html = $ this -> renderer -> render ( $ badge_img );
182
- }
173
+ )
174
+ );
175
+
183
176
$ image_html_large = $ this ->badge_image_service ->getImageFromResourceId (
184
177
$ badge_item ,
185
- $ badge_rid ,
178
+ $ badge_item [ ' image_rid ' ] ,
186
179
ilBadgeImage::IMAGE_SIZE_XL
187
180
);
188
181
if ($ image_html_large !== '' ) {
189
- $ badge_img_large = $ this ->ui_factory ->image ()->responsive (
182
+ $ images [ ' rendered_large ' ] = $ this ->ui_factory ->image ()->responsive (
190
183
$ image_html_large ,
191
184
$ badge_item ['title ' ]
192
185
);
193
186
}
194
187
}
195
188
196
- $ ref_ids = ilObject::_getAllReferences ($ badge_item ['parent_id ' ]);
197
- $ ref_id = array_shift ($ ref_ids );
189
+ $ sortable_container_title_parts = [
190
+ 'title ' => $ badge_item ['parent_title ' ] ?? ''
191
+ ];
192
+ $ container_title_parts = [
193
+ 'icon ' => $ this ->ui_renderer ->render ($ this ->ui_factory ->symbol ()->icon ()->custom (
194
+ ilObject::_getIcon ($ badge_item ['parent_id ' ], 'big ' , $ badge_item ['parent_type ' ] ?? '' ),
195
+ $ this ->lng ->txt ('obj_ ' . ($ badge_item ['parent_type ' ] ?? '' ))
196
+ )),
197
+ 'title ' => $ sortable_container_title_parts ['title ' ],
198
+ ];
198
199
199
- $ container_url_link = '' ;
200
- if ($ this ->access ->checkAccess ('read ' , '' , $ ref_id )) {
201
- $ container_url = ilLink::_getLink ($ ref_id );
202
- $ container_url_link = $ this ->renderer ->render (
203
- new Standard ($ badge_item ['parent_title ' ], (string ) new URI ($ container_url ))
204
- );
205
- $ container_icon = '<img class="ilIcon" src=" ' .
206
- ilObject::_getIcon ((int ) $ badge_item ['parent_id ' ], 'big ' , $ badge_item ['parent_type ' ]) .
207
- '" alt=" ' . $ this ->lng ->txt ('obj_ ' . $ badge_item ['parent_type ' ]) .
208
- '" title=" ' . $ this ->lng ->txt ('obj_ ' . $ badge_item ['parent_type ' ]) . '" /> ' ;
200
+ if ($ badge_item ['deleted ' ]) {
201
+ $ container_title_parts ['suffix ' ] = $ container_deleted_title_part ;
202
+ $ sortable_container_title_parts ['suffix ' ] = $ container_deleted_title_part ;
203
+ } else {
204
+ $ ref_ids = ilObject::_getAllReferences ($ badge_item ['parent_id ' ]);
205
+ $ ref_id = array_shift ($ ref_ids );
206
+ if ($ ref_id && $ this ->access ->checkAccess ('read ' , '' , $ ref_id )) {
207
+ $ container_title_parts ['title ' ] = $ this ->renderer ->render (
208
+ new Standard (
209
+ $ container_title_parts ['title ' ],
210
+ (string ) new URI (ilLink::_getLink ($ ref_id ))
211
+ )
212
+ );
213
+ } else {
214
+ $ container_title_parts ['suffix ' ] = $ container_deleted_title_part ;
215
+ $ sortable_container_title_parts ['suffix ' ] = $ container_deleted_title_part ;
216
+ }
209
217
}
210
218
211
219
$ badge_information = [
212
- 'active ' => ( $ badge_item ['active ' ] ? $ this ->lng ->txt ('yes ' ) : $ this ->lng ->txt ('no ' ) ),
220
+ 'active ' => $ badge_item ['active ' ] ? $ this ->lng ->txt ('yes ' ) : $ this ->lng ->txt ('no ' ),
213
221
'type ' => $ type_caption ,
214
- 'container ' => $ container_url_link ?: $ badge_item [ ' parent_title ' ] ,
222
+ 'container ' => implode ( ' ' , \array_slice ( $ container_title_parts , 1 , null , true )) ,
215
223
];
216
224
217
225
$ modal = $ modal_container ->constructModal (
218
- $ badge_img_large ?: null ,
226
+ $ images [ ' rendered_large ' ] ?: null ,
219
227
$ badge_item ['title ' ],
220
228
$ badge_information
221
229
);
222
230
223
- $ data [] = [
224
- 'id ' => ( int ) $ badge_item ['id ' ],
231
+ $ rows [] = [
232
+ 'id ' => $ badge_item ['id ' ],
225
233
'active ' => (bool ) $ badge_item ['active ' ],
226
234
'type ' => $ type_caption ,
227
- 'image_rid ' => $ modal_container ->renderShyButton (
228
- $ image_html ,
235
+ 'image ' => $ images [ ' rendered ' ] ? ( $ modal_container ->renderShyButton (
236
+ $ images [ ' rendered ' ] ,
229
237
$ modal
230
- ) . ' ' . $ modal_container ->renderModal ($ modal ),
231
- 'title ' => $ modal_container ->renderShyButton ($ badge_item ['title ' ], $ modal ),
232
- 'container ' => $ badge_item ['parent_title ' ],
233
- 'container_icon ' => $ container_icon ,
234
- 'container_url ' => $ container_icon . $ container_url_link ?: '' ,
235
- 'container_deleted ' => ($ badge_item ['deleted ' ] ?? false ),
236
- 'container_id ' => (int ) $ badge_item ['parent_id ' ],
237
- 'container_type ' => $ badge_item ['parent_type ' ],
238
+ ) . ' ' ) : '' ,
239
+ // Just an boolean-like indicator for sorting
240
+ 'image_sortable ' => $ images ['rendered ' ] ? 'A ' : 'Z ' ,
241
+ 'title ' => implode ('' , [
242
+ $ modal_container ->renderShyButton ($ badge_item ['title ' ], $ modal ),
243
+ $ modal_container ->renderModal ($ modal )
244
+ ]),
245
+ 'title_sortable ' => $ badge_item ['title ' ],
246
+ 'container ' => implode (' ' , $ container_title_parts ),
247
+ 'container_sortable ' => implode (' ' , $ sortable_container_title_parts ),
238
248
];
239
249
}
240
250
@@ -243,21 +253,33 @@ private function getRecords(Range $range = null, Order $order = null): array
243
253
[],
244
254
fn ($ ret , $ key , $ value ) => [$ key , $ value ]
245
255
);
246
- usort ($ data , static fn ($ a , $ b ) => $ a [$ order_field ] <=> $ b [$ order_field ]);
256
+ usort (
257
+ $ rows ,
258
+ static function (array $ left , array $ right ) use ($ order_field ): int {
259
+ if (\in_array ($ order_field , ['image ' , 'container ' , 'title ' ], true )) {
260
+ return \ilStr::strCmp (
261
+ $ left [$ order_field . '_sortable ' ],
262
+ $ right [$ order_field . '_sortable ' ]
263
+ );
264
+ }
265
+
266
+ return $ left [$ order_field ] <=> $ right [$ order_field ];
267
+ }
268
+ );
247
269
if ($ order_field === 'active ' ) {
248
270
if ($ order_direction === 'ASC ' ) {
249
- $ data = array_reverse ($ data );
271
+ $ rows = array_reverse ($ rows );
250
272
}
251
273
} elseif ($ order_direction === 'DESC ' ) {
252
- $ data = array_reverse ($ data );
274
+ $ rows = array_reverse ($ rows );
253
275
}
254
276
}
255
277
256
278
if ($ range ) {
257
- $ data = \array_slice ($ data , $ range ->getStart (), $ range ->getLength ());
279
+ $ rows = \array_slice ($ rows , $ range ->getStart (), $ range ->getLength ());
258
280
}
259
281
260
- return $ data ;
282
+ return $ rows ;
261
283
}
262
284
};
263
285
}
@@ -309,10 +331,10 @@ public function renderTable(): void
309
331
$ df = new \ILIAS \Data \Factory ();
310
332
311
333
$ columns = [
312
- 'image_rid ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('image ' )),
334
+ 'image ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('image ' )),
313
335
'title ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('title ' )),
314
336
'type ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('type ' )),
315
- 'container_url ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('container ' )),
337
+ 'container ' => $ f ->table ()->column ()->text ($ this ->lng ->txt ('container ' )),
316
338
'active ' => $ f ->table ()->column ()->boolean (
317
339
$ this ->lng ->txt ('active ' ),
318
340
$ this ->lng ->txt ('yes ' ),
@@ -337,6 +359,7 @@ public function renderTable(): void
337
359
338
360
$ table = $ f ->table ()
339
361
->data ($ this ->lng ->txt ('badge_object_badges ' ), $ columns , $ data_retrieval )
362
+ ->withOrder (new Order ('title ' , Order::ASC ))
340
363
->withActions ($ actions )
341
364
->withRequest ($ request );
342
365
0 commit comments