3 if (!defined('GNUSOCIAL')) { exit(1); }
5 class RawEventsNoticeStream extends NoticeStream
7 function getNoticeIds($offset, $limit, $since_id, $max_id)
9 $notice = new Notice();
12 $qry = 'SELECT notice.* FROM notice ';
13 $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
14 $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
17 $qry .= 'AND notice.id > ' . $since_id . ' ';
21 $qry .= 'AND notice.id <= ' . $max_id . ' ';
24 // NOTE: we sort by event time, not by notice time!
25 $qry .= 'ORDER BY happening.created DESC ';
26 if (!is_null($offset)) {
27 $qry .= "LIMIT $limit OFFSET $offset";
32 while ($notice->fetch()) {
42 class EventsNoticeStream extends ScopingNoticeStream
44 // possible values of RSVP in our database
45 protected $rsvp = ['Y', 'N', '?'];
46 protected $target = null;
48 function __construct(Profile $target, Profile $scoped=null, array $rsvp=array())
50 $stream = new RawEventsNoticeStream();
52 if ($target->sameAs($scoped)) {
53 $key = 'happening:ids_for_user_own:'.$target->getID();
55 $key = 'happening:ids_for_user:'.$target->getID();
58 // Match RSVP against our possible values, given in the class variable
59 // and if no RSVPs are given is empty, assume we want all events, even
60 // without RSVPs from this profile.
61 $this->rsvp = array_intersect($this->rsvp, $rsvp);
62 $this->target = $target;
64 parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
67 protected function filter(Notice $notice)
69 if (!parent::filter($notice)) {
70 // if not in our scope, return false
74 if (empty($this->rsvp)) {
75 // Don't filter on RSVP (for only events with RSVP if no responses
76 // are given (give ['Y', 'N', '?'] for only RSVP'd events!).
81 $rsvp->profile_id = $this->target->getID();
82 $rsvp->event_uri = $notice->getUri();
83 $rsvp->whereAddIn('response', $this->rsvp, $rsvp->columnType('response'));
85 // filter out if no RSVP match was found