mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-21 06:30:10 -07:00
Remove Manager classes, Use repositories
This commit is contained in:
parent
6042c05cb0
commit
9319b737c5
@ -1,32 +1 @@
|
||||
services:
|
||||
local.manager.base:
|
||||
abstract: true
|
||||
class: AppBundle\Manager\BaseManager
|
||||
calls:
|
||||
- [setEntityManager, ['@doctrine.orm.entity_manager']]
|
||||
|
||||
local.manager.rebrickable:
|
||||
class: AppBundle\Manager\RebrickableManager
|
||||
parent: local.manager.base
|
||||
|
||||
manager.ldraw.keyword:
|
||||
class: AppBundle\Manager\LDraw\KeywordManager
|
||||
arguments:
|
||||
- "@repository.ldraw.keyword"
|
||||
manager.ldraw.category:
|
||||
class: AppBundle\Manager\LDraw\CategoryManager
|
||||
arguments:
|
||||
- "@repository.ldraw.category"
|
||||
manager.ldraw.subpart:
|
||||
class: AppBundle\Manager\LDraw\SubpartManager
|
||||
arguments:
|
||||
- "@repository.ldraw.subpart"
|
||||
manager.ldraw.model:
|
||||
class: AppBundle\Manager\LDraw\ModelManager
|
||||
arguments:
|
||||
- "@repository.ldraw.model"
|
||||
manager.ldraw.alias:
|
||||
class: AppBundle\Manager\LDraw\AliasManager
|
||||
arguments:
|
||||
- "@repository.ldraw.alias"
|
||||
|
||||
services:
|
@ -1,13 +1,4 @@
|
||||
services:
|
||||
manager.ldraw:
|
||||
class: AppBundle\Manager\LDrawManager
|
||||
arguments:
|
||||
- '@manager.ldraw.category'
|
||||
- '@manager.ldraw.keyword'
|
||||
- '@manager.ldraw.subpart'
|
||||
- '@manager.ldraw.model'
|
||||
- '@manager.ldraw.alias'
|
||||
|
||||
app.twig_extension:
|
||||
class: AppBundle\Twig\AppExtension
|
||||
public: false
|
||||
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager;
|
||||
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
class BaseManager
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
protected $em;
|
||||
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @return BaseRepository
|
||||
*/
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
public function setEntityManager(EntityManager $entityManager)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\AliasRepository;
|
||||
|
||||
class AliasManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* AliasManager constructor.
|
||||
*
|
||||
* @param AliasRepository $repository
|
||||
*/
|
||||
public function __construct(AliasRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Alias entity.
|
||||
*
|
||||
* @param $number
|
||||
* @param Model $model
|
||||
*
|
||||
* @return Alias
|
||||
*/
|
||||
public function create($number, $model)
|
||||
{
|
||||
if (($alias = $this->repository->findOneBy(['number' => $number, 'model' => $model])) == null) {
|
||||
$alias = new Alias();
|
||||
$alias->setModel($model);
|
||||
$alias->setNumber($number);
|
||||
}
|
||||
|
||||
return $alias;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Category;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\CategoryRepository;
|
||||
|
||||
class CategoryManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* CategoryManager constructor.
|
||||
*
|
||||
* @param CategoryRepository $repository
|
||||
*/
|
||||
public function __construct(CategoryRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Category entity with $name or retrieve one.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function create($name)
|
||||
{
|
||||
if (($category = $this->repository->findByName($name)) == null) {
|
||||
$category = new Category();
|
||||
$category->setName($name);
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Keyword;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\KeywordRepository;
|
||||
|
||||
class KeywordManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* KeywordManager constructor.
|
||||
*
|
||||
* @param KeywordRepository $repository
|
||||
*/
|
||||
public function __construct(KeywordRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Keyword entity with $name or retrieve one.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Keyword
|
||||
*/
|
||||
public function create($name)
|
||||
{
|
||||
if (($keyword = $this->repository->findByName($name)) == null) {
|
||||
$keyword = new Keyword();
|
||||
$keyword->setName($name);
|
||||
}
|
||||
|
||||
return $keyword;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\ModelRepository;
|
||||
|
||||
class ModelManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* ModelManager constructor.
|
||||
*
|
||||
* @param ModelRepository $repository
|
||||
*/
|
||||
public function __construct(ModelRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Model entity with $number or retrieve one.
|
||||
*
|
||||
* @param $number
|
||||
*
|
||||
* @return Model
|
||||
*/
|
||||
public function create($number)
|
||||
{
|
||||
if (($model = $this->repository->findOneBy(['number' => $number])) == null) {
|
||||
$model = new Model();
|
||||
$model->setNumber($number);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function findByNumber($number)
|
||||
{
|
||||
return $this->repository->findOneByNumber($number);
|
||||
}
|
||||
|
||||
public function findByName($name)
|
||||
{
|
||||
return $this->repository->findOneBy(['name' => $name]);
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Subpart;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\SubpartRepository;
|
||||
|
||||
class SubpartManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* SubpartManager constructor.
|
||||
*
|
||||
* @param SubpartRepository $repository
|
||||
*/
|
||||
public function __construct(SubpartRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Subpart relation entity or retrieve one by foreign keys.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Subpart
|
||||
*/
|
||||
public function create($parent, $child, $count)
|
||||
{
|
||||
// if (($subpart = $this->repository->findOneByKeys($parent, $child))) {
|
||||
// $subpart->setCount($count);
|
||||
// } else {
|
||||
$subpart = new Subpart();
|
||||
$subpart
|
||||
->setParent($parent)
|
||||
->setSubpart($child)
|
||||
->setCount($count);
|
||||
// }
|
||||
|
||||
return $subpart;
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager;
|
||||
|
||||
use AppBundle\Manager\LDraw\AliasManager;
|
||||
use AppBundle\Manager\LDraw\CategoryManager;
|
||||
use AppBundle\Manager\LDraw\KeywordManager;
|
||||
use AppBundle\Manager\LDraw\ModelManager;
|
||||
use AppBundle\Manager\LDraw\SubpartManager;
|
||||
use AppBundle\Manager\LDraw\TypeManager;
|
||||
|
||||
class LDrawManager
|
||||
{
|
||||
/** @var CategoryManager */
|
||||
private $categoryManager;
|
||||
|
||||
/** @var KeywordManager */
|
||||
private $keywordManager;
|
||||
|
||||
/** @var SubpartManager */
|
||||
private $subpartManager;
|
||||
|
||||
/** @var ModelManager */
|
||||
private $modelManager;
|
||||
|
||||
/** @var AliasManager */
|
||||
private $aliasManager;
|
||||
|
||||
/**
|
||||
* LDrawService constructor.
|
||||
*
|
||||
* @param CategoryManager $categoryManager
|
||||
* @param KeywordManager $keywordManager
|
||||
* @param SubpartManager $subpartManager
|
||||
* @param ModelManager $modelManager
|
||||
* @param AliasManager $aliasManager
|
||||
*/
|
||||
public function __construct(CategoryManager $categoryManager, KeywordManager $keywordManager, SubpartManager $subpartManager, ModelManager $modelManager, AliasManager $aliasManager)
|
||||
{
|
||||
$this->categoryManager = $categoryManager;
|
||||
$this->keywordManager = $keywordManager;
|
||||
$this->subpartManager = $subpartManager;
|
||||
$this->modelManager = $modelManager;
|
||||
$this->aliasManager = $aliasManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCategoryManager()
|
||||
{
|
||||
return $this->categoryManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getKeywordManager()
|
||||
{
|
||||
return $this->keywordManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SubpartManager
|
||||
*/
|
||||
public function getSubpartManager()
|
||||
{
|
||||
return $this->subpartManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ModelManager
|
||||
*/
|
||||
public function getModelManager()
|
||||
{
|
||||
return $this->modelManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AliasManager
|
||||
*/
|
||||
public function getAliasManager()
|
||||
{
|
||||
return $this->aliasManager;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager;
|
||||
|
||||
use AppBundle\Entity\Rebrickable\Theme;
|
||||
|
||||
class RebrickableManager extends BaseManager
|
||||
{
|
||||
public function findAllThemes() {
|
||||
return $this->em->getRepository(Theme::class)->findAll();
|
||||
}
|
||||
}
|
@ -2,8 +2,28 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class AliasRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* Get existing entity or create new.
|
||||
*
|
||||
* @param $number
|
||||
* @param Model $model
|
||||
*
|
||||
* @return Alias
|
||||
*/
|
||||
public function getOrCreate($number, $model)
|
||||
{
|
||||
if (($alias = $this->findOneBy(['number' => $number, 'model' => $model])) == null) {
|
||||
$alias = new Alias();
|
||||
$alias->setModel($model);
|
||||
$alias->setNumber($number);
|
||||
}
|
||||
|
||||
return $alias;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Category;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class CategoryRepository extends BaseRepository
|
||||
@ -10,4 +11,21 @@ class CategoryRepository extends BaseRepository
|
||||
{
|
||||
return $this->findOneBy(['name' => $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get existing entity or create new.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function getOrCreate($name)
|
||||
{
|
||||
if (($category = $this->findByName($name)) == null) {
|
||||
$category = new Category();
|
||||
$category->setName($name);
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Keyword;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class KeywordRepository extends BaseRepository
|
||||
@ -10,4 +11,21 @@ class KeywordRepository extends BaseRepository
|
||||
{
|
||||
return $this->findOneBy(['name' => $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Keyword entity with $name or retrieve one.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Keyword
|
||||
*/
|
||||
public function getOrCreate($name)
|
||||
{
|
||||
if (($keyword = $this->findByName($name)) == null) {
|
||||
$keyword = new Keyword();
|
||||
$keyword->setName($name);
|
||||
}
|
||||
|
||||
return $keyword;
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,29 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\LDraw\Category;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Entity\LDraw\Subpart;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\LDraw\Alias;
|
||||
use AppBundle\Entity\Rebrickable\Inventory;
|
||||
use AppBundle\Entity\Rebrickable\Inventory_Part;
|
||||
use AppBundle\Entity\Rebrickable\Part;
|
||||
use AppBundle\Entity\Rebrickable\Set;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
|
||||
class ModelRepository extends BaseRepository
|
||||
{
|
||||
public function getFilteredQueryBuilder()
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model')
|
||||
// ->where('model.name NOT LIKE :obsolete')
|
||||
// ->setParameter('obsolete','~%')
|
||||
;
|
||||
|
||||
return $queryBuilder;
|
||||
}
|
||||
|
||||
public function findAllByCategory($category)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model')
|
||||
@ -42,6 +52,11 @@ class ModelRepository extends BaseRepository
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function findOneByName($name)
|
||||
{
|
||||
return $this->findOneBy(['name' => $name]);
|
||||
}
|
||||
|
||||
public function findAllBySetNumber($number)
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder('model');
|
||||
@ -74,4 +89,21 @@ class ModelRepository extends BaseRepository
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Model entity with $number or retrieve one.
|
||||
*
|
||||
* @param $number
|
||||
*
|
||||
* @return Model
|
||||
*/
|
||||
public function getOrCreate($number)
|
||||
{
|
||||
if (($model = $this->findOneBy(['number' => $number])) == null) {
|
||||
$model = new Model();
|
||||
$model->setNumber($number);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace AppBundle\Repository\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Subpart;
|
||||
use AppBundle\Repository\BaseRepository;
|
||||
|
||||
class SubpartRepository extends BaseRepository
|
||||
@ -10,4 +11,26 @@ class SubpartRepository extends BaseRepository
|
||||
{
|
||||
return $this->find(['parent' => $parent, 'subpart' => $child]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Subpart relation entity or retrieve one by foreign keys.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Subpart
|
||||
*/
|
||||
public function getOrCreate($parent, $child, $count)
|
||||
{
|
||||
if (($subpart = $this->findOneByKeys($parent, $child))) {
|
||||
$subpart->setCount($count);
|
||||
} else {
|
||||
$subpart = new Subpart();
|
||||
$subpart
|
||||
->setParent($parent)
|
||||
->setSubpart($child)
|
||||
->setCount($count);
|
||||
}
|
||||
|
||||
return $subpart;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user