3 * Table Definition for fave
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Fave extends Memcached_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'fave'; // table name
13 public $notice_id; // int(4) primary_key not_null
14 public $user_id; // int(4) primary_key not_null
15 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
18 function staticGet($k,$v=null)
19 { return Memcached_DataObject::staticGet('Fave',$k,$v); }
21 /* the code above is auto generated do not remove the tag below */
24 static function addNew($profile, $notice) {
28 if (Event::handle('StartFavorNotice', array($profile, $notice, &$fave))) {
32 $fave->user_id = $profile->id;
33 $fave->notice_id = $notice->id;
35 if (!$fave->insert()) {
36 common_log_db_error($fave, 'INSERT', __FILE__);
40 Event::handle('EndFavorNotice', array($profile, $notice));
48 $profile = Profile::staticGet('id', $this->user_id);
49 $notice = Notice::staticGet('id', $this->notice_id);
53 if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) {
55 $result = parent::delete();
58 Event::handle('EndDisfavorNotice', array($profile, $notice));
67 return Memcached_DataObject::pkeyGet('Fave', $kv);
70 function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false)
72 $ids = Notice::stream(array('Fave', '_streamDirect'),
73 array($user_id, $own),
74 ($own) ? 'fave:ids_by_user_own:'.$user_id :
75 'fave:ids_by_user:'.$user_id,
80 function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
86 $qry = 'SELECT fave.* FROM fave ';
87 $qry .= 'WHERE fave.user_id = ' . $user_id . ' ';
89 $qry = 'SELECT fave.* FROM fave ';
90 $qry .= 'INNER JOIN notice ON fave.notice_id = notice.id ';
91 $qry .= 'WHERE fave.user_id = ' . $user_id . ' ';
92 $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
96 $qry .= 'AND notice_id > ' . $since_id . ' ';
100 $qry .= 'AND notice_id <= ' . $max_id . ' ';
103 if (!is_null($since)) {
104 $qry .= 'AND modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
107 // NOTE: we sort by fave time, not by notice time!
109 $qry .= 'ORDER BY modified DESC ';
111 if (!is_null($offset)) {
112 $qry .= "LIMIT $limit OFFSET $offset";
119 while ($fav->fetch()) {
120 $ids[] = $fav->notice_id;