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