2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
2019-08-12 15:47:57 +02:00
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
|
|
|
* 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-03-20 23:16:07 +01:00
|
|
|
|
|
|
|
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
|
2019-03-20 23:16:07 +01:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2019-08-12 15:47:57 +02: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;
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Attachments\AttachmentContainingDBElement;
|
|
|
|
use App\Entity\Devices\Device;
|
2019-09-16 21:40:47 +02:00
|
|
|
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;
|
2019-03-20 19:11:34 +01:00
|
|
|
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;
|
2019-03-13 13:23:12 +01:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-09-16 13:27:53 +02:00
|
|
|
* Part class.
|
|
|
|
*
|
2019-09-16 21:40:47 +02:00
|
|
|
* The class properties are split over various traits in directory PartTraits.
|
|
|
|
* Otherwise this class would be too big, to be maintained.
|
|
|
|
*
|
2019-02-23 22:52:48 +01:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\PartRepository")
|
2019-08-06 13:18:29 +02:00
|
|
|
* @ORM\Table("`parts`")
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
class Part extends AttachmentContainingDBElement
|
|
|
|
{
|
2019-09-16 21:40:47 +02:00
|
|
|
use AdvancedPropertyTrait;
|
2019-09-24 13:39:49 +02:00
|
|
|
//use MasterAttachmentTrait;
|
2019-09-16 21:40:47 +02:00
|
|
|
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;
|
|
|
|
|
2019-03-20 22:30:03 +01:00
|
|
|
/**
|
2019-09-16 21:40:47 +02:00
|
|
|
* @ColumnSecurity(type="datetime")
|
2019-09-02 15:03:20 +02:00
|
|
|
* @ORM\Column(type="datetime", name="datetime_added", options={"default"="CURRENT_TIMESTAMP"})
|
2019-03-20 22:30:03 +01:00
|
|
|
*/
|
|
|
|
protected $addedDate;
|
|
|
|
|
2020-01-05 22:32:19 +01:00
|
|
|
/** *************************************************************
|
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 = '';
|
|
|
|
|
2019-03-20 19:11:34 +01:00
|
|
|
/**
|
2019-09-17 13:57:40 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
2019-09-16 21:40:47 +02:00
|
|
|
* @ColumnSecurity(type="collection", prefix="attachments")
|
2019-08-19 23:31:16 +02:00
|
|
|
* @Assert\Valid()
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-09-16 21:40:47 +02:00
|
|
|
protected $attachments;
|
2019-08-12 15:47:57 +02:00
|
|
|
|
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();
|
2019-08-30 14:25:05 +02:00
|
|
|
$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-03-20 23:16:07 +01:00
|
|
|
*
|
2019-02-23 22:41:13 +01:00
|
|
|
* @return string The ID as a string;
|
|
|
|
*/
|
|
|
|
public function getIDString(): string
|
|
|
|
{
|
2019-11-09 00:47:20 +01:00
|
|
|
return 'P'.sprintf('%06d', $this->getID());
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all devices which uses this part.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +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)
|
2019-03-13 13:23:12 +01:00
|
|
|
* * the array is sorted by the devices names
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
2019-03-20 23:16:07 +01:00
|
|
|
public function getDevices(): array
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
return $this->devices;
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|