src/Domain/Zones/Model/CountryArea.php line 18

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\Agrupation;
  10. /**
  11. * Class CountryArea
  12. *
  13. * @package Whater\Domain\Zones\Model
  14. */
  15. class CountryArea implements ContainsRecordedEvents
  16. {
  17. use EventRecorderCapabilities;
  18. const IDS_SINAC_PROVINCIA = 'sinac_codProvincia';
  19. /**
  20. * @var string
  21. */
  22. private $uuid;
  23. /**
  24. * @var string
  25. */
  26. private $slug;
  27. /**
  28. * @var array
  29. */
  30. private $externalIds;
  31. /**
  32. * @var string
  33. */
  34. private $name;
  35. /**
  36. * @var Country
  37. */
  38. private $country;
  39. /**
  40. * @var Collection
  41. */
  42. private $towns;
  43. /**
  44. * @var Collection
  45. */
  46. private $townLocations;
  47. /**
  48. * @var Collection
  49. */
  50. private $organizationLicenses;
  51. /**
  52. * @var Collection
  53. */
  54. private $products;
  55. /**
  56. * @var Collection
  57. */
  58. private $agrupations;
  59. /**
  60. * @var \DateTime
  61. */
  62. private $createdAt;
  63. /**
  64. * @var \DateTime
  65. */
  66. private $updatedAt;
  67. /**
  68. * @var string
  69. */
  70. private $adminCode;
  71. /**
  72. * @var string
  73. */
  74. private $geoNameId;
  75. /**
  76. * @var int
  77. */
  78. private $population;
  79. /**
  80. * @param string $areaId
  81. * @param Country $country
  82. * @param string $name
  83. * @param string $isoCode
  84. */
  85. public function __construct(
  86. string $areaId = null,
  87. Country $country,
  88. string $name,
  89. string $slug = null,
  90. array $externalIds = []
  91. ) {
  92. try {
  93. $this->uuid = Uuid::fromString($areaId ?: Uuid::uuid4())->toString();
  94. } catch (\InvalidArgumentException $e) {
  95. throw new InvalidUUIDException();
  96. }
  97. $this->country = $country;
  98. $this->slug = $slug;
  99. $this->externalIds = $externalIds;
  100. $this->name = $name;
  101. $this->towns = new ArrayCollection();
  102. $this->townLocations = new ArrayCollection();
  103. $this->organizationLicenses = new ArrayCollection();
  104. $this->products = new ArrayCollection();
  105. $this->agrupations = new ArrayCollection();
  106. $this->createdAt = new \DateTime();
  107. $this->updatedAt = new \DateTime();
  108. }
  109. public function updateCountryAreaData(
  110. string $name,
  111. string $slug = null,
  112. string $adminCode = null,
  113. string $geoNameId = null,
  114. int $population = null
  115. ) {
  116. $this->name = $name;
  117. $this->slug = $slug;
  118. $this->adminCode = $adminCode;
  119. $this->geoNameId = $geoNameId;
  120. $this->population = $population;
  121. $this->updatedAt = new \DateTime();
  122. }
  123. public function addAgrupation(
  124. Agrupation $agrupation = null
  125. ) {
  126. if(!$this->agrupations()){
  127. $this->agrupations = new ArrayCollection();
  128. }
  129. $this->agrupations->add($agrupation);
  130. $this->updatedAt = new \DateTime();
  131. }
  132. /**
  133. * @return string
  134. */
  135. public function id(): string
  136. {
  137. return $this->uuid;
  138. }
  139. /**
  140. * @return string
  141. */
  142. public function name(): string
  143. {
  144. return $this->name;
  145. }
  146. /**
  147. * @return string
  148. */
  149. public function adminCode(): ?string
  150. {
  151. return $this->adminCode;
  152. }
  153. /**
  154. * @return string
  155. */
  156. public function geoNameId(): ?string
  157. {
  158. return $this->geoNameId;
  159. }
  160. /**
  161. * @return integer|null
  162. */
  163. public function population(): ?int
  164. {
  165. return $this->population;
  166. }
  167. /**
  168. * @return string
  169. */
  170. public function slug(): ?string
  171. {
  172. return $this->slug;
  173. }
  174. /**
  175. * @return array
  176. */
  177. public function externalIds(): array
  178. {
  179. return $this->externalIds;
  180. }
  181. /**
  182. * @return Country
  183. */
  184. public function country(): Country
  185. {
  186. return $this->country;
  187. }
  188. /**
  189. * @return Collection
  190. */
  191. public function towns(): Collection
  192. {
  193. return $this->towns;
  194. }
  195. /**
  196. * @return Collection
  197. */
  198. public function townLocations(): Collection
  199. {
  200. return $this->townLocations;
  201. }
  202. /**
  203. * @return Collection
  204. */
  205. public function organizationLicenses(): Collection
  206. {
  207. return $this->organizationLicenses;
  208. }
  209. /**
  210. * @return Collection
  211. */
  212. public function products(): Collection
  213. {
  214. return $this->products;
  215. }
  216. /**
  217. * @return Collection
  218. */
  219. public function agrupations(): Collection
  220. {
  221. return $this->agrupations;
  222. }
  223. /**
  224. * @return \DateTime
  225. */
  226. public function createdAt(): \DateTime
  227. {
  228. return $this->createdAt;
  229. }
  230. /**
  231. * @return \DateTime
  232. */
  233. public function updatedAt(): \DateTime
  234. {
  235. return $this->updatedAt;
  236. }
  237. /**
  238. * @return bool
  239. */
  240. public function equals(CountryArea $countryArea)
  241. {
  242. return $this->id() === $countryArea->id();
  243. }
  244. }