19declare(strict_types=1);
30use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Message\RequestInterface;
47 private readonly ServerRequestInterface|RequestInterface
$request;
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(
'', [
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);
250 $modal_container =
new ModalBuilder();
251 foreach ($records as $record) {
252 $record = $this->
enrichRecord($modal_container, $record);
256 ->withDisabledAction(
257 'award_revoke_badge',
258 !$record[
'manual'] || !$record[
'active']
265 ?array $additional_parameters
267 return \count($this->getRecords());
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' =>
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)
349 ->withOrder(
new Order(
'title', Order::ASC))
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(
374 Streams::ofString($this->
renderer->renderAsync([
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();
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
renderShyButton(string $label, Modal $modal)
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
renderModal(Modal $modal)
readonly ILIAS Refinery Factory $refinery
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
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...
readonly ILIAS ResourceStorage Services $irss
readonly Factory $factory
readonly Renderer $renderer
__construct(int $parent_obj_id, string $parent_obj_type, protected bool $has_write=false)
readonly string $parent_type
readonly ServerRequestInterface RequestInterface $request
readonly ilGlobalTemplateInterface $tpl
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
readonly ilBadgeImage $badge_image_service
enrichRecord(ModalBuilder $modal_builder, array $record)
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
join($init, callable $fn)
A simple class to express a naive range of whole positive numbers.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static getExtendedTypeCaption(ilBadgeType $a_type)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A Column describes the form of presentation for a certain aspect of data, i.e.
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.