NoteRepeat.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Plugin\RepeatNote\Entity;
  20. use App\Core\DB\DB;
  21. use App\Core\Entity;
  22. use App\Entity\Note;
  23. /**
  24. * Entity for notices
  25. *
  26. * @category DB
  27. * @package GNUsocial
  28. *
  29. * @author Eliseu Amaro <mail@eliseuama.ro>
  30. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  31. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  32. */
  33. class NoteRepeat extends Entity
  34. {
  35. private int $note_id;
  36. private int $actor_id;
  37. private int $repeat_of;
  38. public function setNoteId(int $note_id): self
  39. {
  40. $this->note_id = $note_id;
  41. return $this;
  42. }
  43. public function getNoteId(): int
  44. {
  45. return $this->note_id;
  46. }
  47. public function setActorId(int $actor_id): self
  48. {
  49. $this->actor_id = $actor_id;
  50. return $this;
  51. }
  52. public function getActorId(): ?int
  53. {
  54. return $this->actor_id;
  55. }
  56. public function setRepeatOf(int $repeat_of): self
  57. {
  58. $this->repeat_of = $repeat_of;
  59. return $this;
  60. }
  61. public function getRepeatOf(): int
  62. {
  63. return $this->repeat_of;
  64. }
  65. public static function getNoteRepeats(Note $note): array
  66. {
  67. return DB::sql(
  68. <<<'EOF'
  69. select {select} from note n
  70. inner join note_repeat nr
  71. on nr.note_id = n.id
  72. where repeat_of = :note_id
  73. order by n.created DESC
  74. EOF,
  75. ['note_id' => $note->getId()]
  76. );
  77. }
  78. public static function schemaDef(): array
  79. {
  80. return [
  81. 'name' => 'note_repeat',
  82. 'fields' => [
  83. 'note_id' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'The id of the repeat itself'],
  84. 'actor_id' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'description' => 'Who made this repeat'],
  85. 'repeat_of' => ['type' => 'int', 'not null' => true, 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'Note this is a repeat of'],
  86. ],
  87. 'primary key' => ['note_id'],
  88. 'foreign keys' => [
  89. 'note_id_to_id_fkey' => ['note', ['note_id' => 'id']],
  90. 'note_repeat_of_id_fkey' => ['note', ['repeat_of' => 'id']],
  91. 'actor_reply_to_id_fkey' => ['actor', ['actor_id' => 'id']],
  92. ],
  93. 'indexes' => [
  94. 'note_repeat_of_idx' => ['repeat_of'],
  95. ],
  96. ];
  97. }
  98. }