Remove Managers (avoid double classes), use Resource repositories

pull/3016/head
Julio Montoya 5 years ago
parent b75c6edda0
commit 32701bfe8d
  1. 4
      src/CoreBundle/Entity/Tool.php
  2. 8
      src/CoreBundle/Repository/ResourceRepository.php
  3. 11
      src/CoreBundle/Security/Authorization/Voter/GroupVoter.php
  4. 8
      src/CourseBundle/Repository/CAnnouncementRepository.php
  5. 9
      src/CourseBundle/Repository/CGroupInfoRepository.php
  6. 22
      src/CourseBundle/Resources/config/services.yml
  7. 4
      src/GraphQlBundle/Resolver/CourseResolver.php

@ -72,8 +72,8 @@ class Tool
{ {
$this->toolResourceRight = new ArrayCollection(); $this->toolResourceRight = new ArrayCollection();
foreach ($toolResourceRight as $toolResourceRight) { foreach ($toolResourceRight as $item) {
$this->addToolResourceRight($toolResourceRight); $this->addToolResourceRight($item);
} }
} }

@ -435,4 +435,12 @@ class ResourceRepository extends EntityRepository
->getRepository('ChamiloCoreBundle:Tool') ->getRepository('ChamiloCoreBundle:Tool')
->findOneBy(['name' => $tool]); ->findOneBy(['name' => $tool]);
} }
/**
* @return mixed
*/
public function create()
{
return new $this->className;
}
} }

@ -3,15 +3,12 @@
namespace Chamilo\CoreBundle\Security\Authorization\Voter; namespace Chamilo\CoreBundle\Security\Authorization\Voter;
use Chamilo\CoreBundle\Entity\Manager\CourseManager;
use Chamilo\CoreBundle\Repository\CourseRepository; use Chamilo\CoreBundle\Repository\CourseRepository;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\Manager\GroupManager; use Chamilo\CourseBundle\Repository\CGroupInfoRepository;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 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\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter; use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
@ -35,15 +32,15 @@ class GroupVoter extends Voter
/** /**
* @param EntityManager $entityManager * @param EntityManager $entityManager
* @param CourseManager $courseManager * @param CourseRepository $courseManager
* @param GroupManager $groupManager * @param CGroupInfoRepository $groupManager
* @param AuthorizationCheckerInterface $authorizationChecker * @param AuthorizationCheckerInterface $authorizationChecker
* @param ContainerInterface $container * @param ContainerInterface $container
*/ */
public function __construct( public function __construct(
EntityManager $entityManager, EntityManager $entityManager,
CourseRepository $courseManager, CourseRepository $courseManager,
GroupManager $groupManager, CGroupInfoRepository $groupManager,
AuthorizationCheckerInterface $authorizationChecker, AuthorizationCheckerInterface $authorizationChecker,
ContainerInterface $container ContainerInterface $container
) { ) {

@ -1,18 +1,18 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity\Manager; namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User; use Chamilo\UserBundle\Entity\User;
use Sonata\Doctrine\Entity\BaseEntityManager;
/** /**
* Class AnnouncementManager. * Class CAnnouncementRepository.
*/ */
class AnnouncementManager extends BaseEntityManager final class CAnnouncementRepository extends ResourceRepository
{ {
/** /**
* @param User $user * @param User $user

@ -1,16 +1,15 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity\Manager; namespace Chamilo\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroupInfo;
use Sonata\Doctrine\Entity\BaseEntityManager;
/** /**
* Class CourseManager. * Class CGroupInfoRepository.
*
*/ */
class GroupManager extends BaseEntityManager final class CGroupInfoRepository extends ResourceRepository
{ {
/** /**
* @return CGroupInfo * @return CGroupInfo

@ -16,28 +16,30 @@ services:
tags: ['doctrine.repository_service'] tags: ['doctrine.repository_service']
# Entity repository as a service # Entity repository as a service
Chamilo\CourseBundle\Repository\CAnnouncementRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CExerciseCategory'
Chamilo\CourseBundle\Repository\CDocumentRepository: Chamilo\CourseBundle\Repository\CDocumentRepository:
arguments: arguments:
$className: 'Chamilo\CourseBundle\Entity\CDocument' $className: 'Chamilo\CourseBundle\Entity\CDocument'
Chamilo\CourseBundle\Repository\CGroupInfoRepository:
arguments:
$className: 'Chamilo\CourseBundle\Entity\CGroupInfo'
Chamilo\CourseBundle\Repository\CQuizRepository: Chamilo\CourseBundle\Repository\CQuizRepository:
arguments: arguments:
$className: 'Chamilo\CourseBundle\Entity\CQuiz' $className: 'Chamilo\CourseBundle\Entity\CQuiz'
Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository: Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository:
arguments: arguments:
$className: 'Chamilo\CourseBundle\Entity\CQuizQuestionCategory' $className: 'Chamilo\CourseBundle\Entity\CQuizQuestionCategory'
Chamilo\CourseBundle\Repository\CExerciseCategoryRepository: Chamilo\CourseBundle\Repository\CExerciseCategoryRepository:
arguments: arguments:
$className: 'Chamilo\CourseBundle\Entity\CExerciseCategory' $className: 'Chamilo\CourseBundle\Entity\CExerciseCategory'
# Managers
chamilo_course.entity.manager.group_manager:
class: 'Chamilo\CourseBundle\Entity\Manager\GroupManager'
arguments: ['Chamilo\CourseBundle\Entity\CGroupInfo', '@doctrine']
chamilo_course.entity.manager.announcement_manager:
class: 'Chamilo\CourseBundle\Entity\Manager\AnnouncementManager'
arguments: ['Chamilo\CourseBundle\Entity\CAnnouncement', '@doctrine']
# Event Listeners # Event Listeners
chamilo_course.listener.course: chamilo_course.listener.course:
class: Chamilo\CourseBundle\EventListener\CourseListener class: Chamilo\CourseBundle\EventListener\CourseListener
@ -74,7 +76,7 @@ services:
arguments: arguments:
- '@doctrine.orm.entity_manager' - '@doctrine.orm.entity_manager'
- '@Chamilo\CoreBundle\Repository\CourseRepository' - '@Chamilo\CoreBundle\Repository\CourseRepository'
- '@chamilo_course.entity.manager.group_manager' - '@Chamilo\CourseBundle\Repository\CGroupInfoRepository'
- '@security.authorization_checker' - '@security.authorization_checker'
- '@service_container' - '@service_container'
public: false public: false

@ -24,8 +24,6 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
/** /**
* Class CourseResolver. * Class CourseResolver.
*
* @package Chamilo\GraphQlBundle\Resolver
*/ */
class CourseResolver implements ContainerAwareInterface class CourseResolver implements ContainerAwareInterface
{ {
@ -167,7 +165,7 @@ class CourseResolver implements ContainerAwareInterface
*/ */
public function getAnnouncements(CTool $tool, \ArrayObject $context): array public function getAnnouncements(CTool $tool, \ArrayObject $context): array
{ {
$announcementManager = $this->container->get('chamilo_course.entity.manager.announcement_manager'); $announcementManager = $this->container->get('Chamilo\CourseBundle\Repository\CAnnouncementRepository');
$announcementsInfo = $announcementManager->getAnnouncements( $announcementsInfo = $announcementManager->getAnnouncements(
$this->getCurrentUser(), $this->getCurrentUser(),
$tool->getCourse(), $tool->getCourse(),

Loading…
Cancel
Save