]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Event/lib/eventsnoticestream.php
minor happening changes
[quix0rs-gnu-social.git] / plugins / Event / lib / eventsnoticestream.php
1 <?php
2
3 class RawEventsNoticeStream extends NoticeStream
4 {
5     protected $target;
6     protected $own;
7
8     function __construct(Profile $target)
9     {
10         $this->target   = $target;
11     }
12
13     function getNoticeIds($offset, $limit, $since_id, $max_id)
14     {
15         $notice = new Notice();
16         $qry = null;
17
18         $qry =  'SELECT notice.* FROM notice ';
19         $qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
20         $qry .= 'WHERE happening.profile_id = ' . $this->target->getID() . ' ';
21         $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
22
23         if ($since_id != 0) {
24             $qry .= 'AND notice.id > ' . $since_id . ' ';
25         }
26
27         if ($max_id != 0) {
28             $qry .= 'AND notice.id <= ' . $max_id . ' ';
29         }
30
31         // NOTE: we sort by event time, not by notice time!
32         $qry .= 'ORDER BY created DESC ';
33         if (!is_null($offset)) {
34             $qry .= "LIMIT $limit OFFSET $offset";
35         }
36
37         $notice->query($qry);
38         $ids = array();
39         while ($notice->fetch()) {
40             $ids[] = $notice->id;
41         }
42
43         $notice->free();
44         unset($notice);
45         return $ids;
46     }
47 }
48
49 class EventsNoticeStream extends ScopingNoticeStream
50 {
51     function __construct(Profile $target, Profile $scoped=null)
52     {
53         $stream = new RawEventsNoticeStream($target);
54
55         if ($target->sameAs($scoped)) {
56             $key = 'happening:ids_for_user_own:'.$target->getID();
57         } else {
58             $key = 'happening:ids_for_user:'.$target->getID();
59         }
60
61         parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
62     }
63 }