<?php
namespace App\Entity\PriceDecision;
use App\Entity\Admin\AdminEntityInterface;
use App\Entity\Extension\TimestampableTrait;
use App\Utils\Utils;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\Client\ElectricityDistributorRepository;
/**
* @ORM\Entity(repositoryClass=ElectricityDistributorRepository::class)
* @ORM\Table(name="pd_distributor")
*/
class Distributor implements AdminEntityInterface
{
use TimestampableTrait;
/**
* @var null|int
*
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected ?int $id = null;
/**
* @var string
*
* @ORM\Column(type="string")
*/
protected string $name;
/**
* @var string
*
* @ORM\Column(type="string", name="machine_name", unique=true)
*/
protected string $machineName;
/**
* @var Collection|CircuitBreakerPrice[]
*
* @ORM\OneToMany(targetEntity=CircuitBreakerPrice::class, mappedBy="distributor", cascade={"all"})
*/
protected $circuitBreakerPrices;
/**
* @var TariffPrice[]|Collection
*
* @ORM\OneToMany(targetEntity=TariffPrice::class, mappedBy="distributor", cascade={"all"})
*/
protected $tariffs;
public function __construct()
{
$this->circuitBreakerPrices = new ArrayCollection();
$this->tariffs = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return self
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getMachineName(): string
{
return $this->machineName;
}
/**
* @param string $machineName
* @return $this
*/
public function setMachineName(string $machineName): self
{
$this->machineName = $machineName;
return $this;
}
/**
* @return CircuitBreakerPrice[]|Collection
*/
public function getCircuitBreakerPrices(): Collection
{
return $this->circuitBreakerPrices;
}
/**
* @param CircuitBreakerPrice[]|Collection $circuitBreakerPrices
* @return self
*/
public function setCircuitBreakerPrices($circuitBreakerPrices): self
{
$this->circuitBreakerPrices = $circuitBreakerPrices;
return $this;
}
/**
* @return TariffPrice[]|Collection
*/
public function getTariffs(): Collection
{
return $this->tariffs;
}
/**
* @param TariffPrice[]|Collection $tariffs
* @return self
*/
public function setTariffs($tariffs): self
{
$this->tariffs = $tariffs;
return $this;
}
public function __toString()
{
return $this->getName() || $this->getMachineName() ? sprintf(
'%s (%s)',
$this->getName() ?? '-',
$this->getMachineName() ?? '-'
) : '';
}
public static function generateCodeFromName($name): string
{
$name = Utils::removeDiacritics($name);
return preg_replace('/[^A-Za-z0-9\\.\\-]+/', '', $name);
}
public function toArray(): array
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'machineName' => $this->getMachineName(),
];
}
public function getEntityDetailName(): string
{
return $this->getName();
}
public function getDetailHeading(): string
{
return 'Detail distributora - ';
}
public static function getListFieldsDefinition(): array
{
return [
'id' => [
'label' => 'ID',
'sortable' => true,
'searchable' => true,
],
'machineName' => [
'label' => 'Strojový název',
'sortable' => true,
'searchable' => true,
],
'name' => [
'label' => 'Název distributora',
'sortable' => true,
'searchable' => true,
],
];
}
public static function getDetailFieldsDefinition(): array
{
return [
'id' => [
'label' => 'ID',
'type' => 'text',
],
'machineName' => [
'label' => 'Strojový název',
'type' => 'text',
],
'name' => [
'label' => 'Název distributora',
'type' => 'text',
],
];
}
public static function getFormFieldsDefinition(): array
{
return [
'machineName' => [
'label' => 'Strojový název',
'help' => 'Tento název se využívá při importu nového cenového rozhodnutí jako identifikátor distributora. V případě změny názvu existujícího distributora lze změnit i strojový název.',
'type' => 'text',
'rules' => [
'required' => true,
],
],
'name' => [
'label' => 'Název distributora',
'help' => 'Tento název je využíván v celé aplikaci a změna se projeví všude kde je distributor využit (detail měřidla, detail klienta, přehledy - optimalizace sazeb, detail nahraného cen. rozhodnutí)',
'type' => 'text',
'rules' => [
'required' => true,
],
],
];
}
}