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

83 lines
2.6 KiB
PHP
Raw Normal View History

<?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
* 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;
use App\Validator\Constraints\NoneOfItsChildren;
2019-02-23 22:41:13 +01:00
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
2019-02-23 22:41:13 +01:00
use Doctrine\ORM\Mapping as ORM;
/**
* 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
/**
* @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;
/**
* Get all attachements ("Attachement" objects) with this type.
2019-02-23 22:41:13 +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)
*/
public function getAttachementsForType(): Collection
2019-02-23 22:41:13 +01:00
{
// the attribute $this->attachements is used from class "AttachementsContainingDBELement"
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-02-23 22:41:13 +01:00
* @return string The ID as a string;
*/
public function getIDString(): string
{
return 'AT' . sprintf('%09d', $this->getID());
2019-02-23 22:41:13 +01:00
}
}