<?php
/**
* @license SILK SOFTWARE HOUSE SP Z O O
*/
namespace App\Entity;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\TimePreUpdateTrait;
use App\Entity\Traits\TimeTrait;
use App\Model\DefaultStrengthPoints;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Class MeasurementSetting.
*
* @ORM\Table("measurement_settings")
* @ORM\Entity(repositoryClass="App\Repository\MeasurementSettingRepository")
* @ORM\HasLifecycleCallbacks()
*/
class MeasurementSetting
{
use IdTrait;
use TimeTrait;
use TimePreUpdateTrait;
/**
* Measurement.
*
* @var Measurement|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Measurement", inversedBy="settings")
* @ORM\JoinColumn(name="measurement_id", nullable=true)
*/
private $measurement;
/**
* @var ArrayCollection|ChannelSetting[]
*
* @ORM\OneToMany(targetEntity="App\Entity\ChannelSetting", cascade={"persist", "remove"}, mappedBy="measurementSetting")
* @ORM\OrderBy({"priority": "ASC", "number": "ASC"})
*/
private $channelSettings;
/**
* Standard recipe.
*
* @var Recipe|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Recipe")
* @ORM\JoinColumn(name="standard_recipe_id", nullable=true)
*/
private $standardRecipe;
/**
* Note.
*
* @var string|null
*
* @ORM\Column(name="note", type="text", nullable=true, options={"comment": "Measurement notes."})
*/
private $note;
/**
* Line type group.
*
* @var LineTypeGroup|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\LineTypeGroup", inversedBy="settings")
* @ORM\JoinColumn(name="line_type_group_id", nullable=true)
*/
private $lineTypeGroup;
/**
* Strength points.
*
* @var array
*
* @ORM\Column(name="strength_points", type="json", nullable=false, options={"comment": "Strength points.", "default": "{}"})
*/
private $strengthPoints = [];
/**
* Is strength points per channel.
*
* @var bool
*
* @ORM\Column(name="is_strength_points_per_channel", type="boolean", nullable=false, options={"comment": "Are strength points calculated per channel.", "default": false})
*/
private $isStrengthPointsPerChannel = false;
/**
* @var bool
*
* @ORM\Column(name="is_deleted", type="boolean", nullable=false, options={"comment": "Is measurement deleted"})
*/
private $isDeleted = false;
/**
* @var bool
*
* @ORM\Column(name="is_temperature_split_view", type="boolean", nullable=false, options={"comment": "Is temperature chart split into two diagrams", "default": false})
*/
private $isTemperatureSplitView = false;
/**
* @var bool
*
* @ORM\Column(name="is_automatic_strength_points_enabled", type="boolean", nullable=false, options={"comment": "Show automatic recipe strength points on temperature chart.", "default": false})
*/
private $isAutomaticStrengthPointsEnabled = false;
/**
* MeasurementSetting constructor.
*/
public function __construct()
{
$this->channelSettings = new ArrayCollection();
$this->strengthPoints = DefaultStrengthPoints::get();
}
/**
* Get channel settings.
*
* @return ChannelSetting[]|ArrayCollection
*/
public function getChannelSettings()
{
return $this->channelSettings;
}
/**
* Remove channel setting.
*
* @param ChannelSetting $channelSetting
*
* @return MeasurementSetting
*/
public function removeChannelSetting(ChannelSetting $channelSetting): MeasurementSetting
{
if ($this->channelSettings->contains($channelSetting)) {
$this->channelSettings->removeElement($channelSetting);
}
return $this;
}
/**
* Add channel setting.
*
* @param ChannelSetting $channelSetting
*
* @return MeasurementSetting
*/
public function addChannelSetting(ChannelSetting $channelSetting): MeasurementSetting
{
if (!$this->channelSettings->contains($channelSetting)) {
$this->channelSettings->add($channelSetting);
}
return $this;
}
/**
* Get standard recipe.
*
* @return Recipe|null
*/
public function getStandardRecipe(): ?Recipe
{
return $this->standardRecipe;
}
/**
* Set standard recipe.
*
* @param Recipe|null $standardRecipe
*
* @return MeasurementSetting
*/
public function setStandardRecipe(?Recipe $standardRecipe): MeasurementSetting
{
$this->standardRecipe = $standardRecipe;
return $this;
}
/**
* Get measurement.
*
* @return Measurement|null
*/
public function getMeasurement(): ?Measurement
{
return $this->measurement;
}
/**
* Set measurement.
*
* @param Measurement|null $measurement
*
* @return MeasurementSetting
*/
public function setMeasurement(?Measurement $measurement): MeasurementSetting
{
$this->measurement = $measurement;
return $this;
}
/**
* Get note.
*
* @return string|null
*/
public function getNote(): ?string
{
return $this->note;
}
/**
* Set note.
*
* @param string|null $note
*
* @return MeasurementSetting
*/
public function setNote(?string $note): MeasurementSetting
{
$this->note = $note;
return $this;
}
/**
* Get channel setting max number.
*
* @return int|null
*/
public function getChannelSettingMaxNumber(): ?int
{
$numbers = [];
foreach ($this->channelSettings as $setting) {
if (null !== $setting->getNumber()) {
$numbers[] = $setting->getNumber();
}
}
return count($numbers) ? max($numbers) : null;
}
/**
* Get line type group.
*
* @return LineTypeGroup|null
*/
public function getLineTypeGroup(): ?LineTypeGroup
{
return $this->lineTypeGroup;
}
/**
* Set line type group.
*
* @param LineTypeGroup|null $lineTypeGroup
*
* @return MeasurementSetting
*/
public function setLineTypeGroup(?LineTypeGroup $lineTypeGroup): MeasurementSetting
{
$this->lineTypeGroup = $lineTypeGroup;
return $this;
}
/**
* Get strength points.
*
* @return array
*/
public function getStrengthPoints(): array
{
return $this->strengthPoints;
}
/**
* Set strength points.
*
* @param array $strengthPoints
*
* @return MeasurementSetting
*/
public function setStrengthPoints(array $strengthPoints): MeasurementSetting
{
$this->strengthPoints = $strengthPoints;
return $this;
}
/**
* Get strength points per channel.
*
* @return bool
*/
public function getIsStrengthPointsPerChannel(): bool
{
return $this->isStrengthPointsPerChannel;
}
/**
* Set strength points per channel.
*
* @param bool $isStrengthPointsPerChannel
*
* @return MeasurementSetting
*/
public function setIsStrengthPointsPerChannel(bool $isStrengthPointsPerChannel): MeasurementSetting
{
$this->isStrengthPointsPerChannel = $isStrengthPointsPerChannel;
return $this;
}
/**
* Get active channel strength points.
*
* @return array
*/
public function getActiveChannelStrengthPoints(): array
{
$result = [];
foreach ($this->channelSettings as $setting) {
$result[] = $this->isStrengthPointsPerChannel ?
$setting->getActiveStrengthPoints() : $this->getActiveStrengthPoints();
}
return $result;
}
/**
* Get active strength points.
*
* @return array
*/
public function getActiveStrengthPoints()
{
return array_keys(array_filter($this->strengthPoints, function ($element) {
return true === $element;
}));
}
/**
* @return bool
*/
public function isDeleted(): bool
{
return $this->isDeleted;
}
/**
* @param bool $isDeleted
*
* @return self
*/
public function setIsDeleted(bool $isDeleted): MeasurementSetting
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getIsTemperatureSplitView(): bool
{
return $this->isTemperatureSplitView;
}
public function setIsTemperatureSplitView(bool $isTemperatureSplitView): MeasurementSetting
{
$this->isTemperatureSplitView = $isTemperatureSplitView;
return $this;
}
public function getIsAutomaticStrengthPointsEnabled(): bool
{
return $this->isAutomaticStrengthPointsEnabled;
}
public function setIsAutomaticStrengthPointsEnabled(bool $isAutomaticStrengthPointsEnabled): MeasurementSetting
{
$this->isAutomaticStrengthPointsEnabled = $isAutomaticStrengthPointsEnabled;
return $this;
}
}