<?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;
/**
* StdAttributes
*/
#[ORM\Table(name: 'std_attributes')]
#[ORM\Index(name: 'fk_std_attributes_std_users', columns: ['created_by'])]
#[ORM\Index(name: 'fk_std_attributes_std_users_0', columns: ['updated_by'])]
#[ORM\Entity(repositoryClass: 'App\Admin\Repository\StdAttributesRepository')]
#[ORM\HasLifecycleCallbacks]
class StdAttributes
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false, options: ['unsigned' => true, 'comment' => 'Attribute unique identifier'])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 50, nullable: false, options: ['comment' => 'Attribute name'])]
private $name;
/**
* @var string
*/
#[ORM\Column(name: 'machine_name', type: 'string', length: 50, nullable: false, options: ['comment' => 'Attribute machine name'])]
private $machineName;
/**
* @var string
*/
#[ORM\Column(name: 'type', type: 'string', length: 20, nullable: false, options: ['comment' => 'Attribute type (e.g: CHECKBOX, RADIO)'])]
private $type;
/**
* @var bool
*/
#[ORM\Column(name: 'is_active', type: 'boolean', nullable: false, options: ['default' => 1, 'comment' => 'Flag that indicates if the attribute 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 int
*/
#[ORM\Column(name: 'order_value', type: 'integer', nullable: true, options: ['comment' => 'Attribute order'])]
private $orderValue;
/**
* @var Doctrine\Common\Collections\ArrayCollection|null
*/
#[ORM\OneToMany(targetEntity: 'StdAttributesContent', mappedBy: 'attribute', cascade: ['persist'], orphanRemoval: true)]
private $contents;
public function __construct()
{
$this->contents = new ArrayCollection();
}
/**
* @return Collection|StdAttributesContent[]
*/
public function getContents(): ?Collection
{
return $this->contents;
}
/**
* @return StdAttributesContent
*/
public function getLocalizedContents(StdLanguages $locale): ?StdAttributesContent
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("languageCode", $locale))
->setMaxResults(1);
if($this->getContents()){
$contents = $this->getContents()->matching($criteria);
if(count($contents)){
$contents = array_values($contents->toArray());
return $contents[0];
}else{
return null;
}
}else{
return null;
}
}
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 getMachineName(): ?string
{
return $this->machineName;
}
public function setMachineName(string $machineName): self
{
$this->machineName = $machineName;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
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;
}
public function getOrderValue(): ?int
{
return $this->orderValue;
}
public function setOrderValue(int $orderValue): self
{
$this->orderValue = $orderValue;
return $this;
}
public function removeContent(StdAttributesContent $content): self
{
if ($this->contents->contains($content)) {
$this->contents->removeElement($content);
// set the owning side to null (unless already changed)
if ($content->getAttribute() === $this) {
$content->setAttribute(null);
}
}
return $this;
}
public function addContent(StdAttributesContent $content): self
{
if (!$this->contents->contains($content)) {
$this->contents[] = $content;
$content->setAttribute($this);
}
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;
}
}