Part-DB.Part-DB-server/src/Entity/Parts/Part.php

161 lines
5.3 KiB
PHP
Raw Normal View History

<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
2019-11-01 13:40:30 +01:00
* Copyright (C) 2019 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
declare(strict_types=1);
2019-03-05 14:37:41 +01:00
2019-02-23 22:41:13 +01:00
/**
2019-03-05 14:37:41 +01:00
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/.
2019-03-05 14:37:41 +01:00
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 2019 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2019-02-23 22:41:13 +01:00
*/
namespace App\Entity\Parts;
2019-02-23 22:41:13 +01:00
2019-09-24 16:09:54 +02:00
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Devices\Device;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
use App\Entity\Parts\PartTraits\ManufacturerTrait;
use App\Entity\Parts\PartTraits\OrderTrait;
use App\Security\Annotations\ColumnSecurity;
2020-01-05 22:49:00 +01:00
use DateTime;
2019-08-19 23:41:58 +02:00
use Doctrine\Common\Collections\ArrayCollection;
2019-02-23 22:41:13 +01:00
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
2019-02-23 22:41:13 +01:00
/**
* Part class.
*
* 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`")
2019-02-23 22:41:13 +01:00
*/
class Part extends AttachmentContainingDBElement
{
use AdvancedPropertyTrait;
//use MasterAttachmentTrait;
use BasicPropertyTrait;
use InstockTrait;
use ManufacturerTrait;
use OrderTrait;
2019-02-23 22:41:13 +01:00
2020-01-05 22:49:00 +01:00
/**
2020-02-01 16:17:20 +01:00
* TODO.
2020-01-05 22:49:00 +01:00
*/
2019-02-23 22:41:13 +01:00
protected $devices;
/**
* @ColumnSecurity(type="datetime")
* @ORM\Column(type="datetime", name="datetime_added", options={"default"="CURRENT_TIMESTAMP"})
*/
protected $addedDate;
/** *************************************************************
2019-11-10 14:00:56 +01:00
* Overridden properties
2020-01-05 22:49:00 +01:00
* (They are defined here and not in a trait, to avoid conflicts).
2019-09-16 22:04:59 +02:00
****************************************************************/
/**
* @var string The name of this part
* @ORM\Column(type="string")
* @ColumnSecurity(prefix="name")
*/
protected $name = '';
/**
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ColumnSecurity(type="collection", prefix="attachments")
* @Assert\Valid()
2019-02-23 22:41:13 +01:00
*/
protected $attachments;
2020-01-05 22:49:00 +01:00
/**
* @var DateTime the date when this element was modified the last time
* @ColumnSecurity(type="datetime")
* @ORM\Column(type="datetime", name="last_modified", options={"default"="CURRENT_TIMESTAMP"})
*/
protected $lastModified;
2019-09-24 16:09:54 +02:00
/**
* @var Attachment
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment")
* @ORM\JoinColumn(name="id_preview_attachement", referencedColumnName="id")
* @Assert\Expression("value == null or value.isPicture()", message="part.master_attachment.must_be_picture")
*/
protected $master_picture_attachment;
2019-08-19 23:41:58 +02:00
public function __construct()
{
parent::__construct();
$this->partLots = new ArrayCollection();
$this->orderdetails = new ArrayCollection();
2019-08-19 23:41:58 +02:00
}
2019-02-23 22:41:13 +01:00
/**
* Returns the ID as an string, defined by the element class.
* This should have a form like P000014, for a part with ID 14.
*
2019-02-23 22:41:13 +01:00
* @return string The ID as a string;
*/
public function getIDString(): string
{
return 'P'.sprintf('%06d', $this->getID());
2019-02-23 22:41:13 +01:00
}
/**
* Get all devices which uses this part.
2019-02-23 22:41:13 +01:00
*
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects
* (empty array if there are no ones)
* * the array is sorted by the devices names
2019-02-23 22:41:13 +01:00
*/
public function getDevices(): array
2019-02-23 22:41:13 +01:00
{
return $this->devices;
}
}