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 public $__table = 'email_reminder';
33 public $type; // type of reminder
34 public $code; // confirmation code
35 public $days; // number of days after code was created
36 public $sent; // timestamp
37 public $created; // timestamp
38 public $modified; // timestamp
41 * Get an instance by key
43 * This is a utility method to get a single instance with a given key value.
45 * @param string $k Key to use to lookup
46 * @param mixed $v Value to lookup
48 * @return QnA_Answer object found, or null for no hits
50 function staticGet($k, $v=null)
52 return Memcached_DataObject::staticGet('email_reminder', $k, $v);
56 * Do we need to send a reminder?
58 * @param string $type type of reminder
59 * @param Object $object an object with a 'code' property
60 * (Confirm_address or Invitation)
61 * @param int $days Number of days after the code was created
62 * @return boolean true if any Email_reminder records were found
64 static function needsReminder($type, $object, $days = null) {
66 $reminder = new Email_reminder();
67 $reminder->type = $type;
68 $reminder->code = $object->code;
70 $reminder->days = $days;
72 $result = $reminder->find();
74 if (!empty($result)) {
82 * Record a record of sending the reminder
84 * @param string $type type of reminder
85 * @param Object $object an object with a 'code' property
86 * (Confirm_address or Invitation)
87 * @param int $days Number of days after the code was created
88 * @return int $result row ID of the new reminder record
90 static function recordReminder($type, $object, $days) {
92 $reminder = new Email_reminder();
93 $reminder->type = $type;
94 $reminder->code = $object->code;
95 $reminder->days = $days;
96 $reminder->sent = $reminder->created = common_sql_now();
97 $result = $reminder->insert();
100 common_log_db_error($reminder, 'INSERT', __FILE__);
101 throw new ServerException(
102 // TRANS: Server exception thrown when a reminder record could not be inserted into the database.
103 _m('Database error inserting reminder record.')
111 * Data definition for email reminders
113 public static function schemaDef()
116 'description' => 'Record of email reminders that have been sent',
122 'description' => 'type of reminder'
126 'not null' => 'true',
128 'description' => 'confirmation code'
132 'not null' => 'true',
133 'description' => 'number of days since code creation'
136 'type' => 'datetime',
138 'description' => 'Date and time the reminder was sent'
141 'type' => 'datetime',
143 'description' => 'Date and time the record was created'
146 'type' => 'timestamp',
148 'description' => 'Date and time the record was last modified'
151 'primary key' => array('type', 'code', 'days'),
153 'sent_idx' => array('sent'),