src/Admin/Entity/StdAttributesValues.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\Criteria;
  7. /**
  8.  * StdAttributesValues
  9.  */
  10. #[ORM\Table(name'std_attributes_values')]
  11. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdAttributesValuesRepository')]
  12. #[ORM\HasLifecycleCallbacks]
  13. class StdAttributesValues
  14. {
  15.     /**
  16.      * @var int
  17.      */
  18.     #[ORM\Column(name'id'type'integer'nullablefalseoptions: ['unsigned' => true'comment' => 'Attribute value unique identifier'])]
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  21.     private $id;
  22.     /**
  23.      * @var string
  24.      */
  25.     #[ORM\Column(name'attribute_machine_name'type'string'length50nullablefalseoptions: ['comment' => 'Attribute machine name'])]
  26.     private $attributeMachineName;
  27.     /**
  28.      * @var string
  29.      */
  30.     #[ORM\Column(name'label'type'string'length50nullablefalseoptions: ['comment' => 'Attribute value label'])]
  31.     private $label;
  32.     
  33.     /**
  34.      * @var string
  35.      */
  36.     #[ORM\Column(name'value'type'string'length20nullablefalseoptions: ['comment' => 'Attribute value'])]
  37.     private $value;
  38.     /**
  39.      * @var int
  40.      */
  41.     #[ORM\Column(name'order_value'type'integer'nullabletrueoptions: ['comment' => 'Attribute value order'])]
  42.     private $orderValue;
  43.     /**
  44.      * @var string
  45.      */
  46.     #[ORM\Column(name'color'type'string'length20nullabletrueoptions: ['comment' => 'Attribute color'])]
  47.     private $color;
  48.     /**
  49.      * @var string
  50.      */
  51.     #[ORM\Column(name'image'type'string'length100nullabletrueoptions: ['comment' => 'Attribute image'])]
  52.     private $image;
  53.     /**
  54.      * @var \StdAttributes
  55.      */
  56.     #[ORM\JoinColumn(name'attribute_id'referencedColumnName'id')]
  57.     #[ORM\ManyToOne(targetEntity'StdAttributes'inversedBy'contents')]
  58.     private $attribute;
  59.     /**
  60.      * @var \StdUsers
  61.      */
  62.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  63.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  64.     private $createdBy;
  65.     /**
  66.      * @var \DateTime
  67.      */
  68.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time of the record creation'])]
  69.     private $createdDate;
  70.     /**
  71.      * @var \StdUsers
  72.      */
  73.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  74.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  75.     private $updatedBy;
  76.     /**
  77.      * @var \DateTime
  78.      */
  79.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time the record was last updated'])]
  80.     private $updatedDate;    
  81.      /**
  82.      * @var Doctrine\Common\Collections\ArrayCollection|null
  83.      */
  84.     #[ORM\OneToMany(targetEntity'StdAttributesValuesContent'mappedBy'attributeValue'cascade: ['persist'], orphanRemovaltrue)]
  85.     private $contents;
  86.     public function __construct()
  87.     {
  88.         $this->contents = new ArrayCollection();
  89.     }    
  90.     /**
  91.      * @return Collection|StdAttributesValuesContent[]
  92.      */
  93.     public function getContents(): ?Collection
  94.     {
  95.         return $this->contents;
  96.     }
  97.     /**
  98.      * @return StdAttributesValuesContent
  99.      */
  100.     public function getLocalizedContents(StdLanguages $locale): ?StdAttributesValuesContent
  101.     {
  102.         $criteria Criteria::create()
  103.         ->where(Criteria::expr()->eq("languageCode"$locale))
  104.         ->setMaxResults(1);
  105.         if($this->getContents()){
  106.             $contents $this->getContents()->matching($criteria);
  107.             if(count($contents)){
  108.                 $contents array_values($contents->toArray());
  109.                 return $contents[0];
  110.             }else{
  111.                 return null;
  112.             }
  113.         }else{
  114.             return null;
  115.         }
  116.         
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getAttributeMachineName(): ?string
  123.     {
  124.         return $this->attributeMachineName;
  125.     }
  126.     public function setAttributeMachineName(string $attributeMachineName): self
  127.     {
  128.         $this->attributeMachineName $attributeMachineName;
  129.         return $this;
  130.     }
  131.     public function getLabel(): ?string
  132.     {
  133.         return $this->label;
  134.     }
  135.     public function setLabel(string $label): self
  136.     {
  137.         $this->label $label;
  138.         return $this;
  139.     }
  140.  
  141.     public function getValue(): ?string
  142.     {
  143.         return $this->value;
  144.     }
  145.     public function setValue(string $value): self
  146.     {
  147.         $this->value $value;
  148.         return $this;
  149.     }
  150.     public function getOrderValue(): ?int
  151.     {
  152.         return $this->orderValue;
  153.     }
  154.     public function setOrderValue(int $orderValue): self
  155.     {
  156.         $this->orderValue $orderValue;
  157.         return $this;
  158.     }
  159.     public function getColor(): ?string
  160.     {
  161.         return $this->color;
  162.     }
  163.     public function setColor(string $color): self
  164.     {
  165.         $this->color $color;
  166.         return $this;
  167.     }
  168.     public function getImage(): ?string
  169.     {
  170.         return $this->image;
  171.     }
  172.     public function setImage(string $image): self
  173.     {
  174.         $this->image $image;
  175.         return $this;
  176.     }
  177.     public function getAttribute(): ?StdAttributes
  178.     {
  179.         return $this->attribute;
  180.     }
  181.     public function setAttribute(StdAttributes $attribute): self
  182.     {
  183.         $this->attribute $attribute;
  184.         return $this;
  185.     }
  186.     public function getCreatedDate(): ?\DateTimeInterface
  187.     {
  188.         return $this->createdDate;
  189.     }
  190.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  191.     {
  192.         $this->createdDate $createdDate;
  193.         return $this;
  194.     }
  195.     public function getUpdatedDate(): ?\DateTimeInterface
  196.     {
  197.         return $this->updatedDate;
  198.     }
  199.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  200.     {
  201.         $this->updatedDate $updatedDate;
  202.         return $this;
  203.     }
  204.     public function getCreatedBy(): ?StdUsers
  205.     {
  206.         return $this->createdBy;
  207.     }
  208.     public function setCreatedBy(?StdUsers $createdBy): self
  209.     {
  210.         $this->createdBy $createdBy;
  211.         return $this;
  212.     }
  213.     public function getUpdatedBy(): ?StdUsers
  214.     {
  215.         return $this->updatedBy;
  216.     }
  217.     public function setUpdatedBy(?StdUsers $updatedBy): self
  218.     {
  219.         $this->updatedBy $updatedBy;
  220.         return $this;
  221.     }
  222.     public function removeContent(StdAttributesValuesContent $content): self
  223.     {
  224.         if ($this->contents->contains($content)) {
  225.             $this->contents->removeElement($content);
  226.             // set the owning side to null (unless already changed)
  227.             if ($content->getAttributeValue() === $this) {
  228.                 $content->setAttributeValue(null);
  229.             }
  230.         }
  231.         return $this;
  232.     }
  233.     public function addContent(StdAttributesValuesContent $content): self
  234.     {
  235.         if (!$this->contents->contains($content)) {
  236.             $this->contents[] = $content;
  237.             $content->setAttributeValue($this);
  238.         }
  239.         return $this;
  240.     }        
  241.      #[ORM\PreUpdate]
  242.     public function setUpdated()
  243.     {
  244.         $this->setUpdatedDate(new \DateTime());
  245.     }
  246.     
  247.     #[ORM\PrePersist]
  248.     public function setCreated()
  249.     {
  250.         $this->setUpdatedDate(new \DateTime());
  251.         $this->setCreatedDate(new \DateTime());
  252.     }
  253.     
  254.     public function __toString() {
  255.         return $this->label;
  256.     }
  257. }