Local_group.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Table Definition for local_group
  4. */
  5. class Local_group extends Managed_DataObject
  6. {
  7. ###START_AUTOCODE
  8. /* the code below is auto generated do not remove the above tag */
  9. public $__table = 'local_group'; // table name
  10. public $group_id; // int(4) primary_key not_null
  11. public $nickname; // varchar(64) unique_key
  12. public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
  13. public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
  14. /* the code above is auto generated do not remove the tag below */
  15. ###END_AUTOCODE
  16. public static function schemaDef()
  17. {
  18. return array(
  19. 'description' => 'Record for a user group on the local site, with some additional info not in user_group',
  20. 'fields' => array(
  21. 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group represented'),
  22. 'nickname' => array('type' => 'varchar', 'length' => 64, 'description' => 'group represented'),
  23. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  24. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  25. ),
  26. 'primary key' => array('group_id'),
  27. 'foreign keys' => array(
  28. 'local_group_group_id_fkey' => array('user_group', array('group_id' => 'id')),
  29. ),
  30. 'unique keys' => array(
  31. 'local_group_nickname_key' => array('nickname'),
  32. ),
  33. );
  34. }
  35. public function getProfile()
  36. {
  37. return $this->getGroup()->getProfile();
  38. }
  39. public function getGroup()
  40. {
  41. $group = new User_group();
  42. $group->id = $this->group_id;
  43. $group->find(true);
  44. if (!$group instanceof User_group) {
  45. common_log(LOG_ERR, 'User_group does not exist for Local_group: '.$this->group_id);
  46. throw new NoSuchGroupException(array('id' => $this->group_id));
  47. }
  48. return $group;
  49. }
  50. function setNickname($nickname)
  51. {
  52. $this->decache();
  53. $qry = 'UPDATE local_group set nickname = "'.$this->escape($nickname).'" where group_id = ' . $this->group_id;
  54. $result = $this->query($qry);
  55. if ($result) {
  56. $this->nickname = $nickname;
  57. $this->fixupTimestamps();
  58. $this->encache();
  59. } else {
  60. common_log_db_error($local, 'UPDATE', __FILE__);
  61. // TRANS: Server exception thrown when updating a local group fails.
  62. throw new ServerException(_('Could not update local group.'));
  63. }
  64. return $result;
  65. }
  66. }