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