src/Entity/MeasurementSetting.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * @license SILK SOFTWARE HOUSE SP Z O O
  4.  */
  5. namespace App\Entity;
  6. use App\Entity\Traits\IdTrait;
  7. use App\Entity\Traits\TimePreUpdateTrait;
  8. use App\Entity\Traits\TimeTrait;
  9. use App\Model\DefaultStrengthPoints;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * Class MeasurementSetting.
  14.  *
  15.  * @ORM\Table("measurement_settings")
  16.  * @ORM\Entity(repositoryClass="App\Repository\MeasurementSettingRepository")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. class MeasurementSetting
  20. {
  21.     use IdTrait;
  22.     use TimeTrait;
  23.     use TimePreUpdateTrait;
  24.     /**
  25.      * Measurement.
  26.      *
  27.      * @var Measurement|null
  28.      *
  29.      * @ORM\ManyToOne(targetEntity="App\Entity\Measurement", inversedBy="settings")
  30.      * @ORM\JoinColumn(name="measurement_id", nullable=true)
  31.      */
  32.     private $measurement;
  33.     /**
  34.      * @var ArrayCollection|ChannelSetting[]
  35.      *
  36.      * @ORM\OneToMany(targetEntity="App\Entity\ChannelSetting", cascade={"persist", "remove"}, mappedBy="measurementSetting")
  37.      * @ORM\OrderBy({"priority": "ASC", "number": "ASC"})
  38.      */
  39.     private $channelSettings;
  40.     /**
  41.      * Standard recipe.
  42.      *
  43.      * @var Recipe|null
  44.      *
  45.      * @ORM\ManyToOne(targetEntity="App\Entity\Recipe")
  46.      * @ORM\JoinColumn(name="standard_recipe_id", nullable=true)
  47.      */
  48.     private $standardRecipe;
  49.     /**
  50.      * Note.
  51.      *
  52.      * @var string|null
  53.      *
  54.      * @ORM\Column(name="note", type="text", nullable=true, options={"comment": "Measurement notes."})
  55.      */
  56.     private $note;
  57.     /**
  58.      * Line type group.
  59.      *
  60.      * @var LineTypeGroup|null
  61.      *
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\LineTypeGroup", inversedBy="settings")
  63.      * @ORM\JoinColumn(name="line_type_group_id", nullable=true)
  64.      */
  65.     private $lineTypeGroup;
  66.     /**
  67.      * Strength points.
  68.      *
  69.      * @var array
  70.      *
  71.      * @ORM\Column(name="strength_points", type="json", nullable=false, options={"comment": "Strength points.", "default": "{}"})
  72.      */
  73.     private $strengthPoints = [];
  74.     /**
  75.      * Is strength points per channel.
  76.      *
  77.      * @var bool
  78.      *
  79.      * @ORM\Column(name="is_strength_points_per_channel", type="boolean", nullable=false, options={"comment": "Are strength points calculated per channel.", "default": false})
  80.      */
  81.     private $isStrengthPointsPerChannel false;
  82.     /**
  83.      * @var bool
  84.      *
  85.      * @ORM\Column(name="is_deleted", type="boolean", nullable=false, options={"comment": "Is measurement deleted"})
  86.      */
  87.     private $isDeleted false;
  88.     /**
  89.      * @var bool
  90.      *
  91.      * @ORM\Column(name="is_temperature_split_view", type="boolean", nullable=false, options={"comment": "Is temperature chart split into two diagrams", "default": false})
  92.      */
  93.     private $isTemperatureSplitView false;
  94.     /**
  95.      * @var bool
  96.      *
  97.      * @ORM\Column(name="is_automatic_strength_points_enabled", type="boolean", nullable=false, options={"comment": "Show automatic recipe strength points on temperature chart.", "default": false})
  98.      */
  99.     private $isAutomaticStrengthPointsEnabled false;
  100.     /**
  101.      * MeasurementSetting constructor.
  102.      */
  103.     public function __construct()
  104.     {
  105.         $this->channelSettings = new ArrayCollection();
  106.         $this->strengthPoints DefaultStrengthPoints::get();
  107.     }
  108.     /**
  109.      * Get channel settings.
  110.      *
  111.      * @return ChannelSetting[]|ArrayCollection
  112.      */
  113.     public function getChannelSettings()
  114.     {
  115.         return $this->channelSettings;
  116.     }
  117.     /**
  118.      * Remove channel setting.
  119.      *
  120.      * @param ChannelSetting $channelSetting
  121.      *
  122.      * @return MeasurementSetting
  123.      */
  124.     public function removeChannelSetting(ChannelSetting $channelSetting): MeasurementSetting
  125.     {
  126.         if ($this->channelSettings->contains($channelSetting)) {
  127.             $this->channelSettings->removeElement($channelSetting);
  128.         }
  129.         return $this;
  130.     }
  131.     /**
  132.      * Add channel setting.
  133.      *
  134.      * @param ChannelSetting $channelSetting
  135.      *
  136.      * @return MeasurementSetting
  137.      */
  138.     public function addChannelSetting(ChannelSetting $channelSetting): MeasurementSetting
  139.     {
  140.         if (!$this->channelSettings->contains($channelSetting)) {
  141.             $this->channelSettings->add($channelSetting);
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * Get standard recipe.
  147.      *
  148.      * @return Recipe|null
  149.      */
  150.     public function getStandardRecipe(): ?Recipe
  151.     {
  152.         return $this->standardRecipe;
  153.     }
  154.     /**
  155.      * Set standard recipe.
  156.      *
  157.      * @param Recipe|null $standardRecipe
  158.      *
  159.      * @return MeasurementSetting
  160.      */
  161.     public function setStandardRecipe(?Recipe $standardRecipe): MeasurementSetting
  162.     {
  163.         $this->standardRecipe $standardRecipe;
  164.         return $this;
  165.     }
  166.     /**
  167.      * Get measurement.
  168.      *
  169.      * @return Measurement|null
  170.      */
  171.     public function getMeasurement(): ?Measurement
  172.     {
  173.         return $this->measurement;
  174.     }
  175.     /**
  176.      * Set measurement.
  177.      *
  178.      * @param Measurement|null $measurement
  179.      *
  180.      * @return MeasurementSetting
  181.      */
  182.     public function setMeasurement(?Measurement $measurement): MeasurementSetting
  183.     {
  184.         $this->measurement $measurement;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get note.
  189.      *
  190.      * @return string|null
  191.      */
  192.     public function getNote(): ?string
  193.     {
  194.         return $this->note;
  195.     }
  196.     /**
  197.      * Set note.
  198.      *
  199.      * @param string|null $note
  200.      *
  201.      * @return MeasurementSetting
  202.      */
  203.     public function setNote(?string $note): MeasurementSetting
  204.     {
  205.         $this->note $note;
  206.         return $this;
  207.     }
  208.     /**
  209.      * Get channel setting max number.
  210.      *
  211.      * @return int|null
  212.      */
  213.     public function getChannelSettingMaxNumber(): ?int
  214.     {
  215.         $numbers = [];
  216.         foreach ($this->channelSettings as $setting) {
  217.             if (null !== $setting->getNumber()) {
  218.                 $numbers[] = $setting->getNumber();
  219.             }
  220.         }
  221.         return count($numbers) ? max($numbers) : null;
  222.     }
  223.     /**
  224.      * Get line type group.
  225.      *
  226.      * @return LineTypeGroup|null
  227.      */
  228.     public function getLineTypeGroup(): ?LineTypeGroup
  229.     {
  230.         return $this->lineTypeGroup;
  231.     }
  232.     /**
  233.      * Set line type group.
  234.      *
  235.      * @param LineTypeGroup|null $lineTypeGroup
  236.      *
  237.      * @return MeasurementSetting
  238.      */
  239.     public function setLineTypeGroup(?LineTypeGroup $lineTypeGroup): MeasurementSetting
  240.     {
  241.         $this->lineTypeGroup $lineTypeGroup;
  242.         return $this;
  243.     }
  244.     /**
  245.      * Get strength points.
  246.      *
  247.      * @return array
  248.      */
  249.     public function getStrengthPoints(): array
  250.     {
  251.         return $this->strengthPoints;
  252.     }
  253.     /**
  254.      * Set strength points.
  255.      *
  256.      * @param array $strengthPoints
  257.      *
  258.      * @return MeasurementSetting
  259.      */
  260.     public function setStrengthPoints(array $strengthPoints): MeasurementSetting
  261.     {
  262.         $this->strengthPoints $strengthPoints;
  263.         return $this;
  264.     }
  265.     /**
  266.      * Get strength points per channel.
  267.      *
  268.      * @return bool
  269.      */
  270.     public function getIsStrengthPointsPerChannel(): bool
  271.     {
  272.         return $this->isStrengthPointsPerChannel;
  273.     }
  274.     /**
  275.      * Set strength points per channel.
  276.      *
  277.      * @param bool $isStrengthPointsPerChannel
  278.      *
  279.      * @return MeasurementSetting
  280.      */
  281.     public function setIsStrengthPointsPerChannel(bool $isStrengthPointsPerChannel): MeasurementSetting
  282.     {
  283.         $this->isStrengthPointsPerChannel $isStrengthPointsPerChannel;
  284.         return $this;
  285.     }
  286.     /**
  287.      * Get active channel strength points.
  288.      *
  289.      * @return array
  290.      */
  291.     public function getActiveChannelStrengthPoints(): array
  292.     {
  293.         $result = [];
  294.         foreach ($this->channelSettings as $setting) {
  295.             $result[] = $this->isStrengthPointsPerChannel ?
  296.                 $setting->getActiveStrengthPoints() : $this->getActiveStrengthPoints();
  297.         }
  298.         return $result;
  299.     }
  300.     /**
  301.      * Get active strength points.
  302.      *
  303.      * @return array
  304.      */
  305.     public function getActiveStrengthPoints()
  306.     {
  307.         return array_keys(array_filter($this->strengthPoints, function ($element) {
  308.             return true === $element;
  309.         }));
  310.     }
  311.     /**
  312.      * @return bool
  313.      */
  314.     public function isDeleted(): bool
  315.     {
  316.         return $this->isDeleted;
  317.     }
  318.     /**
  319.      * @param bool $isDeleted
  320.      *
  321.      * @return self
  322.      */
  323.     public function setIsDeleted(bool $isDeleted): MeasurementSetting
  324.     {
  325.         $this->isDeleted $isDeleted;
  326.         return $this;
  327.     }
  328.     public function getIsTemperatureSplitView(): bool
  329.     {
  330.         return $this->isTemperatureSplitView;
  331.     }
  332.     public function setIsTemperatureSplitView(bool $isTemperatureSplitView): MeasurementSetting
  333.     {
  334.         $this->isTemperatureSplitView $isTemperatureSplitView;
  335.         return $this;
  336.     }
  337.     public function getIsAutomaticStrengthPointsEnabled(): bool
  338.     {
  339.         return $this->isAutomaticStrengthPointsEnabled;
  340.     }
  341.     public function setIsAutomaticStrengthPointsEnabled(bool $isAutomaticStrengthPointsEnabled): MeasurementSetting
  342.     {
  343.         $this->isAutomaticStrengthPointsEnabled $isAutomaticStrengthPointsEnabled;
  344.         return $this;
  345.     }
  346. }