diff --git a/Controller/Component/AppPaginatorComponent.php b/Controller/Component/AppPaginatorComponent.php new file mode 100644 index 00000000..54722a7f --- /dev/null +++ b/Controller/Component/AppPaginatorComponent.php @@ -0,0 +1,48 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('PaginatorComponent', 'Controller/Component'); + +/** + * NetCommons用に拡張したページネーション Component + * + * @author Shohei Nakajima + * @package NetCommons\NetCommons\Controller\Component + */ +class AppPaginatorComponent extends PaginatorComponent { + +/** + * Handles automatic pagination of model records. + * + * @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel') + * @param string|array $scope Additional find conditions to use while paginating + * @param array $whitelist List of allowed fields for ordering. This allows you to prevent ordering + * on non-indexed, or undesirable columns. See PaginatorComponent::validateSort() for additional details + * on how the whitelisting and sort field validation works. + * @return array Model query results + * @throws MissingModelException + * @throws NotFoundException + */ + public function paginate($object = null, $scope = array(), $whitelist = array()) { + $results = parent::paginate($object, $scope, $whitelist); + + if (in_array('Paginator', $this->Controller->helpers, true)) { + $index = array_search('Paginator', $this->Controller->helpers, true); + unset($this->Controller->helpers[$index]); + } elseif (array_key_exists('Paginator', $this->Controller->helpers, true)) { + unset($this->Controller->helpers['Paginator']); + } + $this->Controller->helpers['Paginator'] = array('className' => 'NetCommons.AppPaginator'); + + return $results; + } + +} diff --git a/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php b/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php index 24701515..16eec8ea 100644 --- a/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php +++ b/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php @@ -139,7 +139,7 @@ public function testCancelAndSaveAndSaveTemp($status, $contentPublishable, $canc */ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $approval) { //キャンセルのチェック - $expected = '' . + $expected = '' . ' ' . __d('net_commons', 'Cancel') . ''; $this->assertTextContains($expected, $result); @@ -156,7 +156,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a } //一時保存のチェック - $expected = ''; if ($disapproval) { @@ -166,7 +166,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a } //差し戻しのチェック - $expected = ''; if ($disapproval) { @@ -176,7 +176,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a } //公開のチェック - $expected = ''; if ($approval) { @@ -186,7 +186,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a } //申請のチェック - $expected = ''; if ($approval) { diff --git a/View/Helper/AppPaginatorHelper.php b/View/Helper/AppPaginatorHelper.php new file mode 100644 index 00000000..bf682fb1 --- /dev/null +++ b/View/Helper/AppPaginatorHelper.php @@ -0,0 +1,48 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('PaginatorHelper', 'View/Helper'); +App::uses('NetCommonsUrl', 'NetCommons.Utility'); + +/** + * NetCommons用に拡張したページネーション Helper + * + * @author Shohei Nakajima + * @package NetCommons\NetCommons\View\Helper + */ +class AppPaginatorHelper extends PaginatorHelper { + +/** + * Converts the keys being used into the format set by options.paramType + * + * @param array $url Array of URL params to convert + * @param string $type Keys type. + * @return array converted URL params. + */ + protected function _convertUrlKeys($url, $type) { + $url = parent::_convertUrlKeys($url, $type); + if (array_key_exists('block_id', $this->request->params)) { + $url['block_id'] = $this->request->params['block_id']; + } + if (array_key_exists('key', $this->request->params)) { + $url['key'] = $this->request->params['key']; + } + + if (array_key_exists('block_id', $this->request->params)) { + $url = NetCommonsUrl::blockUrl($url); + } else { + $url = NetCommonsUrl::actionUrlAsArray($url); + } + + return $url; + } + +}