<?php
namespace App\Entity\Recipe;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Operation\Operation;
use App\Repository\Recipe\IngredientRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=IngredientRepository::class)
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={
* "Recipe:io",
* }},
* "denormalization_context"={"groups"={
* "Recipe:io",
* }}
* },
* collectionOperations={
* "public-get-ingredients"={
* "path"="/public/ingredients",
* "method"="GET",
* },
* },
* ),
*/
class Ingredient
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "Recipe:io",
* })
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({
* "Recipe:io",
* })
*/
private $name;
/**
* @ORM\Column(type="boolean")
* @Groups({
* "Recipe:io",
* })
* @ApiFilter(BooleanFilter::class)
*/
private $brand;
/**
* @ORM\OneToMany(targetEntity=RecipeIngredient::class, mappedBy="ingredient")
*/
private $recipeIngredients;
/**
* @ORM\ManyToMany(targetEntity=Operation::class, inversedBy="ingredients")
* @Groups({
* "Recipe:io",
* })
*/
private $offers;
public function __construct()
{
$this->recipeIngredients = new ArrayCollection();
$this->offers = 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 getBrand(): ?bool
{
return $this->brand;
}
public function setBrand(bool $brand): self
{
$this->brand = $brand;
return $this;
}
/**
* @return Collection<int, RecipeIngredient>
*/
public function getRecipeIngredients(): Collection
{
return $this->recipeIngredients;
}
public function addRecipeIngredient(RecipeIngredient $recipeIngredient): self
{
if (!$this->recipeIngredients->contains($recipeIngredient)) {
$this->recipeIngredients[] = $recipeIngredient;
$recipeIngredient->setIngredient($this);
}
return $this;
}
public function removeRecipeIngredient(RecipeIngredient $recipeIngredient): self
{
if ($this->recipeIngredients->removeElement($recipeIngredient)) {
// set the owning side to null (unless already changed)
if ($recipeIngredient->getIngredient() === $this) {
$recipeIngredient->setIngredient(null);
}
}
return $this;
}
/**
* @return Collection<int, Operation>
*/
public function getOffers(): Collection
{
return $this->offers;
}
public function addOffer(Operation $offer): self
{
if (!$this->offers->contains($offer)) {
$this->offers[] = $offer;
}
return $this;
}
public function removeOffer(Operation $offer): self
{
$this->offers->removeElement($offer);
return $this;
}
}