diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index 698831070..0f357a300 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -37,3 +37,7 @@ services: - "%chill_person.validation.birtdate_not_before%" tags: - { name: validator.constraint_validator, alias: birthdate_not_before } + + Chill\PersonBundle\Repository\: + resource: '../src/Repository/' + tags: ['doctrine.repository_service'] diff --git a/src/Bundle/ChillPersonBundle/config/services/repository.yaml b/src/Bundle/ChillPersonBundle/config/services/repository.yaml index e899ba9e1..e5ce06149 100644 --- a/src/Bundle/ChillPersonBundle/config/services/repository.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/repository.yaml @@ -2,24 +2,6 @@ services: chill.person.repository.person: class: Chill\PersonBundle\Repository\PersonRepository - factory: ['@doctrine.orm.entity_manager', getRepository] - arguments: - - 'Chill\PersonBundle\Entity\Person' + autowire: true + autoconfigure: true Chill\PersonBundle\Repository\PersonRepository: '@chill.person.repository.person' - - Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository: - class: Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository - factory: ['@doctrine.orm.entity_manager', getRepository] - arguments: - - 'Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive' - - Chill\PersonBundle\Repository\AccompanyingPeriodRepository: - class: Chill\PersonBundle\Repository\AccompanyingPeriodRepository - tags: [ doctrine.repository_service ] - arguments: - - '@Doctrine\Persistence\ManagerRegistry' - - Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository: - arguments: - - '@Doctrine\Persistence\ManagerRegistry' - tags: [ doctrine.repository_service ] diff --git a/src/Bundle/ChillPersonBundle/src/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/src/Controller/PersonController.php index bfb32654e..abba491b1 100644 --- a/src/Bundle/ChillPersonBundle/src/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/src/Controller/PersonController.php @@ -38,6 +38,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\MainBundle\Search\SearchProvider; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Symfony\Component\Validator\Validator\ValidatorInterface; use Doctrine\ORM\EntityManagerInterface; @@ -290,7 +291,7 @@ final class PersonController extends AbstractController return $errors; } - public function reviewAction(Request $request) + public function reviewAction(Request $request, PersonNotDuplicateRepository $personNotDuplicateRepository) { if ($request->getMethod() !== 'POST') { $r = new Response("You must send something to review the creation of a new Person"); @@ -342,8 +343,7 @@ final class PersonController extends AbstractController $this->em->persist($person); - $alternatePersons = $this->similarPersonMatcher - ->matchPerson($person); + $alternatePersons = $this->similarPersonMatcher->matchPerson($person, $personNotDuplicateRepository); if (count($alternatePersons) === 0) { return $this->forward('ChillPersonBundle:Person:create'); diff --git a/src/Bundle/ChillPersonBundle/src/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/src/Controller/PersonDuplicateController.php index aa2e2768a..90faab336 100644 --- a/src/Bundle/ChillPersonBundle/src/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/src/Controller/PersonDuplicateController.php @@ -19,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\ActivityBundle\Entity\Activity; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\EventBundle\Entity\Participation; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Chill\TaskBundle\Entity\SingleTask; class PersonDuplicateController extends Controller @@ -62,7 +63,7 @@ class PersonDuplicateController extends Controller $this->eventDispatcher = $eventDispatcher; } - public function viewAction($person_id) + public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository) { $person = $this->_getPerson($person_id); if ($person === null) { @@ -76,8 +77,7 @@ class PersonDuplicateController extends Controller $duplicatePersons = $this->similarPersonMatcher-> matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); - $notDuplicatePersons = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [ 'person' => $person, @@ -97,7 +97,7 @@ class PersonDuplicateController extends Controller $person1->counters = $this->_getCounters($person1_id); $person2->counters = $this->_getCounters($person2_id); - + if ($person1 === null) { throw $this->createNotFoundException("Person with id $person1_id not" . " found on this server"); @@ -264,17 +264,17 @@ class PersonDuplicateController extends Controller return [$person1, $person2]; } - + private function _getCounters($id): ?array { $em = $this->getDoctrine()->getManager(); - + $nb_activity = $em->getRepository(Activity::class)->findBy(['person'=>$id]); $nb_document = $em->getRepository(PersonDocument::class)->findBy(['person'=>$id]); $nb_event = $em->getRepository(Participation::class)->findBy(['person'=>$id]); $nb_task = $em->getRepository(SingleTask::class)->countByParameters(['person'=>$id]); $person = $em->getRepository(Person::class)->findOneBy(['id'=>$id]); - + return [ 'nb_activity' => count($nb_activity), 'nb_document' => count($nb_document), diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod.php index 18ee535b8..0565d0547 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod.php @@ -37,43 +37,43 @@ use Chill\MainBundle\Entity\User; /** * AccompanyingPeriod Class * - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriodRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period") */ class AccompanyingPeriod { /** * Mark an accompanying period as "occasional" - * + * * used in INTENSITY */ public const INTENSITY_OCCASIONAL = 'occasional'; - + /** * Mark an accompanying period as "regular" - * + * * used in INTENSITY */ public const INTENSITY_REGULAR = 'regular'; - + public const INTENSITIES = [self::INTENSITY_OCCASIONAL, self::INTENSITY_REGULAR]; - + /** * Mark an accompanying period as "draft". - * - * This means that the accompanying period is not yet + * + * This means that the accompanying period is not yet * confirmed by the creator */ public const STEP_DRAFT = 'DRAFT'; - + /** * Mark an accompanying period as "confirmed". - * - * This means that the accompanying period **is** + * + * This means that the accompanying period **is** * confirmed by the creator */ public const STEP_CONFIRMED = 'CONFIRMED'; - + /** * @var integer * @@ -148,7 +148,7 @@ class AccompanyingPeriod * @ORM\Column(type="string", length=32, nullable=true) */ private $step = self::STEP_DRAFT; - + /** * @ORM\ManyToOne(targetEntity=Origin::class) * @ORM\JoinColumn(nullable=true) diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 6983f6c0e..25fbcc342 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -4,7 +4,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\Result; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\ThirdPartyBundle\Entity\ThirdParty; @@ -13,7 +12,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=AccompanyingPeriodWorkRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_work") */ class AccompanyingPeriodWork diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php index ec371d6c2..955f9e3a1 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php @@ -4,13 +4,12 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\Goal; use Chill\PersonBundle\Entity\SocialWork\Result; -use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkGoalRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=AccompanyingPeriodWorkGoalRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_work_goal") */ class AccompanyingPeriodWorkGoal diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/ClosingMotive.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/ClosingMotive.php index 4e334b2aa..358b28a85 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/ClosingMotive.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/ClosingMotive.php @@ -29,8 +29,7 @@ use Doctrine\Common\Collections\ArrayCollection; /** * ClosingMotive give an explanation why we closed the Accompanying period * - * @ORM\Entity( - * repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_closingmotive") */ class ClosingMotive @@ -50,14 +49,14 @@ class ClosingMotive * @ORM\Column(type="json") */ private $name; - + /** * @var boolean * * @ORM\Column(type="boolean") */ private $active = true; - + /** * @var self * @@ -66,7 +65,7 @@ class ClosingMotive * inversedBy="children") */ private $parent = null; - + /** * Child Accompanying periods * @var Collection @@ -76,15 +75,15 @@ class ClosingMotive * mappedBy="parent") */ private $children; - + /** * @var float * * @ORM\Column(type="float") */ private $ordering = 0.0; - - + + /** * ClosingMotive constructor. */ @@ -92,7 +91,7 @@ class ClosingMotive { $this->children = new ArrayCollection(); } - + /** * Get id * @@ -126,7 +125,7 @@ class ClosingMotive { return $this->name; } - + /** * @return bool */ @@ -134,7 +133,7 @@ class ClosingMotive { return $this->active; } - + /** * @param bool $active * @return $this @@ -142,16 +141,16 @@ class ClosingMotive public function setActive(bool $active) { $this->active = $active; - + if ($this->active === FALSE) { foreach ($this->getChildren() as $child) { $child->setActive(FALSE); } } - + return $this; } - + /** * @return ClosingMotive */ @@ -159,7 +158,7 @@ class ClosingMotive { return $this->parent; } - + /** * @return Collection */ @@ -167,7 +166,7 @@ class ClosingMotive { return $this->children; } - + /** * @param ClosingMotive|null $parent * @return ClosingMotive @@ -175,14 +174,14 @@ class ClosingMotive public function setParent(?ClosingMotive $parent): ClosingMotive { $this->parent = $parent; - + if (NULL !== $parent) { //$parent->addChildren($this); } - + return $this; } - + /** * @param Collection $children * @return ClosingMotive @@ -190,10 +189,10 @@ class ClosingMotive public function setChildren(Collection $children): ClosingMotive { $this->children = $children; - + return $this; } - + /** * @param ClosingMotive $child * @return ClosingMotive @@ -203,13 +202,13 @@ class ClosingMotive if ($this->children->contains($child)) { return $this; } - + $this->children->add($child); $child->setParent($this); - + return $this; } - + /** * @param ClosingMotive $child * @return ClosingMotive @@ -219,10 +218,10 @@ class ClosingMotive if ($this->children->removeElement($child)) { $child->setParent(null); } - + return $this; } - + /** * @return float */ @@ -230,7 +229,7 @@ class ClosingMotive { return $this->ordering; } - + /** * @param float $ordering * @return $this @@ -238,10 +237,10 @@ class ClosingMotive public function setOrdering(float $ordering) { $this->ordering = $ordering; - + return $this; } - + /** * @return bool */ @@ -249,7 +248,7 @@ class ClosingMotive { return $this->parent !== null; } - + /** * @return bool */ @@ -257,7 +256,7 @@ class ClosingMotive { return $this->children->count() > 0; } - + /** * @return bool */ @@ -265,7 +264,7 @@ class ClosingMotive { return $this->children->count() === 0; } - + /** * @return bool */ diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Comment.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Comment.php index e8ecf3248..60b3466cd 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Comment.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Comment.php @@ -22,13 +22,12 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Repository\AccompanyingPeriod\CommentRepository; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=CommentRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_comment") */ class Comment diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Origin.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Origin.php index 42c75efca..9c1c00a7a 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Origin.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Origin.php @@ -22,11 +22,10 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\AccompanyingPeriod\OriginRepository; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=OriginRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_origin") */ class Origin diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Resource.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Resource.php index ec13fcad6..f660b6f51 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Resource.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriod/Resource.php @@ -22,7 +22,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\Person; @@ -30,7 +29,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=ResourceRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_resource") */ class Resource @@ -121,7 +120,7 @@ class Resource return $this; } - + /** * @return Person|ThirdParty */ diff --git a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriodParticipation.php index c22e84e42..b240d16d3 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriodParticipation.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/AccompanyingPeriodParticipation.php @@ -22,7 +22,6 @@ namespace Chill\PersonBundle\Entity; -use Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Doctrine\ORM\Mapping as ORM; @@ -31,7 +30,7 @@ use Doctrine\ORM\Mapping as ORM; * AccompanyingPeriodParticipation Class * * @package Chill\PersonBundle\Entity - * @ORM\Entity(repositoryClass=AccompanyingPeriodParticipationRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_participation") */ class AccompanyingPeriodParticipation @@ -42,83 +41,83 @@ class AccompanyingPeriodParticipation * @ORM\Column(type="integer") */ private $id; - + /** * @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodParticipations") * @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) */ private $person; - + /** * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, inversedBy="participations", cascade={"persist"}) * @ORM\JoinColumn(name="accompanyingperiod_id", referencedColumnName="id", nullable=false) */ private $accompanyingPeriod; - + /** * @ORM\Column(type="date", nullable=false) */ private $startDate; - + /** * @ORM\Column(type="date", nullable=true) */ private $endDate = null; - + public function __construct(AccompanyingPeriod $accompanyingPeriod, Person $person) { $this->startDate = new \DateTimeImmutable('now'); $this->accompanyingPeriod = $accompanyingPeriod; $this->person = $person; } - + public function getId(): ?int { return $this->id; } - + public function getPerson(): ?Person { return $this->person; } - + public function setPerson(?Person $person): self { $this->person = $person; - + return $this; } - + public function getAccompanyingPeriod(): ?AccompanyingPeriod { return $this->accompanyingPeriod; } - + public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self { $this->accompanyingPeriod = $accompanyingPeriod; - + return $this; } - + public function getStartDate(): ?\DateTimeInterface { return $this->startDate; } - + /* * public function setStartDate(\DateTimeInterface $startDate): self { $this->startDate = $startDate; return $this; } */ - + public function getEndDate(): ?\DateTimeInterface { return $this->endDate; } - + public function setEndDate(?\DateTimeInterface $endDate): self { $this->endDate = $endDate; - + return $this; } } diff --git a/src/Bundle/ChillPersonBundle/src/Entity/MaritalStatus.php b/src/Bundle/ChillPersonBundle/src/Entity/MaritalStatus.php index f1addbb2c..dff01af03 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/MaritalStatus.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/MaritalStatus.php @@ -25,7 +25,7 @@ use Doctrine\ORM\Mapping as ORM; /** * MaritalStatus * - * @ORM\Entity() + * @ORM\Entity * @ORM\Table(name="chill_person_marital_status") * @ORM\HasLifecycleCallbacks() */ @@ -48,7 +48,7 @@ class MaritalStatus /** * Get id * - * @return string + * @return string */ public function getId() { @@ -57,7 +57,7 @@ class MaritalStatus /** * Set id - * + * * @param string $id * @return MaritalStatus */ @@ -76,17 +76,17 @@ class MaritalStatus public function setName($name) { $this->name = $name; - + return $this; } /** * Get name * - * @return string array + * @return string array */ public function getName() { return $this->name; - } + } } diff --git a/src/Bundle/ChillPersonBundle/src/Entity/Person.php b/src/Bundle/ChillPersonBundle/src/Entity/Person.php index 94e0a0ee5..10e107b50 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/Person.php @@ -38,7 +38,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Person Class * - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_person", * indexes={@ORM\Index( * name="person_names", @@ -287,7 +287,7 @@ class Person implements HasCenterInterface $this->open(new AccompanyingPeriod($opening)); } - + /** * This private function scan accompanyingPeriodParticipations Collection, * searching for a given AccompanyingPeriod @@ -299,10 +299,10 @@ class Person implements HasCenterInterface if ($accompanyingPeriod === $participation->getAccompanyingPeriod()) { return $participation; }} - + return null; } - + /** * This public function is the same but return only true or false */ @@ -310,7 +310,7 @@ class Person implements HasCenterInterface { return ($this->participationsContainAccompanyingPeriod($accompanyingPeriod)) ? false : true; } - + /** * Add AccompanyingPeriodParticipation * @@ -320,7 +320,7 @@ class Person implements HasCenterInterface { $participation = new AccompanyingPeriodParticipation($accompanyingPeriod, $this); $this->accompanyingPeriodParticipations->add($participation); - + return $this; } @@ -330,7 +330,7 @@ class Person implements HasCenterInterface public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) : void { $participation = $this->participationsContainAccompanyingPeriod($accompanyingPeriod); - + if (! null === $participation) { $participation->setEndDate(\DateTimeImmutable::class); $this->accompanyingPeriodParticipations->removeElement($participation); @@ -408,7 +408,7 @@ class Person implements HasCenterInterface } return $accompanyingPeriods; } - + /** * Get AccompanyingPeriodParticipations Collection */ @@ -1140,12 +1140,12 @@ class Person implements HasCenterInterface return true; } - + public function getFullnameCanonical() : string { return $this->fullnameCanonical; } - + public function setFullnameCanonical($fullnameCanonical) : Person { $this->fullnameCanonical = $fullnameCanonical; diff --git a/src/Bundle/ChillPersonBundle/src/Entity/PersonAltName.php b/src/Bundle/ChillPersonBundle/src/Entity/PersonAltName.php index c5295487e..5cc0fbfff 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/PersonAltName.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/PersonAltName.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; * PersonAltName * * @ORM\Table(name="chill_person_alt_name") - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonAltNameRepository") + * @ORM\Entity */ class PersonAltName { @@ -34,7 +34,7 @@ class PersonAltName * @ORM\Column(name="label", type="text") */ private $label; - + /** * @var Person * @@ -45,7 +45,7 @@ class PersonAltName */ private $person; - + /** * Get id. * @@ -103,7 +103,7 @@ class PersonAltName { return $this->label; } - + /** * @return Person */ @@ -111,7 +111,7 @@ class PersonAltName { return $this->person; } - + /** * @param Person|null $person * @return $this @@ -119,7 +119,7 @@ class PersonAltName public function setPerson(?Person $person = null) { $this->person = $person; - + return $this; } } diff --git a/src/Bundle/ChillPersonBundle/src/Entity/PersonNotDuplicate.php b/src/Bundle/ChillPersonBundle/src/Entity/PersonNotDuplicate.php index ce2a1c26f..9f116c501 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/PersonNotDuplicate.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/PersonNotDuplicate.php @@ -9,7 +9,7 @@ use Chill\MainBundle\Entity\User; * PersonNotDuplicate * * @ORM\Table(name="chill_person_not_duplicate") - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonNotDuplicateRepository") + * @ORM\Entity */ class PersonNotDuplicate { diff --git a/src/Bundle/ChillPersonBundle/src/Entity/PersonPhone.php b/src/Bundle/ChillPersonBundle/src/Entity/PersonPhone.php index 4a2ffaf28..9f19cb2a0 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/PersonPhone.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/PersonPhone.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; /** * Person Phones * - * @ORM\Entity() + * @ORM\Entity * @ORM\Table(name="chill_person_phone") */ class PersonPhone @@ -107,7 +107,7 @@ class PersonPhone { $this->date = $date; } - + public function isEmpty(): bool { return empty($this->getDescription()) && empty($this->getPhonenumber()); diff --git a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Evaluation.php index 9e6dcbaa6..5a877e264 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Evaluation.php @@ -2,11 +2,10 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=EvaluationRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_evaluation") */ class Evaluation diff --git a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Goal.php b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Goal.php index c92e9a736..996fcf3eb 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Goal.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Goal.php @@ -2,13 +2,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\GoalRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=GoalRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_goal") */ class Goal diff --git a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Result.php b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Result.php index be38b1757..37e5c2b18 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Result.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/Result.php @@ -4,13 +4,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; -use Chill\PersonBundle\Repository\SocialWork\ResultRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=ResultRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_result") */ class Result diff --git a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialAction.php index 64413d987..ff7291b45 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialAction.php @@ -2,13 +2,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=SocialActionRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_action") */ class SocialAction diff --git a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialIssue.php index cfec01751..2b6df9be2 100644 --- a/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/src/Entity/SocialWork/SocialIssue.php @@ -1,14 +1,12 @@ repository = $entityManager->getRepository(AccompanyingPeriodWorkGoal::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index f879e97d7..10f5fd5b0 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriodWork|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriodWork[] findAll() * @method AccompanyingPeriodWork[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodWorkRepository extends ServiceEntityRepository +class AccompanyingPeriodWorkRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriodWork::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ClosingMotiveRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ClosingMotiveRepository.php index ef1130b62..3f5fd91a8 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ClosingMotiveRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ClosingMotiveRepository.php @@ -22,6 +22,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; +use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Query\ResultSetMappingBuilder; @@ -32,33 +34,41 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; * * @package Chill\PersonBundle\Repository */ -class ClosingMotiveRepository extends EntityRepository +class ClosingMotiveRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(ClosingMotive::class); + } + /** * @param bool $onlyLeaf * @return mixed */ public function getActiveClosingMotive(bool $onlyLeaf = true) { - $rsm = new ResultSetMappingBuilder($this->getEntityManager()); - $rsm->addRootEntityFromClassMetadata($this->getClassName(), 'cm'); - + $rsm = new ResultSetMappingBuilder($this->repository->getEntityManager()); + $rsm->addRootEntityFromClassMetadata($this->repository->getClassName(), 'cm'); + $sql = "SELECT ".(string) $rsm." FROM chill_person_accompanying_period_closingmotive AS cm WHERE active IS TRUE "; - + if ($onlyLeaf) { $sql .= "AND cm.id NOT IN ( SELECT DISTINCT parent_id FROM chill_person_accompanying_period_closingmotive WHERE parent_id IS NOT NULL )"; } - + $sql .= " ORDER BY cm.ordering ASC"; - - return $this->_em + + return $this + ->repository + ->getEntityManager() ->createNativeQuery($sql, $rsm) - ->getResult() - ; + ->getResult(); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/CommentRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/CommentRepository.php index b41e77591..b06d8a6e8 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/CommentRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/CommentRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Comment|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Comment[] findAll() * @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class CommentRepository extends ServiceEntityRepository +class CommentRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Comment::class); + $this->repository = $entityManager->getRepository(Comment::class); } - } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/OriginRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/OriginRepository.php index 6a5b28901..e63c299c6 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/OriginRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/OriginRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Origin|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Origin[] findAll() * @method Origin[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class OriginRepository extends ServiceEntityRepository +class OriginRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Origin::class); - } + private EntityRepository $repository; + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Origin::class); + } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ResourceRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ResourceRepository.php index 46eaaaaa0..dc99a45f6 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ResourceRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriod/ResourceRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Resource|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Resource[] findAll() * @method Resource[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class ResourceRepository extends ServiceEntityRepository +class ResourceRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Resource::class); - } + private EntityRepository $repository; + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Resource::class); + } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodParticipationRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodParticipationRepository.php index fbe957ecf..adad2f6d1 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodParticipationRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodParticipationRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriodParticipation|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriodParticipation[] findAll() * @method AccompanyingPeriodParticipation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodParticipationRepository extends ServiceEntityRepository +class AccompanyingPeriodParticipationRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriodParticipation::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriodParticipation::class); } - } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodRepository.php index fffb55ede..5bf586cc5 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/AccompanyingPeriodRepository.php @@ -23,9 +23,8 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\Person; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriod|null find($id, $lockMode = null, $lockVersion = null) @@ -33,10 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriod[] findAll() * @method AccompanyingPeriod[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodRepository extends ServiceEntityRepository +class AccompanyingPeriodRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriod::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriod::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/PersonAltNameRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/PersonAltNameRepository.php index 315cee94f..b836d4c32 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/PersonAltNameRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/PersonAltNameRepository.php @@ -2,12 +2,22 @@ namespace Chill\PersonBundle\Repository; +use Chill\PersonBundle\Entity\PersonAltName; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; + /** * PersonAltNameRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ -class PersonAltNameRepository extends \Doctrine\ORM\EntityRepository +class PersonAltNameRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(PersonAltName::class); + } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/PersonNotDuplicateRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/PersonNotDuplicateRepository.php index 8ab711b15..c2253ebbd 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/PersonNotDuplicateRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/PersonNotDuplicateRepository.php @@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonNotDuplicate; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; /** @@ -11,8 +12,15 @@ use Doctrine\ORM\EntityRepository; * * @package Chill\PersonBundle\Repository */ -class PersonNotDuplicateRepository extends EntityRepository +class PersonNotDuplicateRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(PersonNotDuplicate::class); + } + /** * @param \Chill\PersonBundle\Entity\Person $person * @@ -20,7 +28,7 @@ class PersonNotDuplicateRepository extends EntityRepository */ public function findNotDuplicatePerson(Person $person) { - $qb = $this->createQueryBuilder('pnd'); + $qb = $this->repository->createQueryBuilder('pnd'); $qb->select('pnd') ->where('pnd.person1 = :person OR pnd.person2 = :person') ; diff --git a/src/Bundle/ChillPersonBundle/src/Repository/PersonRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/PersonRepository.php index ccc56b639..34e9d42ac 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/PersonRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/PersonRepository.php @@ -18,16 +18,25 @@ namespace Chill\PersonBundle\Repository; +use Chill\PersonBundle\Entity\Person; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; -/** - * Class PersonRepository - * - * @package Chill\PersonBundle\Repository - */ -class PersonRepository extends EntityRepository +final class PersonRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Person::class); + } + + public function find($id, $lockMode = null, $lockVersion = null) + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + /** * @param string $phonenumber * @param $centers @@ -38,25 +47,25 @@ class PersonRepository extends EntityRepository * @throws \Exception */ public function findByPhone( - string $phonenumber, - $centers, + string $phonenumber, + $centers, $firstResult, $maxResults, array $only = ['mobile', 'phone'] ) { - $qb = $this->createQueryBuilder('p'); + $qb = $this->repository->createQueryBuilder('p'); $qb->select('p'); - + $this->addByCenters($qb, $centers); $this->addPhoneNumber($qb, $phonenumber, $only); - + $qb->setFirstResult($firstResult) ->setMaxResults($maxResults) ; - + return $qb->getQuery()->getResult(); } - + /** * @param string $phonenumber * @param $centers @@ -66,20 +75,20 @@ class PersonRepository extends EntityRepository * @throws \Doctrine\ORM\NonUniqueResultException */ public function countByPhone( - string $phonenumber, - $centers, + string $phonenumber, + $centers, array $only = ['mobile', 'phone'] ): int { - $qb = $this->createQueryBuilder('p'); + $qb = $this->repository->createQueryBuilder('p'); $qb->select('COUNT(p)'); - + $this->addByCenters($qb, $centers); $this->addPhoneNumber($qb, $phonenumber, $only); - + return $qb->getQuery()->getSingleScalarResult(); } - + /** * @param QueryBuilder $qb * @param string $phonenumber @@ -91,23 +100,23 @@ class PersonRepository extends EntityRepository if (count($only) === 0) { throw new \Exception("No array field to search"); } - + $phonenumber = $this->parsePhoneNumber($phonenumber); - + $orX = $qb->expr()->orX(); - + if (\in_array('mobile', $only)) { $orX->add($qb->expr()->like("REPLACE(p.mobilenumber, ' ', '')", ':phonenumber')); } if (\in_array('phone', $only)) { $orX->add($qb->expr()->like("REPLACE(p.phonenumber, ' ', '')", ':phonenumber')); } - + $qb->andWhere($orX); - + $qb->setParameter('phonenumber', '%'.$phonenumber.'%'); } - + /** * @param $phonenumber * @return string @@ -116,7 +125,7 @@ class PersonRepository extends EntityRepository { return \str_replace(' ', '', $phonenumber); } - + /** * @param QueryBuilder $qb * @param array $centers diff --git a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/EvaluationRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/EvaluationRepository.php index b030e1617..577d4c64d 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/EvaluationRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/EvaluationRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Evaluation; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Evaluation|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Evaluation[] findAll() * @method Evaluation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class EvaluationRepository extends ServiceEntityRepository +class EvaluationRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Evaluation::class); + $this->repository = $entityManager->getRepository(Evaluation::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/GoalRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/GoalRepository.php index 031c31764..5e5deea54 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/GoalRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/GoalRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Goal; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Goal|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Goal[] findAll() * @method Goal[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class GoalRepository extends ServiceEntityRepository +class GoalRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Goal::class); + $this->repository = $entityManager->getRepository(Goal::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/ResultRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/ResultRepository.php index 511823d61..aea149187 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/ResultRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/ResultRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Result; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Result|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Result[] findAll() * @method Result[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class ResultRepository extends ServiceEntityRepository +class ResultRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Result::class); + $this->repository = $entityManager->getRepository(Result::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialActionRepository.php index f0f2e81b4..e525ee6b7 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialActionRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method SocialAction|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method SocialAction[] findAll() * @method SocialAction[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class SocialActionRepository extends ServiceEntityRepository +class SocialActionRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, SocialAction::class); + $this->repository = $entityManager->getRepository(SocialAction::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialIssueRepository.php b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialIssueRepository.php index e64b057f4..91352af8c 100644 --- a/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialIssueRepository.php +++ b/src/Bundle/ChillPersonBundle/src/Repository/SocialWork/SocialIssueRepository.php @@ -4,7 +4,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method SocialIssue|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +13,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method SocialIssue[] findAll() * @method SocialIssue[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class SocialIssueRepository extends ServiceEntityRepository +class SocialIssueRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, SocialIssue::class); + $this->repository = $entityManager->getRepository(SocialIssue::class); } } diff --git a/src/Bundle/ChillPersonBundle/src/Search/SimilarPersonMatcher.php b/src/Bundle/ChillPersonBundle/src/Search/SimilarPersonMatcher.php index 956f9a4d2..0e1e3da9a 100644 --- a/src/Bundle/ChillPersonBundle/src/Search/SimilarPersonMatcher.php +++ b/src/Bundle/ChillPersonBundle/src/Search/SimilarPersonMatcher.php @@ -22,12 +22,14 @@ use Chill\PersonBundle\Entity\PersonNotDuplicate; use Doctrine\ORM\EntityManagerInterface; use Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; +use Chill\PersonBundle\Repository\PersonRepository; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; /** - * + * * * @author Julien Fastré */ @@ -41,20 +43,20 @@ class SimilarPersonMatcher * @var EntityManagerInterface */ protected $em; - + /** * @var AuthorizationHelper */ protected $authorizationHelper; - + /** - * @var TokenStorageInterface + * @var TokenStorageInterface */ protected $tokenStorage; - + public function __construct( - EntityManagerInterface $em, - AuthorizationHelper $authorizationHelper, + EntityManagerInterface $em, + AuthorizationHelper $authorizationHelper, TokenStorageInterface $tokenStorage ) { $this->em = $em; @@ -62,7 +64,7 @@ class SimilarPersonMatcher $this->tokenStorage = $tokenStorage; } - public function matchPerson(Person $person, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY) + public function matchPerson(Person $person, PersonNotDuplicateRepository $personNotDuplicateRepository, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY) { $centers = $this->authorizationHelper->getReachableCenters( $this->tokenStorage->getToken()->getUser(), @@ -77,8 +79,7 @@ class SimilarPersonMatcher . ' AND p.id != :personId ' ; - $notDuplicatePersons = $this->em->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); if (count($notDuplicatePersons)) { $dql .= ' AND p.id not in (:notDuplicatePersons)'; diff --git a/src/Bundle/ChillPersonBundle/src/Widget/PersonListWidget.php b/src/Bundle/ChillPersonBundle/src/Widget/PersonListWidget.php index e885e0a26..94ea62cd2 100644 --- a/src/Bundle/ChillPersonBundle/src/Widget/PersonListWidget.php +++ b/src/Bundle/ChillPersonBundle/src/Widget/PersonListWidget.php @@ -30,14 +30,15 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Component\Security\Core\Role\Role; use Doctrine\ORM\EntityManager; use Chill\CustomFieldsBundle\Entity\CustomField; +use Chill\PersonBundle\Repository\PersonRepository; use Twig\Environment; /** - * add a widget with person list. - * + * add a widget with person list. + * * The configuration is defined by `PersonListWidgetFactory` - * - * If the options 'custom_fields' is used, the custom fields entity will be + * + * If the options 'custom_fields' is used, the custom fields entity will be * queried from the db and transmitted to the view under the `customFields` variable. */ class PersonListWidget implements WidgetInterface @@ -45,38 +46,38 @@ class PersonListWidget implements WidgetInterface /** * Repository for persons * - * @var EntityRepository + * @var PersonRepository */ protected $personRepository; - + /** * The entity manager * * @var EntityManager */ protected $entityManager; - + /** * the authorization helper - * + * * @var AuthorizationHelper; */ protected $authorizationHelper; - + /** * * @var TokenStorage */ protected $tokenStorage; - + /** * * @var UserInterface */ protected $user; - + public function __construct( - EntityRepository $personRepostory, + PersonRepository $personRepostory, EntityManager $em, AuthorizationHelper $authorizationHelper, TokenStorage $tokenStorage @@ -88,26 +89,26 @@ class PersonListWidget implements WidgetInterface } /** - * + * * @param type $place * @param array $context * @param array $config * @return string */ public function render(Environment $env, $place, array $context, array $config) - { + { $numberOfItems = $config['number_of_items'] ?? 20; - + $qb = $this->personRepository ->createQueryBuilder('person'); - + // show only the person from the authorized centers $and = $qb->expr()->andX(); $centers = $this->authorizationHelper ->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); $and->add($qb->expr()->in('person.center', ':centers')); $qb->setParameter('centers', $centers); - + // add the "only active" query if (\array_key_exists('only_active', $config) && $config['only_active'] === true) { @@ -126,34 +127,34 @@ class PersonListWidget implements WidgetInterface $qb->setParameter('now', new \DateTime(), Type::DATE); } - + if (\array_key_exists('filtering_class', $config) && $config['filtering_class'] !== NULL) { $filteringClass = new $config['filtering_class']; if ( ! $filteringClass instanceof PersonListWidget\PersonFilteringInterface) { throw new \UnexpectedValueException(sprintf("the class %s does not " - . "implements %s", $config['filtering_class'], + . "implements %s", $config['filtering_class'], PersonListWidget\PersonFilteringInterface::class)); } - $ids = $filteringClass->getPersonIds($this->entityManager, + $ids = $filteringClass->getPersonIds($this->entityManager, $this->getUser()); $in = (new Expr())->in('person.id', ':ids'); $and->add($in); $qb->setParameter('ids', $ids); } - + // adding the where clause to the query $qb->where($and); - + // ordering the query by lastname, firstname $qb->addOrderBy('person.lastName', 'ASC') ->addOrderBy('person.firstName', 'ASC'); - - + + $qb->setFirstResult(0)->setMaxResults($numberOfItems); - + $persons = $qb->getQuery()->getResult(); - - // get some custom field when the view is overriden and we want to + + // get some custom field when the view is overriden and we want to // show some custom field in the overriden view. $cfields = array(); if (isset($config['custom_fields'])) { @@ -166,39 +167,39 @@ class PersonListWidget implements WidgetInterface $cfields[$cf->getSlug()] = $cf; } } - } + } return $env->render( 'ChillPersonBundle:Widget:homepage_person_list.html.twig', array( 'persons' => $persons, 'customFields' => $cfields - + ) ); } - + /** - * + * * @return UserInterface * @throws \RuntimeException */ private function getUser() { $token = $this->tokenStorage->getToken(); - + if ($token === null) { throw new \RuntimeException("the token should not be null"); } - + $user = $token->getUser(); - + if (!$user instanceof UserInterface || $user == null) { throw new \RuntimeException("the user should implement UserInterface. " . "Are you logged in ?"); } - + return $user; } -} \ No newline at end of file +}