Improved serialized fields

This commit is contained in:
Jan Böhmer 2023-03-12 01:12:35 +01:00
parent b99e6c9a21
commit 2c67586873
18 changed files with 84 additions and 1 deletions

View file

@ -27,6 +27,7 @@ use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\CategoryParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -56,48 +57,56 @@ class Category extends AbstractPartsContainingDBElement
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"full"})
*/
protected string $partname_hint = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"full"})
*/
protected string $partname_regex = '';
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $disable_footprints = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $disable_manufacturers = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $disable_autodatasheets = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $disable_properties = false;
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"full"})
*/
protected string $default_description = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"full"})
*/
protected string $default_comment = '';
/**
@ -105,6 +114,7 @@ class Category extends AbstractPartsContainingDBElement
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\CategoryAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "ASC"})
* @Assert\Valid()
* @Groups({"full"})
*/
protected $attachments;
@ -112,6 +122,7 @@ class Category extends AbstractPartsContainingDBElement
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\CategoryParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Assert\Valid()
* @Groups({"full"})
*/
protected $parameters;

View file

@ -28,6 +28,7 @@ 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;
/**
@ -48,6 +49,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
* or m (for meters).
* @ORM\Column(type="string", name="unit", nullable=true)
* @Assert\Length(max=10)
* @Groups({"extended", "full"})
*/
protected ?string $unit = null;
@ -55,6 +57,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
* @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.
* @ORM\Column(type="boolean", name="is_integer")
* @Groups({"extended", "full"})
*/
protected bool $is_integer = false;
@ -63,6 +66,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
* Useful for sizes like meters. For this the unit must be set
* @ORM\Column(type="boolean", name="use_si_prefix")
* @Assert\Expression("this.isUseSIPrefix() == false or this.getUnit() != null", message="validator.measurement_unit.use_si_prefix_needs_unit")
* @Groups({"full"})
*/
protected bool $use_si_prefix = false;

View file

@ -40,6 +40,7 @@ use Doctrine\Common\Collections\ArrayCollection;
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;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@ -72,6 +73,7 @@ class Part extends AttachmentContainingDBElement
* @Assert\Valid()
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\PartParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"})
* @Groups({"full"})
*/
protected $parameters;
@ -96,6 +98,7 @@ class Part extends AttachmentContainingDBElement
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\PartAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "ASC"})
* @Assert\Valid()
* @Groups({"full"})
*/
protected $attachments;

View file

@ -31,6 +31,7 @@ use App\Validator\Constraints\ValidPartLot;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -52,12 +53,14 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
/**
* @var string A short description about this lot, shown in table
* @ORM\Column(type="text")
* @Groups({"simple", "extended", "full"})
*/
protected string $description = '';
/**
* @var string a comment stored with this lot
* @ORM\Column(type="text")
* @Groups({"full"})
*/
protected string $comment = '';
@ -65,6 +68,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
* @var ?DateTime Set a time until when the lot must be used.
* Set to null, if the lot can be used indefinitely.
* @ORM\Column(type="datetime", name="expiration_date", nullable=true)
* @Groups({"extended", "full"})
*/
protected ?DateTime $expiration_date = null;
@ -73,12 +77,14 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
* @ORM\ManyToOne(targetEntity="Storelocation")
* @ORM\JoinColumn(name="id_store_location", referencedColumnName="id", nullable=true)
* @Selectable()
* @Groups({"simple", "extended", "full"})
*/
protected ?Storelocation $storage_location = null;
/**
* @var bool If this is set to true, the instock amount is marked as not known
* @ORM\Column(type="boolean")
* @Groups({"simple", "extended", "full"})
*/
protected bool $instock_unknown = false;
@ -86,12 +92,14 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
* @var float For continuous sizes (length, volume, etc.) the instock is saved here.
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
* @Groups({"simple", "extended", "full"})
*/
protected float $amount = 0.0;
/**
* @var bool determines if this lot was manually marked for refilling
* @ORM\Column(type="boolean")
* @Groups({"extended", "full"})
*/
protected bool $needs_refill = false;

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
trait BasicPropertyTrait
@ -33,12 +34,14 @@ trait BasicPropertyTrait
/**
* @var string A text describing what this part does
* @ORM\Column(type="text")
* @Groups({"simple", "extended", "full"})
*/
protected string $description = '';
/**
* @var string A comment/note related to this part
* @ORM\Column(type="text")
* @Groups({"extended", "full"})
*/
protected string $comment = '';
@ -51,6 +54,7 @@ trait BasicPropertyTrait
/**
* @var bool true, if the part is marked as favorite
* @ORM\Column(type="boolean")
* @Groups({"extended", "full"})
*/
protected bool $favorite = false;
@ -61,6 +65,7 @@ trait BasicPropertyTrait
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
* @Selectable()
* @Assert\NotNull(message="validator.select_valid_category")
* @Groups({"simple", "extended", "full"})
*/
protected ?Category $category = null;
@ -69,6 +74,7 @@ trait BasicPropertyTrait
* @ORM\ManyToOne(targetEntity="Footprint")
* @ORM\JoinColumn(name="id_footprint", referencedColumnName="id")
* @Selectable()
* @Groups({"simple", "extended", "full"})
*/
protected ?Footprint $footprint = null;

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -38,6 +39,7 @@ trait InstockTrait
* @ORM\OneToMany(targetEntity="PartLot", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
* @Assert\Valid()
* @ORM\OrderBy({"amount" = "DESC"})
* @Groups({"extended", "full"})
*/
protected $partLots;
@ -46,6 +48,7 @@ trait InstockTrait
* Given in the partUnit.
* @ORM\Column(type="float")
* @Assert\PositiveOrZero()
* @Groups({"extended", "full"})
*/
protected float $minamount = 0;
@ -53,6 +56,7 @@ trait InstockTrait
* @var ?MeasurementUnit the unit in which the part's amount is measured
* @ORM\ManyToOne(targetEntity="MeasurementUnit")
* @ORM\JoinColumn(name="id_part_unit", referencedColumnName="id", nullable=true)
* @Groups({"extended", "full"})
*/
protected ?MeasurementUnit $partUnit = null;

View file

@ -26,6 +26,7 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -45,12 +46,14 @@ trait ManufacturerTrait
* @var string the url to the part on the manufacturer's homepage
* @ORM\Column(type="string")
* @Assert\Url()
* @Groups({"full"})
*/
protected string $manufacturer_product_url = '';
/**
* @var string The product number used by the manufacturer. If this is set to "", the name field is used.
* @ORM\Column(type="string")
* @Groups({"extended", "full"})
*/
protected string $manufacturer_product_number = '';
@ -58,6 +61,7 @@ trait ManufacturerTrait
* @var string The production status of this part. Can be one of the specified ones.
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Choice({"announced", "active", "nrfnd", "eol", "discontinued", ""})
* @Groups({"extended", "full"})
*/
protected ?string $manufacturing_status = '';

View file

@ -24,6 +24,7 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\PriceInformations\Orderdetail;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use function count;
use Doctrine\Common\Collections\Collection;
@ -39,6 +40,7 @@ trait OrderTrait
* @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=true)
* @Assert\Valid()
* @ORM\OrderBy({"supplierpartnr" = "ASC"})
* @Groups({"extended", "full"})
*/
protected $orderdetails;

View file

@ -27,6 +27,7 @@ use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\StorelocationParameter;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -70,12 +71,14 @@ class Storelocation extends AbstractPartsContainingDBElement
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $is_full = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @Groups({"full"})
*/
protected bool $only_single_part = false;