. */ declare(strict_types=1); namespace App\Entity\Parts; use App\Repository\Parts\MeasurementUnitRepository; use Doctrine\DBAL\Types\Types; use App\Entity\Base\AbstractStructuralDBElement; use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attachments\MeasurementUnitAttachment; use App\Entity\Base\AbstractPartsContainingDBElement; use App\Entity\Parameters\MeasurementUnitParameter; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; /** * This unit represents the unit in which the amount of parts in stock are measured. * This could be something like N, grams, meters, etc... * * @extends AbstractPartsContainingDBElement */ #[UniqueEntity('unit')] #[ORM\Entity(repositoryClass: MeasurementUnitRepository::class)] #[ORM\Table(name: '`measurement_units`')] #[ORM\Index(name: 'unit_idx_name', columns: ['name'])] #[ORM\Index(name: 'unit_idx_parent_name', columns: ['parent_id', 'name'])] class MeasurementUnit extends AbstractPartsContainingDBElement { /** * @var string The unit symbol that should be used for the Unit. This could be something like "", g (for grams) * or m (for meters). */ #[Assert\Length(max: 10)] #[Groups(['extended', 'full', 'import'])] #[ORM\Column(type: Types::STRING, name: 'unit', nullable: true)] protected ?string $unit = null; /** * @var bool Determines if the amount value associated with this unit should be treated as integer. * Set to false, to measure continuous sizes likes masses or lengths. */ #[Groups(['extended', 'full', 'import'])] #[ORM\Column(type: Types::BOOLEAN, name: 'is_integer')] protected bool $is_integer = false; /** * @var bool Determines if the unit can be used with SI Prefixes (kilo, giga, milli, etc.). * Useful for sizes like meters. For this the unit must be set */ #[Assert\Expression('this.isUseSIPrefix() == false or this.getUnit() != null', message: 'validator.measurement_unit.use_si_prefix_needs_unit')] #[Groups(['full', 'import'])] #[ORM\Column(type: Types::BOOLEAN, name: 'use_si_prefix')] protected bool $use_si_prefix = false; #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent', cascade: ['persist'])] #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $children; #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] #[ORM\JoinColumn(name: 'parent_id')] protected ?AbstractStructuralDBElement $parent = null; /** * @var Collection */ #[Assert\Valid] #[ORM\OneToMany(targetEntity: MeasurementUnitAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['name' => 'ASC'])] protected Collection $attachments; /** @var Collection */ #[Assert\Valid] #[ORM\OneToMany(targetEntity: MeasurementUnitParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])] protected Collection $parameters; /** * @return string */ public function getUnit(): ?string { return $this->unit; } public function setUnit(?string $unit): self { $this->unit = $unit; return $this; } public function isInteger(): bool { return $this->is_integer; } public function setIsInteger(bool $isInteger): self { $this->is_integer = $isInteger; return $this; } public function isUseSIPrefix(): bool { return $this->use_si_prefix; } public function setUseSIPrefix(bool $usesSIPrefixes): self { $this->use_si_prefix = $usesSIPrefixes; return $this; } public function __construct() { parent::__construct(); $this->children = new ArrayCollection(); $this->attachments = new ArrayCollection(); $this->parameters = new ArrayCollection(); } }