78 lines
2.6 KiB
PHP
78 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Grid;
|
|
use App\Entity\Node;
|
|
use App\Entity\Worldmark;
|
|
use App\Form\NodeType;
|
|
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 Node|null find($id, $lockMode=null, $lockVersion=null)
|
|
* @method Node|null findOneBy(array $criteria, array $orderBy=null)
|
|
* @method Node[] findAll()
|
|
* @method Node[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
|
*/
|
|
class NodeRepository extends ServiceEntityRepository {
|
|
private RouterInterface $router;
|
|
private FormFactoryInterface $formFactory;
|
|
|
|
public function __construct(ManagerRegistry $registry, RouterInterface $router, FormFactoryInterface $formFactory) {
|
|
parent::__construct($registry, Node::class);
|
|
$this->router=$router;
|
|
$this->formFactory=$formFactory;
|
|
}
|
|
|
|
/**
|
|
* @param Grid[] $grid
|
|
* @param Worldmark[] $worldmarks
|
|
* @param float $version
|
|
* @param bool $includeDeleted
|
|
* @return Node[]
|
|
*/
|
|
public function getGridNodes(array $grid, array $worldmarks, float $version, bool $includeDeleted = false): array {
|
|
$qb=$this->_em->createQueryBuilder();
|
|
|
|
$qb->select("node")
|
|
->from(Node::class, "node")
|
|
->andWhere($qb->expr()->in("node.grid", ":param_inGridId"))
|
|
->andWhere($qb->expr()->in("node.worldmark", ":param_inWorldmarkId"))
|
|
->andWhere($qb->expr()->lte("node.version", ":param_version"))
|
|
->orderBy("node.grid");
|
|
|
|
$qb->setParameters(array(
|
|
'param_inGridId' => $grid,
|
|
'param_inWorldmarkId' => $worldmarks,
|
|
'param_version' => $version,
|
|
));
|
|
|
|
if(!$includeDeleted) {
|
|
$qb->andWhere($qb->expr()->eq("node.isDeleted", 0));
|
|
}
|
|
|
|
return $qb->getQuery()->getResult();
|
|
}
|
|
|
|
public function getForm(string $route, Grid $grid, Worldmark $worldmark, Node $node): FormInterface {
|
|
$params=$node->getId() !== null ? array(
|
|
'gridId'=>$grid->getId(),
|
|
'worldmarkId'=>$worldmark->getId(),
|
|
'id'=>$node->getId(),
|
|
) : array(
|
|
'gridId'=>$grid->getId(),
|
|
'worldmarkId'=>$worldmark->getId(),
|
|
);
|
|
|
|
return $this->formFactory->create(NodeType::class, $node, array(
|
|
'action'=>$this->router->generate($route, $params),
|
|
'method'=>'post',
|
|
'data_route'=>$route,
|
|
));
|
|
}
|
|
}
|