Changeset 14840 for events/phpframework

Show
Ignore:
Timestamp:
06/29/08 18:05:21 (5 years ago)
Author:
kumatch
Message:

Refactored.

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

Legend:

Unmodified
Added
Removed
  • events/phpframework/piece_framework/trunk/libs/Phwittr/Self.php

    r14812 r14840  
    163163 
    164164        return $result; 
     165    } 
     166 
     167    // }}} 
     168    // {{{ follow 
     169 
     170    /** 
     171     * 指定ユーザをフォローする 
     172     *  
     173     * @param integer $userId 
     174     * @return boolean 
     175     */ 
     176    public function follow($userId) 
     177    { 
     178        if ($userId == $this->id) { 
     179            throw new Phwittr_Self_Exception(); 
     180        } 
     181 
     182        $follower = Piece_ORM::createObject('Followers'); 
     183        $follower->userId = $this->id; 
     184        $follower->followId = $userId; 
     185        $follower->createdAt = date('Y-m-d H:i:s'); 
     186 
     187        $mapper = Piece_ORM::getMapper('Followers'); 
     188 
     189        try { 
     190            $result = $mapper->insert($follower); 
     191        } catch (Exception $e) { 
     192            if ($e->getCode() === PIECE_ORM_ERROR_CONSTRAINT) { 
     193                throw new Phwittr_Self_Exception(); 
     194            } else { 
     195                throw new Exception(); 
     196            } 
     197        } 
     198    } 
     199 
     200    // }}} 
     201    // {{{ removeFriend 
     202 
     203    /** 
     204     * 指定したユーザを友人リストから消去する 
     205     *  
     206     * @param integer $userId 
     207     * @return boolean 
     208     */ 
     209    public function removeFriend($userId) 
     210    { 
     211        if ($userId == $this->id) { 
     212            throw new Phwittr_Self_Exception(); 
     213        } 
     214 
     215        $follower = Piece_ORM::createObject('Followers'); 
     216        $follower->userId = $this->id; 
     217        $follower->followId = $userId; 
     218 
     219        $mapper = Piece_ORM::getMapper('Followers'); 
     220        $result = $mapper->delete($follower); 
     221 
     222        if ($result) { 
     223            return true; 
     224        } else { 
     225            throw new Phwittr_Self_Exception(); 
     226        } 
     227    } 
     228 
     229    // }}} 
     230    // {{{ isFriend 
     231 
     232    /** 
     233     * 指定ユーザがフレンドかどうか 
     234     *  
     235     * @param  $userId 
     236     * @return boolean 
     237     */ 
     238    public function isFriend($userId) 
     239    { 
     240        $criteria = new stdClass(); 
     241        $criteria->id = $this->id; 
     242        $criteria->userId = $userId; 
     243 
     244        $mapper = Piece_ORM::getMapper('Users'); 
     245        $user = $mapper->findByIdForUserIsFriend($criteria); 
     246 
     247        if ($user) { 
     248            return true; 
     249        } else { 
     250            return false; 
     251        } 
    165252    } 
    166253 
  • events/phpframework/piece_framework/trunk/libs/Phwittr/User.php

    r14812 r14840  
    249249 
    250250        return $status; 
    251     } 
    252  
    253  
    254  
    255  
    256  
    257  
    258  
    259  
    260  
    261  
    262     // }}} 
    263     // {{{ addFriend 
    264  
    265     /** 
    266      * 指定ユーザを友人に加える 
    267      *  
    268      * @param integer $userId 
    269      * @return boolean 
    270      */ 
    271     public function addFriend($userId) 
    272     { 
    273         if ($userId == $this->id) { 
    274             throw new Phwittr_User_Exception(); 
    275         } 
    276  
    277         $follower = Piece_ORM::createObject('Followers'); 
    278  
    279         $follower->userId = $this->id; 
    280         $follower->followId = $userId; 
    281         $follower->createdAt = date('Y-m-d H:i:s'); 
    282  
    283         $mapper = Piece_ORM::getMapper('Followers'); 
    284  
    285         try { 
    286             $result = $mapper->insert($follower); 
    287         } catch (Exception $e) { 
    288             if ($e->getCode() === PIECE_ORM_ERROR_CONSTRAINT) { 
    289                 throw new Phwittr_User_Exception(); 
    290             } else { 
    291                 throw new Exception(); 
    292             } 
    293         } 
    294     } 
    295  
    296     // }}} 
    297     // {{{ removeFriend 
    298  
    299     /** 
    300      * 指定した友人を削除する 
    301      *  
    302      * @param integer $userId 
    303      * @return boolean 
    304      */ 
    305     public function removeFriend($userId) 
    306     { 
    307         if ($userId == $this->id) { 
    308             throw new Phwittr_User_Exception(); 
    309         } 
    310  
    311         $follower = Piece_ORM::createObject('Followers'); 
    312         $follower->userId = $this->id; 
    313         $follower->followId = $userId; 
    314  
    315         $mapper = Piece_ORM::getMapper('Followers'); 
    316         $result = $mapper->delete($follower); 
    317  
    318         if ($result) { 
    319             return true; 
    320         } else { 
    321             throw new Phwittr_User_Exception(); 
    322         } 
    323     } 
    324  
    325     // }}} 
    326     // {{{ isFollower 
    327  
    328     /** 
    329      * 指定ユーザがフレンドかどうか 
    330      *  
    331      * @param  $userId 
    332      * @return boolean 
    333      */ 
    334     public function isFriend($userId) 
    335     { 
    336         $criteria = new stdClass(); 
    337         $criteria->id = $this->id; 
    338         $criteria->userId = $userId; 
    339  
    340         $mapper = Piece_ORM::getMapper('Users'); 
    341         $user = $mapper->findByIdForUserIsFriend($criteria); 
    342  
    343         if ($user) { 
    344             return true; 
    345         } else { 
    346             return false; 
    347         } 
    348251    } 
    349252