Added some basic DB fields for the new project system

This commit is contained in:
Jan Böhmer 2022-12-18 20:34:25 +01:00
parent 8ae4e9fe05
commit 0c7ec9f0c7
36 changed files with 281 additions and 130 deletions

View file

@ -44,7 +44,7 @@ use LogicException;
* @ORM\DiscriminatorColumn(name="class_name", type="string")
* @ORM\DiscriminatorMap({
* "PartDB\Part" = "PartAttachment", "Part" = "PartAttachment",
* "PartDB\Device" = "DeviceAttachment", "Device" = "DeviceAttachment",
* "PartDB\Device" = "ProjectAttachment", "Device" = "ProjectAttachment",
* "AttachmentType" = "AttachmentTypeAttachment", "Category" = "CategoryAttachment",
* "Footprint" = "FootprintAttachment", "Manufacturer" = "ManufacturerAttachment",
* "Currency" = "CurrencyAttachment", "Group" = "GroupAttachment",

View file

@ -22,7 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Attachments;
use App\Entity\Devices\Device;
use App\Entity\ProjectSystem\Project;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@ -32,12 +32,12 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
* @ORM\Entity()
* @UniqueEntity({"name", "attachment_type", "element"})
*/
class DeviceAttachment extends Attachment
class ProjectAttachment extends Attachment
{
public const ALLOWED_ELEMENT_CLASS = Device::class;
public const ALLOWED_ELEMENT_CLASS = Project::class;
/**
* @var Device the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="attachments")
* @var Project the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\ProjectSystem\Project", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected ?AttachmentContainingDBElement $element = null;

View file

@ -29,6 +29,7 @@ use Doctrine\ORM\Mapping as ORM;
*
* @ORM\MappedSuperclass(repositoryClass="App\Repository\AbstractPartsContainingRepository")
*/
abstract class AbstractPartsContainingDBElement extends AbstractStructuralDBElement
abstract class
AbstractPartsContainingDBElement extends AbstractStructuralDBElement
{
}

View file

@ -25,8 +25,8 @@ namespace App\Entity\LogSystem;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Devices\Device;
use App\Entity\Devices\DevicePart;
use App\Entity\ProjectSystem\Project;
use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category;
@ -124,8 +124,8 @@ abstract class AbstractLogEntry extends AbstractDBElement
self::TARGET_TYPE_ATTACHEMENT => Attachment::class,
self::TARGET_TYPE_ATTACHEMENTTYPE => AttachmentType::class,
self::TARGET_TYPE_CATEGORY => Category::class,
self::TARGET_TYPE_DEVICE => Device::class,
self::TARGET_TYPE_DEVICEPART => DevicePart::class,
self::TARGET_TYPE_DEVICE => Project::class,
self::TARGET_TYPE_DEVICEPART => ProjectBOMEntry::class,
self::TARGET_TYPE_FOOTPRINT => Footprint::class,
self::TARGET_TYPE_GROUP => Group::class,
self::TARGET_TYPE_MANUFACTURER => Manufacturer::class,

View file

@ -46,7 +46,7 @@ use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Attachments\CategoryAttachment;
use App\Entity\Attachments\CurrencyAttachment;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Attachments\ProjectAttachment;
use App\Entity\Attachments\FootprintAttachment;
use App\Entity\Attachments\GroupAttachment;
use App\Entity\Attachments\ManufacturerAttachment;
@ -58,12 +58,12 @@ use App\Entity\Attachments\UserAttachment;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\LogWithEventUndoInterface;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Devices\Device;
use App\Entity\ProjectSystem\Project;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parameters\AttachmentTypeParameter;
use App\Entity\Parameters\CategoryParameter;
use App\Entity\Parameters\CurrencyParameter;
use App\Entity\Parameters\DeviceParameter;
use App\Entity\Parameters\ProjectParameter;
use App\Entity\Parameters\FootprintParameter;
use App\Entity\Parameters\GroupParameter;
use App\Entity\Parameters\ManufacturerParameter;
@ -159,8 +159,8 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
return CategoryParameter::class;
case Currency::class:
return CurrencyParameter::class;
case Device::class:
return DeviceParameter::class;
case Project::class:
return ProjectParameter::class;
case Footprint::class:
return FootprintParameter::class;
case Group::class:
@ -189,8 +189,8 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
return CategoryAttachment::class;
case Currency::class:
return CurrencyAttachment::class;
case Device::class:
return DeviceAttachment::class;
case Project::class:
return ProjectAttachment::class;
case Footprint::class:
return FootprintAttachment::class;
case Group::class:

View file

@ -62,7 +62,7 @@ use function sprintf;
* @ORM\DiscriminatorMap({
* 0 = "CategoryParameter",
* 1 = "CurrencyParameter",
* 2 = "DeviceParameter",
* 2 = "ProjectParameter",
* 3 = "FootprintParameter",
* 4 = "GroupParameter",
* 5 = "ManufacturerParameter",

View file

@ -41,7 +41,7 @@ declare(strict_types=1);
namespace App\Entity\Parameters;
use App\Entity\Devices\Device;
use App\Entity\ProjectSystem\Project;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@ -49,13 +49,13 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
* @ORM\Entity(repositoryClass="App\Repository\ParameterRepository")
* @UniqueEntity(fields={"name", "group", "element"})
*/
class DeviceParameter extends AbstractParameter
class ProjectParameter extends AbstractParameter
{
public const ALLOWED_ELEMENT_CLASS = Device::class;
public const ALLOWED_ELEMENT_CLASS = Project::class;
/**
* @var Device the element this para is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="parameters")
* @var Project the element this para is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\ProjectSystem\Project", inversedBy="parameters")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/
protected $element;

View file

@ -25,7 +25,7 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Devices\Device;
use App\Entity\ProjectSystem\Project;
use App\Entity\Parameters\ParametersTrait;
use App\Entity\Parameters\PartParameter;
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
@ -152,7 +152,7 @@ class Part extends AttachmentContainingDBElement
/**
* Get all devices which uses this part.
*
* @return Device[] * all devices which uses this part as a one-dimensional array of Device objects
* @return Project[] * all devices which uses this part as a one-dimensional array of Device objects
* (empty array if there are no ones)
* * the array is sorted by the devices names
*/

View file

@ -20,11 +20,12 @@
declare(strict_types=1);
namespace App\Entity\Devices;
namespace App\Entity\ProjectSystem;
use App\Entity\Attachments\DeviceAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\DeviceParameter;
use App\Entity\Attachments\ProjectAttachment;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\ProjectParameter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
@ -33,27 +34,27 @@ use InvalidArgumentException;
* Class AttachmentType.
*
* @ORM\Entity(repositoryClass="App\Repository\Parts\DeviceRepository")
* @ORM\Table(name="`devices`")
* @ORM\Table(name="devices")
*/
class Device extends AbstractPartsContainingDBElement
class Project extends AbstractStructuralDBElement
{
/**
* @ORM\OneToMany(targetEntity="Device", mappedBy="parent")
* @ORM\OneToMany(targetEntity="Project", mappedBy="parent")
* @ORM\OrderBy({"name" = "ASC"})
* @var Collection
*/
protected $children;
/**
* @ORM\ManyToOne(targetEntity="Device", inversedBy="children")
* @ORM\ManyToOne(targetEntity="Project", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="DevicePart", mappedBy="device")
* @ORM\OneToMany(targetEntity="ProjectBOMEntry", mappedBy="device")
*/
protected $parts;
protected $bom_entries;
/**
* @ORM\Column(type="integer")
@ -64,15 +65,21 @@ class Device extends AbstractPartsContainingDBElement
* @ORM\Column(type="boolean")
*/
protected bool $order_only_missing_parts = false;
/**
* @var Collection<int, DeviceAttachment>
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\DeviceAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\Column(type="text", nullable=false)
*/
protected string $description = '';
/**
* @var Collection<int, ProjectAttachment>
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ProjectAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $attachments;
/** @var Collection<int, DeviceParameter>
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\DeviceParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
/** @var Collection<int, ProjectParameter>
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\ProjectParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
*/
protected $parameters;
@ -83,6 +90,12 @@ class Device extends AbstractPartsContainingDBElement
*
*********************************************************************************/
public function __construct()
{
parent::__construct();
$this->bom_entries = new ArrayCollection();
}
/**
* Get the order quantity of this device.
*
@ -131,7 +144,7 @@ class Device extends AbstractPartsContainingDBElement
*
* @param bool $new_order_only_missing_parts the new "order_only_missing_parts" attribute
*
* @return Device
* @return Project
*/
public function setOrderOnlyMissingParts(bool $new_order_only_missing_parts): self
{
@ -139,4 +152,42 @@ class Device extends AbstractPartsContainingDBElement
return $this;
}
/**
* @return mixed
*/
public function getBomEntries()
{
return $this->bom_entries;
}
/**
* @param mixed $bom_entries
* @return Project
*/
public function setBomEntries($bom_entries)
{
$this->bom_entries = $bom_entries;
return $this;
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* @param string $description
* @return Project
*/
public function setDescription(string $description): Project
{
$this->description = $description;
return $this;
}
}

View file

@ -20,42 +20,60 @@
declare(strict_types=1);
namespace App\Entity\Devices;
namespace App\Entity\ProjectSystem;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\TimestampTrait;
use App\Entity\Parts\Part;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class DevicePart.
* The ProjectBOMEntry class represents a entry in a project's BOM.
*
* @ORM\Table("`device_parts`")
* @ORM\Table("device_parts")
* @ORM\Entity()
*/
class DevicePart extends AbstractDBElement
class ProjectBOMEntry extends AbstractDBElement
{
/**
* @var int
* @ORM\Column(type="integer", name="quantity")
*/
protected int $quantity;
use TimestampTrait;
/**
* @var string
* @var int
* @ORM\Column(type="float", name="quantity")
* @Assert\PositiveOrZero()
*/
protected float $quantity;
/**
* @var string A comma separated list of the names, where this parts should be placed
* @ORM\Column(type="text", name="mountnames")
*/
protected string $mountnames;
/**
* @var Device
* @ORM\ManyToOne(targetEntity="Device", inversedBy="parts")
* @ORM\JoinColumn(name="id_device", referencedColumnName="id")
*/
protected ?Device $device = null;
/**
* @var Part
* @var string An optional name describing this BOM entry (useful for non-part entries)
* @ORM\Column(type="text")
*/
protected string $name;
/**
* @var string An optional comment for this BOM entry
* @ORM\Column(type="text")
*/
protected string $comment;
/**
* @var Project
* @ORM\ManyToOne(targetEntity="Project", inversedBy="parts")
* @ORM\JoinColumn(name="id_device", referencedColumnName="id")
*/
protected ?Project $device = null;
/**
* @var Part|null The part associated with this
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part")
* @ORM\JoinColumn(name="id_part", referencedColumnName="id")
* @ORM\JoinColumn(name="id_part", referencedColumnName="id", nullable=true)
*/
protected ?Part $part = null;
}