<?php
namespace App\Admin\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Types\Types;
/**
* StdSnippets
*/
#[ORM\Table(name: 'std_snippets')]
#[ORM\Index(name: 'fk_std_snippets_std_users', columns: ['created_by'])]
#[ORM\Index(name: 'fk_std_snippets_std_users_0', columns: ['updated_by'])]
#[ORM\Index(name: 'idx_machine_name', columns: ['machine_name'])]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdSnippetsRepository')]
#[ORM\HasLifecycleCallbacks]
class StdSnippets
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false, options: ['unsigned' => true, 'comment' => 'Snippet unique identifier'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 100, nullable: true, options: ['comment' => 'Snippet name'])]
private $name;
/**
* @var bool
*/
#[ORM\Column(name: 'is_active', type: 'boolean', nullable: false, options: ['default' => 1, 'comment' => 'Flag that indicates if the snippet is active'])]
private $isActive = '1';
/**
* @var \StdUsers
*/
#[ORM\JoinColumn(name: 'created_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $createdBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'created_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time of the record creation'])]
private $createdDate;
/**
* @var \StdUsers
*/
#[ORM\JoinColumn(name: 'updated_by', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: 'StdUsers')]
private $updatedBy;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated_date', type: 'datetime', nullable: false, options: ['comment' => 'Date and time the record was last updated'])]
private $updatedDate;
/**
* @var Doctrine\Common\Collections\ArrayCollection|null
*/
#[ORM\OneToMany(targetEntity: 'StdSnippetsContent', mappedBy: 'snippetId', cascade: ['persist', 'remove'], orphanRemoval: true)]
private $snippetsContent;
#[ORM\Column(name:'machine_name', type:'string', length: 255, nullable: true)]
private ?string $machineName = null;
#[ORM\Column(name:'description', type: Types::TEXT, nullable: true)]
private ?string $description = null;
/**
* @var bool
*/
#[ORM\Column(name: 'is_hidden', type: 'boolean', nullable: false, options: ['default' => 0, 'comment' => 'Flag that indicates if the snippet is hidden'])]
private $isHidden = '0';
public function __construct()
{
$this->snippetsContent = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getCreatedDate(): ?\DateTimeInterface
{
return $this->createdDate;
}
public function setCreatedDate(\DateTimeInterface $createdDate): self
{
$this->createdDate = $createdDate;
return $this;
}
public function getUpdatedDate(): ?\DateTimeInterface
{
return $this->updatedDate;
}
public function setUpdatedDate(\DateTimeInterface $updatedDate): self
{
$this->updatedDate = $updatedDate;
return $this;
}
public function getCreatedBy(): ?StdUsers
{
return $this->createdBy;
}
public function setCreatedBy(?StdUsers $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getUpdatedBy(): ?StdUsers
{
return $this->updatedBy;
}
public function setUpdatedBy(?StdUsers $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
#[ORM\PreUpdate]
public function setUpdated()
{
$this->setUpdatedDate(new \DateTime());
}
#[ORM\PrePersist]
public function setCreated()
{
$this->setUpdatedDate(new \DateTime());
$this->setCreatedDate(new \DateTime());
}
public function __toString() {
return $this->name;
}
/**
* @return Collection|StdSnippetsContent[]
*/
public function getSnippetsContent(): ?Collection
{
return $this->snippetsContent;
}
public function removeSnippetsContent(StdSnippetsContent $snippetsContent): self
{
if ($this->snippetsContent->contains($snippetsContent)) {
$this->snippetsContent->removeElement($snippetsContent);
// set the owning side to null (unless already changed)
if ($snippetsContent->getSnippetId() === $this) {
$snippetsContent->setSnippetId(null);
}
}
return $this;
}
public function addSnippetsContent(StdSnippetsContent $snippetsContent): self
{
if (!$this->snippetsContent->contains($snippetsContent)) {
$this->snippetsContent[] = $snippetsContent;
$snippetsContent->setSnippetId($this);
}
return $this;
}
public function getMachineName(): ?string
{
return $this->machineName;
}
public function setMachineName(?string $machineName): self
{
$this->machineName = $machineName;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return StdSnippetsContent
*/
public function getLocalizedContents(StdLanguages $locale): ?StdSnippetsContent
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("languageCode", $locale))
->setMaxResults(1);
if($this->getSnippetsContent()){
$contents = $this->getSnippetsContent()->matching($criteria);
if(count($contents)){
return $contents[0];
}
}
return null;
}
public function getIsHidden(): ?bool
{
return $this->isHidden;
}
public function setIsHidden(bool $isHidden): self
{
$this->isHidden = $isHidden;
return $this;
}
}