src/Domain/Zones/Model/Agrupation.php line 22

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\User\Model\User;
  12. use Whater\Domain\Whater\Model\DistributionNetwork;
  13. use Whater\Domain\Zones\Exception\InvalidLocationInTownException;
  14. /**
  15. * Class Agrupation
  16. *
  17. * @package Whater\Domain\Zones\Model
  18. */
  19. class Agrupation implements ContainsRecordedEvents
  20. {
  21. use EventRecorderCapabilities;
  22. /**
  23. * @var string
  24. */
  25. private $uuid;
  26. /**
  27. * @var string
  28. */
  29. private $slug;
  30. /**
  31. * @var string
  32. */
  33. private $name;
  34. /**
  35. * @var Collection
  36. */
  37. private $towns;
  38. /**
  39. * @var Collection
  40. */
  41. private $countryAreas;
  42. /**
  43. * @var Collection
  44. */
  45. private $organizationLicenses;
  46. /**
  47. * @var \DateTime
  48. */
  49. private $createdAt;
  50. /**
  51. * @var \DateTime
  52. */
  53. private $updatedAt;
  54. /**
  55. * @param string $agrupationId
  56. * @param Town $town
  57. * @param string $name
  58. * @param string $slug
  59. */
  60. public function __construct(
  61. string $agrupationId = null,
  62. string $name,
  63. string $slug = null
  64. ) {
  65. try {
  66. $this->uuid = Uuid::fromString($agrupationId ?: Uuid::uuid4())->toString();
  67. } catch (\InvalidArgumentException $e) {
  68. throw new InvalidUUIDException();
  69. }
  70. $this->slug = $slug;
  71. $this->name = $name;
  72. $this->towns = new ArrayCollection();
  73. $this->countryAreas = new ArrayCollection();
  74. $this->organizationLicenses = new ArrayCollection();
  75. $this->createdAt = new \DateTime();
  76. $this->updatedAt = new \DateTime();
  77. }
  78. public function updateAgrupationData(
  79. string $name,
  80. string $slug = null
  81. ) {
  82. $this->name = $name;
  83. $this->slug = $slug;
  84. $this->updatedAt = new \DateTime();
  85. }
  86. /**
  87. * @return string
  88. */
  89. public function id(): string
  90. {
  91. return $this->uuid;
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function name(): string
  97. {
  98. return $this->name;
  99. }
  100. /**
  101. * @return string
  102. */
  103. public function slug(): ?string
  104. {
  105. return $this->slug;
  106. }
  107. /**
  108. * @return Collection
  109. */
  110. public function towns(): Collection
  111. {
  112. return $this->towns;
  113. }
  114. /**
  115. * @return Collection
  116. */
  117. public function countryAreas(): Collection
  118. {
  119. return $this->countryAreas;
  120. }
  121. /**
  122. * @return Collection
  123. */
  124. public function organizationLicenses(): Collection
  125. {
  126. return $this->organizationLicenses;
  127. }
  128. /**
  129. * @return \DateTime
  130. */
  131. public function createdAt(): \DateTime
  132. {
  133. return $this->createdAt;
  134. }
  135. /**
  136. * @return \DateTime
  137. */
  138. public function updatedAt(): \DateTime
  139. {
  140. return $this->updatedAt;
  141. }
  142. /**
  143. * @return bool
  144. */
  145. public function equals(Agrupation $agrupation)
  146. {
  147. return $this->id() === $agrupation->id();
  148. }
  149. }