src/Domain/Zones/Model/Establishment.php line 21

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Zones\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Ramsey\Uuid\Uuid;
  8. use Whater\Domain\Common\Exception\InvalidUUIDException;
  9. use Whater\Domain\Zones\Model\Town;
  10. use Whater\Domain\Zones\Model\Ubication;
  11. use Whater\Domain\Whater\Model\DistributionNetwork;
  12. use Whater\Domain\Zones\Exception\InvalidLocationInTownException;
  13. /**
  14. * Class Establishment
  15. *
  16. * @package Whater\Domain\Zones\Model
  17. */
  18. class Establishment implements ContainsRecordedEvents
  19. {
  20. use EventRecorderCapabilities;
  21. const ET_COMMERCIAL_ESTABLISHMENT = 'ET_COMMERCIAL_ESTABLISHMENT';// ESTABLECIMIENTO COMERCIAL
  22. const ET_BAR_RESTAURANT_CAFETERIA = 'ET_BAR_RESTAURANT_CAFETERIA';// BAR, RESTAURANTE CAFETERÍA
  23. const ET_RESTAURANT_CHAIN = 'ET_RESTAURANT_CHAIN';// CADENA DE RESTAURACIÓN
  24. const ET_PRIORITIZED_BUILDING = 'ET_PRIORITIZED_BUILDING';// EDIFICIO PRIORITARIO SEGÚN EL RD 3/2023
  25. const ET_INDIVIDUAL_ACCOMMODATION = 'ET_INDIVIDUAL_ACCOMMODATION';// ALOJAMIENTO INDIVIDUAL
  26. const ET_CENTERS = 'ET_CENTERS';// CENTROS (COMERCIALES, DEPORTIVOS, DE NEGOCIOS)
  27. const ET_HOTEL_CHAIN = 'ET_HOTEL_CHAIN';// CADENA HOTELERA, APARTAMENTOS, CAMPINGS
  28. const ET_TOURISM_OFFICES = 'ET_TOURISM_OFFICES';// OFICINAS DE TURISMO, GESTOR DE DESTINOS
  29. const ET_OTHERS = 'ET_OTHERS';//Otros, inicializamos los ya creados a otros
  30. /**
  31. * @var string
  32. */
  33. private $uuid;
  34. /**
  35. * @var string
  36. */
  37. private $slug;
  38. /**
  39. * @var string
  40. */
  41. private $name;
  42. /**
  43. * @var Town
  44. */
  45. private $town;
  46. /**
  47. * @var TownLocation
  48. */
  49. private $townLocation;
  50. /**
  51. * @var Ubication
  52. */
  53. private $ubication;
  54. /**
  55. * @var Collection
  56. */
  57. private $whaterPoints;
  58. /**
  59. * @var float
  60. */
  61. private $latitude;
  62. /**
  63. * @var float
  64. */
  65. private $longitude;
  66. /**
  67. * @var string
  68. */
  69. private $tipology;
  70. /**
  71. * @var Collection
  72. */
  73. private $whaterDevices;
  74. /**
  75. * @var Collection
  76. */
  77. private $organizationLicenses;
  78. /**
  79. * @var DistributionNetwork
  80. */
  81. private $distributionNetwork;
  82. /**
  83. * @var \DateTime
  84. */
  85. private $createdAt;
  86. /**
  87. * @var \DateTime
  88. */
  89. private $updatedAt;
  90. public function __construct(
  91. string $establishmentId = null,
  92. Town $town,
  93. Ubication $ubication = null,
  94. string $name,
  95. string $tipology,
  96. string $slug = null,
  97. DistributionNetwork $distributionNetwork = null,
  98. string $latitude = null,
  99. string $longitude = null,
  100. TownLocation $townLocation = null,
  101. ) {
  102. try {
  103. $this->uuid = Uuid::fromString($establishmentId ?: Uuid::uuid4())->toString();
  104. } catch (\InvalidArgumentException $e) {
  105. throw new InvalidUUIDException();
  106. }
  107. $this->slug = $slug;
  108. $this->name = $name;
  109. $this->tipology = $tipology;
  110. $this->town = $town;
  111. $this->townLocation = $townLocation;
  112. $this->latitude = $latitude;
  113. $this->longitude = $longitude;
  114. if ($this->latitude == null || $this->longitude == null) {
  115. $this->latitude = $town->latitude();
  116. $this->longitude = $town->longitude();
  117. }
  118. $this->whaterPoints = new ArrayCollection();
  119. $this->createdAt = new \DateTime();
  120. $this->updatedAt = new \DateTime();
  121. $this->ubication = $ubication;
  122. if ($ubication != null && !$ubication->town()->equals($town)) {
  123. throw new InvalidLocationInTownException();
  124. }
  125. $this->whaterDevices = new ArrayCollection();
  126. $this->organizationLicenses = new ArrayCollection();
  127. $this->distributionNetwork = $distributionNetwork;
  128. }
  129. public function updateEstablishmentData(
  130. string $name,
  131. string $tipology,
  132. string $slug = null,
  133. Ubication $ubication = null,
  134. DistributionNetwork $distributionNetwork = null,
  135. float $latitude = null,
  136. float $longitude = null,
  137. TownLocation $townLocation = null
  138. ) {
  139. $this->name = $name;
  140. $this->tipology = $tipology;
  141. $this->slug = $slug;
  142. if ($this->ubication != null) {
  143. if ($ubication != null && !$ubication->town()->equals($this->town)) {
  144. throw new InvalidLocationInTownException();
  145. }
  146. $this->ubication = $ubication;
  147. }
  148. if ($latitude != null && $longitude != null) {
  149. $this->latitude = $latitude;
  150. $this->longitude = $longitude;
  151. }
  152. if ($townLocation != null) {
  153. $this->townLocation = $townLocation;
  154. }
  155. $this->updatedAt = new \DateTime();
  156. $this->distributionNetwork = $distributionNetwork;
  157. }
  158. /**
  159. * @return string
  160. */
  161. public function id(): string
  162. {
  163. return $this->uuid;
  164. }
  165. /**
  166. * @return string
  167. */
  168. public function name(): string
  169. {
  170. return $this->name;
  171. }
  172. /**
  173. * @return string
  174. */
  175. public function slug(): ?string
  176. {
  177. return $this->slug;
  178. }
  179. /**
  180. * @return Ubication
  181. */
  182. public function ubication(): ?Ubication
  183. {
  184. return $this->ubication;
  185. }
  186. /**
  187. * @return Town
  188. */
  189. public function town(): Town
  190. {
  191. return $this->town;
  192. }
  193. /**
  194. * @return TownLocation|null
  195. */
  196. public function townLocation(): ?TownLocation
  197. {
  198. return $this->townLocation;
  199. }
  200. /**
  201. * @return float|null
  202. */
  203. public function latitude(): ?float
  204. {
  205. return $this->latitude;
  206. }
  207. /**
  208. * @return float|null
  209. */
  210. public function longitude(): ?float
  211. {
  212. return $this->longitude;
  213. }
  214. /**
  215. * @return string
  216. */
  217. public function tipology(): string
  218. {
  219. return $this->tipology;
  220. }
  221. /**
  222. * @return Collection
  223. */
  224. public function whaterPoints(): Collection
  225. {
  226. return $this->whaterPoints;
  227. }
  228. /**
  229. * @return Collection
  230. */
  231. public function whaterDevices(): Collection
  232. {
  233. return $this->whaterDevices;
  234. }
  235. /**
  236. * @return Collection
  237. */
  238. public function organizationLicenses(): Collection
  239. {
  240. return $this->organizationLicenses;
  241. }
  242. /**
  243. * @return \DateTime
  244. */
  245. public function createdAt(): \DateTime
  246. {
  247. return $this->createdAt;
  248. }
  249. /**
  250. * @return \DateTime
  251. */
  252. public function updatedAt(): \DateTime
  253. {
  254. return $this->updatedAt;
  255. }
  256. /**
  257. * @return ?DistributionNetwork
  258. */
  259. public function distributionNetwork(): ?DistributionNetwork
  260. {
  261. return $this->distributionNetwork;
  262. }
  263. /**
  264. * @return bool
  265. */
  266. public function equals(Establishment $establishment)
  267. {
  268. return $this->id() === $establishment->id();
  269. }
  270. }