app/Plugin/Recipe/Entity/Recipe.php line 396

Open in your IDE?
  1. <?php
  2. namespace Plugin\Recipe\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. if (!class_exists('\Plugin\Recipe\Entity\Recipe'false)) {
  6.     /**
  7.      * Recipe
  8.      *
  9.      * @ORM\Table(name="plg_recipe")
  10.      * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  11.      * @ORM\Entity(repositoryClass="Plugin\Recipe\Repository\RecipeRepository")
  12.      */
  13.     class Recipe
  14.     {
  15.         /**
  16.          * @var int
  17.          *
  18.          * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  19.          * @ORM\Id
  20.          * @ORM\GeneratedValue(strategy="IDENTITY")
  21.          */
  22.         private $id;
  23.         /**
  24.          * @var bool
  25.          * @ORM\Column(name="public", type="boolean", options={"default":true})
  26.          */
  27.         private $public;
  28.         /**
  29.          * @var string
  30.          *
  31.          * @ORM\Column(name="name", type="string", length=255)
  32.          */
  33.         private $name;
  34.         /**
  35.          * @var int
  36.          *
  37.          * @ORM\Column(name="minute", type="integer", options={"unsigned":false})
  38.          */
  39.         private $minute;
  40.         /**
  41.          * @var int
  42.          *
  43.          * @ORM\Column(name="energy", type="integer", options={"unsigned":false})
  44.          */
  45.         private $energy;
  46.         /**
  47.          * @var \Doctrine\Common\Collections\Collection
  48.          *
  49.          * @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeImage", mappedBy="Recipe", cascade={"remove"})
  50.          * @ORM\OrderBy({
  51.          *     "sort_no"="ASC"
  52.          * })
  53.          */
  54.         private $RecipeImage;
  55.         /**
  56.          * @var \Doctrine\Common\Collections\Collection
  57.          *
  58.          * @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeTag", mappedBy="Recipe", cascade={"remove"})
  59.          */
  60.         private $RecipeTag;
  61.         /**
  62.          * @var \Doctrine\Common\Collections\Collection
  63.          *
  64.          * @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeCategory", mappedBy="Recipe", cascade={"remove"})
  65.          */
  66.         private $RecipeCategory;
  67.         /**
  68.          * @var \Doctrine\Common\Collections\Collection
  69.          *
  70.          * @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RecipeMaterial", mappedBy="Recipe", cascade={"remove"})
  71.          */
  72.         private $RecipeMaterial;
  73.         /**
  74.          * @var int
  75.          *
  76.          * @ORM\Column(name="people", type="integer", options={"unsigned":false}, nullable=true)
  77.          */
  78.         private $people;
  79.         /**
  80.          * @var \Doctrine\Common\Collections\Collection|RecipeMaterialInfo[]
  81.          *
  82.          * @ORM\OneToMany(targetEntity=RecipeMaterialInfo::class, mappedBy="Recipe", cascade={"persist", "remove"})
  83.          * @ORM\OrderBy({"sort_no" = "ASC"})
  84.          */
  85.         private $RecipeMaterialInfos;
  86.         /**
  87.          * @var \Doctrine\Common\Collections\Collection|RecipeStep[]
  88.          *
  89.          * @ORM\OneToMany(targetEntity=RecipeStep::class, mappedBy="Recipe", cascade={"persist", "remove"})
  90.          * @ORM\OrderBy({"sort_no" = "ASC"})
  91.          */
  92.         private $RecipeSteps;
  93.         /**
  94.          * @var \Doctrine\Common\Collections\Collection|RecipeNutrition[]
  95.          *
  96.          * @ORM\OneToMany(targetEntity=RecipeNutrition::class, mappedBy="Recipe", cascade={"persist", "remove"})
  97.          * @ORM\OrderBy({"sort_no" = "ASC"})
  98.          */
  99.         private $RecipeNutritions;
  100.         /**
  101.          * @var \Plugin\Recipe\Entity\RecipeBadge
  102.          *
  103.          * @ORM\ManyToOne(targetEntity="Plugin\Recipe\Entity\RecipeBadge")
  104.          * @ORM\JoinColumns({
  105.          *   @ORM\JoinColumn(name="recipe_badge_id", referencedColumnName="id")
  106.          * })
  107.          */
  108.         private $RecipeBadge;
  109.         /**
  110.          * @var \Plugin\Recipe\Entity\RecipeCreator
  111.          *
  112.          * @ORM\ManyToOne(targetEntity="Plugin\Recipe\Entity\RecipeCreator")
  113.          * @ORM\JoinColumns({
  114.          *   @ORM\JoinColumn(name="recipe_creator_id", referencedColumnName="id")
  115.          * })
  116.          */
  117.         private $RecipeCreator;
  118.         /**
  119.          * @var string
  120.          *
  121.          * @ORM\Column(name="creator_heading", type="string", length=255, nullable=true)
  122.          */
  123.         private $creatorHeading;
  124.         /**
  125.          * @var string
  126.          *
  127.          * @ORM\Column(name="creator_comment", type="string", length=4000, nullable=true)
  128.          */
  129.         private $creatorComment;
  130.         /**
  131.          * @var RelatedProduct[]|Collection
  132.          *
  133.          * @ORM\OneToMany(targetEntity="Plugin\Recipe\Entity\RelatedProduct", mappedBy="Recipe", cascade={"persist", "remove"})
  134.          * @ORM\OrderBy({
  135.          *     "id"="ASC"
  136.          * })
  137.          */
  138.         private $RelatedProducts;
  139.         /**
  140.          * @return RelatedProduct[]|Collection
  141.          */
  142.         public function getEnableRelatedProducts()
  143.         {
  144.           $results = new ArrayCollection();
  145.           foreach ($this->RelatedProducts as $RelatedProduct) {
  146.             if (
  147.               $RelatedProduct->getChildProduct() === null ||
  148.               $RelatedProduct->getChildProduct()->isEnable() === false
  149.             ) {
  150.               continue;
  151.             } else {
  152.               $results->add($RelatedProduct);
  153.             }
  154.           }
  155.           return $results;
  156.         }
  157.         /**
  158.          * @return RelatedProduct[]|Collection
  159.          */
  160.         public function getRelatedProducts()
  161.         {
  162.             if (null === $this->RelatedProducts) {
  163.                 $this->RelatedProducts = new ArrayCollection();
  164.             }
  165.             return $this->RelatedProducts;
  166.         }
  167.         /**
  168.          * @param RelatedProduct $RelatedProduct
  169.          */
  170.         public function addRelatedProduct(RelatedProduct $RelatedProduct)
  171.         {
  172.             if (null === $this->RelatedProducts) {
  173.                 $this->RelatedProducts = new ArrayCollection();
  174.             }
  175.             $this->RelatedProducts[] = $RelatedProduct;
  176.         }
  177.         /**
  178.          * @param RelatedProduct $RelatedProduct
  179.          *
  180.          * @return bool
  181.          */
  182.         public function removeRelatedProduct(RelatedProduct $RelatedProduct)
  183.         {
  184.             if (null === $this->RelatedProducts) {
  185.                 $this->RelatedProducts = new ArrayCollection();
  186.             }
  187.             return $this->RelatedProducts->removeElement($RelatedProduct);
  188.         }
  189.         /**
  190.          * Constructor
  191.          */
  192.         public function __construct()
  193.         {
  194.             $this->RecipeImage = new \Doctrine\Common\Collections\ArrayCollection();
  195.             $this->RecipeTag = new \Doctrine\Common\Collections\ArrayCollection();
  196.             $this->RecipeCategory = new \Doctrine\Common\Collections\ArrayCollection();
  197.             $this->RecipeMaterial = new \Doctrine\Common\Collections\ArrayCollection();
  198.             $this->RecipeMaterialInfos = new ArrayCollection();
  199.             $this->RecipeSteps = new ArrayCollection();
  200.             $this->RecipeNutritions = new ArrayCollection();
  201.         }
  202.         /**
  203.          * @return int
  204.          */
  205.         public function getId()
  206.         {
  207.             return $this->id;
  208.         }
  209.         /**
  210.          * @return bool
  211.          */
  212.         public function getPublic()
  213.         {
  214.             return $this->public;
  215.         }
  216.         /**
  217.          * @param bool $public
  218.          *
  219.          * @return $this;
  220.          */
  221.         public function setPublic($public)
  222.         {
  223.             $this->public $public;
  224.             return $this;
  225.         }
  226.         /**
  227.          * @return string
  228.          */
  229.         public function getName()
  230.         {
  231.             return $this->name;
  232.         }
  233.         /**
  234.          * @param string $name
  235.          *
  236.          * @return $this;
  237.          */
  238.         public function setName($name)
  239.         {
  240.             $this->name $name;
  241.             return $this;
  242.         }
  243.         /**
  244.          * @return int
  245.          */
  246.         public function getMinute()
  247.         {
  248.             return $this->minute;
  249.         }
  250.         /**
  251.          * @param int $minute
  252.          *
  253.          * @return $this;
  254.          */
  255.         public function setMinute($minute)
  256.         {
  257.             $this->minute $minute;
  258.             return $this;
  259.         }
  260.         /**
  261.          * @return string
  262.          */
  263.         public function getEnergy()
  264.         {
  265.             return $this->energy;
  266.         }
  267.         /**
  268.          * @param string $energy
  269.          *
  270.          * @return $this;
  271.          */
  272.         public function setEnergy($energy)
  273.         {
  274.             $this->energy $energy;
  275.             return $this;
  276.         }
  277.         /**
  278.          * Add recipeImage.
  279.          *
  280.          * @param \Plugin\Recipe\Entity\RecipeImage $recipeImage
  281.          *
  282.          * @return Recipe
  283.          */
  284.         public function addRecipeImage(RecipeImage $recipeImage)
  285.         {
  286.             $this->RecipeImage[] = $recipeImage;
  287.             return $this;
  288.         }
  289.         /**
  290.          * Remove recipeImage.
  291.          *
  292.          * @param \Plugin\Recipe\Entity\RecipeImage $recipeImage
  293.          *
  294.          * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  295.          */
  296.         public function removeRecipeImage(RecipeImage $recipeImage)
  297.         {
  298.             return $this->RecipeImage->removeElement($recipeImage);
  299.         }
  300.         /**
  301.          * Get recipeImage.
  302.          *
  303.          * @return \Doctrine\Common\Collections\Collection
  304.          */
  305.         public function getRecipeImage()
  306.         {
  307.             return $this->RecipeImage;
  308.         }
  309.         /**
  310.          * Add recipeTag.
  311.          *
  312.          * @param \Plugin\Recipe\Entity\RecipeTag $recipeTag
  313.          *
  314.          * @return Recipe
  315.          */
  316.         public function addRecipeTag(RecipeTag $recipeTag)
  317.         {
  318.             $this->RecipeTag[] = $recipeTag;
  319.             return $this;
  320.         }
  321.         /**
  322.          * Remove recipeTag.
  323.          *
  324.          * @param \Plugin\Recipe\Entity\RecipeTag $recipeTag
  325.          *
  326.          * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  327.          */
  328.         public function removeRecipeTag(RecipeTag $recipeTag)
  329.         {
  330.             return $this->RecipeTag->removeElement($recipeTag);
  331.         }
  332.         /**
  333.          * Get recipeTag.
  334.          *
  335.          * @return \Doctrine\Common\Collections\Collection
  336.          */
  337.         public function getRecipeTag()
  338.         {
  339.             return $this->RecipeTag;
  340.         }
  341.         /**
  342.          * Get Tag
  343.          * フロント側タグsort_no順の配列を作成する
  344.          *
  345.          * @return []Tag
  346.          */
  347.         public function getTags()
  348.         {
  349.             $tags = [];
  350.             foreach ($this->getRecipeTag() as $recipeTag) {
  351.                 $tags[] = $recipeTag->getTag();
  352.             }
  353.             usort($tags, function (Tag $tag1Tag $tag2) {
  354.                 return $tag1->getSortNo() < $tag2->getSortNo();
  355.             });
  356.             return $tags;
  357.         }
  358.         /**
  359.          * Add recipeCategory.
  360.          *
  361.          * @param \Plugin\Recipe\Entity\RecipeCategory $recipeCategory
  362.          *
  363.          * @return Recipe
  364.          */
  365.         public function addRecipeCategory(RecipeCategory $recipeCategory)
  366.         {
  367.             $this->RecipeCategory[] = $recipeCategory;
  368.             return $this;
  369.         }
  370.         /**
  371.          * Remove recipeCategory.
  372.          *
  373.          * @param \Plugin\Recipe\Entity\RecipeCategory $recipeCategory
  374.          *
  375.          * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  376.          */
  377.         public function removeRecipeCategory(RecipeCategory $recipeCategory)
  378.         {
  379.             return $this->RecipeCategory->removeElement($recipeCategory);
  380.         }
  381.         /**
  382.          * Get recipeCategory.
  383.          *
  384.          * @return \Doctrine\Common\Collections\Collection
  385.          */
  386.         public function getRecipeCategory()
  387.         {
  388.             return $this->RecipeCategory;
  389.         }
  390.         /**
  391.          * Get Category
  392.          * フロント側タグsort_no順の配列を作成する
  393.          *
  394.          * @return []Category
  395.          */
  396.         public function getCategorys()
  397.         {
  398.             $categorys = [];
  399.             foreach ($this->getRecipeCategory() as $recipeCategory) {
  400.                 $categorys[] = $recipeCategory->getCategory();
  401.             }
  402.             usort($categorys, function (Category $category1Category $category2) {
  403.                 return $category1->getSortNo() < $category2->getSortNo();
  404.             });
  405.             return $categorys;
  406.         }
  407.         /**
  408.          * Add recipeMaterial.
  409.          *
  410.          * @param \Plugin\Recipe\Entity\RecipeMaterial $recipeMaterial
  411.          *
  412.          * @return Recipe
  413.          */
  414.         public function addRecipeMaterial(RecipeMaterial $recipeMaterial)
  415.         {
  416.             $this->RecipeMaterial[] = $recipeMaterial;
  417.             return $this;
  418.         }
  419.         /**
  420.          * Remove recipeMaterial.
  421.          *
  422.          * @param \Plugin\Recipe\Entity\RecipeMaterial $recipeMaterial
  423.          *
  424.          * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  425.          */
  426.         public function removeRecipeMaterial(RecipeMaterial $recipeMaterial)
  427.         {
  428.             return $this->RecipeMaterial->removeElement($recipeMaterial);
  429.         }
  430.         /**
  431.          * Get recipeMaterial.
  432.          *
  433.          * @return \Doctrine\Common\Collections\Collection
  434.          */
  435.         public function getRecipeMaterial()
  436.         {
  437.             return $this->RecipeMaterial;
  438.         }
  439.         /**
  440.          * Get Material
  441.          * フロント側タグsort_no順の配列を作成する
  442.          *
  443.          * @return []Material
  444.          */
  445.         public function getMaterials()
  446.         {
  447.             $materials = [];
  448.             foreach ($this->getRecipeMaterial() as $recipeMaterial) {
  449.                 $materials[] = $recipeMaterial->getMaterial();
  450.             }
  451.             usort($materials, function (Material $material1Material $material2) {
  452.                 return $material1->getSortNo() < $material2->getSortNo();
  453.             });
  454.             return $materials;
  455.         }
  456.         /**
  457.          * @return int
  458.          */
  459.         public function getPeople()
  460.         {
  461.             return $this->people;
  462.         }
  463.         /**
  464.          * @param int $people
  465.          *
  466.          * @return $this;
  467.          */
  468.         public function setPeople($people)
  469.         {
  470.             $this->people $people;
  471.             return $this;
  472.         }
  473.         /**
  474.          * @return Collection|RecipeMaterialInfo[]
  475.          */
  476.         public function getRecipeMaterialInfos()
  477.         {
  478.           return $this->RecipeMaterialInfos;
  479.         }
  480.         public function addRecipeMaterialInfo(RecipeMaterialInfo $RecipeMaterialInfo): self
  481.         {
  482.           if (!$this->RecipeMaterialInfos->contains($RecipeMaterialInfo)) {
  483.             $this->RecipeMaterialInfos[] = $RecipeMaterialInfo;
  484.             $RecipeMaterialInfo->setRecipe($this);
  485.           }
  486.           return $this;
  487.         }
  488.         public function removeRecipeMaterialInfo(RecipeMaterialInfo $RecipeMaterialInfo): self
  489.         {
  490.           if ($this->RecipeMaterialInfos->contains($RecipeMaterialInfo)) {
  491.             $this->RecipeMaterialInfos->removeElement($RecipeMaterialInfo);
  492.             // set the owning side to null (unless already changed)
  493.             if ($RecipeMaterialInfo->getRecipe() === $this) {
  494.               $RecipeMaterialInfo->setRecipe(null);
  495.             }
  496.           }
  497.           return $this;
  498.         }
  499.         /**
  500.          * @return Collection|RecipeStep[]
  501.          */
  502.         public function getRecipeSteps()
  503.         {
  504.           return $this->RecipeSteps;
  505.         }
  506.         public function addRecipeStep(RecipeStep $RecipeStep): self
  507.         {
  508.           if (!$this->RecipeSteps->contains($RecipeStep)) {
  509.             $this->RecipeSteps[] = $RecipeStep;
  510.             $RecipeStep->setRecipe($this);
  511.           }
  512.           return $this;
  513.         }
  514.         public function removeRecipeStep(RecipeStep $RecipeStep): self
  515.         {
  516.           if ($this->RecipeSteps->contains($RecipeStep)) {
  517.             $this->RecipeSteps->removeElement($RecipeStep);
  518.             // set the owning side to null (unless already changed)
  519.             if ($RecipeStep->getRecipe() === $this) {
  520.               $RecipeStep->setRecipe(null);
  521.             }
  522.           }
  523.           return $this;
  524.         }
  525.         /**
  526.          * @return Collection|RecipeNutrition[]
  527.          */
  528.         public function getRecipeNutritions()
  529.         {
  530.           return $this->RecipeNutritions;
  531.         }
  532.         public function addRecipeNutrition(RecipeNutrition $RecipeNutrition): self
  533.         {
  534.           if (!$this->RecipeNutritions->contains($RecipeNutrition)) {
  535.             $this->RecipeNutritions[] = $RecipeNutrition;
  536.             $RecipeNutrition->setRecipe($this);
  537.           }
  538.           return $this;
  539.         }
  540.         public function removeRecipeNutrition(RecipeNutrition $RecipeNutrition): self
  541.         {
  542.           if ($this->RecipeNutritions->contains($RecipeNutrition)) {
  543.             $this->RecipeNutritions->removeElement($RecipeNutrition);
  544.             // set the owning side to null (unless already changed)
  545.             if ($RecipeNutrition->getRecipe() === $this) {
  546.               $RecipeNutrition->setRecipe(null);
  547.             }
  548.           }
  549.           return $this;
  550.         }
  551.         /**
  552.          * Set recipeBadge.
  553.          *
  554.          * @param \Plugin\Recipe\Entity\RecipeBadge|null $recipeBadge
  555.          *
  556.          * @return Product
  557.          */
  558.         public function setRecipeBadge(\Plugin\Recipe\Entity\RecipeBadge $recipeBadge null)
  559.         {
  560.             $this->RecipeBadge $recipeBadge;
  561.             return $this;
  562.         }
  563.         /**
  564.          * Get recipeBadge.
  565.          *
  566.          * @return \Plugin\Recipe\Entity\RecipeBadge|null
  567.          */
  568.         public function getRecipeBadge()
  569.         {
  570.             return $this->RecipeBadge;
  571.         }
  572.         /**
  573.          * Set recipeCreator.
  574.          *
  575.          * @param \Plugin\Recipe\Entity\RecipeCreator|null $recipeCreator
  576.          *
  577.          * @return Product
  578.          */
  579.         public function setRecipeCreator(\Plugin\Recipe\Entity\RecipeCreator $recipeCreator null)
  580.         {
  581.             $this->RecipeCreator $recipeCreator;
  582.             return $this;
  583.         }
  584.         /**
  585.          * Get recipeCreator.
  586.          *
  587.          * @return \Plugin\Recipe\Entity\RecipeCreator|null
  588.          */
  589.         public function getRecipeCreator()
  590.         {
  591.             return $this->RecipeCreator;
  592.         }
  593.         /**
  594.          * @return string
  595.          */
  596.         public function getCreatorHeading()
  597.         {
  598.             return $this->creatorHeading;
  599.         }
  600.         /**
  601.          * @param string $creatorHeading
  602.          *
  603.          * @return $this;
  604.          */
  605.         public function setCreatorHeading($creatorHeading)
  606.         {
  607.             $this->creatorHeading $creatorHeading;
  608.             return $this;
  609.         }
  610.         /**
  611.          * @return string
  612.          */
  613.         public function getCreatorComment()
  614.         {
  615.             return $this->creatorComment;
  616.         }
  617.         /**
  618.          * @param string $creatorComment
  619.          *
  620.          * @return $this;
  621.          */
  622.         public function setCreatorComment($creatorComment)
  623.         {
  624.             $this->creatorComment $creatorComment;
  625.             return $this;
  626.         }
  627.         public function getMainListImage()
  628.         {
  629.             $RecipeImage $this->getRecipeImage();
  630.             // 拡張子が画像のものを取得
  631.             foreach ($RecipeImage as $image) {
  632.                 if (in_array(explode('.'$image->getFilename())[1], ['jpg''jpeg''png''gif'])) {
  633.                     return $image->getFilename();
  634.                 }
  635.             }
  636.             return null;
  637.         }
  638.     }
  639. }