Use EntityManagerInterface.

This commit is contained in:
Pol Dellaiera 2021-05-06 12:34:16 +02:00
parent 7f602ffa47
commit c5940c1263
2 changed files with 18 additions and 14 deletions

View File

@ -27,6 +27,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\Form\Type\Select2ChoiceType;
use Doctrine\ORM\EntityManagerInterface;
/**
* A type to select the marital status
@ -38,10 +39,12 @@ class Select2MaritalStatusType extends AbstractType
/** @var RequestStack */
private $requestStack;
/** @var ObjectManager */
/**
* @var EntityManagerInterface
*/
private $em;
public function __construct(RequestStack $requestStack,ObjectManager $em)
public function __construct(RequestStack $requestStack, EntityManagerInterface $em)
{
$this->requestStack = $requestStack;
$this->em = $em;

View File

@ -21,10 +21,11 @@ namespace Chill\PersonBundle\Timeline;
use Chill\MainBundle\Timeline\TimelineProviderInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
/**
* Provide method to build timeline for accompanying periods
*
*
* This class is resued by TimelineAccompanyingPeriodOpening (for opening)
* and TimelineAccompanyingPeriodClosing (for closing)
*
@ -34,17 +35,17 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
{
/**
*
* @var EntityManager
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManager $em)
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
*
*
* {@inheritDoc}
*/
public function getEntities(array $ids)
@ -52,19 +53,19 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
$periods = $this->em
->getRepository('ChillPersonBundle:AccompanyingPeriod')
->findBy(array('id' => $ids));
//set results in an associative array with id as indexes
$results = array();
foreach($periods as $period) {
$results[$period->getId()] = $period;
}
return $results;
}
/**
* prepare fetchQuery without `WHERE` and `TYPE` clause
*
*
* @param string $context
* @param array $args
* @return array
@ -76,15 +77,15 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
throw new \LogicException('TimelineAccompanyingPeriod is not able '
. 'to render context '.$context);
}
$metadata = $this->em
->getClassMetadata('ChillPersonBundle:AccompanyingPeriod')
;
return array(
'id' => $metadata->getColumnName('id'),
'FROM' => $metadata->getTableName(),
'WHERE' => sprintf('%s = %d',
'WHERE' => sprintf('%s = %d',
$metadata
->getAssociationMapping('person')['joinColumns'][0]['name'],
$args['person']->getId())
@ -93,7 +94,7 @@ abstract class AbstractTimelineAccompanyingPeriod implements TimelineProviderInt
/**
* return the expected response for TimelineProviderInterface::getEntityTemplate
*
*
* @param string $template the template for rendering
* @param mixed $entity
* @param string $context