]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailSummary/Email_summary_status.php
add path separators for Plugin::path()
[quix0rs-gnu-social.git] / plugins / EmailSummary / Email_summary_status.php
1 <?php
2 /**
3  * Data class for email summary status
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 email summaries
38  * 
39  * Email summary information for users
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  *
47  * @see      DB_DataObject
48  */
49
50 class Email_summary_status extends Memcached_DataObject
51 {
52     public $__table = 'email_summary_status'; // table name
53     public $user_id;                         // int(4)  primary_key not_null
54     public $send_summary;                    // tinyint not_null
55     public $last_summary_id;                 // int(4)  null
56     public $created;                         // datetime not_null
57     public $modified;                        // datetime not_null
58
59     /**
60      * Get an instance by key
61      *
62      * @param string $k Key to use to lookup (usually 'user_id' for this class)
63      * @param mixed  $v Value to lookup
64      *
65      * @return Email_summary_status object found, or null for no hits
66      *
67      */
68     function staticGet($k, $v=null)
69     {
70         return Memcached_DataObject::staticGet('email_summary_status', $k, $v);
71     }
72
73     /**
74      * return table definition for DB_DataObject
75      *
76      * DB_DataObject needs to know something about the table to manipulate
77      * instances. This method provides all the DB_DataObject needs to know.
78      *
79      * @return array array of column definitions
80      */
81
82     function table()
83     {
84         return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
85                      'send_summary' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
86                      'last_summary_id' => DB_DATAOBJECT_INT,
87                      'created' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
88                      'modified' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
89     }
90
91     /**
92      * return key definitions for DB_DataObject
93      *
94      * @return array list of key field names
95      */
96
97     function keys()
98     {
99         return array_keys($this->keyTypes());
100     }
101
102     /**
103      * return key definitions for Memcached_DataObject
104      *
105      * Our caching system uses the same key definitions, but uses a different
106      * method to get them. This key information is used to store and clear
107      * cached data, so be sure to list any key that will be used for static
108      * lookups.
109      *
110      * @return array associative array of key definitions, field name to type:
111      *         'K' for primary key: for compound keys, add an entry for each component;
112      *         'U' for unique keys: compound keys are not well supported here.
113      */
114     function keyTypes()
115     {
116         return array('user_id' => 'K');
117     }
118
119     /**
120      * Magic formula for non-autoincrementing integer primary keys
121      *
122      * @return array magic three-false array that stops auto-incrementing.
123      */
124     
125     function sequenceKey()
126     {
127         return array(false, false, false);
128     }
129
130     /**
131      * Helper function
132      *
133      * @param integer $user_id ID of the user to get a count for
134      *
135      * @return int flag for whether to send this user a summary email
136      */
137
138     static function getSendSummary($user_id)
139     {
140         $ess = Email_summary_status::staticGet('user_id', $user_id);
141
142         if (!empty($ess)) {
143             return $ess->send_summary;
144         } else {
145             return 1;
146         }
147     }
148
149     /**
150      * Get email summary status for a user
151      *
152      * @param integer $user_id ID of the user to get a count for
153      *
154      * @return Email_summary_status instance for this user, with count already incremented.
155      */
156
157     static function getLastSummaryID($user_id)
158     {
159         $ess = Email_summary_status::staticGet('user_id', $user_id);
160         
161         if (!empty($ess)) {
162             return $ess->last_summary_id;
163         } else {
164             return null;
165         }
166     }
167 }