102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\MerService;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\ORM\Query\ResultSetMapping;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<MerService>
|
|
* @method MerService|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method MerService|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method MerService[] findAll()
|
|
* @method MerService[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class MerServiceRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, MerService::class);
|
|
}
|
|
|
|
public function add(MerService $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function remove(MerService $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->remove($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * @return MerService[] Returns an array of MerService objects
|
|
// */
|
|
// public function findByExampleField($value): array
|
|
// {
|
|
// return $this->createQueryBuilder('m')
|
|
// ->andWhere('m.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->orderBy('m.id', 'ASC')
|
|
// ->setMaxResults(10)
|
|
// ->getQuery()
|
|
// ->getResult()
|
|
// ;
|
|
// }
|
|
|
|
// public function findOneBySomeField($value): ?MerService
|
|
// {
|
|
// return $this->createQueryBuilder('m')
|
|
// ->andWhere('m.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->getQuery()
|
|
// ->getOneOrNullResult()
|
|
// ;
|
|
// }
|
|
|
|
/*
|
|
* offer_id is in MerDM, a trait used by MerParaDM for example.
|
|
* This field can't be used in MerService, so the idea is to do
|
|
* a partial load, and then refresh() the object to get all the
|
|
* fields.
|
|
*/
|
|
public function findByOfferId(int $offerId)
|
|
{
|
|
// return $this->createQueryBuilder('s')
|
|
// ->andWhere('s.offer_id = :offer_id')
|
|
// ->setParameter('offer_id', $offerId)
|
|
// ->getQuery()
|
|
// ->getResult()
|
|
// ;
|
|
|
|
$rsm = new ResultSetMapping();
|
|
$rsm->addEntityResult($this->getClassName(), 's');
|
|
$rsm->addFieldResult('s', 'id', 'id');
|
|
$rsm->addMetaResult('s', 'discr', 'discr');
|
|
$rsm->setDiscriminatorColumn('s', 'discr');
|
|
|
|
$query = $this->getEntityManager()
|
|
->createNativeQuery('SELECT m.id, m.discr FROM mer_service m WHERE offer_id = :offer_id', $rsm);
|
|
$query->setParameter('offer_id', $offerId);
|
|
|
|
$res = $query->getResult();
|
|
|
|
foreach ($res as $k => $obj) {
|
|
$this->getEntityManager()->refresh($obj);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
}
|