Нет описания

NewsletterLinkEntity.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace MailPoet\Entities;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait;
  5. use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
  6. use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
  7. use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
  8. use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
  9. use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
  10. /**
  11. * @ORM\Entity()
  12. * @ORM\Table(name="newsletter_links")
  13. */
  14. class NewsletterLinkEntity {
  15. use AutoincrementedIdTrait;
  16. use CreatedAtTrait;
  17. use UpdatedAtTrait;
  18. use SafeToOneAssociationLoadTrait;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="MailPoet\Entities\NewsletterEntity")
  21. * @ORM\JoinColumn(name="newsletter_id", referencedColumnName="id")
  22. * @var NewsletterEntity|null
  23. */
  24. private $newsletter;
  25. /**
  26. * @ORM\ManyToOne(targetEntity="MailPoet\Entities\SendingQueueEntity")
  27. * @ORM\JoinColumn(name="queue_id", referencedColumnName="id")
  28. * @var SendingQueueEntity|null
  29. */
  30. private $queue;
  31. /**
  32. * @ORM\Column(type="string")
  33. * @var string
  34. */
  35. private $url;
  36. /**
  37. * @ORM\Column(type="string")
  38. * @var string
  39. */
  40. private $hash;
  41. /**
  42. * Extra lazy is here for `getTotalClicksCount`.
  43. * If we didn't specify extra lazy the function would load all clicks and count them. This way it uses a single count query.
  44. * @ORM\OneToMany(targetEntity="MailPoet\Entities\StatisticsClickEntity", mappedBy="link", fetch="EXTRA_LAZY")
  45. *
  46. * @var ArrayCollection<int, StatisticsClickEntity>
  47. */
  48. private $clicks;
  49. public function __construct(
  50. NewsletterEntity $newsletter,
  51. SendingQueueEntity $queue,
  52. string $url,
  53. string $hash
  54. ) {
  55. $this->newsletter = $newsletter;
  56. $this->queue = $queue;
  57. $this->url = $url;
  58. $this->hash = $hash;
  59. }
  60. /**
  61. * @return NewsletterEntity|null
  62. */
  63. public function getNewsletter() {
  64. $this->safelyLoadToOneAssociation('newsletter');
  65. return $this->newsletter;
  66. }
  67. /**
  68. * @return SendingQueueEntity|null
  69. */
  70. public function getQueue() {
  71. $this->safelyLoadToOneAssociation('queue');
  72. return $this->queue;
  73. }
  74. public function getUrl(): string {
  75. return $this->url;
  76. }
  77. public function getHash(): string {
  78. return $this->hash;
  79. }
  80. /**
  81. * @return int
  82. */
  83. public function getTotalClicksCount() {
  84. return $this->clicks->count();
  85. }
  86. }