src/Entity/Subscription.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubscriptionRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * @ORM\Entity(repositoryClass=SubscriptionRepository::class)
  7. */
  8. class Subscription
  9. {
  10. /**
  11. * @ORM\Id
  12. * @ORM\GeneratedValue
  13. * @ORM\Column(type="integer")
  14. */
  15. private $id;
  16. /**
  17. * @ORM\Column(type="datetime_immutable")
  18. */
  19. private $createdAt;
  20. /**
  21. * @ORM\Column(type="datetime_immutable")
  22. */
  23. private $updatedAt;
  24. /**
  25. * @ORM\Column(type="datetime", nullable=true)
  26. */
  27. private $expiresAt;
  28. /**
  29. * @ORM\Column(type="boolean", nullable=true)
  30. */
  31. private $isActivo;
  32. /**
  33. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="subscriptions")
  34. */
  35. private $user;
  36. /**
  37. * @ORM\ManyToOne(targetEntity=Product::class)
  38. */
  39. private $producto;
  40. /**
  41. * @ORM\Column(type="boolean", nullable=true)
  42. */
  43. private $isArchived;
  44. /**
  45. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="soldSubscriptions")
  46. */
  47. private $seller;
  48. /**
  49. * @ORM\Column(type="string", length=1000, nullable=true)
  50. */
  51. private $comentarios;
  52. /**
  53. * @ORM\Column(type="string", length=255, nullable=true)
  54. */
  55. private $currentPlace;
  56. /**
  57. * @ORM\Column(type="boolean", nullable=true)
  58. */
  59. private $hasFlag;
  60. /**
  61. * @ORM\OneToOne(targetEntity=PromoCodeUsage::class, mappedBy="subscription", cascade={"persist", "remove"})
  62. */
  63. private $promoCodeUsage;
  64. /**
  65. * @ORM\Column(type="string", length=255, nullable=true)
  66. */
  67. private $stripeId;
  68. /**
  69. * @ORM\OneToOne(targetEntity=OrdenItem::class, mappedBy="subscription", cascade={"persist", "remove"})
  70. */
  71. private $ordenItem;
  72. /**
  73. * @ORM\Column(type="integer", nullable=true)
  74. */
  75. private $clienteId;
  76. /**
  77. * @ORM\ManyToOne(targetEntity=SubscriptionStatus::class, inversedBy="subscripciones")
  78. */
  79. private $subscriptionStatus;
  80. public function __construct()
  81. {
  82. if(!$this->createdAt) $this->setCreatedAt(new \DateTimeImmutable());
  83. $this->setUpdatedAt(new \DateTimeImmutable());
  84. if(!$this->hasFlag) $this->setHasFlag(0);
  85. // if(!$this->currentPlace) $this->setCurrentPlace('Activa');
  86. }
  87. public function getId(): ?int
  88. {
  89. return $this->id;
  90. }
  91. public function getCreatedAt(): ?\DateTimeImmutable
  92. {
  93. return $this->createdAt;
  94. }
  95. public function setCreatedAt(\DateTimeImmutable $createdAt): self
  96. {
  97. $this->createdAt = $createdAt;
  98. return $this;
  99. }
  100. public function getUpdatedAt(): ?\DateTimeImmutable
  101. {
  102. return $this->updatedAt;
  103. }
  104. public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  105. {
  106. $this->updatedAt = $updatedAt;
  107. return $this;
  108. }
  109. public function getExpiresAt(): ?\DateTime
  110. {
  111. return $this->expiresAt;
  112. }
  113. public function setExpiresAt(\DateTime $expiresAt): self
  114. {
  115. $this->expiresAt = $expiresAt;
  116. return $this;
  117. }
  118. public function updateLastExpireDate(): self
  119. {
  120. $u = $this->getUser();
  121. $u->setLastSubscriptionDate($this->getExpiresAt());
  122. return $this;
  123. }
  124. public function getIsActivo(): ?bool
  125. {
  126. return $this->isActivo;
  127. }
  128. public function setIsActivo(?bool $isActivo): self
  129. {
  130. $this->isActivo = $isActivo;
  131. return $this;
  132. }
  133. public function getUser(): ?User
  134. {
  135. return $this->user;
  136. }
  137. public function setUser(?User $user): self
  138. {
  139. $this->user = $user;
  140. return $this;
  141. }
  142. public function getProducto(): ?Product
  143. {
  144. return $this->producto;
  145. }
  146. public function setProducto(?Product $producto): self
  147. {
  148. $this->producto = $producto;
  149. return $this;
  150. }
  151. public function __toString()
  152. {
  153. $prog = $this->getProducto() ? $this->getProducto()->getPrograma() : 'Producto Nulo';
  154. return $prog . ': ' . $this->getExpiresAt()->format('d-M-Y');
  155. }
  156. public function isIsArchived(): ?bool
  157. {
  158. return $this->isArchived;
  159. }
  160. public function setIsArchived(?bool $isArchived): self
  161. {
  162. $this->isArchived = $isArchived;
  163. return $this;
  164. }
  165. public function getSeller(): ?User
  166. {
  167. return $this->seller;
  168. }
  169. public function setSeller(?User $seller): self
  170. {
  171. $this->seller = $seller;
  172. return $this;
  173. }
  174. public function getComentarios(): ?string
  175. {
  176. return $this->comentarios;
  177. }
  178. public function setComentarios(?string $comentarios): self
  179. {
  180. $this->comentarios = $comentarios;
  181. return $this;
  182. }
  183. public function getCurrentPlace(): ?string
  184. {
  185. return $this->currentPlace;
  186. }
  187. public function setCurrentPlace(?string $currentPlace): self
  188. {
  189. $this->currentPlace = $currentPlace;
  190. return $this;
  191. }
  192. public function isHasFlag(): ?bool
  193. {
  194. return $this->hasFlag;
  195. }
  196. public function setHasFlag(?bool $hasFlag): self
  197. {
  198. $this->hasFlag = $hasFlag;
  199. return $this;
  200. }
  201. public function getPromoCodeUsage(): ?PromoCodeUsage
  202. {
  203. return $this->promoCodeUsage;
  204. }
  205. public function setPromoCodeUsage(?PromoCodeUsage $promoCodeUsage): self
  206. {
  207. // unset the owning side of the relation if necessary
  208. if ($promoCodeUsage === null && $this->promoCodeUsage !== null) {
  209. $this->promoCodeUsage->setSubscription(null);
  210. }
  211. // set the owning side of the relation if necessary
  212. if ($promoCodeUsage !== null && $promoCodeUsage->getSubscription() !== $this) {
  213. $promoCodeUsage->setSubscription($this);
  214. }
  215. $this->promoCodeUsage = $promoCodeUsage;
  216. return $this;
  217. }
  218. public function getStripeId(): ?string
  219. {
  220. return $this->stripeId;
  221. }
  222. public function setStripeId(?string $stripeId): self
  223. {
  224. $this->stripeId = $stripeId;
  225. return $this;
  226. }
  227. public function getOrdenItem(): ?OrdenItem
  228. {
  229. return $this->ordenItem;
  230. }
  231. public function setOrdenItem(?OrdenItem $ordenItem): self
  232. {
  233. // unset the owning side of the relation if necessary
  234. if ($ordenItem === null && $this->ordenItem !== null) {
  235. $this->ordenItem->setSubscription(null);
  236. }
  237. // set the owning side of the relation if necessary
  238. if ($ordenItem !== null && $ordenItem->getSubscription() !== $this) {
  239. $ordenItem->setSubscription($this);
  240. }
  241. $this->ordenItem = $ordenItem;
  242. return $this;
  243. }
  244. public function getClienteId(): ?int
  245. {
  246. return $this->clienteId;
  247. }
  248. public function setClienteId(?int $clienteId): self
  249. {
  250. $this->clienteId = $clienteId;
  251. return $this;
  252. }
  253. public function getUserSubStatus()
  254. {
  255. return $this->getUser()->getSubscriptionStatus();
  256. }
  257. public function getUserTel()
  258. {
  259. return $this->getUser()->getTel1();
  260. }
  261. public function getSubscriptionStatus(): ?SubscriptionStatus
  262. {
  263. return $this->subscriptionStatus;
  264. }
  265. public function setSubscriptionStatus(?SubscriptionStatus $subscriptionStatus): self
  266. {
  267. $this->subscriptionStatus = $subscriptionStatus;
  268. return $this;
  269. }
  270. }