diff --git a/Utility/CurrentPage.php b/Utility/CurrentPage.php index 765955c5..1fbc72cc 100644 --- a/Utility/CurrentPage.php +++ b/Utility/CurrentPage.php @@ -10,6 +10,7 @@ */ App::uses('CurrentFrame', 'NetCommons.Utility'); +App::uses('Space', 'Rooms.Space'); /** * CurrentPage Utility @@ -42,6 +43,7 @@ public function initialize() { } $this->setPage(); + $this->setTopPage(); $this->setPageByRoomPageTopId(); $this->setRolesRoomsUser(); $this->setDefaultRolePermissions(); @@ -194,6 +196,28 @@ private function __getPageConditions() { return $conditions; } +/** + * Set TopPage + * + * @return bool + */ + public function setTopPage() { + $this->Page = ClassRegistry::init('Pages.Page'); + if (isset(Current::$current['TopPage'])) { + return; + } + + $result = $this->__getPage(array( + 'recursive' => -1, + 'conditions' => array( + 'Page.room_id' => Space::getRoomIdRoot(Space::PUBLIC_SPACE_ID), + 'Page.parent_id NOT' => null, + ), + 'order' => array('Page.lft' => 'asc') + )); + Current::$current['TopPage'] = $result['Page']; + } + /** * ページ取得 * diff --git a/Utility/NetCommonsUrl.php b/Utility/NetCommonsUrl.php index 6ec6d583..8f05d774 100644 --- a/Utility/NetCommonsUrl.php +++ b/Utility/NetCommonsUrl.php @@ -17,6 +17,7 @@ * * @author Shohei Nakajima * @package NetCommons\NetCommons\Utility + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class NetCommonsUrl { @@ -33,12 +34,15 @@ public static function backToPageUrl($settingMode = false, $full = false) { $url = '/'; if (! Current::isControlPanel()) { - if ($settingMode) { + if ($settingMode || $settingMode === null && Current::isSettingMode()) { $url .= Current::SETTING_MODE_WORD . '/'; } - if (Hash::get($page, 'Page.parent_id') === Page::PUBLIC_ROOT_PAGE_ID && - Hash::get($page, 'Page.id') === Current::read('Room.page_id_top')) { + if (Current::read('Space.permalink')) { + $url .= Current::read('Space.permalink') . '/'; + } + + if (Hash::get($page, 'Page.id') === Current::read('TopPage.id')) { $url .= ''; } else { $url .= h(Hash::get($page, 'Page.permalink')); diff --git a/View/Helper/BackToHelper.php b/View/Helper/BackToHelper.php index d63b84ba..77ca07f4 100644 --- a/View/Helper/BackToHelper.php +++ b/View/Helper/BackToHelper.php @@ -152,7 +152,7 @@ public function linkButton($title, $url, $options = array()) { * @return string */ public function pageLinkButton($title, $options = array()) { - $url = NetCommonsUrl::backToPageUrl(); + $url = NetCommonsUrl::backToPageUrl(null); return $this->linkButton($title, $url, $options); } diff --git a/View/Helper/ButtonHelper.php b/View/Helper/ButtonHelper.php index ef4aab9e..9c4578ba 100644 --- a/View/Helper/ButtonHelper.php +++ b/View/Helper/ButtonHelper.php @@ -235,7 +235,7 @@ public function cancel($title, $url, $options = array()) { public function cancelAndSave($cancelTitle, $saveTitle, $cancelUrl = null, $cancelOptions = [], $saveOptions = []) { if (! isset($cancelUrl)) { - $cancelUrl = NetCommonsUrl::backToPageUrl(); + $cancelUrl = NetCommonsUrl::backToPageUrl(null); } $output = ''; @@ -259,7 +259,7 @@ public function cancelAndSaveAndSaveTemp($cancelUrl = null, $cancelOptions = [], App::uses('WorkflowComponent', 'Workflow.Controller/Component'); if (! isset($cancelUrl)) { - $cancelUrl = NetCommonsUrl::backToPageUrl(); + $cancelUrl = NetCommonsUrl::backToPageUrl(null); } $output = ''; diff --git a/View/Helper/LinkButtonHelper.php b/View/Helper/LinkButtonHelper.php index f5cb569d..1a5a48df 100644 --- a/View/Helper/LinkButtonHelper.php +++ b/View/Helper/LinkButtonHelper.php @@ -206,7 +206,7 @@ public function toList($title = '', $url = null, $options = array()) { $output = ''; if (! isset($url)) { - $url = NetCommonsUrl::backToPageUrl(); + $url = NetCommonsUrl::backToPageUrl(null); } //Linkオプションの設定 diff --git a/View/Helper/WizardHelper.php b/View/Helper/WizardHelper.php index 7d140b02..0b1f0f35 100644 --- a/View/Helper/WizardHelper.php +++ b/View/Helper/WizardHelper.php @@ -96,7 +96,7 @@ public function beforeRender($viewFile) { $this->settings['navibar'] = array(); } if (! isset($this->settings['cancelUrl'])) { - $this->settings['cancelUrl'] = NetCommonsUrl::backToPageUrl(); + $this->settings['cancelUrl'] = NetCommonsUrl::backToPageUrl(null); } }