Merge pull request #5728 from christianbeeznest/ofaj-21551

Session: Integrated Asset URL Handling for API Image Display - refs BT#21551
pull/5733/head
christianbeeznest 3 months ago committed by GitHub
commit 779b0661f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      src/CoreBundle/Entity/Listener/SessionListener.php
  2. 15
      src/CoreBundle/Entity/Session.php

@ -7,9 +7,11 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity\Listener;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\AssetRepository;
use Chamilo\CoreBundle\Traits\AccessUrlListenerTrait;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Exception;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RequestStack;
@ -23,7 +25,8 @@ class SessionListener
public function __construct(
protected RequestStack $request,
protected Security $security
protected Security $security,
protected AssetRepository $assetRepository
) {}
/**
@ -46,6 +49,16 @@ class SessionListener
// $this->checkLimit($repo, $url);
}
/**
* This code is executed when a session is loaded from the database.
*/
public function postLoad(Session $session, LifecycleEventArgs $args): void
{
if ($session->getImage()) {
$session->setImageUrl($this->assetRepository->getAssetUrl($session->getImage()));
}
}
/**
* This code is executed when a session is updated.
*/

@ -368,6 +368,9 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
#[ORM\JoinColumn(name: 'image_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
protected ?Asset $image = null;
#[Groups(['user_subscriptions:sessions', 'session:read', 'session:item:read', 'session:basic'])]
private ?string $imageUrl = null;
#[Groups(['user_subscriptions:sessions', 'session:read', 'session:item:read'])]
private int $accessVisibility = 0;
@ -1185,6 +1188,18 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
return null !== $this->image;
}
public function setImageUrl(?string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
/**
* Check if $user is course coach in any course.
*/

Loading…
Cancel
Save