Initial commit
This commit is contained in:
49
src/Repository/RegionRepository.php
Normal file
49
src/Repository/RegionRepository.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Region;
|
||||
use App\Form\RegionType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
/**
|
||||
* @method Region|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method Region|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method Region[] findAll()
|
||||
* @method Region[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class RegionRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Region::class);
|
||||
}
|
||||
|
||||
|
||||
public function getRegions() {
|
||||
$qb=$this->_em->createQueryBuilder();
|
||||
|
||||
$qb->addSelect("region")
|
||||
->addSelect("subRegions")
|
||||
->from(Region::class, "region")
|
||||
->leftJoin("region.subRegions", "subRegions")
|
||||
->andWhere($qb->expr()->isNull("region.parentRegion"))
|
||||
->orderBy("region.sortOrder");
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function getForm(string $route, Region $region): FormInterface {
|
||||
$params=$region->getId() !== null ? array('id'=>$region->getId()) : array();
|
||||
|
||||
return $this->formFactory->create(RegionType::class, $region, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user