3 * Data class for email summary status
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Data class for email summaries
39 * Email summary information for users
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45 * @link http://status.net/
49 class Email_summary_status extends Managed_DataObject
51 public $__table = 'email_summary_status'; // table name
52 public $user_id; // int(4) primary_key not_null
53 public $send_summary; // tinyint not_null
54 public $last_summary_id; // int(4) null
55 public $created; // datetime not_null
56 public $modified; // datetime not_null
59 * return table definition for DB_DataObject
61 * DB_DataObject needs to know something about the table to manipulate
62 * instances. This method provides all the DB_DataObject needs to know.
64 * @return array array of column definitions
68 return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
69 'send_summary' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
70 'last_summary_id' => DB_DATAOBJECT_INT,
71 'created' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
72 'modified' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
76 * return key definitions for DB_DataObject
78 * @return array list of key field names
82 return array_keys($this->keyTypes());
86 * return key definitions for Memcached_DataObject
88 * Our caching system uses the same key definitions, but uses a different
89 * method to get them. This key information is used to store and clear
90 * cached data, so be sure to list any key that will be used for static
93 * @return array associative array of key definitions, field name to type:
94 * 'K' for primary key: for compound keys, add an entry for each component;
95 * 'U' for unique keys: compound keys are not well supported here.
99 return array('user_id' => 'K');
103 * Magic formula for non-autoincrementing integer primary keys
105 * @return array magic three-false array that stops auto-incrementing.
107 function sequenceKey()
109 return array(false, false, false);
115 * @param integer $user_id ID of the user to get a count for
117 * @return int flag for whether to send this user a summary email
119 static function getSendSummary($user_id)
121 $ess = Email_summary_status::staticGet('user_id', $user_id);
124 return $ess->send_summary;
131 * Get email summary status for a user
133 * @param integer $user_id ID of the user to get a count for
135 * @return Email_summary_status instance for this user, with count already incremented.
137 static function getLastSummaryID($user_id)
139 $ess = Email_summary_status::staticGet('user_id', $user_id);
142 return $ess->last_summary_id;