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

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

Loading…
Cancel
Save