From 5d9e22d76ff7e35c6963f79cef3de1b91696d521 Mon Sep 17 00:00:00 2001 From: "ohga.ryohei" Date: Mon, 27 Aug 2018 19:47:09 +0900 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E7=94=A8=E6=84=8F=E3=81=ABHash?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E7=AE=87=E6=89=80=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/TopicFrameSettingsController.php | 51 ++++++++++++------- Controller/TopicsController.php | 49 ++++++++++-------- Model/Behavior/TopicsBehavior.php | 16 ++++-- Model/Topic.php | 41 +++++++-------- Model/TopicFrameSetting.php | 2 +- Model/TopicFramesBlock.php | 14 +++-- Model/TopicFramesPlugin.php | 24 ++++++--- Model/TopicFramesRoom.php | 31 +++++++---- Model/TopicReadable.php | 2 +- Model/TopicUserStatus.php | 2 +- .../Elements/TopicFrameSettings/edit_form.ctp | 21 +++++--- View/Elements/Topics/select_status.ctp | 2 +- View/Helper/TopicsHelper.php | 44 ++++++++-------- View/Topics/json/index_plugins.ctp | 2 +- View/Topics/json/index_rooms.ctp | 2 +- 15 files changed, 181 insertions(+), 122 deletions(-) diff --git a/Controller/TopicFrameSettingsController.php b/Controller/TopicFrameSettingsController.php index a8463a8..22a3e6d 100644 --- a/Controller/TopicFrameSettingsController.php +++ b/Controller/TopicFrameSettingsController.php @@ -77,33 +77,39 @@ class TopicFrameSettingsController extends TopicsAppController { * edit * * @return void + * + * 速度改善の修正に伴って発生したため抑制 + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function edit() { $this->RoomsForm->setRoomsForCheckbox(); $this->PluginsForm->setPluginsRoomForCheckbox($this, $this->PluginsForm->findOptions); - $options = Hash::extract( - $this->viewVars['pluginsRoom'], '{n}.Plugin.key' - ); + $pluginKeys = []; + foreach ($this->viewVars['pluginsRoom'] as $item) { + $pluginKeys[] = $item['Plugin']['key']; + } - $blocks = $this->TopicFrameSetting->getBlocks($options, array_keys($this->viewVars['rooms'])); + $blocks = $this->TopicFrameSetting->getBlocks($pluginKeys, array_keys($this->viewVars['rooms'])); $this->set('selectBlocks', $blocks); if ($this->request->is('put') || $this->request->is('post')) { //登録処理 $data = $this->data; - $data['TopicFramesRoom']['room_id'] = Hash::get($data, 'TopicFramesRoom.room_id'); - if (! $data['TopicFramesRoom']['room_id']) { - $data['TopicFramesRoom']['room_id'] = array(); + $data['TopicFramesRoom']['room_id'] = []; + if (! empty($this->data['TopicFramesRoom']['room_id'])) { + $data['TopicFramesRoom']['room_id'] = $this->data['TopicFramesRoom']['room_id']; } - $data['TopicFramesPlugin']['plugin_key'] = Hash::get($data, 'TopicFramesPlugin.plugin_key'); - if (! $data['TopicFramesPlugin']['plugin_key']) { - $data['TopicFramesPlugin']['plugin_key'] = array(); + $data['TopicFramesPlugin']['plugin_key'] = []; + if (! empty($this->data['TopicFramesPlugin']['plugin_key'])) { + $data['TopicFramesPlugin']['plugin_key'] = $this->data['TopicFramesPlugin']['plugin_key']; } - $data['TopicFramesBlock'] = Hash::get($data, 'TopicFramesBlock'); + $data['TopicFramesBlock'] = isset($data['TopicFramesBlock']) + ? $data['TopicFramesBlock'] + : null; if ($this->TopicFrameSetting->saveTopicFrameSetting($data)) { $this->redirect(NetCommonsUrl::backToPageUrl(true)); @@ -139,15 +145,22 @@ public function edit() { 'conditions' => ['frame_key' => Current::read('Frame.key')], )); - $this->request->data['TopicFramesBlock'] = Hash::get($result, 'TopicFramesBlock', array()); - if (! $this->request->data['TopicFramesBlock']) { - $block = Hash::extract($blocks, '{s}.{s}'); - $this->request->data['TopicFramesBlock'] = array( - 'block_key' => Hash::get($block, '0.key'), - 'plugin_key' => Hash::get($block, '0.plugin_key'), - 'room_id' => Hash::get($block, '0.room_id'), - ); + if (isset($result['TopicFramesBlock'])) { + $topicFramesBlock = $result['TopicFramesBlock']; + } else { + $topicFramesBlock = []; + foreach ($blocks as $block) { + foreach ($block as $item) { + $topicFramesBlock = [ + 'block_key' => $item['key'], + 'plugin_key' => $item['plugin_key'], + 'room_id' => $item['room_id'], + ]; + break 2; // 1件目を取得してループを抜ける + } + } } + $this->request->data['TopicFramesBlock'] = $topicFramesBlock; } } } diff --git a/Controller/TopicsController.php b/Controller/TopicsController.php index 2746090..49c2f4a 100644 --- a/Controller/TopicsController.php +++ b/Controller/TopicsController.php @@ -74,6 +74,9 @@ public function beforeFilter() { * index * * @return void + * + * 速度改善の修正に伴って発生したため抑制 + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function index() { $topicFrameSetting = $this->viewVars['topicFrameSetting']; @@ -81,7 +84,9 @@ public function index() { $conditions = array(); - $days = Hash::get($this->params['named'], 'days'); + $days = isset($this->params['named']['days']) + ? $this->params['named']['days'] + : null; if ($days) { $date = new DateTime(); $date->sub(new DateInterval('P' . $days . 'D')); @@ -91,11 +96,10 @@ public function index() { if ($displayType === TopicFrameSetting::DISPLAY_TYPE_ROOMS) { //ルームごとに表示する - $roomId = Hash::get($this->request->query, 'room_id'); - if ($roomId) { - $conditionsByRoom['Room.id'] = $roomId; - } else { - $conditionsByRoom = array(); + $conditionsByRoom = []; + if (isset($this->request->query['room_id']) && + ! empty($this->request->query['room_id'])) { + $conditionsByRoom['Room.id'] = $this->request->query['room_id']; } $rooms = $this->TopicFramesRoom->getRooms( @@ -117,11 +121,10 @@ public function index() { } elseif ($displayType === TopicFrameSetting::DISPLAY_TYPE_PLUGIN) { //プラグインごとに表示する - $pluginKey = Hash::get($this->request->query, 'plugin_key'); - if ($pluginKey) { - $conditionsByPlugin['Plugin.key'] = $pluginKey; - } else { - $conditionsByPlugin = array(); + $conditionsByPlugin = []; + if (isset($this->request->query['plugin_key']) && + ! empty($this->request->query['plugin_key'])) { + $conditionsByPlugin['Plugin.key'] = $this->request->query['plugin_key']; } $plugins = $this->TopicFramesPlugin->getPlugins( @@ -164,28 +167,34 @@ public function index() { */ private function __getTopics($topicFrameSetting, $conditions) { $options = $this->TopicFrameSetting->getQueryOptions($topicFrameSetting, $conditions); + $status = isset($this->params['named']['status']) + ? $this->params['named']['status'] + : 0; + $this->Paginator->settings = array( - 'Topic' => $this->Topic->getQueryOptions( - Hash::get($this->params['named'], 'status', '0'), $options - ), + 'Topic' => $this->Topic->getQueryOptions($status, $options), ); - $maxPage = Hash::get($this->params['named'], 'page', '1'); - $startPage = Hash::get($this->params['named'], 'startPage', $maxPage); + $maxPage = isset($this->params['named']['page']) + ? $this->params['named']['page'] + : '1'; + $startPage = isset($this->params['named']['startPage']) + ? $this->params['named']['startPage'] + : $maxPage; $topics = array(); for ($page = $startPage; $page <= $maxPage; $page++) { $this->params['named'] = Hash::insert($this->params['named'], 'page', $page); $result = $this->Paginator->paginate('Topic'); foreach ($result as $topic) { + unset($topic['Topic']['search_contents']); $topics[] = $topic; } } - $topics = Hash::remove($topics, '{n}.Topic.search_contents'); $paging = $this->request['paging']; - $paging = Hash::remove($paging, 'Topic.order'); - $paging = Hash::remove($paging, 'Topic.options'); - $paging = Hash::remove($paging, 'Topic.paramType'); + unset($paging['Topic']['order']); + unset($paging['Topic']['options']); + unset($paging['Topic']['paramType']); return array('topics' => $topics, 'paging' => $paging['Topic']); } diff --git a/Model/Behavior/TopicsBehavior.php b/Model/Behavior/TopicsBehavior.php index 2c7995e..aa6806d 100644 --- a/Model/Behavior/TopicsBehavior.php +++ b/Model/Behavior/TopicsBehavior.php @@ -116,9 +116,8 @@ public function saveTopics(Model $model) { $this->_deleteTopicUserStatus($model); //新着に表示させる会員のリスト登録 - $topicIds = Hash::extract($model->data, $model->Topic->alias . '.{n}.id'); - foreach ($topicIds as $topicId) { - $this->_saveTopicReadable($model, $topicId); + foreach ($model->data[$model->Topic->alias] as $topic) { + $this->_saveTopicReadable($model, $topic['id']); } return true; @@ -129,6 +128,9 @@ public function saveTopics(Model $model) { * * @param Model $model 呼び出し元のモデル * @return bool + * + * 速度改善の修正に伴って発生したため抑制 + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function beforeDeleteTopics(Model $model) { $model->loadModels([ @@ -143,7 +145,9 @@ public function beforeDeleteTopics(Model $model) { 'fields' => array('id', 'key'), 'conditions' => array('id' => $model->id) )); - $model->contentKey = Hash::get($content, $model->alias . '.key'); + $model->contentKey = isset($content[$model->alias]['key']) + ? $content[$model->alias]['key'] + : null; } elseif ($model->blockId && ! $model->blockKey) { $block = $model->Block->find('first', array( @@ -151,7 +155,9 @@ public function beforeDeleteTopics(Model $model) { 'fields' => array('id', 'key'), 'conditions' => array('id' => $model->blockId) )); - $model->blockKey = Hash::get($block, $model->Block->alias . '.key'); + $model->blockKey = isset($block[$model->Block->alias]['key']) + ? $block[$model->Block->alias]['key'] + : null; } //削除するトピックID取得 diff --git a/Model/Topic.php b/Model/Topic.php index 06cb694..2efd879 100644 --- a/Model/Topic.php +++ b/Model/Topic.php @@ -343,7 +343,7 @@ public function __construct($id = false, $table = null, $ds = null) { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'language_id' => array( 'numeric' => array( 'rule' => array('numeric'), @@ -564,19 +564,24 @@ private function __getRoomsConditions($now) { ); //room_idの取得 - $editableRoomIds = array_merge( - Hash::extract( - $rooms, '{n}.RolesRoom[role_key=' . Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR . '].room_id' - ), - Hash::extract( - $rooms, '{n}.RolesRoom[role_key=' . Role::ROOM_ROLE_KEY_CHIEF_EDITOR . '].room_id' - ), - Hash::extract( - $rooms, '{n}.RolesRoom[role_key=' . Role::ROOM_ROLE_KEY_EDITOR . '].room_id' - ) - ); + $editableRoomIds = []; // 編集権限の条件生成 + $readableRoomIds = []; // 閲覧権限の条件生成 + $blockEditableRoomIds = []; //ブロック公開設定の条件生成 + foreach ($rooms as $room) { + switch ($room['RolesRoom']['role_key']) { + case Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR: + case Role::ROOM_ROLE_KEY_CHIEF_EDITOR: + $editableRoomIds[] = $room['RolesRoom']['room_id']; + $blockEditableRoomIds[] = $room['RolesRoom']['room_id']; + break; + case Role::ROOM_ROLE_KEY_EDITOR: + $editableRoomIds[] = $room['RolesRoom']['room_id']; + break; + } + $readableRoomIds[] = $room['Room']['id']; + } $readableRoomIds = array_diff( - Hash::extract($rooms, '{n}.Room.id'), $editableRoomIds + $readableRoomIds, $editableRoomIds ); $roomConditions = array(); @@ -592,16 +597,6 @@ private function __getRoomsConditions($now) { //is_activeの条件生成 $roomConditions = $this->__getIsActiveConditions($now, $roomConditions, $readableRoomIds); - //ブロック公開設定の条件生成 - $blockEditableRoomIds = array_merge( - Hash::extract( - $rooms, '{n}.RolesRoom[role_key=' . Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR . '].room_id' - ), - Hash::extract( - $rooms, '{n}.RolesRoom[role_key=' . Role::ROOM_ROLE_KEY_CHIEF_EDITOR . '].room_id' - ) - ); - $blockPubConditions['OR'] = array( array($this->Block->alias . '.public_type' => self::TYPE_PUBLIC), array( diff --git a/Model/TopicFrameSetting.php b/Model/TopicFrameSetting.php index 3072a42..8351989 100644 --- a/Model/TopicFrameSetting.php +++ b/Model/TopicFrameSetting.php @@ -88,7 +88,7 @@ class TopicFrameSetting extends TopicsAppModel { * @throws BadRequestException */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'frame_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), diff --git a/Model/TopicFramesBlock.php b/Model/TopicFramesBlock.php index 1c96b02..00b3921 100644 --- a/Model/TopicFramesBlock.php +++ b/Model/TopicFramesBlock.php @@ -55,7 +55,7 @@ class TopicFramesBlock extends TopicsAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'frame_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), @@ -80,7 +80,9 @@ public function beforeValidate($options = array()) { public function validateRequestData($data) { $blockKeys = Hash::extract($data, 'Block.{n}.key'); - $check = Hash::get($data, 'TopicFrameSetting' . '.block_key', array()); + $check = isset($data['TopicFrameSetting']['block_key']) + ? $data['TopicFrameSetting']['block_key'] + : []; foreach ($check as $blockKey) { if (! in_array($blockKey, $blockKeys, true)) { return false; @@ -122,8 +124,10 @@ public function getConditions($topicFrameSetting, $conditions) { * @throws InternalErrorException */ public function saveTopicFramesBlock($data) { - $blockKey = Hash::get($data, $this->alias . '.block_key'); - if ($blockKey && Hash::get($data, 'TopicFrameSetting.select_block')) { + $blockKey = isset($data[$this->alias]['block_key']) + ? $data[$this->alias]['block_key'] + : null; + if ($blockKey && $data['TopicFrameSetting']['select_block']) { $conditions = array( 'TopicFramesBlock' . '.frame_key' => Current::read('Frame.key'), 'TopicFramesBlock' . '.block_key !=' => $blockKey, @@ -137,7 +141,7 @@ public function saveTopicFramesBlock($data) { 'TopicFramesBlock' . '.block_key' => $blockKey, ); if (! $this->find('count', ['recursive' => -1, 'conditions' => $conditions])) { - $saveData = $this->create(Hash::get($data, $this->alias)); + $saveData = $this->create($data[$this->alias]); if (! $this->save($saveData)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } diff --git a/Model/TopicFramesPlugin.php b/Model/TopicFramesPlugin.php index 3c7d552..0ee9179 100644 --- a/Model/TopicFramesPlugin.php +++ b/Model/TopicFramesPlugin.php @@ -36,7 +36,7 @@ class TopicFramesPlugin extends TopicsAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'frame_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), @@ -59,9 +59,16 @@ public function beforeValidate($options = array()) { * @return bool */ public function validateRequestData($data) { - $pluginKeys = Hash::extract($data, 'Plugin.{n}.key'); + $pluginKeys = []; + if (isset($data['Plugin'])) { + foreach ($data['Plugin'] as $plugin) { + $pluginKeys[] = $plugin['key']; + } + } - $check = Hash::get($data, 'TopicFrameSetting' . '.plugin_key', array()); + $check = isset($data['TopicFramesPlugin']['plugin_key']) + ? $data['TopicFramesPlugin']['plugin_key'] + : []; foreach ($check as $pluginKey) { if (! in_array($pluginKey, $pluginKeys, true)) { return false; @@ -79,8 +86,8 @@ public function validateRequestData($data) { * @return array 条件配列 */ public function getConditions($topicFrameSetting, $conditions = []) { - if (Hash::get($conditions, 'Topic.plugin_key')) { - $conditions['Topic.plugin_key'] = Hash::get($conditions, 'Topic.plugin_key'); + if (isset($conditions['Topic']['plugin_key'])) { + $conditions['Topic.plugin_key'] = $conditions['Topic']['plugin_key']; } elseif ($topicFrameSetting['TopicFrameSetting']['select_plugin']) { $pluginKeys = $this->find('list', array( 'recursive' => -1, @@ -157,7 +164,12 @@ public function getPlugins($topicFrameSetting, $conditions = []) { * @throws InternalErrorException */ public function saveTopicFramesPlugin($data) { - $pluginKeys = Hash::get($data, $this->alias . '.plugin_key', array()); + $pluginKeys = []; + foreach ($data[$this->alias] as $frame) { + if (isset($frame['plugin_key'])) { + $pluginKeys[] = $frame['plugin_key']; + } + } $saved = $this->find('list', array( 'recursive' => -1, diff --git a/Model/TopicFramesRoom.php b/Model/TopicFramesRoom.php index d542f78..c68da42 100644 --- a/Model/TopicFramesRoom.php +++ b/Model/TopicFramesRoom.php @@ -55,7 +55,7 @@ class TopicFramesRoom extends TopicsAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'frame_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), @@ -78,9 +78,16 @@ public function beforeValidate($options = array()) { * @return bool */ public function validateRequestData($data) { - $roomIds = Hash::extract($data, 'Room.{n}.id'); + $roomIds = []; + if (isset($data['Room'])) { + foreach ($data['Room'] as $room) { + $roomIds[] = $room['id']; + } + } + $check = isset($data['TopicFrameSetting']['room_id']) + ? $data['TopicFrameSetting']['room_id'] + : []; - $check = Hash::get($data, 'TopicFrameSetting' . '.room_id', array()); foreach ($check as $roomId) { if (! in_array($roomId, $roomIds, true)) { return false; @@ -98,8 +105,8 @@ public function validateRequestData($data) { * @return array 条件配列 */ public function getTopicConditions($topicFrameSetting, $conditions) { - if (Hash::get($conditions, 'Topic.room_id')) { - $conditions['Topic.room_id'] = Hash::get($conditions, 'Topic.room_id'); + if (isset($conditions['Topic']['room_id'])) { + $conditions['Topic.room_id'] = $conditions['Topic']['room_id']; } elseif ($topicFrameSetting['TopicFrameSetting']['select_room']) { $roomIds = $this->find('list', array( @@ -126,8 +133,8 @@ public function getTopicConditions($topicFrameSetting, $conditions) { * @return array 条件配列 */ public function getConditions($topicFrameSetting, $conditions) { - if (Hash::get($conditions, $this->alias . '.room_id')) { - $conditions[$this->alias . '.room_id'] = Hash::get($conditions, $this->alias . '.room_id'); + if (isset($conditions[$this->alias]['room_id'])) { + $conditions[$this->alias . '.room_id'] = $conditions[$this->alias]['room_id']; } elseif ($topicFrameSetting['TopicFrameSetting']['select_room']) { $roomIds = $this->find('list', array( @@ -156,7 +163,9 @@ public function getConditions($topicFrameSetting, $conditions) { * @throws InternalErrorException */ public function saveTopicFramesRoom($data) { - $roomIds = Hash::get($data, $this->alias . '.room_id', array()); + $roomIds = isset($data[$this->alias]['room_id']) + ? $data[$this->alias]['room_id'] + : []; $saved = $this->find('list', array( 'recursive' => -1, @@ -178,15 +187,15 @@ public function saveTopicFramesRoom($data) { $new = array_diff($roomIds, $saved); if (count($new) > 0) { - $saveDate = array(); + $saveData = array(); foreach ($new as $i => $roomId) { - $saveDate[$i] = array( + $saveData[$i] = array( 'id' => null, 'room_id' => $roomId, 'frame_key' => Current::read('Frame.key') ); } - if (! $this->saveMany($saveDate)) { + if (! $this->saveMany($saveData)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } } diff --git a/Model/TopicReadable.php b/Model/TopicReadable.php index 6b106ab..910405e 100644 --- a/Model/TopicReadable.php +++ b/Model/TopicReadable.php @@ -63,7 +63,7 @@ class TopicReadable extends TopicsAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'topic_id' => array( 'numeric' => array( 'rule' => array('numeric'), diff --git a/Model/TopicUserStatus.php b/Model/TopicUserStatus.php index 16eab64..d546e41 100644 --- a/Model/TopicUserStatus.php +++ b/Model/TopicUserStatus.php @@ -56,7 +56,7 @@ class TopicUserStatus extends TopicsAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'topic_id' => array( 'numeric' => array( 'rule' => array('numeric'), diff --git a/View/Elements/TopicFrameSettings/edit_form.ctp b/View/Elements/TopicFrameSettings/edit_form.ctp index a1097f6..1027a70 100644 --- a/View/Elements/TopicFrameSettings/edit_form.ctp +++ b/View/Elements/TopicFrameSettings/edit_form.ctp @@ -22,11 +22,14 @@ $selectBlockDomId = $this->NetCommonsForm->domId('TopicFrameSetting.select_block'); $rssFeedDomId = $this->NetCommonsForm->domId('TopicFrameSetting.use_rss_feed'); - $ngInit = $displayTypeDomId . ' = ' . (int)Hash::get($this->request->data, 'TopicFrameSetting.display_type', '0') . '; ' . - $selectRoomDomId . ' = ' . (int)Hash::get($this->request->data, 'TopicFrameSetting.select_room') . '; ' . - $selectPluginDomId . ' = ' . (int)Hash::get($this->request->data, 'TopicFrameSetting.select_plugin') . '; ' . - $selectBlockDomId . ' = ' . (int)Hash::get($this->request->data, 'TopicFrameSetting.select_block') . '; ' . - $rssFeedDomId . ' = ' . (int)Hash::get($this->request->data, 'TopicFrameSetting.use_rss_feed') . ';'; + $useRssFeed = isset($this->request->data['TopicFrameSetting']['use_rss_feed']) + ? $this->request->data['TopicFrameSetting']['use_rss_feed'] + : null; + $ngInit = $displayTypeDomId . ' = ' . (int)$this->request->data['TopicFrameSetting']['display_type'] . '; ' . + $selectRoomDomId . ' = ' . (int)$this->request->data['TopicFrameSetting']['select_room'] . '; ' . + $selectPluginDomId . ' = ' . (int)$this->request->data['TopicFrameSetting']['select_plugin'] . '; ' . + $selectBlockDomId . ' = ' . (int)$this->request->data['TopicFrameSetting']['select_block'] . '; ' . + $rssFeedDomId . ' = ' . (int)$useRssFeed . ';'; ?>
@@ -186,7 +189,9 @@ 'TopicFramesRoom.room_id', array( 'privateSpace' => false, - 'default' => Hash::get($this->request->data, 'TopicFramesRoom.room_id'), + 'default' => isset($this->request->data['TopicFramesRoom']['room_id']) + ? $this->request->data['TopicFramesRoom']['room_id'] + : null, ) ); ?> @@ -220,7 +225,9 @@ 'TopicFramesPlugin.plugin_key', array( 'div' => array('class' => 'plugin-checkbox-outer'), - 'default' => Hash::get($this->request->data, 'TopicFramesPlugin.plugin_key'), + 'default' => isset($this->request->data['TopicFramesPlugin']['plugin_key']) + ? $this->request->data['TopicFramesPlugin']['plugin_key'] + : null, ) ); ?> diff --git a/View/Elements/Topics/select_status.ctp b/View/Elements/Topics/select_status.ctp index 8b43c6a..f155f9b 100644 --- a/View/Elements/Topics/select_status.ctp +++ b/View/Elements/Topics/select_status.ctp @@ -18,7 +18,7 @@ diff --git a/View/Helper/TopicsHelper.php b/View/Helper/TopicsHelper.php index 2a320d6..1ff6a97 100644 --- a/View/Helper/TopicsHelper.php +++ b/View/Helper/TopicsHelper.php @@ -154,17 +154,13 @@ public function camelizeKeyRecursive($orig) { $newResult = []; foreach ($orig as $key => $value) { - if (Hash::get($value, 'TrackableCreator')) { + if (isset($value['TrackableCreator'])) { $avatar = $this->DisplayUser->avatar($value, [], 'TrackableCreator.id'); - $value = Hash::insert( - $value, 'TrackableCreator.avatar', $avatar - ); + $value['TrackableCreator']['avatar'] = $avatar; } - if (Hash::get($value, 'TrackableUpdater')) { + if (isset($value['TrackableUpdater'])) { $avatar = $this->DisplayUser->avatar($value, [], 'TrackableUpdater.id'); - $value = Hash::insert( - $value, 'TrackableUpdater.avatar', $avatar - ); + $value['TrackableUpdater']['avatar'] = $avatar; } $newResult[$key] = $this->__camelizeKeyRecursive($value); @@ -350,14 +346,16 @@ public function dropdownStatus() { $named['page'] = '1'; $named['limit'] = null; - $options = Hash::merge( - array('0' => __d('net_commons', 'All Statuses')), - Hash::combine($this->statuses, '{n}.key', '{n}.message') - ); + $options = [0 => __d('net_commons', 'All Statuses')]; + foreach ($this->statuses as $status) { + $options[$status['key']] = $status['message']; + } return $this->_View->element('Topics.Topics/select_status', array( 'options' => $options, - 'current' => Hash::get($named, 'status', '0'), + 'current' => isset($named['status']) + ? $named['status'] + : 0, 'url' => $named, )); } @@ -383,7 +381,7 @@ public function initSelectBlock() { } /** - * 特定のブロックを表示する選択ボックス群の + * 特定のブロックを表示する選択ボックス群の初期処理 * * @return string HTML出力 */ @@ -402,11 +400,11 @@ public function selectBlock() { ); //プラグイン選択 - $options = Hash::combine( - $this->_View->viewVars['pluginsRoom'], '{n}.Plugin.key', '{n}.Plugin.name' - ); - foreach (TopicFrameSetting::$outPlugins as $plugin) { - $options = Hash::remove($options, $plugin); + $options = []; + foreach ($this->_View->viewVars['pluginsRoom'] as $pluginsRoom) { + if (! in_array($pluginsRoom['Plugin']['key'], TopicFrameSetting::$outPlugins)) { + $options[$pluginsRoom['Plugin']['key']] = $pluginsRoom['Plugin']['name']; + } } $html .= $this->PluginsForm->selectPluginsRoom('TopicFramesBlock.plugin_key', array( @@ -426,8 +424,14 @@ public function selectBlock() { $html .= '
'; if ($this->_View->viewVars['selectBlocks']) { + $selectOptions = []; + foreach ($this->_View->viewVars['selectBlocks'] as $selectBlock) { + foreach ($selectBlock as $key => $item) { + $selectOptions[$key] = $item['name']; + } + } $html .= $this->NetCommonsForm->select('TopicFramesBlock.block_key', - Hash::combine($this->_View->viewVars['selectBlocks'], '{s}.{s}.key', '{s}.{s}.name'), + $selectOptions, array( 'size' => 10, 'class' => 'form-control', 'empty' => false, 'ng-options' => 'item as item.name for item in blockOptions track by item.key', diff --git a/View/Topics/json/index_plugins.ctp b/View/Topics/json/index_plugins.ctp index d4d5972..5d73e46 100644 --- a/View/Topics/json/index_plugins.ctp +++ b/View/Topics/json/index_plugins.ctp @@ -9,7 +9,7 @@ * @copyright Copyright 2014, NetCommons Project */ -$pluginKey = Hash::get($this->request->query, 'plugin_key'); +$pluginKey = $this->request->query['plugin_key']; echo $this->NetCommonsHtml->json(array( 'paging' => $topics[$pluginKey]['paging'], diff --git a/View/Topics/json/index_rooms.ctp b/View/Topics/json/index_rooms.ctp index 5d1bc5e..aee86e9 100644 --- a/View/Topics/json/index_rooms.ctp +++ b/View/Topics/json/index_rooms.ctp @@ -9,7 +9,7 @@ * @copyright Copyright 2014, NetCommons Project */ -$roomId = Hash::get($this->request->query, 'room_id'); +$roomId = $this->request->query['room_id']; echo $this->NetCommonsHtml->json(array( 'paging' => $topics[$roomId]['paging'],