]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Fave.php
915b4572ffed5dd11e533a664c55e4d687d725b3
[quix0rs-gnu-social.git] / classes / Fave.php
1 <?php
2 /**
3  * Table Definition for fave
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Fave extends Memcached_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'fave';                            // table name
13     public $notice_id;                       // int(4)  primary_key not_null
14     public $user_id;                         // int(4)  primary_key not_null
15     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
16
17     /* Static get */
18     function staticGet($k,$v=null)
19     { return Memcached_DataObject::staticGet('Fave',$k,$v); }
20
21     /* the code above is auto generated do not remove the tag below */
22     ###END_AUTOCODE
23
24     static function addNew($user, $notice) {
25         $fave = new Fave();
26         $fave->user_id = $user->id;
27         $fave->notice_id = $notice->id;
28         if (!$fave->insert()) {
29             common_log_db_error($fave, 'INSERT', __FILE__);
30             return false;
31         }
32         return $fave;
33     }
34
35     function &pkeyGet($kv)
36     {
37         return Memcached_DataObject::pkeyGet('Fave', $kv);
38     }
39
40     function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE)
41     {
42         $ids = Notice::stream(array('Fave', '_streamDirect'),
43                               array($user_id),
44                               'fave:ids_by_user:'.$user_id,
45                               $offset, $limit);
46         return $ids;
47     }
48
49     function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since)
50     {
51         $fav = new Fave();
52
53         $fav->user_id = $user_id;
54
55         $fav->selectAdd();
56         $fav->selectAdd('notice_id');
57
58         if ($since_id != 0) {
59             $fav->whereAdd('notice_id > ' . $since_id);
60         }
61
62         if ($before_id != 0) {
63             $fav->whereAdd('notice_id < ' . $before_id);
64         }
65
66         if (!is_null($since)) {
67             $fav->whereAdd('modified > \'' . date('Y-m-d H:i:s', $since) . '\'');
68         }
69
70         // NOTE: we sort by fave time, not by notice time!
71
72         $fav->orderBy('modified DESC');
73
74         if (!is_null($offset)) {
75             $fav->limit($offset, $limit);
76         }
77
78         $ids = array();
79
80         if ($fav->find()) {
81             while ($fav->fetch()) {
82                 $ids[] = $fav->notice_id;
83             }
84         }
85
86         return $ids;
87     }
88 }