From 163d130848eb5a7cb1029b5efec3833a14bd7e8d Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Thu, 29 Oct 2026 12:42:48 +0100 Subject: [PATCH 1/2] [Refactoring] Badge: Remove legacy filesystem image paths Drop the IRSS file migrations and the runtime fallback that still served unmigrated badge images from sec/ilBadge. Badges and templates now use resource ids only. --- components/ILIAS/Badge/ROADMAP.md | 6 +- .../ILIAS/Badge/classes/BadgeException.php | 49 ---- components/ILIAS/Badge/classes/Modal.php | 8 +- .../Setup/class.ilBadgeDBUpdateSteps.php | 22 ++ .../classes/Setup/class.ilBadgeSetupAgent.php | 8 - .../class.ilBadgeTemplatesFilesMigration.php | 200 -------------- .../Setup/class.ilBadgesFilesMigration.php | 207 -------------- components/ILIAS/Badge/classes/Tile.php | 6 - .../ILIAS/Badge/classes/class.ilBadge.php | 254 ++++++------------ .../Badge/classes/class.ilBadgeImage.php | 19 +- .../classes/class.ilBadgeImageTemplate.php | 203 +++++--------- .../classes/class.ilBadgeManagementGUI.php | 17 +- .../ILIAS/Badge/classes/class.ilBadgeWAC.php | 137 ---------- .../Badge/classes/class.ilFSStorageBadge.php | 35 --- .../class.ilFSStorageBadgeImageTemplate.php | 35 --- .../class.ilObjBadgeAdministrationGUI.php | 14 +- .../classes/class.ilObjectBadgeTableGUI.php | 8 +- components/ILIAS/Badge/service.xml | 3 - components/ILIAS/Badge/tests/ModalTest.php | 7 +- components/ILIAS/Badge/tests/TileTest.php | 14 +- 20 files changed, 212 insertions(+), 1040 deletions(-) delete mode 100644 components/ILIAS/Badge/classes/BadgeException.php delete mode 100644 components/ILIAS/Badge/classes/Setup/class.ilBadgeTemplatesFilesMigration.php delete mode 100644 components/ILIAS/Badge/classes/Setup/class.ilBadgesFilesMigration.php delete mode 100755 components/ILIAS/Badge/classes/class.ilBadgeWAC.php delete mode 100755 components/ILIAS/Badge/classes/class.ilFSStorageBadge.php delete mode 100755 components/ILIAS/Badge/classes/class.ilFSStorageBadgeImageTemplate.php diff --git a/components/ILIAS/Badge/ROADMAP.md b/components/ILIAS/Badge/ROADMAP.md index 0ea1e984afce..b0a0b7d43cff 100755 --- a/components/ILIAS/Badge/ROADMAP.md +++ b/components/ILIAS/Badge/ROADMAP.md @@ -4,8 +4,4 @@ ### Introduction of UI elements -More elements of the UI framework should be used for the user interface. - -### IRSS Integration - -Files should be handled by the IRSS \ No newline at end of file +More elements of the UI framework should be used for the user interface. \ No newline at end of file diff --git a/components/ILIAS/Badge/classes/BadgeException.php b/components/ILIAS/Badge/classes/BadgeException.php deleted file mode 100644 index c599d140d09b..000000000000 --- a/components/ILIAS/Badge/classes/BadgeException.php +++ /dev/null @@ -1,49 +0,0 @@ -badge = $badge; - - } - - public static function uploadedBadgeImageFileNotFound(ilBadge $badge, ?ilException $previous_exception = null): self - { - return new self(self::EXCEPTION_FILE_NOT_FOUND, $badge, $previous_exception); - } - - public static function moveUploadedBadgeImageFailed(ilBadge $badge, ?ilException $previous_exception = null): self - { - return new self(self::EXCEPTION_MOVE_UPLOADED_IMAGE_FAILED, $badge, $previous_exception); - } -} diff --git a/components/ILIAS/Badge/classes/Modal.php b/components/ILIAS/Badge/classes/Modal.php index e6cdbf4f42a7..c76d31ad9287 100755 --- a/components/ILIAS/Badge/classes/Modal.php +++ b/components/ILIAS/Badge/classes/Modal.php @@ -21,21 +21,15 @@ namespace ILIAS\Badge; use ILIAS\DI\Container; -use Closure; use ILIAS\UI\Component\Component; -use ilWACSignedPath; class Modal { - /** @var Closure(string): string */ - private readonly Closure $sign_file; private ilBadgeImage $badge_image_service; public function __construct( - private readonly Container $container, - $sign_file = [ilWACSignedPath::class, 'signFile'] + private readonly Container $container ) { - $this->sign_file = Closure::fromCallable($sign_file); $this->badge_image_service = new ilBadgeImage( $container->resourceStorage(), $container->upload(), diff --git a/components/ILIAS/Badge/classes/Setup/class.ilBadgeDBUpdateSteps.php b/components/ILIAS/Badge/classes/Setup/class.ilBadgeDBUpdateSteps.php index 13360c1fd0ad..fc2264c21753 100644 --- a/components/ILIAS/Badge/classes/Setup/class.ilBadgeDBUpdateSteps.php +++ b/components/ILIAS/Badge/classes/Setup/class.ilBadgeDBUpdateSteps.php @@ -58,4 +58,26 @@ public function step_2(): void ); } } + + public function step_3(): void + { + $this->db->manipulate( + 'UPDATE badge_badge SET image_rid = NULL WHERE image_rid = ' . $this->db->quote( + '-', + ilDBConstants::T_TEXT + ) + ); + $this->db->manipulate( + 'UPDATE badge_image_template SET image_rid = NULL WHERE image_rid = ' . $this->db->quote( + '-', + ilDBConstants::T_TEXT + ) + ); + if ($this->db->tableColumnExists('badge_badge', 'image')) { + $this->db->dropTableColumn('badge_badge', 'image'); + } + if ($this->db->tableColumnExists('badge_image_template', 'image')) { + $this->db->dropTableColumn('badge_image_template', 'image'); + } + } } diff --git a/components/ILIAS/Badge/classes/Setup/class.ilBadgeSetupAgent.php b/components/ILIAS/Badge/classes/Setup/class.ilBadgeSetupAgent.php index f19474d4de1a..afba9f0e76d2 100644 --- a/components/ILIAS/Badge/classes/Setup/class.ilBadgeSetupAgent.php +++ b/components/ILIAS/Badge/classes/Setup/class.ilBadgeSetupAgent.php @@ -31,12 +31,4 @@ public function getStatusObjective(?Setup\Metrics\Storage $storage): Setup\Objec { return new ilDatabaseUpdateStepsMetricsCollectedObjective($storage, new ilBadgeDBUpdateSteps()); } - - public function getMigrations(): array - { - return [ - new ilBadgesFilesMigration(), - new ilBadgeTemplatesFilesMigration() - ]; - } } diff --git a/components/ILIAS/Badge/classes/Setup/class.ilBadgeTemplatesFilesMigration.php b/components/ILIAS/Badge/classes/Setup/class.ilBadgeTemplatesFilesMigration.php deleted file mode 100644 index a56e33df8aaf..000000000000 --- a/components/ILIAS/Badge/classes/Setup/class.ilBadgeTemplatesFilesMigration.php +++ /dev/null @@ -1,200 +0,0 @@ -helper = new ilResourceStorageMigrationHelper( - new ilBadgeFileStakeholder(), - $environment - ); - $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION); - if ($io instanceof IOWrapper) { - $this->io = $io; - } - } - - public function step(Environment $environment): void - { - $this->helper->getDatabase()->setLimit(1); - $res = $this->helper->getDatabase()->query( - 'SELECT id, image, image_rid FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''" - ); - $row = $this->helper->getDatabase()->fetchObject($res); - if (!($row instanceof stdClass)) { - return; - } - - $id = (int) $row->id; - $image = $row->image; - - if ($image !== '' && $image !== null) { - $image_path = $this->getImagePath($id, $image); - - try { - $this->inform("Trying to move badge image template file $image_path for id $id to the storage service."); - $identification = $this->helper->movePathToStorage($image_path, ResourceCollection::NO_SPECIFIC_OWNER); - $this->inform('Migration proceeded without error.'); - if ($identification === null) { - $this->error( - 'IRSS returned NULL as identification when trying to move badge image template ' . - "file $image_path for id $id to the storage service." - ); - } else { - $this->inform( - "IRSS identification for badge image template with id $id: {$identification->serialize()}", - true - ); - } - } catch (Throwable $e) { - $this->error("Failed to move badge image template file $image_path for id $id to the storage service with exception: {$e->getMessage()}"); - $this->error($e->getTraceAsString()); - throw $e; - } - - if ($identification === null) { - $identification = '-'; - } else { - $identification = $identification->serialize(); - } - - $this->helper->getDatabase()->update( - self::TABLE_NAME, - [ - 'image_rid' => [ilDBConstants::T_TEXT, $identification], - 'image' => [ilDBConstants::T_TEXT, null] - ], - ['id' => [ilDBConstants::T_INTEGER, $id]] - ); - } else { - $this->inform( - 'Cannot migrate badge image template with id ' . $id - . ' (table: ' . self::TABLE_NAME . ') because no image is set.', - true - ); - $this->helper->getDatabase()->update( - self::TABLE_NAME, - [ - 'image_rid' => [ilDBConstants::T_TEXT, '-'], - ], - ['id' => [ilDBConstants::T_INTEGER, $id]] - ); - } - } - - private function getImagePath(int $id, string $image): string - { - $exp = explode('.', $image); - $suffix = strtolower(array_pop($exp)); - - return $this->getFilePath($id) . '/img' . $id . '.' . $suffix; - } - - private function getFilePath(int $a_id): string - { - return ILIAS_ABSOLUTE_PATH . '/' . $this->legacyWebDir() . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeTemplateId($a_id); - } - - private function legacyWebDir(): string - { - $web_dir = trim(ILIAS_WEB_DIR, '/'); - if ($web_dir !== 'public' && !str_starts_with($web_dir, 'public/')) { - return 'public/' . $web_dir; - } - - return $web_dir; - } - - private function createLegacyPathSegmentForBadgeTemplateId(int $id): string - { - $path = []; - $found = false; - $num = $id; - $path_string = ''; - for ($i = 3; $i > 0; $i--) { - $factor = 100 ** $i; - if (($tmp = (int) ($num / $factor)) || $found) { - $path[] = $tmp; - $num %= $factor; - $found = true; - } - } - - if (count($path)) { - $path_string = (implode('/', $path) . '/'); - } - - return $path_string . 'badgetmpl_' . $id; - } - - public function getRemainingAmountOfSteps(): int - { - $res = $this->helper->getDatabase()->query( - 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''" - ); - $row = $this->helper->getDatabase()->fetchObject($res); - - return (int) ($row->amount ?? 0); - } - - private function inform(string $text, bool $force = false): void - { - if ($this->io === null || (!$force && !$this->io->isVerbose())) { - return; - } - - $this->io->inform($text); - } - - private function error(string $text): void - { - if ($this->io === null) { - return; - } - - $this->io->error($text); - } -} diff --git a/components/ILIAS/Badge/classes/Setup/class.ilBadgesFilesMigration.php b/components/ILIAS/Badge/classes/Setup/class.ilBadgesFilesMigration.php deleted file mode 100644 index 91d7598fc485..000000000000 --- a/components/ILIAS/Badge/classes/Setup/class.ilBadgesFilesMigration.php +++ /dev/null @@ -1,207 +0,0 @@ -helper = new ilResourceStorageMigrationHelper( - new ilBadgeFileStakeholder(), - $environment - ); - $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION); - if ($io instanceof IOWrapper) { - $this->io = $io; - } - } - - public function step(Environment $environment): void - { - $this->helper->getDatabase()->setLimit(1); - $res = $this->helper->getDatabase()->query( - 'SELECT id, image, image_rid FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''" - ); - $row = $this->helper->getDatabase()->fetchObject($res); - if (!($row instanceof stdClass)) { - return; - } - - $id = (int) $row->id; - $image = $row->image; - - if ($image !== '' && $image !== null) { - $image_path = $this->getImagePath($id, $image); - - try { - $this->inform("Trying to move badge file $image_path for id $id to the storage service."); - $identification = $this->helper->movePathToStorage($image_path, ResourceCollection::NO_SPECIFIC_OWNER); - $this->inform('Migration proceeded without error.'); - if ($identification === null) { - $this->error( - 'IRSS returned NULL as identification when trying to move badge ' . - "file $image_path for id $id to the storage service." - ); - } else { - $this->inform("IRSS identification for badge with id $id: {$identification->serialize()}", true); - } - } catch (Throwable $e) { - $this->error("Failed to move badge file {$image_path} for id {$id} to the storage service with exception: {$e->getMessage()}"); - $this->error($e->getTraceAsString()); - throw $e; - } - - if ($identification === null) { - $identification = '-'; - } else { - $identification = $identification->serialize(); - } - - $this->helper->getDatabase()->update( - self::TABLE_NAME, - [ - 'image_rid' => [ilDBConstants::T_TEXT, $identification], - 'image' => [ilDBConstants::T_TEXT, null] - ], - ['id' => [ilDBConstants::T_INTEGER, $id]] - ); - } else { - $this->inform( - 'Cannot migrate badge with id ' . $id - . ' (table: ' . self::TABLE_NAME . ') because no image is set.', - true - ); - $this->helper->getDatabase()->update( - self::TABLE_NAME, - [ - 'image_rid' => [ilDBConstants::T_TEXT, '-'], - ], - ['id' => [ilDBConstants::T_INTEGER, $id]] - ); - } - } - - private function getImagePath(int $id, string $image): string - { - $exp = explode('.', $image); - $suffix = strtolower(array_pop($exp)); - - return $this->getFilePath($id) . '/img' . $id . '.' . $suffix; - } - - private function getFilePath(int $a_id): string - { - return ILIAS_ABSOLUTE_PATH . '/' . $this->legacyWebDir() . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeId($a_id); - } - - private function legacyWebDir(): string - { - $web_dir = trim(ILIAS_WEB_DIR, '/'); - if ($web_dir !== 'public' && !str_starts_with($web_dir, 'public/')) { - return 'public/' . $web_dir; - } - - return $web_dir; - } - - private function createLegacyPathSegmentForBadgeId(int $id): string - { - $path = []; - $found = false; - $num = $id; - $path_string = ''; - for ($i = 3; $i > 0; $i--) { - $factor = 100 ** $i; - if (($tmp = (int) ($num / $factor)) || $found) { - $path[] = $tmp; - $num %= $factor; - $found = true; - } - } - - if (count($path)) { - $path_string = (implode('/', $path) . '/'); - } - - return $path_string . 'badge_' . $id; - } - - public function getRemainingAmountOfSteps(): int - { - $res = $this->helper->getDatabase()->query( - 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''" - ); - $row = $this->helper->getDatabase()->fetchObject($res); - - return (int) ($row->amount ?? 0); - } - - /** - * @return Closure(string): string - */ - public function getRevisionNameCallback(): Closure - { - return static function (string $file_name): string { - return md5($file_name); - }; - } - - private function inform(string $text, bool $force = false): void - { - if ($this->io === null || (!$force && !$this->io->isVerbose())) { - return; - } - - $this->io->inform($text); - } - - private function error(string $text): void - { - if ($this->io === null) { - return; - } - - $this->io->error($text); - } -} diff --git a/components/ILIAS/Badge/classes/Tile.php b/components/ILIAS/Badge/classes/Tile.php index 18d118808ea3..bc37a9eee36a 100755 --- a/components/ILIAS/Badge/classes/Tile.php +++ b/components/ILIAS/Badge/classes/Tile.php @@ -29,12 +29,9 @@ use ilDatePresentation; use ilDateTime; use ilDateTimeException; -use ilWACSignedPath; class Tile { - /** @var Closure(string): string */ - private readonly Closure $sign_file; private readonly BadgeParent $parent; private readonly Modal $modal; /** @var Closure(int): string */ @@ -42,19 +39,16 @@ class Tile private readonly ilBadgeImage $badge_image_service; /** - * @param Closure(string): string $sign_file * @param Closure(int): string $format_date */ public function __construct( private readonly Container $container, ?BadgeParent $parent = null, ?Modal $modal = null, - $sign_file = [ilWACSignedPath::class, 'signFile'], ?Closure $format_date = null, ) { $this->parent = $parent ?? new BadgeParent($this->container); $this->modal = $modal ?? new Modal($this->container); - $this->sign_file = Closure::fromCallable($sign_file); if (!$format_date) { class_exists(ilDateTime::class); // Ensure ilDateTime is loaded as IL_CAL_UNIX is defined in ilDateTime.php. $format_date = static fn($date, int $format = IL_CAL_UNIX): string => ( diff --git a/components/ILIAS/Badge/classes/class.ilBadge.php b/components/ILIAS/Badge/classes/class.ilBadge.php index d18cc9b5e37c..ae08fdabd2d3 100755 --- a/components/ILIAS/Badge/classes/class.ilBadge.php +++ b/components/ILIAS/Badge/classes/class.ilBadge.php @@ -16,10 +16,9 @@ * *********************************************************************/ +use ILIAS\DI\Container; use ILIAS\ResourceStorage\Services; use ILIAS\ResourceStorage\Identification\ResourceIdentification; -use ILIAS\DI\Container; -use ILIAS\Services\Badge\BadgeException; class ilBadge { @@ -27,23 +26,20 @@ class ilBadge protected ilDBInterface $db; protected int $id = 0; protected int $parent_id = 0; - protected string $type_id = ""; + protected string $type_id = ''; protected bool $active = false; - protected string $title = ""; - protected string $desc = ""; - protected string $image = ""; + protected string $title = ''; + protected string $desc = ''; protected ?string $image_rid = null; - protected string $valid = ""; + protected string $valid = ''; protected ?array $config = null; - protected string $criteria = ""; - + protected string $criteria = ''; private ?Services $resource_storage; public function __construct( ?int $a_id = null, ?Container $container = null ) { - if ($container === null) { global $DIC; $container = $DIC; @@ -58,7 +54,6 @@ public function __construct( } /** - * @param array|null $a_filter * @return self[] */ public static function getInstancesByParentId( @@ -71,20 +66,20 @@ public static function getInstancesByParentId( $res = []; - $sql = "SELECT * FROM badge_badge" . - " WHERE parent_id = " . $ilDB->quote($a_parent_id); + $sql = 'SELECT * FROM badge_badge' . + ' WHERE parent_id = ' . $ilDB->quote($a_parent_id); if ($a_filter) { - if ($a_filter["title"] ?? false) { - $sql .= " AND " . $ilDB->like("title", "text", "%" . trim($a_filter["title"]) . "%"); + if ($a_filter['title'] ?? false) { + $sql .= ' AND ' . $ilDB->like('title', 'text', '%' . trim($a_filter['title']) . '%'); } - if ($a_filter["type"] ?? false) { - $sql .= " AND type_id = " . $ilDB->quote($a_filter["type"], "integer"); + if ($a_filter['type'] ?? false) { + $sql .= ' AND type_id = ' . $ilDB->quote($a_filter['type'], 'integer'); } } $set = $ilDB->query($sql . - " ORDER BY title"); + ' ORDER BY title'); while ($row = $ilDB->fetchAssoc($set)) { $obj = new self(); $obj->importDBRow($row); @@ -106,9 +101,9 @@ public static function getInstancesByType( $res = []; - $set = $ilDB->query("SELECT * FROM badge_badge" . - " WHERE type_id = " . $ilDB->quote($a_type_id, "text") . - " ORDER BY title"); + $set = $ilDB->query('SELECT * FROM badge_badge' . + ' WHERE type_id = ' . $ilDB->quote($a_type_id, 'text') . + ' ORDER BY title'); while ($row = $ilDB->fetchAssoc($set)) { $obj = new self(); $obj->importDBRow($row); @@ -123,25 +118,27 @@ public function clone(int $target_parent_obj_id): void $this->setParentId($target_parent_obj_id); $this->setActive(false); - if ($this->getId()) { - if ($this->getImageRid()) { - $current_collection_id = new ResourceIdentification($this->getImageRid()); - $new_collection_id = $this->resource_storage->manage()->clone($current_collection_id); - $this->setId(0); - $this->setImageRid($new_collection_id); - $this->create(); - } else { - $this->log->warning('Please run the "Migration of files of badges to the resource storage service" job, before working with badges.'); - } + if (!$this->getId()) { + return; } + + $image_rid = $this->getImageRid(); + $this->setId(0); + if ($image_rid !== null) { + $cloned_rid = $this->resource_storage->manage()->clone(new ResourceIdentification($image_rid)); + $this->setImageRid($cloned_rid); + } + $this->create(); } public function getTypeInstance(): ?ilBadgeType { if ($this->getTypeId()) { $handler = ilBadgeHandler::getInstance(); + return $handler->getTypeInstanceByUniqueId($this->getTypeId()); } + return null; } @@ -149,7 +146,7 @@ public function copy( int $a_new_parent_id, string $copy_suffix ): void { - $this->setTitle($this->getTitle() . " " . $copy_suffix); + $this->setTitle($this->getTitle() . ' ' . $copy_suffix); $this->setParentId($a_new_parent_id); $this->setActive(false); @@ -175,7 +172,6 @@ public function copy( * title: ?string, * descr: ?string, * conf: ?string, - * image: ?string, * valid: ?string, * crit: ?string, * image_rid: ?string, @@ -325,94 +321,6 @@ public function getConfiguration(): ?array return $this->config; } - public function setImage(?string $a_value): void - { - if ($a_value !== null) { - $this->image = trim($a_value); - } - } - - public function getImage(): string - { - return $this->image; - } - - /** - * @throws BadgeException - */ - public function uploadImage( - array $a_upload_meta - ): void { - if ($this->getId() && - $a_upload_meta["tmp_name"]) { - $this->setImage($a_upload_meta["name"]); - $path = $this->getImagePath(); - - try { - if (ilFileUtils::moveUploadedFile($a_upload_meta['tmp_name'], $this->getImagePath(false), $path)) { - $this->update(); - } - } catch (ilException $e) { - throw BadgeException::moveUploadedBadgeImageFailed($this, $e); - } - - } - } - - /** - * @throws BadgeException - */ - public function importImage( - string $a_name, - string $a_file - ): void { - if (file_exists($a_file)) { - $this->setImage($a_name); - copy($a_file, $this->getImagePath()); // #18280 - - $this->update(); - } else { - throw BadgeException::uploadedBadgeImageFileNotFound($this); - } - } - - public function getImagePath( - bool $a_full_path = true - ): string { - if ($this->getId()) { - $exp = explode(".", $this->getImage()); - $suffix = strtolower(array_pop($exp)); - if ($a_full_path) { - return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix; - } - - return "img" . $this->getId() . "." . $suffix; - } - - return ""; - } - - protected function getFilePath( - int $a_id, - ?string $a_subdir = null - ): string { - $storage = new ilFSStorageBadge($a_id); - $storage->create(); - - $path = $storage->getAbsolutePath() . "/"; - - if ($a_subdir) { - $path .= $a_subdir . "/"; - - if (!is_dir($path)) { - mkdir($path); - } - } - - return $path; - } - - // // crud // @@ -421,8 +329,8 @@ protected function read(int $a_id): void { $ilDB = $this->db; - $set = $ilDB->query("SELECT * FROM badge_badge" . - " WHERE id = " . $ilDB->quote($a_id, "integer")); + $set = $ilDB->query('SELECT * FROM badge_badge' . + ' WHERE id = ' . $ilDB->quote($a_id, 'integer')); if ($ilDB->numRows($set)) { $row = $ilDB->fetchAssoc($set); $this->importDBRow($row); @@ -432,18 +340,17 @@ protected function read(int $a_id): void protected function importDBRow( array $a_row ): void { - $this->setId($a_row["id"]); - $this->setParentId($a_row["parent_id"]); - $this->setTypeId($a_row["type_id"]); - $this->setActive($a_row["active"]); - $this->setTitle($a_row["title"]); - $this->setDescription($a_row["descr"]); - $this->setCriteria($a_row["crit"]); - $this->setImage($a_row["image"]); - $this->setImageRid($a_row["image_rid"]); - $this->setValid($a_row["valid"]); - $this->setConfiguration($a_row["conf"] - ? unserialize($a_row["conf"], ["allowed_classes" => false]) + $this->setId($a_row['id']); + $this->setParentId($a_row['parent_id']); + $this->setTypeId($a_row['type_id']); + $this->setActive($a_row['active']); + $this->setTitle($a_row['title']); + $this->setDescription($a_row['descr']); + $this->setCriteria($a_row['crit']); + $this->setImageRid($a_row['image_rid']); + $this->setValid($a_row['valid']); + $this->setConfiguration($a_row['conf'] + ? unserialize($a_row['conf'], ['allowed_classes' => false]) : null); } @@ -453,19 +360,20 @@ public function create(): void if ($this->getId()) { $this->update(); + return; } - $id = $ilDB->nextId("badge_badge"); + $id = $ilDB->nextId('badge_badge'); $this->setId($id); $fields = $this->getPropertiesForStorage(); - $fields["id"] = ["integer", $id]; - $fields["parent_id"] = ["integer", $this->getParentId()]; - $fields["type_id"] = ["text", $this->getTypeId()]; + $fields['id'] = ['integer', $id]; + $fields['parent_id'] = ['integer', $this->getParentId()]; + $fields['type_id'] = ['text', $this->getTypeId()]; - $ilDB->insert("badge_badge", $fields); + $ilDB->insert('badge_badge', $fields); } public function update(): void @@ -474,15 +382,16 @@ public function update(): void if (!$this->getId()) { $this->create(); + return; } $fields = $this->getPropertiesForStorage(); $ilDB->update( - "badge_badge", + 'badge_badge', $fields, - ["id" => ["integer", $this->getId()]] + ['id' => ['integer', $this->getId()]] ); } @@ -506,8 +415,8 @@ public function delete(): void ilBadgeAssignment::deleteByBadgeId($this->getId()); - $ilDB->manipulate("DELETE FROM badge_badge" . - " WHERE id = " . $ilDB->quote($this->getId(), "integer")); + $ilDB->manipulate('DELETE FROM badge_badge' . + ' WHERE id = ' . $ilDB->quote($this->getId(), 'integer')); } /** @@ -516,20 +425,18 @@ public function delete(): void protected function getPropertiesForStorage(): array { return [ - "active" => ["integer", $this->isActive()], - "title" => ["text", $this->getTitle()], - "descr" => ["text", $this->getDescription()], - "crit" => ["text", $this->getCriteria()], - "image" => ["text", $this->getImage()], - "image_rid" => ["text", $this->getImageRid()], - "valid" => ["text", $this->getValid()], - "conf" => [ - "text", $this->getConfiguration() ? serialize($this->getConfiguration()) : null + 'active' => ['integer', $this->isActive()], + 'title' => ['text', $this->getTitle()], + 'descr' => ['text', $this->getDescription()], + 'crit' => ['text', $this->getCriteria()], + 'image_rid' => ['text', $this->getImageRid()], + 'valid' => ['text', $this->getValid()], + 'conf' => [ + 'text', $this->getConfiguration() ? serialize($this->getConfiguration()) : null ] ]; } - // // helper // @@ -540,29 +447,28 @@ protected function getPropertiesForStorage(): array public function getParentMeta(): array { $parent_type = ilObject::_lookupType($this->getParentId()); - $parent_title = ""; + $parent_title = ''; if ($parent_type) { $parent_title = ilObject::_lookupTitle($this->getParentId()); $deleted = false; } else { // already deleted? $parent = ilObjectDataDeletionLog::get($this->getParentId()); - if ($parent["type"]) { - $parent_type = $parent["type"]; - $parent_title = $parent["title"]; + if ($parent['type']) { + $parent_type = $parent['type']; + $parent_title = $parent['title']; } $deleted = true; } return [ - "id" => $this->getParentId(), - "type" => $parent_type, - "title" => $parent_title, - "deleted" => $deleted + 'id' => $this->getParentId(), + 'type' => $parent_type, + 'title' => $parent_title, + 'deleted' => $deleted ]; } - // // PUBLISHING // @@ -572,19 +478,18 @@ protected function prepareJson( string $a_img_suffix ): stdClass { $json = new stdClass(); - $json->{"@context"} = "https://w3id.org/openbadges/v1"; - $json->type = "BadgeClass"; - $json->id = $a_base_url . "class.json"; + $json->{'@context'} = 'https://w3id.org/openbadges/v1'; + $json->type = 'BadgeClass'; + $json->id = $a_base_url . 'class.json'; $json->name = $this->getTitle(); $json->description = $this->getDescription(); - $json->image = $a_base_url . "image." . $a_img_suffix; - $json->criteria = $a_base_url . "criteria.txt"; + $json->image = $a_base_url . 'image.' . $a_img_suffix; + $json->criteria = $a_base_url . 'criteria.txt'; $json->issuer = ilBadgeHandler::getInstance()->getIssuerStaticUrl(); return $json; } - public function deleteStaticFiles(): void { // remove instance files @@ -601,14 +506,19 @@ public static function getExtendedTypeCaption( $lng = $DIC->language(); - return $a_type->getCaption() . " (" . + return $a_type->getCaption() . ' (' . ($a_type instanceof ilBadgeAuto - ? $lng->txt("badge_subtype_auto") - : $lng->txt("badge_subtype_manual")) . ")"; + ? $lng->txt('badge_subtype_auto') + : $lng->txt('badge_subtype_manual')) . ')'; } public function getImageRid(): ?string { + // '-' was written by the removed filesystem migration for badges without an image. + if ($this->image_rid === null || $this->image_rid === '' || $this->image_rid === '-') { + return null; + } + return $this->image_rid; } diff --git a/components/ILIAS/Badge/classes/class.ilBadgeImage.php b/components/ILIAS/Badge/classes/class.ilBadgeImage.php index 0359188f128f..1a9c845d1d28 100644 --- a/components/ILIAS/Badge/classes/class.ilBadgeImage.php +++ b/components/ILIAS/Badge/classes/class.ilBadgeImage.php @@ -26,9 +26,7 @@ use ILIAS\FileUpload\FileUpload; use ILIAS\FileUpload\Exception\IllegalStateException; use ilGlobalTemplateInterface; -use ilWACSignedPath; use ILIAS\ResourceStorage\Identification\ResourceIdentification; -use Exception; class ilBadgeImage { @@ -62,18 +60,17 @@ public function getImageFromResourceId( ilBadge $badge, int $size = self::IMAGE_SIZE_XS ): string { - $image_src = ''; + $image_rid = $badge->getImageRid(); + if ($image_rid === null) { + return ''; + } - if ($badge->getImageRid() !== '' && $badge->getImageRid() !== null) { - $identification = $this->resource_storage->manage()->find($badge->getImageRid()); - if ($identification !== null) { - $image_src = $this->resource_storage->consume()->src($identification)->getSrc(); - } - } elseif ($badge->getImage()) { - $image_src = ilWACSignedPath::signFile($badge->getImagePath()); + $identification = $this->resource_storage->manage()->find($image_rid); + if ($identification === null) { + return ''; } - return $image_src; + return $this->resource_storage->consume()->src($identification)->getSrc(); } diff --git a/components/ILIAS/Badge/classes/class.ilBadgeImageTemplate.php b/components/ILIAS/Badge/classes/class.ilBadgeImageTemplate.php index c95b348f852a..750e6f4fc0ea 100755 --- a/components/ILIAS/Badge/classes/class.ilBadgeImageTemplate.php +++ b/components/ILIAS/Badge/classes/class.ilBadgeImageTemplate.php @@ -16,23 +16,24 @@ * *********************************************************************/ -use ILIAS\FileUpload\Exception\IllegalStateException; -use ILIAS\ResourceStorage\Services; use ILIAS\FileUpload\FileUpload; +use ILIAS\ResourceStorage\Services; +use ILIAS\FileUpload\Exception\IllegalStateException; use ILIAS\ResourceStorage\Identification\ResourceIdentification; class ilBadgeImageTemplate { protected ilDBInterface $db; protected int $id = 0; - protected string $title = ""; - protected string $image = ""; - protected ?string $image_rid = ""; + protected string $title = ''; + protected ?string $image_rid = null; + /** @var string[] */ protected ?array $types = null; protected Services $resource_storage; protected FileUpload $upload_service; protected ilGlobalTemplateInterface $main_template; + protected ilLogger $log; public function __construct(?int $a_id = null) { @@ -41,6 +42,7 @@ public function __construct(?int $a_id = null) $this->resource_storage = $DIC->resourceStorage(); $this->upload_service = $DIC->upload(); $this->main_template = $DIC->ui()->mainTemplate(); + $this->log = $DIC->logger()->forComponent('badge'); $this->db = $DIC->database(); if ($a_id) { $this->read($a_id); @@ -56,18 +58,18 @@ public static function getInstances(): array $ilDB = $DIC->database(); - $res = array(); + $res = []; - $types = array(); - $set = $ilDB->query("SELECT * FROM badge_image_templ_type"); + $types = []; + $set = $ilDB->query('SELECT * FROM badge_image_templ_type'); while ($row = $ilDB->fetchAssoc($set)) { - $types[$row["tmpl_id"]][] = $row["type_id"]; + $types[$row['tmpl_id']][] = $row['type_id']; } - $set = $ilDB->query("SELECT * FROM badge_image_template" . - " ORDER BY title"); + $set = $ilDB->query('SELECT * FROM badge_image_template' . + ' ORDER BY title'); while ($row = $ilDB->fetchAssoc($set)) { - $row["types"] = (array) ($types[$row["id"]] ?? null); + $row['types'] = (array) ($types[$row['id']] ?? null); $obj = new self(); $obj->importDBRow($row); @@ -93,7 +95,6 @@ public static function getInstancesByType(string $a_type_unique_id): array return $res; } - // // setter/getter // @@ -118,13 +119,6 @@ public function getTitle(): string return $this->title; } - protected function setImage(?string $a_value): void - { - if ($a_value !== null) { - $this->image = trim($a_value); - } - } - /** * @return string[] */ @@ -140,34 +134,6 @@ public function setTypes(?array $types = null): void : null; } - public function getImage(): string - { - return $this->image; - } - - /** - * @throws ilException - * @throws ilFileUtilsException - */ - public function uploadImage(array $a_upload_meta): void - { - if ($this->getId() && - $a_upload_meta["tmp_name"]) { - $path = $this->getFilePath($this->getId()); - - $filename = ilFileUtils::getValidFilename($a_upload_meta["name"]); - - $exp = explode(".", $filename); - $suffix = strtolower(array_pop($exp)); - $tgt = $path . "img" . $this->getId() . "." . $suffix; - - if (ilFileUtils::moveUploadedFile($a_upload_meta["tmp_name"], "img" . $this->getId() . "." . $suffix, $tgt)) { - $this->setImage($filename); - $this->update(); - } - } - } - public function processImageUpload(ilBadgeImageTemplate $badge): void { try { @@ -192,44 +158,6 @@ public function processImageUpload(ilBadgeImageTemplate $badge): void } } - public function getImagePath(): string - { - if ($this->getId()) { - if (is_file($this->getFilePath($this->getId()) . "img" . $this->getId())) { // formerly (early 5.2 versino), images have been uploaded with no suffix - return $this->getFilePath($this->getId()) . "img" . $this->getId(); - } - - $exp = explode(".", $this->getImage()); - $suffix = strtolower(array_pop($exp)); - return $this->getFilePath($this->getId()) . "img" . $this->getId() . "." . $suffix; - } - return ""; - } - - /** - * Init file system storage - */ - protected function getFilePath( - int $a_id, - ?string $a_subdir = null - ): string { - $storage = new ilFSStorageBadgeImageTemplate($a_id); - $storage->create(); - - $path = $storage->getAbsolutePath() . "/"; - - if ($a_subdir) { - $path .= $a_subdir . "/"; - - if (!is_dir($path)) { - mkdir($path); - } - } - - return $path; - } - - // // crud // @@ -238,11 +166,11 @@ protected function read(int $a_id): void { $ilDB = $this->db; - $set = $ilDB->query("SELECT * FROM badge_image_template" . - " WHERE id = " . $ilDB->quote($a_id, "integer")); + $set = $ilDB->query('SELECT * FROM badge_image_template' . + ' WHERE id = ' . $ilDB->quote($a_id, 'integer')); if ($ilDB->numRows($set)) { $row = $ilDB->fetchAssoc($set); - $row["types"] = $this->readTypes($a_id); + $row['types'] = $this->readTypes($a_id); $this->importDBRow($row); } } @@ -251,11 +179,11 @@ protected function readTypes(int $a_id): ?array { $ilDB = $this->db; - $res = array(); + $res = []; - $set = $ilDB->query("SELECT * FROM badge_image_templ_type WHERE tmpl_id = " . $ilDB->quote($a_id, "integer")); + $set = $ilDB->query('SELECT * FROM badge_image_templ_type WHERE tmpl_id = ' . $ilDB->quote($a_id, 'integer')); while ($row = $ilDB->fetchAssoc($set)) { - $res[] = $row["type_id"]; + $res[] = $row['type_id']; } if (!count($res)) { @@ -267,15 +195,12 @@ protected function readTypes(int $a_id): ?array protected function importDBRow(array $a_row): void { - $this->setId($a_row["id"]); - $this->setTitle($a_row["title"]); - if (isset($a_row["image"])) { - $this->setImage($a_row["image"]); - } - if (isset($a_row["image_rid"])) { - $this->setImageRid($a_row["image_rid"]); + $this->setId($a_row['id']); + $this->setTitle($a_row['title']); + if (isset($a_row['image_rid'])) { + $this->setImageRid($a_row['image_rid']); } - $this->setTypes($a_row["types"]); + $this->setTypes($a_row['types']); } public function create(): void @@ -284,16 +209,17 @@ public function create(): void if ($this->getId()) { $this->update(); + return; } - $id = $ilDB->nextId("badge_image_template"); + $id = $ilDB->nextId('badge_image_template'); $this->setId($id); $fields = $this->getPropertiesForStorage(); - $fields["id"] = array("integer", $id); + $fields['id'] = ['integer', $id]; - $ilDB->insert("badge_image_template", $fields); + $ilDB->insert('badge_image_template', $fields); $this->saveTypes(); } @@ -304,15 +230,16 @@ public function update(): void if (!$this->getId()) { $this->create(); + return; } $fields = $this->getPropertiesForStorage(); $ilDB->update( - "badge_image_template", + 'badge_image_template', $fields, - array("id" => array("integer", $this->getId())) + ['id' => ['integer', $this->getId()]] ); $this->saveTypes(); @@ -326,11 +253,24 @@ public function delete(): void return; } - $path = $this->getFilePath($this->getId()); - ilFileUtils::delDir($path); + $image_rid = $this->getImageRid(); + if ($image_rid !== null) { + try { + $this->resource_storage->manage()->remove( + new ResourceIdentification($image_rid), + new ilBadgeFileStakeholder() + ); + } catch (Exception $e) { + $this->log->warning(sprintf( + 'There was an exception, while deleting the badge image template with id %s. Exception: %s', + $this->getId(), + $e->getMessage() + )); + } + } - $ilDB->manipulate("DELETE FROM badge_image_template" . - " WHERE id = " . $ilDB->quote($this->getId(), "integer")); + $ilDB->manipulate('DELETE FROM badge_image_template' . + ' WHERE id = ' . $ilDB->quote($this->getId(), 'integer')); } /** @@ -339,9 +279,8 @@ public function delete(): void protected function getPropertiesForStorage(): array { return [ - "title" => ["text", $this->getTitle()], - "image" => ["text", $this->getImage()], - "image_rid" => ["text", $this->getImageRid()] + 'title' => ['text', $this->getTitle()], + 'image_rid' => ['text', $this->getImageRid()] ]; } @@ -350,16 +289,16 @@ protected function saveTypes(): void $ilDB = $this->db; if ($this->getId()) { - $ilDB->manipulate("DELETE FROM badge_image_templ_type" . - " WHERE tmpl_id = " . $ilDB->quote($this->getId(), "integer")); + $ilDB->manipulate('DELETE FROM badge_image_templ_type' . + ' WHERE tmpl_id = ' . $ilDB->quote($this->getId(), 'integer')); if ($this->getTypes()) { foreach ($this->getTypes() as $type) { - $fields = array( - "tmpl_id" => array("integer", $this->getId()), - "type_id" => array("text", $type) - ); - $ilDB->insert("badge_image_templ_type", $fields); + $fields = [ + 'tmpl_id' => ['integer', $this->getId()], + 'type_id' => ['text', $type] + ]; + $ilDB->insert('badge_image_templ_type', $fields); } } } @@ -367,6 +306,11 @@ protected function saveTypes(): void public function getImageRid(): ?string { + // '-' was written by the removed filesystem migration for templates without an image. + if ($this->image_rid === null || $this->image_rid === '' || $this->image_rid === '-') { + return null; + } + return $this->image_rid; } @@ -375,19 +319,18 @@ public function setImageRid(?string $image_rid = null): void $this->image_rid = $image_rid; } - public function getImageFromResourceId( - ): string { - $image_src = ''; + public function getImageFromResourceId(): string + { + $image_rid = $this->getImageRid(); + if ($image_rid === null) { + return ''; + } - if ($this->getImageRid()) { - $identification = $this->resource_storage->manage()->find($this->getImageRid()); - if ($identification !== null) { - $image_src = $this->resource_storage->consume()->src($identification)->getSrc(); - } - } elseif ($this->getImage()) { - $image_src = ilWACSignedPath::signFile($this->getImagePath()); + $identification = $this->resource_storage->manage()->find($image_rid); + if ($identification === null) { + return ''; } - return $image_src; + return $this->resource_storage->consume()->src($identification)->getSrc(); } } diff --git a/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php b/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php index 24990641a995..163d52aa5518 100755 --- a/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php +++ b/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php @@ -476,7 +476,10 @@ private function saveBadgeCmd(): void $this->badge_image_service->processImageUpload($badge); } else { $tmpl = new ilBadgeImageTemplate($form->getInput('tmpl')); - $this->cloneBadgeTemplate($badge, new ResourceIdentification($tmpl->getImageRid())); + $image_rid = $tmpl->getImageRid(); + if ($image_rid !== null) { + $this->cloneBadgeTemplate($badge, new ResourceIdentification($image_rid)); + } } $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('settings_saved'), true); @@ -529,8 +532,6 @@ private function setBadgeFormValues( $a_form->getItemByPostVar('title')->setValue($a_badge->getTitle()); $a_form->getItemByPostVar('desc')->setValue($a_badge->getDescription()); $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_service->getImageFromBadge($a_badge); if ($image_src !== '') { @@ -588,7 +589,10 @@ private function updateBadgeCmd(): void if ($tmpl_id !== '') { $this->removeResourceStorageImage($badge); $tmpl = new ilBadgeImageTemplate($tmpl_id); - $this->cloneBadgeTemplate($badge, new ResourceIdentification($tmpl->getImageRid())); + $image_rid = $tmpl->getImageRid(); + if ($image_rid !== null) { + $this->cloneBadgeTemplate($badge, new ResourceIdentification($image_rid)); + } } $badge->update(); @@ -964,9 +968,10 @@ private function cloneBadgeTemplate(ilBadge $badge, ?ResourceIdentification $rid private function removeResourceStorageImage(ilBadge $badge): void { - if ($badge->getImageRid() !== '') { + $image_rid = $badge->getImageRid(); + if ($image_rid !== null) { $this->resource_storage->manage()->remove( - new ResourceIdentification($badge->getImageRid()), + new ResourceIdentification($image_rid), new ilBadgeFileStakeholder() ); } diff --git a/components/ILIAS/Badge/classes/class.ilBadgeWAC.php b/components/ILIAS/Badge/classes/class.ilBadgeWAC.php deleted file mode 100755 index 1fd47bfa5ec3..000000000000 --- a/components/ILIAS/Badge/classes/class.ilBadgeWAC.php +++ /dev/null @@ -1,137 +0,0 @@ -getPath(), '..') !== false) { - return false; - } - - if (!preg_match('@ilBadge\/(\d+\/)*?badge(tmpl)?_(\d+)\/@ui', $ilWACPath->getPath())) { - return false; - } - - $obj_id = array_keys(ilObject::_getObjectsByType('bdga'))[0] ?? null; - $admin_ref_id = null; - if ($obj_id > 0) { - $admin_ref_id = array_values(ilObject::_getAllReferences($obj_id))[0] ?? null; - } - - $has_global_badge_administration_access = ( - $admin_ref_id > 0 && - $DIC->rbac()->system()->checkAccessOfUser($DIC->user()->getId(), 'read', $admin_ref_id) - ); - - if (preg_match('@\/badgetmpl_(\d+)\/@ui', $ilWACPath->getPath())) { - // Badge template images must only be accessible for accounts with `read` permission on the badge administration node - return $has_global_badge_administration_access; - } - - if (preg_match('@\/badge_(\d+)\/@ui', $ilWACPath->getPath(), $matches)) { - if ($has_global_badge_administration_access) { - return true; - } - - $badge_id = (int) $matches[1]; - - return ( - $this->isAssignedBadge($DIC, $badge_id) || - $this->isAssignedBadgeOfPublishedUserProfile($DIC, $badge_id) || - $this->hasAccessToBadgeParentIdNode($DIC, $badge_id, $has_global_badge_administration_access) - ); - } - - return false; - } - - private function hasAccessToBadgeParentIdNode( - \ILIAS\DI\Container $DIC, - int $badge_id, - bool $has_global_badge_administration_access - ): bool { - // If the acting user still does not have access, check if the image is used in an object badge type - $badge = new ilBadge($badge_id); - if ($badge->getParentId() > 0) { - return false; - } - - $badge_handler = ilBadgeHandler::getInstance(); - if (!$badge_handler->isObjectActive((int) $badge->getParentId())) { - return false; - } - - $context_ref_id = array_values(ilObject::_getAllReferences((int) $badge->getParentId()))[0] ?? null; - if (!($context_ref_id > 0)) { - return false; - } - - $context_ref_id = (int) $context_ref_id; - if ($DIC->repositoryTree()->isGrandChild((int) SYSTEM_FOLDER_ID, $context_ref_id)) { - $has_access = $has_global_badge_administration_access; - } else { - $has_access = $DIC->access()->checkAccessOfUser( - $DIC->user()->getId(), - 'write', - '', - $context_ref_id - ); - } - - return $has_access; - } - - private function isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id): bool - { - // First, check all badge assignments of the current user for a match - $badges_of_user = ilBadgeAssignment::getInstancesByUserId($DIC->user()->getId()); - foreach ($badges_of_user as $user_badge) { - if ((int) $user_badge->getBadgeId() === $badge_id) { - return true; - } - } - - return false; - } - - private function isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id): bool - { - // It seems the badge is not assigned to the curent user, so check if the profile of the badge user is made visible - $assignments = ilBadgeAssignment::getInstancesByBadgeId($badge_id); - foreach ($assignments as $assignment) { - if (!$assignment->getPosition()) { - continue; - } - - $user = ilObjectFactory::getInstanceByObjId((int) $assignment->getUserId(), false); - if (!$user instanceof ilObjUser) { - continue; - } - - $profile_visibility = $user->getPref('public_profile'); - if ($profile_visibility === 'g' || ($profile_visibility === 'y' && !$DIC->user()->isAnonymous())) { - return true; - } - } - - return false; - } -} diff --git a/components/ILIAS/Badge/classes/class.ilFSStorageBadge.php b/components/ILIAS/Badge/classes/class.ilFSStorageBadge.php deleted file mode 100755 index 5e11d56fd5cb..000000000000 --- a/components/ILIAS/Badge/classes/class.ilFSStorageBadge.php +++ /dev/null @@ -1,35 +0,0 @@ -getItemByPostVar('title')->setValue($a_tmpl->getTitle()); - if ($a_tmpl->getImageRid() !== null) { - $img = $a_tmpl->getImageFromResourceId(); - $a_form->getItemByPostVar('img')->setImage($img); - $a_form->getItemByPostVar('img')->setValue($a_tmpl->getImageRid()); - } else { - $a_form->getItemByPostVar('img')->setImage($a_tmpl->getImagePath()); - $a_form->getItemByPostVar('img')->setValue($a_tmpl->getImage()); + $image_src = $a_tmpl->getImageFromResourceId(); + if ($image_src !== '') { + $a_form->getItemByPostVar('img')->setImage($image_src); + } + $image_rid = $a_tmpl->getImageRid(); + if ($image_rid !== null) { + $a_form->getItemByPostVar('img')->setValue($image_rid); } if ($a_tmpl->getTypes()) { diff --git a/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php b/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php index 9ca370369496..9ec357c3242c 100755 --- a/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php +++ b/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php @@ -150,8 +150,9 @@ public function getRows( $identifications = []; foreach ($records as $record) { - if (isset($record[self::RECORD_RAW]['image_rid']) && $record[self::RECORD_RAW]['image_rid'] !== '') { - $identifications[] = $record[self::RECORD_RAW]['image_rid']; + $image_rid = $record[self::RECORD_RAW]['image_rid'] ?? null; + if (is_string($image_rid) && $image_rid !== '' && $image_rid !== '-') { + $identifications[] = $image_rid; } } @@ -190,7 +191,6 @@ public function getTotalRowCount( * title: ?string, * descr: ?string, * conf: ?string, - * image: ?string, * valid: ?string, * crit: ?string, * image_rid: ?string, @@ -220,7 +220,6 @@ private function enrichRecord( $badge = new ilBadge(0); $badge->setId($badge_item['id']); $badge->setImageRid($badge_item['image_rid']); - $badge->setImage($badge_item['image']); $images = [ 'rendered' => null, @@ -337,7 +336,6 @@ private function enrichRecord( * title: ?string, * descr: ?string, * conf: ?string, - * image: ?string, * valid: ?string, * crit: ?string, * image_rid: ?string, diff --git a/components/ILIAS/Badge/service.xml b/components/ILIAS/Badge/service.xml index 0be84dded30e..ab26114a7680 100755 --- a/components/ILIAS/Badge/service.xml +++ b/components/ILIAS/Badge/service.xml @@ -11,7 +11,4 @@ - - - \ No newline at end of file diff --git a/components/ILIAS/Badge/tests/ModalTest.php b/components/ILIAS/Badge/tests/ModalTest.php index 036f8e091c6c..53a38c5b9362 100755 --- a/components/ILIAS/Badge/tests/ModalTest.php +++ b/components/ILIAS/Badge/tests/ModalTest.php @@ -20,7 +20,6 @@ namespace ILIAS\Badge\test; -use Exception; use ILIAS\DI\Container; use ILIAS\DI\UIServices; use ILIAS\Badge\Modal; @@ -43,9 +42,7 @@ class ModalTest extends TestCase public function testConstruct(): void { $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); - $modal = new Modal($container, static function (): void { - throw new Exception('Should not be called.'); - }); + $modal = new Modal($container); $this->assertInstanceOf(Modal::class, $modal); } @@ -89,7 +86,7 @@ public function testComponents(): void $content->method('badge')->willReturn($badge); $content->method('properties')->willReturn($properties); - $modal = new Modal($container, fn(string $file): string => '/'); + $modal = new Modal($container); $this->assertSame([$image_component, $divider_component, $item_component], $modal->components($content)); } diff --git a/components/ILIAS/Badge/tests/TileTest.php b/components/ILIAS/Badge/tests/TileTest.php index 36f1e8e4a6c6..f87a44cf3b36 100755 --- a/components/ILIAS/Badge/tests/TileTest.php +++ b/components/ILIAS/Badge/tests/TileTest.php @@ -43,18 +43,14 @@ public function testConstruct(): void $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); $parent = $this->getMockBuilder(BadgeParent::class)->disableOriginalConstructor()->getMock(); $modal = $this->getMockBuilder(Modal::class)->disableOriginalConstructor()->getMock(); - $sign_file = static fn(string $x): string => ''; $format_date = static fn(int $x): string => ''; - $this->assertInstanceOf(Tile::class, new Tile($container, $parent, $modal, $sign_file, $format_date)); + $this->assertInstanceOf(Tile::class, new Tile($container, $parent, $modal, $format_date)); } #[DataProvider('provideAsVariants')] public function testAs(string $method, array $expected_components): void { - $signed_file = '/some-signed-file'; - $badge_image_path = '/file-path'; - $badge_image_name = 'Dummy image'; $badge_image_rid_name = '43242-324234-324234-234233'; $badge = $this->getMockBuilder(ilBadge::class)->disableOriginalConstructor()->getMock(); $modal_content = $this->getMockBuilder(ModalContent::class)->disableOriginalConstructor()->getMock(); @@ -75,16 +71,10 @@ public function testAs(string $method, array $expected_components): void $format_date = function (int $x): void { throw new \RuntimeException('Should not be called.'); }; - $sign_file = function (string $path) use ($signed_file, $badge_image_path): string { - return $signed_file; - }; - - $badge->method('getImagePath')->willReturn($badge_image_path); - $badge->method('getImage')->willReturn($badge_image_name); $badge->method('getImageRid')->willReturn($badge_image_rid_name); $modal_content->method('badge')->willReturn($badge); - $tile = new Tile($container, $parent, $modal, $sign_file, $format_date); + $tile = new Tile($container, $parent, $modal, $format_date); $components = $tile->$method($modal_content); From 888e130f63c874775dafe4924478f33d4b2d3da3 Mon Sep 17 00:00:00 2001 From: Fabian Helfer Date: Thu, 29 Oct 2026 11:32:40 +0100 Subject: [PATCH 2/2] [Chore] Badge: Apply PHP-CS-Fixer formatting --- components/ILIAS/Badge/classes/Tile.php | 22 +++-- .../Badge/classes/class.ilBadgeImage.php | 6 +- .../classes/class.ilBadgeManagementGUI.php | 44 +++++---- .../class.ilObjBadgeAdministrationGUI.php | 12 +-- .../classes/class.ilObjectBadgeTableGUI.php | 91 ++++++++++--------- components/ILIAS/Badge/tests/ModalTest.php | 20 ++-- components/ILIAS/Badge/tests/TileTest.php | 23 +++-- 7 files changed, 114 insertions(+), 104 deletions(-) diff --git a/components/ILIAS/Badge/classes/Tile.php b/components/ILIAS/Badge/classes/Tile.php index bc37a9eee36a..3a93edf39ec2 100755 --- a/components/ILIAS/Badge/classes/Tile.php +++ b/components/ILIAS/Badge/classes/Tile.php @@ -21,19 +21,20 @@ namespace ILIAS\Badge; use Closure; -use ILIAS\DI\Container; -use ILIAS\UI\Component\Card\Card; -use ILIAS\UI\Component\Component; use ilBadge; +use ilDateTime; use ilBadgeAssignment; use ilDatePresentation; -use ilDateTime; +use ILIAS\DI\Container; use ilDateTimeException; +use ILIAS\UI\Component\Card\Card; +use ILIAS\UI\Component\Component; class Tile { private readonly BadgeParent $parent; private readonly Modal $modal; + /** @var Closure(int): string */ private readonly Closure $format_date; private readonly ilBadgeImage $badge_image_service; @@ -51,9 +52,9 @@ public function __construct( $this->modal = $modal ?? new Modal($this->container); if (!$format_date) { class_exists(ilDateTime::class); // Ensure ilDateTime is loaded as IL_CAL_UNIX is defined in ilDateTime.php. - $format_date = static fn($date, int $format = IL_CAL_UNIX): string => ( + $format_date = static fn($date, int $format = IL_CAL_UNIX): string => ilDatePresentation::formatDate(new ilDateTime($date, $format)) - ); + ; } $this->format_date = $format_date; $this->badge_image_service = new ilBadgeImage($container->resourceStorage(), $container->upload(), $container->ui()->mainTemplate()); @@ -73,8 +74,8 @@ public function inDeck(ilBadge $badge, ilBadgeAssignment $assignment, string $gu $modal = $this->modal($card); $image = $this->image($modal, $badge); $card = $card->withSections($badge_sections) - ->withImage($image) - ->withTitleAction($modal->getShowSignal()); + ->withImage($image) + ->withTitleAction($modal->getShowSignal()); return [ 'card' => $card, @@ -88,6 +89,7 @@ public function inDeck(ilBadge $badge, ilBadgeAssignment $assignment, string $gu public function asTitleWithLeadingImage(ModalContent $content): array { $modal = $this->modal($this->card($content)); + return [ $modal, $this->image($modal, $content->badge()), @@ -101,6 +103,7 @@ public function asTitleWithLeadingImage(ModalContent $content): array public function asImage(ModalContent $content, int $size = ilBadgeImage::IMAGE_SIZE_M): array { $modal = $this->modal($this->card($content)); + return [ $modal, $this->image($modal, $content->badge(), $size), @@ -113,6 +116,7 @@ public function asImage(ModalContent $content, int $size = ilBadgeImage::IMAGE_S public function asTitle(ModalContent $content): array { $modal = $this->modal($this->card($content)); + return [ $modal, $this->title($modal, $content->badge()), @@ -139,6 +143,7 @@ private function modal(Card $card): Component private function image(Component $modal, ilBadge $badge, int $size = ilBadgeImage::IMAGE_SIZE_M): Component { $image_src = $this->badge_image_service->getImageFromBadge($badge, $size); + return $this->container ->ui() ->factory() @@ -159,6 +164,7 @@ private function title(Component $modal, ilBadge $badge): Component public function modalContent(ilBadge $badge): ModalContent { $awarded_by = $this->parent->asProperty($badge); + return new ModalContent($badge, [ $this->txt('criteria') => $badge->getCriteria(), ...($awarded_by !== null ? [$this->txt('awarded_by') => $awarded_by] : []), diff --git a/components/ILIAS/Badge/classes/class.ilBadgeImage.php b/components/ILIAS/Badge/classes/class.ilBadgeImage.php index 1a9c845d1d28..0a98dfae5bf1 100644 --- a/components/ILIAS/Badge/classes/class.ilBadgeImage.php +++ b/components/ILIAS/Badge/classes/class.ilBadgeImage.php @@ -21,11 +21,11 @@ namespace ILIAS\Badge; use ilBadge; -use ILIAS\ResourceStorage\Services; use ilBadgeFileStakeholder; +use ilGlobalTemplateInterface; use ILIAS\FileUpload\FileUpload; +use ILIAS\ResourceStorage\Services; use ILIAS\FileUpload\Exception\IllegalStateException; -use ilGlobalTemplateInterface; use ILIAS\ResourceStorage\Identification\ResourceIdentification; class ilBadgeImage @@ -36,7 +36,6 @@ class ilBadgeImage public const IMAGE_SIZE_L = 1; public const IMAGE_SIZE_XL = 0; public const IMAGE_URL_COUNT = 5; - private ?Services $resource_storage; private ?FileUpload $upload_service; private ?ilGlobalTemplateInterface $main_template; @@ -73,7 +72,6 @@ public function getImageFromResourceId( return $this->resource_storage->consume()->src($identification)->getSrc(); } - public function processImageUpload(ilBadge $badge): void { try { diff --git a/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php b/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php index 163d52aa5518..27e92b1cc8b1 100755 --- a/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php +++ b/components/ILIAS/Badge/classes/class.ilBadgeManagementGUI.php @@ -16,12 +16,12 @@ * *********************************************************************/ +use ILIAS\Refinery\Factory; use ILIAS\Badge\ilBadgeImage; -use ILIAS\ResourceStorage\Services; -use ILIAS\FileUpload\Exception\IllegalStateException; use ILIAS\Badge\ilBadgeTableGUI; +use ILIAS\ResourceStorage\Services; use ILIAS\Badge\ilBadgeUserTableGUI; -use ILIAS\Refinery\Factory; +use ILIAS\FileUpload\Exception\IllegalStateException; use ILIAS\ResourceStorage\Identification\ResourceIdentification; /** @@ -43,7 +43,6 @@ class ilBadgeManagementGUI implements ilCtrlSecurityInterface private const string DEFAULT_ACTION = self::LIST_BADGES_ACTION; private const string TABLE_ACTIONS = 'handleTableActions'; public const string TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'; - private ilBadgeGUIRequest $request; private ilBadgeManagementSessionRepository $session_repo; private ilLanguage $lng; @@ -53,13 +52,12 @@ class ilBadgeManagementGUI implements ilCtrlSecurityInterface private ilToolbarGUI $toolbar; private ilGlobalTemplateInterface $tpl; private ilObjUser $user; - private \ILIAS\UI\Factory $ui_factory; + private ILIAS\UI\Factory $ui_factory; private int $parent_obj_id; private string $parent_obj_type; - private ?ilBadgeImage $badge_image_service = null; private ?Services $resource_storage; - private \ILIAS\HTTP\Services $http; + private ILIAS\HTTP\Services $http; private Factory $refinery; public function __construct( @@ -106,7 +104,7 @@ public function __construct( } /** - * @param list $splittable_user_ids + * @param list $splittable_user_ids * @return array{0: list, 1: int} */ private function splitBadgeAndUserIdsFromString(array $splittable_user_ids): array @@ -128,21 +126,20 @@ private function splitBadgeAndUserIdsFromString(array $splittable_user_ids): arr $badge_id = $this->http->wrapper()->query()->retrieve('bid', $this->refinery->kindlyTo()->int()); return [$user_ids, $badge_id]; - } else { - foreach ($splittable_user_ids as $row) { - if (str_contains($row, '_')) { - $split = explode('_', $row); - - if ($badge_id === null && $split[0] !== '') { - $badge_id = (int) $split[0]; - } - - if ($split[1] !== '') { - $user_ids[] = (int) $split[1]; - } - } else { - return [$user_ids, 0]; + } + foreach ($splittable_user_ids as $row) { + if (str_contains($row, '_')) { + $split = explode('_', $row); + + if ($badge_id === null && $split[0] !== '') { + $badge_id = (int) $split[0]; + } + + if ($split[1] !== '') { + $user_ids[] = (int) $split[1]; } + } else { + return [$user_ids, 0]; } } } @@ -176,8 +173,8 @@ public function executeCommand(): void $form = $this->initBadgeForm('create', $type, $type_id); } $this->ctrl->forwardCommand($form); - break; + break; default: $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl(); if (count($badge_ids) === 1) { @@ -186,6 +183,7 @@ public function executeCommand(): void } $this->$cmd(); + break; } } diff --git a/components/ILIAS/Badge/classes/class.ilObjBadgeAdministrationGUI.php b/components/ILIAS/Badge/classes/class.ilObjBadgeAdministrationGUI.php index 8360ff3e90eb..b87a1580d7e6 100755 --- a/components/ILIAS/Badge/classes/class.ilObjBadgeAdministrationGUI.php +++ b/components/ILIAS/Badge/classes/class.ilObjBadgeAdministrationGUI.php @@ -16,10 +16,10 @@ * *********************************************************************/ -use ILIAS\Badge\ilBadgeImageTemplateTableGUI; +use ILIAS\Badge\ilBadgeUserTableGUI; use ILIAS\Badge\ilBadgeTypesTableGUI; use ILIAS\Badge\ilObjectBadgeTableGUI; -use ILIAS\Badge\ilBadgeUserTableGUI; +use ILIAS\Badge\ilBadgeImageTemplateTableGUI; /** * @ilCtrl_Calls ilObjBadgeAdministrationGUI: ilPermissionGUI, ilBadgeManagementGUI @@ -40,7 +40,6 @@ class ilObjBadgeAdministrationGUI extends ilObjectGUI implements ilCtrlSecurityI private const string DEFAULT_ACTION = self::EDIT_SETTINGS_ACTION; private const string TABLE_ACTIONS = 'handleTableActions'; public const string TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'; - private ilRbacSystem $rbacsystem; private ilBadgeGUIRequest $badge_request; private ilTabsGUI $tabs; @@ -83,15 +82,15 @@ public function executeCommand(): void $this->tabs_gui->setTabActive('perm_settings'); $perm_gui = new ilPermissionGUI($this); $this->ctrl->forwardCommand($perm_gui); - break; + break; case strtolower(ilBadgeManagementGUI::class): $this->assertActive(); $this->tabs_gui->setTabActive('activity'); $gui = new ilBadgeManagementGUI($this->ref_id, $this->obj_id, $this->type); $this->ctrl->forwardCommand($gui); - break; + break; default: if ($cmd === '' || $cmd === null || $cmd === 'view' || !method_exists($this, $cmd . 'Cmd')) { $cmd = self::DEFAULT_ACTION; @@ -103,6 +102,7 @@ public function executeCommand(): void } $this->$cmd(); + break; } } @@ -638,7 +638,7 @@ private function toggleObjectBadges(bool $a_status): void { $badge_ids = $this->getObjectBadgesFromMultiAction(); if (current($badge_ids) === self::TABLE_ALL_OBJECTS_ACTION) { - $filter = ['type' => '' , 'title' => '', 'object' => '']; + $filter = ['type' => '', 'title' => '', 'object' => '']; $badge_ids = []; foreach (ilBadge::getObjectInstances($filter) as $badge_item) { $badge_ids[] = $badge_item['id']; diff --git a/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php b/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php index 9ec357c3242c..81ddb7051233 100755 --- a/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php +++ b/components/ILIAS/Badge/classes/class.ilObjectBadgeTableGUI.php @@ -20,37 +20,42 @@ namespace ILIAS\Badge; -use ILIAS\UI\Factory; -use ILIAS\UI\URLBuilder; +use ilStr; +use ilLink; +use ilBadge; +use ilObject; +use Generator; +use ilLanguage; +use ilBadgeHandler; +use ILIAS\Data\URI; +use ilAccessHandler; use ILIAS\Data\Order; use ILIAS\Data\Range; -use ilLanguage; -use ilGlobalTemplateInterface; +use ILIAS\UI\Factory; use ILIAS\UI\Renderer; -use Psr\Http\Message\ServerRequestInterface; use ILIAS\HTTP\Services; -use Psr\Http\Message\RequestInterface; -use ILIAS\UI\Component\Table\DataRowBuilder; -use Generator; -use ILIAS\UI\Component\Table\DataRetrieval; +use ILIAS\UI\URLBuilder; use ILIAS\UI\URLBuilderToken; -use ilBadge; -use ilBadgeHandler; -use ILIAS\Data\URI; -use ILIAS\UI\Implementation\Component\Link\Standard; -use ilObject; -use ilLink; +use ilGlobalTemplateInterface; use ilObjBadgeAdministrationGUI; use ILIAS\Filesystem\Stream\Streams; +use Psr\Http\Message\RequestInterface; +use ILIAS\Badge\Table\TableContentWrapper; use ILIAS\UI\Component\Table\Action\Action; -use ilAccessHandler; use ILIAS\UI\Component\Table\Column\Column; -use ILIAS\Badge\Table\TableContentWrapper; +use ILIAS\UI\Component\Table\DataRetrieval; +use ILIAS\UI\Component\Table\DataRowBuilder; +use Psr\Http\Message\ServerRequestInterface; +use ILIAS\UI\Implementation\Component\Link\Standard; + +use function count; +use function in_array; +use function is_array; +use function array_slice; class ilObjectBadgeTableGUI implements DataRetrieval { private const RECORD_RAW = '__raw__'; - private readonly Factory $factory; private readonly Renderer $renderer; private readonly \ILIAS\Refinery\Factory $refinery; @@ -62,6 +67,7 @@ class ilObjectBadgeTableGUI implements DataRetrieval private readonly ilAccessHandler $access; private readonly \ILIAS\ResourceStorage\Services $irss; private readonly ilBadgeImage $badge_image_service; + /** * @var null|list */ private ?array $cached_records = null; + /** @var array */ private array $has_access_by_parent_cache = []; + /** @var array */ private array $first_ref_id_for_parent_cache = []; @@ -121,12 +129,12 @@ public function getRows( ); usort($records, static function (array $left, array $right) use ($order_field): int { - if (\in_array($order_field, ['container', 'title', 'type'], true)) { - if (\in_array($order_field, ['container', 'title'], true)) { + if (in_array($order_field, ['container', 'title', 'type'], true)) { + if (in_array($order_field, ['container', 'title'], true)) { $order_field .= '_sortable'; } - return \ilStr::strCmp( + return ilStr::strCmp( $left[$order_field], $right[$order_field] ); @@ -145,7 +153,7 @@ public function getRows( } if ($range) { - $records = \array_slice($records, $range->getStart(), $range->getLength()); + $records = array_slice($records, $range->getStart(), $range->getLength()); } $identifications = []; @@ -173,7 +181,7 @@ public function getTotalRowCount( mixed $filter_data, mixed $additional_parameters ): ?int { - return \count($this->getRecords()); + return count($this->getRecords()); } /** @@ -298,7 +306,7 @@ private function enrichRecord( [ 'active' => $badge_item['active'] ? $this->lng->txt('yes') : $this->lng->txt('no'), 'type' => $record['type'], - 'container' => implode(' ', \array_slice($container_title_parts, 1, null, true)), + 'container' => implode(' ', array_slice($container_title_parts, 1, null, true)), ], true ); @@ -413,24 +421,21 @@ private function getActions( $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'), $row_id_token ), - 'obj_badge_deactivate' => - $this->factory->table()->action()->multi( - $this->lng->txt('deactivate'), - $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'), - $row_id_token - ), - 'obj_badge_delete' => - $this->factory->table()->action()->multi( - $this->lng->txt('delete'), - $url_builder->withParameter($action_parameter_token, 'obj_badge_delete'), - $row_id_token - ), - 'obj_badge_show_users' => - $this->factory->table()->action()->single( - $this->lng->txt('user'), - $url_builder->withParameter($action_parameter_token, 'obj_badge_show_users'), - $row_id_token - ) + 'obj_badge_deactivate' => $this->factory->table()->action()->multi( + $this->lng->txt('deactivate'), + $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'), + $row_id_token + ), + 'obj_badge_delete' => $this->factory->table()->action()->multi( + $this->lng->txt('delete'), + $url_builder->withParameter($action_parameter_token, 'obj_badge_delete'), + $row_id_token + ), + 'obj_badge_show_users' => $this->factory->table()->action()->single( + $this->lng->txt('user'), + $url_builder->withParameter($action_parameter_token, 'obj_badge_show_users'), + $row_id_token + ) ] : []; } @@ -464,7 +469,7 @@ public function renderTable(string $url): void if ($action === 'obj_badge_delete') { $items = []; - if (\is_array($ids) && \count($ids) > 0) { + if (is_array($ids) && count($ids) > 0) { if ($ids === ['ALL_OBJECTS']) { $filter = [ 'type' => '', diff --git a/components/ILIAS/Badge/tests/ModalTest.php b/components/ILIAS/Badge/tests/ModalTest.php index 53a38c5b9362..8a4f9ab9c441 100755 --- a/components/ILIAS/Badge/tests/ModalTest.php +++ b/components/ILIAS/Badge/tests/ModalTest.php @@ -20,22 +20,22 @@ namespace ILIAS\Badge\test; +use ilBadge; +use ilLanguage; +use ILIAS\Badge\Modal; use ILIAS\DI\Container; use ILIAS\DI\UIServices; -use ILIAS\Badge\Modal; +use ILIAS\UI\Factory as UI; use ILIAS\Badge\ModalContent; -use ILIAS\UI\Component\Divider\Factory as Divider; -use ILIAS\UI\Component\Divider\Horizontal; -use ILIAS\UI\Component\Image\Factory as ImageFactory; -use ILIAS\UI\Component\Image\Image; -use ILIAS\UI\Component\Item\Factory as ItemFactory; +use PHPUnit\Framework\TestCase; use ILIAS\UI\Component\Item\Group; +use ILIAS\UI\Component\Image\Image; +use ILIAS\UI\Component\Divider\Horizontal; use ILIAS\UI\Component\Item\Standard as Item; +use ILIAS\UI\Component\Divider\Factory as Divider; use ILIAS\UI\Component\Listing\Factory as Listing; -use ILIAS\UI\Factory as UI; -use PHPUnit\Framework\TestCase; -use ilBadge; -use ilLanguage; +use ILIAS\UI\Component\Item\Factory as ItemFactory; +use ILIAS\UI\Component\Image\Factory as ImageFactory; class ModalTest extends TestCase { diff --git a/components/ILIAS/Badge/tests/TileTest.php b/components/ILIAS/Badge/tests/TileTest.php index f87a44cf3b36..8df992170599 100755 --- a/components/ILIAS/Badge/tests/TileTest.php +++ b/components/ILIAS/Badge/tests/TileTest.php @@ -20,21 +20,24 @@ namespace ILIAS\Badge\test; +use ilCtrl; +use ilBadge; +use ilLanguage; +use ILIAS\Badge\Tile; +use RuntimeException; +use ILIAS\Badge\Modal; use ILIAS\DI\Container; use ILIAS\DI\UIServices; use ILIAS\Badge\BadgeParent; -use ILIAS\Badge\Modal; use ILIAS\Badge\ModalContent; -use ILIAS\Badge\Tile; -use ILIAS\UI\Component\Button\Button as ButtonComponent; -use ILIAS\UI\Component\Image\Image as ImageComponent; -use ILIAS\UI\Component\Modal\Modal as ModalComponent; use PHPUnit\Framework\TestCase; -use ilBadge; -use ilCtrl; -use ilLanguage; use ILIAS\ResourceStorage\Services; use PHPUnit\Framework\Attributes\DataProvider; +use ILIAS\UI\Component\Image\Image as ImageComponent; +use ILIAS\UI\Component\Modal\Modal as ModalComponent; +use ILIAS\UI\Component\Button\Button as ButtonComponent; + +use function count; class TileTest extends TestCase { @@ -69,7 +72,7 @@ public function testAs(string $method, array $expected_components): void $container->method('language')->willReturn($language); $container->method('resourceStorage')->willReturn($resource_storage); $format_date = function (int $x): void { - throw new \RuntimeException('Should not be called.'); + throw new RuntimeException('Should not be called.'); }; $badge->method('getImageRid')->willReturn($badge_image_rid_name); $modal_content->method('badge')->willReturn($badge); @@ -78,7 +81,7 @@ public function testAs(string $method, array $expected_components): void $components = $tile->$method($modal_content); - $this->assertCount(\count($expected_components), $components); + $this->assertCount(count($expected_components), $components); array_map($this->assertInstanceOf(...), $expected_components, $components); }