GroupMember.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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\Group\Entity;
  20. use App\Core\Entity;
  21. use DateTimeInterface;
  22. /**
  23. * Entity for a Group Member
  24. *
  25. * @category DB
  26. * @package GNUsocial
  27. *
  28. * @author Zach Copley <zach@status.net>
  29. * @copyright 2010 StatusNet Inc.
  30. * @author Mikael Nordfeldth <mmn@hethane.se>
  31. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  32. * @author Hugo Sales <hugo@hsal.es>
  33. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  34. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  35. */
  36. class GroupMember extends Entity
  37. {
  38. // {{{ Autocode
  39. // @codeCoverageIgnoreStart
  40. private int $group_id;
  41. private int $actor_id;
  42. private ?bool $is_admin = false;
  43. private ?string $uri = null;
  44. private DateTimeInterface $created;
  45. private DateTimeInterface $modified;
  46. public function setGroupId(int $group_id): self
  47. {
  48. $this->group_id = $group_id;
  49. return $this;
  50. }
  51. public function getGroupId(): int
  52. {
  53. return $this->group_id;
  54. }
  55. public function setActorId(int $actor_id): self
  56. {
  57. $this->actor_id = $actor_id;
  58. return $this;
  59. }
  60. public function getActorId(): int
  61. {
  62. return $this->actor_id;
  63. }
  64. public function setIsAdmin(?bool $is_admin): self
  65. {
  66. $this->is_admin = $is_admin;
  67. return $this;
  68. }
  69. public function getIsAdmin(): ?bool
  70. {
  71. return $this->is_admin;
  72. }
  73. public function setUri(?string $uri): self
  74. {
  75. $this->uri = \is_null($uri) ? null : mb_substr($uri, 0, 191);
  76. return $this;
  77. }
  78. public function getUri(): ?string
  79. {
  80. return $this->uri;
  81. }
  82. public function setCreated(DateTimeInterface $created): self
  83. {
  84. $this->created = $created;
  85. return $this;
  86. }
  87. public function getCreated(): DateTimeInterface
  88. {
  89. return $this->created;
  90. }
  91. public function setModified(DateTimeInterface $modified): self
  92. {
  93. $this->modified = $modified;
  94. return $this;
  95. }
  96. public function getModified(): DateTimeInterface
  97. {
  98. return $this->modified;
  99. }
  100. // @codeCoverageIgnoreEnd
  101. // }}} Autocode
  102. public static function schemaDef(): array
  103. {
  104. return [
  105. 'name' => 'group_member',
  106. 'fields' => [
  107. 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'name' => 'group_member_group_id_fkey', 'not null' => true, 'description' => 'foreign key to group table'],
  108. 'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'name' => 'group_member_actor_id_fkey', 'not null' => true, 'description' => 'foreign key to actor table'],
  109. 'is_admin' => ['type' => 'bool', 'default' => false, 'description' => 'is this actor an admin?'],
  110. 'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'],
  111. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  112. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  113. ],
  114. 'primary key' => ['group_id', 'actor_id'],
  115. 'unique keys' => [
  116. 'group_member_uri_key' => ['uri'],
  117. ],
  118. 'indexes' => [
  119. 'group_member_actor_id_idx' => ['actor_id'],
  120. 'group_member_created_idx' => ['created'],
  121. 'group_member_actor_id_created_idx' => ['actor_id', 'created'],
  122. 'group_member_group_id_created_idx' => ['group_id', 'created'],
  123. ],
  124. ];
  125. }
  126. }