mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 21:00:09 -07:00
Add LDraw entity managers
This commit is contained in:
parent
a7a58764bf
commit
8ebde0c02f
16
src/AppBundle/Manager/BaseManager.php
Normal file
16
src/AppBundle/Manager/BaseManager.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager;
|
||||
|
||||
class BaseManager
|
||||
{
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
}
|
42
src/AppBundle/Manager/LDraw/CategoryManager.php
Normal file
42
src/AppBundle/Manager/LDraw/CategoryManager.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
37
src/AppBundle/Manager/LDraw/KeywordManager.php
Normal file
37
src/AppBundle/Manager/LDraw/KeywordManager.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
37
src/AppBundle/Manager/LDraw/ModelManager.php
Normal file
37
src/AppBundle/Manager/LDraw/ModelManager.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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->find($number)) == null) {
|
||||
$model = new Model();
|
||||
$model->setNumber($number);
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
38
src/AppBundle/Manager/LDraw/PartManager.php
Normal file
38
src/AppBundle/Manager/LDraw/PartManager.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Part;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\CategoryRepository;
|
||||
use AppBundle\Repository\LDraw\PartRepository;
|
||||
|
||||
class PartManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* PartManager constructor.
|
||||
*
|
||||
* @param CategoryRepository $repository
|
||||
*/
|
||||
public function __construct(PartRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Part entity with $number or retrieve one.
|
||||
*
|
||||
* @param $number
|
||||
*
|
||||
* @return Part
|
||||
*/
|
||||
public function create($number)
|
||||
{
|
||||
if (($part = $this->repository->find($number)) == null) {
|
||||
$part = new Part();
|
||||
$part->setNumber($number);
|
||||
}
|
||||
|
||||
return $part;
|
||||
}
|
||||
}
|
41
src/AppBundle/Manager/LDraw/Part_RelationManager.php
Normal file
41
src/AppBundle/Manager/LDraw/Part_RelationManager.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Part_Relation;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\Part_RelationRepository;
|
||||
|
||||
class Part_RelationManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* Part_RelationManager constructor.
|
||||
*
|
||||
* @param Part_RelationRepository $repository
|
||||
*/
|
||||
public function __construct(Part_RelationRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Keyword entity with $name or retrieve one.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Part_Relation
|
||||
*/
|
||||
public function create($parent, $child, $relationType)
|
||||
{
|
||||
if (($partRelation = $this->repository->findByForeignKeys($parent, $child, $relationType)) == null) {
|
||||
$partRelation = new Part_Relation();
|
||||
$partRelation
|
||||
->setParent($parent)
|
||||
->setChild($child)
|
||||
->setCount(0)
|
||||
->setType($relationType);
|
||||
}
|
||||
|
||||
return $partRelation;
|
||||
}
|
||||
}
|
37
src/AppBundle/Manager/LDraw/TypeManager.php
Normal file
37
src/AppBundle/Manager/LDraw/TypeManager.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace AppBundle\Manager\LDraw;
|
||||
|
||||
use AppBundle\Entity\LDraw\Type;
|
||||
use AppBundle\Manager\BaseManager;
|
||||
use AppBundle\Repository\LDraw\TypeRepository;
|
||||
|
||||
class TypeManager extends BaseManager
|
||||
{
|
||||
/**
|
||||
* TypeManager constructor.
|
||||
*
|
||||
* @param TypeRepository $typeRepository
|
||||
*/
|
||||
public function __construct(TypeRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new Keyword entity with $name or retrieve one.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public function create($name)
|
||||
{
|
||||
if (($type = $this->repository->findByName($name)) == null) {
|
||||
$type = new Type();
|
||||
$type->setName($name);
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user