mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 04:30:08 +02:00
Moved getParts() and getPartsCount() to a repository (instead of a class method).
This commit is contained in:
parent
350f1bb979
commit
14adb77a97
24 changed files with 421 additions and 71 deletions
|
@ -30,28 +30,9 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
/**
|
||||
* Class PartsContainingDBElement.
|
||||
*
|
||||
* @ORM\MappedSuperclass()
|
||||
* @ORM\MappedSuperclass(repositoryClass="App\Repository\AbstractPartsContainingRepository")
|
||||
*/
|
||||
abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElement
|
||||
{
|
||||
/**
|
||||
* @var Part[]|Collection
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->parts = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parts associated with this element.
|
||||
*
|
||||
* @return Collection|Part[]
|
||||
*/
|
||||
public function getParts(): Collection
|
||||
{
|
||||
return $this->parts;
|
||||
}
|
||||
}
|
||||
|
|
43
src/Entity/Base/PartsContainingRepositoryInterface.php
Normal file
43
src/Entity/Base/PartsContainingRepositoryInterface.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Base;
|
||||
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
interface PartsContainingRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Returns all parts associated with this element.
|
||||
* @param object $element The element for which the parts should be determined.
|
||||
* @param array $order_by The order of the parts. Format ['name' => 'ASC']
|
||||
* @return Part[]
|
||||
*/
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array;
|
||||
|
||||
/**
|
||||
* Gets the count of the parts associated with this element.
|
||||
* @param object $element The element for which the parts should be determined.
|
||||
* @return int
|
||||
*/
|
||||
public function getPartsCount(object $element): int;
|
||||
}
|
|
@ -32,7 +32,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
/**
|
||||
* Class AttachmentType.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\CategoryRepository")
|
||||
* @ORM\Table(name="`categories`")
|
||||
*/
|
||||
class Category extends AbstractPartsContainingDBElement
|
||||
|
@ -49,11 +49,6 @@ class Category extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="category", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @ORM\Column(type="text")
|
||||
|
|
|
@ -60,7 +60,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
/**
|
||||
* Class Footprint.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\FootprintRepository")
|
||||
* @ORM\Table("`footprints`")
|
||||
*/
|
||||
class Footprint extends AbstractPartsContainingDBElement
|
||||
|
@ -77,10 +77,6 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="footprint", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection<int, FootprintAttachment>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\FootprintAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
|
|
|
@ -60,7 +60,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
/**
|
||||
* Class Manufacturer.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\ManufacturerRepository")
|
||||
* @ORM\Table("`manufacturers`")
|
||||
*/
|
||||
class Manufacturer extends AbstractCompany
|
||||
|
@ -77,10 +77,6 @@ class Manufacturer extends AbstractCompany
|
|||
*/
|
||||
protected $children;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="manufacturer", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection<int, ManufacturerAttachment>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
|
|
|
@ -54,7 +54,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
* This unit represents the unit in which the amount of parts in stock are measured.
|
||||
* This could be something like N, grams, meters, etc...
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\MeasurementUnitRepository")
|
||||
* @ORM\Table(name="`measurement_units`")
|
||||
* @UniqueEntity("unit")
|
||||
*/
|
||||
|
@ -94,10 +94,6 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Part", mappedBy="partUnit", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $parts;
|
||||
/**
|
||||
* @var Collection<int, MeasurementUnitAttachment>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
|
|
|
@ -114,7 +114,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
|
||||
/**
|
||||
* @var Part The part that is stored in this lot
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
|
||||
* @ORM\ManyToOne(targetEntity="Part")
|
||||
* @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
|
|
|
@ -79,7 +79,7 @@ trait BasicPropertyTrait
|
|||
/**
|
||||
* @var Category The category this part belongs too (e.g. Resistors). Use tags, for more complex grouping.
|
||||
* Every part must have a category.
|
||||
* @ORM\ManyToOne(targetEntity="Category", inversedBy="parts")
|
||||
* @ORM\ManyToOne(targetEntity="Category")
|
||||
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
|
||||
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category")
|
||||
* @Selectable()
|
||||
|
@ -88,7 +88,7 @@ trait BasicPropertyTrait
|
|||
|
||||
/**
|
||||
* @var Footprint|null The footprint of this part (e.g. DIP8)
|
||||
* @ORM\ManyToOne(targetEntity="Footprint", inversedBy="parts")
|
||||
* @ORM\ManyToOne(targetEntity="Footprint")
|
||||
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
|
||||
* @ColumnSecurity(prefix="footprint", type="App\Entity\Parts\Footprint")
|
||||
* @Selectable()
|
||||
|
|
|
@ -72,7 +72,7 @@ trait InstockTrait
|
|||
|
||||
/**
|
||||
* @var ?MeasurementUnit the unit in which the part's amount is measured
|
||||
* @ORM\ManyToOne(targetEntity="MeasurementUnit", inversedBy="parts")
|
||||
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
|
||||
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true)
|
||||
* @ColumnSecurity(type="object", prefix="unit")
|
||||
*/
|
||||
|
|
|
@ -54,7 +54,7 @@ trait ManufacturerTrait
|
|||
{
|
||||
/**
|
||||
* @var Manufacturer|null The manufacturer of this part
|
||||
* @ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="parts")
|
||||
* @ORM\ManyToOne(targetEntity="Manufacturer")
|
||||
* @ORM\JoinColumn(name="id_manufacturer", referencedColumnName="id")
|
||||
* @ColumnSecurity(prefix="manufacturer", type="App\Entity\Parts\Manufacturer")
|
||||
* @Selectable()
|
||||
|
|
|
@ -60,7 +60,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
/**
|
||||
* Class Store location.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\StorelocationRepository")
|
||||
* @ORM\Table("`storelocations`")
|
||||
*/
|
||||
class Storelocation extends AbstractPartsContainingDBElement
|
||||
|
@ -84,15 +84,6 @@ class Storelocation extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
protected $storage_type;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="part_lots",
|
||||
* joinColumns={@ORM\JoinColumn(name="id_store_location", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="id_part", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/** @var Collection<int, StorelocationParameter>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\StorelocationParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
|
||||
|
|
|
@ -62,7 +62,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
/**
|
||||
* Class Supplier.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
||||
* @ORM\Entity(repositoryClass="App\Repository\Parts\SupplierRepository")
|
||||
* @ORM\Table("`suppliers`")
|
||||
*/
|
||||
class Supplier extends AbstractCompany
|
||||
|
@ -100,15 +100,6 @@ class Supplier extends AbstractCompany
|
|||
*/
|
||||
protected $shipping_costs;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Part", fetch="EXTRA_LAZY")
|
||||
* @ORM\JoinTable(name="orderdetails",
|
||||
* joinColumns={@ORM\JoinColumn(name="id_supplier", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="part_id", referencedColumnName="id")}
|
||||
* )
|
||||
*/
|
||||
protected $parts;
|
||||
|
||||
/**
|
||||
* @var Collection<int, SupplierAttachment>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\SupplierAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue