Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Dec 7, 2023
1 parent 8b4f119 commit 8be39a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
13 changes: 12 additions & 1 deletion Services/Badge/classes/class.ilBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*
*********************************************************************/

use ILIAS\ResourceStorage\Services;
use ILIAS\ResourceStorage\Identification\ResourceIdentification;

/**
* @author Jörg Lützenkirchen <[email protected]>
*/
Expand All @@ -36,13 +39,16 @@ class ilBadge
protected ?array $config = null;
protected string $criteria = "";

private ?Services $resource_storage = null;

public function __construct(
int $a_id = null
) {
global $DIC;

$this->lng = $DIC->language();
$this->db = $DIC->database();
$this->resource_storage = $DIC->resourceStorage();
if ($a_id) {
$this->read($a_id);
}
Expand Down Expand Up @@ -465,6 +471,8 @@ public function delete(): void

if (file_exists($this->getImagePath())) {
unlink($this->getImagePath());
} else {
$this->resource_storage->manage()->remove($this->getImageRid(), new ilBadgeFileStakeholder());
}

$this->deleteStaticFiles();
Expand Down Expand Up @@ -572,7 +580,10 @@ public static function getExtendedTypeCaption(
: $lng->txt("badge_subtype_manual")) . ")";
}

public function getImageRid() : ?string
/**
* @return string|null|ResourceIdentification
*/
public function getImageRid()
{
return $this->image_rid;
}
Expand Down
24 changes: 17 additions & 7 deletions Services/Badge/classes/class.ilBadgeManagementGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*********************************************************************/

use ILIAS\Badge\ilBadgeImage;
use ILIAS\ResourceStorage\Services;
use ILIAS\FileUpload\FileUpload;

/**
* Class ilBadgeManagementGUI
Expand All @@ -40,6 +42,8 @@ class ilBadgeManagementGUI
private string $parent_obj_type;

private ?ilBadgeImage $badge_image = null;
private ?Services $resource_storage = null;
private ?FileUpload $upload_service = null;

public function __construct(
private readonly int $parent_ref_id,
Expand All @@ -54,7 +58,9 @@ public function __construct(
$this->access = $DIC->access();
$this->toolbar = $DIC->toolbar();
$this->ui_factory = $DIC->ui()->factory();
$this->tpl = $DIC['tpl'];
$this->resource_storage = $DIC->resourceStorage();
$this->upload_service = $DIC->upload();
$this->tpl = $DIC->ui()->mainTemplate();
$this->user = $DIC->user();
$lng = $DIC->language();
$this->parent_obj_id = $a_parent_obj_id
Expand Down Expand Up @@ -391,13 +397,11 @@ protected function saveBadge(): void

if ($form->getInput('img_mode') === 'up') {
# $badge->uploadImage($_FILES['img']);
global $DIC;
$upload_service = $DIC->upload();
$upload_service->process();
$array_result = $upload_service->getResults();
$this->upload_service->process();
$array_result = $this->upload_service->getResults();
$array_result = array_pop($array_result);
$stakeholder = new ilBadgeFileStakeholder();
$identification = $DIC['resource_storage']->manage()->upload($array_result, $stakeholder);
$identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
$badge->setImageRid($identification);
$badge->update();
} else {
Expand Down Expand Up @@ -501,7 +505,13 @@ protected function updateBadge(): void

$badge->update();

$badge->uploadImage($_FILES['img']);
$this->upload_service->process();
$array_result = $this->upload_service->getResults();
$array_result = array_pop($array_result);
$stakeholder = new ilBadgeFileStakeholder();
$identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
$badge->setImageRid($identification);
$badge->update();

$this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
$ilCtrl->redirect($this, 'listBadges');
Expand Down

0 comments on commit 8be39a9

Please sign in to comment.