src/Domain/Zones/Model/Ubication.php line 20

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\Whater\Model\DistributionNetwork;
  11. use Whater\Domain\Whater\Model\WhaterOrganization;
  12. /**
  13. * Class Ubication
  14. *
  15. * @package Whater\Domain\Zones\Model
  16. */
  17. class Ubication implements ContainsRecordedEvents
  18. {
  19. use EventRecorderCapabilities;
  20. /**
  21. * @var string
  22. */
  23. private $uuid;
  24. /**
  25. * @var string
  26. */
  27. private $slug;
  28. /**
  29. * @var string
  30. */
  31. private $name;
  32. /**
  33. * @var string
  34. */
  35. private $postalCode;
  36. /**
  37. * @var string
  38. */
  39. private $email;
  40. /**
  41. * @var float
  42. */
  43. private $latitude;
  44. /**
  45. * @var float
  46. */
  47. private $longitude;
  48. /**
  49. * @var int
  50. */
  51. private $population;
  52. /**
  53. * @var Town
  54. */
  55. private $town;
  56. /**
  57. * @var TownLocation
  58. */
  59. private $townLocation;
  60. /**
  61. * @var DistributionNetwork
  62. */
  63. private $distributionNetwork;
  64. /**
  65. * @var WhaterOrganization
  66. */
  67. private $whaterOrganization;
  68. /**
  69. * @var Collection
  70. */
  71. private $valorations;
  72. /**
  73. * @var Collection
  74. */
  75. private $whaterPoints;
  76. /**
  77. * @var Collection
  78. */
  79. private $establishments;
  80. /**
  81. * @var Collection
  82. */
  83. private $images;
  84. /**
  85. * @var Collection
  86. */
  87. private $comments;
  88. /**
  89. * @var Collection
  90. */
  91. private $ownershipRequests;
  92. /**
  93. * @var \DateTime
  94. */
  95. private $createdAt;
  96. /**
  97. * @var \DateTime
  98. */
  99. private $updatedAt;
  100. /**
  101. * @var Collection
  102. */
  103. private $whaterDevices;
  104. public function __construct(
  105. string $locationId = null,
  106. Town $town,
  107. DistributionNetwork $distributionNetwork = null,
  108. string $name,
  109. string $slug = null,
  110. string $postalCode = null,
  111. string $latitude = null,
  112. string $longitude = null,
  113. TownLocation $townLocation = null
  114. ) {
  115. try {
  116. $this->uuid = Uuid::fromString($locationId ?: Uuid::uuid4())->toString();
  117. } catch (\InvalidArgumentException $e) {
  118. throw new InvalidUUIDException();
  119. }
  120. $this->slug = $slug;
  121. $this->name = $name;
  122. $this->town = $town;
  123. $this->townLocation = $townLocation;
  124. $this->postalCode = $postalCode;
  125. $this->whaterPoints = new ArrayCollection();
  126. $this->establishments = new ArrayCollection();
  127. $this->createdAt = new \DateTime();
  128. $this->updatedAt = new \DateTime();
  129. $this->latitude = $latitude;
  130. $this->longitude = $longitude;
  131. if ($this->latitude == null || $this->longitude == null) {
  132. $this->latitude = $town->latitude();
  133. $this->longitude = $town->longitude();
  134. }
  135. $this->distributionNetwork = $distributionNetwork;
  136. $this->valorations = new ArrayCollection();
  137. $this->images = new ArrayCollection();
  138. $this->comments = new ArrayCollection();
  139. $this->whaterDevices = new ArrayCollection();
  140. $this->ownershipRequests = new ArrayCollection();
  141. }
  142. public function updateUbicationData(
  143. string $name,
  144. string $slug = null,
  145. float $latitude = null,
  146. float $longitude = null,
  147. string $postalCode = null,
  148. DistributionNetwork $distributionNetwork = null,
  149. string $email = null,
  150. int $population = null,
  151. TownLocation $townLocation = null
  152. ) {
  153. $this->name = $name;
  154. $this->slug = $slug;
  155. if ($latitude != null && $longitude != null) {
  156. $this->latitude = $latitude;
  157. $this->longitude = $longitude;
  158. }
  159. $this->postalCode = $postalCode;
  160. $this->distributionNetwork = $distributionNetwork;
  161. $this->email = $email;
  162. $this->population = $population;
  163. if($townLocation != null){
  164. $this->townLocation = $townLocation;
  165. }
  166. $this->updatedAt = new \DateTime();
  167. }
  168. public function addWhaterOrganization(
  169. WhaterOrganization $whaterOrganization
  170. )
  171. {
  172. $this->whaterOrganization = $whaterOrganization;
  173. $this->updatedAt = new \DateTime();
  174. }
  175. /**
  176. * @return string
  177. */
  178. public function id(): string
  179. {
  180. return $this->uuid;
  181. }
  182. /**
  183. * @return string
  184. */
  185. public function name(): string
  186. {
  187. return $this->name;
  188. }
  189. /**
  190. * @return string
  191. */
  192. public function slug(): ?string
  193. {
  194. return $this->slug;
  195. }
  196. /**
  197. * @return string
  198. */
  199. public function postalCode(): ?string
  200. {
  201. return $this->postalCode;
  202. }
  203. /**
  204. * @return string
  205. */
  206. public function email(): ?string
  207. {
  208. return $this->email;
  209. }
  210. /**
  211. * @return float|null
  212. */
  213. public function latitude(): ?float
  214. {
  215. return $this->latitude;
  216. }
  217. /**
  218. * @return float|null
  219. */
  220. public function longitude(): ?float
  221. {
  222. return $this->longitude;
  223. }
  224. /**
  225. * @return integer|null
  226. */
  227. public function population(): ?int
  228. {
  229. return $this->population;
  230. }
  231. /**
  232. * @return Town
  233. */
  234. public function town(): Town
  235. {
  236. return $this->town;
  237. }
  238. /**
  239. * @return TownLocation|null
  240. */
  241. public function townLocation(): ?TownLocation
  242. {
  243. return $this->townLocation;
  244. }
  245. /**
  246. * @return DistributionNetwork
  247. */
  248. public function distributionNetwork(): ?DistributionNetwork
  249. {
  250. return $this->distributionNetwork;
  251. }
  252. /**
  253. * @return Collection
  254. */
  255. public function valorations(): Collection
  256. {
  257. return $this->valorations;
  258. }
  259. /**
  260. * @return Collection
  261. */
  262. public function images(): Collection
  263. {
  264. return $this->images;
  265. }
  266. /**
  267. * @return Collection
  268. */
  269. public function comments(): Collection
  270. {
  271. return $this->comments;
  272. }
  273. /**
  274. * @return Collection
  275. */
  276. public function ownershipRequests(): Collection
  277. {
  278. return $this->ownershipRequests;
  279. }
  280. /**
  281. * @return Collection
  282. */
  283. public function whaterPoints(): Collection
  284. {
  285. return $this->whaterPoints;
  286. }
  287. /**
  288. * @return Collection
  289. */
  290. public function whaterDevices(): Collection
  291. {
  292. return $this->whaterDevices;
  293. }
  294. /**
  295. * @return Collection
  296. */
  297. public function establishments(): Collection
  298. {
  299. return $this->establishments;
  300. }
  301. /**
  302. * @return \DateTime
  303. */
  304. public function createdAt(): \DateTime
  305. {
  306. return $this->createdAt;
  307. }
  308. /**
  309. * @return \DateTime
  310. */
  311. public function updatedAt(): \DateTime
  312. {
  313. return $this->updatedAt;
  314. }
  315. /**
  316. * @return WhaterOrganization
  317. */
  318. public function whaterOrganization(): ?WhaterOrganization
  319. {
  320. return $this->whaterOrganization;
  321. }
  322. /**
  323. * @return bool
  324. */
  325. public function equals(Ubication $ubication)
  326. {
  327. return $this->id() === $ubication->id();
  328. }
  329. }