<?php
/**
* @license Silk Software House Sp. Z O. O.
*/
declare(strict_types=1);
namespace App\Entity;
use App\Entity\Interfaces\PriorityInterface;
use App\Entity\Interfaces\UserPriorityInterface;
use App\Entity\Traits\CreatedByTrait;
use App\Entity\Traits\CustomerOwnerTrait;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\TimePreUpdateTrait;
use App\Entity\Traits\TimeTrait;
use App\Entity\Traits\PriorityTrait;
use App\Entity\Traits\UserPriorityTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Recipe.
*
* @ORM\Table("recipes")
* @ORM\Entity(repositoryClass="App\Repository\RecipeRepository")
* @ORM\HasLifecycleCallbacks()
*
* @Gedmo\SoftDeleteable()
*/
class Recipe implements PriorityInterface, UserPriorityInterface
{
use IdTrait;
use TimeTrait;
use TimePreUpdateTrait;
use CreatedByTrait;
use CustomerOwnerTrait;
use PriorityTrait;
use UserPriorityTrait;
/**
* Name.
*
* @var string
*
* @Assert\NotBlank()
*
* @ORM\Column(name="name", type="text", nullable=false, options={"comment": "Recipe name.","default": ""})
*/
private string $name = '';
/**
* Short name.
*
* @var string
*
* @Assert\NotBlank()
*
* @ORM\Column(name="short_name", type="text", nullable=false, options={"comment": "Recipe name.","default": ""})
*/
private string $shortName = '';
/**
* Fcc28 [MPa].
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="fcc28", type="float", nullable=true, options={
* "comment": "Compressive strength - fcc28 [MPa]",
* "default": 28.0
* })
*/
private ?float $fcc = 28.0;
/**
* Dte0 [h].
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="dte0", type="float", nullable=true, options={
* "comment": "Dte0 [h]",
* "default": 0.0
* })
*/
private ?float $dTe = 0.0;
/**
* Beta add.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="beta_add", type="float", nullable=true, options={
* "comment": "Beta add.",
* "default": 1.0
* })
*/
private ?float $betaAdd = 1.0;
/**
* Theta.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="theta", type="float", nullable=true, options={
* "comment": "Theta.",
* "default": 4790.0
* })
*/
private ?float $theta = 4790.0;
/**
* Kappa.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="kappa", type="float", nullable=true, options={
* "comment": "Beta add.",
* "default": 0.54
* })
*/
private ?float $kappa = 0.54;
/**
* S.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="s", type="float", nullable=true, options={
* "comment": "s [-]",
* "default": 0.179146067858747
* })
*/
private ?float $s = 0.179146067858747;
/**
* tS.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="ts", type="float", nullable=true, options={
* "comment": "tS [h]",
* "default": 14.2917220426857
* })
*/
private ?float $tS = 14.2917220426857;
/**
* tA.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="ta", type="float", nullable=true, options={
* "comment": "tA [h].",
* "default": 15.4857640822475
* })
*/
private ?float $tA = 15.4857640822475;
/**
* nA.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="na", type="float", nullable=true, options={
* "comment": "nA [h].",
* "default": 2.0
* })
*/
private ?float $nA = 2.0;
/**
* fA.
*
* @var float|null
*
* @Assert\Type(type={"float", "integer"})
*
* @ORM\Column(name="fa", type="float", nullable=true, options={
* "comment": "FA [MPa]",
* "default": 0.5
* })
*/
private ?float $fa = 0.5;
/**
* Created from entity.
*
* @var Recipe|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Recipe", inversedBy="clones")
* @ORM\JoinColumn(name="created_from_id", nullable=true)
*/
private ?Recipe $createdFrom = null;
/**
* Clones.
*
* @ORM\OneToMany(targetEntity="App\Entity\Recipe", mappedBy="createdFrom")
*/
private $clones;
/**
* @var float error virtual field.
*/
private float $error = 0.0;
/**
* @ORM\OneToMany(targetEntity="App\Entity\RecipeToSync", mappedBy="recipe", cascade={"remove"})
*/
private $recipeToSyncs;
/**
* country.
*
* @var string|null
*
* @ORM\Column(name="country", type="text", nullable=true, options={"comment": "Recipe country.","default": ""})
*/
private ?string $country = null;
/**
* Brand.
*
* @var string|null
*
* @ORM\Column(name="brand", type="text", nullable=true, options={"comment": "Recipe brand.","default": ""})
*/
private ?string $brand = null;
/**
* Recipe constructor.
*/
public function __construct()
{
$this->clones = new ArrayCollection();
$this->recipeToSyncs = new ArrayCollection();
}
/**
* Get name.
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* Set name.
*
* @param string $name
*
* @return Recipe
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* Get short name.
*
* @return string
*/
public function getShortName(): ?string
{
return $this->shortName;
}
/**
* Set a short name.
*
* @param string $shortName
*
* @return Recipe
*/
public function setShortName(string $shortName): self
{
$this->shortName = $shortName;
return $this;
}
/**
* Get fcc.
*
* @return float
*/
public function getFcc(): ?float
{
return $this->fcc;
}
/**
* Get fcc or calculate for given maturity.
*
* @param float|null $te
*
* @return float
*/
public function getFccInPoint(float $te): float
{
if ($te <= 0) {
return 0.0;
}
if ($te <= $this->getTa()) {
return $this->getFa() * (($te / $this->getTa()) ** $this->getNa());
}
if ($te <= 672.0) {
return $this->getFcc() * exp($this->getS() * (1.0 - sqrt((672.0 - $this->getTs()) / ($te - $this->getTS()))));
}
return $this->getFcc();
}
/**
* Set fcc.
*
* @param float $fcc
*
* @return Recipe
*/
public function setFcc(float $fcc): self
{
$this->fcc = $fcc;
return $this;
}
/**
* Get DTe.
*
* @return float
*/
public function getDTe(): ?float
{
return $this->dTe ?? 0.0;
}
/**
* Set dte.
*
* @param float $dTe
*
* @return Recipe
*/
public function setDTe(float $dTe): self
{
$this->dTe = $dTe;
return $this;
}
/**
* Get beta add.
*
* @return float
*/
public function getBetaAdd(): ?float
{
return $this->betaAdd;
}
/**
* Set beta add.
*
* @param float $betaAdd
*
* @return Recipe
*/
public function setBetaAdd(float $betaAdd): self
{
$this->betaAdd = $betaAdd;
return $this;
}
/**
* Get theta.
*
* @return float
*/
public function getTheta(): ?float
{
return $this->theta;
}
/**
* Set theta.
*
* @param float $theta
*
* @return Recipe
*/
public function setTheta(float $theta): self
{
$this->theta = $theta;
return $this;
}
/**
* Get kappa.
*
* @return float
*/
public function getKappa(): ?float
{
return $this->kappa;
}
/**
* Set kappa.
*
* @param float $kappa
*
* @return Recipe
*/
public function setKappa(float $kappa): self
{
$this->kappa = $kappa;
return $this;
}
/**
* Get s.
*
* @return float
*/
public function getS(): ?float
{
return $this->s;
}
/**
* Set s.
*
* @param float $s
*
* @return Recipe
*/
public function setS(float $s): self
{
$this->s = $s;
return $this;
}
/**
* Get ts.
*
* @return float
*/
public function getTS(): ?float
{
return $this->tS;
}
/**
* Set ts.
*
* @param float $tS
*
* @return Recipe
*/
public function setTS(float $tS): self
{
$this->tS = $tS;
return $this;
}
/**
* Get na.
*
* @return float
*/
public function getNA(): ?float
{
return $this->nA;
}
/**
* Set na.
*
* @param float $nA
*
* @return Recipe
*/
public function setNA(float $nA): self
{
$this->nA = $nA;
return $this;
}
/**
* Get ta.
*
* @return float
*/
public function getTA(): ?float
{
return $this->tA;
}
/**
* Set ta.
*
* @param float $tA
*
* @return Recipe
*/
public function setTA(float $tA): self
{
$this->tA = $tA;
return $this;
}
/**
* Get fa.
*
* @return float
*/
public function getFa(): ?float
{
return $this->fa;
}
/**
* Set fa.
*
* @param float $fa
*
* @return Recipe
*/
public function setFa(float $fa): self
{
$this->fa = $fa;
return $this;
}
/**
* To string.
*
* @return string
*/
public function __toString()
{
return $this->name ?? '';
}
/**
* Get created from.
*
* @return Recipe|null
*/
public function getCreatedFrom(): ?self
{
return $this->createdFrom;
}
/**
* Set created from.
*
* @param Recipe $createdFrom
*
* @return Recipe
*/
public function setCreatedFrom(self $createdFrom): self
{
$this->createdFrom = $createdFrom;
return $this;
}
/**
* Get is complete.
*
* @return bool
*/
public function getIsComplete(): bool
{
return isset(
$this->dTe,
$this->fa,
$this->nA,
$this->tS,
$this->kappa,
$this->betaAdd,
$this->theta,
$this->fcc,
$this->s,
);
}
/**
* @return float
*/
public function getError(): float
{
return $this->error;
}
/**
* @param float $error
*
* @return Recipe
*/
public function setError(float $error): self
{
$this->error = $error;
return $this;
}
/**
* @return Collection|RecipeToSync[]
*/
public function getRecipeToSyncs(): Collection
{
return $this->recipeToSyncs;
}
public function addRecipeToSync(RecipeToSync $recipeToSync): self
{
if (!$this->recipeToSyncs->contains($recipeToSync)) {
$this->recipeToSyncs[] = $recipeToSync;
$recipeToSync->setRecipe($this);
}
return $this;
}
public function removeRecipeToSync(RecipeToSync $recipeToSync): self
{
if ($this->recipeToSyncs->contains($recipeToSync)) {
$this->recipeToSyncs->removeElement($recipeToSync);
// set the owning side to null (unless already changed)
if ($recipeToSync->getRecipe() === $this) {
$recipeToSync->setRecipe(null);
}
}
return $this;
}
/**
* @return string|null
*/
public function getCountry(): ?string
{
return $this->country;
}
/**
* @param string|null $country
*
* @return $this
*/
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
/**
* @return string|null
*/
public function getBrand(): ?string
{
return $this->brand;
}
/**
* @param string|null $brand
*
* @return Recipe
*/
public function setBrand(?string $brand): self
{
$this->brand = $brand ? : null;
return $this;
}
/**
* @return string[]
*/
public function getBrands(): array
{
$brands = explode(',', $this->brand ?? '');
return array_map(static function (string $brand) {
return trim($brand);
}, $brands);
}
}