<?php
namespace App\Entity;
use App\Annotation\EsUploadable;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CompanyProductRepository;
use App\Entity\Interfaces\ClientMappedInterface;
use App\Entity\Interfaces\UploadMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* @ApiResource(
* attributes={"filters"={"translation.groups"}},
* normalizationContext={"groups"={"CompanyProduct:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"CompanyProduct:Write", "CompanyProductTranslationsGroup"}},
* collectionOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "post"={"security"="is_granted('ROLE_ADMIN')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
* "put"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
* "patch"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"},
* "delete"={"security"="is_granted('ROLE_SUPER_ADMIN') || is_granted('IS_CLIENT_OWNER_COMPANY_SPE_PRODUCT', object)"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "container.id": "exact", "company.id": "exact", "translations.name": "partial", "companyProductTags.id": "exact", "companyProductTags.name": "partial"})
* @ApiFilter(BooleanFilter::class, properties={"isActive"})
* @ApiFilter(OrderFilter::class, properties={"translations.name": "DESC"})
* @ORM\Entity(repositoryClass=CompanyProductRepository::class)
*/
class CompanyProduct extends AbstractTranslatable implements ClientMappedInterface, UploadMappedInterface
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\OneToMany(targetEntity="CompanyProductTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
*
* @Groups({"CompanyProduct:Write", "CompanyProductTranslationsGroup"})
* @Assert\Valid()
*/
protected $translations;
/**
* @Groups({"CompanyProduct:Read"})
*/
private $name;
/**
* @Groups({"CompanyProduct:Read"})
*/
private $description;
/**
* @Groups({"CompanyProduct:Read"})
*/
private $ctaLabel;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"CompanyProduct:Read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
* @EsUploadable()
*/
protected $imageName;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $isActive;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $isCta;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $ctaUrl;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $price;
/**
* @ORM\ManyToOne(targetEntity=Client::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $client;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="companyProducts")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $company;
/**
* @ORM\ManyToMany(targetEntity=CompanyProductTag::class, inversedBy="companyProducts", cascade={"persist"})
*
* @Groups({"CompanyProduct:Read", "CompanyProduct:Write"})
*/
private $companyProductTags;
public function __construct()
{
parent::__construct();
$this->companyProductTags = new ArrayCollection();
}
protected function createTranslation(): TranslationInterface
{
return new CompanyProductTranslation();
}
public function getName(): ?string
{
return $this->getTranslation()->getName();
}
public function setName(string $name): self
{
$this->getTranslation()->setName($name);
return $this;
}
public function getDescription(): ?string
{
return $this->getTranslation()->getDescription();
}
public function setDescription(string $description): self
{
$this->getTranslation()->setDescription($description);
return $this;
}
public function getCtaLabel(): ?string
{
return $this->getTranslation()->getCtaLabel();
}
public function setCtaLabel(string $ctaLabel): self
{
$this->getTranslation()->setCtaLabel($ctaLabel);
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): self
{
$this->imageName = $imageName;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getIsCta(): ?bool
{
return $this->isCta;
}
public function setIsCta(?bool $isCta): self
{
$this->isCta = $isCta;
return $this;
}
public function getCtaUrl(): ?string
{
return $this->ctaUrl;
}
public function setCtaUrl(?string $ctaUrl): self
{
$this->ctaUrl = $ctaUrl;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(?string $price): self
{
$this->price = $price;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): self
{
$this->client = $client;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|CompanyProductTag[]
*/
public function getCompanyProductTags(): Collection
{
return $this->companyProductTags;
}
public function addCompanyProductTag(CompanyProductTag $companyProductTag): self
{
if (!$this->companyProductTags->contains($companyProductTag)) {
$this->companyProductTags[] = $companyProductTag;
}
return $this;
}
public function removeCompanyProductTag(CompanyProductTag $companyProductTag): self
{
$this->companyProductTags->removeElement($companyProductTag);
return $this;
}
}