diff --git a/src/AppBundle/Entity/Rebrickable/Category.php b/src/AppBundle/Entity/Rebrickable/Category.php index 8bd8181..dca48f7 100644 --- a/src/AppBundle/Entity/Rebrickable/Category.php +++ b/src/AppBundle/Entity/Rebrickable/Category.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; * Category. * * @ORM\Table(name="rebrickable_category") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\CategoryRepository") */ class Category { diff --git a/src/AppBundle/Entity/Rebrickable/Color.php b/src/AppBundle/Entity/Rebrickable/Color.php index 7fa803e..e6d65d1 100644 --- a/src/AppBundle/Entity/Rebrickable/Color.php +++ b/src/AppBundle/Entity/Rebrickable/Color.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; * Color. * * @ORM\Table(name="rebrickable_color") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\ColorRepository") */ class Color { diff --git a/src/AppBundle/Entity/Rebrickable/Inventory.php b/src/AppBundle/Entity/Rebrickable/Inventory.php index e0a912a..b818668 100644 --- a/src/AppBundle/Entity/Rebrickable/Inventory.php +++ b/src/AppBundle/Entity/Rebrickable/Inventory.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; * Part. * * @ORM\Table(name="rebrickable_inventory") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\InventoryRepository") */ class Inventory { diff --git a/src/AppBundle/Entity/Rebrickable/Inventory_Part.php b/src/AppBundle/Entity/Rebrickable/Inventory_Part.php index c7b06d4..c172daf 100644 --- a/src/AppBundle/Entity/Rebrickable/Inventory_Part.php +++ b/src/AppBundle/Entity/Rebrickable/Inventory_Part.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; * Inventory_Part. * * @ORM\Table(name="rebrickable_inventory_parts") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\Inventory_PartRepository") */ class Inventory_Part { diff --git a/src/AppBundle/Entity/Rebrickable/Part.php b/src/AppBundle/Entity/Rebrickable/Part.php index 90f0da5..c172f9d 100644 --- a/src/AppBundle/Entity/Rebrickable/Part.php +++ b/src/AppBundle/Entity/Rebrickable/Part.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; * Part. * * @ORM\Table(name="rebrickable_part") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\PartRepository") */ class Part { diff --git a/src/AppBundle/Entity/Rebrickable/Set.php b/src/AppBundle/Entity/Rebrickable/Set.php index ab83694..1fdf69f 100644 --- a/src/AppBundle/Entity/Rebrickable/Set.php +++ b/src/AppBundle/Entity/Rebrickable/Set.php @@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM; * Set. * * @ORM\Table(name="rebrickable_set") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\SetRepository") */ class Set { diff --git a/src/AppBundle/Entity/Rebrickable/Theme.php b/src/AppBundle/Entity/Rebrickable/Theme.php index b0ddfb0..4c4fc98 100644 --- a/src/AppBundle/Entity/Rebrickable/Theme.php +++ b/src/AppBundle/Entity/Rebrickable/Theme.php @@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM; * Theme. * * @ORM\Table(name="rebrickable_theme") - * @ORM\Entity + * @ORM\Entity(repositoryClass="AppBundle\Repository\Rebrickable\ThemeRepository") */ class Theme { diff --git a/src/AppBundle/Repository/BaseRepository.php b/src/AppBundle/Repository/BaseRepository.php index 0e7f080..36d80fa 100644 --- a/src/AppBundle/Repository/BaseRepository.php +++ b/src/AppBundle/Repository/BaseRepository.php @@ -2,18 +2,23 @@ namespace AppBundle\Repository; - use Doctrine\ORM\EntityRepository; class BaseRepository extends EntityRepository { - public function save($entity) { + public function save($entity, $flush = true) + { $this->_em->persist($entity); - $this->_em->flush($entity); + if ($flush) { + $this->_em->flush($entity); + } } - public function delete($entity) { + public function delete($entity, $flush = true) + { $this->_em->remove($entity); - $this->_em->flush($entity); + if ($flush) { + $this->_em->flush($entity); + } } -} \ No newline at end of file +} diff --git a/src/AppBundle/Repository/Rebrickable/CategoryRepository.php b/src/AppBundle/Repository/Rebrickable/CategoryRepository.php new file mode 100644 index 0000000..d0cad61 --- /dev/null +++ b/src/AppBundle/Repository/Rebrickable/CategoryRepository.php @@ -0,0 +1,9 @@ +createQueryBuilder('inventory_part'); + + $queryBuilder + ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory.id') + ->join(Set::class, 's', Join::WITH, 'inventory.set = s.number') + ->where('s.number LIKE :number') + ->setParameter('number', $number) + ->distinct(true); + + return $queryBuilder->getQuery()->getResult(); + } +} diff --git a/src/AppBundle/Repository/Rebrickable/PartRepository.php b/src/AppBundle/Repository/Rebrickable/PartRepository.php new file mode 100644 index 0000000..5bcacc1 --- /dev/null +++ b/src/AppBundle/Repository/Rebrickable/PartRepository.php @@ -0,0 +1,27 @@ +createQueryBuilder('part'); + + $queryBuilder + ->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'part.number = inventory_part.part') + ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory_part.inventory = inventory.id') + ->join(Set::class, 's', Join::WITH, 'inventory.set = s.number') + ->where('s.number LIKE :number') + ->setParameter('number', $number) + ->distinct(true); + + return $queryBuilder->getQuery()->getResult(); + } +} diff --git a/src/AppBundle/Repository/Rebrickable/SetRepository.php b/src/AppBundle/Repository/Rebrickable/SetRepository.php new file mode 100644 index 0000000..8a810e9 --- /dev/null +++ b/src/AppBundle/Repository/Rebrickable/SetRepository.php @@ -0,0 +1,27 @@ +createQueryBuilder('s'); + + $queryBuilder + ->join(Inventory::class, 'inventory', JOIN::WITH, 'inventory.set = s.number') + ->join(Inventory_Part::class, 'inventory_part', JOIN::WITH, 'inventory.id = inventory_part.inventory') + ->join(Part::class, 'part', Join::WITH, 'inventory_part.part = part.number') + ->where('part.number LIKE :number') + ->setParameter('number', $number.'%') + ->distinct(true); + + return $queryBuilder->getQuery()->getResult(); + } +} diff --git a/src/AppBundle/Repository/Rebrickable/ThemeRepository.php b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php new file mode 100644 index 0000000..11b0d88 --- /dev/null +++ b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php @@ -0,0 +1,9 @@ +