src/Domain/Whater/Model/WhaterValoration.php line 19

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