+
+ /**
+ * Fetch a stream of favorites by profile
+ *
+ * @param integer $profileId Profile that faved
+ * @param integer $offset Offset from last
+ * @param integer $limit Number to get
+ *
+ * @return mixed stream of faves, use fetch() to iterate
+ *
+ * @todo Cache results
+ * @todo integrate with Fave::stream()
+ */
+
+ static function byProfile($profileId, $offset, $limit)
+ {
+ $fav = new Fave();
+
+ $fav->user_id = $profileId;
+
+ $fav->orderBy('modified DESC');
+
+ $fav->limit($offset, $limit);
+
+ $fav->find();
+
+ return $fav;
+ }
+
+ /**
+ * Grab a list of profile who have favored this notice.
+ *
+ * @return ArrayWrapper masquerading as a Fave
+ */
+ static function byNotice($noticeId)
+ {
+ $c = self::memcache();
+ $key = Cache::key('fave:by_notice:' . $noticeId);
+
+ $wrapper = $c->get($key);
+ if (!$wrapper) {
+ // @fixme caching & scalability!
+ $fave = new Fave();
+ $fave->notice_id = $noticeId;
+ $fave->find();
+
+ $list = array();
+ while ($fave->fetch()) {
+ $list[] = clone($fave);
+ }
+ $wrapper = new ArrayWrapper($list);
+ $c->set($key, $wrapper);
+ }
+ return $wrapper;
+ }