Changeset 14808

Show
Ignore:
Timestamp:
06/29/08 01:09:50 (5 years ago)
Author:
kumatch
Message:

Added update()/delete() methods.

Files:
1 modified

Legend:

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

    r14793 r14808  
    6767        $user = $mapper->findById($id); 
    6868        if (is_null($user)) { 
    69             throw new Phwittr_User_Exception(); 
     69            throw new Phwittr_Self_Exception(); 
    7070        } 
    7171 
     
    121121    } 
    122122 
     123    // }}} 
     124    // {{{ update 
     125 
     126    /** 
     127     * ステータスを更新する 
     128     *  
     129     * @param string $comment 
     130     * @return mixed 
     131     */ 
     132    public function update($comment) 
     133    { 
     134        $status = Piece_ORM::createObject('Statuses'); 
     135        $status->userId = $this->id; 
     136        $status->comment = $comment; 
     137        $status->replyUserId = $this->_findReplyUserId($comment); 
     138        $status->createdAt = date('Y-m-d H:i:s'); 
     139 
     140        $mapper = Piece_ORM::getMapper('Statuses'); 
     141        return $mapper->insert($status); 
     142    } 
     143 
     144    // }}} 
     145    // {{{ delete 
     146 
     147    /** 
     148     * ステータスを削除する 
     149     *  
     150     * @param integer $id 
     151     * @return mixed 
     152     */ 
     153    public function delete($id) 
     154    { 
     155        $criteria->id = $id; 
     156        $criteria->userId = $this->id; 
     157 
     158        $mapper = Piece_ORM::getMapper('Statuses'); 
     159        $result = $mapper->deleteByIdAndUserId($criteria); 
     160        if (!$result) { 
     161            throw new Phwittr_Self_Exception(); 
     162        } 
     163 
     164        return $result; 
     165    } 
     166 
    123167    /**#@-*/ 
    124168 
     
    126170     * @access private 
    127171     */ 
     172 
     173    // }}} 
     174    // {{{ _findReplyUserIdByComment 
     175 
     176    /** 
     177     * コメントから返信先ユーザIdを取得する 
     178     *  
     179     * @param string $comment 
     180     * @return mixed 
     181     */ 
     182    private function _findReplyUserId($comment) 
     183    { 
     184        $replyUserId = null; 
     185        if (preg_match('/^@([0-9a-zA-Z_]{1,20}+).*$/', $comment, $matches)) { 
     186            $replyUserName = $matches[1]; 
     187 
     188            $mapper = Piece_ORM::getMapper('Users'); 
     189            $replyUser = $mapper->findByUserName($replyUserName); 
     190            if ($replyUser) { 
     191                $replyUserId = $replyUser->id; 
     192            } 
     193        } 
     194 
     195        return $replyUserId; 
     196    } 
    128197 
    129198    /**#@-*/