src/Admin/Entity/StdSnippets.php line 20

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