3 class RawEventsNoticeStream extends NoticeStream
5 function getNoticeIds($offset, $limit, $since_id, $max_id)
7 $notice = new Notice();
10 $qry = 'SELECT notice.* FROM notice ';
11 $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
12 $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
15 $qry .= 'AND notice.id > ' . $since_id . ' ';
19 $qry .= 'AND notice.id <= ' . $max_id . ' ';
22 // NOTE: we sort by event time, not by notice time!
23 $qry .= 'ORDER BY happening.created DESC ';
24 if (!is_null($offset)) {
25 $qry .= "LIMIT $limit OFFSET $offset";
30 while ($notice->fetch()) {
40 class EventsNoticeStream extends ScopingNoticeStream
42 // possible values of RSVP in our database
43 protected $rsvp = ['Y', 'N', '?'];
44 protected $target = null;
46 function __construct(Profile $target, Profile $scoped=null, array $rsvp=array())
48 $stream = new RawEventsNoticeStream();
50 if ($target->sameAs($scoped)) {
51 $key = 'happening:ids_for_user_own:'.$target->getID();
53 $key = 'happening:ids_for_user:'.$target->getID();
56 // Match RSVP against our possible values, given in the class variable
57 // and if no RSVPs are given is empty, assume we want all events, even
58 // without RSVPs from this profile.
59 $this->rsvp = array_intersect($this->rsvp, $rsvp);
60 $this->target = $target;
62 parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
65 function filter($notice)
67 if (!parent::filter($notice)) {
68 // if not in our scope, return false
72 if (empty($this->rsvp)) {
73 // Don't filter on RSVP (for only events with RSVP if no responses
74 // are given (give ['Y', 'N', '?'] for only RSVP'd events!).
79 $rsvp->profile_id = $this->target->getID();
80 $rsvp->event_uri = $notice->getUri();
81 $rsvp->whereAddIn('response', $this->rsvp, $rsvp->columnType('response'));
83 // filter out if no RSVP match was found