3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Data class for email reminders
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @package EmailReminder
23 * @author Zach Copley <zach@status.net>
24 * @copyright 2011 StatusNet, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26 * @link http://status.net/
29 class Email_reminder extends Managed_DataObject
31 const INVITE_REMINDER = 'invite'; // @todo Move this to the invite reminder handler
33 public $__table = 'email_reminder';
35 public $type; // type of reminder
36 public $code; // confirmation code
37 public $days; // number of days after code was created
38 public $sent; // timestamp
39 public $created; // timestamp
40 public $modified; // timestamp
43 * Get an instance by key
45 * This is a utility method to get a single instance with a given key value.
47 * @param string $k Key to use to lookup
48 * @param mixed $v Value to lookup
50 * @return QnA_Answer object found, or null for no hits
53 function staticGet($k, $v=null)
55 return Memcached_DataObject::staticGet('email_reminder', $k, $v);
61 * @param type $confirm
65 static function needsReminder($type, $confirm, $days) {
67 $reminder = new Email_reminder();
68 $reminder->type = $type;
69 $reminder->code = $confirm->code;
70 $reminder->days = $days;
72 $result = $reminder->find(true);
84 * @param type $confirm
88 static function recordReminder($type, $confirm, $days) {
90 $reminder = new Email_reminder();
91 $reminder->type = $type;
92 $reminder->code = $confirm->code;
93 $reminder->days = $days;
94 $reminder->sent = $reminder->created = common_sql_now();
95 $result = $reminder->insert();
98 common_log_db_error($reminder, 'INSERT', __FILE__);
99 throw new ServerException(
100 _m('Database error inserting reminder record.')
108 * Data definition for email reminders
110 public static function schemaDef()
113 'description' => 'Record of email reminders that have been sent',
119 'description' => 'type of reminder'
123 'not null' => 'true',
125 'description' => 'confirmation code'
129 'not null' => 'true',
130 'description' => 'number of days since code creation'
133 'type' => 'datetime',
135 'description' => 'Date and time the reminder was sent'
138 'type' => 'datetime',
140 'description' => 'Date and time the record was created'
143 'type' => 'timestamp',
145 'description' => 'Date and time the record was last modified'
148 'primary key' => array('type', 'code', 'days'),
150 'sent_idx' => array('sent'),