Notice_tag.php 3.07 KB
Newer Older
Mike Cochrane's avatar
Mike Cochrane committed
1
<?php
2 3
/*
 * Laconica - a distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, Control Yourself, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Mike Cochrane's avatar
Mike Cochrane committed
18
 */
19

20
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
Mike Cochrane's avatar
Mike Cochrane committed
21

22
class Notice_tag extends Memcached_DataObject
Mike Cochrane's avatar
Mike Cochrane committed
23 24 25 26 27 28 29 30 31 32
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'notice_tag';                      // table name
    public $tag;                             // varchar(64)  primary_key not_null
    public $notice_id;                       // int(4)  primary_key not_null
    public $created;                         // datetime()   not_null

    /* Static get */
33 34
    function staticGet($k,$v=null)
    { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); }
Mike Cochrane's avatar
Mike Cochrane committed
35 36 37

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE
38

39
    static function getStream($tag, $offset=0, $limit=20) {
40 41 42 43 44 45 46 47 48

        $ids = Notice::stream(array('Notice_tag', '_streamDirect'),
                              array($tag),
                              'notice_tag:notice_ids:' . common_keyize($tag),
                              $offset, $limit);

        return Notice::getStreamByIds($ids);
    }

49
    function _streamDirect($tag, $offset, $limit, $since_id, $max_id, $since)
50 51 52 53 54 55 56 57 58 59 60 61
    {
        $nt = new Notice_tag();

        $nt->tag = $tag;

        $nt->selectAdd();
        $nt->selectAdd('notice_id');

        if ($since_id != 0) {
            $nt->whereAdd('notice_id > ' . $since_id);
        }

62 63
        if ($max_id != 0) {
            $nt->whereAdd('notice_id < ' . $max_id);
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        }

        if (!is_null($since)) {
            $nt->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
        }

        $nt->orderBy('notice_id DESC');

        if (!is_null($offset)) {
            $nt->limit($offset, $limit);
        }

        $ids = array();

        if ($nt->find()) {
            while ($nt->fetch()) {
                $ids[] = $nt->notice_id;
            }
        }

        return $ids;
85
    }
86

87
    function blowCache($blowLast=false)
88
    {
89 90
        $cache = common_memcache();
        if ($cache) {
91 92 93 94 95
            $idkey = common_cache_key('notice_tag:notice_ids:' . common_keyize($this->tag));
            $cache->delete($idkey);
            if ($blowLast) {
                $cache->delete($idkey.';last');
            }
96 97
        }
    }
98 99 100 101 102

    function &pkeyGet($kv)
    {
        return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
    }
Mike Cochrane's avatar
Mike Cochrane committed
103
}