src/Entity/Recipe.php line 34

Open in your IDE?
  1. <?php
  2. /**
  3.  * @license Silk Software House Sp. Z O. O.
  4.  */
  5. declare(strict_types=1);
  6. namespace App\Entity;
  7. use App\Entity\Interfaces\PriorityInterface;
  8. use App\Entity\Interfaces\UserPriorityInterface;
  9. use App\Entity\Traits\CreatedByTrait;
  10. use App\Entity\Traits\CustomerOwnerTrait;
  11. use App\Entity\Traits\IdTrait;
  12. use App\Entity\Traits\TimePreUpdateTrait;
  13. use App\Entity\Traits\TimeTrait;
  14. use App\Entity\Traits\PriorityTrait;
  15. use App\Entity\Traits\UserPriorityTrait;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\ORM\Mapping as ORM;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. /**
  22.  * Class Recipe.
  23.  *
  24.  * @ORM\Table("recipes")
  25.  * @ORM\Entity(repositoryClass="App\Repository\RecipeRepository")
  26.  * @ORM\HasLifecycleCallbacks()
  27.  *
  28.  * @Gedmo\SoftDeleteable()
  29.  */
  30. class Recipe implements PriorityInterfaceUserPriorityInterface
  31. {
  32.     use IdTrait;
  33.     use TimeTrait;
  34.     use TimePreUpdateTrait;
  35.     use CreatedByTrait;
  36.     use CustomerOwnerTrait;
  37.     use PriorityTrait;
  38.     use UserPriorityTrait;
  39.     /**
  40.      * Name.
  41.      *
  42.      * @var string
  43.      *
  44.      * @Assert\NotBlank()
  45.      *
  46.      * @ORM\Column(name="name", type="text", nullable=false, options={"comment": "Recipe name.","default": ""})
  47.      */
  48.     private string $name '';
  49.     /**
  50.      * Short name.
  51.      *
  52.      * @var string
  53.      *
  54.      * @Assert\NotBlank()
  55.      *
  56.      * @ORM\Column(name="short_name", type="text", nullable=false, options={"comment": "Recipe name.","default": ""})
  57.      */
  58.     private string $shortName '';
  59.     /**
  60.      * Fcc28 [MPa].
  61.      *
  62.      * @var float|null
  63.      *
  64.      * @Assert\Type(type={"float", "integer"})
  65.      *
  66.      * @ORM\Column(name="fcc28", type="float", nullable=true, options={
  67.      *     "comment": "Compressive strength - fcc28 [MPa]",
  68.      *     "default": 28.0
  69.      * })
  70.      */
  71.     private ?float $fcc 28.0;
  72.     /**
  73.      * Dte0 [h].
  74.      *
  75.      * @var float|null
  76.      *
  77.      * @Assert\Type(type={"float", "integer"})
  78.      *
  79.      * @ORM\Column(name="dte0", type="float", nullable=true, options={
  80.      *     "comment": "Dte0 [h]",
  81.      *     "default": 0.0
  82.      * })
  83.      */
  84.     private ?float $dTe 0.0;
  85.     /**
  86.      * Beta add.
  87.      *
  88.      * @var float|null
  89.      *
  90.      * @Assert\Type(type={"float", "integer"})
  91.      *
  92.      * @ORM\Column(name="beta_add", type="float", nullable=true, options={
  93.      *     "comment": "Beta add.",
  94.      *     "default": 1.0
  95.      * })
  96.      */
  97.     private ?float $betaAdd 1.0;
  98.     /**
  99.      * Theta.
  100.      *
  101.      * @var float|null
  102.      *
  103.      * @Assert\Type(type={"float", "integer"})
  104.      *
  105.      * @ORM\Column(name="theta", type="float", nullable=true, options={
  106.      *     "comment": "Theta.",
  107.      *     "default": 4790.0
  108.      * })
  109.      */
  110.     private ?float $theta 4790.0;
  111.     /**
  112.      * Kappa.
  113.      *
  114.      * @var float|null
  115.      *
  116.      * @Assert\Type(type={"float", "integer"})
  117.      *
  118.      * @ORM\Column(name="kappa", type="float", nullable=true, options={
  119.      *     "comment": "Beta add.",
  120.      *     "default": 0.54
  121.      * })
  122.      */
  123.     private ?float $kappa 0.54;
  124.     /**
  125.      * S.
  126.      *
  127.      * @var float|null
  128.      *
  129.      * @Assert\Type(type={"float", "integer"})
  130.      *
  131.      * @ORM\Column(name="s", type="float", nullable=true, options={
  132.      *     "comment": "s [-]",
  133.      *     "default": 0.179146067858747
  134.      * })
  135.      */
  136.     private ?float $s 0.179146067858747;
  137.     /**
  138.      * tS.
  139.      *
  140.      * @var float|null
  141.      *
  142.      * @Assert\Type(type={"float", "integer"})
  143.      *
  144.      * @ORM\Column(name="ts", type="float", nullable=true, options={
  145.      *     "comment": "tS [h]",
  146.      *     "default": 14.2917220426857
  147.      * })
  148.      */
  149.     private ?float $tS 14.2917220426857;
  150.     /**
  151.      * tA.
  152.      *
  153.      * @var float|null
  154.      *
  155.      * @Assert\Type(type={"float", "integer"})
  156.      *
  157.      * @ORM\Column(name="ta", type="float", nullable=true, options={
  158.      *     "comment": "tA [h].",
  159.      *     "default": 15.4857640822475
  160.      * })
  161.      */
  162.     private ?float $tA 15.4857640822475;
  163.     /**
  164.      * nA.
  165.      *
  166.      * @var float|null
  167.      *
  168.      * @Assert\Type(type={"float", "integer"})
  169.      *
  170.      * @ORM\Column(name="na", type="float", nullable=true, options={
  171.      *     "comment": "nA [h].",
  172.      *     "default": 2.0
  173.      * })
  174.      */
  175.     private ?float $nA 2.0;
  176.     /**
  177.      * fA.
  178.      *
  179.      * @var float|null
  180.      *
  181.      * @Assert\Type(type={"float", "integer"})
  182.      *
  183.      * @ORM\Column(name="fa", type="float", nullable=true, options={
  184.      *     "comment": "FA [MPa]",
  185.      *     "default": 0.5
  186.      * })
  187.      */
  188.     private ?float $fa 0.5;
  189.     /**
  190.      * Created from entity.
  191.      *
  192.      * @var Recipe|null
  193.      *
  194.      * @ORM\ManyToOne(targetEntity="App\Entity\Recipe", inversedBy="clones")
  195.      * @ORM\JoinColumn(name="created_from_id", nullable=true)
  196.      */
  197.     private ?Recipe $createdFrom null;
  198.     /**
  199.      * Clones.
  200.      *
  201.      * @ORM\OneToMany(targetEntity="App\Entity\Recipe", mappedBy="createdFrom")
  202.      */
  203.     private $clones;
  204.     /**
  205.      * @var float error virtual field.
  206.      */
  207.     private float $error 0.0;
  208.     /**
  209.      * @ORM\OneToMany(targetEntity="App\Entity\RecipeToSync", mappedBy="recipe", cascade={"remove"})
  210.      */
  211.     private $recipeToSyncs;
  212.     /**
  213.      * country.
  214.      *
  215.      * @var string|null
  216.      *
  217.      * @ORM\Column(name="country", type="text", nullable=true, options={"comment": "Recipe country.","default": ""})
  218.      */
  219.     private ?string $country null;
  220.     /**
  221.      * Brand.
  222.      *
  223.      * @var string|null
  224.      *
  225.      * @ORM\Column(name="brand", type="text", nullable=true, options={"comment": "Recipe brand.","default": ""})
  226.      */
  227.     private ?string $brand null;
  228.     /**
  229.      * Recipe constructor.
  230.      */
  231.     public function __construct()
  232.     {
  233.         $this->clones = new ArrayCollection();
  234.         $this->recipeToSyncs = new ArrayCollection();
  235.     }
  236.     /**
  237.      * Get name.
  238.      *
  239.      * @return string
  240.      */
  241.     public function getName(): string
  242.     {
  243.         return $this->name;
  244.     }
  245.     /**
  246.      * Set name.
  247.      *
  248.      * @param string $name
  249.      *
  250.      * @return Recipe
  251.      */
  252.     public function setName(string $name): self
  253.     {
  254.         $this->name $name;
  255.         return $this;
  256.     }
  257.     /**
  258.      * Get short name.
  259.      *
  260.      * @return string
  261.      */
  262.     public function getShortName(): ?string
  263.     {
  264.         return $this->shortName;
  265.     }
  266.     /**
  267.      * Set a short name.
  268.      *
  269.      * @param string $shortName
  270.      *
  271.      * @return Recipe
  272.      */
  273.     public function setShortName(string $shortName): self
  274.     {
  275.         $this->shortName $shortName;
  276.         return $this;
  277.     }
  278.     /**
  279.      * Get fcc.
  280.      *
  281.      * @return float
  282.      */
  283.     public function getFcc(): ?float
  284.     {
  285.         return $this->fcc;
  286.     }
  287.     /**
  288.      * Get fcc or calculate for given maturity.
  289.      *
  290.      * @param float|null $te
  291.      *
  292.      * @return float
  293.      */
  294.     public function getFccInPoint(float $te): float
  295.     {
  296.         if ($te <= 0) {
  297.             return 0.0;
  298.         }
  299.         if ($te <= $this->getTa()) {
  300.             return $this->getFa() * (($te $this->getTa()) ** $this->getNa());
  301.         }
  302.         if ($te <= 672.0) {
  303.             return $this->getFcc() * exp($this->getS() * (1.0 sqrt((672.0 $this->getTs()) / ($te $this->getTS()))));
  304.         }
  305.         return $this->getFcc();
  306.     }
  307.     /**
  308.      * Set fcc.
  309.      *
  310.      * @param float $fcc
  311.      *
  312.      * @return Recipe
  313.      */
  314.     public function setFcc(float $fcc): self
  315.     {
  316.         $this->fcc $fcc;
  317.         return $this;
  318.     }
  319.     /**
  320.      * Get DTe.
  321.      *
  322.      * @return float
  323.      */
  324.     public function getDTe(): ?float
  325.     {
  326.         return $this->dTe ?? 0.0;
  327.     }
  328.     /**
  329.      * Set dte.
  330.      *
  331.      * @param float $dTe
  332.      *
  333.      * @return Recipe
  334.      */
  335.     public function setDTe(float $dTe): self
  336.     {
  337.         $this->dTe $dTe;
  338.         return $this;
  339.     }
  340.     /**
  341.      * Get beta add.
  342.      *
  343.      * @return float
  344.      */
  345.     public function getBetaAdd(): ?float
  346.     {
  347.         return $this->betaAdd;
  348.     }
  349.     /**
  350.      * Set beta add.
  351.      *
  352.      * @param float $betaAdd
  353.      *
  354.      * @return Recipe
  355.      */
  356.     public function setBetaAdd(float $betaAdd): self
  357.     {
  358.         $this->betaAdd $betaAdd;
  359.         return $this;
  360.     }
  361.     /**
  362.      * Get theta.
  363.      *
  364.      * @return float
  365.      */
  366.     public function getTheta(): ?float
  367.     {
  368.         return $this->theta;
  369.     }
  370.     /**
  371.      * Set theta.
  372.      *
  373.      * @param float $theta
  374.      *
  375.      * @return Recipe
  376.      */
  377.     public function setTheta(float $theta): self
  378.     {
  379.         $this->theta $theta;
  380.         return $this;
  381.     }
  382.     /**
  383.      * Get kappa.
  384.      *
  385.      * @return float
  386.      */
  387.     public function getKappa(): ?float
  388.     {
  389.         return $this->kappa;
  390.     }
  391.     /**
  392.      * Set kappa.
  393.      *
  394.      * @param float $kappa
  395.      *
  396.      * @return Recipe
  397.      */
  398.     public function setKappa(float $kappa): self
  399.     {
  400.         $this->kappa $kappa;
  401.         return $this;
  402.     }
  403.     /**
  404.      * Get s.
  405.      *
  406.      * @return float
  407.      */
  408.     public function getS(): ?float
  409.     {
  410.         return $this->s;
  411.     }
  412.     /**
  413.      * Set s.
  414.      *
  415.      * @param float $s
  416.      *
  417.      * @return Recipe
  418.      */
  419.     public function setS(float $s): self
  420.     {
  421.         $this->$s;
  422.         return $this;
  423.     }
  424.     /**
  425.      * Get ts.
  426.      *
  427.      * @return float
  428.      */
  429.     public function getTS(): ?float
  430.     {
  431.         return $this->tS;
  432.     }
  433.     /**
  434.      * Set ts.
  435.      *
  436.      * @param float $tS
  437.      *
  438.      * @return Recipe
  439.      */
  440.     public function setTS(float $tS): self
  441.     {
  442.         $this->tS $tS;
  443.         return $this;
  444.     }
  445.     /**
  446.      * Get na.
  447.      *
  448.      * @return float
  449.      */
  450.     public function getNA(): ?float
  451.     {
  452.         return $this->nA;
  453.     }
  454.     /**
  455.      * Set na.
  456.      *
  457.      * @param float $nA
  458.      *
  459.      * @return Recipe
  460.      */
  461.     public function setNA(float $nA): self
  462.     {
  463.         $this->nA $nA;
  464.         return $this;
  465.     }
  466.     /**
  467.      * Get ta.
  468.      *
  469.      * @return float
  470.      */
  471.     public function getTA(): ?float
  472.     {
  473.         return $this->tA;
  474.     }
  475.     /**
  476.      * Set ta.
  477.      *
  478.      * @param float $tA
  479.      *
  480.      * @return Recipe
  481.      */
  482.     public function setTA(float $tA): self
  483.     {
  484.         $this->tA $tA;
  485.         return $this;
  486.     }
  487.     /**
  488.      * Get fa.
  489.      *
  490.      * @return float
  491.      */
  492.     public function getFa(): ?float
  493.     {
  494.         return $this->fa;
  495.     }
  496.     /**
  497.      * Set fa.
  498.      *
  499.      * @param float $fa
  500.      *
  501.      * @return Recipe
  502.      */
  503.     public function setFa(float $fa): self
  504.     {
  505.         $this->fa $fa;
  506.         return $this;
  507.     }
  508.     /**
  509.      * To string.
  510.      *
  511.      * @return string
  512.      */
  513.     public function __toString()
  514.     {
  515.         return $this->name ?? '';
  516.     }
  517.     /**
  518.      * Get created from.
  519.      *
  520.      * @return Recipe|null
  521.      */
  522.     public function getCreatedFrom(): ?self
  523.     {
  524.         return $this->createdFrom;
  525.     }
  526.     /**
  527.      * Set created from.
  528.      *
  529.      * @param Recipe $createdFrom
  530.      *
  531.      * @return Recipe
  532.      */
  533.     public function setCreatedFrom(self $createdFrom): self
  534.     {
  535.         $this->createdFrom $createdFrom;
  536.         return $this;
  537.     }
  538.     /**
  539.      * Get is complete.
  540.      *
  541.      * @return bool
  542.      */
  543.     public function getIsComplete(): bool
  544.     {
  545.         return isset(
  546.             $this->dTe,
  547.             $this->fa,
  548.             $this->nA,
  549.             $this->tS,
  550.             $this->kappa,
  551.             $this->betaAdd,
  552.             $this->theta,
  553.             $this->fcc,
  554.             $this->s,
  555.         );
  556.     }
  557.     /**
  558.      * @return float
  559.      */
  560.     public function getError(): float
  561.     {
  562.         return $this->error;
  563.     }
  564.     /**
  565.      * @param float $error
  566.      *
  567.      * @return Recipe
  568.      */
  569.     public function setError(float $error): self
  570.     {
  571.         $this->error $error;
  572.         return $this;
  573.     }
  574.     /**
  575.      * @return Collection|RecipeToSync[]
  576.      */
  577.     public function getRecipeToSyncs(): Collection
  578.     {
  579.         return $this->recipeToSyncs;
  580.     }
  581.     public function addRecipeToSync(RecipeToSync $recipeToSync): self
  582.     {
  583.         if (!$this->recipeToSyncs->contains($recipeToSync)) {
  584.             $this->recipeToSyncs[] = $recipeToSync;
  585.             $recipeToSync->setRecipe($this);
  586.         }
  587.         return $this;
  588.     }
  589.     public function removeRecipeToSync(RecipeToSync $recipeToSync): self
  590.     {
  591.         if ($this->recipeToSyncs->contains($recipeToSync)) {
  592.             $this->recipeToSyncs->removeElement($recipeToSync);
  593.             // set the owning side to null (unless already changed)
  594.             if ($recipeToSync->getRecipe() === $this) {
  595.                 $recipeToSync->setRecipe(null);
  596.             }
  597.         }
  598.         return $this;
  599.     }
  600.     /**
  601.      * @return string|null
  602.      */
  603.     public function getCountry(): ?string
  604.     {
  605.         return $this->country;
  606.     }
  607.     /**
  608.      * @param string|null $country
  609.      *
  610.      * @return $this
  611.      */
  612.     public function setCountry(?string $country): self
  613.     {
  614.         $this->country $country;
  615.         return $this;
  616.     }
  617.     /**
  618.      * @return string|null
  619.      */
  620.     public function getBrand(): ?string
  621.     {
  622.         return $this->brand;
  623.     }
  624.     /**
  625.      * @param string|null $brand
  626.      *
  627.      * @return Recipe
  628.      */
  629.     public function setBrand(?string $brand): self
  630.     {
  631.         $this->brand $brand ? : null;
  632.         return $this;
  633.     }
  634.     /**
  635.      * @return string[]
  636.      */
  637.     public function getBrands(): array
  638.     {
  639.         $brands explode(','$this->brand ?? '');
  640.         return array_map(static function (string $brand) {
  641.             return trim($brand);
  642.         }, $brands);
  643.     }
  644. }