]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Notice_tag.php
change Laconica and Control Yourself to StatusNet in PHP files
[quix0rs-gnu-social.git] / classes / Notice_tag.php
1 <?php
2 /*
3  * StatusNet - a distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
21
22 class Notice_tag extends Memcached_DataObject
23 {
24     ###START_AUTOCODE
25     /* the code below is auto generated do not remove the above tag */
26
27     public $__table = 'notice_tag';                      // table name
28     public $tag;                             // varchar(64)  primary_key not_null
29     public $notice_id;                       // int(4)  primary_key not_null
30     public $created;                         // datetime()   not_null
31
32     /* Static get */
33     function staticGet($k,$v=null)
34     { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); }
35
36     /* the code above is auto generated do not remove the tag below */
37     ###END_AUTOCODE
38
39     static function getStream($tag, $offset=0, $limit=20) {
40
41         $ids = Notice::stream(array('Notice_tag', '_streamDirect'),
42                               array($tag),
43                               'notice_tag:notice_ids:' . common_keyize($tag),
44                               $offset, $limit);
45
46         return Notice::getStreamByIds($ids);
47     }
48
49     function _streamDirect($tag, $offset, $limit, $since_id, $max_id, $since)
50     {
51         $nt = new Notice_tag();
52
53         $nt->tag = $tag;
54
55         $nt->selectAdd();
56         $nt->selectAdd('notice_id');
57
58         if ($since_id != 0) {
59             $nt->whereAdd('notice_id > ' . $since_id);
60         }
61
62         if ($max_id != 0) {
63             $nt->whereAdd('notice_id < ' . $max_id);
64         }
65
66         if (!is_null($since)) {
67             $nt->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
68         }
69
70         $nt->orderBy('notice_id DESC');
71
72         if (!is_null($offset)) {
73             $nt->limit($offset, $limit);
74         }
75
76         $ids = array();
77
78         if ($nt->find()) {
79             while ($nt->fetch()) {
80                 $ids[] = $nt->notice_id;
81             }
82         }
83
84         return $ids;
85     }
86
87     function blowCache($blowLast=false)
88     {
89         $cache = common_memcache();
90         if ($cache) {
91             $idkey = common_cache_key('notice_tag:notice_ids:' . common_keyize($this->tag));
92             $cache->delete($idkey);
93             if ($blowLast) {
94                 $cache->delete($idkey.';last');
95             }
96         }
97     }
98
99     function &pkeyGet($kv)
100     {
101         return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
102     }
103 }