Local_group.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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; // datetime() 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, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
  24. 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', '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. }