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)
55 'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' .
56 'WHERE group_inbox.group_id = %d ';
57 return Notice::getStream(sprintf($qry, $this->id),
58 'group:notices:'.$this->id,
62 function allowedNickname($nickname)
64 static $blacklist = array('new');
65 return !in_array($nickname, $blacklist);
68 function getMembers($offset=0, $limit=null)
72 'FROM profile JOIN group_member '.
73 'ON profile.id = group_member.profile_id ' .
74 'WHERE group_member.group_id = %d ' .
75 'ORDER BY group_member.created DESC ';
78 if (common_config('db','type') == 'pgsql') {
79 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
81 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
85 $members = new Profile();
87 $members->query(sprintf($qry, $this->id));
91 function setOriginal($filename, $type)
94 $this->original_logo = common_avatar_url($filename);
95 $this->homepage_logo = common_avatar_url($this->scale($filename,
98 $this->stream_logo = common_avatar_url($this->scale($filename,
101 $this->mini_logo = common_avatar_url($this->scale($filename,
104 common_debug(common_log_objstring($this));
105 return $this->update($orig);
108 function scale($filename, $size, $type)
110 $filepath = common_avatar_path($filename);
112 if (!file_exists($filepath)) {
113 $this->serverError(_('Lost our file.'));
117 $info = @getimagesize($filepath);
121 $image_src = imagecreatefromgif($filepath);
124 $image_src = imagecreatefromjpeg($filepath);
127 $image_src = imagecreatefrompng($filepath);
130 $this->serverError(_('Unknown file type'));
134 $image_dest = imagecreatetruecolor($size, $size);
136 $background = imagecolorallocate($image_dest, 0, 0, 0);
137 ImageColorTransparent($image_dest, $background);
138 imagealphablending($image_dest, false);
140 imagecopyresized($image_dest, $image_src,
142 $size, $size, $info[0], $info[1]);
144 $outname = common_avatar_filename($this->id,
145 image_type_to_extension($type),
149 $outpath = common_avatar_path($outname);
153 imagegif($image_dest, $outpath);
156 imagejpeg($image_dest, $outpath);
159 imagepng($image_dest, $outpath);
162 $this->serverError(_('Unknown file type'));