X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FFave.php;h=915b4572ffed5dd11e533a664c55e4d687d725b3;hb=21aad16b58e98f61aded9c102adaef7616a6728f;hp=bbd72ca0b0d5298be28a4cc3a9d2a84cdab08f17;hpb=47d15bc662c0bf160f895640b882e92a56c34208;p=quix0rs-gnu-social.git diff --git a/classes/Fave.php b/classes/Fave.php index bbd72ca0b0..915b4572ff 100644 --- a/classes/Fave.php +++ b/classes/Fave.php @@ -2,9 +2,9 @@ /** * Table Definition for fave */ -require_once 'DB/DataObject.php'; +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Fave extends DB_DataObject +class Fave extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -15,8 +15,74 @@ class Fave extends DB_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Fave',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Fave',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + static function addNew($user, $notice) { + $fave = new Fave(); + $fave->user_id = $user->id; + $fave->notice_id = $notice->id; + if (!$fave->insert()) { + common_log_db_error($fave, 'INSERT', __FILE__); + return false; + } + return $fave; + } + + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Fave', $kv); + } + + function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE) + { + $ids = Notice::stream(array('Fave', '_streamDirect'), + array($user_id), + 'fave:ids_by_user:'.$user_id, + $offset, $limit); + return $ids; + } + + function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since) + { + $fav = new Fave(); + + $fav->user_id = $user_id; + + $fav->selectAdd(); + $fav->selectAdd('notice_id'); + + if ($since_id != 0) { + $fav->whereAdd('notice_id > ' . $since_id); + } + + if ($before_id != 0) { + $fav->whereAdd('notice_id < ' . $before_id); + } + + if (!is_null($since)) { + $fav->whereAdd('modified > \'' . date('Y-m-d H:i:s', $since) . '\''); + } + + // NOTE: we sort by fave time, not by notice time! + + $fav->orderBy('modified DESC'); + + if (!is_null($offset)) { + $fav->limit($offset, $limit); + } + + $ids = array(); + + if ($fav->find()) { + while ($fav->fetch()) { + $ids[] = $fav->notice_id; + } + } + + return $ids; + } }