Index: trunk/extensions/SocialProfile/SystemGifts/UserSystemGiftsClass.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * |
| 4 | + * Class for managing awards (a.k.a system gifts) |
5 | 5 | */ |
6 | 6 | class UserSystemGifts { |
7 | 7 | |
— | — | @@ -20,41 +20,42 @@ |
21 | 21 | * @private |
22 | 22 | */ |
23 | 23 | /* private */ function __construct( $username ) { |
24 | | - $title1 = Title::newFromDBkey($username); |
| 24 | + $title1 = Title::newFromDBkey( $username ); |
25 | 25 | $this->user_name = $title1->getText(); |
26 | | - $this->user_id = User::idFromName($this->user_name); |
| 26 | + $this->user_id = User::idFromName( $this->user_name ); |
27 | 27 | } |
28 | 28 | |
29 | 29 | public function sendSystemGift( $gift_id, $email = true ){ |
30 | 30 | global $wgMemc; |
31 | 31 | |
32 | | - if( $this->doesUserHaveGift($this->user_id, $gift_id) ) return ''; |
| 32 | + if( $this->doesUserHaveGift( $this->user_id, $gift_id ) ) return ''; |
33 | 33 | |
34 | 34 | $dbw = wfGetDB( DB_MASTER ); |
35 | 35 | $dbw->insert( 'user_system_gift', |
36 | | - array( |
37 | | - 'sg_gift_id' => $gift_id, |
38 | | - 'sg_user_id' => $this->user_id, |
39 | | - 'sg_user_name' => $this->user_name, |
40 | | - 'sg_status' => 1, |
41 | | - 'sg_date' => date("Y-m-d H:i:s"), |
42 | | - ), __METHOD__ |
| 36 | + array( |
| 37 | + 'sg_gift_id' => $gift_id, |
| 38 | + 'sg_user_id' => $this->user_id, |
| 39 | + 'sg_user_name' => $this->user_name, |
| 40 | + 'sg_status' => 1, |
| 41 | + 'sg_date' => date("Y-m-d H:i:s"), |
| 42 | + ), |
| 43 | + __METHOD__ |
43 | 44 | ); |
44 | 45 | $sg_gift_id = $dbw->insertId(); |
45 | | - $this->incGiftGivenCount($gift_id); |
| 46 | + $this->incGiftGivenCount( $gift_id ); |
46 | 47 | |
47 | | - //add to new gift count cache for receiving user |
48 | | - $this->incNewSystemGiftCount($this->user_id); |
| 48 | + // Add to new gift count cache for receiving user |
| 49 | + $this->incNewSystemGiftCount( $this->user_id ); |
49 | 50 | |
50 | | - if( $email && !empty( $sg_gift_id ) ) $this->sendGiftNotificationEmail( $this->user_id, $gift_id ); |
| 51 | + if( $email && !empty( $sg_gift_id ) ) $this->sendGiftNotificationEmail( $this->user_id, $gift_id ); |
51 | 52 | $wgMemc->delete( wfMemcKey( 'user', 'profile', 'system_gifts', $this->user_id ) ); |
52 | 53 | return $sg_gift_id; |
53 | 54 | } |
54 | 55 | |
55 | 56 | public function sendGiftNotificationEmail( $user_id_to, $gift_id ){ |
56 | | - wfLoadExtensionMessages('SystemGifts'); |
57 | | - $gift = SystemGifts::getGift($gift_id); |
58 | | - $user = User::newFromId($user_id_to); |
| 57 | + wfLoadExtensionMessages( 'SystemGifts' ); |
| 58 | + $gift = SystemGifts::getGift( $gift_id ); |
| 59 | + $user = User::newFromId( $user_id_to ); |
59 | 60 | $user->loadFromDatabase(); |
60 | 61 | if( $user->isEmailConfirmed() && $user->getIntOption( 'notifygift', 1 ) ){ |
61 | 62 | $gifts_link = SpecialPage::getTitleFor( 'ViewSystemGifts' ); |
— | — | @@ -90,9 +91,9 @@ |
91 | 92 | 'sg_status' => 0 |
92 | 93 | ), array( /* WHERE */ |
93 | 94 | 'sg_user_id' => $this->user_id |
94 | | - ), "" |
| 95 | + ), __METHOD__ |
95 | 96 | ); |
96 | | - $this->clearNewSystemGiftCountCache($this->user_id); |
| 97 | + $this->clearNewSystemGiftCountCache( $this->user_id ); |
97 | 98 | } |
98 | 99 | |
99 | 100 | static function clearUserGiftStatus( $id ){ |
— | — | @@ -102,7 +103,7 @@ |
103 | 104 | 'sg_status' => 0 |
104 | 105 | ), array( /* WHERE */ |
105 | 106 | 'sg_id' => $id |
106 | | - ), "" |
| 107 | + ), __METHOD__ |
107 | 108 | ); |
108 | 109 | } |
109 | 110 | |
— | — | @@ -110,7 +111,7 @@ |
111 | 112 | $dbr = wfGetDB( DB_SLAVE ); |
112 | 113 | $s = $dbr->selectRow( 'user_system_gift', array( 'sg_user_id' ), array( 'sg_id' => $sg_id ), __METHOD__ ); |
113 | 114 | if ( $s !== false ) { |
114 | | - if($user_id == $s->ug_user_id_to){ |
| 115 | + if( $user_id == $s->ug_user_id_to ){ |
115 | 116 | return true; |
116 | 117 | } |
117 | 118 | } |
— | — | @@ -131,15 +132,15 @@ |
132 | 133 | $res = $dbr->query($sql); |
133 | 134 | $row = $dbr->fetchObject( $res ); |
134 | 135 | if( $row ){ |
135 | | - $gift['id']= $row->sg_id; |
136 | | - $gift['user_id']= $row->sg_user_id; |
137 | | - $gift['user_name']= $row->sg_user_name; |
138 | | - $gift['gift_count']= $row->gift_given_count; |
139 | | - $gift['timestamp']= $row->sg_date; |
140 | | - $gift['gift_id']= $row->gift_id; |
141 | | - $gift['name']= $row->gift_name; |
142 | | - $gift['description']= $row->gift_description; |
143 | | - $gift['status']= $row->sg_status; |
| 136 | + $gift['id'] = $row->sg_id; |
| 137 | + $gift['user_id'] = $row->sg_user_id; |
| 138 | + $gift['user_name'] = $row->sg_user_name; |
| 139 | + $gift['gift_count'] = $row->gift_given_count; |
| 140 | + $gift['timestamp'] = $row->sg_date; |
| 141 | + $gift['gift_id'] = $row->gift_id; |
| 142 | + $gift['name'] = $row->gift_name; |
| 143 | + $gift['description'] = $row->gift_description; |
| 144 | + $gift['status'] = $row->sg_status; |
144 | 145 | } |
145 | 146 | |
146 | 147 | return $gift; |
— | — | @@ -175,12 +176,12 @@ |
176 | 177 | |
177 | 178 | static function getNewSystemGiftCount( $user_id ){ |
178 | 179 | global $wgMemc; |
179 | | - $data = self::getNewSystemGiftCountCache($user_id); |
| 180 | + $data = self::getNewSystemGiftCountCache( $user_id ); |
180 | 181 | |
181 | 182 | if( $data != '' ){ |
182 | 183 | $count = $data; |
183 | 184 | } else { |
184 | | - $count = self::getNewSystemGiftCountDB($user_id); |
| 185 | + $count = self::getNewSystemGiftCountDB( $user_id ); |
185 | 186 | } |
186 | 187 | return $count; |
187 | 188 | } |
— | — | @@ -193,9 +194,9 @@ |
194 | 195 | $dbr = wfGetDB( DB_SLAVE ); |
195 | 196 | $new_gift_count = 0; |
196 | 197 | $s = $dbr->selectRow( 'user_system_gift', array( 'count(*) AS count' ), array( 'sg_user_id' => $user_id, 'sg_status' => 1 ), __METHOD__ ); |
197 | | - if ( $s !== false )$new_gift_count = $s->count; |
| 198 | + if ( $s !== false ) $new_gift_count = $s->count; |
198 | 199 | |
199 | | - $wgMemc->set($key, $new_gift_count); |
| 200 | + $wgMemc->set( $key, $new_gift_count ); |
200 | 201 | |
201 | 202 | return $new_gift_count; |
202 | 203 | } |
— | — | @@ -224,7 +225,7 @@ |
225 | 226 | 'gift_id' => $row->sg_gift_id, |
226 | 227 | 'timestamp' => ($row->sg_date), |
227 | 228 | 'status' => $row->sg_status, |
228 | | - 'user_id' => $row->sg_user, |
| 229 | + 'user_id' => $row->sg_user_id, |
229 | 230 | 'user_name' => $row->sg_user_name, |
230 | 231 | 'gift_name' => $row->gift_name, |
231 | 232 | 'gift_description' => $row->gift_description, |
— | — | @@ -240,12 +241,13 @@ |
241 | 242 | $dbw->update( 'system_gift', |
242 | 243 | array( 'gift_given_count=gift_given_count+1' ), |
243 | 244 | array( 'gift_id' => $gift_id ), |
244 | | - __METHOD__ ); |
| 245 | + __METHOD__ |
| 246 | + ); |
245 | 247 | } |
246 | 248 | |
247 | 249 | static function getGiftCountByUsername( $user_name ){ |
248 | 250 | $dbr = wfGetDB( DB_SLAVE ); |
249 | | - $user_id = User::idFromName($user_name); |
| 251 | + $user_id = User::idFromName( $user_name ); |
250 | 252 | $sql = "SELECT count(*) AS count |
251 | 253 | FROM {$dbr->tableName( 'user_system_gift' )} |
252 | 254 | WHERE sg_user_id = {$user_id} |
— | — | @@ -256,7 +258,7 @@ |
257 | 259 | if( $row ){ |
258 | 260 | $gift_count = $row->count; |
259 | 261 | } |
260 | | - return $gift_count; |
| 262 | + return $gift_count; |
261 | 263 | } |
262 | 264 | |
263 | 265 | } |
\ No newline at end of file |