You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
7.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Reduction;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
  9. use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
  10. use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
  11. use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyTrait;
  12. use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
  13. use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait;
  14. use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
  15. use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
  16. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  17. use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
  18. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  19. use Lc\SovBundle\Doctrine\Extension\StatusInterface;
  20. use Lc\SovBundle\Doctrine\Extension\StatusTrait;
  21. use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
  22. use Lc\SovBundle\Model\User\UserInterface;
  23. /**
  24. * @ORM\MappedSuperclass()
  25. */
  26. abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
  27. ReductionCartPropertyInterface,
  28. FilterSectionInterface,
  29. OrderAmountMinInterface, StatusInterface
  30. {
  31. const APPLIED_TO_DELIVERY = 'delivery';
  32. const APPLIED_TO_ORDER_PRODUCTS = 'order-products';
  33. use StatusTrait;
  34. use OrderAmountMinTrait;
  35. use ReductionTrait;
  36. use ReductionCartPropertyTrait;
  37. use ReductionPropertyTrait {
  38. ReductionPropertyTrait::__construct as private __reductionPropertyConstruct;
  39. }
  40. /**
  41. * @ORM\Column(type="string", length=255)
  42. */
  43. protected $title;
  44. /**
  45. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
  46. * @ORM\JoinColumn(nullable=false)
  47. */
  48. protected $section;
  49. /**
  50. * @ORM\Column(type="array", nullable=true)
  51. */
  52. protected $codes = [];
  53. /**
  54. * @ORM\Column(type="integer")
  55. */
  56. protected $availableQuantity;
  57. /**
  58. * @ORM\Column(type="integer")
  59. */
  60. protected $availableQuantityPerUser;
  61. /**
  62. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\PointSale\PointSaleInterface")
  63. */
  64. protected $pointSales;
  65. /**
  66. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface")
  67. */
  68. protected $uncombinables;
  69. /**
  70. * @ORM\Column(type="array", nullable=true)
  71. */
  72. protected $uncombinableTypes = [];
  73. /**
  74. * @ORM\Column(type="integer", nullable=true)
  75. */
  76. protected $availableQuantityPerCode;
  77. public function __toString()
  78. {
  79. return $this->title;
  80. }
  81. public function __construct()
  82. {
  83. $this->__reductionPropertyConstruct();
  84. $this->pointSales = new ArrayCollection();
  85. $this->uncombinables = new ArrayCollection();
  86. }
  87. // isReductionCartMatchWithUser
  88. public function matchWithUser(UserInterface $user)
  89. {
  90. $conditionUser = false;
  91. if ($user) {
  92. if ($this->getUsers()->isEmpty() || $this->getUsers()->contains($user)) {
  93. $conditionUser = true;
  94. }
  95. }
  96. return $conditionUser;
  97. }
  98. // isReductionCartMatchWithGroupUser
  99. public function matchWithGroupUser(UserInterface $user)
  100. {
  101. $conditionGroupUser = false;
  102. if ($user) {
  103. if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) {
  104. foreach ($user->getGroupUsers() as $groupUser) {
  105. if ($this->getGroupUsers()->isEmpty() || $this->getGroupUsers()->contains($groupUser)) {
  106. $conditionGroupUser = true;
  107. }
  108. }
  109. } else {
  110. if ($reductionCart->getGroupUsers()->isEmpty()) {
  111. $conditionGroupUser = true;
  112. }
  113. }
  114. }
  115. return $conditionGroupUser;
  116. }
  117. public function getTitle(): ?string
  118. {
  119. return $this->title;
  120. }
  121. public function setTitle(string $title): self
  122. {
  123. $this->title = $title;
  124. return $this;
  125. }
  126. public function getSection(): SectionInterface
  127. {
  128. return $this->section;
  129. }
  130. public function setSection(SectionInterface $section): self
  131. {
  132. $this->section = $section;
  133. return $this;
  134. }
  135. public function getCodes(): ?array
  136. {
  137. return $this->codes;
  138. }
  139. public function setCodes(?array $codes): self
  140. {
  141. $this->codes = $codes;
  142. return $this;
  143. }
  144. /**
  145. * @return Collection|PointSaleInterface[]
  146. */
  147. public function getPointSales(): Collection
  148. {
  149. return $this->pointSales;
  150. }
  151. public function addPointSale(PointSaleInterface $pointSale): self
  152. {
  153. if (!$this->pointSales->contains($pointSale)) {
  154. $this->pointSales[] = $pointSale;
  155. }
  156. return $this;
  157. }
  158. public function removePointSale(PointSaleInterface $pointSale): self
  159. {
  160. if ($this->pointSales->contains($pointSale)) {
  161. $this->pointSales->removeElement($pointSale);
  162. }
  163. return $this;
  164. }
  165. public function getAvailableQuantity(): ?int
  166. {
  167. return $this->availableQuantity;
  168. }
  169. public function setAvailableQuantity(int $availableQuantity): self
  170. {
  171. $this->availableQuantity = $availableQuantity;
  172. return $this;
  173. }
  174. public function getAvailableQuantityPerUser(): ?int
  175. {
  176. return $this->availableQuantityPerUser;
  177. }
  178. public function setAvailableQuantityPerUser(int $availableQuantityPerUser): self
  179. {
  180. $this->availableQuantityPerUser = $availableQuantityPerUser;
  181. return $this;
  182. }
  183. /**
  184. * @return Collection|self[]
  185. */
  186. public function getUncombinables(): Collection
  187. {
  188. return $this->uncombinables;
  189. }
  190. public function addUncombinable(self $uncombinable): self
  191. {
  192. if (!$this->uncombinables->contains($uncombinable)) {
  193. $this->uncombinables[] = $uncombinable;
  194. }
  195. return $this;
  196. }
  197. public function removeUncombinables(self $uncombinable): self
  198. {
  199. if ($this->uncombinables->contains($uncombinable)) {
  200. $this->uncombinables->removeElement($uncombinable);
  201. }
  202. return $this;
  203. }
  204. public function getUncombinableTypes(): ?array
  205. {
  206. return $this->uncombinableTypes;
  207. }
  208. public function setUncombinableTypes(?array $uncombinableTypes): self
  209. {
  210. $this->uncombinableTypes = $uncombinableTypes;
  211. return $this;
  212. }
  213. public function getAvailableQuantityPerCode(): ?int
  214. {
  215. return $this->availableQuantityPerCode;
  216. }
  217. public function setAvailableQuantityPerCode(int $availableQuantityPerCode): self
  218. {
  219. $this->availableQuantityPerCode = $availableQuantityPerCode;
  220. return $this;
  221. }
  222. }