mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-28 12:40:08 +02:00
Added a basic possibility to create/edit/delete specifications for parts.
This commit is contained in:
parent
502febb008
commit
a6e0f1738b
15 changed files with 1359 additions and 765 deletions
|
@ -50,6 +50,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
*/
|
||||
abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
|
||||
{
|
||||
use SpecificationsTrait;
|
||||
|
||||
public const ID_ROOT_ELEMENT = 0;
|
||||
|
||||
/**
|
||||
|
|
54
src/Entity/Base/SpecificationsTrait.php
Normal file
54
src/Entity/Base/SpecificationsTrait.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Base;
|
||||
|
||||
|
||||
use App\Entity\Specifications\Specification;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
trait SpecificationsTrait
|
||||
{
|
||||
/**
|
||||
* @var Specification[]
|
||||
* @ORM\Column(type="json_document")
|
||||
* @Assert\Valid()
|
||||
*/
|
||||
protected $specifications = [];
|
||||
|
||||
/**
|
||||
* Return all associated specifications
|
||||
* @return Specification[]
|
||||
*/
|
||||
public function getSpecifications(): array
|
||||
{
|
||||
return $this->specifications ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $specifications
|
||||
* @return $this
|
||||
*/
|
||||
public function setSpecifications(array $specifications): self
|
||||
{
|
||||
$this->specifications = $specifications;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -52,6 +52,7 @@ namespace App\Entity\Parts;
|
|||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Base\SpecificationsTrait;
|
||||
use App\Entity\Devices\Device;
|
||||
use App\Entity\Parts\PartTraits\AdvancedPropertyTrait;
|
||||
use App\Entity\Parts\PartTraits\BasicPropertyTrait;
|
||||
|
@ -81,6 +82,7 @@ class Part extends AttachmentContainingDBElement
|
|||
use InstockTrait;
|
||||
use ManufacturerTrait;
|
||||
use OrderTrait;
|
||||
use SpecificationsTrait;
|
||||
|
||||
/**
|
||||
* TODO.
|
||||
|
|
214
src/Entity/Specifications/Specification.php
Normal file
214
src/Entity/Specifications/Specification.php
Normal file
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\Specifications;
|
||||
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class Specification
|
||||
{
|
||||
/**
|
||||
* @var string The name of the specification (e.g. "Collector-Base Voltage"). Required!
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name = "";
|
||||
|
||||
/**
|
||||
* @var string The mathematical symbol for this specification. Can be rendered pretty later. Should be short
|
||||
* @Assert\Length(max=10)
|
||||
*/
|
||||
protected $symbol = "";
|
||||
|
||||
/**
|
||||
* @var float|null The guaranteed minimum value of this property.
|
||||
* @Assert\Type({"float","null"})
|
||||
* @Assert\LessThanOrEqual(propertyPath="value_typical")
|
||||
* @Assert\LessThan(propertyPath="value_max")
|
||||
*/
|
||||
protected $value_min;
|
||||
|
||||
/**
|
||||
* @var float|null The typical value of this property.
|
||||
* @Assert\Type({"null", "float"})
|
||||
*/
|
||||
protected $value_typical;
|
||||
|
||||
/**
|
||||
* @var float|null The maximum value of this property.
|
||||
* @Assert\Type({"float", "null"})
|
||||
* @Assert\GreaterThanOrEqual(propertyPath="value_typical")
|
||||
*/
|
||||
protected $value_max;
|
||||
|
||||
/**
|
||||
* @var string The unit in which the value values are given (e.g. V)
|
||||
* @Assert\Length(max=5)
|
||||
*/
|
||||
protected $unit = "";
|
||||
|
||||
/**
|
||||
* @var string A text value for the given property.
|
||||
*
|
||||
*/
|
||||
protected $value_text = "";
|
||||
|
||||
/**
|
||||
* Returns the name of the specification (e.g. "Collector-Base Voltage").
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the specification. This value is required.
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName(string $name): Specification
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mathematical symbol for this specification (e.g. "V_CB")
|
||||
* @return string
|
||||
*/
|
||||
public function getSymbol(): string
|
||||
{
|
||||
return $this->symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mathematical symbol for this specification (e.g. "V_CB")
|
||||
* @param string $symbol
|
||||
* @return $this
|
||||
*/
|
||||
public function setSymbol(string $symbol): Specification
|
||||
{
|
||||
$this->symbol = $symbol;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns The guaranteed minimum value of this property.
|
||||
* @return float|null
|
||||
*/
|
||||
public function getValueMin(): ?float
|
||||
{
|
||||
return $this->value_min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum value of this property.
|
||||
* @param float|null $value_min
|
||||
* @return $this
|
||||
*/
|
||||
public function setValueMin(?float $value_min): Specification
|
||||
{
|
||||
$this->value_min = $value_min;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the typical value of this property.
|
||||
* @return float|null
|
||||
*/
|
||||
public function getValueTypical(): ?float
|
||||
{
|
||||
return $this->value_typical;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the typical value of this property
|
||||
* @param float $value_typical
|
||||
* @return $this
|
||||
*/
|
||||
public function setValueTypical(?float $value_typical): Specification
|
||||
{
|
||||
$this->value_typical = $value_typical;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the guaranteed maximum value
|
||||
* @return float|null
|
||||
*/
|
||||
public function getValueMax(): ?float
|
||||
{
|
||||
return $this->value_max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the guaranteed maximum value
|
||||
* @param float|null $value_max
|
||||
* @return $this
|
||||
*/
|
||||
public function setValueMax(?float $value_max): Specification
|
||||
{
|
||||
$this->value_max = $value_max;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unit used by the value (e.g. "V")
|
||||
* @return string
|
||||
*/
|
||||
public function getUnit(): string
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unit used by the value.
|
||||
* @param string $unit
|
||||
* @return $this
|
||||
*/
|
||||
public function setUnit(string $unit): Specification
|
||||
{
|
||||
$this->unit = $unit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text value.
|
||||
* @return string
|
||||
*/
|
||||
public function getValueText(): string
|
||||
{
|
||||
return $this->value_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text value.
|
||||
* @param string $value_text
|
||||
* @return $this
|
||||
*/
|
||||
public function setValueText(string $value_text): Specification
|
||||
{
|
||||
$this->value_text = $value_text;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue