]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Reply.php
Merge branch 'righttoleave' into 0.9.x
[quix0rs-gnu-social.git] / classes / Reply.php
1 <?php
2 /**
3  * Table Definition for reply
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Reply extends Memcached_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'reply';                           // table name
13     public $notice_id;                       // int(4)  primary_key not_null
14     public $profile_id;                      // int(4)  primary_key not_null
15     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
16     public $replied_id;                      // int(4)
17
18     /* Static get */
19     function staticGet($k,$v=null)
20     { return Memcached_DataObject::staticGet('Reply',$k,$v); }
21
22     /* the code above is auto generated do not remove the tag below */
23     ###END_AUTOCODE
24
25     /**
26      * Wrapper for record insertion to update related caches
27      */
28     function insert()
29     {
30         $result = parent::insert();
31
32         if ($result) {
33             self::blow('reply:stream:%d', $this->profile_id);
34         }
35
36         return $result;
37     }
38
39     function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
40     {
41         $ids = Notice::stream(array('Reply', '_streamDirect'),
42                               array($user_id),
43                               'reply:stream:' . $user_id,
44                               $offset, $limit, $since_id, $max_id);
45         return $ids;
46     }
47
48     function _streamDirect($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
49     {
50         $reply = new Reply();
51         $reply->profile_id = $user_id;
52
53         Notice::addWhereSinceId($reply, $since_id, 'notice_id', 'modified');
54         Notice::addWhereMaxId($reply, $max_id, 'notice_id', 'modified');
55
56         $reply->orderBy('modified DESC, notice_id DESC');
57
58         if (!is_null($offset)) {
59             $reply->limit($offset, $limit);
60         }
61
62         $ids = array();
63
64         if ($reply->find()) {
65             while ($reply->fetch()) {
66                 $ids[] = $reply->notice_id;
67             }
68         }
69
70         return $ids;
71     }
72 }