Favourite.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace Plugin\Favourite\Entity;
  19. use App\Core\Entity;
  20. use DateTimeInterface;
  21. class Favourite extends Entity
  22. {
  23. // {{{ Autocode
  24. // @codeCoverageIgnoreStart
  25. private int $note_id;
  26. private int $gsactor_id;
  27. private \DateTimeInterface $created;
  28. private \DateTimeInterface $modified;
  29. public function setNoteId(int $note_id): self
  30. {
  31. $this->note_id = $note_id;
  32. return $this;
  33. }
  34. public function getNoteId(): int
  35. {
  36. return $this->note_id;
  37. }
  38. public function setGSActorId(int $gsactor_id): self
  39. {
  40. $this->gsactor_id = $gsactor_id;
  41. return $this;
  42. }
  43. public function getGSActorId(): int
  44. {
  45. return $this->gsactor_id;
  46. }
  47. public function setCreated(DateTimeInterface $created): self
  48. {
  49. $this->created = $created;
  50. return $this;
  51. }
  52. public function getCreated(): DateTimeInterface
  53. {
  54. return $this->created;
  55. }
  56. public function setModified(DateTimeInterface $modified): self
  57. {
  58. $this->modified = $modified;
  59. return $this;
  60. }
  61. public function getModified(): DateTimeInterface
  62. {
  63. return $this->modified;
  64. }
  65. // @codeCoverageIgnoreEnd
  66. // }}} Autocode
  67. public static function schemaDef()
  68. {
  69. return [
  70. 'name' => 'favourite',
  71. 'fields' => [
  72. 'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'note that is the favorite of'],
  73. 'gsactor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor who favourited this note'], // note: formerly referenced notice.id, but we can now record remote users' favorites
  74. 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
  75. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  76. ],
  77. 'primary key' => ['note_id', 'gsactor_id'],
  78. 'indexes' => [
  79. 'fave_note_id_idx' => ['note_id'],
  80. 'fave_actor_id_idx' => ['gsactor_id', 'modified'],
  81. 'fave_modified_idx' => ['modified'],
  82. ],
  83. ];
  84. }
  85. }