ActorSubscription.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Component\Subscription\Entity;
  20. use App\Core\Entity;
  21. use App\Entity\Actor;
  22. use App\Entity\LocalUser;
  23. use Component\Group\Entity\LocalGroup;
  24. use DateTimeInterface;
  25. /**
  26. * Entity for subscription
  27. *
  28. * @category DB
  29. * @package GNUsocial
  30. *
  31. * @author Zach Copley <zach@status.net>
  32. * @copyright 2010 StatusNet Inc.
  33. * @author Mikael Nordfeldth <mmn@hethane.se>
  34. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  35. * @author Hugo Sales <hugo@hsal.es>
  36. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class ActorSubscription extends Entity
  40. {
  41. // {{{ Autocode
  42. // @codeCoverageIgnoreStart
  43. private int $subscriber_id;
  44. private int $subscribed_id;
  45. private DateTimeInterface $created;
  46. private DateTimeInterface $modified;
  47. public function setSubscriberId(int $subscriber_id): self
  48. {
  49. $this->subscriber_id = $subscriber_id;
  50. return $this;
  51. }
  52. public function getSubscriberId(): int
  53. {
  54. return $this->subscriber_id;
  55. }
  56. public function setSubscribedId(int $subscribed_id): self
  57. {
  58. $this->subscribed_id = $subscribed_id;
  59. return $this;
  60. }
  61. public function getSubscribedId(): int
  62. {
  63. return $this->subscribed_id;
  64. }
  65. public function setCreated(DateTimeInterface $created): self
  66. {
  67. $this->created = $created;
  68. return $this;
  69. }
  70. public function getCreated(): DateTimeInterface
  71. {
  72. return $this->created;
  73. }
  74. public function setModified(DateTimeInterface $modified): self
  75. {
  76. $this->modified = $modified;
  77. return $this;
  78. }
  79. public function getModified(): DateTimeInterface
  80. {
  81. return $this->modified;
  82. }
  83. // @codeCoverageIgnoreEnd
  84. // }}} Autocode
  85. public function getSubscriber(): Actor
  86. {
  87. return Actor::getById($this->getSubscriberId());
  88. }
  89. public function getSubscribed(): Actor
  90. {
  91. return Actor::getById($this->getSubscribedId());
  92. }
  93. public static function cacheKeys(LocalUser|LocalGroup|Actor $subject, LocalUser|LocalGroup|Actor $target): array
  94. {
  95. return [
  96. 'subscribed' => "subscription-{$subject->getId()}-{$target->getId()}",
  97. ];
  98. }
  99. public static function schemaDef(): array
  100. {
  101. return [
  102. 'name' => 'actor_subscription',
  103. 'fields' => [
  104. 'subscriber_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'name' => 'subscription_subscriber_fkey', 'not null' => true, 'description' => 'actor listening'],
  105. 'subscribed_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'name' => 'subscription_subscribed_fkey', 'not null' => true, 'description' => 'actor being listened to'],
  106. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  107. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  108. ],
  109. 'primary key' => ['subscriber_id', 'subscribed_id'],
  110. 'indexes' => [
  111. 'subscription_subscriber_idx' => ['subscriber_id', 'created'],
  112. 'subscription_subscribed_idx' => ['subscribed_id', 'created'],
  113. ],
  114. ];
  115. }
  116. }