ActorToAttachment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\Attachment\Entity;
  20. use App\Core\DB\DB;
  21. use App\Core\Entity;
  22. use DateTimeInterface;
  23. /**
  24. * Entity for relating an actor to an attachment
  25. *
  26. * @category DB
  27. * @package GNUsocial
  28. *
  29. * @author Diogo Peralta Cordeiro <mail@diogo.site>
  30. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  31. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  32. */
  33. class ActorToAttachment extends Entity
  34. {
  35. // {{{ Autocode
  36. // @codeCoverageIgnoreStart
  37. private int $attachment_id;
  38. private int $actor_id;
  39. private DateTimeInterface $modified;
  40. public function setAttachmentId(int $attachment_id): self
  41. {
  42. $this->attachment_id = $attachment_id;
  43. return $this;
  44. }
  45. public function getAttachmentId(): int
  46. {
  47. return $this->attachment_id;
  48. }
  49. public function setActorId(int $actor_id): self
  50. {
  51. $this->actor_id = $actor_id;
  52. return $this;
  53. }
  54. public function getActorId(): int
  55. {
  56. return $this->actor_id;
  57. }
  58. public function setModified(DateTimeInterface $modified): self
  59. {
  60. $this->modified = $modified;
  61. return $this;
  62. }
  63. public function getModified(): DateTimeInterface
  64. {
  65. return $this->modified;
  66. }
  67. // @codeCoverageIgnoreEnd
  68. // }}} Autocode
  69. public static function removeWhereAttachmentId(int $attachment_id): mixed
  70. {
  71. return DB::dql(
  72. <<<'EOF'
  73. DELETE FROM actor_to_attachment ata
  74. WHERE ata.attachment_id = :attachment_id
  75. EOF,
  76. ['attachment_id' => $attachment_id],
  77. );
  78. }
  79. public static function removeWhere(int $attachment_id, int $actor_id): mixed
  80. {
  81. return DB::dql(
  82. <<<'EOF'
  83. DELETE FROM actor_to_attachment ata
  84. WHERE (ata.attachment_id = :attachment_id
  85. OR ata.actor_id = :actor_id)
  86. EOF,
  87. ['attachment_id' => $attachment_id, 'actor_id' => $actor_id],
  88. );
  89. }
  90. public static function removeWhereActorId(int $actor_id): mixed
  91. {
  92. return DB::dql(
  93. <<<'EOF'
  94. DELETE FROM actor_to_attachment ata
  95. WHERE ata.actor_id = :actor_id
  96. EOF,
  97. ['actor_id' => $actor_id],
  98. );
  99. }
  100. public static function schemaDef(): array
  101. {
  102. return [
  103. 'name' => 'actor_to_attachment',
  104. 'fields' => [
  105. 'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'name' => 'attachment_to_note_attachment_id_fkey', 'not null' => true, 'description' => 'id of attachment'],
  106. 'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'name' => 'attachment_to_note_note_id_fkey', 'not null' => true, 'description' => 'id of the note it belongs to'],
  107. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  108. ],
  109. 'primary key' => ['attachment_id', 'actor_id'],
  110. 'indexes' => [
  111. 'attachment_id_idx' => ['attachment_id'],
  112. 'actor_id_idx' => ['actor_id'],
  113. ],
  114. ];
  115. }
  116. }