19 declare(strict_types=1);
53 private readonly \ILIAS\ResourceStorage\Services
$irss;
69 public function __construct(
int $parent_obj_id,
string $parent_obj_type,
protected bool $has_write =
false)
73 $this->
lng = $DIC->language();
74 $this->tpl = $DIC->ui()->mainTemplate();
75 $this->
factory = $DIC->ui()->factory();
76 $this->
renderer = $DIC->ui()->renderer();
78 $this->request = $DIC->http()->request();
79 $this->
http = $DIC->http();
80 $this->irss = $DIC->resourceStorage();
82 $this->parent_id = $parent_obj_id;
83 $this->parent_type = $parent_obj_type;
87 $DIC->ui()->mainTemplate()
103 if ($this->cached_records !==
null) {
110 'id' => $badge->getId(),
112 'active' => $badge->isActive(),
113 'type' => $this->parent_type !==
'bdga' 115 : $badge->getTypeInstance()->getCaption(),
116 'manual' => !$badge->getTypeInstance() instanceof
ilBadgeAuto,
117 'title_sortable' => $badge->getTitle()
121 $this->cached_records = $rows;
148 $badge = $record[
'badge'];
155 $image_src = $this->badge_image_service->getImageFromBadge($badge);
156 if ($image_src !==
'') {
157 $images[
'rendered'] = $this->
renderer->render(
158 $this->
factory->image()->responsive(
164 $image_src_large = $this->badge_image_service->getImageFromBadge(
168 if ($image_src_large !==
'') {
169 $images[
'large'] = $this->
factory->image()->responsive(
180 'description' => $badge->getDescription(),
181 'badge_criteria' => $badge->getCriteria(),
185 $record[
'image'] = $images[
'rendered']
188 $record[
'title'] = implode(
'', [
198 DataRowBuilder $row_builder,
199 array $visible_column_ids,
203 ?array $additional_parameters
208 [$order_field, $order_direction] = $order->
join(
210 fn($ret, $key, $value) => [$key, $value]
213 usort($records,
static function (array $left, array $right) use ($order_field):
int {
214 if (\in_array($order_field, [
'title',
'type'],
true)) {
215 if ($order_field ===
'title') {
216 $order_field .=
'_sortable';
219 return \ilStr::strCmp(
225 if ($order_field ===
'active') {
226 return $right[$order_field] <=> $left[$order_field];
229 return $left[$order_field] <=> $right[$order_field];
233 $records = array_reverse($records);
241 $identifications = [];
242 foreach ($records as $record) {
243 if ($record[
'badge']->getImageRid() !==
null && $record[
'badge']->getImageRid() !==
'') {
244 $identifications[] = $record[
'badge']->getImageRid();
248 $this->irss->preload($identifications);
251 foreach ($records as $record) {
252 $record = $this->
enrichRecord($modal_container, $record);
255 ->buildDataRow((
string) $record[
'id'], $record)
256 ->withDisabledAction(
257 'award_revoke_badge',
258 !$record[
'manual'] || !$record[
'active']
265 ?array $additional_parameters
276 'image' => $this->
factory->table()->column()->text($this->
lng->txt(
'image'))->withIsSortable(
false),
277 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
278 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
279 'active' => $this->
factory->table()->column()->boolean(
280 $this->
lng->txt(
'active'),
281 $this->
lng->txt(
'yes'),
282 $this->
lng->txt(
'no')
283 )->withOrderingLabels(
284 $this->
lng->txt(
'badge_sort_active_badges_first'),
285 $this->
lng->txt(
'badge_sort_active_badges_last')
298 return $this->has_write ? [
299 'badge_table_activate' =>
300 $this->
factory->table()->action()->multi(
301 $this->
lng->txt(
'activate'),
302 $url_builder->
withParameter($action_parameter_token,
'badge_table_activate'),
305 'badge_table_deactivate' =>
306 $this->
factory->table()->action()->multi(
307 $this->
lng->txt(
'deactivate'),
308 $url_builder->
withParameter($action_parameter_token,
'badge_table_deactivate'),
311 'badge_table_edit' => $this->
factory->table()->action()->single(
312 $this->
lng->txt(
'edit'),
313 $url_builder->
withParameter($action_parameter_token,
'badge_table_edit'),
316 'badge_table_delete' =>
317 $this->
factory->table()->action()->standard(
318 $this->
lng->txt(
'delete'),
319 $url_builder->
withParameter($action_parameter_token,
'badge_table_delete'),
322 'award_revoke_badge' =>
323 $this->
factory->table()->action()->single(
324 $this->
lng->txt(
'badge_award_revoke'),
325 $url_builder->
withParameter($action_parameter_token,
'award_revoke_badge'),
333 $df = new \ILIAS\Data\Factory();
335 $table_uri = $df->uri($url);
337 $query_params_namespace = [
'tid'];
339 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
340 $query_params_namespace,
347 ->data($this, $this->
lng->txt(
'obj_bdga'), $this->
getColumns())
348 ->withId(self::class .
'_' . $this->parent_id)
350 ->withActions($this->
getActions($url_builder, $action_parameter_token, $row_id_token))
351 ->withRequest($this->request);
354 $query = $this->
http->wrapper()->query();
356 if ($query->has($action_parameter_token->getName())) {
357 $action = $query->retrieve($action_parameter_token->getName(), $this->
refinery->to()->string());
358 $ids = $query->retrieve($row_id_token->getName(), $this->
refinery->custom()->transformation(fn($v) => $v));
360 if ($action ===
'delete') {
362 foreach ($ids as
$id) {
363 $items[] = $this->
factory->modal()->interruptiveItem()->keyValue(
365 $row_id_token->getName(),
370 $this->
http->saveResponse(
375 $this->factory->modal()->interruptive(
376 $this->
lng->txt(
'badge_deletion'),
377 $this->
lng->txt(
'badge_deletion_confirmation'),
379 )->withAffectedItems($items)
383 $this->
http->sendResponse();
384 $this->
http->close();
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
readonly ilGlobalTemplateInterface $tpl
readonly Renderer $renderer
join($init, callable $fn)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
renderModal(Modal $modal)
__construct(int $parent_obj_id, string $parent_obj_type, protected bool $has_write=false)
readonly ILIAS Refinery Factory $refinery
readonly ilBadgeImage $badge_image_service
Both the subject and the direction need to be specified when expressing an order. ...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly string $parent_type
static http()
Fetches the global http state from ILIAS.
static getExtendedTypeCaption(ilBadgeType $a_type)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
readonly Factory $factory
static ofString(string $string)
Creates a new stream with an initial value.
readonly ServerRequestInterface RequestInterface $request
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
enrichRecord(ModalBuilder $modal_builder, array $record)
renderShyButton(string $label, Modal $modal)
A simple class to express a naive range of whole positive numbers.
readonly ILIAS ResourceStorage Services $irss