Conversation.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Component\Conversation\Entity;
  20. use App\Core\DB\DB;
  21. use App\Core\Entity;
  22. use App\Core\Router\Router;
  23. use App\Entity\Note;
  24. /**
  25. * Entity class for Conversations
  26. *
  27. * @category DB
  28. * @package GNUsocial
  29. *
  30. * @author Zach Copley <zach@status.net>
  31. * @author Mikael Nordfeldth <mmn@hethane.se>
  32. * @copyright 2010 StatusNet Inc.
  33. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  34. * @author Hugo Sales <hugo@hsal.es>
  35. * @author Eliseu Amaro <mail@eliseuama.ro>
  36. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class Conversation extends Entity
  40. {
  41. // {{{ Autocode
  42. // @codeCoverageIgnoreStart
  43. private int $id;
  44. private int $initial_note_id;
  45. public function setId(int $id): self
  46. {
  47. $this->id = $id;
  48. return $this;
  49. }
  50. public function getId(): int
  51. {
  52. return $this->id;
  53. }
  54. public function setInitialNoteId(int $initial_note_id): self
  55. {
  56. $this->initial_note_id = $initial_note_id;
  57. return $this;
  58. }
  59. public function getInitialNoteId(): int
  60. {
  61. return $this->initial_note_id;
  62. }
  63. // @codeCoverageIgnoreEnd
  64. // }}} Autocode
  65. public function getUrl(int $type = Router::ABSOLUTE_URL): string
  66. {
  67. return Router::url('conversation', ['conversation_id' => $this->getId()], $type);
  68. }
  69. public function getUri(): string
  70. {
  71. return $this->getUrl(type: Router::ABSOLUTE_URL);
  72. }
  73. public static function schemaDef(): array
  74. {
  75. return [
  76. 'name' => 'conversation',
  77. 'fields' => [
  78. 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'Serial identifier, since any additional meaning would require updating its value for every reply upon receiving a new aparent root'],
  79. 'initial_note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'Initial note seen on this host for this conversation'],
  80. ],
  81. 'primary key' => ['id'],
  82. 'foreign keys' => [
  83. 'initial_note_id_to_id_fkey' => ['note', ['initial_note_id' => 'id']],
  84. ],
  85. ];
  86. }
  87. }