2019-03-20 23:16:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-02-23 22:41:13 +01:00
|
|
|
/**
|
|
|
|
* Part-DB Version 0.4+ "nextgen"
|
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer
|
2019-03-20 23:16:07 +01:00
|
|
|
* https://github.com/jbtronics.
|
2019-02-23 22:41:13 +01: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
2019-03-28 19:24:34 +01:00
|
|
|
use App\Validator\Constraints\NoneOfItsChildren;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-04-05 17:49:02 +02:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2019-02-23 22:41:13 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Class AttachmentType.
|
|
|
|
*
|
2019-03-25 12:44:44 +01:00
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository")
|
2019-02-23 22:41:13 +01:00
|
|
|
* @ORM\Table(name="attachement_types")
|
|
|
|
*/
|
|
|
|
class AttachmentType extends StructuralDBElement
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ArrayCollection
|
|
|
|
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachement_type")
|
|
|
|
*/
|
2019-03-20 22:53:06 +01:00
|
|
|
protected $attachments;
|
2019-02-23 22:41:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-04-11 22:41:21 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent", cascade={"persist"})
|
2019-02-23 22:41:13 +01:00
|
|
|
*/
|
|
|
|
protected $children;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="children")
|
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
protected $parent;
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* Get all attachements ("Attachement" objects) with this type.
|
2019-02-23 22:41:13 +01:00
|
|
|
*
|
2019-03-20 23:16:07 +01:00
|
|
|
* @return Attachment[] all attachements with this type, as a one-dimensional array of Attachement-objects
|
2019-02-23 22:41:13 +01:00
|
|
|
* (sorted by their names)
|
|
|
|
*/
|
2019-04-05 17:49:02 +02:00
|
|
|
public function getAttachementsForType(): Collection
|
2019-02-23 22:41:13 +01:00
|
|
|
{
|
|
|
|
// the attribute $this->attachements is used from class "AttachementsContainingDBELement"
|
2019-03-20 23:16:07 +01:00
|
|
|
if (null === $this->attachments) {
|
2019-02-23 22:41:13 +01:00
|
|
|
$this->attachments = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->attachments;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-07 19:30:42 +02:00
|
|
|
return 'AT' . sprintf('%09d', $this->getID());
|
2019-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|