src/Admin/Entity/StdAttributes.php line 18

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.  * StdAttributes
  9.  */
  10. #[ORM\Table(name'std_attributes')]
  11. #[ORM\Index(name'fk_std_attributes_std_users'columns: ['created_by'])]
  12. #[ORM\Index(name'fk_std_attributes_std_users_0'columns: ['updated_by'])]
  13. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdAttributesRepository')]
  14. #[ORM\HasLifecycleCallbacks]
  15. class StdAttributes
  16. {
  17.     /**
  18.      * @var int
  19.      */
  20.     #[ORM\Column(name'id'type'integer'nullablefalseoptions: ['unsigned' => true'comment' => 'Attribute unique identifier'])]
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  23.     private $id;
  24.     /**
  25.      * @var string
  26.      */
  27.     #[ORM\Column(name'name'type'string'length50nullablefalseoptions: ['comment' => 'Attribute name'])]
  28.     private $name;
  29.     /**
  30.      * @var string
  31.      */
  32.     #[ORM\Column(name'machine_name'type'string'length50nullablefalseoptions: ['comment' => 'Attribute machine name'])]
  33.     private $machineName;
  34.     /**
  35.      * @var string
  36.      */
  37.     #[ORM\Column(name'type'type'string'length20nullablefalseoptions: ['comment' => 'Attribute type (e.g: CHECKBOX, RADIO)'])]
  38.     private $type;
  39.     /**
  40.      * @var bool
  41.      */
  42.     #[ORM\Column(name'is_active'type'boolean'nullablefalseoptions: ['default' => 1'comment' => 'Flag that indicates if the attribute is active'])]
  43.     private $isActive '1';
  44.     /**
  45.      * @var \StdUsers
  46.      */
  47.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  48.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  49.     private $createdBy;
  50.     /**
  51.      * @var \DateTime
  52.      */
  53.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time of the record creation'])]
  54.     private $createdDate;
  55.     /**
  56.      * @var \StdUsers
  57.      */
  58.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  59.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  60.     private $updatedBy;
  61.     /**
  62.      * @var \DateTime
  63.      */
  64.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time the record was last updated'])]
  65.     private $updatedDate;
  66.     /**
  67.      * @var int
  68.      */
  69.     #[ORM\Column(name'order_value'type'integer'nullabletrueoptions: ['comment' => 'Attribute order'])]
  70.     private $orderValue;
  71.      /**
  72.      * @var Doctrine\Common\Collections\ArrayCollection|null
  73.      */
  74.     #[ORM\OneToMany(targetEntity'StdAttributesContent'mappedBy'attribute'cascade: ['persist'], orphanRemovaltrue)]
  75.     private $contents;
  76.     public function __construct()
  77.     {
  78.         $this->contents = new ArrayCollection();
  79.     }    
  80.     /**
  81.      * @return Collection|StdAttributesContent[]
  82.      */
  83.     public function getContents(): ?Collection
  84.     {
  85.         return $this->contents;
  86.     }
  87.     /**
  88.      * @return StdAttributesContent
  89.      */
  90.     public function getLocalizedContents(StdLanguages $locale): ?StdAttributesContent
  91.     {
  92.         $criteria Criteria::create()
  93.         ->where(Criteria::expr()->eq("languageCode"$locale))
  94.         ->setMaxResults(1);
  95.         if($this->getContents()){
  96.             $contents $this->getContents()->matching($criteria);
  97.             if(count($contents)){
  98.                 $contents array_values($contents->toArray());
  99.                 return $contents[0];
  100.             }else{
  101.                 return null;
  102.             }
  103.         }else{
  104.             return null;
  105.         }
  106.         
  107.     }
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getName(): ?string
  113.     {
  114.         return $this->name;
  115.     }
  116.     public function setName(string $name): self
  117.     {
  118.         $this->name $name;
  119.         return $this;
  120.     }
  121.     public function getMachineName(): ?string
  122.     {
  123.         return $this->machineName;
  124.     }
  125.     public function setMachineName(string $machineName): self
  126.     {
  127.         $this->machineName $machineName;
  128.         return $this;
  129.     }
  130.  
  131.     public function getType(): ?string
  132.     {
  133.         return $this->type;
  134.     }
  135.     public function setType(string $type): self
  136.     {
  137.         $this->type $type;
  138.         return $this;
  139.     }
  140.     public function getIsActive(): ?bool
  141.     {
  142.         return $this->isActive;
  143.     }
  144.     public function setIsActive(bool $isActive): self
  145.     {
  146.         $this->isActive $isActive;
  147.         return $this;
  148.     }
  149.     public function getCreatedDate(): ?\DateTimeInterface
  150.     {
  151.         return $this->createdDate;
  152.     }
  153.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  154.     {
  155.         $this->createdDate $createdDate;
  156.         return $this;
  157.     }
  158.     public function getUpdatedDate(): ?\DateTimeInterface
  159.     {
  160.         return $this->updatedDate;
  161.     }
  162.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  163.     {
  164.         $this->updatedDate $updatedDate;
  165.         return $this;
  166.     }
  167.     public function getCreatedBy(): ?StdUsers
  168.     {
  169.         return $this->createdBy;
  170.     }
  171.     public function setCreatedBy(?StdUsers $createdBy): self
  172.     {
  173.         $this->createdBy $createdBy;
  174.         return $this;
  175.     }
  176.     public function getUpdatedBy(): ?StdUsers
  177.     {
  178.         return $this->updatedBy;
  179.     }
  180.     public function setUpdatedBy(?StdUsers $updatedBy): self
  181.     {
  182.         $this->updatedBy $updatedBy;
  183.         return $this;
  184.     }
  185.     public function getOrderValue(): ?int
  186.     {
  187.         return $this->orderValue;
  188.     }
  189.     public function setOrderValue(int $orderValue): self
  190.     {
  191.         $this->orderValue $orderValue;
  192.         return $this;
  193.     }
  194.     public function removeContent(StdAttributesContent $content): self
  195.     {
  196.         if ($this->contents->contains($content)) {
  197.             $this->contents->removeElement($content);
  198.             // set the owning side to null (unless already changed)
  199.             if ($content->getAttribute() === $this) {
  200.                 $content->setAttribute(null);
  201.             }
  202.         }
  203.         return $this;
  204.     }
  205.     public function addContent(StdAttributesContent $content): self
  206.     {
  207.         if (!$this->contents->contains($content)) {
  208.             $this->contents[] = $content;
  209.             $content->setAttribute($this);
  210.         }
  211.         return $this;
  212.     }    
  213.      #[ORM\PreUpdate]
  214.     public function setUpdated()
  215.     {
  216.         $this->setUpdatedDate(new \DateTime());
  217.     }
  218.     
  219.     #[ORM\PrePersist]
  220.     public function setCreated()
  221.     {
  222.         $this->setUpdatedDate(new \DateTime());
  223.         $this->setCreatedDate(new \DateTime());
  224.     }
  225.     public function __toString() {
  226.         return $this->name;
  227.     }
  228. }