Local_group.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $qry = 'UPDATE local_group set nickname = "'.$this->escape($nickname).'" where group_id = ' . $this->group_id;
  69. $result = $this->query($qry);
  70. if ($result) {
  71. $this->nickname = $nickname;
  72. $this->fixupTimestamps();
  73. $this->encache();
  74. } else {
  75. common_log_db_error($local, 'UPDATE', __FILE__);
  76. // TRANS: Server exception thrown when updating a local group fails.
  77. throw new ServerException(_('Could not update local group.'));
  78. }
  79. return $result;
  80. }
  81. }