Changeset 15410
- Timestamp:
- 07/07/08 23:04:15 (5 years ago)
- Location:
- events/phpframework/piece_framework/trunk
- Files:
-
- 2 modified
-
config/orm/mappers/Users.yaml (modified) (1 diff)
-
libs/Phwittr/Self.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/piece_framework/trunk/config/orm/mappers/Users.yaml
r15235 r15410 78 78 query: > 79 79 SELECT 80 id, 81 user_name, 82 image 80 friend_requests.id as id, 81 users.id as user_id, 82 users.user_name, 83 users.image 83 84 FROM 84 users, friend_requests 85 WHERE 86 users.id = friend_requests.requester_id 87 AND friend_requests.user_id = $id 85 users 86 JOIN friend_requests ON friend_requests.requester_id = users.id 87 WHERE EXISTS 88 (SELECT * 89 FROM friend_requests 90 WHERE friend_requests.user_id = $id 91 ) -
events/phpframework/piece_framework/trunk/libs/Phwittr/Self.php
r15306 r15410 248 248 249 249 // }}} 250 // {{{ cancel 251 252 /** 253 * 指定フレンドリクエストをキャンセルする 254 * 255 * @param integer $requestId 256 * @return boolean 257 */ 258 public function cancel($requestId) 259 { 260 $requestMapper = Piece_ORM::getMapper('FriendRequests'); 261 $friendRequest = $requestMapper->findById($requestId); 262 if (!$friendRequest) { 263 throw new Phwittr_Self_Exception(); 264 } 265 266 if ($friendRequest->requesterId !== $this->id) { 267 throw new Phwittr_Self_Exception(); 268 } 269 270 $requestMapper->delete($friendRequest); 271 } 272 273 // }}} 250 274 // {{{ accept 251 275 252 276 /** 253 * 指定 ユーザのフォローを許可する254 * 255 * @param integer $ userId277 * 指定フレンドリクエストを許可する 278 * 279 * @param integer $requestId 256 280 * @return boolean 257 281 */ 258 public function accept($ userId)282 public function accept($requestId) 259 283 { 260 284 $requestMapper = Piece_ORM::getMapper('FriendRequests'); 261 $criteria->userId = $this->id; 262 $criteria->requesterId = $userId; 263 $friendRequest = $requestMapper->findByUserIdAndRequesterId($criteria); 285 $friendRequest = $requestMapper->findById($requestId); 264 286 if (!$friendRequest) { 265 287 throw new Phwittr_Self_Exception(); 266 288 } 267 289 290 if ($friendRequest->userId !== $this->id) { 291 throw new Phwittr_Self_Exception(); 292 } 293 268 294 $entity = Piece_ORM::createObject('Followers'); 269 $entity->userId = $ userId;270 $entity->followId = $ this->id;295 $entity->userId = $friendRequest->requesterId; 296 $entity->followId = $friendRequest->userId; 271 297 $entity->createdAt = date('Y-m-d H:i:s'); 272 298 … … 276 302 $followerMapper->insert($entity); 277 303 $requestMapper->delete($friendRequest); 278 279 304 } catch (Exception $e) { 280 305 if ($e->getCode() === PIECE_ORM_ERROR_CONSTRAINT) { … … 290 315 291 316 /** 292 * 指定 ユーザのフォローを拒否する293 * 294 * @param integer $ userId317 * 指定フレンドリクエストを拒否する 318 * 319 * @param integer $requestId 295 320 * @return boolean 296 321 */ 297 public function deny($ userId)322 public function deny($requestId) 298 323 { 299 324 $requestMapper = Piece_ORM::getMapper('FriendRequests'); 300 $criteria->userId = $this->id; 301 $criteria->requesterId = $userId; 302 $friendRequest = $requestMapper->findByUserIdAndRequesterId($criteria); 325 $friendRequest = $requestMapper->findById($requestId); 303 326 if (!$friendRequest) { 304 327 throw new Phwittr_Self_Exception(); 305 328 } 306 329 307 try { 308 $requestMapper->delete($friendRequest); 309 310 } catch (Exception $e) { 311 if ($e->getCode() === PIECE_ORM_ERROR_CONSTRAINT) { 312 throw new Phwittr_Self_Exception(); 313 } else { 314 throw new Exception(); 315 } 316 } 330 if ($friendRequest->userId !== $this->id) { 331 throw new Phwittr_Self_Exception(); 332 } 333 334 $requestMapper->delete($friendRequest); 317 335 } 318 336
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)