Changed DB structure the way, many more elements can have attachments

Also every Element has now a preview attachment field. For the user this will be used as profile picture.
This commit is contained in:
Jan Böhmer 2019-09-24 13:39:49 +02:00
parent 5061c29872
commit ccc345cd1b
28 changed files with 985 additions and 28 deletions

View file

@ -34,7 +34,15 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="`attachments`")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="class_name", type="string")
* @ORM\DiscriminatorMap({"PartDB\Part" = "PartAttachment", "Part" = "PartAttachment"})
* @ORM\DiscriminatorMap({
* "PartDB\Part" = "PartAttachment", "Part" = "PartAttachment",
* "PartDB\Device" = "DeviceAttachment", "Device" = "DeviceAttachment",
* "AttachmentType" = "AttachmentTypeAttachment", "Category" = "CategoryAttachment",
* "Footprint" = "FootprintAttachment", "Manufacturer" = "ManufacturerAttachment",
* "Currency" = "CurrencyAttachment", "Group" = "GroupAttachment",
* "MeasurementUnit" = "MeasurementUnitAttachment", "Storelocation" = "StorelocationAttachment",
* "Supplier" = "SupplierAttachment", "User" = "UserAttachment"
* })
* @ORM\EntityListeners({"App\EntityListeners\AttachmentDeleteListener"})
*
*/
@ -56,11 +64,17 @@ abstract class Attachment extends NamedDBElement
protected $show_in_table = false;
/**
* @var string The filename using the %BASE% variable
* @ORM\Column(type="string", name="filename")
* @var string The path to the file relative to a placeholder path like %MEDIA%
* @ORM\Column(type="string", name="path")
*/
protected $path = '';
/**
* @var string The original filenamethe file had, when the user uploaded it.
* @ORM\Column(type="string", nullable=true)
*/
protected $original_filename;
/**
* ORM mapping is done in sub classes (like PartAttachment)
*/
@ -68,7 +82,7 @@ abstract class Attachment extends NamedDBElement
/**
* @var AttachmentType
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="attachments")
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="attachments_with_type")
* @ORM\JoinColumn(name="type_id", referencedColumnName="id")
* @Selectable()
*/

View file

@ -52,16 +52,20 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Base\NamedDBElement;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\MappedSuperclass()
*/
abstract class AttachmentContainingDBElement extends NamedDBElement
{
use MasterAttachmentTrait;
/**
* @var Attachment[]
* //TODO

View file

@ -66,11 +66,17 @@ use Doctrine\ORM\Mapping as ORM;
class AttachmentType extends StructuralDBElement
{
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachment_type")
* @var Collection|AttachmentTypeAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\AttachmentTypeAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @var Collection|Attachment[]
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachment_type")
*/
protected $attachments_with_type;
/**
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent", cascade={"persist"})
*/

View file

@ -0,0 +1,61 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to an attachmentType element.
* @package App\Entity
* @ORM\Entity()
*/
class AttachmentTypeAttachment extends Attachment
{
/**
* @var AttachmentType The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof AttachmentType) {
throw new \InvalidArgumentException('The element associated with a AttachmentTypeAttachment must be an AttachmentType!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a category element.
* @package App\Entity
* @ORM\Entity()
*/
class CategoryAttachment extends Attachment
{
/**
* @var Category The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Category) {
throw new \InvalidArgumentException('The element associated with a CategoryAttachment must be a Category!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a currency element.
* @package App\Entity
* @ORM\Entity()
*/
class CurrencyAttachment extends Attachment
{
/**
* @var Currency The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Currency) {
throw new \InvalidArgumentException('The element associated with a CurrencyAttachment must be a Currency!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,62 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a device element.
* @package App\Entity
* @ORM\Entity()
*/
class DeviceAttachment extends Attachment
{
/**
* @var Device The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Device) {
throw new \InvalidArgumentException('The element associated with a PartAttachment must be a Device!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a footprint element.
* @package App\Entity
* @ORM\Entity()
*/
class FootprintAttachment extends Attachment
{
/**
* @var Footprint The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Footprint) {
throw new \InvalidArgumentException('The element associated with a FootprintAttachment must be a Footprint!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,69 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a Group element.
* @package App\Entity
* @ORM\Entity()
*/
class GroupAttachment extends Attachment
{
/**
* @var Group The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Group) {
throw new \InvalidArgumentException('The element associated with a UserAttachment must be a User!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a manufacturer element.
* @package App\Entity
* @ORM\Entity()
*/
class ManufacturerAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Manufacturer) {
throw new \InvalidArgumentException('The element associated with a ManufacturerAttachment must be a Manufacturer!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,64 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
* @ORM\Entity()
*/
class MeasurementUnitAttachment extends Attachment
{
/**
* @var Manufacturer The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof MeasurementUnit) {
throw new \InvalidArgumentException('The element associated with a MeasurementUnitAttachmentAttachment must be a MeasurementUnit!');
}
$this->element = $element;
return $this;
}
}

View file

@ -35,7 +35,7 @@ use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
/**
* Class PartAttachment
* A attachment attached to a part element.
* @package App\Entity
* @ORM\Entity()
*/
@ -43,7 +43,7 @@ class PartAttachment extends Attachment
{
/**
*
* @var Part The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
@ -56,7 +56,6 @@ class PartAttachment extends Attachment
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a measurement unit element.
* @package App\Entity
* @ORM\Entity()
*/
class StorelocationAttachment extends Attachment
{
/**
* @var Storelocation The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Storelocation) {
throw new \InvalidArgumentException('The element associated with a StorelocationAttachment must be a Storelocation!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a supplier element.
* @package App\Entity
* @ORM\Entity()
*/
class SupplierAttachment extends Attachment
{
/**
* @var Supplier The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof Supplier) {
throw new \InvalidArgumentException('The element associated with a SupplierAttachment must be a Supplier!');
}
$this->element = $element;
return $this;
}
}

View file

@ -0,0 +1,68 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* 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
*
*/
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
/**
* A attachment attached to a user element.
* @package App\Entity
* @ORM\Entity()
*/
class UserAttachment extends Attachment
{
/**
* @var User The element this attachment is associated with.
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;
public function setElement(AttachmentContainingDBElement $element): Attachment
{
if (!$element instanceof User) {
throw new \InvalidArgumentException('The element associated with a UserAttachment must be a User!');
}
$this->element = $element;
return $this;
}
}