3 * Table Definition for user_group
6 class User_group extends Memcached_DataObject
9 /* the code below is auto generated do not remove the above tag */
11 public $__table = 'user_group'; // table name
12 public $id; // int(4) primary_key not_null
13 public $nickname; // varchar(64) unique_key
14 public $fullname; // varchar(255)
15 public $homepage; // varchar(255)
16 public $description; // varchar(140)
17 public $location; // varchar(255)
18 public $original_logo; // varchar(255)
19 public $homepage_logo; // varchar(255)
20 public $stream_logo; // varchar(255)
21 public $mini_logo; // varchar(255)
22 public $created; // datetime() not_null
23 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
26 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_group',$k,$v); }
28 /* the code above is auto generated do not remove the tag below */
31 function defaultLogo($size)
33 static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
34 AVATAR_STREAM_SIZE => 'stream',
35 AVATAR_MINI_SIZE => 'mini');
36 return theme_path('default-avatar-'.$sizenames[$size].'.png');
41 return common_local_url('showgroup',
42 array('nickname' => $this->nickname));
47 return common_local_url('groupbyid',
48 array('id' => $this->id));
51 function getNotices($offset, $limit)
53 $ids = Notice::stream(array($this, '_streamDirect'),
55 'user_group:notice_ids:' . $this->id,
58 return Notice::getStreamByIds($ids);
61 function _streamDirect($offset, $limit, $since_id, $before_id, $since)
63 $inbox = new Group_inbox();
65 $inbox->group_id = $this->id;
68 $inbox->selectAdd('notice_id');
71 $inbox->whereAdd('notice_id > ' . $since_id);
74 if ($before_id != 0) {
75 $inbox->whereAdd('notice_id < ' . $before_id);
78 if (!is_null($since)) {
79 $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
82 $inbox->orderBy('notice_id DESC');
84 if (!is_null($offset)) {
85 $inbox->limit($offset, $limit);
91 while ($inbox->fetch()) {
92 $ids[] = $inbox->notice_id;
99 function allowedNickname($nickname)
101 static $blacklist = array('new');
102 return !in_array($nickname, $blacklist);
105 function getMembers($offset=0, $limit=null)
108 'SELECT profile.* ' .
109 'FROM profile JOIN group_member '.
110 'ON profile.id = group_member.profile_id ' .
111 'WHERE group_member.group_id = %d ' .
112 'ORDER BY group_member.created DESC ';
114 if ($limit != null) {
115 if (common_config('db','type') == 'pgsql') {
116 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
118 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
122 $members = new Profile();
124 $members->query(sprintf($qry, $this->id));
128 function setOriginal($filename)
130 $imagefile = new ImageFile($this->id, Avatar::path($filename));
132 $orig = clone($this);
133 $this->original_logo = Avatar::url($filename);
134 $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
135 $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
136 $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
137 common_debug(common_log_objstring($this));
138 return $this->update($orig);