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 * Do we need to send a reminder?
43 * @param string $type type of reminder
44 * @param Object $object an object with a 'code' property
45 * (Confirm_address or Invitation)
46 * @param int $days Number of days after the code was created
47 * @return boolean true if any Email_reminder records were found
49 static function needsReminder($type, $object, $days = null) {
51 $reminder = new Email_reminder();
52 $reminder->type = $type;
53 $reminder->code = $object->code;
55 $reminder->days = $days;
57 $result = $reminder->find();
59 if (!empty($result)) {
67 * Record a record of sending the reminder
69 * @param string $type type of reminder
70 * @param Object $object an object with a 'code' property
71 * (Confirm_address or Invitation)
72 * @param int $days Number of days after the code was created
73 * @return int $result row ID of the new reminder record
75 static function recordReminder($type, $object, $days) {
77 $reminder = new Email_reminder();
78 $reminder->type = $type;
79 $reminder->code = $object->code;
80 $reminder->days = $days;
81 $reminder->sent = $reminder->created = common_sql_now();
82 $result = $reminder->insert();
85 common_log_db_error($reminder, 'INSERT', __FILE__);
86 throw new ServerException(
87 // TRANS: Server exception thrown when a reminder record could not be inserted into the database.
88 _m('Database error inserting reminder record.')
96 * Data definition for email reminders
98 public static function schemaDef()
101 'description' => 'Record of email reminders that have been sent',
107 'description' => 'type of reminder'
111 'not null' => 'true',
113 'description' => 'confirmation code'
117 'not null' => 'true',
118 'description' => 'number of days since code creation'
121 'type' => 'datetime',
123 'description' => 'Date and time the reminder was sent'
126 'type' => 'datetime',
128 'description' => 'Date and time the record was created'
131 'type' => 'timestamp',
133 'description' => 'Date and time the record was last modified'
136 'primary key' => array('type', 'code', 'days'),
138 'sent_idx' => array('sent'),