]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailSummary/Email_summary_status.php
460053f9f858de1aae2de808b0ead313eb3374d6
[quix0rs-gnu-social.git] / plugins / EmailSummary / Email_summary_status.php
1 <?php
2 /**
3  * Data class for email summary status
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Data class for email summaries
38  *
39  * Email summary information for users
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  *
47  * @see      DB_DataObject
48  */
49 class Email_summary_status extends Managed_DataObject
50 {
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
57
58     public static function schemaDef()
59     {
60         return array(
61             'fields' => array(
62                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
63                 'send_summary' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'not null' => true, 'description' => 'whether to send a summary or not'),
64                 'last_summary_id' => array('type' => 'int', 'description' => 'last summary id'),
65                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),   
66                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
67             ),
68             'primary key' => array('user_id'),
69             'foreign keys' => array(
70                 'email_summary_status_user_id_fkey' => array('user', array('user_id' => 'id')),
71             ),
72         );
73     }
74
75     /**
76      * Helper function
77      *
78      * @param integer $user_id ID of the user to get a count for
79      *
80      * @return int flag for whether to send this user a summary email
81      */
82     static function getSendSummary($user_id)
83     {
84         $ess = Email_summary_status::getKV('user_id', $user_id);
85
86         if (!empty($ess)) {
87             return $ess->send_summary;
88         } else {
89             return 1;
90         }
91     }
92
93     /**
94      * Get email summary status for a user
95      *
96      * @param integer $user_id ID of the user to get a count for
97      *
98      * @return Email_summary_status instance for this user, with count already incremented.
99      */
100     static function getLastSummaryID($user_id)
101     {
102         $ess = Email_summary_status::getKV('user_id', $user_id);
103
104         if (!empty($ess)) {
105             return $ess->last_summary_id;
106         } else {
107             return null;
108         }
109     }
110 }