2020-03-08 22:46:29 +01:00
|
|
|
<?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/>.
|
|
|
|
*/
|
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
namespace App\Entity\Parameters;
|
2020-03-08 22:46:29 +01:00
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
use App\Entity\Base\AbstractDBElement;
|
|
|
|
use App\Entity\Base\AbstractNamedDBElement;
|
|
|
|
use App\Repository\DBElementRepository;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use LogicException;
|
2020-03-08 22:46:29 +01:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
/**
|
|
|
|
* @ORM\Entity()
|
|
|
|
* @ORM\Table("parameters")
|
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE")
|
|
|
|
* @ORM\DiscriminatorColumn(name="type", type="smallint")
|
|
|
|
* @ORM\DiscriminatorMap({
|
|
|
|
* 0 = "CategoryParameter",
|
|
|
|
* 1 = "CurrencyParameter",
|
|
|
|
* 2 = "DeviceParameter",
|
|
|
|
* 3 = "FootprintParameter",
|
|
|
|
* 4 = "GroupParameter",
|
|
|
|
* 5 = "ManufacturerParameter",
|
|
|
|
* 6 = "MeasurementUnitParameter",
|
|
|
|
* 7 = "PartParameter",
|
|
|
|
* 8 = "StorelocationParameter",
|
|
|
|
* 9 = "SupplierParameter",
|
|
|
|
* 10 = "AttachmentTypeParameter"
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
abstract class AbstractParameter extends AbstractNamedDBElement
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
2020-03-11 21:48:47 +01:00
|
|
|
/**
|
|
|
|
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
|
|
|
|
*/
|
|
|
|
public const ALLOWED_ELEMENT_CLASS = '';
|
|
|
|
|
2020-03-08 22:46:29 +01:00
|
|
|
/**
|
|
|
|
* @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)
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="string", nullable=false)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
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")
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="float", nullable=true)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
protected $value_min;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float|null The typical value of this property.
|
|
|
|
* @Assert\Type({"null", "float"})
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="float", nullable=true)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
protected $value_typical;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var float|null The maximum value of this property.
|
|
|
|
* @Assert\Type({"float", "null"})
|
|
|
|
* @Assert\GreaterThanOrEqual(propertyPath="value_typical")
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="float", nullable=true)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
protected $value_max;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The unit in which the value values are given (e.g. V)
|
|
|
|
* @Assert\Length(max=5)
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="string", nullable=false)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
protected $unit = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string A text value for the given property.
|
2020-03-11 21:48:47 +01:00
|
|
|
* @ORM\Column(type="string", nullable=false)
|
2020-03-08 22:46:29 +01:00
|
|
|
*/
|
|
|
|
protected $value_text = "";
|
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
/**
|
|
|
|
* @var string The group this parameter belongs to.
|
|
|
|
* @ORM\Column(type="string", nullable=false, name="param_group")
|
|
|
|
*/
|
|
|
|
protected $group = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mapping is done in sub classes
|
|
|
|
* @var AbstractDBElement|null The element to which this parameter belongs to.
|
|
|
|
*/
|
|
|
|
protected $element;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
if ('' === static::ALLOWED_ELEMENT_CLASS) {
|
|
|
|
throw new LogicException('An *Attachment class must override the ALLOWED_ELEMENT_CLASS const!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 22:46:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the name of the specification (e.g. "Collector-Base Voltage").
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName(): string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
/**
|
|
|
|
* Returns the element this parameter belongs to.
|
|
|
|
* @return AbstractDBElement|null
|
|
|
|
*/
|
|
|
|
public function getElement(): ?AbstractDBElement
|
|
|
|
{
|
|
|
|
return $this->element;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the element to which this parameter belongs to.
|
|
|
|
* @param AbstractDBElement $element
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function setElement(AbstractDBElement $element): self
|
|
|
|
{
|
|
|
|
if (! is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
|
|
|
|
throw new InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->element = $element;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-08 22:46:29 +01:00
|
|
|
/**
|
|
|
|
* Sets the name of the specification. This value is required.
|
|
|
|
* @param string $name
|
|
|
|
* @return $this
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setName(string $name): AbstractNamedDBElement
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setSymbol(string $symbol): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setValueMin(?float $value_min): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setValueTypical(?float $value_typical): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setValueMax(?float $value_max): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setUnit(string $unit): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
2020-03-11 21:48:47 +01:00
|
|
|
public function setValueText(string $value_text): self
|
2020-03-08 22:46:29 +01:00
|
|
|
{
|
|
|
|
$this->value_text = $value_text;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:48:47 +01:00
|
|
|
public function getIDString(): string
|
|
|
|
{
|
|
|
|
return 'PM'.sprintf('%09d', $this->getID());
|
|
|
|
}
|
2020-03-08 22:46:29 +01:00
|
|
|
}
|