Favourite.php 3.1 KB

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