src/Domain/Product/Model/ProductCategory.php line 17

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Product\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use Ramsey\Uuid\Uuid;
  6. use Whater\Domain\Common\Exception\InvalidUUIDException;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. /**
  10. * Class ProductCategory
  11. *
  12. * @package Whater\Domain\productCategory\Model
  13. */
  14. class ProductCategory implements ContainsRecordedEvents
  15. {
  16. use EventRecorderCapabilities;
  17. /**
  18. * @var string
  19. */
  20. private $uuid;
  21. /**
  22. * @var string
  23. */
  24. private $productCategoryName;
  25. /**
  26. * @var string
  27. */
  28. private $productCategorySlug;
  29. /**
  30. * @var string
  31. */
  32. private $productCategoryDescription;
  33. /**
  34. * @var \DateTime
  35. */
  36. private $createdAt;
  37. /**
  38. * @var null|\DateTime
  39. */
  40. private $updatedAt;
  41. /**
  42. * @var Collection
  43. */
  44. private $productCategoryChildren;
  45. /**
  46. * @var Collection
  47. */
  48. private $products;
  49. /**
  50. * @var ProductCategory
  51. */
  52. private $productCategoryParent;
  53. /**
  54. * @param string $productCategoryId
  55. */
  56. public function __construct(
  57. string $productCategoryId = null,
  58. string $productCategoryName,
  59. string $productCategoryDescription = null,
  60. ProductCategory $productCategoryParent = null,
  61. ) {
  62. try {
  63. $this->uuid = Uuid::fromString($productCategoryId ?: Uuid::uuid4())->toString();
  64. } catch (\InvalidArgumentException $e) {
  65. throw new InvalidUUIDException();
  66. }
  67. $this->productCategoryName = $productCategoryName;
  68. $this->productCategorySlug = $productCategoryName;
  69. $this->productCategoryDescription = $productCategoryDescription;
  70. $this->productCategoryParent = $productCategoryParent;
  71. $this->createdAt = new \DateTime();
  72. $this->updatedAt = new \DateTime();
  73. $this->productCategoryChildren = new ArrayCollection();
  74. }
  75. public function editproductCategory(
  76. string $productCategoryName,
  77. string $productCategoryDescription = null,
  78. string $productCategorySlug = null,
  79. ProductCategory $productCategoryParent = null
  80. ) {
  81. $this->productCategoryName = $productCategoryName;
  82. $this->productCategoryDescription = $productCategoryDescription;
  83. $this->productCategorySlug = $productCategorySlug;
  84. $this->productCategoryParent = $productCategoryParent;
  85. $this->updatedAt = new \DateTime();
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function id(): string
  91. {
  92. return $this->uuid;
  93. }
  94. /**
  95. * @return string
  96. */
  97. public function productCategoryName(): string
  98. {
  99. return $this->productCategoryName;
  100. }
  101. /**
  102. * @return string
  103. */
  104. public function productCategorySlug(): string
  105. {
  106. return $this->productCategorySlug;
  107. }
  108. /**
  109. * @return string
  110. */
  111. public function productCategoryDescription(): ?string
  112. {
  113. return $this->productCategoryDescription;
  114. }
  115. /**
  116. * @return ProductCategory
  117. */
  118. public function productCategoryParent(): ?ProductCategory
  119. {
  120. return $this->productCategoryParent;
  121. }
  122. public function categoryPath(): string
  123. {
  124. if ($this->productCategoryParent() == null) {
  125. return $this->productCategoryName();
  126. } else {
  127. return $this->productCategoryParent()->categoryPath() . ' > ' . $this->productCategoryName();
  128. }
  129. }
  130. /**
  131. * @return \DateTime
  132. */
  133. public function createdAt(): \DateTime
  134. {
  135. return $this->createdAt;
  136. }
  137. /**
  138. * @return \DateTime|null
  139. */
  140. public function updatedAt()
  141. {
  142. return $this->updatedAt;
  143. }
  144. public function productCategoryChildren(): Collection
  145. {
  146. return $this->productCategoryChildren;
  147. }
  148. public function products(): Collection
  149. {
  150. return $this->products;
  151. }
  152. }