Local_group.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Table Definition for local_group
  18. */
  19. defined('GNUSOCIAL') || die();
  20. class Local_group extends Managed_DataObject
  21. {
  22. ###START_AUTOCODE
  23. /* the code below is auto generated do not remove the above tag */
  24. public $__table = 'local_group'; // table name
  25. public $group_id; // int(4) primary_key not_null
  26. public $nickname; // varchar(64) unique_key
  27. public $created; // datetime()
  28. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  29. /* the code above is auto generated do not remove the tag below */
  30. ###END_AUTOCODE
  31. public static function schemaDef()
  32. {
  33. return array(
  34. 'description' => 'Record for a user group on the local site, with some additional info not in user_group',
  35. 'fields' => array(
  36. 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group represented'),
  37. 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
  38. 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
  39. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  40. ),
  41. 'primary key' => array('group_id'),
  42. 'foreign keys' => array(
  43. 'local_group_group_id_fkey' => array('user_group', array('group_id' => 'id')),
  44. ),
  45. 'unique keys' => array(
  46. 'local_group_nickname_key' => array('nickname'),
  47. ),
  48. );
  49. }
  50. public function getProfile()
  51. {
  52. return $this->getGroup()->getProfile();
  53. }
  54. public function getGroup()
  55. {
  56. $group = new User_group();
  57. $group->id = $this->group_id;
  58. $group->find(true);
  59. if (!$group instanceof User_group) {
  60. common_log(LOG_ERR, 'User_group does not exist for Local_group: '.$this->group_id);
  61. throw new NoSuchGroupException(array('id' => $this->group_id));
  62. }
  63. return $group;
  64. }
  65. public function setNickname($nickname)
  66. {
  67. $this->decache();
  68. $modified = common_sql_now();
  69. $result = $this->query(sprintf(
  70. <<<'END'
  71. UPDATE local_group SET nickname = %1$s, modified = %2$s
  72. WHERE group_id = %3$d;
  73. END,
  74. $this->_quote($nickname),
  75. $this->_quote($modified),
  76. $this->group_id
  77. ));
  78. if ($result) {
  79. $this->nickname = $nickname;
  80. $this->modified = $modified;
  81. $this->encache();
  82. } else {
  83. common_log_db_error($local, 'UPDATE', __FILE__);
  84. // TRANS: Server exception thrown when updating a local group fails.
  85. throw new ServerException(_('Could not update local group.'));
  86. }
  87. return $result;
  88. }
  89. }