]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/User_flag_profile.php
...and drop the unnecessary &reference from child class pkeyGet() overrides.
[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
48 class User_flag_profile extends Memcached_DataObject
49 {
50     ###START_AUTOCODE
51     /* the code below is auto generated do not remove the above tag */
52
53     public $__table = 'user_flag_profile';               // table name
54     public $profile_id;                      // int(4)  primary_key not_null
55     public $user_id;                         // int(4)  primary_key not_null
56     public $created;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
57     public $cleared;                         // datetime   not_null default_0000-00-00%2000%3A00%3A00
58
59     /* Static get */
60     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_flag_profile',$k,$v); }
61
62     /* the code above is auto generated do not remove the tag below */
63     ###END_AUTOCODE
64
65     /**
66      * return table definition for DB_DataObject
67      *
68      * @return array array of column definitions
69      */
70
71     function table()
72     {
73         return array(
74                      'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
75                      'user_id'    => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
76                      'created'    => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
77                      'cleared'    => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
78                      );
79     }
80
81     /**
82      * return key definitions for DB_DataObject
83      *
84      * @return array key definitions
85      */
86
87     function keys()
88     {
89         return array('profile_id' => 'N', 'user_id' => 'N');
90     }
91
92     /**
93      * Get a single object with multiple keys
94      *
95      * @param array $kv Map of key-value pairs
96      *
97      * @return User_flag_profile found object or null
98      */
99
100     function pkeyGet($kv)
101     {
102         return Memcached_DataObject::pkeyGet('User_flag_profile', $kv);
103     }
104
105     /**
106      * Check if a flag exists for given profile and user
107      *
108      * @param integer $profile_id Profile to check for
109      * @param integer $user_id    User to check for
110      *
111      * @return boolean true if exists, else false
112      */
113
114     static function exists($profile_id, $user_id)
115     {
116         $ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
117                                                 'user_id' => $user_id));
118
119         return !empty($ufp);
120     }
121
122     static function create($user_id, $profile_id)
123     {
124         $ufp = new User_flag_profile();
125
126         $ufp->profile_id = $profile_id;
127         $ufp->user_id    = $user_id;
128         $ufp->created    = common_sql_now();
129
130         if (!$ufp->insert()) {
131             $msg = sprintf(_("Couldn't flag profile '%d' for review."),
132                            $profile_id);
133             throw new ServerException($msg);
134         }
135
136         $ufp->free();
137
138         return true;
139     }
140 }