Skip to content

Commit

Permalink
Refactoring/restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Dec 7, 2023
1 parent da81d1d commit 1e6edbe
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 32 deletions.
7 changes: 6 additions & 1 deletion Services/Badge/classes/Tile.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Tile
/** @var Closure(int): string */
private readonly Closure $format_date;

private ilBadgeImage|null $badge_image = null;

/**
* @param Closure(string): string $sign_file
* @param Closure(int): string $format_date
Expand All @@ -61,6 +63,8 @@ class_exists(ilDateTime::class); // Ensure ilDateTime is loaded as IL_CAL_UNIX i
);
}
$this->format_date = $format_date;
global $DIC;
$this->badge_image = new ilBadgeImage($DIC);
}

/**
Expand Down Expand Up @@ -130,10 +134,11 @@ private function modal(Card $card): Component

private function image(Component $modal, ilBadge $badge): Component
{
$image_src = $this->badge_image->getImageFromBadge($badge);
return $this->container->ui()
->factory()
->image()
->responsive(($this->sign_file)($badge->getImagePath()), $badge->getImage())
->responsive(($this->sign_file)($image_src), $image_src)
->withAction($modal->getShowSignal());
}

Expand Down
1 change: 1 addition & 0 deletions Services/Badge/classes/class.ilBadgeBackpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function getBadges(string $a_group_id): ?array
"title" => $badge->name,
"description" => $badge->description,
"image_url" => $badge->image,
"image_rid" => $badge->image_rid,
"criteria_url" => $badge->criteria,
"issuer_name" => $badge->issuer->name,
"issuer_url" => $badge->issuer->origin,
Expand Down
38 changes: 38 additions & 0 deletions Services/Badge/classes/class.ilBadgeImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace ILIAS\Badge;

use ilBadge;

class ilBadgeImage
{

private $dic;
public function __construct($DIC)
{
$this->dic = $DIC;
}

/**
* @param int $badge_id
* @param string $image_rid
* @return string
*/
public function getImageFromResourceId(int $badge_id, string $image_rid) : string
{
if ($image_rid !== null) {
$identification = $this->dic['resource_storage']->manage()->find($image_rid);
$image_src = $this->dic['resource_storage']->consume()->src($identification)->getSrc();
} else {
$badge = new ilBadge($badge_id);
$image_src = $this->dic['resource_storage']->consume()->src($badge->getImage());
}
return $image_src;
}

public function getImageFromBadge(ilBadge $badge) : string
{
$image_rid = $badge->getImageRid();
return $this->getImageFromResourceId($badge->getId(), $image_rid);
}
}
9 changes: 9 additions & 0 deletions Services/Badge/classes/class.ilBadgeManagementGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*********************************************************************/

use ILIAS\Badge\ilBadgeImage;

/**
* Class ilBadgeManagementGUI
*
Expand All @@ -37,6 +39,8 @@ class ilBadgeManagementGUI
private int $parent_obj_id;
private string $parent_obj_type;

private ?ilBadgeImage $badge_image = null;

public function __construct(
private readonly int $parent_ref_id,
int $a_parent_obj_id = null,
Expand Down Expand Up @@ -70,6 +74,7 @@ public function __construct(
);

$this->session_repo = new ilBadgeManagementSessionRepository();
$this->badge_image = new ilBadgeImage($DIC);
}

public function executeCommand(): void
Expand Down Expand Up @@ -449,6 +454,10 @@ protected function setBadgeFormValues(
$a_form->getItemByPostVar('crit')->setValue($a_badge->getCriteria());
$a_form->getItemByPostVar('img')->setValue($a_badge->getImage());
$a_form->getItemByPostVar('img')->setImage($a_badge->getImagePath());

$image_src = $this->badge_image->getImageFromBadge($a_badge);
$a_form->getItemByPostVar('img')->setImage($image_src);

$a_form->getItemByPostVar('valid')->setValue($a_badge->getValid());

$custom = $a_type->getConfigGUIInstance();
Expand Down
59 changes: 29 additions & 30 deletions Services/Badge/classes/class.ilBadgeTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use ILIAS\DI\UIServices;
use ILIAS\Badge\Tile;
use ILIAS\Badge\ilBadgeImage;

/**
* TableGUI class for badge listing
Expand All @@ -29,6 +30,7 @@ class ilBadgeTableGUI extends ilTable2GUI
protected array $filter = [];
private readonly Tile $tile;
private readonly UIServices $ui;
private ilBadgeImage|null $badge_image = null;

public function __construct(
object $a_parent_obj,
Expand All @@ -44,6 +46,7 @@ public function __construct(
$this->tile = new Tile($DIC);
$ilCtrl = $DIC->ctrl();
$lng = $DIC->language();
$this->badge_image = new ilBadgeImage($DIC);

$this->setId("bdgbdg");
$this->parent_type = ilObject::_lookupType($a_parent_obj_id);
Expand Down Expand Up @@ -137,49 +140,45 @@ protected function fillRow(array $a_set): void
$ilCtrl = $this->ctrl;

if ($this->has_write) {
$this->tpl->setVariable("VAL_ID", $a_set["id"]);
$this->tpl->setVariable('VAL_ID', $a_set['id']);
}

global $DIC;
$rid_string = $a_set['image_rid'];

if (null !== $rid_string) {
$identification = $DIC['resource_storage']->manage()->find($rid_string);
$image_src = $DIC['resource_storage']->consume()->src($identification);
$image = $DIC->ui()->factory()->image()->responsive($image_src->getSrc(), $a_set['title']);
$image = $this->ui->renderer()->render($image);
$image_src = $this->badge_image->getImageFromResourceId($a_set['id'], $a_set['image_rid']);
if (null !== $a_set['image_rid']) {
global $DIC;
$image_responsive = $DIC->ui()->factory()->image()->responsive($image_src, $a_set['title']);
$image = $this->ui->renderer()->render($image_responsive);
} else {
$image = $this->ui->renderer()->render($a_set["renderer"]());
$image = $this->ui->renderer()->render($a_set['renderer']());
}


$this->tpl->setVariable("PREVIEW", $image);
$this->tpl->setVariable("TXT_TYPE", $a_set["type"]);
$this->tpl->setVariable("TXT_ACTIVE", $a_set["active"]
? $lng->txt("yes")
: $lng->txt("no"));

$this->tpl->setVariable('PREVIEW', $image);
$this->tpl->setVariable('TXT_TYPE', $a_set['type']);
$this->tpl->setVariable('TXT_ACTIVE', $a_set['active']
? $lng->txt('yes')
: $lng->txt('no'));

if ($this->has_write) {
$buttons = [];

if ($a_set["manual"] && $a_set["active"]) {
$ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
$ilCtrl->setParameter($this->getParentObject(), "tgt", "bdgl");
$url = $ilCtrl->getLinkTarget($this->getParentObject(), "awardBadgeUserSelection");
$ilCtrl->setParameter($this->getParentObject(), "bid", "");
$ilCtrl->setParameter($this->getParentObject(), "tgt", "");
if ($a_set['manual'] && $a_set['active']) {
$ilCtrl->setParameter($this->getParentObject(), 'bid', $a_set['id']);
$ilCtrl->setParameter($this->getParentObject(), 'tgt', 'bdgl');
$url = $ilCtrl->getLinkTarget($this->getParentObject(), 'awardBadgeUserSelection');
$ilCtrl->setParameter($this->getParentObject(), 'bid', '');
$ilCtrl->setParameter($this->getParentObject(), 'tgt', '');

$buttons[] = $this->ui->factory()->button()->shy($lng->txt("badge_award_badge"), $url);
$buttons[] = $this->ui->factory()->button()->shy($lng->txt('badge_award_badge'), $url);
}

$ilCtrl->setParameter($this->getParentObject(), "bid", $a_set["id"]);
$url = $ilCtrl->getLinkTarget($this->getParentObject(), "editBadge");
$ilCtrl->setParameter($this->getParentObject(), "bid", "");
$ilCtrl->setParameter($this->getParentObject(), 'bid', $a_set['id']);
$url = $ilCtrl->getLinkTarget($this->getParentObject(), 'editBadge');
$ilCtrl->setParameter($this->getParentObject(), 'bid', '');

$buttons[] = $this->ui->factory()->button()->shy($lng->txt("edit"), $url);
$actions = $this->ui->factory()->dropdown()->standard($buttons)->withLabel($lng->txt("actions"));
$buttons[] = $this->ui->factory()->button()->shy($lng->txt('edit'), $url);
$actions = $this->ui->factory()->dropdown()->standard($buttons)->withLabel($lng->txt('actions'));

$this->tpl->setVariable("ACTIONS", $this->ui->renderer()->render($actions));
$this->tpl->setVariable('ACTIONS', $this->ui->renderer()->render($actions));
}
}
}
2 changes: 1 addition & 1 deletion Services/Init/classes/class.ilInitialisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ protected static function initRefinery(\ILIAS\DI\Container $container): void
/**
* @param Container $container
*/
protected static function replaceSuperGlobals(\ILIAS\DI\Container $container): void
protected static function replaceSuperGlobals(\ILIAS\DI\Container $container): void
{
/** @var ilIniFile $client_ini */
$client_ini = $container['ilClientIniFile'];
Expand Down

0 comments on commit 1e6edbe

Please sign in to comment.