]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/User_flag_profile.php
More info for a proper, fancy-url lighttpd setup
[quix0rs-gnu-social.git] / plugins / UserFlag / User_flag_profile.php
1 <?php
2 /**
3  * Data class for profile flags
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) 2009, 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 profile flags
38  *
39  * A class representing a user flagging another profile for review.
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 class User_flag_profile extends Managed_DataObject
48 {
49     ###START_AUTOCODE
50     /* the code below is auto generated do not remove the above tag */
51
52     public $__table = 'user_flag_profile';               // table name
53     public $profile_id;                      // int(11)  primary_key not_null
54     public $user_id;                         // int(11)  primary_key not_null
55     public $cleared;                         // datetime   default_0000-00-00%2000%3A00%3A00
56     public $created;                         // datetime()   not_null
57     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
58
59     /* the code above is auto generated do not remove the tag below */
60     ###END_AUTOCODE
61
62     public static function schemaDef()
63     {
64         return array(
65             'fields' => array(
66                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile id flagged'),
67                 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id of the actor'),
68                 'cleared' => array('type' => 'datetime', 'description' => 'when flag was removed'),
69                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
70                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
71             ),
72             'primary key' => array('profile_id', 'user_id'),
73             'indexes' => array(
74                 'user_flag_profile_cleared_idx' => array('cleared'),
75                 'user_flag_profile_created_idx' => array('created'),
76             ),
77         );
78     }
79
80     /**
81      * Check if a flag exists for given profile and user
82      *
83      * @param integer $profile_id Profile to check for
84      * @param integer $user_id    User to check for
85      *
86      * @return boolean true if exists, else false
87      */
88     static function exists($profile_id, $user_id)
89     {
90         $ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
91                                                 'user_id' => $user_id));
92
93         return !empty($ufp);
94     }
95
96     /**
97      * Create a new flag
98      *
99      * @param integer $user_id    ID of user who's flagging
100      * @param integer $profile_id ID of profile being flagged
101      *
102      * @return boolean success flag
103      */
104     static function create($user_id, $profile_id)
105     {
106         $ufp = new User_flag_profile();
107
108         $ufp->profile_id = $profile_id;
109         $ufp->user_id    = $user_id;
110         $ufp->created    = common_sql_now();
111
112         if (!$ufp->insert()) {
113             // TRANS: Server exception.
114             // TRANS: %d is a profile ID (number).
115             $msg = sprintf(_m('Could not flag profile "%d" for review.'),
116                            $profile_id);
117             throw new ServerException($msg);
118         }
119
120         $ufp->free();
121
122         return true;
123     }
124 }