From 32701bfe8dcdca980a53a27273ed420e2516a8e5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sat, 26 Oct 2019 16:24:34 +0200 Subject: [PATCH] Remove Managers (avoid double classes), use Resource repositories --- src/CoreBundle/Entity/Tool.php | 4 ++-- .../Repository/ResourceRepository.php | 8 +++++++ .../Authorization/Voter/GroupVoter.php | 11 ++++------ .../CAnnouncementRepository.php} | 8 +++---- .../CGroupInfoRepository.php} | 9 ++++---- .../Resources/config/services.yml | 22 ++++++++++--------- src/GraphQlBundle/Resolver/CourseResolver.php | 4 +--- 7 files changed, 35 insertions(+), 31 deletions(-) rename src/CourseBundle/{Entity/Manager/AnnouncementManager.php => Repository/CAnnouncementRepository.php} (97%) rename src/CourseBundle/{Entity/Manager/GroupManager.php => Repository/CGroupInfoRepository.php} (76%) diff --git a/src/CoreBundle/Entity/Tool.php b/src/CoreBundle/Entity/Tool.php index 2ad653775f..97f678c84d 100644 --- a/src/CoreBundle/Entity/Tool.php +++ b/src/CoreBundle/Entity/Tool.php @@ -72,8 +72,8 @@ class Tool { $this->toolResourceRight = new ArrayCollection(); - foreach ($toolResourceRight as $toolResourceRight) { - $this->addToolResourceRight($toolResourceRight); + foreach ($toolResourceRight as $item) { + $this->addToolResourceRight($item); } } diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index cda96838ec..f43f03fbc4 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -435,4 +435,12 @@ class ResourceRepository extends EntityRepository ->getRepository('ChamiloCoreBundle:Tool') ->findOneBy(['name' => $tool]); } + + /** + * @return mixed + */ + public function create() + { + return new $this->className; + } } diff --git a/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php b/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php index 4ba45a8b8e..d1cb5a72c9 100644 --- a/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php +++ b/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php @@ -3,15 +3,12 @@ namespace Chamilo\CoreBundle\Security\Authorization\Voter; -use Chamilo\CoreBundle\Entity\Manager\CourseManager; use Chamilo\CoreBundle\Repository\CourseRepository; use Chamilo\CourseBundle\Entity\CGroupInfo; -use Chamilo\CourseBundle\Entity\Manager\GroupManager; -use Chamilo\UserBundle\Entity\User; +use Chamilo\CourseBundle\Repository\CGroupInfoRepository; use Doctrine\ORM\EntityManager; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\User\UserInterface; @@ -35,15 +32,15 @@ class GroupVoter extends Voter /** * @param EntityManager $entityManager - * @param CourseManager $courseManager - * @param GroupManager $groupManager + * @param CourseRepository $courseManager + * @param CGroupInfoRepository $groupManager * @param AuthorizationCheckerInterface $authorizationChecker * @param ContainerInterface $container */ public function __construct( EntityManager $entityManager, CourseRepository $courseManager, - GroupManager $groupManager, + CGroupInfoRepository $groupManager, AuthorizationCheckerInterface $authorizationChecker, ContainerInterface $container ) { diff --git a/src/CourseBundle/Entity/Manager/AnnouncementManager.php b/src/CourseBundle/Repository/CAnnouncementRepository.php similarity index 97% rename from src/CourseBundle/Entity/Manager/AnnouncementManager.php rename to src/CourseBundle/Repository/CAnnouncementRepository.php index 87f07e292b..1a994fcf39 100644 --- a/src/CourseBundle/Entity/Manager/AnnouncementManager.php +++ b/src/CourseBundle/Repository/CAnnouncementRepository.php @@ -1,18 +1,18 @@ container->get('chamilo_course.entity.manager.announcement_manager'); + $announcementManager = $this->container->get('Chamilo\CourseBundle\Repository\CAnnouncementRepository'); $announcementsInfo = $announcementManager->getAnnouncements( $this->getCurrentUser(), $tool->getCourse(),