ActivitypubActivity.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /**
  20. * ActivityPub implementation for GNU social
  21. *
  22. * @package GNUsocial
  23. * @category ActivityPub
  24. *
  25. * @author Diogo Peralta Cordeiro <@diogo.site>
  26. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  27. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  28. */
  29. namespace Plugin\ActivityPub\Entity;
  30. use App\Core\DB\DB;
  31. use App\Core\Entity;
  32. use App\Entity\Activity;
  33. use DateTimeInterface;
  34. /**
  35. * Table Definition for activitypub_activity
  36. *
  37. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  38. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  39. */
  40. class ActivitypubActivity extends Entity
  41. {
  42. // {{{ Autocode
  43. // @codeCoverageIgnoreStart
  44. private int $activity_id;
  45. private string $activity_uri;
  46. private DateTimeInterface $created;
  47. private DateTimeInterface $modified;
  48. public function setActivityId(int $activity_id): self
  49. {
  50. $this->activity_id = $activity_id;
  51. return $this;
  52. }
  53. public function getActivityId(): int
  54. {
  55. return $this->activity_id;
  56. }
  57. public function setActivityUri(string $activity_uri): self
  58. {
  59. $this->activity_uri = $activity_uri;
  60. return $this;
  61. }
  62. public function getActivityUri(): string
  63. {
  64. return $this->activity_uri;
  65. }
  66. public function setCreated(DateTimeInterface $created): self
  67. {
  68. $this->created = $created;
  69. return $this;
  70. }
  71. public function getCreated(): DateTimeInterface
  72. {
  73. return $this->created;
  74. }
  75. public function setModified(DateTimeInterface $modified): self
  76. {
  77. $this->modified = $modified;
  78. return $this;
  79. }
  80. public function getModified(): DateTimeInterface
  81. {
  82. return $this->modified;
  83. }
  84. // @codeCoverageIgnoreEnd
  85. // }}} Autocode
  86. public function getActivity(): Activity
  87. {
  88. return DB::findOneBy('activity', ['id' => $this->getActivityId()]);
  89. }
  90. public static function schemaDef(): array
  91. {
  92. return [
  93. 'name' => 'activitypub_activity',
  94. 'fields' => [
  95. 'activity_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Activity.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'activity_id to give attention'],
  96. 'activity_uri' => ['type' => 'text', 'not null' => true, 'description' => 'Activity\'s URI'],
  97. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  98. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  99. ],
  100. 'primary key' => ['activity_uri'],
  101. 'indexes' => [
  102. 'activity_activity_uri_idx' => ['activity_uri'],
  103. ],
  104. ];
  105. }
  106. }