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

@ -52,7 +52,9 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\CategoryAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -63,6 +65,13 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Category extends PartsContainingDBElement
{
/**
* @var Collection|CategoryAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
*/

View file

@ -61,7 +61,10 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -72,6 +75,12 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Footprint extends PartsContainingDBElement
{
/**
* @var Collection|FootprintAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\FootprintAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Footprint", mappedBy="parent")
*/
@ -83,22 +92,17 @@ class Footprint extends PartsContainingDBElement
*/
protected $parent;
/**
* @var string
* @ORM\Column(type="text")
*/
protected $filename;
/**
* @ORM\OneToMany(targetEntity="Part", mappedBy="footprint", fetch="EXTRA_LAZY")
*/
protected $parts;
/**
* @var string
* @ORM\Column(type="text")
* @var FootprintAttachment
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\FootprintAttachment")
* @ORM\JoinColumn(name="id_footprint_3d", referencedColumnName="id")
*/
protected $filename_3d;
protected $footprint_3d;
/**
* Returns the ID as an string, defined by the element class.

View file

@ -61,7 +61,10 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Base\Company;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -72,6 +75,13 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Manufacturer extends Company
{
/**
* @var Collection|ManufacturerAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Manufacturer", mappedBy="parent")
*/

View file

@ -32,7 +32,10 @@
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\MeasurementUnitAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
@ -49,6 +52,12 @@ use Symfony\Component\Validator\Constraints as Assert;
class MeasurementUnit extends PartsContainingDBElement
{
/**
* @var Collection|MeasurementUnitAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\MeasurementUnitAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @var string The unit symbol that should be used for the Unit. This could be something like "", g (for gramms)
* or m (for meters).

View file

@ -64,7 +64,7 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Devices\Device;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
use App\Entity\Parts\PartTraits\MasterAttachmentTrait;
use App\Entity\Base\MasterAttachmentTrait;
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
use App\Entity\Parts\PartTraits\InstockTrait;
use App\Entity\Parts\PartTraits\ManufacturerTrait;
@ -87,7 +87,7 @@ use Symfony\Component\Validator\Constraints as Assert;
class Part extends AttachmentContainingDBElement
{
use AdvancedPropertyTrait;
use MasterAttachmentTrait;
//use MasterAttachmentTrait;
use BasicPropertyTrait;
use InstockTrait;
use ManufacturerTrait;

View file

@ -1,77 +0,0 @@
<?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\Parts\PartTraits;
use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
/**
* A entity with this class has a master attachment, which is used as a preview image for this object.
* @package App\Entity\Parts\PartTraits
*/
trait MasterAttachmentTrait
{
/**
* @var Attachment
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\Attachment")
* @ORM\JoinColumn(name="id_master_picture_attachement", referencedColumnName="id")
* @Assert\Expression("value == null or value.isPicture()", message="part.master_attachment.must_be_picture")
* @ColumnSecurity(prefix="attachments", type="object")
*/
protected $master_picture_attachment;
/**
* Get the master picture "Attachment"-object of this part (if there is one).
* The master picture should be used as a visual description/representation of this part.
* @return Attachment the master picture Attachement of this part (if there is one)
*/
public function getMasterPictureAttachment(): ?Attachment
{
return $this->master_picture_attachment;
}
/**
* Sets the new master picture for this part.
* @param Attachment|null $new_master_attachment
* @return Part
*/
public function setMasterPictureAttachment(?Attachment $new_master_attachment): self
{
$this->master_picture_attachment = $new_master_attachment;
return $this;
}
}

View file

@ -61,7 +61,10 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Base\PartsContainingDBElement;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -72,6 +75,13 @@ use Doctrine\ORM\Mapping as ORM;
*/
class Storelocation extends PartsContainingDBElement
{
/**
* @var Collection|StorelocationAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Storelocation", mappedBy="parent")
*/

View file

@ -61,9 +61,12 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use App\Entity\Attachments\ManufacturerAttachment;
use App\Entity\Attachments\SupplierAttachment;
use App\Entity\Base\Company;
use App\Entity\PriceInformations\Currency;
use App\Validator\Constraints\Selectable;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@ -75,6 +78,12 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
class Supplier extends Company
{
/**
* @var Collection|SupplierAttachment[]
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element")
*/
protected $attachments;
/**
* @ORM\OneToMany(targetEntity="Supplier", mappedBy="parent")
*/