Attention.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\Notification\Entity;
  20. use App\Core\Entity;
  21. /**
  22. * Entity for object attentions
  23. *
  24. * An attention is a form of persistent notification.
  25. * It exists together and for as long as the object it belongs to.
  26. * Creating an attention requires creating a Notification.
  27. *
  28. * @category DB
  29. * @package GNUsocial
  30. *
  31. * @author Zach Copley <zach@status.net>
  32. * @copyright 2010 StatusNet Inc.
  33. * @author Mikael Nordfeldth <mmn@hethane.se>
  34. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  35. * @author Diogo Peralta Cordeiro <@diogo.site>
  36. * @copyright 2021-2022 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 Attention extends Entity
  40. {
  41. // {{{ Autocode
  42. // @codeCoverageIgnoreStart
  43. private string $object_type;
  44. private int $object_id;
  45. private int $target_id;
  46. public function setObjectType(string $object_type): self
  47. {
  48. $this->object_type = mb_substr($object_type, 0, 32);
  49. return $this;
  50. }
  51. public function getObjectType(): string
  52. {
  53. return $this->object_type;
  54. }
  55. public function setObjectId(int $object_id): self
  56. {
  57. $this->object_id = $object_id;
  58. return $this;
  59. }
  60. public function getObjectId(): int
  61. {
  62. return $this->object_id;
  63. }
  64. public function setTargetId(int $target_id): self
  65. {
  66. $this->target_id = $target_id;
  67. return $this;
  68. }
  69. public function getTargetId(): int
  70. {
  71. return $this->target_id;
  72. }
  73. // @codeCoverageIgnoreEnd
  74. // }}} Autocode
  75. public static function schemaDef(): array
  76. {
  77. return [
  78. 'name' => 'attention',
  79. 'description' => 'Attentions to actors (these are not mentions)',
  80. 'fields' => [
  81. 'object_type' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'the name of the table this object refers to'],
  82. 'object_id' => ['type' => 'int', 'not null' => true, 'description' => 'id in the referenced table'],
  83. 'target_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor_id for feed receiver'],
  84. ],
  85. 'primary key' => ['object_type', 'object_id', 'target_id'],
  86. 'indexes' => [
  87. 'attention_object_id_idx' => ['object_id'],
  88. 'attention_target_id_idx' => ['target_id'],
  89. ],
  90. ];
  91. }
  92. }