3 * Who received a group message
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) 2011, 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 group direct messages for users
39 * @category GroupPrivateMessage
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://status.net/
47 class Group_message_profile extends Memcached_DataObject
49 public $__table = 'group_message_profile'; // table name
50 public $to_profile; // int
51 public $group_message_id; // char(36) primary_key not_null
55 * Get an instance by key
57 * This is a utility method to get a single instance with a given key value.
59 * @param string $k Key to use to lookup (usually 'user_id' for this class)
60 * @param mixed $v Value to lookup
62 * @return Group_message object found, or null for no hits
64 function staticGet($k, $v=null)
66 return Memcached_DataObject::staticGet('Group_message_profile', $k, $v);
70 * return table definition for DB_DataObject
72 * DB_DataObject needs to know something about the table to manipulate
73 * instances. This method provides all the DB_DataObject needs to know.
75 * @return array array of column definitions
79 return array('to_profile' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
80 'group_message_id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
81 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
85 * return key definitions for DB_DataObject
87 * DB_DataObject needs to know about keys that the table has, since it
88 * won't appear in StatusNet's own keys list. In most cases, this will
89 * simply reference your keyTypes() function.
91 * @return array list of key field names
95 return array_keys($this->keyTypes());
99 * return key definitions for Memcached_DataObject
101 * @return array associative array of key definitions, field name to type:
102 * 'K' for primary key: for compound keys, add an entry for each component;
103 * 'U' for unique keys: compound keys are not well supported here.
107 return array('to_profile' => 'K', 'group_message_id' => 'K');
111 * No sequence keys in this table.
113 function sequenceKey()
115 return array(false, false, false);
118 function send($gm, $profile)
120 $gmp = new Group_message_profile();
122 $gmp->group_message_id = $gm->id;
123 $gmp->to_profile = $profile->id;
124 $gmp->created = common_sql_now();
128 // If it's not for the author, send email notification
129 if ($gm->from_profile != $profile->id) {
138 // XXX: add more here
139 $this->notifyByMail();
142 function notifyByMail()
144 $to = User::staticGet('id', $this->to_profile);
146 if (empty($to) || is_null($to->email) || !$to->emailnotifymsg) {
150 $gm = Group_message::staticGet('id', $this->group_message_id);
152 $from_profile = Profile::staticGet('id', $gm->from_profile);
154 $group = $gm->getGroup();
156 common_switch_locale($to->language);
158 // TRANS: Subject for direct-message notification email.
159 // TRANS: %1$s is the sending user's nickname, %2$s is the group nickname.
160 $subject = sprintf(_m('New private message from %1$s to group %2$s'), $from_profile->nickname, $group->nickname);
162 // TRANS: Body for direct-message notification email.
163 // TRANS: %1$s is the sending user's long name, %2$s is the sending user's nickname,
164 // TRANS: %3$s is the message content, %4$s a URL to the message,
165 // TRANS: %5$s is the StatusNet sitename.
166 $body = sprintf(_m("%1\$s (%2\$s) sent a private message to group %3\$s:\n\n".
167 "------------------------------------------------------\n".
169 "------------------------------------------------------\n\n".
170 "You can reply to their message here:\n\n".
172 "Do not reply to this email; it will not get to them.\n\n".
173 "With kind regards,\n".
175 $from_profile->getBestName(),
176 $from_profile->nickname,
179 common_local_url('newmessage', array('to' => $from_profile->id)),
180 common_config('site', 'name')) . "\n";
182 $headers = _mail_prepare_headers('message', $to->nickname, $from_profile->nickname);
184 common_switch_locale();
186 return mail_to_user($to, $subject, $body, $headers);