src/Entity/PriceDecision/Distributor.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\PriceDecision;
  3. use App\Entity\Admin\AdminEntityInterface;
  4. use App\Entity\Extension\TimestampableTrait;
  5. use App\Utils\Utils;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use App\Repository\Client\ElectricityDistributorRepository;
  10. /**
  11. * @ORM\Entity(repositoryClass=ElectricityDistributorRepository::class)
  12. * @ORM\Table(name="pd_distributor")
  13. */
  14. class Distributor implements AdminEntityInterface
  15. {
  16. use TimestampableTrait;
  17. /**
  18. * @var null|int
  19. *
  20. * @ORM\Id()
  21. * @ORM\GeneratedValue()
  22. * @ORM\Column(type="integer")
  23. */
  24. protected ?int $id = null;
  25. /**
  26. * @var string
  27. *
  28. * @ORM\Column(type="string")
  29. */
  30. protected string $name;
  31. /**
  32. * @var string
  33. *
  34. * @ORM\Column(type="string", name="machine_name", unique=true)
  35. */
  36. protected string $machineName;
  37. /**
  38. * @var Collection|CircuitBreakerPrice[]
  39. *
  40. * @ORM\OneToMany(targetEntity=CircuitBreakerPrice::class, mappedBy="distributor", cascade={"all"})
  41. */
  42. protected $circuitBreakerPrices;
  43. /**
  44. * @var TariffPrice[]|Collection
  45. *
  46. * @ORM\OneToMany(targetEntity=TariffPrice::class, mappedBy="distributor", cascade={"all"})
  47. */
  48. protected $tariffs;
  49. public function __construct()
  50. {
  51. $this->circuitBreakerPrices = new ArrayCollection();
  52. $this->tariffs = new ArrayCollection();
  53. }
  54. /**
  55. * @return int|null
  56. */
  57. public function getId(): ?int
  58. {
  59. return $this->id;
  60. }
  61. /**
  62. * @return string
  63. */
  64. public function getName(): string
  65. {
  66. return $this->name;
  67. }
  68. /**
  69. * @param string $name
  70. * @return self
  71. */
  72. public function setName(string $name): self
  73. {
  74. $this->name = $name;
  75. return $this;
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getMachineName(): string
  81. {
  82. return $this->machineName;
  83. }
  84. /**
  85. * @param string $machineName
  86. * @return $this
  87. */
  88. public function setMachineName(string $machineName): self
  89. {
  90. $this->machineName = $machineName;
  91. return $this;
  92. }
  93. /**
  94. * @return CircuitBreakerPrice[]|Collection
  95. */
  96. public function getCircuitBreakerPrices(): Collection
  97. {
  98. return $this->circuitBreakerPrices;
  99. }
  100. /**
  101. * @param CircuitBreakerPrice[]|Collection $circuitBreakerPrices
  102. * @return self
  103. */
  104. public function setCircuitBreakerPrices($circuitBreakerPrices): self
  105. {
  106. $this->circuitBreakerPrices = $circuitBreakerPrices;
  107. return $this;
  108. }
  109. /**
  110. * @return TariffPrice[]|Collection
  111. */
  112. public function getTariffs(): Collection
  113. {
  114. return $this->tariffs;
  115. }
  116. /**
  117. * @param TariffPrice[]|Collection $tariffs
  118. * @return self
  119. */
  120. public function setTariffs($tariffs): self
  121. {
  122. $this->tariffs = $tariffs;
  123. return $this;
  124. }
  125. public function __toString()
  126. {
  127. return $this->getName() || $this->getMachineName() ? sprintf(
  128. '%s (%s)',
  129. $this->getName() ?? '-',
  130. $this->getMachineName() ?? '-'
  131. ) : '';
  132. }
  133. public static function generateCodeFromName($name): string
  134. {
  135. $name = Utils::removeDiacritics($name);
  136. return preg_replace('/[^A-Za-z0-9\\.\\-]+/', '', $name);
  137. }
  138. public function toArray(): array
  139. {
  140. return [
  141. 'id' => $this->getId(),
  142. 'name' => $this->getName(),
  143. 'machineName' => $this->getMachineName(),
  144. ];
  145. }
  146. public function getEntityDetailName(): string
  147. {
  148. return $this->getName();
  149. }
  150. public function getDetailHeading(): string
  151. {
  152. return 'Detail distributora - ';
  153. }
  154. public static function getListFieldsDefinition(): array
  155. {
  156. return [
  157. 'id' => [
  158. 'label' => 'ID',
  159. 'sortable' => true,
  160. 'searchable' => true,
  161. ],
  162. 'machineName' => [
  163. 'label' => 'Strojový název',
  164. 'sortable' => true,
  165. 'searchable' => true,
  166. ],
  167. 'name' => [
  168. 'label' => 'Název distributora',
  169. 'sortable' => true,
  170. 'searchable' => true,
  171. ],
  172. ];
  173. }
  174. public static function getDetailFieldsDefinition(): array
  175. {
  176. return [
  177. 'id' => [
  178. 'label' => 'ID',
  179. 'type' => 'text',
  180. ],
  181. 'machineName' => [
  182. 'label' => 'Strojový název',
  183. 'type' => 'text',
  184. ],
  185. 'name' => [
  186. 'label' => 'Název distributora',
  187. 'type' => 'text',
  188. ],
  189. ];
  190. }
  191. public static function getFormFieldsDefinition(): array
  192. {
  193. return [
  194. 'machineName' => [
  195. 'label' => 'Strojový název',
  196. '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.',
  197. 'type' => 'text',
  198. 'rules' => [
  199. 'required' => true,
  200. ],
  201. ],
  202. 'name' => [
  203. 'label' => 'Název distributora',
  204. '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í)',
  205. 'type' => 'text',
  206. 'rules' => [
  207. 'required' => true,
  208. ],
  209. ],
  210. ];
  211. }
  212. }