]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/User_group.php
minilist for groups
[quix0rs-gnu-social.git] / classes / User_group.php
1 <?php
2 /**
3  * Table Definition for user_group
4  */
5 require_once 'classes/Memcached_DataObject.php';
6
7 class User_group extends Memcached_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'user_group';                      // table name
13     public $id;                              // int(4)  primary_key not_null
14     public $nickname;                        // varchar(64)  unique_key
15     public $fullname;                        // varchar(255)
16     public $homepage;                        // varchar(255)
17     public $description;                     // varchar(140)
18     public $location;                        // varchar(255)
19     public $original_logo;                   // varchar(255)
20     public $homepage_logo;                   // varchar(255)
21     public $stream_logo;                     // varchar(255)
22     public $mini_logo;                       // varchar(255)
23     public $created;                         // datetime()   not_null
24     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
25
26     /* Static get */
27     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_group',$k,$v); }
28
29     /* the code above is auto generated do not remove the tag below */
30     ###END_AUTOCODE
31
32     function defaultLogo($size)
33     {
34         static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
35                                   AVATAR_STREAM_SIZE => 'stream',
36                                   AVATAR_MINI_SIZE => 'mini');
37         return theme_path('default-avatar-'.$sizenames[$size].'.png');
38     }
39
40     function homeUrl()
41     {
42         return common_local_url('showgroup',
43                                 array('nickname' => $this->nickname));
44     }
45
46     function permalink()
47     {
48         return common_local_url('groupbyid',
49                                 array('id' => $this->id));
50     }
51
52     function getNotices($offset, $limit)
53     {
54         $qry =
55           'SELECT notice.* ' .
56           'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' .
57           'WHERE group_inbox.group_id = %d ';
58         return Notice::getStream(sprintf($qry, $this->id),
59                                  'group:notices:'.$this->id,
60                                  $offset, $limit);
61     }
62
63     function allowedNickname($nickname)
64     {
65         static $blacklist = array('new');
66         return !in_array($nickname, $blacklist);
67     }
68
69     function getMembers($offset=0, $limit=null)
70     {
71         $qry =
72           'SELECT profile.* ' .
73           'FROM profile JOIN group_member '.
74           'ON profile.id = group_member.profile_id ' .
75           'WHERE group_member.group_id = %d ' .
76           'ORDER BY group_member.created DESC ';
77
78         if (common_config('db','type') == 'pgsql') {
79             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
80         } else {
81             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
82         }
83
84         $members = new Profile();
85
86         $cnt = $members->query(sprintf($qry, $this->id));
87
88         return $members;
89     }
90 }