Changeset 14154
- Timestamp:
- 06/17/08 01:44:03 (5 years ago)
- Location:
- events/phpframework/piece_framework/trunk
- Files:
-
- 3 modified
-
libs/Phwittr/Status.php (modified) (9 diffs)
-
specs/Phwittr/SpecCommon.php (modified) (2 diffs)
-
specs/Phwittr/StatusListSpec.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/piece_framework/trunk/libs/Phwittr/Status.php
r13426 r14154 7 7 * @package Phwittr_PieceFramework 8 8 * @copyright 2008 KUMAKURA Yousuke All rights reserved. 9 * @version SVN: $Id :$9 * @version SVN: $Id$ 10 10 * @since File available since Release 0.1.0 11 11 */ … … 48 48 protected $_watcherId; 49 49 50 protected $_limit = 20; 51 50 52 /**#@-*/ 51 53 … … 80 82 81 83 $mapper = Piece_ORM::getMapper('Users'); 82 83 84 $user = $mapper->findById($this->_userId); 84 85 if (is_null($user)) { … … 155 156 * フォローしているユーザと自身の発言リストを取得する 156 157 * 157 * @return mixed 158 */ 159 public function listByFollowers() 158 * @param integer $page 159 * @return mixed 160 */ 161 public function listByFollowers($page = 1) 160 162 { 161 163 $status = Piece_ORM::createObject('Statuses'); 162 164 $status->userId = $this->_userId; 163 165 164 $mapper = Piece_ORM::getMapper('Statuses');166 $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 165 167 return $mapper->findAllByUserIdForListFollowersStatus($status); 166 168 } … … 172 174 * 自身への返信リストを取得する 173 175 * 174 * @return mixed 175 */ 176 public function listReplies() 176 * @param integer $page 177 * @return mixed 178 */ 179 public function listReplies($page = 1) 177 180 { 178 181 $status = Piece_ORM::createObject('Statuses'); 179 182 $status->replyUserId = $this->_userId; 180 183 181 $mapper = Piece_ORM::getMapper('Statuses');184 $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 182 185 return $mapper->findAllByReplyUserIdForListReplies($status); 183 186 } … … 189 192 * 自身の発言リストを取得する 190 193 * 191 * @return mixed 192 */ 193 public function listArchives() 194 * @param integer $page 195 * @return mixed 196 */ 197 public function listArchives($page = 1) 194 198 { 195 199 $criteria = new stdClass(); … … 197 201 $criteria->watcherId = $this->_watcherId; 198 202 199 $mapper = Piece_ORM::getMapper('Statuses');203 $mapper = $this->_createListMapper($this->_limit * ($page - 1)); 200 204 return $mapper->findAllByUserIdForListArchives($criteria); 201 205 } … … 207 211 * すべての人の発言リストを取得する 208 212 * 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)); 214 219 return $mapper->findAllForListPublicTimeline(); 215 220 } … … 263 268 264 269 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; 265 288 } 266 289 -
events/phpframework/piece_framework/trunk/specs/Phwittr/SpecCommon.php
r14093 r14154 139 139 } 140 140 141 protected function _createStatusRecord($userId, $replyId, $comment )141 protected function _createStatusRecord($userId, $replyId, $comment, $timeLag = 0) 142 142 { 143 143 $status = Piece_ORM::createObject('Statuses'); … … 148 148 $mapper = Piece_ORM::getMapper('Statuses'); 149 149 $mapper->insert($status); 150 151 if ($timeLag) { 152 $status->createdAt = date('Y-m-d H:i:s', time() + $timeLag); 153 $mapper->update($status); 154 } 150 155 } 151 156 -
events/phpframework/piece_framework/trunk/specs/Phwittr/StatusListSpec.php
r13431 r14154 7 7 * @package Phwittr_PieceFramework 8 8 * @copyright 2008 KUMAKURA Yousuke All rights reserved. 9 * @version SVN: $Id :$9 * @version SVN: $Id$ 10 10 * @since File available since Release 0.1.0 11 11 */ … … 249 249 $this->_createStatusRecord($barUser->id, null, 'bar4'); 250 250 251 // $status = new Phwittr_Status($barUser->id, $fooUser->id);252 251 $status = new Phwittr_Status($barUser->id); 253 252 $userStatuses = $status->listArchives(); … … 422 421 423 422 $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 } 424 465 } 425 466
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)