Initial commit
This commit is contained in:
0
src/Repository/.gitignore
vendored
Normal file
0
src/Repository/.gitignore
vendored
Normal file
116
src/Repository/GridRepository.php
Normal file
116
src/Repository/GridRepository.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Grid;
|
||||
use App\Entity\Map;
|
||||
use App\Entity\Region;
|
||||
use App\Form\GridType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use LogicException;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
/**
|
||||
* @method Grid|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method Grid|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method Grid[] findAll()
|
||||
* @method Grid[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class GridRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory,
|
||||
private MapRepository $mapRepository) {
|
||||
parent::__construct($registry, Grid::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, Grid $grid): FormInterface {
|
||||
$params=$grid->getId() !== null ? array('id'=>$grid->getId()) : array();
|
||||
|
||||
return $this->formFactory->create(GridType::class, $grid, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
|
||||
public function getGridForm(string $route, Region $region): FormInterface {
|
||||
return $this->formFactory->create(GridType::class, null, array(
|
||||
'action'=>$this->router->generate($route, array('regionId'=>$region->getId())),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Region $region
|
||||
* @return Grid[]
|
||||
*/
|
||||
public function getGridCells(Region $region): array {
|
||||
$qb=$this->_em->createQueryBuilder();
|
||||
|
||||
$qb->select("grid")
|
||||
->from(Grid::class, "grid")
|
||||
->andWhere($qb->expr()->eq("grid.region", ":param_region"))
|
||||
->orderBy("grid.row")
|
||||
->addOrderBy("grid.col");
|
||||
|
||||
$qb->setParameter('param_region', $region->getId(), Types::INTEGER);
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function buildWorldmap(float $version, array $cells, array $maps, bool $withForm=false): array {
|
||||
$grid=array();
|
||||
|
||||
/** @var Map $map */
|
||||
foreach($maps as $key=>$map) {
|
||||
if(!($map instanceof Map)) {
|
||||
throw new LogicException(sprintf(
|
||||
'Variable passed must be an instance of "%s". "%s" given',
|
||||
Map::class,
|
||||
gettype($map)
|
||||
));
|
||||
}
|
||||
|
||||
$maps["cell_{$map->getGrid()->getId()}"]=array(
|
||||
'map'=>$map,
|
||||
'form'=>$withForm ? $this->mapRepository->getForm('bo_map_edit', $map->getGrid(), $map)->createView() : null
|
||||
);
|
||||
|
||||
unset($maps[$key]);
|
||||
}
|
||||
|
||||
/** @var Grid $cell */
|
||||
foreach($cells as $cell) {
|
||||
if(!($cell instanceof Grid)) {
|
||||
throw new LogicException(sprintf(
|
||||
'Variable passed must be an instance of "%s". "%s" given',
|
||||
Grid::class,
|
||||
gettype($map)
|
||||
));
|
||||
}
|
||||
|
||||
if(!array_key_exists("cell_{$cell->getId()}", $maps)) {
|
||||
$_map=new Map();
|
||||
$_map->setVersion($version);
|
||||
|
||||
$maps["cell_{$cell->getId()}"]=array(
|
||||
'map'=>$_map,
|
||||
'form'=>$withForm ? $this->mapRepository->getForm('bo_map_new', $cell, $_map)->createView() : null
|
||||
);
|
||||
}
|
||||
|
||||
$grid[$cell->getRow()][$cell->getCol()]=array(
|
||||
'id'=>$cell->getId(),
|
||||
'map_data'=>$maps["cell_{$cell->getId()}"],
|
||||
);
|
||||
}
|
||||
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
35
src/Repository/ItemCategoryRepository.php
Normal file
35
src/Repository/ItemCategoryRepository.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ItemCategory;
|
||||
use App\Form\ItemCategoryType;
|
||||
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 ItemCategory|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ItemCategory|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ItemCategory[] findAll()
|
||||
* @method ItemCategory[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ItemCategoryRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, ItemCategory::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, ItemCategory $itemCategory): FormInterface {
|
||||
$params=$itemCategory->getId() !== null ? array('id'=>$itemCategory->getId()) : array();
|
||||
|
||||
return $this->formFactory->create(ItemCategoryType::class, $itemCategory, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
36
src/Repository/ItemRepository.php
Normal file
36
src/Repository/ItemRepository.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Item;
|
||||
use App\Entity\ItemCategory;
|
||||
use App\Form\ItemType;
|
||||
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 Item|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Item|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Item[] findAll()
|
||||
* @method Item[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ItemRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Item::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, ItemCategory $itemCategory, Item $item): FormInterface {
|
||||
$params=$item->getId() !== null ? array('itemCategoryId'=>$itemCategory->getId(), 'id'=>$item->getId()) : array('itemCategoryId'=>$itemCategory->getId());
|
||||
|
||||
return $this->formFactory->create(ItemType::class, $item, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
57
src/Repository/MapRepository.php
Normal file
57
src/Repository/MapRepository.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Grid;
|
||||
use App\Entity\Map;
|
||||
use App\Form\MapType;
|
||||
use App\Kernel;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
/**
|
||||
* @method Map|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method Map|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method Map[] findAll()
|
||||
* @method Map[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class MapRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Map::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, Grid $cell, Map $map): FormInterface {
|
||||
$params=$map->getId() !== null ? array('cellId'=>$cell->getId(), 'id'=>$map->getId()) : array('cellId'=>$cell->getId());
|
||||
|
||||
return $this->formFactory->create(MapType::class, $map, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cells
|
||||
* @param float $version
|
||||
* @return Map[]
|
||||
*/
|
||||
public function getCellsMap(array $cells, float $version=Kernel::GAME_VERSION): array {
|
||||
$qb=$this->_em->createQueryBuilder();
|
||||
|
||||
$qb->select("map")
|
||||
->from(Map::class, "map")
|
||||
->andWhere($qb->expr()->eq("map.version", ":param_version"))
|
||||
->andWhere($qb->expr()->in("map.grid", ":param_in"));
|
||||
|
||||
$qb->setParameter('param_in', $cells)
|
||||
->setParameter("param_version", $version, Types::FLOAT);
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
35
src/Repository/MonsterCategoryRepository.php
Normal file
35
src/Repository/MonsterCategoryRepository.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\MonsterCategory;
|
||||
use App\Form\MonsterCategoryType;
|
||||
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 MonsterCategory|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method MonsterCategory|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method MonsterCategory[] findAll()
|
||||
* @method MonsterCategory[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class MonsterCategoryRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, MonsterCategory::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, MonsterCategory $monsterCategory): FormInterface {
|
||||
$params=$monsterCategory->getId() !== null ? array('id'=>$monsterCategory->getId()) : array();
|
||||
|
||||
return $this->formFactory->create(MonsterCategoryType::class, $monsterCategory, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
36
src/Repository/MonsterRepository.php
Normal file
36
src/Repository/MonsterRepository.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Monster;
|
||||
use App\Entity\MonsterCategory;
|
||||
use App\Form\MonsterType;
|
||||
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 Monster|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method Monster|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method Monster[] findAll()
|
||||
* @method Monster[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class MonsterRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Monster::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, MonsterCategory $monsterCategory, Monster $monster): FormInterface {
|
||||
$params=$monster->getId() !== null ? array('monsterCategoryId'=>$monsterCategory->getId(), 'id'=>$monster->getId()) : array('monsterCategoryId'=>$monsterCategory->getId());
|
||||
|
||||
return $this->formFactory->create(MonsterType::class, $monster, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
77
src/Repository/NodeRepository.php
Normal file
77
src/Repository/NodeRepository.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?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,
|
||||
));
|
||||
}
|
||||
}
|
||||
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,
|
||||
));
|
||||
}
|
||||
}
|
||||
52
src/Repository/UserRepository.php
Normal file
52
src/Repository/UserRepository.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\SecurityType;
|
||||
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;
|
||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
||||
use function get_class;
|
||||
|
||||
/**
|
||||
* @method User|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method User|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method User[] findAll()
|
||||
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to upgrade (rehash) the user's password automatically over time.
|
||||
*/
|
||||
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void {
|
||||
if(!$user instanceof User) {
|
||||
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
|
||||
}
|
||||
|
||||
$user->setPassword($newHashedPassword);
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
public function getForm(string $route, User $user): FormInterface {
|
||||
$params=$user->getId() !== null ? array('id'=>$user->getId(),) : array();
|
||||
|
||||
return $this->formFactory->create(SecurityType::class, $user, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
35
src/Repository/WorldmarkCategoryRepository.php
Normal file
35
src/Repository/WorldmarkCategoryRepository.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\WorldmarkCategory;
|
||||
use App\Form\WorldmarkCategoryType;
|
||||
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 WorldmarkCategory|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method WorldmarkCategory|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method WorldmarkCategory[] findAll()
|
||||
* @method WorldmarkCategory[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class WorldmarkCategoryRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, WorldmarkCategory::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, WorldmarkCategory $worldmarkCategory): FormInterface {
|
||||
$params=$worldmarkCategory->getId() !== null ? array('id'=>$worldmarkCategory->getId()) : array();
|
||||
|
||||
return $this->formFactory->create(WorldmarkCategoryType::class, $worldmarkCategory, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
68
src/Repository/WorldmarkRepository.php
Normal file
68
src/Repository/WorldmarkRepository.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Region;
|
||||
use App\Entity\Worldmark;
|
||||
use App\Entity\WorldmarkCategory;
|
||||
use App\Form\WorldmarkType;
|
||||
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 Worldmark|null find($id, $lockMode=null, $lockVersion=null)
|
||||
* @method Worldmark|null findOneBy(array $criteria, array $orderBy=null)
|
||||
* @method Worldmark[] findAll()
|
||||
* @method Worldmark[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
|
||||
*/
|
||||
class WorldmarkRepository extends ServiceEntityRepository {
|
||||
/**
|
||||
* @param ManagerRegistry $registry
|
||||
* @param RouterInterface $router
|
||||
* @param FormFactoryInterface $formFactory
|
||||
*/
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Worldmark::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Region $region
|
||||
* @param float $version
|
||||
* @return Worldmark[]
|
||||
*/
|
||||
public function getRegionWorldmarks(Region $region, float $version): array {
|
||||
$qb=$this->_em->createQueryBuilder();
|
||||
|
||||
$qb->select("worldmark")
|
||||
->addSelect("category")
|
||||
->from(Worldmark::class, "worldmark")
|
||||
->join("worldmark.regions", "regions")
|
||||
->join("worldmark.category", "category")
|
||||
->andWhere($qb->expr()->eq("regions.id", ":param_regionId"))
|
||||
->andWhere($qb->expr()->lte("worldmark.version", ":param_version"))
|
||||
->orderBy("category.sortOrder")
|
||||
->addOrderBy("worldmark.sortOrder");
|
||||
|
||||
$qb->setParameters(array(
|
||||
'param_regionId'=>$region->getId(),
|
||||
'param_version'=>$version,
|
||||
));
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function getForm(string $route, WorldmarkCategory $worldmarkCategory, Worldmark $worldmark): FormInterface {
|
||||
$params=$worldmark->getId() !== null ? array('worldmarkCategoryId'=>$worldmarkCategory->getId(), 'id'=>$worldmark->getId()) : array('worldmarkCategoryId'=>$worldmarkCategory->getId());
|
||||
|
||||
return $this->formFactory->create(WorldmarkType::class, $worldmark, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user