src/Entity/Article.php line 58
<?phpnamespace App\Entity;use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;use ApiPlatform\Metadata\ApiFilter;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\GetCollection;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\Link;use ApiPlatform\Metadata\Patch;use ApiPlatform\Metadata\Post;use App\Controller\Api\Article\ApiEstablishmentArticleNewController;use App\Repository\ArticleRepository;use App\State\UpdateArticleProcessor;use App\Trait\ActivableTrait;use App\Trait\ArrayableTrait;use App\Trait\AuthorTrait;use App\Trait\CurrentStateTrait;use App\Trait\DateTrait;use App\Trait\DeletableTrait;use DateTimeImmutable;use DateTimeInterface;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;use Tchoulom\ViewCounterBundle\Model\ViewCountable;#[ApiResource(operations: [new GetCollection(normalizationContext: ['groups' => ['article:list']]),new GetCollection(uriTemplate: "/departments/{departmentId}/articles",normalizationContext: ['groups' => ['article:list']]),new Get(),new Post(controller: ApiEstablishmentArticleNewController::class,denormalizationContext: ['groups' => ['article:new']]),new Patch(denormalizationContext: ['groups' => ['article:patch']],processor: UpdateArticleProcessor::class)],normalizationContext: ['groups' => ['article:list', 'article:view']],)]#[ApiFilter(OrderFilter::class, properties: ['id' => 'DESC'])]#[ApiFilter(SearchFilter::class, properties: ['id' => 'exact', 'type' => 'exact', 'inLanguage' => 'partial'])]#[ApiFilter(BooleanFilter::class, properties: ['isActive'])]#[ORM\Entity(repositoryClass: ArticleRepository::class)]class Article implements ViewCountable{const TYPE_PHYSICS = 0;const TYPE_SERVICE = 1;const TYPE_SUBSCRIPTION = 2;const TYPES = ['Physique' => self::TYPE_PHYSICS,'Service' => self::TYPE_SERVICE,'Abonnement' => self::TYPE_SUBSCRIPTION,];use ArrayableTrait;use DateTrait {DateTrait::__construct as private dateConstruct;}use AuthorTrait;use ActivableTrait;use CurrentStateTrait;use DeletableTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['article:list'])]private ?int $id = null;#[ORM\Column(length: 255)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?string $name = null;#[ORM\Column(length: 255, nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?string $slug = null;#[ORM\Column(type: Types::TEXT)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?string $content = null;#[ORM\ManyToOne(cascade: ["persist"])]#[ORM\JoinColumn(nullable: true)]#[Groups(['article:list'])]private ?Attachment $thumbnail = null;#[ORM\Column]#[Groups(['article:list', 'article:new', 'article:patch', 'order:list'])]private ?float $amount = null;#[ORM\Column]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?bool $isPromote = false;#[ORM\Column(nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?float $promotePrice = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]#[Groups(['article:list', 'article:patch', 'order:list', 'article:new'])]private ?Currency $currency = null;#[ORM\Column(length: 255, nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch', 'order:list'])]private ?string $shortcode = null;#[ORM\Column(nullable: true)]#[Groups(['article:list', 'article:new'])]private ?int $quantity = null;#[ORM\Column(length: 255)]#[Groups(['article:list', 'article:new', 'article:patch', 'order:list'])]private ?string $type = null;#[ORM\ManyToMany(targetEntity: Option::class, cascade: ["persist"])]#[Groups(['article:view', 'article:new'])]private Collection $options;#[ORM\ManyToMany(targetEntity: Collections::class, inversedBy: 'articles')]private Collection $collections;#[ORM\ManyToOne(inversedBy: 'articles')]#[ORM\JoinColumn(nullable: false)]private ?Establishment $establishment = null;#[ORM\Column]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?bool $isTaxable = false;#[ORM\OneToMany(mappedBy: 'article', targetEntity: ArticleDepartment::class, orphanRemoval: true)]#[Groups(['article:view'])]private Collection $departments;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]#[Groups(['article:view', 'article:patch'])]private ?DateTimeInterface $expiryAt = null;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]#[Groups(['article:view'])]private ?DateTimeInterface $lastSupplyAt = null;#[ORM\OneToMany(mappedBy: 'article', targetEntity: ArticleSupply::class, orphanRemoval: true)]private Collection $supplies;#[ORM\Column(nullable: true)]#[Groups(['article:view'])]private ?int $minimum = null;#[ORM\Column(nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?int $lowQuantity = null;#[ORM\Column]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?bool $isBookable = false;#[ORM\Column(nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?int $reservationTime = null;#[ORM\Column(nullable: true)]#[Groups(['article:list', 'article:new', 'article:patch'])]private ?float $reservationMargin = null;#[ORM\Column(nullable: true)]private ?array $controls = null;#[ORM\ManyToOne]#[Groups(['article:list', 'article:new'])]private ?Tax $tax = null;#[ORM\Column(nullable: true)]private ?int $views = 0;#[ORM\OneToMany(mappedBy: 'article', targetEntity: ViewCounter::class)]private Collection $viewCounters;public function __construct(){$this->dateConstruct();$this->currentState = 'draft';$this->isActive = true;$this->options = new ArrayCollection();$this->collections = new ArrayCollection();$this->departments = new ArrayCollection();$this->supplies = new ArrayCollection();$this->viewCounters = new ArrayCollection();}public function getId(): ?int{return $this->id;}/*** @param int|null $id** @return $this*/public function setId(?int $id): self{$this->id = $id;return $this;}public function getName(): ?string{return $this->name;}public function getNameOrder(): ?string{return "{$this->getName()} ({$this->getAmount()} {$this->getCurrency()?->getSymbol()})";}public function setName(string $name): self{$this->name = $name;return $this;}public function getSlug(): ?string{return $this->slug;}public function setSlug(?string $slug): self{$this->slug = $slug;return $this;}public function getContent(): ?string{return $this->content;}public function setContent(string $content): self{$this->content = $content;return $this;}public function getThumbnail(): ?Attachment{return $this->thumbnail;}public function setThumbnail(?Attachment $thumbnail): self{$this->thumbnail = $thumbnail;return $this;}public function getAmount(): ?float{return $this->amount;}public function setAmount(float $amount): self{$this->amount = $amount;return $this;}public function isIsPromote(): ?bool{return $this->isPromote;}public function setIsPromote(bool $isPromote): self{$this->isPromote = $isPromote;return $this;}public function getPromotePrice(): ?float{return $this->promotePrice;}public function setPromotePrice(?float $promotePrice): self{$this->promotePrice = $promotePrice;return $this;}public function getCurrency(): ?Currency{return $this->currency;}public function setCurrency(?Currency $currency): self{$this->currency = $currency;return $this;}public function getShortcode(): ?string{return $this->shortcode;}public function setShortcode(?string $shortcode): self{$this->shortcode = $shortcode;return $this;}public function getQuantity(): ?int{return $this->quantity;}public function setQuantity(?int $quantity): self{$this->quantity = $quantity;return $this;}public function getType(): string{return $this->type;}public function getTypeName(): ?string{return array_flip(self::TYPES)[$this->getType()];}public function setType(string $type): self{$this->type = $type;return $this;}/*** @return Collection<int, Option>*/public function getOptions(): Collection{return $this->options;}public function addOption(Option $option): self{if (!$this->options->contains($option)) {$this->options->add($option);}return $this;}public function removeOption(Option $option): self{$this->options->removeElement($option);return $this;}/*** @return Collection<int, Collections>*/public function getCollections(): Collection{return $this->collections;}public function addCollection(Collections $collection): self{if (!$this->collections->contains($collection)) {$this->collections->add($collection);}return $this;}public function removeCollection(Collections $collection): self{$this->collections->removeElement($collection);return $this;}public function getEstablishment(): ?Establishment{return $this->establishment;}public function setEstablishment(?Establishment $establishment): self{$this->establishment = $establishment;return $this;}public function isIsTaxable(): ?bool{return $this->isTaxable;}public function setIsTaxable(bool $isTaxable): self{$this->isTaxable = $isTaxable;return $this;}/*** @return Collection<int, ArticleDepartment>*/public function getDepartments(): Collection{return $this->departments;}public function addDepartment(ArticleDepartment $department): self{if (!$this->departments->contains($department)) {$this->departments->add($department);$department->setArticle($this);}return $this;}public function removeDepartment(ArticleDepartment $department): self{if ($this->departments->removeElement($department)) {// set the owning side to null (unless already changed)if ($department->getArticle() === $this) {$department->setArticle(null);}}return $this;}public function getExpiryAt(): ?DateTimeInterface{return $this->expiryAt;}public function setExpiryAt(?DateTimeInterface $expiryAt): self{$this->expiryAt = $expiryAt;return $this;}public function getLastSupplyAt(): ?DateTimeInterface{return $this->lastSupplyAt;}public function setLastSupplyAt(?DateTimeInterface $lastSupplyAt): self{$this->lastSupplyAt = $lastSupplyAt;return $this;}/*** @return Collection<int, ArticleSupply>*/public function getSupplies(): Collection{return $this->supplies;}public function addSupply(ArticleSupply $supply): self{if (!$this->supplies->contains($supply)) {$this->supplies->add($supply);$supply->setArticle($this);}return $this;}public function removeSupply(ArticleSupply $supply): self{if ($this->supplies->removeElement($supply)) {// set the owning side to null (unless already changed)if ($supply->getArticle() === $this) {$supply->setArticle(null);}}return $this;}public function getMinimum(): ?int{return $this->minimum;}public function setMinimum(?int $minimum): self{$this->minimum = $minimum;return $this;}public function getLowQuantity(): ?int{return $this->lowQuantity;}public function setLowQuantity(?int $lowQuantity): self{$this->lowQuantity = $lowQuantity;return $this;}public function isIsBookable(): ?bool{return $this->isBookable;}public function setIsBookable(bool $isBookable): self{$this->isBookable = $isBookable;return $this;}public function getReservationTime(): ?int{return $this->reservationTime;}public function setReservationTime(?int $reservationTime): self{$this->reservationTime = $reservationTime;return $this;}public function getReservationMargin(): ?float{return $this->reservationMargin;}public function setReservationMargin(?float $reservationMargin): self{$this->reservationMargin = $reservationMargin;return $this;}public function getControls(): ?array{return $this->controls;}public function setControls(?array $controls): static{$this->controls = $controls;return $this;}#[Groups(['article:list'])]public function getValue(): ?int{return $this->id;}#[Groups(['article:list'])]public function getLabel(): ?string{return $this->name;}public static function getVariables(): array{return ["Prix" => "amount","Temps de reservation" => "reservationTime","Quantité" => "quantity",];}public function getTax(): ?Tax{return $this->tax;}public function setTax(?Tax $tax): static{$this->tax = $tax;return $this;}public function __toString(): string{return $this->name;}public function getViews(): ?int{return $this->views;}public function setViews($views): void{$this->views = $views;}/*** @return Collection<int, ViewCounter>*/public function getViewCounters(): Collection{return $this->viewCounters;}public function addViewCounter(ViewCounter $viewCounter): static{if (!$this->viewCounters->contains($viewCounter)) {$this->viewCounters->add($viewCounter);$viewCounter->setArticle($this);}return $this;}public function removeViewCounter(ViewCounter $viewCounter): static{if ($this->viewCounters->removeElement($viewCounter)) {// set the owning side to null (unless already changed)if ($viewCounter->getArticle() === $this) {$viewCounter->setArticle(null);}}return $this;}}