diff --git a/Test/Case/Utility/CurrentFrame/SetBlockTest.php b/Test/Case/Utility/CurrentFrame/SetBlockTest.php new file mode 100644 index 00000000..c717c339 --- /dev/null +++ b/Test/Case/Utility/CurrentFrame/SetBlockTest.php @@ -0,0 +1,226 @@ + + * @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('NetCommonsCurrentUtilityBase', 'NetCommons.TestSuite'); +App::uses('CurrentFrame', 'NetCommons.Utility'); + +/** + * CurrentFrame::setBlock()のテスト + * + * @author Shohei Nakajima + * @package NetCommons\NetCommons\Test\Case\Utility\CurrentFrame + */ +class NetCommonsUtilityCurrentFrameSetBlockTest extends NetCommonsCurrentUtilityBase { + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'net_commons'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + $this->CurrentFrame = new CurrentFrame(); + } + +/** + * POSTリクエストのテスト + * + * @return void + */ + public function testPost() { + //データ生成 + Current::$request->data['Block']['id'] = '2'; + + //テスト実施 + $this->CurrentFrame->setBlock(); + + //チェック + $this->__assertBlockHeader(); + } + +/** + * 引数$blockIdがある場合のテスト + * + * @return void + */ + public function testWithFrameId() { + //データ生成 + $blockId = '2'; + + //テスト実施 + $this->CurrentFrame->setBlock($blockId); + + //チェック + $this->__assertBlockHeader(); + } + +/** + * Current::$current['Frame']がある場合のテスト + * + * @return void + */ + public function testWithFrame() { + //データ生成 + $blockId = '2'; + Current::$current['Frame'] = array( + 'id' => '9999', + 'key' => 'frame_9999', + ); + + //テスト実施 + $this->CurrentFrame->setBlock($blockId); + + //チェック + $expected = array( + 'Frame' => array( + 'id' => '9999', + 'key' => 'frame_9999', + ), + 'Room' => array( + 'id' => '2', + 'space_id' => '2', + 'page_id_top' => '1', + 'root_id' => null, + 'parent_id' => '1', + 'lft' => '2', + 'rght' => '7', + 'active' => true, + 'in_draft' => false, + 'default_role_key' => 'visitor', + 'need_approval' => true, + 'default_participation' => true, + 'page_layout_permitted' => true, + 'theme' => null, + ), + ); + $this->__assertBlockHeader($expected, array('Frame', 'Box', 'Space', 'Plugin')); + } + +/** + * block_id=2の評価 + * + * @param array $mergeExpected $expectedにマージするデータ + * @param array $removeKeys $expectedから削除するデータ + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + private function __assertBlockHeader($mergeExpected = array(), $removeKeys = array()) { + Current::$current = Hash::remove(Current::$current, '{s}.created_user'); + Current::$current = Hash::remove(Current::$current, '{s}.created'); + Current::$current = Hash::remove(Current::$current, '{s}.modified_user'); + Current::$current = Hash::remove(Current::$current, '{s}.modified'); + + $default = array( + 'Block' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => 'test_frames', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + 'content_count' => '0', + ), + 'Language' => array( + 'id' => '2', + 'code' => 'ja', + 'weight' => '2', + 'is_active' => true, + ), + 'Room' => array( + 'id' => '1', + 'space_id' => '1', + 'page_id_top' => null, + 'root_id' => null, + 'parent_id' => null, + 'lft' => '1', + 'rght' => '12', + 'active' => true, + 'in_draft' => false, + 'default_role_key' => 'visitor', + 'need_approval' => true, + 'default_participation' => true, + 'page_layout_permitted' => false, + 'theme' => null, + ), + 'Frame' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '1', + 'box_id' => '1', + 'plugin_key' => 'test_frames', + 'block_id' => '2', + 'key' => 'frame_header', + 'name' => 'Test frame header', + 'header_type' => 'default', + 'weight' => '1', + 'is_deleted' => false, + 'default_action' => '', + ), + 'Box' => array( + 'id' => '1', + 'container_id' => null, + 'type' => '1', + 'space_id' => '1', + 'room_id' => '1', + 'page_id' => null, + 'container_type' => '1', + 'weight' => null, + ), + 'Plugin' => array( + 'id' => '2', + 'language_id' => '2', + 'key' => 'test_frames', + 'name' => 'Lorem ipsum dolor sit amet', + 'namespace' => 'Lorem ipsum dolor sit amet', + 'weight' => '1', + 'type' => '1', + 'version' => null, + 'commit_version' => null, + 'commited' => null, + 'default_action' => '', + 'default_setting_action' => '', + 'frame_add_action' => null, + 'display_topics' => false, + 'display_search' => false, + 'serialize_data' => null, + ), + 'Space' => array( + 'id' => '1', + 'parent_id' => null, + 'lft' => '1', + 'rght' => '8', + 'type' => '1', + 'plugin_key' => null, + 'default_setting_action' => null, + ), + ); + + foreach ($removeKeys as $keyPath) { + $default = Hash::remove($default, $keyPath); + } + + $expected = Hash::merge($default, $mergeExpected); + + $this->assertEquals(Current::$current, $expected); + } + +} diff --git a/Test/Case/Utility/CurrentFrame/SetFrameTest.php b/Test/Case/Utility/CurrentFrame/SetFrameTest.php new file mode 100644 index 00000000..3d7d21d2 --- /dev/null +++ b/Test/Case/Utility/CurrentFrame/SetFrameTest.php @@ -0,0 +1,442 @@ + + * @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('NetCommonsCurrentUtilityBase', 'NetCommons.TestSuite'); +App::uses('CurrentFrame', 'NetCommons.Utility'); + +/** + * CurrentFrame::setFrame()のテスト + * + * @author Shohei Nakajima + * @package NetCommons\NetCommons\Test\Case\Utility\CurrentFrame + */ +class NetCommonsUtilityCurrentFrameSetFrameTest extends NetCommonsCurrentUtilityBase { + +/** + * Plugin name + * + * @var string + */ + public $plugin = 'net_commons'; + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + + $this->CurrentFrame = new CurrentFrame(); + } + +/** + * データなし、リクエストなしのテスト + * + * @return void + */ + public function testNoData() { + //データ生成 + //$frameId = null; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + $expected = array(); + $this->assertEquals(Current::$current, $expected); + } + +/** + * POSTリクエストのテスト + * + * @return void + */ + public function testPost() { + //データ生成 + Current::$request->data['Frame']['id'] = '2'; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + //チェック + $this->__assertFrameHeader(); + } + +/** + * GETリクエスト(params['?']['frame_id'])のテスト + * ※query['frame_id']になるため、基本的にないが念のため + * + * @return void + */ + public function testGetParams() { + //データ生成 + Current::$request->params['?']['frame_id'] = '2'; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + //チェック + $this->__assertFrameHeader(); + } + +/** + * GETリクエスト(query['frame_id'])のテスト + * + * @return void + */ + public function testGetQuery() { + //データ生成 + Current::$request->query['frame_id'] = '2'; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + //チェック + $this->__assertFrameHeader(); + } + +/** + * ブロック追加のテスト + * + * @return void + */ + public function testBlockAdd() { + //データ生成 + Current::$request->data['Frame']['id'] = '2'; + Current::$layout = 'NetCommons.setting'; + Current::$request->params['controller'] = 'test_frame_blocks'; + Current::$request->params['action'] = 'add'; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + //チェック + $this->__assertFrameHeader(array( + 'Block' => array( + 'public_type' => '1', + 'content_count' => '0', + 'language_id' => '2', + 'room_id' => '1', + 'plugin_key' => 'blocks', + 'key' => '', + 'name' => null, + 'publish_start' => null, + 'publish_end' => null, + 'id' => null, + ) + )); + } + +/** + * フレーム追加のテスト + * + * @return void + */ + public function testFrameAdd() { + //データ生成 + Current::$request->data['Frame']['box_id'] = '1'; + Current::$layout = 'NetCommons.setting'; + Current::$request->params['controller'] = 'frames'; + Current::$request->params['action'] = 'add'; + + //テスト実施 + $this->CurrentFrame->setFrame(); + + //チェック + $this->__assertFrameHeader(array(), array('Frame', 'Block', 'Language')); + } + +/** + * setBox()で取得したRoomがおかしい場合のテスト + * + * @return void + */ + public function testSetBoxOnRoomFailure() { + //データ生成 + $frameId = '2'; + + $query = array( + 'recursive' => 0, + 'conditions' => array( + 'Box.id' => '1', + ), + ); + $result = array( + 'Room' => array( + 'id' => '999', + 'space_id' => '999', + 'page_id_top' => null, + 'root_id' => null, + 'parent_id' => null, + 'lft' => null, + 'rght' => null, + 'active' => null, + 'in_draft' => null, + 'default_role_key' => null, + 'need_approval' => null, + 'default_participation' => null, + 'page_layout_permitted' => null, + 'theme' => null, + ), + 'Space' => array( + 'id' => '1', + 'parent_id' => null, + 'lft' => '1', + 'rght' => '8', + 'type' => '1', + 'plugin_key' => null, + 'default_setting_action' => null, + ), + ); + $this->CurrentFrame->Box = $this->getMock('Box', array('find')); + $this->CurrentFrame->Box + ->expects($this->once())->method('find') + ->with('first', $query) + ->will($this->returnValue($result)); + + //テスト実施 + $this->CurrentFrame->setFrame($frameId); + + //チェック + $this->__assertFrameHeader(); + } + +/** + * setBox()で取得したRoomがおかしい場合のテスト + * + * @return void + */ + public function testMainContainre() { + //データ生成 + $frameId = '6'; + + //テスト実施 + $this->CurrentFrame->setFrame($frameId); + + //チェック + $this->__assertFrameMain(); + } + +/** + * frame_id=2の評価 + * + * @param array $mergeExpected $expectedにマージするデータ + * @param array $removeKeys $expectedから削除するデータ + * @return void + */ + private function __assertFrameHeader($mergeExpected = array(), $removeKeys = array()) { + Current::$current = Hash::remove(Current::$current, '{s}.created_user'); + Current::$current = Hash::remove(Current::$current, '{s}.created'); + Current::$current = Hash::remove(Current::$current, '{s}.modified_user'); + Current::$current = Hash::remove(Current::$current, '{s}.modified'); + + $default = array( + 'Frame' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '1', + 'box_id' => '1', + 'plugin_key' => 'test_frames', + 'block_id' => '2', + 'key' => 'frame_header', + 'name' => 'Test frame header', + 'header_type' => 'default', + 'weight' => '1', + 'is_deleted' => false, + 'default_action' => '', + ), + 'Box' => array( + 'id' => '1', + 'container_id' => null, + 'type' => '1', + 'space_id' => '1', + 'room_id' => '1', + 'page_id' => null, + 'container_type' => '1', + 'weight' => null, + ), + 'Language' => array( + 'id' => '2', + 'code' => 'ja', + 'weight' => '2', + 'is_active' => true, + ), + 'Block' => array( + 'id' => '2', + 'language_id' => '2', + //Frameのroom_idとBlockのroom_idが異なることは、基本あり得ないが。テストで使っているFixtureの関係上、当データの結果となる + 'room_id' => '2', + 'plugin_key' => 'test_frames', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + 'content_count' => '0', + ), + 'Room' => array( + 'id' => '1', + 'space_id' => '1', + 'page_id_top' => null, + 'root_id' => null, + 'parent_id' => null, + 'lft' => '1', + 'rght' => '12', + 'active' => true, + 'in_draft' => false, + 'default_role_key' => 'visitor', + 'need_approval' => true, + 'default_participation' => true, + 'page_layout_permitted' => false, + 'theme' => null, + ), + 'Space' => array( + 'id' => '1', + 'parent_id' => null, + 'lft' => '1', + 'rght' => '8', + 'type' => '1', + 'plugin_key' => null, + 'default_setting_action' => null, + ), + ); + + foreach ($removeKeys as $keyPath) { + $default = Hash::remove($default, $keyPath); + } + + $expected = Hash::merge($default, $mergeExpected); + + $this->assertEquals(Current::$current, $expected); + } + +/** + * frame_id=6の評価 + * + * @param array $mergeExpected $expectedにマージするデータ + * @param array $removeKeys $expectedから削除するデータ + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + private function __assertFrameMain($mergeExpected = array(), $removeKeys = array()) { + Current::$current = Hash::remove(Current::$current, '{s}.created_user'); + Current::$current = Hash::remove(Current::$current, '{s}.created'); + Current::$current = Hash::remove(Current::$current, '{s}.modified_user'); + Current::$current = Hash::remove(Current::$current, '{s}.modified'); + + $default = array( + 'Frame' => array( + 'id' => '6', + 'language_id' => '2', + 'room_id' => '2', + 'box_id' => '28', + 'plugin_key' => 'test_frames', + 'block_id' => '2', + 'key' => 'frame_3', + 'name' => 'Test frame main', + 'header_type' => 'default', + 'weight' => '1', + 'is_deleted' => false, + 'default_action' => '', + ), + 'Box' => array( + 'id' => '28', + 'container_id' => null, + 'type' => '4', + 'space_id' => '2', + 'room_id' => '2', + 'page_id' => '2', + 'container_type' => '3', + 'weight' => null, + ), + 'Language' => array( + 'id' => '2', + 'code' => 'ja', + 'weight' => '2', + 'is_active' => true, + ), + 'Block' => array( + 'id' => '2', + 'language_id' => '2', + 'room_id' => '2', + 'plugin_key' => 'test_frames', + 'key' => 'block_1', + 'name' => 'Block name 1', + 'public_type' => '1', + 'publish_start' => null, + 'publish_end' => null, + 'content_count' => '0', + ), + 'Room' => array( + 'id' => '2', + 'space_id' => '2', + 'page_id_top' => '1', + 'root_id' => null, + 'parent_id' => '1', + 'lft' => '2', + 'rght' => '7', + 'active' => true, + 'in_draft' => false, + 'default_role_key' => 'visitor', + 'need_approval' => true, + 'default_participation' => true, + 'page_layout_permitted' => true, + 'theme' => null, + ), + 'Space' => array( + 'id' => '2', + 'parent_id' => '1', + 'lft' => '2', + 'rght' => '3', + 'type' => '2', + 'plugin_key' => 'public_space', + 'default_setting_action' => 'rooms/index/2', + ), + 'BoxesPageContainer' => array( + 'id' => '58', + 'page_container_id' => '8', + 'page_id' => '2', + 'container_type' => '3', + 'box_id' => '28', + 'is_published' => true, + 'weight' => '1', + ), + 'PageContainer' => array( + 'id' => '8', + 'page_id' => '2', + 'container_type' => '3', + 'is_published' => true, + 'is_configured' => false, + ), + 'Page' => array( + 'id' => '2', + 'room_id' => '2', + 'root_id' => '1', + 'parent_id' => '1', + 'lft' => '2', + 'rght' => '3', + 'permalink' => 'home', + 'slug' => 'home', + 'is_container_fluid' => true, + 'theme' => null, + ), + ); + + foreach ($removeKeys as $keyPath) { + $default = Hash::remove($default, $keyPath); + } + + $expected = Hash::merge($default, $mergeExpected); + + $this->assertEquals(Current::$current, $expected); + } + +} diff --git a/TestSuite/NetCommonsCurrentUtilityBase.php b/TestSuite/NetCommonsCurrentUtilityBase.php new file mode 100644 index 00000000..0b5e2c4a --- /dev/null +++ b/TestSuite/NetCommonsCurrentUtilityBase.php @@ -0,0 +1,93 @@ + + * @author Shohei Nakajima + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +//@codeCoverageIgnoreStart; +App::uses('AppController', 'Controller'); +App::uses('CakeRequest', 'Network'); +App::uses('CakeResponse', 'Network'); +App::uses('NetCommonsCakeTestCase', 'NetCommons.TestSuite'); +App::uses('Current', 'NetCommons.Utility'); +//@codeCoverageIgnoreEnd; + +/** + * NetCommonsCakeTestCase class + * + * @package NetCommons\NetCommons\TestSuite + * @codeCoverageIgnore + */ +class NetCommonsCurrentUtilityBase extends NetCommonsCakeTestCase { + +/** + * Fixtures + * + * @var array + */ + private $__fixtures = array( + 'plugin.frames.frame4frames', + 'plugin.frames.block4frames', + 'plugin.frames.plugin4frames', + ); + +/** + * Fixtures + * + * @var array + */ + protected $_Controller = null; + +/** + * Fixtures load + * + * @param string $name The name parameter on PHPUnit_Framework_TestCase::__construct() + * @param array $data The data parameter on PHPUnit_Framework_TestCase::__construct() + * @param string $dataName The dataName parameter on PHPUnit_Framework_TestCase::__construct() + * @return void + */ + public function __construct($name = null, array $data = array(), $dataName = '') { + if (! isset($this->fixtures)) { + $this->fixtures = array(); + } + $this->fixtures = array_merge($this->__fixtures, $this->fixtures); + parent::__construct($name, $data, $dataName); + } + +/** + * setUp method + * + * @return void + */ + public function setUp() { + parent::setUp(); + Current::$current = array(); + + $CakeRequest = new CakeRequest(); + $CakeResponse = new CakeResponse(); + $this->_Controller = new AppController($CakeRequest, $CakeResponse); + Current::$request = $this->_Controller->request; + Current::$request->params['params'] = 'test_frames'; + Current::$request->params['controller'] = 'test_frames'; + Current::$request->params['action'] = 'index'; + } + +/** + * tearDown method + * + * @return void + */ + public function tearDown() { + Current::$current = array(); + Current::$request = null; + Current::$layout = null; + unset($this->_Controller); + parent::tearDown(); + } + +} diff --git a/Utility/Current.php b/Utility/Current.php index 8a8888ad..7e52326c 100644 --- a/Utility/Current.php +++ b/Utility/Current.php @@ -429,4 +429,28 @@ public static function allowSystemPlugin($pluginKey) { return Hash::check(Current::$current['PluginsRole'], '{n}[plugin_key=' . $pluginKey . ']'); } +/** + * 取得した結果を$currentにセットする + * + * @param array $results 取得結果 + * @param array $forceMargeModels 既に取得済みでも強制でマージするModelのリスト + * @return void + */ + public static function setCurrent($results, $forceMargeModels = []) { + if (! $results) { + return; + } + $models = array_keys($results); + + foreach ($models as $model) { + if (array_key_exists('id', $results[$model]) && ! Hash::get($results[$model], 'id')) { + continue; + } + if (! isset(Current::$current[$model]) || + $forceMargeModels === true || in_array($model, $forceMargeModels, true)) { + Current::$current[$model] = $results[$model]; + } + } + } + } diff --git a/Utility/CurrentFrame.php b/Utility/CurrentFrame.php index 1ef90876..e00f67ea 100644 --- a/Utility/CurrentFrame.php +++ b/Utility/CurrentFrame.php @@ -67,6 +67,7 @@ public function clear() { * * @param string $frameId フレームID * @return void + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function setFrame($frameId = null) { if ($frameId) { @@ -81,18 +82,24 @@ public function setFrame($frameId = null) { } $this->Frame = ClassRegistry::init('Frames.Frame'); - $this->Box = ClassRegistry::init('Boxes.Box'); $this->Block = ClassRegistry::init('Blocks.Block'); if (isset($frameId)) { - $result = $this->Frame->findById($frameId); - Current::$current = Hash::merge(Current::$current, $result); + //Frame、Box、Block、Room、Language更新 + $result = $this->Frame->find('first', array( + 'recursive' => 0, + 'conditions' => array( + 'Frame.id' => $frameId, + ), + )); + Current::setCurrent($result, true); } //ブロック設定の新規の場合の処理 if (Current::$layout === 'NetCommons.setting' && - Hash::get(Current::$request->params, 'action') === 'add') { - Current::$current['Block'] = $this->Block->create()['Block']; + substr(Current::$request->params['controller'], -7) === '_blocks' && + Current::$request->params['action'] === 'add') { + Current::$current['Block'] = $this->Block->create(['id' => null])['Block']; } $this->setBox(); @@ -104,6 +111,10 @@ public function setFrame($frameId = null) { * @return void */ public function setBox() { + if (empty($this->Box)) { + $this->Box = ClassRegistry::init('Boxes.Box'); + } + if (isset(Current::$current['Box']['id'])) { $boxId = Current::$current['Box']['id']; } elseif (isset(Current::$request->data['Frame']) && @@ -113,18 +124,14 @@ public function setBox() { return; } + //Box、Room、Space更新 $result = $this->Box->find('first', array( 'recursive' => 0, 'conditions' => array( 'Box.id' => $boxId, ), )); - if (! $result) { - return; - } - - //Box、Room、Space更新 - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); $this->setBoxPageContainer(); } @@ -152,6 +159,7 @@ public function setBoxPageContainer() { $this->BoxesPageContainer = ClassRegistry::init('Boxes.BoxesPageContainer'); + //BoxesPageContainer、Box、PageContainer、Page更新 $result = $this->BoxesPageContainer->find('first', array( 'recursive' => 0, 'conditions' => array( @@ -160,25 +168,18 @@ public function setBoxPageContainer() { 'BoxesPageContainer.container_type' => Current::$current['Box']['container_type'], ), )); - if (! $result) { - return; - } - - //BoxesPageContainer、Box、PageContainer、Page更新 - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); } /** * Set Block * - * ※PHPMのSuppressWarningsは暫定 - * * @param int $blockId Blocks.id * @return void - * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function setBlock($blockId = null) { $this->Block = ClassRegistry::init('Blocks.Block'); + $this->Frame = ClassRegistry::init('Frames.Frame'); if (! Hash::get(Current::$request->params, 'requested') && Hash::get(Current::$request->data, 'Block.id')) { @@ -197,10 +198,10 @@ public function setBlock($blockId = null) { 'Block.id' => $blockId, ), )); - if ($result) { - Current::$current = Hash::merge(Current::$current, $result); - } + //Block、Room、Language更新 + Current::setCurrent($result, true); + //Frameデータがない場合、block_idから配置しているFrameを探し出してセットする if (! isset(Current::$current['Frame'])) { $frame = $this->Frame->find('first', array( 'fields' => array('id'), @@ -218,17 +219,16 @@ public function setBlock($blockId = null) { } } - if (! isset(Current::$current['Block']) && isset(Current::$current['Frame']['block_id'])) { - $result = $this->Block->find('first', array( - 'recursive' => 0, - 'conditions' => array( - 'Block.id' => Current::$current['Frame']['block_id'], - ), - )); - if ($result) { - Current::$current = Hash::merge(Current::$current, $result); - } - } + //あり得ない?のでコメントアウト + //if (! isset(Current::$current['Block']) && isset(Current::$current['Frame']['block_id'])) { + // $result = $this->Block->find('first', array( + // 'recursive' => 0, + // 'conditions' => array( + // 'Block.id' => Current::$current['Frame']['block_id'], + // ), + // )); + // Current::setCurrent($result, true); + //} } /** diff --git a/Utility/CurrentPage.php b/Utility/CurrentPage.php index c8db9655..701ee27f 100644 --- a/Utility/CurrentPage.php +++ b/Utility/CurrentPage.php @@ -47,7 +47,7 @@ public function initialize() { $this->setDefaultRolePermissions(); $this->setRoomRolePermissions(); $this->setPluginsRoom(); - $this->setSpace(); + //$this->setSpace(); } /** @@ -65,7 +65,8 @@ public function setRolesRoomsUser() { 'Room.id' => Current::$current['Room']['id'] )); if ($result) { - Current::$current = Hash::merge(Current::$current, $result[0]); + unset($result[0]['Room']); + Current::setCurrent($result[0], true); } } } @@ -181,7 +182,8 @@ private function __getPageConditions() { ! Current::$request->is('ajax')) { $this->Room = ClassRegistry::init('Rooms.Room'); $result = $this->Room->getPrivateRoomByUserId(Current::read('User.id')); - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); + $conditions = array( 'Page.id' => Hash::get($result, 'Room.page_id_top', Page::PUBLIC_ROOT_PAGE_ID) ); @@ -229,7 +231,7 @@ public function setPage() { 'order' => array('Page.lft' => 'asc') )); - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); if (isset(Current::$current['Page'])) { return; } @@ -247,7 +249,7 @@ public function setPage() { 'recursive' => 0, 'conditions' => array('Page.id' => $pageId), )); - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); } (new CurrentFrame())->setBoxPageContainer(); @@ -271,7 +273,7 @@ public function setPageByRoomPageTopId() { 'conditions' => $conditions, )); - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); } /** @@ -305,7 +307,7 @@ public function setRoom($roomId) { 'recursive' => 0, 'conditions' => $conditions, )); - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result); } /** @@ -313,20 +315,20 @@ public function setRoom($roomId) { * * @return void */ - public function setSpace() { - if (!isset(Current::$current['Room'])) { - return; - } - - $this->Space = ClassRegistry::init('Rooms.Space'); - $conditions = array( - 'Space.id' => Hash::get(Current::$current, 'Room.space_id') - ); - $result = $this->Space->find('first', array( - 'recursive' => 0, - 'conditions' => $conditions, - )); - Current::$current = Hash::merge(Current::$current, $result); - } + //public function setSpace() { + // if (! isset(Current::$current['Room'])) { + // return; + // } + // + // $this->Space = ClassRegistry::init('Rooms.Space'); + // $conditions = array( + // 'Space.id' => Hash::get(Current::$current, 'Room.space_id') + // ); + // $result = $this->Space->find('first', array( + // 'recursive' => 0, + // 'conditions' => $conditions, + // )); + // Current::setCurrent($result, true); + //} } diff --git a/Utility/CurrentSystem.php b/Utility/CurrentSystem.php index 82f590e5..9fff1c2e 100644 --- a/Utility/CurrentSystem.php +++ b/Utility/CurrentSystem.php @@ -79,10 +79,7 @@ public function setPlugin() { 'language_id' => Current::$current['Language']['id'] ), )); - if (! $result) { - return; - } - Current::$current = Hash::merge(Current::$current, $result); + Current::setCurrent($result, true); } /**