src/Domain/Zones/Model/Country.php line 17

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