src/Domain/Whater/Model/DistributionNetworkValoration.php line 20

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Whater\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\Media\Model\DistributionNetworkValorationImage;
  10. use Whater\Domain\Media\Model\WhaterValorationImage;
  11. use Whater\Domain\User\Model\User;
  12. /**
  13. * Class DistributionNetworkValoration
  14. *
  15. * @package Whater\Domain\Whater\Model
  16. */
  17. class DistributionNetworkValoration implements ContainsRecordedEvents
  18. {
  19. use EventRecorderCapabilities;
  20. public const DN_MAX_VALORATION = 5;
  21. public const DN_MIN_VALORATION = 0;
  22. public const DN_QUALITY_ACCEPTABLE_VALORATION = "DN_QUALITY_ACCEPTABLE_VALORATION";
  23. public const DN_QUALITY_NOT_ACCEPTABLE_VALORATION = "DN_QUALITY_NOT_ACCEPTABLE_VALORATION";
  24. public const DN_QUALITY_NEEDS_IMPROVEMENT_VALORATION = "DN_QUALITY_NEEDS_IMPROVEMENT_VALORATION";
  25. /**
  26. * @var string
  27. */
  28. private $uuid;
  29. /**
  30. * @var DistributionNetwork
  31. */
  32. private $distributionNetwork;
  33. /**
  34. * @var User
  35. */
  36. private $createdBy;
  37. /**
  38. * @var \DateTime
  39. */
  40. private $createdAt;
  41. /**
  42. * @var string
  43. */
  44. private $colorValoration;
  45. /**
  46. * @var string
  47. */
  48. private $tasteValoration;
  49. /**
  50. * @var string
  51. */
  52. private $smellValoration;
  53. /**
  54. * @var string
  55. */
  56. private $turbidityValoration;
  57. /**
  58. * @var string
  59. */
  60. private $generalValoration;
  61. /**
  62. * @var string
  63. */
  64. private $userCommentText;
  65. /**
  66. * @var string
  67. */
  68. private $responseCommentText;
  69. /**
  70. * @var \DateTime
  71. */
  72. private $responseCommentAt;
  73. /**
  74. * @var bool
  75. */
  76. private $hideUserComment;
  77. /**
  78. * @var DistributionNetworkValorationImage
  79. */
  80. private $commentImage;
  81. /**
  82. * @var bool
  83. */
  84. private $isProfessionalValoration;
  85. public function __construct(
  86. string $distributionNetworkPointValorationId = null,
  87. DistributionNetwork $distributionNetwork,
  88. User $createdBy,
  89. string $colorValoration = null,
  90. string $tasteValoration = null,
  91. string $smellValoration = null,
  92. string $turbidityValoration = null,
  93. string $generalValoration = null,
  94. bool $isProfessionalValoration = false,
  95. DistributionNetworkValorationImage $commentImage = null
  96. ) {
  97. try {
  98. $this->uuid = Uuid::fromString($distributionNetworkPointValorationId ?: Uuid::uuid4())->toString();
  99. } catch (\InvalidArgumentException $e) {
  100. throw new InvalidUUIDException();
  101. }
  102. $this->distributionNetwork = $distributionNetwork;
  103. $this->createdBy = $createdBy;
  104. $this->isProfessionalValoration = $isProfessionalValoration;
  105. $this->hideUserComment = true;
  106. $this->commentImage = $commentImage;
  107. $this->createdAt = new \DateTime();
  108. $this->updateValoration(
  109. $colorValoration,
  110. $tasteValoration,
  111. $smellValoration,
  112. $turbidityValoration,
  113. $generalValoration
  114. );
  115. }
  116. public function updateValoration(
  117. string $colorValoration = null,
  118. string $tasteValoration = null,
  119. string $smellValoration = null,
  120. string $turbidityValoration = null,
  121. string $generalValoration = null
  122. ): DistributionNetworkValoration {
  123. if (!$this->distributionNetwork()->valorations()->contains($this)) {
  124. $this->distributionNetwork()->valorations()->add($this);
  125. }
  126. if (!is_null($colorValoration)) {
  127. $this->colorValoration = $colorValoration;
  128. }
  129. if (!is_null($tasteValoration)) {
  130. $this->tasteValoration = $tasteValoration;
  131. }
  132. if (!is_null($smellValoration)) {
  133. $this->smellValoration = $smellValoration;
  134. }
  135. if (!is_null($turbidityValoration)) {
  136. $this->turbidityValoration = $turbidityValoration;
  137. }
  138. if (!is_null($generalValoration)) {
  139. $this->generalValoration = $generalValoration;
  140. }
  141. $this->distributionNetwork()->updateValorations();
  142. return $this;
  143. }
  144. public function updateComment(
  145. string $userCommentText = null,
  146. string $responseCommentText = null,
  147. \DateTime $responseCommentAt = null,
  148. bool $hideUserComment = false
  149. ): DistributionNetworkValoration {
  150. $this->userCommentText = $userCommentText;
  151. $this->responseCommentText = $responseCommentText;
  152. $this->responseCommentAt = $responseCommentAt;
  153. $this->hideUserComment = $hideUserComment;
  154. return $this;
  155. }
  156. /**
  157. * @return string
  158. */
  159. public function id(): string
  160. {
  161. return $this->uuid;
  162. }
  163. /**
  164. * @return DistributionNetwork
  165. */
  166. public function distributionNetwork(): DistributionNetwork
  167. {
  168. return $this->distributionNetwork;
  169. }
  170. /**
  171. * @return User
  172. */
  173. public function createdBy(): User
  174. {
  175. return $this->createdBy;
  176. }
  177. /**
  178. * @return string
  179. */
  180. public function colorValoration(): ?string
  181. {
  182. return $this->colorValoration;
  183. }
  184. /**
  185. * @return string
  186. */
  187. public function tasteValoration(): ?string
  188. {
  189. return $this->tasteValoration;
  190. }
  191. /**
  192. * @return string
  193. */
  194. public function smellValoration(): ?string
  195. {
  196. return $this->smellValoration;
  197. }
  198. /**
  199. * @return string
  200. */
  201. public function turbidityValoration(): ?string
  202. {
  203. return $this->turbidityValoration;
  204. }
  205. /**
  206. * @return string
  207. */
  208. public function generalValoration(): ?string
  209. {
  210. return $this->generalValoration;
  211. }
  212. /**
  213. * @return bool
  214. */
  215. public function isProfessionalValoration(): bool
  216. {
  217. return $this->isProfessionalValoration;
  218. }
  219. /**
  220. * @return string
  221. */
  222. public function userCommentText(): ?string
  223. {
  224. return $this->userCommentText;
  225. }
  226. /**
  227. * @return string
  228. */
  229. public function responseCommentText(): ?string
  230. {
  231. return $this->responseCommentText;
  232. }
  233. /**
  234. * @return \DateTime
  235. */
  236. public function responseCommentAt(): ?\DateTime
  237. {
  238. return $this->responseCommentAt;
  239. }
  240. /**
  241. * @return bool
  242. */
  243. public function hideUserComment(): bool
  244. {
  245. return $this->hideUserComment;
  246. }
  247. /**
  248. * @return DistributionNetworkValorationImage
  249. */
  250. public function commentImage(): ?DistributionNetworkValorationImage
  251. {
  252. return $this->commentImage;
  253. }
  254. /**
  255. * @return \DateTime
  256. */
  257. public function createdAt(): \DateTime
  258. {
  259. return $this->createdAt;
  260. }
  261. /**
  262. * @return bool
  263. */
  264. public function equals(DistributionNetworkValoration $distributionNetworkValoration)
  265. {
  266. return $this->id() === $distributionNetworkValoration->id();
  267. }
  268. }