Minor: Format code and fix types - refs BT#20903

pull/5402/head
Angel Fernando Quiroz Campos 7 months ago
parent 8e7c06395a
commit d6699a3203
  1. 6
      src/CoreBundle/Entity/Session.php
  2. 4
      src/CoreBundle/Repository/Node/CourseRepository.php
  3. 4
      src/CoreBundle/Repository/SessionRepository.php
  4. 42
      src/CoreBundle/State/CalendarEventStateProvider.php

@ -430,6 +430,9 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
return false;
}
/**
* @return Collection<int, SessionRelCourse>
*/
public function getCourses(): Collection
{
return $this->courses;
@ -578,6 +581,9 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
return false;
}
/**
* @return Collection<int, SessionRelCourseRelUser>
*/
public function getSessionRelCourseByUser(User $user, ?int $status = null): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('user', $user));

@ -59,9 +59,9 @@ class CourseRepository extends ResourceRepository
/**
* Get course user relationship based in the course_rel_user table.
*
* @return CourseRelUser[]
* @return array<int, CourseRelUser>
*/
public function getCoursesByUser(User $user, AccessUrl $url)
public function getCoursesByUser(User $user, AccessUrl $url): array
{
$qb = $this->getEntityManager()->createQueryBuilder();

@ -63,9 +63,9 @@ class SessionRepository extends ServiceEntityRepository
}
/**
* @return Session[]
* @return array<int, Session>
*/
public function getSessionsByUser(User $user, AccessUrl $url)
public function getSessionsByUser(User $user, AccessUrl $url): array
{
$qb = $this->createQueryBuilder('s');
$qb

@ -10,15 +10,17 @@ use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use Chamilo\CoreBundle\ApiResource\CalendarEvent;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @template-implements ProviderInterface<CalendarEvent[]>
* @template-implements ProviderInterface<CCalendarEvent|Session>
*/
final class CalendarEventStateProvider implements ProviderInterface
{
@ -31,39 +33,39 @@ final class CalendarEventStateProvider implements ProviderInterface
private readonly SettingsManager $settingsManager,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
{
/** @var User|null $user */
$user = $this->security->getUser();
$accessUrl = $this->accessUrlService->getCurrent();
if ($operation instanceof CollectionOperationInterface) {
$cCalendarEvents = $this->collectionProvider->provide($operation, $uriVariables, $context);
$userSessions = [];
/** @var array<CCalendarEvent> $cCalendarEvents */
$cCalendarEvents = $this->collectionProvider->provide($operation, $uriVariables, $context);
$userSessions = [];
$request = $this->requestStack->getMainRequest();
$courseId = $request->query->getInt('cid');
$sessionId = $request->query->getInt('sid');
$request = $this->requestStack->getMainRequest();
$courseId = $request->query->getInt('cid');
$sessionId = $request->query->getInt('sid');
$inCourseBase = !empty($courseId);
$inSession = !empty($sessionId);
$inCourseSession = $inCourseBase && $inSession;
$inCourseBase = !empty($courseId);
$inSession = !empty($sessionId);
$inCourseSession = $inCourseBase && $inSession;
$inPersonalAgenda = !$inCourseBase && !$inCourseSession;
$inPersonalAgenda = !$inCourseBase && !$inCourseSession;
if ($inPersonalAgenda
&& 'true' === $this->settingsManager->getSetting('agenda.personal_calendar_show_sessions_occupation')
) {
$userSessions = $this->getSessionList($user, $accessUrl, $context);
}
return array_merge($cCalendarEvents, $userSessions);
if ($inPersonalAgenda
&& 'true' === $this->settingsManager->getSetting('agenda.personal_calendar_show_sessions_occupation')
) {
$userSessions = $this->getSessionList($user, $accessUrl, $context);
}
return null;
return array_merge($cCalendarEvents, $userSessions);
}
/**
* @return array<Session>
*/
private function getSessionList(User $user, AccessUrl $accessUrl, array $context = []): array
{
$qb = $this->sessionRepository->getUserFollowedSessionsInAccessUrl($user, $accessUrl);

Loading…
Cancel
Save