Changeset 14154

Show
Ignore:
Timestamp:
06/17/08 01:44:03 (5 years ago)
Author:
kumatch
Message:

Added the limit count of status at a page.

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

Legend:

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

    r13426 r14154  
    77 * @package    Phwittr_PieceFramework 
    88 * @copyright  2008 KUMAKURA Yousuke All rights reserved. 
    9  * @version    SVN: $Id:$ 
     9 * @version    SVN: $Id$ 
    1010 * @since      File available since Release 0.1.0 
    1111 */ 
     
    4848    protected $_watcherId; 
    4949 
     50    protected $_limit = 20; 
     51 
    5052    /**#@-*/ 
    5153 
     
    8082 
    8183        $mapper = Piece_ORM::getMapper('Users'); 
    82  
    8384        $user = $mapper->findById($this->_userId); 
    8485        if (is_null($user)) { 
     
    155156     * フォローしているユーザと自身の発言リストを取得する 
    156157     *  
    157      * @return mixed 
    158      */ 
    159     public function listByFollowers() 
     158     * @param  integer $page 
     159     * @return mixed 
     160     */ 
     161    public function listByFollowers($page = 1) 
    160162    { 
    161163        $status = Piece_ORM::createObject('Statuses'); 
    162164        $status->userId = $this->_userId; 
    163165 
    164         $mapper = Piece_ORM::getMapper('Statuses'); 
     166        $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 
    165167        return $mapper->findAllByUserIdForListFollowersStatus($status); 
    166168    } 
     
    172174     * 自身への返信リストを取得する 
    173175     *  
    174      * @return mixed 
    175      */ 
    176     public function listReplies() 
     176     * @param  integer $page 
     177     * @return mixed 
     178     */ 
     179    public function listReplies($page = 1) 
    177180    { 
    178181        $status = Piece_ORM::createObject('Statuses'); 
    179182        $status->replyUserId = $this->_userId; 
    180183 
    181         $mapper = Piece_ORM::getMapper('Statuses'); 
     184        $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 
    182185        return $mapper->findAllByReplyUserIdForListReplies($status); 
    183186    } 
     
    189192     * 自身の発言リストを取得する 
    190193     *  
    191      * @return mixed 
    192      */ 
    193     public function listArchives() 
     194     * @param  integer $page 
     195     * @return mixed 
     196     */ 
     197    public function listArchives($page = 1) 
    194198    { 
    195199        $criteria = new stdClass(); 
     
    197201        $criteria->watcherId = $this->_watcherId; 
    198202 
    199         $mapper = Piece_ORM::getMapper('Statuses'); 
     203        $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 
    200204        return $mapper->findAllByUserIdForListArchives($criteria); 
    201205    } 
     
    207211     * すべての人の発言リストを取得する 
    208212     *  
    209      * @return mixed 
    210      */ 
    211     public function listPublicTimeline() 
    212     { 
    213         $mapper = Piece_ORM::getMapper('Statuses'); 
     213     * @param  integer $page 
     214     * @return mixed 
     215     */ 
     216    public function listPublicTimeline($page = 1) 
     217    { 
     218        $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 
    214219        return $mapper->findAllForListPublicTimeline(); 
    215220    } 
     
    263268 
    264269        return $replyUserId; 
     270    } 
     271 
     272    // }}} 
     273    // {{{ _createListMapper 
     274 
     275    /** 
     276     * ステータスリスト用マッパーを作成する 
     277     *  
     278     * @return object 
     279     */ 
     280    private function _createListMapper($offset = null) 
     281    { 
     282        $mapper = Piece_ORM::getMapper('Statuses'); 
     283 
     284        $mapper->setLimit($this->_limit, $offset); 
     285        $mapper->addOrder('statuses.created_at', true); 
     286 
     287        return $mapper; 
    265288    } 
    266289 
  • events/phpframework/piece_framework/trunk/specs/Phwittr/SpecCommon.php

    r14093 r14154  
    139139    } 
    140140 
    141     protected function _createStatusRecord($userId, $replyId, $comment) 
     141    protected function _createStatusRecord($userId, $replyId, $comment, $timeLag = 0) 
    142142    { 
    143143        $status = Piece_ORM::createObject('Statuses'); 
     
    148148        $mapper = Piece_ORM::getMapper('Statuses'); 
    149149        $mapper->insert($status); 
     150 
     151        if ($timeLag) { 
     152            $status->createdAt = date('Y-m-d H:i:s', time() + $timeLag); 
     153            $mapper->update($status); 
     154        } 
    150155    } 
    151156 
  • events/phpframework/piece_framework/trunk/specs/Phwittr/StatusListSpec.php

    r13431 r14154  
    77 * @package    Phwittr_PieceFramework 
    88 * @copyright  2008 KUMAKURA Yousuke All rights reserved. 
    9  * @version    SVN: $Id:$ 
     9 * @version    SVN: $Id$ 
    1010 * @since      File available since Release 0.1.0 
    1111 */ 
     
    249249        $this->_createStatusRecord($barUser->id, null, 'bar4'); 
    250250 
    251         // $status = new Phwittr_Status($barUser->id, $fooUser->id); 
    252251        $status = new Phwittr_Status($barUser->id); 
    253252        $userStatuses = $status->listArchives(); 
     
    422421 
    423422        $this->fail(); 
     423    } 
     424 
     425    public function it表示される発言リストは、通常は最新20件() 
     426    { 
     427        $this->_createUserRecord($this->_foo); 
     428 
     429        $mapper = Piece_ORM::getMapper('Users'); 
     430        $fooUser = $mapper->findByUserName($this->_foo->userName); 
     431 
     432        for ($i = 0; $i < 100; ++$i) { 
     433            $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
     434        } 
     435 
     436        $status = new Phwittr_Status($fooUser->id, $fooUser->id); 
     437        $userStatuses = $status->listByFollowers(); 
     438 
     439        $this->spec(count($userStatuses))->should->be(20); 
     440        for ($i = 0; $i < 20; ++$i) { 
     441            $number = 100 - $i; 
     442            $this->spec($userStatuses[$i]->comment)->should->be("foo$number"); 
     443        } 
     444    } 
     445 
     446    public function it表示される発言リスト20件のページが指定できる() 
     447    { 
     448        $this->_createUserRecord($this->_foo); 
     449 
     450        $mapper = Piece_ORM::getMapper('Users'); 
     451        $fooUser = $mapper->findByUserName($this->_foo->userName); 
     452 
     453        for ($i = 0; $i < 100; ++$i) { 
     454            $this->_createStatusRecord($fooUser->id, null, 'foo' . ($i + 1), $i); 
     455        } 
     456 
     457        $status = new Phwittr_Status($fooUser->id, $fooUser->id); 
     458        $userStatuses = $status->listByFollowers(3); 
     459 
     460        $this->spec(count($userStatuses))->should->be(20); 
     461        for ($i = 0; $i < 20; ++$i) { 
     462            $number = 100 - (20 * 2 + $i); 
     463            $this->spec($userStatuses[$i]->comment)->should->be("foo$number"); 
     464        } 
    424465    } 
    425466