<?php
namespace Plugin\Recipe\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
if (!class_exists('\Plugin\Recipe\Entity\Recipe', false)) {
/**
* Recipe
*
* @ORM\Table(name="plg_recipe")
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
* @ORM\Entity(repositoryClass="Plugin\Recipe\Repository\RecipeRepository")
*/
class Recipe
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var bool
* @ORM\Column(name="public", type="boolean", options={"default":true})
*/
private $public;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var int
*
* @ORM\Column(name="minute", type="integer", options={"unsigned":false})
*/
private $minute;
/**
* @var int
*
* @ORM\Column(name="energy", type="integer", options={"unsigned":false})
*/
private $energy;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeImage", mappedBy="Recipe", cascade={"remove"})
* @ORM\OrderBy({
* "sort_no"="ASC"
* })
*/
private $RecipeImage;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeTag", mappedBy="Recipe", cascade={"remove"})
*/
private $RecipeTag;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeCategory", mappedBy="Recipe", cascade={"remove"})
*/
private $RecipeCategory;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeMaterial", mappedBy="Recipe", cascade={"remove"})
*/
private $RecipeMaterial;
/**
* @var int
*
* @ORM\Column(name="people", type="integer", options={"unsigned":false}, nullable=true)
*/
private $people;
/**
* @var \Doctrine\Common\Collections\Collection|RecipeMaterialInfo[]
*
* @ORM\OneToMany(targetEntity=RecipeMaterialInfo::class, mappedBy="Recipe", cascade={"persist", "remove"})
* @ORM\OrderBy({"sort_no" = "ASC"})
*/
private $RecipeMaterialInfos;
/**
* @var \Doctrine\Common\Collections\Collection|RecipeStep[]
*
* @ORM\OneToMany(targetEntity=RecipeStep::class, mappedBy="Recipe", cascade={"persist", "remove"})
* @ORM\OrderBy({"sort_no" = "ASC"})
*/
private $RecipeSteps;
/**
* @var \Doctrine\Common\Collections\Collection|RecipeNutrition[]
*
* @ORM\OneToMany(targetEntity=RecipeNutrition::class, mappedBy="Recipe", cascade={"persist", "remove"})
* @ORM\OrderBy({"sort_no" = "ASC"})
*/
private $RecipeNutritions;
/**
* @var \Plugin\Recipe\Entity\RecipeBadge
*
* @ORM\ManyToOne(targetEntity="Plugin\Recipe\Entity\RecipeBadge")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="recipe_badge_id", referencedColumnName="id")
* })
*/
private $RecipeBadge;
/**
* @var \Plugin\Recipe\Entity\RecipeCreator
*
* @ORM\ManyToOne(targetEntity="Plugin\Recipe\Entity\RecipeCreator")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="recipe_creator_id", referencedColumnName="id")
* })
*/
private $RecipeCreator;
/**
* @var string
*
* @ORM\Column(name="creator_heading", type="string", length=255, nullable=true)
*/
private $creatorHeading;
/**
* @var string
*
* @ORM\Column(name="creator_comment", type="string", length=4000, nullable=true)
*/
private $creatorComment;
/**
* @var RelatedProduct[]|Collection
*
* @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RelatedProduct", mappedBy="Recipe", cascade={"persist", "remove"})
* @ORM\OrderBy({
* "id"="ASC"
* })
*/
private $RelatedProducts;
/**
* @return RelatedProduct[]|Collection
*/
public function getEnableRelatedProducts()
{
$results = new ArrayCollection();
foreach ($this->RelatedProducts as $RelatedProduct) {
if (
$RelatedProduct->getChildProduct() === null ||
$RelatedProduct->getChildProduct()->isEnable() === false
) {
continue;
} else {
$results->add($RelatedProduct);
}
}
return $results;
}
/**
* @return RelatedProduct[]|Collection
*/
public function getRelatedProducts()
{
if (null === $this->RelatedProducts) {
$this->RelatedProducts = new ArrayCollection();
}
return $this->RelatedProducts;
}
/**
* @param RelatedProduct $RelatedProduct
*/
public function addRelatedProduct(RelatedProduct $RelatedProduct)
{
if (null === $this->RelatedProducts) {
$this->RelatedProducts = new ArrayCollection();
}
$this->RelatedProducts[] = $RelatedProduct;
}
/**
* @param RelatedProduct $RelatedProduct
*
* @return bool
*/
public function removeRelatedProduct(RelatedProduct $RelatedProduct)
{
if (null === $this->RelatedProducts) {
$this->RelatedProducts = new ArrayCollection();
}
return $this->RelatedProducts->removeElement($RelatedProduct);
}
/**
* Constructor
*/
public function __construct()
{
$this->RecipeImage = new \Doctrine\Common\Collections\ArrayCollection();
$this->RecipeTag = new \Doctrine\Common\Collections\ArrayCollection();
$this->RecipeCategory = new \Doctrine\Common\Collections\ArrayCollection();
$this->RecipeMaterial = new \Doctrine\Common\Collections\ArrayCollection();
$this->RecipeMaterialInfos = new ArrayCollection();
$this->RecipeSteps = new ArrayCollection();
$this->RecipeNutritions = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return bool
*/
public function getPublic()
{
return $this->public;
}
/**
* @param bool $public
*
* @return $this;
*/
public function setPublic($public)
{
$this->public = $public;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return $this;
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return int
*/
public function getMinute()
{
return $this->minute;
}
/**
* @param int $minute
*
* @return $this;
*/
public function setMinute($minute)
{
$this->minute = $minute;
return $this;
}
/**
* @return string
*/
public function getEnergy()
{
return $this->energy;
}
/**
* @param string $energy
*
* @return $this;
*/
public function setEnergy($energy)
{
$this->energy = $energy;
return $this;
}
/**
* Add recipeImage.
*
* @param \Plugin\Recipe\Entity\RecipeImage $recipeImage
*
* @return Recipe
*/
public function addRecipeImage(RecipeImage $recipeImage)
{
$this->RecipeImage[] = $recipeImage;
return $this;
}
/**
* Remove recipeImage.
*
* @param \Plugin\Recipe\Entity\RecipeImage $recipeImage
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeRecipeImage(RecipeImage $recipeImage)
{
return $this->RecipeImage->removeElement($recipeImage);
}
/**
* Get recipeImage.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecipeImage()
{
return $this->RecipeImage;
}
/**
* Add recipeTag.
*
* @param \Plugin\Recipe\Entity\RecipeTag $recipeTag
*
* @return Recipe
*/
public function addRecipeTag(RecipeTag $recipeTag)
{
$this->RecipeTag[] = $recipeTag;
return $this;
}
/**
* Remove recipeTag.
*
* @param \Plugin\Recipe\Entity\RecipeTag $recipeTag
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeRecipeTag(RecipeTag $recipeTag)
{
return $this->RecipeTag->removeElement($recipeTag);
}
/**
* Get recipeTag.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecipeTag()
{
return $this->RecipeTag;
}
/**
* Get Tag
* フロント側タグsort_no順の配列を作成する
*
* @return []Tag
*/
public function getTags()
{
$tags = [];
foreach ($this->getRecipeTag() as $recipeTag) {
$tags[] = $recipeTag->getTag();
}
usort($tags, function (Tag $tag1, Tag $tag2) {
return $tag1->getSortNo() < $tag2->getSortNo();
});
return $tags;
}
/**
* Add recipeCategory.
*
* @param \Plugin\Recipe\Entity\RecipeCategory $recipeCategory
*
* @return Recipe
*/
public function addRecipeCategory(RecipeCategory $recipeCategory)
{
$this->RecipeCategory[] = $recipeCategory;
return $this;
}
/**
* Remove recipeCategory.
*
* @param \Plugin\Recipe\Entity\RecipeCategory $recipeCategory
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeRecipeCategory(RecipeCategory $recipeCategory)
{
return $this->RecipeCategory->removeElement($recipeCategory);
}
/**
* Get recipeCategory.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecipeCategory()
{
return $this->RecipeCategory;
}
/**
* Get Category
* フロント側タグsort_no順の配列を作成する
*
* @return []Category
*/
public function getCategorys()
{
$categorys = [];
foreach ($this->getRecipeCategory() as $recipeCategory) {
$categorys[] = $recipeCategory->getCategory();
}
usort($categorys, function (Category $category1, Category $category2) {
return $category1->getSortNo() < $category2->getSortNo();
});
return $categorys;
}
/**
* Add recipeMaterial.
*
* @param \Plugin\Recipe\Entity\RecipeMaterial $recipeMaterial
*
* @return Recipe
*/
public function addRecipeMaterial(RecipeMaterial $recipeMaterial)
{
$this->RecipeMaterial[] = $recipeMaterial;
return $this;
}
/**
* Remove recipeMaterial.
*
* @param \Plugin\Recipe\Entity\RecipeMaterial $recipeMaterial
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeRecipeMaterial(RecipeMaterial $recipeMaterial)
{
return $this->RecipeMaterial->removeElement($recipeMaterial);
}
/**
* Get recipeMaterial.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getRecipeMaterial()
{
return $this->RecipeMaterial;
}
/**
* Get Material
* フロント側タグsort_no順の配列を作成する
*
* @return []Material
*/
public function getMaterials()
{
$materials = [];
foreach ($this->getRecipeMaterial() as $recipeMaterial) {
$materials[] = $recipeMaterial->getMaterial();
}
usort($materials, function (Material $material1, Material $material2) {
return $material1->getSortNo() < $material2->getSortNo();
});
return $materials;
}
/**
* @return int
*/
public function getPeople()
{
return $this->people;
}
/**
* @param int $people
*
* @return $this;
*/
public function setPeople($people)
{
$this->people = $people;
return $this;
}
/**
* @return Collection|RecipeMaterialInfo[]
*/
public function getRecipeMaterialInfos()
{
return $this->RecipeMaterialInfos;
}
public function addRecipeMaterialInfo(RecipeMaterialInfo $RecipeMaterialInfo): self
{
if (!$this->RecipeMaterialInfos->contains($RecipeMaterialInfo)) {
$this->RecipeMaterialInfos[] = $RecipeMaterialInfo;
$RecipeMaterialInfo->setRecipe($this);
}
return $this;
}
public function removeRecipeMaterialInfo(RecipeMaterialInfo $RecipeMaterialInfo): self
{
if ($this->RecipeMaterialInfos->contains($RecipeMaterialInfo)) {
$this->RecipeMaterialInfos->removeElement($RecipeMaterialInfo);
// set the owning side to null (unless already changed)
if ($RecipeMaterialInfo->getRecipe() === $this) {
$RecipeMaterialInfo->setRecipe(null);
}
}
return $this;
}
/**
* @return Collection|RecipeStep[]
*/
public function getRecipeSteps()
{
return $this->RecipeSteps;
}
public function addRecipeStep(RecipeStep $RecipeStep): self
{
if (!$this->RecipeSteps->contains($RecipeStep)) {
$this->RecipeSteps[] = $RecipeStep;
$RecipeStep->setRecipe($this);
}
return $this;
}
public function removeRecipeStep(RecipeStep $RecipeStep): self
{
if ($this->RecipeSteps->contains($RecipeStep)) {
$this->RecipeSteps->removeElement($RecipeStep);
// set the owning side to null (unless already changed)
if ($RecipeStep->getRecipe() === $this) {
$RecipeStep->setRecipe(null);
}
}
return $this;
}
/**
* @return Collection|RecipeNutrition[]
*/
public function getRecipeNutritions()
{
return $this->RecipeNutritions;
}
public function addRecipeNutrition(RecipeNutrition $RecipeNutrition): self
{
if (!$this->RecipeNutritions->contains($RecipeNutrition)) {
$this->RecipeNutritions[] = $RecipeNutrition;
$RecipeNutrition->setRecipe($this);
}
return $this;
}
public function removeRecipeNutrition(RecipeNutrition $RecipeNutrition): self
{
if ($this->RecipeNutritions->contains($RecipeNutrition)) {
$this->RecipeNutritions->removeElement($RecipeNutrition);
// set the owning side to null (unless already changed)
if ($RecipeNutrition->getRecipe() === $this) {
$RecipeNutrition->setRecipe(null);
}
}
return $this;
}
/**
* Set recipeBadge.
*
* @param \Plugin\Recipe\Entity\RecipeBadge|null $recipeBadge
*
* @return Product
*/
public function setRecipeBadge(\Plugin\Recipe\Entity\RecipeBadge $recipeBadge = null)
{
$this->RecipeBadge = $recipeBadge;
return $this;
}
/**
* Get recipeBadge.
*
* @return \Plugin\Recipe\Entity\RecipeBadge|null
*/
public function getRecipeBadge()
{
return $this->RecipeBadge;
}
/**
* Set recipeCreator.
*
* @param \Plugin\Recipe\Entity\RecipeCreator|null $recipeCreator
*
* @return Product
*/
public function setRecipeCreator(\Plugin\Recipe\Entity\RecipeCreator $recipeCreator = null)
{
$this->RecipeCreator = $recipeCreator;
return $this;
}
/**
* Get recipeCreator.
*
* @return \Plugin\Recipe\Entity\RecipeCreator|null
*/
public function getRecipeCreator()
{
return $this->RecipeCreator;
}
/**
* @return string
*/
public function getCreatorHeading()
{
return $this->creatorHeading;
}
/**
* @param string $creatorHeading
*
* @return $this;
*/
public function setCreatorHeading($creatorHeading)
{
$this->creatorHeading = $creatorHeading;
return $this;
}
/**
* @return string
*/
public function getCreatorComment()
{
return $this->creatorComment;
}
/**
* @param string $creatorComment
*
* @return $this;
*/
public function setCreatorComment($creatorComment)
{
$this->creatorComment = $creatorComment;
return $this;
}
public function getMainListImage()
{
$RecipeImage = $this->getRecipeImage();
// 拡張子が画像のものを取得
foreach ($RecipeImage as $image) {
if (in_array(explode('.', $image->getFilename())[1], ['jpg', 'jpeg', 'png', 'gif'])) {
return $image->getFilename();
}
}
return null;
}
}
}