]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sitemap/Sitemap_user_count.php
Database tables to cache expensive query data
[quix0rs-gnu-social.git] / plugins / Sitemap / Sitemap_user_count.php
1 <?php
2 /**
3  * Data class for counting user registrations by date
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Data class for counting users by date
38  *
39  * We make a separate sitemap for each user registered by date.
40  * To save ourselves some processing effort, we cache this data
41  *
42  * @category Action
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://status.net/
47  *
48  * @see      DB_DataObject
49  */
50
51 class Sitemap_user_count extends Memcached_DataObject
52 {
53     public $__table = 'sitemap_user_count'; // table name
54
55     public $registration_date;               // date primary_key not_null
56     public $user_count;                      // int(4)
57     public $created;
58     public $modified;
59
60     /**
61      * Get an instance by key
62      *
63      * This is a utility method to get a single instance with a given key value.
64      *
65      * @param string $k Key to use to lookup (usually 'user_id' for this class)
66      * @param mixed  $v Value to lookup
67      *
68      * @return Sitemap_user_count object found, or null for no hits
69      *
70      */
71
72     function staticGet($k, $v=null)
73     {
74         return Memcached_DataObject::staticGet('Sitemap_user_count', $k, $v);
75     }
76
77     /**
78      * return table definition for DB_DataObject
79      *
80      * DB_DataObject needs to know something about the table to manipulate
81      * instances. This method provides all the DB_DataObject needs to know.
82      *
83      * @return array array of column definitions
84      */
85
86     function table()
87     {
88         return array('registration_date' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_NOTNULL,
89                      'user_count' => DB_DATAOBJECT_INT,
90                      'created'   => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
91                      'modified'  => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
92     }
93
94     /**
95      * return key definitions for DB_DataObject
96      *
97      * DB_DataObject needs to know about keys that the table has; this function
98      * defines them.
99      *
100      * @return array key definitions
101      */
102
103     function keys()
104     {
105         return array('registration_date' => 'K');
106     }
107
108     /**
109      * return key definitions for Memcached_DataObject
110      *
111      * Our caching system uses the same key definitions, but uses a different
112      * method to get them.
113      *
114      * @return array key definitions
115      */
116
117     function keyTypes()
118     {
119         return $this->keys();
120     }
121 }