Minor: Format code

pull/5665/head
Angel Fernando Quiroz Campos 4 months ago
parent 1899d81eef
commit 1cf8c3dad6
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 5
      src/CoreBundle/Controller/PermissionsController.php
  2. 5
      src/CoreBundle/DataFixtures/PermissionFixtures.php
  3. 3
      src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php
  4. 4
      src/CoreBundle/Entity/Permission.php
  5. 11
      src/CoreBundle/Entity/PermissionRelRole.php
  6. 4
      src/CoreBundle/Migrations/Schema/V200/Version20201216122012.php
  7. 7
      src/CoreBundle/Migrations/Schema/V200/Version20240709222700.php
  8. 1
      src/CoreBundle/Repository/PermissionRelRoleRepository.php
  9. 1
      src/CoreBundle/Repository/PermissionRepository.php
  10. 7
      src/CoreBundle/ServiceHelper/PermissionServiceHelper.php

@ -11,6 +11,7 @@ use Chamilo\CoreBundle\Form\PermissionType;
use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository; use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository;
use Chamilo\CoreBundle\Repository\PermissionRepository; use Chamilo\CoreBundle\Repository\PermissionRepository;
use Chamilo\CoreBundle\ServiceHelper\PermissionServiceHelper; use Chamilo\CoreBundle\ServiceHelper\PermissionServiceHelper;
use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -50,7 +51,7 @@ class PermissionsController extends AbstractController
$permRelRole->setRoleCode($role); $permRelRole->setRoleCode($role);
} }
$permRelRole->setChangeable(true); $permRelRole->setChangeable(true);
$permRelRole->setUpdatedAt(new \DateTime()); $permRelRole->setUpdatedAt(new DateTime());
$em->persist($permRelRole); $em->persist($permRelRole);
} else { } else {
if ($permRelRole) { if ($permRelRole) {
@ -79,7 +80,7 @@ class PermissionsController extends AbstractController
return $this->render('@ChamiloCore/Permission/index.html.twig', [ return $this->render('@ChamiloCore/Permission/index.html.twig', [
'permissions' => $permissions, 'permissions' => $permissions,
'forms' => $forms, 'forms' => $forms,
'roles' => $roles 'roles' => $roles,
]); ]);
} }

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\DataFixtures;
use Chamilo\CoreBundle\Entity\Permission; use Chamilo\CoreBundle\Entity\Permission;
use Chamilo\CoreBundle\Entity\PermissionRelRole; use Chamilo\CoreBundle\Entity\PermissionRelRole;
use DateTime;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
@ -40,12 +41,12 @@ class PermissionFixtures extends Fixture implements FixtureGroupInterface
$manager->flush(); $manager->flush();
foreach ($roles as $roleName => $roleCode) { foreach ($roles as $roleName => $roleCode) {
if (in_array($roleCode, $permissionsMapping[$permData['slug']])) { if (\in_array($roleCode, $permissionsMapping[$permData['slug']])) {
$permRelRole = new PermissionRelRole(); $permRelRole = new PermissionRelRole();
$permRelRole->setPermission($permission); $permRelRole->setPermission($permission);
$permRelRole->setRoleCode($roleName); $permRelRole->setRoleCode($roleName);
$permRelRole->setChangeable(true); $permRelRole->setChangeable(true);
$permRelRole->setUpdatedAt(new \DateTime()); $permRelRole->setUpdatedAt(new DateTime());
$manager->persist($permRelRole); $manager->persist($permRelRole);
} }
} }

@ -2135,9 +2135,8 @@ class SettingsCurrentFixtures extends Fixture implements FixtureGroupInterface
[ [
'name' => 'access_to_personal_file_for_all', 'name' => 'access_to_personal_file_for_all',
'title' => 'Access to personal file for all', 'title' => 'Access to personal file for all',
'comment' => "Allows all users to access, view, and manage their personal files within the system.", 'comment' => 'Allows all users to access, view, and manage their personal files within the system.',
], ],
], ],
'language' => [ 'language' => [
[ [

@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping as ORM;
use Stringable; use Stringable;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PermissionRepository::class)] #[ORM\Entity(repositoryClass: PermissionRepository::class)]
#[ORM\Table(name: 'permission')] #[ORM\Table(name: 'permission')]
/** /**
@ -49,6 +48,7 @@ class Permission implements Stringable
public function setTitle(string $title): self public function setTitle(string $title): self
{ {
$this->title = $title; $this->title = $title;
return $this; return $this;
} }
@ -60,6 +60,7 @@ class Permission implements Stringable
public function setSlug(string $slug): self public function setSlug(string $slug): self
{ {
$this->slug = $slug; $this->slug = $slug;
return $this; return $this;
} }
@ -71,6 +72,7 @@ class Permission implements Stringable
public function setDescription(?string $description): self public function setDescription(?string $description): self
{ {
$this->description = $description; $this->description = $description;
return $this; return $this;
} }

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository; use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -36,7 +37,7 @@ class PermissionRelRole
private bool $changeable; private bool $changeable;
#[ORM\Column(type: 'datetime')] #[ORM\Column(type: 'datetime')]
private \DateTime $updatedAt; private DateTime $updatedAt;
public function getId(): ?int public function getId(): ?int
{ {
@ -51,6 +52,7 @@ class PermissionRelRole
public function setPermission(Permission $permission): self public function setPermission(Permission $permission): self
{ {
$this->permission = $permission; $this->permission = $permission;
return $this; return $this;
} }
@ -62,6 +64,7 @@ class PermissionRelRole
public function setRoleCode(string $roleCode): self public function setRoleCode(string $roleCode): self
{ {
$this->roleCode = $roleCode; $this->roleCode = $roleCode;
return $this; return $this;
} }
@ -73,17 +76,19 @@ class PermissionRelRole
public function setChangeable(bool $changeable): self public function setChangeable(bool $changeable): self
{ {
$this->changeable = $changeable; $this->changeable = $changeable;
return $this; return $this;
} }
public function getUpdatedAt(): \DateTime public function getUpdatedAt(): DateTime
{ {
return $this->updatedAt; return $this->updatedAt;
} }
public function setUpdatedAt(\DateTime $updatedAt): self public function setUpdatedAt(DateTime $updatedAt): self
{ {
$this->updatedAt = $updatedAt; $this->updatedAt = $updatedAt;
return $this; return $this;
} }
} }

@ -71,7 +71,7 @@ final class Version20201216122012 extends AbstractMigrationChamilo
$this->entityManager->persist($resource); $this->entityManager->persist($resource);
if ($counter % self::BATCH_SIZE === 0) { if (0 === $counter % self::BATCH_SIZE) {
$this->entityManager->flush(); $this->entityManager->flush();
} }
@ -128,7 +128,7 @@ final class Version20201216122012 extends AbstractMigrationChamilo
; ;
$this->entityManager->persist($rootItem); $this->entityManager->persist($rootItem);
if ($counter % self::BATCH_SIZE === 0) { if (0 === $counter % self::BATCH_SIZE) {
$this->entityManager->flush(); $this->entityManager->flush();
} }

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\DataFixtures\PermissionFixtures;
use Chamilo\CoreBundle\Entity\Permission; use Chamilo\CoreBundle\Entity\Permission;
use Chamilo\CoreBundle\Entity\PermissionRelRole; use Chamilo\CoreBundle\Entity\PermissionRelRole;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use DateTime;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
final class Version20240709222700 extends AbstractMigrationChamilo final class Version20240709222700 extends AbstractMigrationChamilo
@ -42,11 +43,11 @@ final class Version20240709222700 extends AbstractMigrationChamilo
} }
foreach ($roles as $roleName => $roleCode) { foreach ($roles as $roleName => $roleCode) {
if (in_array($roleCode, $permissionsMapping[$permData['slug']])) { if (\in_array($roleCode, $permissionsMapping[$permData['slug']])) {
$permissionRelRoleRepository = $this->entityManager->getRepository(PermissionRelRole::class); $permissionRelRoleRepository = $this->entityManager->getRepository(PermissionRelRole::class);
$existingRelation = $permissionRelRoleRepository->findOneBy([ $existingRelation = $permissionRelRoleRepository->findOneBy([
'permission' => $permission, 'permission' => $permission,
'roleCode' => $roleName 'roleCode' => $roleName,
]); ]);
if ($existingRelation) { if ($existingRelation) {
@ -57,7 +58,7 @@ final class Version20240709222700 extends AbstractMigrationChamilo
$permissionRelRole->setPermission($permission); $permissionRelRole->setPermission($permission);
$permissionRelRole->setRoleCode($roleName); $permissionRelRole->setRoleCode($roleName);
$permissionRelRole->setChangeable(true); $permissionRelRole->setChangeable(true);
$permissionRelRole->setUpdatedAt(new \DateTime()); $permissionRelRole->setUpdatedAt(new DateTime());
$this->entityManager->persist($permissionRelRole); $this->entityManager->persist($permissionRelRole);
$this->entityManager->flush(); $this->entityManager->flush();

@ -19,5 +19,4 @@ class PermissionRelRoleRepository extends ServiceEntityRepository
{ {
parent::__construct($registry, PermissionRelRole::class); parent::__construct($registry, PermissionRelRole::class);
} }
} }

@ -19,5 +19,4 @@ class PermissionRepository extends ServiceEntityRepository
{ {
parent::__construct($registry, Permission::class); parent::__construct($registry, Permission::class);
} }
} }

@ -21,7 +21,7 @@ class PermissionServiceHelper
$roles = $this->parameterBag->get('security.role_hierarchy.roles'); $roles = $this->parameterBag->get('security.role_hierarchy.roles');
return array_filter(array_keys($roles), function ($role) { return array_filter(array_keys($roles), function ($role) {
return !str_starts_with($role, 'ROLE_CURRENT_') && $role !== 'ROLE_ANONYMOUS'; return !str_starts_with($role, 'ROLE_CURRENT_') && 'ROLE_ANONYMOUS' !== $role;
}); });
} }
@ -34,10 +34,11 @@ class PermissionServiceHelper
->andWhere('prr.changeable = :changeable') ->andWhere('prr.changeable = :changeable')
->setParameter('permissionSlug', $permissionSlug) ->setParameter('permissionSlug', $permissionSlug)
->setParameter('roles', $roles) ->setParameter('roles', $roles)
->setParameter('changeable', true); ->setParameter('changeable', true)
;
$results = $queryBuilder->getQuery()->getResult(); $results = $queryBuilder->getQuery()->getResult();
return count($results) > 0; return \count($results) > 0;
} }
} }

Loading…
Cancel
Save