Minor: Format code

pull/5012/head
Angel Fernando Quiroz Campos 12 months ago
parent 175218f570
commit 8d61ed0839
  1. 6
      src/CoreBundle/Controller/ContactCategoryController.php
  2. 6
      src/CoreBundle/Controller/ContactController.php
  3. 61
      src/CoreBundle/Controller/CourseController.php
  4. 19
      src/CoreBundle/Entity/ContactCategory.php
  5. 83
      src/CoreBundle/EventListener/CourseListener.php
  6. 49
      src/CoreBundle/EventSubscriber/AnonymousUserSubscriber.php
  7. 4
      src/CoreBundle/Form/ContactCategoryType.php
  8. 14
      src/CoreBundle/Form/ContactType.php
  9. 3
      src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php
  10. 34
      src/CoreBundle/Migrations/Schema/V200/Version20231110194300.php
  11. 9
      src/CoreBundle/Security/Authorization/Voter/AnonymousVoter.php
  12. 12
      src/CoreBundle/Settings/StylesheetsSettingsSchema.php
  13. 8
      src/CourseBundle/Entity/CCalendarEvent.php

@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\ContactCategory;
@ -23,7 +24,8 @@ class ContactCategoryController extends AbstractController
$contactCategories = $entityManager
->getRepository(ContactCategory::class)
->findAll();
->findAll()
;
return $this->render('@ChamiloCore/ContactCategory/index.html.twig', [
'contact_categories' => $contactCategories,

@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Controller;
use Chamilo\CoreBundle\Form\ContactType;
@ -39,7 +40,8 @@ class ContactController extends AbstractController
->text(
"Sender: {$contactData['email']}\n".
"Message: {$contactData['message']}"
);
)
;
// Send the email
$mailer->send($email);

@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Controller;
use Chamilo\CoreBundle\Entity\Course;
@ -714,6 +714,31 @@ class CourseController extends ToolBaseController
return new JsonResponse($responseData);
}
#[Route('/check-enrollments', name: 'chamilo_core_check_enrollments', methods: ['GET'])]
public function checkEnrollments(EntityManagerInterface $em, SettingsManager $settingsManager): JsonResponse
{
/** @var User|null $user */
$user = $this->getUser();
if (!$user) {
return new JsonResponse(['error' => 'User not found'], Response::HTTP_UNAUTHORIZED);
}
$isEnrolledInCourses = $this->isUserEnrolledInAnyCourse($user, $em);
$isEnrolledInSessions = $this->isUserEnrolledInAnySession($user, $em);
if (!$isEnrolledInCourses && !$isEnrolledInSessions) {
$defaultMenuEntry = $settingsManager->getSetting('platform.default_menu_entry_for_course_or_session');
$isEnrolledInCourses = 'my_courses' === $defaultMenuEntry;
$isEnrolledInSessions = 'my_sessions' === $defaultMenuEntry;
}
return new JsonResponse([
'isEnrolledInCourses' => $isEnrolledInCourses,
'isEnrolledInSessions' => $isEnrolledInSessions,
]);
}
private function autoLaunch(): void
{
$autoLaunchWarning = '';
@ -900,37 +925,13 @@ class CourseController extends ToolBaseController
return $link.'?'.$this->getCourseUrlQuery();
}
#[Route('/check-enrollments', name: 'chamilo_core_check_enrollments', methods: ['GET'])]
public function checkEnrollments(EntityManagerInterface $em, SettingsManager $settingsManager): JsonResponse
{
/** @var User|null $user */
$user = $this->getUser();
if (!$user) {
return new JsonResponse(['error' => 'User not found'], Response::HTTP_UNAUTHORIZED);
}
$isEnrolledInCourses = $this->isUserEnrolledInAnyCourse($user, $em);
$isEnrolledInSessions = $this->isUserEnrolledInAnySession($user, $em);
if (!$isEnrolledInCourses && !$isEnrolledInSessions) {
$defaultMenuEntry = $settingsManager->getSetting('platform.default_menu_entry_for_course_or_session');
$isEnrolledInCourses = 'my_courses' === $defaultMenuEntry;
$isEnrolledInSessions = 'my_sessions' === $defaultMenuEntry;
}
return new JsonResponse([
'isEnrolledInCourses' => $isEnrolledInCourses,
'isEnrolledInSessions' => $isEnrolledInSessions,
]);
}
// Implement the real logic to check course enrollment
private function isUserEnrolledInAnyCourse(User $user, EntityManagerInterface $em): bool
{
$enrollmentCount = $em
->getRepository(CourseRelUser::class)
->count(['user' => $user]);
->count(['user' => $user])
;
return $enrollmentCount > 0;
}
@ -939,9 +940,9 @@ class CourseController extends ToolBaseController
private function isUserEnrolledInAnySession(User $user, EntityManagerInterface $em): bool
{
$enrollmentCount = $em->getRepository(SessionRelUser::class)
->count(['user' => $user]);
->count(['user' => $user])
;
return $enrollmentCount > 0;
}
}

@ -1,29 +1,30 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
#[Entity]
#[Table(name: "contact_form_contact_category")]
#[Table(name: 'contact_form_contact_category')]
class ContactCategory
{
#[Id]
#[GeneratedValue]
#[Column(type: "integer")]
#[Column(type: 'integer')]
private ?int $id = null;
#[Column(type: "string", length: 255)]
#[Column(type: 'string', length: 255)]
private string $name;
#[Column(type: "string", length: 255)]
#[Column(type: 'string', length: 255)]
private string $email;
public function getId(): ?int
@ -39,6 +40,7 @@ class ContactCategory
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
@ -50,6 +52,7 @@ class ContactCategory
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
}

@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\EventListener;
use Chamilo\CoreBundle\Controller\EditorController;
@ -15,7 +15,7 @@ use Chamilo\CoreBundle\Security\Authorization\Voter\GroupVoter;
use Chamilo\CoreBundle\Security\Authorization\Voter\SessionVoter;
use Chamilo\CourseBundle\Controller\CourseControllerInterface;
use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
@ -25,6 +25,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
/**
@ -37,7 +38,9 @@ class CourseListener
public function __construct(
private readonly Environment $twig,
private readonly AuthorizationCheckerInterface $authorizationChecker
private readonly AuthorizationCheckerInterface $authorizationChecker,
private readonly TranslatorInterface $translator,
private readonly EntityManagerInterface $entityManager,
) {
}
@ -46,6 +49,8 @@ class CourseListener
*/
public function onKernelRequest(RequestEvent $event): void
{
global $cidReset;
if (!$event->isMainRequest()) {
// don't do anything if it's not the master request
return;
@ -67,9 +72,13 @@ class CourseListener
return;
}
if (true === $cidReset) {
$this->removeCourseFromSession($request);
return;
}
$sessionHandler = $request->getSession();
$container = $this->container;
$translator = $container->get('translator');
$twig = $this->twig;
$course = null;
@ -79,46 +88,25 @@ class CourseListener
$courseId = (int) $request->get('cid');
$checker = $this->authorizationChecker;
/** @var EntityManager $em */
$em = $container->get('doctrine')->getManager();
//dump("cid value in request: $courseId");
if (!empty($courseId)) {
$course = null;
if ($sessionHandler->has('course')) {
/** @var Course $courseFromSession */
$courseFromSession = $sessionHandler->get('course');
if ($courseId === $courseFromSession->getId()) {
$course = $courseFromSession;
$courseInfo = $sessionHandler->get('_course');
//dump("Course #$courseId loaded from Session ");
}
}
//$course = null; //force loading from database
//if (null === $course) {
$course = $em->getRepository(Course::class)->find($courseId);
if (null === $course) {
throw new NotFoundHttpException($translator->trans('Course does not exist'));
$course = $this->entityManager->find(Course::class, $courseId);
$courseInfo = api_get_course_info($course->getCode());
}
//dump("Course loaded from DB #$courseId");
$courseInfo = api_get_course_info($course->getCode());
//}
/*if (null === $course) {
throw new NotFoundHttpException($translator->trans('Course does not exist'));
}*/
}
global $cidReset;
if (true === $cidReset) {
$this->removeCourseFromSession($request);
return;
}
if (null === $course) {
throw new NotFoundHttpException($this->translator->trans('Course does not exist'));
}
if (null !== $course) {
// Setting variables in the session.
$sessionHandler->set('course', $course);
$sessionHandler->set('_real_cid', $course->getId());
@ -129,32 +117,27 @@ class CourseListener
// Setting variables for the twig templates.
$twig->addGlobal('course', $course);
if (false === $checker->isGranted(CourseVoter::VIEW, $course)) {
throw new AccessDeniedException($this->translator->trans('You\'re not allowed in this course'));
}
// Checking if sid is used.
$sessionId = (int) $request->get('sid');
$session = null;
if (empty($sessionId)) {
$sessionHandler->remove('session_name');
$sessionHandler->remove('sid');
$sessionHandler->remove('session');
// Check if user is allowed to this course
// See CourseVoter.php
//dump("Checkisgranted");
if (false === $checker->isGranted(CourseVoter::VIEW, $course)) {
throw new AccessDeniedException($translator->trans('You\'re not allowed in this course'));
}
} else {
//dump("Load chamilo session from DB");
$session = $em->getRepository(Session::class)->find($sessionId);
$session = $this->entityManager->find(Session::class, $sessionId);
if (null !== $session) {
if (!$session->hasCourse($course)) {
throw new AccessDeniedException($translator->trans('Course is not registered in the Session'));
}
//$course->setCurrentSession($session);
$session->setCurrentCourse($course);
// Check if user is allowed to this course-session
// See SessionVoter.php
if (false === $checker->isGranted(SessionVoter::VIEW, $session)) {
throw new AccessDeniedException($translator->trans('You\'re not allowed in this session'));
throw new AccessDeniedException($this->translator->trans('You\'re not allowed in this session'));
}
$sessionHandler->set('session_name', $session->getName());
$sessionHandler->set('sid', $session->getId());
@ -162,7 +145,7 @@ class CourseListener
$twig->addGlobal('session', $session);
} else {
throw new NotFoundHttpException($translator->trans('Session not found'));
throw new NotFoundHttpException($this->translator->trans('Session not found'));
}
}
@ -173,16 +156,16 @@ class CourseListener
$sessionHandler->remove('gid');
} else {
//dump('Load chamilo group from DB');
$group = $em->getRepository(CGroup::class)->find($groupId);
$group = $this->entityManager->getRepository(CGroup::class)->find($groupId);
if (null === $group) {
throw new NotFoundHttpException($translator->trans('Group not found'));
throw new NotFoundHttpException($this->translator->trans('Group not found'));
}
$group->setParent($course);
if (false === $checker->isGranted(GroupVoter::VIEW, $group)) {
throw new AccessDeniedException($translator->trans('You\'re not allowed in this group'));
throw new AccessDeniedException($this->translator->trans('You\'re not allowed in this group'));
}
$sessionHandler->set('gid', $groupId);
@ -191,11 +174,11 @@ class CourseListener
// Check if user is allowed to this course-group
// See GroupVoter.php
if (false === $checker->isGranted(GroupVoter::VIEW, $group)) {
throw new AccessDeniedException($translator->trans('Unauthorised access to group'));
throw new AccessDeniedException($this->translator->trans('Unauthorised access to group'));
}
$sessionHandler->set('gid', $groupId);
} else {
throw new AccessDeniedException($translator->trans('Group does not exist in course'));
throw new AccessDeniedException($this->translator->trans('Group does not exist in course'));
}*/
}

@ -1,13 +1,15 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\EventSubscriber;
use Chamilo\CoreBundle\Entity\TrackELogin;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Settings\SettingsManager;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@ -17,11 +19,11 @@ use Symfony\Component\Security\Core\Security;
class AnonymousUserSubscriber implements EventSubscriberInterface
{
private const MAX_ANONYMOUS_USERS = 5;
private Security $security;
private EntityManagerInterface $entityManager;
private SessionInterface $session;
private SettingsManager $settingsManager;
private const MAX_ANONYMOUS_USERS = 5;
public function __construct(Security $security, EntityManagerInterface $entityManager, SessionInterface $session, SettingsManager $settingsManager)
{
@ -33,7 +35,7 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
public function onKernelRequest(RequestEvent $event): void
{
if ($this->security->getUser() !== null) {
if (null !== $this->security->getUser()) {
return;
}
@ -41,7 +43,7 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
$userIp = $request->getClientIp();
$anonymousUserId = $this->getOrCreateAnonymousUserId($userIp);
if ($anonymousUserId !== null) {
if (null !== $anonymousUserId) {
$trackLoginRepository = $this->entityManager->getRepository(TrackELogin::class);
// Check if a login record already exists for this user and IP
@ -50,8 +52,9 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
// Record the access if it does not exist
$trackLogin = new TrackELogin();
$trackLogin->setUserIp($userIp)
->setLoginDate(new \DateTime())
->setUser($this->entityManager->getReference(User::class, $anonymousUserId));
->setLoginDate(new DateTime())
->setUser($this->entityManager->getReference(User::class, $anonymousUserId))
;
$this->entityManager->persist($trackLogin);
$this->entityManager->flush();
@ -88,7 +91,15 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
}
}
private function getOrCreateAnonymousUserId(string $userIp): ?int {
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'onKernelRequest',
];
}
private function getOrCreateAnonymousUserId(string $userIp): ?int
{
$userRepository = $this->entityManager->getRepository(User::class);
$trackLoginRepository = $this->entityManager->getRepository(TrackELogin::class);
@ -102,16 +113,17 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
foreach ($anonymousUsers as $user) {
$loginRecord = $trackLoginRepository->findOneBy(['userIp' => $userIp, 'user' => $user]);
if ($loginRecord) {
error_log('Existing login found for user ID: ' . $user->getId());
error_log('Existing login found for user ID: '.$user->getId());
return $user->getId();
}
}
// Delete excess anonymous users
while (count($anonymousUsers) >= $maxAnonymousUsers) {
while (\count($anonymousUsers) >= $maxAnonymousUsers) {
$oldestAnonymousUser = array_shift($anonymousUsers);
if ($oldestAnonymousUser) {
error_log('Deleting oldest anonymous user: ' . $oldestAnonymousUser->getId());
error_log('Deleting oldest anonymous user: '.$oldestAnonymousUser->getId());
$this->entityManager->remove($oldestAnonymousUser);
$this->entityManager->flush();
}
@ -123,25 +135,20 @@ class AnonymousUserSubscriber implements EventSubscriberInterface
->setSkipResourceNode(true)
->setLastname('Joe')
->setFirstname('Anonymous')
->setUsername('anon_' . $uniqueId)
->setUsername('anon_'.$uniqueId)
->setStatus(User::ANONYMOUS)
->setPlainPassword('anon')
->setEmail('anon_' . $uniqueId . '@localhost.local')
->setEmail('anon_'.$uniqueId.'@localhost.local')
->setOfficialCode('anonymous')
->setCreatorId(1)
->addRole('ROLE_ANONYMOUS');
->addRole('ROLE_ANONYMOUS')
;
$this->entityManager->persist($anonymousUser);
$this->entityManager->flush();
error_log('New anonymous user created: ' . $anonymousUser->getId());
return $anonymousUser->getId();
}
error_log('New anonymous user created: '.$anonymousUser->getId());
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'onKernelRequest',
];
return $anonymousUser->getId();
}
}

@ -1,5 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Form;
use Chamilo\CoreBundle\Entity\ContactCategory;

@ -1,22 +1,23 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Form;
use Chamilo\CoreBundle\Entity\ContactCategory;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Chamilo\CoreBundle\Entity\ContactCategory;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactType extends AbstractType
{
@ -81,7 +82,8 @@ class ContactType extends AbstractType
'class' => 'btn btn--primary hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer',
'style' => 'border: none;',
],
]);
])
;
}
public function configureOptions(OptionsResolver $resolver): void

@ -11,7 +11,6 @@ use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use DateTime;
use DateTimeZone;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Exception\ORMException;
use Exception;
@ -83,7 +82,7 @@ class Version20230904173400 extends AbstractMigrationChamilo
if ($subscriptionsEnabled) {
$subscriptionsInfo = $this->getSubscriptions((int) $personalAgenda['id']);
if (count($subscriptionsInfo) > 0) {
if (\count($subscriptionsInfo) > 0) {
$hasSubscriptions = true;
$invitationsOrSubscriptionsInfo = $subscriptionsInfo;

@ -14,7 +14,7 @@ final class Version20231110194300 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return "Copy custom theme folder to assets and update webpack.config";
return 'Copy custom theme folder to assets and update webpack.config';
}
public function up(Schema $schema): void
@ -54,13 +54,12 @@ final class Version20231110194300 extends AbstractMigrationChamilo
'fruity_orange',
'medical',
'simplex',
'tasty_olive'
'tasty_olive',
];
$sourceDir = $rootPath.'/app/Resources/public/css/themes';
$destinationDir = $rootPath.'/assets/css/themes/';
$chamiloDefaultCssPath = $destinationDir . 'chamilo/default.css';
$chamiloDefaultCssPath = $destinationDir.'chamilo/default.css';
if (!file_exists($sourceDir)) {
return;
@ -72,16 +71,16 @@ final class Version20231110194300 extends AbstractMigrationChamilo
foreach ($finder as $folder) {
$folderName = $folder->getRelativePathname();
if (!in_array($folderName, $customThemesFolders, true)) {
if (!\in_array($folderName, $customThemesFolders, true)) {
$sourcePath = $folder->getRealPath();
$destinationPath = $destinationDir . $folderName;
$destinationPath = $destinationDir.$folderName;
if (!file_exists($destinationPath)) {
$this->copyDirectory($sourcePath, $destinationPath);
$newThemes[] = $folderName;
if (file_exists($chamiloDefaultCssPath)) {
$newThemeDefaultCssPath = $destinationPath . '/default.css';
$newThemeDefaultCssPath = $destinationPath.'/default.css';
copy($chamiloDefaultCssPath, $newThemeDefaultCssPath);
}
}
@ -96,11 +95,11 @@ final class Version20231110194300 extends AbstractMigrationChamilo
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
$this->copyDirectory($src . '/' . $file, $dst . '/' . $file);
if (('.' !== $file) && ('..' !== $file)) {
if (is_dir($src.'/'.$file)) {
$this->copyDirectory($src.'/'.$file, $dst.'/'.$file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
copy($src.'/'.$file, $dst.'/'.$file);
}
}
}
@ -109,7 +108,7 @@ final class Version20231110194300 extends AbstractMigrationChamilo
private function updateWebpackConfig(string $rootPath, array $newThemes): void
{
$webpackConfigPath = $rootPath . '/webpack.config.js';
$webpackConfigPath = $rootPath.'/webpack.config.js';
if (!file_exists($webpackConfigPath)) {
return;
@ -117,13 +116,14 @@ final class Version20231110194300 extends AbstractMigrationChamilo
$content = file_get_contents($webpackConfigPath);
$pattern = "/(const themes = \[\n\s*)([^\]]*?)(\s*\];)/s";
$replacement = function($matches) use ($newThemes) {
$pattern = "/(const themes = \\[\n\\s*)([^\\]]*?)(\\s*\\];)/s";
$replacement = function ($matches) use ($newThemes) {
$existingThemesString = rtrim($matches[2], ", \n");
$newThemesString = implode("',\n '", $newThemes);
$formattedNewThemesString = $existingThemesString .
(empty($existingThemesString) ? '' : ",\n '") . $newThemesString . "'";
return $matches[1] . $formattedNewThemesString . $matches[3];
$formattedNewThemesString = $existingThemesString.
(empty($existingThemesString) ? '' : ",\n '").$newThemesString."'";
return $matches[1].$formattedNewThemesString.$matches[3];
};
$newContent = preg_replace_callback($pattern, $replacement, $content);

@ -1,19 +1,20 @@
<?php
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Security\Authorization\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chamilo\CoreBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class AnonymousVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
return $attribute === 'ROLE_ANONYMOUS';
return 'ROLE_ANONYMOUS' === $attribute;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
@ -24,6 +25,6 @@ class AnonymousVoter extends Voter
return false;
}
return $user->getStatus() === User::ANONYMOUS;
return User::ANONYMOUS === $user->getStatus();
}
}

@ -1,16 +1,16 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
declare(strict_types=1);
namespace Chamilo\CoreBundle\Settings;
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Contracts\Service\Attribute\Required;
class StylesheetsSettingsSchema extends AbstractSettingsSchema
@ -30,7 +30,8 @@ class StylesheetsSettingsSchema extends AbstractSettingsSchema
[
'stylesheets' => 'chamilo',
]
);
)
;
$allowedTypes = [
'stylesheets' => ['string'],
];
@ -50,7 +51,7 @@ class StylesheetsSettingsSchema extends AbstractSettingsSchema
private function getThemeChoices(): array
{
$projectDir = $this->parameterBag->get('kernel.project_dir');
$themesDirectory = $projectDir . '/assets/css/themes/';
$themesDirectory = $projectDir.'/assets/css/themes/';
$finder = new Finder();
$choices = [];
@ -66,7 +67,6 @@ class StylesheetsSettingsSchema extends AbstractSettingsSchema
return $choices;
}
private function formatFolderName(string $name): string
{
return ucwords(str_replace('_', ' ', $name));

@ -376,7 +376,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
return $this->invitaionType;
}
public function setInvitaionType(string $invitaionType): CCalendarEvent
public function setInvitaionType(string $invitaionType): self
{
$this->invitaionType = $invitaionType;
@ -388,7 +388,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
return $this->subscriptionVisibility;
}
public function setSubscriptionVisibility(int $subscriptionVisibility): CCalendarEvent
public function setSubscriptionVisibility(int $subscriptionVisibility): self
{
$this->subscriptionVisibility = $subscriptionVisibility;
@ -400,7 +400,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
return $this->subscriptionItemId;
}
public function setSubscriptionItemId(?int $subscriptionItemId): CCalendarEvent
public function setSubscriptionItemId(?int $subscriptionItemId): self
{
$this->subscriptionItemId = $subscriptionItemId;
@ -412,7 +412,7 @@ class CCalendarEvent extends AbstractResource implements ResourceInterface, Stri
return $this->maxAttendees;
}
public function setMaxAttendees(int $maxAttendees): CCalendarEvent
public function setMaxAttendees(int $maxAttendees): self
{
$this->maxAttendees = $maxAttendees;

Loading…
Cancel
Save