]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/filenoticestream.php
Merge branch 'limitdist' into limitdist2
[quix0rs-gnu-social.git] / lib / filenoticestream.php
1 <?php
2
3 class FileNoticeStream extends CachingNoticeStream
4 {
5     function __construct($file)
6     {
7         parent::__construct(new RawFileNoticeStream($file),
8                             'file:notice-ids:'.$this->url);
9     }
10 }
11
12 class RawFileNoticeStream extends NoticeStream
13 {
14     protected $file = null;
15
16     function __construct($file)
17     {
18         $this->file = $file;
19         parent::__construct();
20     }
21
22     /**
23      * Stream of notices linking to this URL
24      *
25      * @param integer $offset   Offset to show; default is 0
26      * @param integer $limit    Limit of notices to show
27      * @param integer $since_id Since this notice
28      * @param integer $max_id   Before this notice
29      *
30      * @return array ids of notices that link to this file
31      */
32     function getNoticeIds($offset, $limit, $since_id, $max_id)
33     {
34         $f2p = new File_to_post();
35
36         $f2p->selectAdd();
37         $f2p->selectAdd('post_id');
38
39         $f2p->file_id = $this->file->id;
40
41         Notice::addWhereSinceId($f2p, $since_id, 'post_id', 'modified');
42         Notice::addWhereMaxId($f2p, $max_id, 'post_id', 'modified');
43
44         $f2p->orderBy('modified DESC, post_id DESC');
45
46         if (!is_null($offset)) {
47             $f2p->limit($offset, $limit);
48         }
49
50         $ids = array();
51
52         if ($f2p->find()) {
53             while ($f2p->fetch()) {
54                 $ids[] = $f2p->post_id;
55             }
56         }
57
58         return $ids;
59     }
60 }