Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mbecker-databay committed Oct 26, 2023
2 parents aafa21e + 9f062c9 commit 7c7dfd5
Show file tree
Hide file tree
Showing 118 changed files with 2,855 additions and 799 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function executeCommand(): void
switch ($next_class) {
default:
if (in_array($cmd, array("log", "logDetails", "changeStatusObject", "rsvConfirmCancelUser", "rsvCancelUser",
"applyLogFilter", "resetLogFilter", "rsvConfirmCancel", "rsvCancel", "back", "rsvConfirmDelete", "rsvDelete", "confirmResetRun", "resetRun", "displayPostInfo", "deliverPostFile"))) {
"applyLogFilter", "resetLogFilter", "rsvConfirmCancel", "rsvCancel", "back", "rsvConfirmDelete", "rsvDelete", "confirmResetRun", "resetRun", "displayPostInfo", "deliverPostFile", "redirectMailToBooker"))) {
$this->$cmd();
}
}
Expand Down Expand Up @@ -709,4 +709,53 @@ public function deliverPostFile(): void
$this->user->getId()
);
}

public function redirectMailToBooker(): void
{
if (!$this->checkPermissionBool("write")) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
$this->ctrl->redirect($this, 'log');
}

$ids = $this->getLogReservationIds();
if (count($ids) === 0) {
$this->back();
}

$users = [];
if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE) {
foreach ($ids as $idx => $id) {
[$obj_id, $user_id, $from, $to] = explode("_", $id);
$rsv_ids = ilBookingReservation::getCancelDetails($obj_id, $user_id, $from, $to);
$rsv_id = $rsv_ids[0];
$rsv = new ilBookingReservation($rsv_id);
$users[$rsv->getUserId()] = ilObjUser::_lookupLogin($rsv->getUserId());
}
} else {
foreach ($ids as $idx => $rsv_id) {
$rsv = new ilBookingReservation($rsv_id);
$users[$rsv->getUserId()] = ilObjUser::_lookupLogin($rsv->getUserId());
}
}
$logins = implode(",", $users);
// #16530 - see ilObjCourseGUI::createMailSignature
$sig = chr(13) . chr(10) . chr(13) . chr(10) . chr(13) . chr(10);
$sig .= $this->lng->txt('book_mail_permanent_link') . ": ";
$sig .= chr(13) . chr(10);
$sig .= ilLink::_getLink($this->book_request->getRefId());
$sig = rawurlencode(base64_encode($sig));

ilMailFormCall::setRecipients($users);
\ilUtil::redirect(ilMailFormCall::getRedirectTarget(
$this,
"log",
array(),
array(
'type' => 'new',
'rcp_to' => $logins,
ilMailFormCall::SIGNATURE_KEY => $sig
)
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public function __construct(
if ($ilUser->getId() !== ANONYMOUS_USER_ID) {
$this->addMultiCommand('rsvConfirmCancel', $lng->txt('book_set_cancel'));
if ($this->access->checkAccess('write', '', $this->ref_id)) {
$this->addMultiCommand('redirectMailToBooker', $lng->txt('book_mail_to_booker'));
$this->addMultiCommand('rsvConfirmDelete', $lng->txt('delete'));
}
$this->setSelectAllCheckbox('mrsv');
Expand Down Expand Up @@ -729,6 +730,10 @@ protected function fillRow(array $a_set): void

if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
$ilCtrl->setParameter($this->parent_obj, 'reservation_id', $a_set['booking_reservation_id']);
$dd_items[] = $f->button()->shy(
$lng->txt('book_mail_to_booker'),
$ilCtrl->getLinkTarget($this->parent_obj, 'redirectMailToBooker')
);
$dd_items[] = $f->button()->shy(
$lng->txt('delete'),
$ilCtrl->getLinkTarget($this->parent_obj, 'rsvConfirmDelete')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,74 @@
declare(strict_types=1);

use ILIAS\Object\Properties\ObjectTypeSpecificProperties\ilObjectTypeSpecificPropertyProviders;
use ILIAS\Object\Properties\CoreProperties\TileImage\ilObjectTileImageFlavourDefinition;
use ILIAS\UI\Component\Symbol\Icon\Icon;
use ILIAS\UI\Component\Symbol\Icon\Factory as IconFactory;
use ILIAS\UI\Component\Image\Image;
use ILIAS\UI\Component\Image\Factory as ImageFactory;
use ILIAS\ResourceStorage\Services as StorageService;
use ILIAS\ResourceStorage\Flavour\Definition\CropToSquare;
use ILIAS\ResourceStorage\Flavour\Flavour;
use ILIAS\ResourceStorage\Flavour\Definition\FlavourDefinition;
use ILIAS\ResourceStorage\Flavour\Definition\PagesToExtract;

class FileObjectPropertyProviders implements ilObjectTypeSpecificPropertyProviders
{
private bool $persist = true;
private int $max_size = 512;
private FlavourDefinition $crop_definition;
private FlavourDefinition $extract_definition;

public function __construct()
{
$this->crop_definition = new CropToSquare($this->persist, $this->max_size);
$this->extract_definition = new PagesToExtract($this->persist, $this->max_size, 1, true);
$this->crop_definition = new ilObjectTileImageFlavourDefinition();
$this->extract_definition = new FirstPageToTileImageFlavourDefinition();
}

public function getObjectTypeSpecificTileImage(
int $obj_id,
ImageFactory $factory,
StorageService $irss
): ?Image {
if (($flavour_path = $this->getCardImageFallbackPath(
$obj_id,
$irss
)) !== '') {
return $factory->responsive($flavour_path, '');
}

return null;
}

/**
* @description Can be used to take preview flavours as card images
*/
protected function getCardImageFallbackPath(
int $obj_id,
StorageService $irss
): string {
$rid = $irss->manage()->find(ilObjFileAccess::getListGUIData($obj_id)['rid'] ?? '');
if ($rid === null) {
return '';
return null;
}
if ($irss->flavours()->possible($rid, $this->crop_definition)) {
$url = $irss->consume()->flavourUrls(
$irss->flavours()->get(
$rid,
$this->crop_definition
)
)->getURLs(false)->current();
if ($url !== null) {
return $url;
}
$flavour = $irss->flavours()->get($rid, $this->crop_definition);
return $this->getImageFromIRSS($irss, $factory, $flavour);
}
if ($irss->flavours()->possible($rid, $this->extract_definition)) {
$url = $irss->consume()->flavourUrls(
$irss->flavours()->get(
$rid,
$this->extract_definition
)
)->getURLs(false)->current();
if ($url !== null) {
return $url;
}
$flavour = $irss->flavours()->get($rid, $this->extract_definition);
return $this->getImageFromIRSS($irss, $factory, $flavour);
}
return '';

return null;
}

private function getImageFromIRSS(
StorageService $irss,
ImageFactory $factory,
Flavour $flavour
): ?Image {
$urls = $irss->consume()->flavourUrls($flavour)->getURLsAsArray();

if ($urls === []) {
return null;
}

$available_widths = $this->crop_definition->getWidths();
array_pop($available_widths);

$image = $factory->responsive($urls[count($available_widths)], '');
return array_reduce(
$available_widths,
function ($carry, $size) use ($urls) {
$image = $carry['image']->withAdditionalHighResSource($urls[$carry['counter']], $size / 2);
$counter = ++$carry['counter'];
return [
'image' => $image,
'counter' => $counter
];
},
['image' => $image, 'counter' => 0]
)['image'];
}

public function getObjectTypeSpecificCustomIcon(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

use ILIAS\Object\Properties\CoreProperties\TileImage\ilObjectTileImageFlavourDefinition;

class FirstPageToTileImageFlavourDefinition extends ilObjectTileImageFlavourDefinition
{
private const ID = 'b9b2f16325492412304989a9b3e32479e612957582f60ed667af31e7b36e50ed';

public function getId(): string
{
return self::ID;
}

public function getFlavourMachineId(): string
{
return FirstPageToTileImageMachine::ID;
}

public function getInternalName(): string
{
return 'first_page_tile_image';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

use ILIAS\Object\Properties\CoreProperties\TileImage\ilObjectTileImageFlavourDefinition;
use ILIAS\Filesystem\Stream\FileStream;
use ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\CropRectangle;
use ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\ExtractPages;
use ILIAS\ResourceStorage\Flavour\Definition\FlavourDefinition;
use ILIAS\ResourceStorage\Flavour\Definition\CropToRectangle;
use ILIAS\ResourceStorage\Flavour\Definition\PagesToExtract;
use ILIAS\ResourceStorage\Flavour\Machine\FlavourMachine;
use ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\AbstractMachine;
use ILIAS\ResourceStorage\Flavour\Machine\Result;
use ILIAS\ResourceStorage\Information\FileInformation;
use ILIAS\ResourceStorage\Flavour\Engine\ImagickEngine;

/**
* @author Thibeau Fuhrer <[email protected]>
* @noinspection AutoloadingIssuesInspection
*/
class FirstPageToTileImageMachine extends AbstractMachine implements FlavourMachine
{
public const ID = "be03e07e396a61f7d9b31a712f0913fe9c6cd43b009ce69d30aa0f10bd3500bd";
private const FULL_QUALITY_SIZE_THRESHOLD = 100;
private ExtractPages $extract_pages;
private CropRectangle $crop;
private ?ilObjectTileImageFlavourDefinition $definition = null;
private ?FileInformation $information = null;

public function __construct()
{
$this->extract_pages = new ExtractPages();
$this->crop = new CropRectangle();
}


public function getId(): string
{
return self::ID;
}

public function canHandleDefinition(FlavourDefinition $definition): bool
{
return $definition instanceof ilObjectTileImageFlavourDefinition;
}

public function dependsOnEngine(): ?string
{
return ImagickEngine::class;
}

public function processStream(
FileInformation $information,
FileStream $stream,
FlavourDefinition $for_definition
): \Generator {
$this->definition = $for_definition;
$this->information = $information;

$page_stream = $this->extract_pages->processStream(
$this->information,
$stream,
new PagesToExtract(
false,
$this->definition->getWidths()['xl'],
1,
false,
100
)
)->current()?->getStream();

if ($page_stream === null) {
return;
}

$i = 0;
foreach ($for_definition->getWidths() as $width) {
yield new Result(
$for_definition,
$this->cropImage($page_stream, $width),
$i,
true
);
$i++;
}
}

protected function cropImage(
FileStream $stream,
int $width
) {
$quality = $width <= self::FULL_QUALITY_SIZE_THRESHOLD
? 100 // we take 100% jpeg quality for small resultions
: $this->definition->getQuality();


return $this->crop->processStream(
$this->information,
$stream,
new CropToRectangle(
false,
$width,
$this->definition->getRatio(),
$quality
)
)->current()->getStream();
}
}
Loading

0 comments on commit 7c7dfd5

Please sign in to comment.