3 * Data class for profile flags
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) 2009, 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 profile flags
39 * A class representing a user flagging another profile for review.
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45 * @link http://status.net/
47 class User_flag_profile extends Memcached_DataObject
50 /* the code below is auto generated do not remove the above tag */
52 public $__table = 'user_flag_profile'; // table name
53 public $profile_id; // int(4) primary_key not_null
54 public $user_id; // int(4) primary_key not_null
55 public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
56 public $cleared; // datetime not_null default_0000-00-00%2000%3A00%3A00
59 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_flag_profile',$k,$v); }
61 /* the code above is auto generated do not remove the tag below */
65 * return table definition for DB_DataObject
67 * @return array array of column definitions
72 'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
73 'user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
74 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
75 'cleared' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
80 * return key definitions for DB_DataObject
82 * @return array key definitions
86 return array('profile_id' => 'K', 'user_id' => 'K');
90 * return key definitions for DB_DataObject
92 * @return array key definitions
100 * Get a single object with multiple keys
102 * @param array $kv Map of key-value pairs
104 * @return User_flag_profile found object or null
106 function pkeyGet($kv)
108 return Memcached_DataObject::pkeyGet('User_flag_profile', $kv);
112 * Check if a flag exists for given profile and user
114 * @param integer $profile_id Profile to check for
115 * @param integer $user_id User to check for
117 * @return boolean true if exists, else false
119 static function exists($profile_id, $user_id)
121 $ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
122 'user_id' => $user_id));
130 * @param integer $user_id ID of user who's flagging
131 * @param integer $profile_id ID of profile being flagged
133 * @return boolean success flag
135 static function create($user_id, $profile_id)
137 $ufp = new User_flag_profile();
139 $ufp->profile_id = $profile_id;
140 $ufp->user_id = $user_id;
141 $ufp->created = common_sql_now();
143 if (!$ufp->insert()) {
144 // TRANS: Server exception.
145 $msg = sprintf(_m('Couldn\'t flag profile "%d" for review.'),
147 throw new ServerException($msg);