Favourite.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Favourite\Entity;
  20. use App\Core\Entity;
  21. use DateTimeInterface;
  22. class Favourite extends Entity
  23. {
  24. // {{{ Autocode
  25. // @codeCoverageIgnoreStart
  26. private int $note_id;
  27. private int $actor_id;
  28. private DateTimeInterface $created;
  29. private DateTimeInterface $modified;
  30. public function setNoteId(int $note_id): self
  31. {
  32. $this->note_id = $note_id;
  33. return $this;
  34. }
  35. public function getNoteId(): int
  36. {
  37. return $this->note_id;
  38. }
  39. public function setActorId(int $actor_id): self
  40. {
  41. $this->actor_id = $actor_id;
  42. return $this;
  43. }
  44. public function getActorId(): int
  45. {
  46. return $this->actor_id;
  47. }
  48. public function setCreated(DateTimeInterface $created): self
  49. {
  50. $this->created = $created;
  51. return $this;
  52. }
  53. public function getCreated(): DateTimeInterface
  54. {
  55. return $this->created;
  56. }
  57. public function setModified(DateTimeInterface $modified): self
  58. {
  59. $this->modified = $modified;
  60. return $this;
  61. }
  62. public function getModified(): DateTimeInterface
  63. {
  64. return $this->modified;
  65. }
  66. // @codeCoverageIgnoreEnd
  67. // }}} Autocode
  68. public static function schemaDef()
  69. {
  70. return [
  71. 'name' => 'favourite',
  72. 'fields' => [
  73. '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'],
  74. 'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'App\Entity\Actor.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
  75. 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
  76. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  77. ],
  78. 'primary key' => ['note_id', 'actor_id'],
  79. 'indexes' => [
  80. 'fave_note_id_idx' => ['note_id'],
  81. 'fave_actor_id_idx' => ['actor_id', 'modified'],
  82. 'fave_modified_idx' => ['modified'],
  83. ],
  84. ];
  85. }
  86. }