Local_group.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. $group = $this->getGroup();
  38. if (!$group instanceof User_group) {
  39. return null; // TODO: Throw exception when other code is ready
  40. }
  41. return $group->getProfile();
  42. }
  43. public function getGroup()
  44. {
  45. return User_group::getKV('id', $this->group_id);
  46. }
  47. function setNickname($nickname)
  48. {
  49. $this->decache();
  50. $qry = 'UPDATE local_group set nickname = "'.$this->escape($nickname).'" where group_id = ' . $this->group_id;
  51. $result = $this->query($qry);
  52. if ($result) {
  53. $this->nickname = $nickname;
  54. $this->fixupTimestamps();
  55. $this->encache();
  56. } else {
  57. common_log_db_error($local, 'UPDATE', __FILE__);
  58. // TRANS: Server exception thrown when updating a local group fails.
  59. throw new ServerException(_('Could not update local group.'));
  60. }
  61. return $result;
  62. }
  63. }