mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Feature: aggregator for accompanying course by geographical level
This commit is contained in:
@@ -44,7 +44,7 @@ class GeographicalUnit
|
||||
private string $unitRefId;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class)
|
||||
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class, inversedBy="units")
|
||||
*/
|
||||
private ?GeographicalUnitLayer $layer;
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,16 @@ class GeographicalUnitLayer
|
||||
*/
|
||||
private string $refId = '';
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=GeographicalUnit::class, mappedBy="layer")
|
||||
*/
|
||||
private Collection $units;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->units = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
@@ -54,4 +66,20 @@ class GeographicalUnitLayer
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRefId(): string
|
||||
{
|
||||
return $this->refId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getUnits(): Collection
|
||||
{
|
||||
return $this->units;
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use UnexpectedValueException;
|
||||
|
||||
final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLayerRepositoryInterface
|
||||
{
|
||||
private EntityRepository $repository;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->repository = $em->getRepository($this->getClassName());
|
||||
}
|
||||
|
||||
public function find($id): ?GeographicalUnitLayer
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|GeographicalUnitLayer[]
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|GeographicalUnitLayer[]
|
||||
*/
|
||||
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?GeographicalUnitLayer
|
||||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return GeographicalUnitLayer::class;
|
||||
}
|
||||
|
||||
public function findAllHavingUnits(): array
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('l');
|
||||
|
||||
return $qb->where($qb->expr()->gt('SIZE(l.units)', 0))
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
interface GeographicalUnitLayerRepositoryInterface extends ObjectRepository
|
||||
{
|
||||
/**
|
||||
* @return array|GeographicalUnitLayer[]
|
||||
*/
|
||||
public function findAllHavingUnits(): array;
|
||||
}
|
Reference in New Issue
Block a user