Skip to content

Commit

Permalink
Refactoring class inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
gvollbach committed Dec 7, 2023
1 parent 8be39a9 commit b9d407b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Services/Badge/classes/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
) {
$this->sign_file = Closure::fromCallable($sign_file);
global $DIC;
$this->badge_image = new ilBadgeImage($DIC->resourceStorage());
$this->badge_image = new ilBadgeImage($DIC->resourceStorage(), $DIC->upload());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/Tile.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ 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->resourceStorage());
$this->badge_image = new ilBadgeImage($DIC->resourceStorage(), $DIC->upload());
}

/**
Expand Down
23 changes: 22 additions & 1 deletion Services/Badge/classes/class.ilBadgeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

use ilBadge;
use ILIAS\ResourceStorage\Services;
use ilBadgeFileStakeholder;
use ILIAS\FileUpload\FileUpload;
use ILIAS\FileUpload\Exception\IllegalStateException;

class ilBadgeImage
{
private ?Services $resource_storage = null;
private ?FileUpload $upload_service = null;

public function __construct(Services $resourceStorage)
public function __construct(Services $resourceStorage, FileUpload $uploadService)
{
$this->resource_storage = $resourceStorage;
$this->upload_service = $uploadService;
}

public function getImageFromBadge(ilBadge $badge) : string
Expand All @@ -31,4 +36,20 @@ public function getImageFromResourceId(int $badge_id, ?string $image_rid) : stri
}
return $image_src;
}

/**
* @param ilBadge $badge
* @return void
* @throws IllegalStateException
*/
public function processImageUpload(ilBadge $badge) : void
{
$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();
}
}
29 changes: 12 additions & 17 deletions Services/Badge/classes/class.ilBadgeManagementGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ILIAS\Badge\ilBadgeImage;
use ILIAS\ResourceStorage\Services;
use ILIAS\FileUpload\FileUpload;
use ILIAS\FileUpload\Exception\IllegalStateException;

/**
* Class ilBadgeManagementGUI
Expand Down Expand Up @@ -80,7 +81,7 @@ public function __construct(
);

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

public function executeCommand(): void
Expand Down Expand Up @@ -356,6 +357,10 @@ protected function initBadgeForm(
return $form;
}

/**
* @throws ilCtrlException
* @throws IllegalStateException
*/
protected function saveBadge(): void
{
$ilCtrl = $this->ctrl;
Expand Down Expand Up @@ -396,14 +401,7 @@ protected function saveBadge(): void
$badge->create();

if ($form->getInput('img_mode') === 'up') {
# $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->badge_image->processImageUpload($badge);
} else {
$tmpl = new ilBadgeImageTemplate($form->getInput('tmpl'));
$badge->importImage($tmpl->getImage(), $tmpl->getImagePath());
Expand Down Expand Up @@ -470,6 +468,10 @@ protected function setBadgeFormValues(
}
}

/**
* @throws ilCtrlException
* @throws IllegalStateException
*/
protected function updateBadge(): void
{
$ilCtrl = $this->ctrl;
Expand Down Expand Up @@ -504,14 +506,7 @@ protected function updateBadge(): void
}

$badge->update();

$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->badge_image->processImageUpload($badge);

$this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
$ilCtrl->redirect($this, 'listBadges');
Expand Down
2 changes: 1 addition & 1 deletion Services/Badge/classes/class.ilBadgeTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
$this->tile = new Tile($DIC);
$ilCtrl = $DIC->ctrl();
$lng = $DIC->language();
$this->badge_image = new ilBadgeImage($DIC->resourceStorage());
$this->badge_image = new ilBadgeImage($DIC->resourceStorage(), $DIC->upload());

$this->setId("bdgbdg");
$this->parent_type = ilObject::_lookupType($a_parent_obj_id);
Expand Down

0 comments on commit b9d407b

Please sign in to comment.