mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-14 20:35:08 +02:00
Migrated doctrine annotations to attributes
This commit is contained in:
parent
0bc4699cdc
commit
0837f84a43
8 changed files with 121 additions and 159 deletions
|
@ -47,15 +47,13 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
*
|
||||
* The class properties are split over various traits in directory PartTraits.
|
||||
* Otherwise, this class would be too big, to be maintained.
|
||||
*
|
||||
* @ORM\Entity(repositoryClass="App\Repository\PartRepository")
|
||||
* @ORM\Table("`parts`", indexes={
|
||||
* @ORM\Index(name="parts_idx_datet_name_last_id_needs", columns={"datetime_added", "name", "last_modified", "id", "needs_review"}),
|
||||
* @ORM\Index(name="parts_idx_name", columns={"name"}),
|
||||
* @ORM\Index(name="parts_idx_ipn", columns={"ipn"}),
|
||||
* })
|
||||
*/
|
||||
#[UniqueEntity(fields: ['ipn'], message: 'part.ipn.must_be_unique')]
|
||||
#[ORM\Entity(repositoryClass: 'App\Repository\PartRepository')]
|
||||
#[ORM\Table('`parts`')]
|
||||
#[ORM\Index(name: 'parts_idx_datet_name_last_id_needs', columns: ['datetime_added', 'name', 'last_modified', 'id', 'needs_review'])]
|
||||
#[ORM\Index(name: 'parts_idx_name', columns: ['name'])]
|
||||
#[ORM\Index(name: 'parts_idx_ipn', columns: ['ipn'])]
|
||||
class Part extends AttachmentContainingDBElement
|
||||
{
|
||||
use AdvancedPropertyTrait;
|
||||
|
@ -68,54 +66,44 @@ class Part extends AttachmentContainingDBElement
|
|||
use ProjectTrait;
|
||||
|
||||
/** @var Collection<int, PartParameter>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\PartParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['full'])]
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Parameters\PartParameter', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", name="datetime_added", options={"default":"CURRENT_TIMESTAMP"})
|
||||
*/
|
||||
protected ?DateTime $addedDate = null;
|
||||
|
||||
/** *************************************************************
|
||||
* Overridden properties
|
||||
* (They are defined here and not in a trait, to avoid conflicts).
|
||||
****************************************************************/
|
||||
|
||||
/**
|
||||
* @var string The name of this part
|
||||
* @ORM\Column(type="string")
|
||||
*/
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
||||
protected string $name = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, PartAttachment>
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
||||
* @ORM\OrderBy({"name" = "ASC"})
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['full'])]
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Attachments\PartAttachment', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
/**
|
||||
* @var DateTime|null the date when this element was modified the last time
|
||||
* @ORM\Column(type="datetime", name="last_modified", options={"default":"CURRENT_TIMESTAMP"})
|
||||
*/
|
||||
protected ?DateTime $lastModified = null;
|
||||
|
||||
/**
|
||||
* @var Attachment|null
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment")
|
||||
* @ORM\JoinColumn(name="id_preview_attachment", referencedColumnName="id", onDelete="SET NULL", nullable=true)
|
||||
*/
|
||||
#[Assert\Expression('value == null or value.isPicture()', message: 'part.master_attachment.must_be_picture')]
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\Attachments\Attachment')]
|
||||
#[ORM\JoinColumn(name: 'id_preview_attachment', onDelete: 'SET NULL')]
|
||||
protected ?Attachment $master_picture_attachment = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->attachments = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
parent::__construct();
|
||||
$this->partLots = new ArrayCollection();
|
||||
$this->orderdetails = new ArrayCollection();
|
||||
|
|
|
@ -40,84 +40,83 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
* This entity describes a lot where parts can be stored.
|
||||
* It is the connection between a part and its store locations.
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table(name="part_lots", indexes={
|
||||
* @ORM\Index(name="part_lots_idx_instock_un_expiration_id_part", columns={"instock_unknown", "expiration_date", "id_part"}),
|
||||
* @ORM\Index(name="part_lots_idx_needs_refill", columns={"needs_refill"}),
|
||||
* })
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
* @ValidPartLot()
|
||||
*/
|
||||
#[ORM\Entity]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\Table(name: 'part_lots')]
|
||||
#[ORM\Index(name: 'part_lots_idx_instock_un_expiration_id_part', columns: ['instock_unknown', 'expiration_date', 'id_part'])]
|
||||
#[ORM\Index(name: 'part_lots_idx_needs_refill', columns: ['needs_refill'])]
|
||||
class PartLot extends AbstractDBElement implements TimeStampableInterface, NamedElementInterface
|
||||
{
|
||||
use TimestampTrait;
|
||||
|
||||
/**
|
||||
* @var string A short description about this lot, shown in table
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import'])]
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT)]
|
||||
protected string $description = '';
|
||||
|
||||
/**
|
||||
* @var string a comment stored with this lot
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
#[Groups(['full', 'import'])]
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT)]
|
||||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var ?DateTime Set a time until when the lot must be used.
|
||||
* @var \DateTimeInterface|null Set a time until when the lot must be used.
|
||||
* Set to null, if the lot can be used indefinitely.
|
||||
* @ORM\Column(type="datetime", name="expiration_date", nullable=true)
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
protected ?DateTime $expiration_date = null;
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE, name: 'expiration_date', nullable: true)]
|
||||
protected ?\DateTimeInterface $expiration_date = null;
|
||||
|
||||
/**
|
||||
* @var Storelocation|null The storelocation of this lot
|
||||
* @ORM\ManyToOne(targetEntity="Storelocation")
|
||||
* @ORM\JoinColumn(name="id_store_location", referencedColumnName="id", nullable=true)
|
||||
* @Selectable()
|
||||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import'])]
|
||||
#[ORM\ManyToOne(targetEntity: 'Storelocation')]
|
||||
#[ORM\JoinColumn(name: 'id_store_location')]
|
||||
protected ?Storelocation $storage_location = null;
|
||||
|
||||
/**
|
||||
* @var bool If this is set to true, the instock amount is marked as not known
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import'])]
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)]
|
||||
protected bool $instock_unknown = false;
|
||||
|
||||
/**
|
||||
* @var float For continuous sizes (length, volume, etc.) the instock is saved here.
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
#[Assert\PositiveOrZero]
|
||||
#[Groups(['simple', 'extended', 'full', 'import'])]
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::FLOAT)]
|
||||
protected float $amount = 0.0;
|
||||
|
||||
/**
|
||||
* @var bool determines if this lot was manually marked for refilling
|
||||
* @ORM\Column(type="boolean")
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)]
|
||||
protected bool $needs_refill = false;
|
||||
|
||||
/**
|
||||
* @var Part The part that is stored in this lot
|
||||
* @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
|
||||
* @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=false, onDelete="CASCADE")
|
||||
*/
|
||||
#[Assert\NotNull]
|
||||
#[ORM\ManyToOne(targetEntity: 'Part', inversedBy: 'partLots')]
|
||||
#[ORM\JoinColumn(name: 'id_part', nullable: false, onDelete: 'CASCADE')]
|
||||
protected Part $part;
|
||||
|
||||
/**
|
||||
* @var User|null The owner of this part lot
|
||||
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User")
|
||||
* @ORM\JoinColumn(name="id_owner", referencedColumnName="id", nullable=true, onDelete="SET NULL")
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\UserSystem\User')]
|
||||
#[ORM\JoinColumn(name: 'id_owner', onDelete: 'SET NULL')]
|
||||
protected ?User $owner = null;
|
||||
|
||||
public function __clone()
|
||||
|
@ -189,7 +188,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
/**
|
||||
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
|
||||
*/
|
||||
public function getExpirationDate(): ?DateTime
|
||||
public function getExpirationDate(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->expiration_date;
|
||||
}
|
||||
|
@ -197,11 +196,11 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
/**
|
||||
* Sets the expiration date for the part lot. Set to null, if the part lot does not expire.
|
||||
*
|
||||
* @param DateTime|null $expiration_date
|
||||
* @param \DateTimeInterface|null $expiration_date
|
||||
*
|
||||
* @return PartLot
|
||||
*/
|
||||
public function setExpirationDate(?DateTime $expiration_date): self
|
||||
public function setExpirationDate(?\DateTimeInterface $expiration_date): self
|
||||
{
|
||||
$this->expiration_date = $expiration_date;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Entity\Parts\PartTraits;
|
|||
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
|
@ -13,7 +14,7 @@ trait ProjectTrait
|
|||
* @var \Doctrine\Common\Collections\Collection<\App\Entity\ProjectSystem\ProjectBOMEntry> $project_bom_entries
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\ProjectSystem\ProjectBOMEntry', mappedBy: 'part', cascade: ['remove'], orphanRemoval: true)]
|
||||
protected \Doctrine\Common\Collections\Collection $project_bom_entries = [];
|
||||
protected \Doctrine\Common\Collections\Collection $project_bom_entries;
|
||||
|
||||
/**
|
||||
* @var Project|null If a project is set here, then this part is special and represents the builds of a project.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue