src/Entity/User.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\EmailTemplateRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\AttributeOverrides;
  8. use Doctrine\ORM\Mapping\AttributeOverride;
  9. use Doctrine\ORM\Mapping\Column;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. use Serializable;
  16. use Doctrine\Common\Collections\Criteria;
  17. /**
  18. * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  19. * @ORM\HasLifecycleCallbacks()
  20. * @UniqueEntity("username")
  21. * @Vich\Uploadable
  22. */
  23. class User implements \Utixodev\FicBundle\Entity\UserInterface, UserInterface, Serializable
  24. {
  25. const STATUS_ACTIVE = 'active';
  26. const STATUS_SUSPENDED = 'suspended';
  27. const STATUS_TERMINATED = 'terminated';
  28. /**
  29. * @ORM\Id()
  30. * @ORM\GeneratedValue()
  31. * @ORM\Column(type="integer")
  32. */
  33. private $id;
  34. /**
  35. * @ORM\Column(type="string", length=180, unique=true)
  36. * @Assert\NotNull()
  37. */
  38. private $username;
  39. /**
  40. * @ORM\Column(type="json")
  41. */
  42. private $roles = [];
  43. /**
  44. * @var string The hashed password
  45. * @ORM\Column(type="string")
  46. * @Assert\NotNull()
  47. */
  48. private $password;
  49. /**
  50. * @ORM\Column(type="string", length=255)
  51. * @Assert\Email()
  52. * @Assert\NotNull()
  53. */
  54. private $email;
  55. /**
  56. * @ORM\Column(type="datetime")
  57. */
  58. private $created_at;
  59. /**
  60. * @ORM\Column(type="datetime", nullable=true)
  61. * @Assert\NotNull
  62. */
  63. private $last_login;
  64. /**
  65. * @ORM\OneToMany(targetEntity="App\Entity\Contact", mappedBy="user", fetch="EXTRA_LAZY")
  66. */
  67. private $contacts;
  68. /**
  69. * @ORM\OneToMany(targetEntity="App\Entity\Email", mappedBy="user")
  70. */
  71. private $emails;
  72. /**
  73. * @ORM\OneToMany(targetEntity="App\Entity\Campaign", mappedBy="user", orphanRemoval=true)
  74. */
  75. private $campaigns;
  76. /**
  77. * @ORM\OneToMany(targetEntity="App\Entity\ContactGroup", mappedBy="user", orphanRemoval=true)
  78. */
  79. private $contactGroups;
  80. /**
  81. * @ORM\Column(type="string", length=255, nullable=true)
  82. */
  83. private $company;
  84. /**
  85. * @ORM\Column(type="string", length=255, nullable=true)
  86. */
  87. private $website;
  88. /**
  89. * @ORM\Column(type="string", length=255, nullable=true)
  90. */
  91. private $logo;
  92. /**
  93. * @Vich\UploadableField(mapping="uploads", fileNameProperty="logo")
  94. */
  95. private $logo_file;
  96. /**
  97. * @ORM\Column(type="datetime")
  98. */
  99. private $updated_at;
  100. /**
  101. * @ORM\Column(type="string", length=255, nullable=true)
  102. */
  103. private $address;
  104. /**
  105. * @ORM\Column(type="string", length=255, nullable=true)
  106. */
  107. private $from_address;
  108. /**
  109. * @ORM\OneToMany(targetEntity="App\Entity\ApiToken", mappedBy="user", orphanRemoval=true)
  110. */
  111. private $apiTokens;
  112. /**
  113. * @ORM\OneToMany(targetEntity="App\Entity\Form", mappedBy="user", orphanRemoval=true)
  114. */
  115. private $forms;
  116. /**
  117. * @ORM\Column(type="json")
  118. */
  119. private $send_count;
  120. /**
  121. * @ORM\ManyToOne(targetEntity="App\Entity\Plan", inversedBy="users")
  122. * @Assert\NotNull()
  123. */
  124. private $plan;
  125. /**
  126. * @ORM\OneToMany(targetEntity="App\Entity\Task", mappedBy="user")
  127. * @ORM\OrderBy({"created_at" = "DESC"})
  128. */
  129. private $tasks;
  130. /**
  131. * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="user")
  132. */
  133. private $notifications;
  134. /**
  135. * @ORM\OneToMany(targetEntity=EmailTemplate::class, mappedBy="user")
  136. */
  137. private $emailTemplates;
  138. /**
  139. * @ORM\OneToMany(targetEntity=Upload::class, mappedBy="user", orphanRemoval=true)
  140. */
  141. private $uploads;
  142. /**
  143. * @ORM\Column(type="string", length=255)
  144. */
  145. private $status;
  146. /**
  147. * @ORM\OneToMany(targetEntity=Domain::class, mappedBy="user", orphanRemoval=true)
  148. */
  149. private $domains;
  150. /**
  151. * @ORM\OneToOne(targetEntity=CustomFields::class, mappedBy="user", cascade={"persist", "remove"})
  152. */
  153. private $customFields;
  154. /**
  155. * @ORM\ManyToMany(targetEntity=Addon::class, inversedBy="users")
  156. */
  157. private $addons;
  158. public function __construct()
  159. {
  160. $this->contacts = new ArrayCollection();
  161. $this->emails = new ArrayCollection();
  162. $this->campaigns = new ArrayCollection();
  163. $this->contactGroups = new ArrayCollection();
  164. $this->apiTokens = new ArrayCollection();
  165. $this->forms = new ArrayCollection();
  166. $this->tasks = new ArrayCollection();
  167. $this->notifications = new ArrayCollection();
  168. $this->emailTemplates = new ArrayCollection();
  169. $this->uploads = new ArrayCollection();
  170. $this->domains = new ArrayCollection();
  171. $this->addons = new ArrayCollection();
  172. }
  173. public function getId(): ?int
  174. {
  175. return $this->id;
  176. }
  177. /**
  178. * A visual identifier that represents this user.
  179. *
  180. * @see UserInterface
  181. */
  182. public function getUsername(): string
  183. {
  184. return (string) $this->username;
  185. }
  186. public function setUsername(string $username): self
  187. {
  188. $this->username = $username;
  189. return $this;
  190. }
  191. /**
  192. * @see UserInterface
  193. */
  194. public function getRoles(): array
  195. {
  196. $roles = $this->roles;
  197. // guarantee every user at least has ROLE_USER
  198. $roles[] = 'ROLE_USER';
  199. return array_unique($roles);
  200. }
  201. public function setRoles(array $roles): self
  202. {
  203. $this->roles = $roles;
  204. return $this;
  205. }
  206. /**
  207. * @see UserInterface
  208. */
  209. public function getPassword(): string
  210. {
  211. return (string) $this->password;
  212. }
  213. public function setPassword(string $password): self
  214. {
  215. $this->password = $password;
  216. return $this;
  217. }
  218. /**
  219. * @see UserInterface
  220. */
  221. public function getSalt()
  222. {
  223. // not needed when using the "bcrypt" algorithm in security.yaml
  224. }
  225. /**
  226. * @see UserInterface
  227. */
  228. public function eraseCredentials()
  229. {
  230. // If you store any temporary, sensitive data on the user, clear it here
  231. // $this->plainPassword = null;
  232. }
  233. public function getEmail(): ?string
  234. {
  235. return $this->email;
  236. }
  237. public function setEmail(string $email): self
  238. {
  239. $this->email = $email;
  240. return $this;
  241. }
  242. public function getCreatedAt(): ?\DateTimeInterface
  243. {
  244. return $this->created_at;
  245. }
  246. public function setCreatedAt(\DateTimeInterface $created_at): self
  247. {
  248. $this->created_at = $created_at;
  249. return $this;
  250. }
  251. /**
  252. * Gets triggered only on insert
  253. * @ORM\PrePersist
  254. */
  255. public function setCreatedAtValue()
  256. {
  257. $this->setCreatedAt(new \DateTime());
  258. }
  259. /**
  260. * Gets triggered only on update
  261. * @ORM\PreUpdate
  262. */
  263. public function updateLastLoginValue(){
  264. $this->setLastLogin(new \DateTime());
  265. }
  266. public function getLastLogin(): ?\DateTimeInterface
  267. {
  268. return $this->last_login;
  269. }
  270. public function setLastLogin(?\DateTimeInterface $last_login): self
  271. {
  272. $this->last_login = $last_login;
  273. return $this;
  274. }
  275. /**
  276. * @param Bool $showDeleted
  277. * @return Collection|Contact[]
  278. */
  279. public function getContacts(bool $showDeleted = false): Collection
  280. {
  281. if($showDeleted){
  282. return $this->contacts;
  283. } else {
  284. return $this->contacts->filter(function(Contact $contact){
  285. return $contact->getStatus() != 'deleted' && $contact->getStatus() != 'unsubscribed';
  286. });
  287. }
  288. }
  289. /**
  290. * @param String $status
  291. * @return Collection|Contact[]
  292. */
  293. public function getContactsByStatus($status): Collection
  294. {
  295. $criteria = Criteria::create()->where(Criteria::expr()->eq('status', $status));
  296. return $this->getContacts(true)->matching($criteria);
  297. }
  298. public function addContact(Contact $contact): self
  299. {
  300. if (!$this->contacts->contains($contact)) {
  301. $this->contacts[] = $contact;
  302. $contact->setUser($this);
  303. }
  304. return $this;
  305. }
  306. public function removeContact(Contact $contact): self
  307. {
  308. if ($this->contacts->contains($contact)) {
  309. $this->contacts->removeElement($contact);
  310. // set the owning side to null (unless already changed)
  311. if ($contact->getUser() === $this) {
  312. $contact->setUser(null);
  313. }
  314. }
  315. return $this;
  316. }
  317. /**
  318. * @return Collection|Email[]
  319. */
  320. public function getEmails(): Collection
  321. {
  322. return $this->emails;
  323. }
  324. public function addEmail(Email $email): self
  325. {
  326. if (!$this->emails->contains($email)) {
  327. $this->emails[] = $email;
  328. $email->setUser($this);
  329. }
  330. return $this;
  331. }
  332. public function removeEmail(Email $email): self
  333. {
  334. if ($this->emails->contains($email)) {
  335. $this->emails->removeElement($email);
  336. // set the owning side to null (unless already changed)
  337. if ($email->getUser() === $this) {
  338. $email->setUser(null);
  339. }
  340. }
  341. return $this;
  342. }
  343. /**
  344. * @return Collection|Campaign[]
  345. */
  346. public function getCampaigns(): Collection
  347. {
  348. return $this->campaigns;
  349. }
  350. /**
  351. * @return Collection|Campaign[]
  352. */
  353. public function getActiveCampaigns(): Collection
  354. {
  355. return $this->campaigns->filter(function(Campaign $campaign){
  356. return $campaign->getActive() === true;
  357. });
  358. }
  359. /**
  360. * @return Collection|Campaign[]
  361. */
  362. public function getCampaignsToSend(): Collection
  363. {
  364. return $this->campaigns->filter(function(Campaign $campaign){
  365. return ($campaign->getActive() === true && $campaign->isSent() === false);
  366. });
  367. }
  368. public function addCampaign(Campaign $campaign): self
  369. {
  370. if (!$this->campaigns->contains($campaign)) {
  371. $this->campaigns[] = $campaign;
  372. $campaign->setUser($this);
  373. }
  374. return $this;
  375. }
  376. public function removeCampaign(Campaign $campaign): self
  377. {
  378. if ($this->campaigns->contains($campaign)) {
  379. $this->campaigns->removeElement($campaign);
  380. // set the owning side to null (unless already changed)
  381. if ($campaign->getUser() === $this) {
  382. $campaign->setUser(null);
  383. }
  384. }
  385. return $this;
  386. }
  387. /**
  388. * @return Collection|ContactGroup[]
  389. */
  390. public function getContactGroups(): Collection
  391. {
  392. return $this->contactGroups;
  393. }
  394. public function addContactGroup(ContactGroup $contactGroup): self
  395. {
  396. if (!$this->contactGroups->contains($contactGroup)) {
  397. $this->contactGroups[] = $contactGroup;
  398. $contactGroup->setUser($this);
  399. }
  400. return $this;
  401. }
  402. public function removeContactGroup(ContactGroup $contactGroup): self
  403. {
  404. if ($this->contactGroups->contains($contactGroup)) {
  405. $this->contactGroups->removeElement($contactGroup);
  406. // set the owning side to null (unless already changed)
  407. if ($contactGroup->getUser() === $this) {
  408. $contactGroup->setUser(null);
  409. }
  410. }
  411. return $this;
  412. }
  413. public function getCompany(): ?string
  414. {
  415. return $this->company;
  416. }
  417. public function setCompany(string $company): self
  418. {
  419. $this->company = $company;
  420. return $this;
  421. }
  422. public function getWebsite(): ?string
  423. {
  424. return $this->website;
  425. }
  426. public function setWebsite(?string $website): self
  427. {
  428. $this->website = $website;
  429. return $this;
  430. }
  431. public function getLogo(): ?string
  432. {
  433. return $this->logo;
  434. }
  435. public function setLogo(?string $logo): self
  436. {
  437. $this->logo = $logo;
  438. return $this;
  439. }
  440. public function getLogoFile(): ?File
  441. {
  442. return $this->logo_file;
  443. }
  444. /**
  445. * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  446. * of 'UploadedFile' is injected into this setter to trigger the update. If this
  447. * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  448. * must be able to accept an instance of 'File' as the bundle will inject one here
  449. * during Doctrine hydration.
  450. *
  451. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $imageFile
  452. */
  453. public function setLogoFile(?File $imageFile = null): void
  454. {
  455. $this->logo_file = $imageFile;
  456. if (null !== $imageFile) {
  457. // It is required that at least one field changes if you are using doctrine
  458. // otherwise the event listeners won't be called and the file is lost
  459. $this->updated_at = new \DateTimeImmutable();
  460. }
  461. }
  462. public function getUpdatedAt(): ?\DateTimeInterface
  463. {
  464. return $this->updated_at;
  465. }
  466. public function setUpdatedAt(\DateTimeInterface $updated_at): self
  467. {
  468. $this->updated_at = $updated_at;
  469. return $this;
  470. }
  471. public function serialize()
  472. {
  473. return serialize([
  474. $this->id,
  475. $this->username,
  476. $this->password,
  477. $this->roles,
  478. $this->email,
  479. $this->created_at,
  480. $this->updated_at,
  481. $this->last_login,
  482. //$this->contacts,
  483. $this->emails,
  484. //$this->campaigns,
  485. //$this->contactGroups,
  486. $this->website,
  487. $this->company,
  488. $this->logo
  489. ]);
  490. }
  491. public function unserialize($serialized)
  492. {
  493. list(
  494. $this->id,
  495. $this->username,
  496. $this->password,
  497. $this->roles,
  498. $this->email,
  499. $this->created_at,
  500. $this->updated_at,
  501. $this->last_login,
  502. //$this->contacts,
  503. $this->emails,
  504. //$this->campaigns,
  505. //$this->contactGroups,
  506. $this->website,
  507. $this->company,
  508. $this->logo
  509. ) = unserialize($serialized);
  510. }
  511. public function getAddress(): ?string
  512. {
  513. return $this->address;
  514. }
  515. public function setAddress(string $address): self
  516. {
  517. $this->address = $address;
  518. return $this;
  519. }
  520. public function getFromAddress(): ?string
  521. {
  522. return $this->from_address;
  523. }
  524. public function setFromAddress(string $from_address): self
  525. {
  526. $this->from_address = $from_address;
  527. return $this;
  528. }
  529. /**
  530. * @return Collection|ApiToken[]
  531. */
  532. public function getApiTokens(): Collection
  533. {
  534. return $this->apiTokens;
  535. }
  536. public function addApiToken(ApiToken $apiToken): self
  537. {
  538. if (!$this->apiTokens->contains($apiToken)) {
  539. $this->apiTokens[] = $apiToken;
  540. $apiToken->setUser($this);
  541. }
  542. return $this;
  543. }
  544. public function removeApiToken(ApiToken $apiToken): self
  545. {
  546. if ($this->apiTokens->contains($apiToken)) {
  547. $this->apiTokens->removeElement($apiToken);
  548. // set the owning side to null (unless already changed)
  549. if ($apiToken->getUser() === $this) {
  550. $apiToken->setUser(null);
  551. }
  552. }
  553. return $this;
  554. }
  555. /**
  556. * @return Collection|Form[]
  557. */
  558. public function getForms(): Collection
  559. {
  560. return $this->forms;
  561. }
  562. public function addForm(Form $form): self
  563. {
  564. if (!$this->forms->contains($form)) {
  565. $this->forms[] = $form;
  566. $form->setUser($this);
  567. }
  568. return $this;
  569. }
  570. public function removeForm(Form $form): self
  571. {
  572. if ($this->forms->contains($form)) {
  573. $this->forms->removeElement($form);
  574. // set the owning side to null (unless already changed)
  575. if ($form->getUser() === $this) {
  576. $form->setUser(null);
  577. }
  578. }
  579. return $this;
  580. }
  581. public function getSendCount(): ?array
  582. {
  583. if(is_array($this->send_count) && count($this->send_count) === 31){
  584. return $this->send_count;
  585. } else {
  586. return [];
  587. }
  588. }
  589. public function resetSendCount(): self
  590. {
  591. $sendCount = array();
  592. for($i = 0; $i < 31; $i++){
  593. $sendCount[] = 0;
  594. }
  595. $this->setSendCount($sendCount);
  596. return $this;
  597. }
  598. public function setSendCount(array $send_count): self
  599. {
  600. $this->send_count = $send_count;
  601. return $this;
  602. }
  603. public function getPlan(): ?Plan
  604. {
  605. return $this->plan;
  606. }
  607. public function setPlan(?Plan $plan): self
  608. {
  609. $this->plan = $plan;
  610. return $this;
  611. }
  612. public function updatePlan(?Plan $plan): self
  613. {
  614. /** @var Plan $currentPlan */
  615. $currentPlan = $this->plan;
  616. // if upgrade
  617. if ($plan->getMonthlyLimit() > $currentPlan->getMonthlyLimit()) {
  618. $this->plan = $plan;
  619. } else {
  620. // TODO if downgrade, only change plan at the end of plan cycle?
  621. $this->plan = $plan;
  622. }
  623. return $this;
  624. }
  625. public function increaseSendCount(int $add = 1): self
  626. {
  627. // Get daily counts array
  628. $sendCount = $this->getSendCount();
  629. // Get last element of send count, increase count and put it back in array
  630. $latestCount = array_pop($sendCount);
  631. $sendCount[] = $latestCount + $add;
  632. $this->setSendCount($sendCount);
  633. return $this;
  634. }
  635. public function sendingAllowanceBalanced(): array
  636. {
  637. $allowance = array();
  638. $plan = $this->getPlan();
  639. $sendCount = $this->getSendCount();
  640. if($plan->getDailyLimit() != 0){
  641. $dayCount = $sendCount[count($sendCount) - 1];
  642. $allowance['day'] = $dayAllowance = $plan->getDailyLimit() - $dayCount;
  643. }
  644. if($plan->getWeeklyLimit() != 0){
  645. $i = count($sendCount) - 1;
  646. $weekCount = 0;
  647. while($i >= count($sendCount) - 7){
  648. $weekCount += $sendCount[$i];
  649. $i--;
  650. }
  651. $allowance['week'] = $weekAllowance = $plan->getWeeklyLimit() - $weekCount;
  652. }
  653. if($plan->getMonthlyLimit() != 0){
  654. // Get number of days to this day the last month
  655. $today = new \DateTime();
  656. $monthAgo = new \DateTime();
  657. $monthAgo->sub(new \DateInterval('P1M'));
  658. $diff = date_diff($today, $monthAgo);
  659. $monthDays = $diff->days;
  660. $i = count($sendCount) - 1;
  661. $monthCount = 0;
  662. while($i >= count($sendCount) - $monthDays){
  663. $monthCount += $sendCount[$i];
  664. $i--;
  665. }
  666. $allowance['month'] = $monthAllowance = $plan->getMonthlyLimit() - $monthCount;
  667. }
  668. return $allowance;
  669. }
  670. public function sendingAllowanceCyclic(): array
  671. {
  672. $allowance = array();
  673. $plan = $this->getPlan();
  674. $sendCount = $this->getSendCount();
  675. $baseDate = $this->getCreatedAt();
  676. $now = new \DateTime();
  677. $baseDate->setTime(0,0);
  678. $now->setTime(0,0);
  679. $diff = $baseDate->diff($now);
  680. if($plan->getDailyLimit() != 0){
  681. $dayCount = $sendCount[count($sendCount) - 1];
  682. $allowance['day'] = $dayAllowance = $plan->getDailyLimit() - $dayCount;
  683. }
  684. if($plan->getWeeklyLimit() != 0){
  685. $i = count($sendCount) - 1;
  686. $weekCount = 0;
  687. while($i >= count($sendCount) - ($diff->days % 7)){
  688. $weekCount += $sendCount[$i];
  689. $i--;
  690. }
  691. $allowance['week'] = $weekAllowance = $plan->getWeeklyLimit() - $weekCount;
  692. }
  693. if($plan->getMonthlyLimit() != 0){
  694. $i = count($sendCount) - 1;
  695. $monthCount = 0;
  696. while($i >= count($sendCount) - ($diff->d)){
  697. $monthCount += $sendCount[$i];
  698. $i--;
  699. }
  700. $allowance['month'] = $monthAllowance = $plan->getMonthlyLimit() - $monthCount;
  701. }
  702. return $allowance;
  703. }
  704. public function sendingAllowanceCyclicDates(): array
  705. {
  706. $allowanceDates = array();
  707. $plan = $this->getPlan();
  708. $sendCount = $this->getSendCount();
  709. $baseDate = $this->getCreatedAt();
  710. $now = new \DateTime();
  711. $baseDate->setTime(0,0);
  712. $now->setTime(0,0);
  713. $diff = $baseDate->diff($now);
  714. if($plan->getDailyLimit() != 0){
  715. $dayDate = clone $now;
  716. $allowanceDates['day'] = $dayDate->add(new \DateInterval('P1D'));
  717. }
  718. if($plan->getWeeklyLimit() != 0){
  719. $weekDate = clone $now;
  720. $allowanceDates['week'] = $weekDate->add(new \DateInterval('P' . (7 - ($diff->days % 7)) . 'D'));
  721. }
  722. if($plan->getMonthlyLimit() != 0){
  723. $monthDate = clone $now;
  724. $allowanceDates['month'] = $monthDate->sub(new \DateInterval('P' . $diff->d . 'D'))->add(new \DateInterval('P1M'));
  725. }
  726. return $allowanceDates;
  727. }
  728. /**
  729. * @return Collection|Task[]
  730. */
  731. public function getTasks(): Collection
  732. {
  733. return $this->tasks;
  734. }
  735. /**
  736. * @return Collection|Task[]
  737. */
  738. public function getTasksNotUnfreeze(): Collection
  739. {
  740. return $this->tasks->filter(function (Task $task){
  741. return $task->getType() != Task::TYPE_CAMPAIGN_UNFREEZE;
  742. });
  743. }
  744. /**
  745. * @return Collection|Task[]
  746. */
  747. public function getPendingTasks(): Collection
  748. {
  749. return $this->tasks->filter(function (Task $task) {
  750. return !$task->isFinished();
  751. });
  752. }
  753. /**
  754. * @return Collection|Task[]
  755. */
  756. public function getPendingTasksNotUnfreeze(): Collection
  757. {
  758. return $this->tasks->filter(function (Task $task) {
  759. return !$task->isFinished() && $task->getType() != Task::TYPE_CAMPAIGN_UNFREEZE;
  760. });
  761. }
  762. /**
  763. * @return Collection|Task[]
  764. */
  765. public function getFinishedTasks(): Collection
  766. {
  767. return $this->tasks->filter(function (Task $task){
  768. return $task->isFinished();
  769. });
  770. }
  771. /**
  772. * @return Collection|Task[]
  773. */
  774. public function getFinishedTasksNotUnfreeze(): Collection
  775. {
  776. return $this->tasks->filter(function (Task $task){
  777. return $task->isFinished() && $task->getType() != Task::TYPE_CAMPAIGN_UNFREEZE;
  778. });
  779. }
  780. public function addTask(Task $task): self
  781. {
  782. if (!$this->tasks->contains($task)) {
  783. $this->tasks[] = $task;
  784. $task->setUser($this);
  785. }
  786. return $this;
  787. }
  788. public function removeTask(Task $task): self
  789. {
  790. if ($this->tasks->contains($task)) {
  791. $this->tasks->removeElement($task);
  792. // set the owning side to null (unless already changed)
  793. if ($task->getUser() === $this) {
  794. $task->setUser(null);
  795. }
  796. }
  797. return $this;
  798. }
  799. /**
  800. * @return Collection|Notification[]
  801. */
  802. public function getNotifications(): Collection
  803. {
  804. return $this->notifications;
  805. }
  806. public function addNotification(Notification $notification): self
  807. {
  808. if (!$this->notifications->contains($notification)) {
  809. $this->notifications[] = $notification;
  810. $notification->setUser($this);
  811. }
  812. return $this;
  813. }
  814. public function removeNotification(Notification $notification): self
  815. {
  816. if ($this->notifications->contains($notification)) {
  817. $this->notifications->removeElement($notification);
  818. // set the owning side to null (unless already changed)
  819. if ($notification->getUser() === $this) {
  820. $notification->setUser(null);
  821. }
  822. }
  823. return $this;
  824. }
  825. /**
  826. * @return Collection|EmailTemplate[]
  827. */
  828. public function getEmailTemplates(?bool $publishedOnly, ?string $version): Collection
  829. {
  830. $emailTemplates = $this->emailTemplates;
  831. if ($publishedOnly === true) $emailTemplates = $emailTemplates->matching(EmailTemplateRepository::isPublishedCriteria());
  832. if (isset($version)) $emailTemplates = $emailTemplates->matching(EmailTemplateRepository::editorVersionCriteria($version));
  833. return $emailTemplates;
  834. }
  835. public function addEmailTemplate(EmailTemplate $emailTemplate): self
  836. {
  837. if (!$this->emailTemplates->contains($emailTemplate)) {
  838. $this->emailTemplates[] = $emailTemplate;
  839. $emailTemplate->setUser($this);
  840. }
  841. return $this;
  842. }
  843. public function removeEmailTemplate(EmailTemplate $emailTemplate): self
  844. {
  845. if ($this->emailTemplates->contains($emailTemplate)) {
  846. $this->emailTemplates->removeElement($emailTemplate);
  847. // set the owning side to null (unless already changed)
  848. if ($emailTemplate->getUser() === $this) {
  849. $emailTemplate->setUser(null);
  850. }
  851. }
  852. return $this;
  853. }
  854. /**
  855. * @return Collection|Upload[]
  856. */
  857. public function getUploads(): Collection
  858. {
  859. return $this->uploads;
  860. }
  861. public function addUpload(Upload $upload): self
  862. {
  863. if (!$this->uploads->contains($upload)) {
  864. $this->uploads[] = $upload;
  865. $upload->setUser($this);
  866. }
  867. return $this;
  868. }
  869. public function removeUpload(Upload $upload): self
  870. {
  871. if ($this->uploads->contains($upload)) {
  872. $this->uploads->removeElement($upload);
  873. // set the owning side to null (unless already changed)
  874. if ($upload->getUser() === $this) {
  875. $upload->setUser(null);
  876. }
  877. }
  878. return $this;
  879. }
  880. public function getStatus(): ?string
  881. {
  882. return $this->status;
  883. }
  884. public function setStatus(string $status): self
  885. {
  886. $this->status = $status;
  887. return $this;
  888. }
  889. /**
  890. * @return Collection|Domain[]
  891. */
  892. public function getDomains(): Collection
  893. {
  894. return $this->domains;
  895. }
  896. public function addDomain(Domain $domain): self
  897. {
  898. if (!$this->domains->contains($domain)) {
  899. $this->domains[] = $domain;
  900. $domain->setUser($this);
  901. }
  902. return $this;
  903. }
  904. public function removeDomain(Domain $domain): self
  905. {
  906. if ($this->domains->removeElement($domain)) {
  907. // set the owning side to null (unless already changed)
  908. if ($domain->getUser() === $this) {
  909. $domain->setUser(null);
  910. }
  911. }
  912. return $this;
  913. }
  914. public function getCustomFields(): ?CustomFields
  915. {
  916. return $this->customFields;
  917. }
  918. public function setCustomFields(CustomFields $customFields): self
  919. {
  920. // set the owning side of the relation if necessary
  921. if ($customFields->getUser() !== $this) {
  922. $customFields->setUser($this);
  923. }
  924. $this->customFields = $customFields;
  925. return $this;
  926. }
  927. /**
  928. * @return Collection<int, Addon>
  929. */
  930. public function getAddons(): Collection
  931. {
  932. return $this->addons;
  933. }
  934. /**
  935. * @return $this
  936. */
  937. public function clearAddons() : self
  938. {
  939. $this->addons->clear();
  940. return $this;
  941. }
  942. public function addAddon(Addon $addon): self
  943. {
  944. if (!$this->addons->contains($addon)) {
  945. $this->addons[] = $addon;
  946. }
  947. return $this;
  948. }
  949. public function removeAddon(Addon $addon): self
  950. {
  951. $this->addons->removeElement($addon);
  952. return $this;
  953. }
  954. public function hasAddon($addon) : bool
  955. {
  956. if ($addon instanceof Addon) {
  957. return $this->addons->contains($addon);
  958. } else {
  959. foreach ($this->addons as $userAddon) {
  960. if ($userAddon->getName() === $addon) {
  961. return true;
  962. }
  963. }
  964. return false;
  965. }
  966. }
  967. }