Changeset 15410

Show
Ignore:
Timestamp:
07/07/08 23:04:15 (5 years ago)
Author:
kumatch
Message:

- Added the cancel() method.
- Changed the accept/deny argument from user_id to request_id.

Location:
events/phpframework/piece_framework/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/piece_framework/trunk/config/orm/mappers/Users.yaml

    r15235 r15410  
    7878  query: > 
    7979    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 
    8384    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  
    248248 
    249249    // }}} 
     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    // }}} 
    250274    // {{{ accept 
    251275 
    252276    /** 
    253      * 指定ユーザのフォローを許可する 
    254      *  
    255      * @param integer $userId 
     277     * 指定フレンドリクエストを許可する 
     278     *  
     279     * @param integer $requestId 
    256280     * @return boolean 
    257281     */ 
    258     public function accept($userId) 
     282    public function accept($requestId) 
    259283    { 
    260284        $requestMapper = Piece_ORM::getMapper('FriendRequests'); 
    261         $criteria->userId = $this->id; 
    262         $criteria->requesterId = $userId; 
    263         $friendRequest = $requestMapper->findByUserIdAndRequesterId($criteria); 
     285        $friendRequest = $requestMapper->findById($requestId); 
    264286        if (!$friendRequest) { 
    265287            throw new Phwittr_Self_Exception(); 
    266288        } 
    267289 
     290        if ($friendRequest->userId !== $this->id) { 
     291            throw new Phwittr_Self_Exception(); 
     292        } 
     293 
    268294        $entity = Piece_ORM::createObject('Followers'); 
    269         $entity->userId = $userId; 
    270         $entity->followId = $this->id; 
     295        $entity->userId = $friendRequest->requesterId; 
     296        $entity->followId = $friendRequest->userId; 
    271297        $entity->createdAt = date('Y-m-d H:i:s'); 
    272298 
     
    276302            $followerMapper->insert($entity); 
    277303            $requestMapper->delete($friendRequest); 
    278              
    279304        } catch (Exception $e) { 
    280305            if ($e->getCode() === PIECE_ORM_ERROR_CONSTRAINT) { 
     
    290315 
    291316    /** 
    292      * 指定ユーザのフォローを拒否する 
    293      *  
    294      * @param integer $userId 
     317     * 指定フレンドリクエストを拒否する 
     318     *  
     319     * @param integer $requestId 
    295320     * @return boolean 
    296321     */ 
    297     public function deny($userId) 
     322    public function deny($requestId) 
    298323    { 
    299324        $requestMapper = Piece_ORM::getMapper('FriendRequests'); 
    300         $criteria->userId = $this->id; 
    301         $criteria->requesterId = $userId; 
    302         $friendRequest = $requestMapper->findByUserIdAndRequesterId($criteria); 
     325        $friendRequest = $requestMapper->findById($requestId); 
    303326        if (!$friendRequest) { 
    304327            throw new Phwittr_Self_Exception(); 
    305328        } 
    306329 
    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); 
    317335    } 
    318336