diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index f04b077..f466d54 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -127,21 +127,27 @@ public function index() { ); $this->set('options', $options); - $curretSort = Hash::get($this->params['named'], 'sort', 'BbsArticle.created'); - $curretDirection = Hash::get($this->params['named'], 'direction', 'desc'); - if (! isset($options[$curretSort . '.' . $curretDirection])) { - $curretSort = 'BbsArticle.created'; - $curretDirection = 'desc'; + $currentSort = isset($this->params['named']['sort']) + ? $this->params['named']['sort'] + : 'BbsArticle.created'; + $currentDirection = isset($this->params['named']['sort']) + ? $this->params['named']['direction'] + : 'desc'; + if (! isset($options[$currentSort . '.' . $currentDirection])) { + $currentSort = 'BbsArticle.created'; + $currentDirection = 'desc'; } - $this->set('curretSort', $curretSort); - $this->set('curretDirection', $curretDirection); + $this->set('curretSort', $currentSort); + $this->set('curretDirection', $currentDirection); - $query['order'] = array($curretSort => $curretDirection); + $query['order'] = array($currentSort => $currentDirection); //表示件数 - $query['limit'] = (int)Hash::get( - $this->params['named'], 'limit', $this->viewVars['bbsFrameSetting']['articles_per_page'] - ); + $limit = $this->viewVars['bbsFrameSetting']['articles_per_page']; + if (isset($this->params['named']['limit'])) { + $limit = $this->params['named']['limit']; + } + $query['limit'] = (int)$limit; $this->Paginator->settings = $query; $recursive = $this->BbsArticle->recursive; @@ -200,7 +206,7 @@ public function view() { return $this->throwBadRequest(); } - $bbsArticleKey = Hash::get($this->request->params, 'key', null); + $bbsArticleKey = isset($this->request->params['key']) ? $this->request->params['key'] : null; //カレント記事の取得 $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( @@ -258,7 +264,10 @@ public function view() { ); $this->set('treeList', $treeList); } - $children = Hash::combine($children, '{n}.BbsArticleTree.id', '{n}'); + $bbsArticleChildren = []; + foreach ($children as $child) { + $bbsArticleChildren[$child['BbsArticleTree']['id']] = $child; + } $this->set('bbsArticleChildren', $children); } @@ -288,15 +297,13 @@ public function add() { $this->NetCommons->handleValidationError($this->BbsArticle->validationErrors); } else { - $this->request->data = Hash::merge($this->request->data, - $this->BbsArticle->create(array( + $this->request->data += $this->BbsArticle->create(array( 'bbs_key' => $this->viewVars['bbs']['key'], - )), - $this->BbsArticleTree->create(array( + )); + $this->request->data += $this->BbsArticleTree->create(array( 'bbs_key' => $this->viewVars['bbs']['key'], 'post_no' => 1, - )) - ); + )); $this->request->data['Bbs'] = $this->viewVars['bbs']; $this->request->data['Frame'] = Current::read('Frame'); $this->request->data['Block'] = Current::read('Block'); @@ -309,7 +316,7 @@ public function add() { * @return void */ public function reply() { - $bbsArticleKey = Hash::get($this->request->params, 'key', null); + $bbsArticleKey = isset($this->request->params['key']) ? $this->request->params['key'] : null; $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( 'recursive' => 0, @@ -319,7 +326,8 @@ public function reply() { ) )); - if (Hash::get($bbsArticle, 'BbsArticle.status') !== WorkflowComponent::STATUS_PUBLISHED) { + if (!isset($bbsArticle['BbsArticle']['status']) || + $bbsArticle['BbsArticle']['status'] !== WorkflowComponent::STATUS_PUBLISHED) { return $this->throwBadRequest(); } @@ -356,18 +364,16 @@ public function reply() { } else { $content = null; } - $this->request->data = Hash::merge($this->request->data, - $this->BbsArticle->create(array( + $this->request->data += $this->BbsArticle->create(array( 'bbs_key' => $this->viewVars['bbs']['key'], 'title' => $title, 'content' => $content, - )), - $this->BbsArticleTree->create(array( + )); + $this->request->data += $this->BbsArticleTree->create(array( 'bbs_key' => $this->viewVars['bbs']['key'], 'root_id' => $rootId, 'parent_id' => $bbsArticle['BbsArticleTree']['id'], - )) - ); + )); $this->request->data['Bbs'] = $this->viewVars['bbs']; $this->request->data['Frame'] = Current::read('Frame'); $this->request->data['Block'] = Current::read('Block'); @@ -382,7 +388,7 @@ public function reply() { public function edit() { $this->view = 'edit'; - $bbsArticleKey = Hash::get($this->request->params, 'key', null); + $bbsArticleKey = isset($this->request->params['key']) ? $this->request->params['key'] : null; if ($this->request->is('put')) { $bbsArticleKey = $this->data['BbsArticle']['key']; } diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php old mode 100755 new mode 100644 index 159a350..52636b5 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -113,9 +113,7 @@ public function add() { } else { //表示処理(初期データセット) $this->request->data = $this->Bbs->createBbs(); - $this->request->data = Hash::merge( - $this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true) - ); + $this->request->data += $this->BbsFrameSetting->getBbsFrameSetting(true); $this->request->data['Frame'] = Current::read('Frame'); } } @@ -138,12 +136,9 @@ public function edit() { if (! $bbs = $this->Bbs->getBbs()) { return $this->throwBadRequest(); } - $this->request->data = Hash::merge($this->request->data, $bbs); - $this->request->data = Hash::merge( - $this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true) - ); + $this->request->data += $bbs; + $this->request->data += $this->BbsFrameSetting->getBbsFrameSetting(true); $this->request->data['Frame'] = Current::read('Frame'); - $this->request->data['Block'] = Current::read('Block'); } } diff --git a/Model/Bbs.php b/Model/Bbs.php old mode 100755 new mode 100644 index c7539a3..aaa44ed --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -107,7 +107,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( //'block_id' => array( // 'numeric' => array( // 'rule' => array('numeric'), @@ -138,7 +138,7 @@ public function beforeValidate($options = array()) { if (isset($this->data['BbsSetting'])) { $this->BbsSetting->set($this->data['BbsSetting']); if (! $this->BbsSetting->validates()) { - $this->validationErrors = Hash::merge( + $this->validationErrors = array_merge( $this->validationErrors, $this->BbsSetting->validationErrors ); return false; @@ -148,7 +148,7 @@ public function beforeValidate($options = array()) { if (isset($this->data['BbsFrameSetting']) && ! $this->data['BbsFrameSetting']['id']) { $this->BbsFrameSetting->set($this->data['BbsFrameSetting']); if (! $this->BbsFrameSetting->validates()) { - $this->validationErrors = Hash::merge( + $this->validationErrors = array_merge( $this->validationErrors, $this->BbsFrameSetting->validationErrors ); return false; @@ -201,9 +201,8 @@ public function createBbs() { 'room_id' => Current::read('Room.id'), ), )); - $bbs = Hash::merge($bbs, $this->BbsSetting->createBlockSetting()); - return $bbs; + return ($bbs + $this->BbsSetting->createBlockSetting()); } /** @@ -214,7 +213,6 @@ public function createBbs() { public function getBbs() { $bbs = $this->find('first', [ 'recursive' => 0, - 'fields' => ['Bbs.*'], 'conditions' => $this->getBlockConditionById(), ]); @@ -222,7 +220,7 @@ public function getBbs() { return $bbs; } - return Hash::merge($bbs, $this->BbsSetting->getBbsSetting()); + return ($bbs + $this->BbsSetting->getBbsSetting()); } /** diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index a3a44bd..d5a8712 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -165,7 +165,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( 'title' => array( 'notBlank' => array( 'rule' => array('notBlank'), @@ -188,7 +188,7 @@ public function beforeValidate($options = array()) { if (isset($this->data['BbsArticleTree'])) { $this->BbsArticleTree->set($this->data['BbsArticleTree']); if (! $this->BbsArticleTree->validates()) { - $this->validationErrors = Hash::merge( + $this->validationErrors = array_merge( $this->validationErrors, $this->BbsArticleTree->validationErrors ); return false; diff --git a/Model/BbsArticleTree.php b/Model/BbsArticleTree.php index e5cb0ec..ef124b4 100644 --- a/Model/BbsArticleTree.php +++ b/Model/BbsArticleTree.php @@ -70,7 +70,7 @@ class BbsArticleTree extends BbsesAppModel { * @see Model::save() */ public function beforeValidate($options = array()) { - $this->validate = Hash::merge($this->validate, array( + $this->validate = array_merge($this->validate, array( 'bbs_key' => array( 'notBlank' => array( 'rule' => array('notBlank'), diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index d192f7d..a6061c9 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -70,7 +70,7 @@ class BbsFrameSetting extends BbsesAppModel { * @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'), diff --git a/Model/Behavior/BbsArticleBehavior.php b/Model/Behavior/BbsArticleBehavior.php index a09f381..6c9d2a9 100644 --- a/Model/Behavior/BbsArticleBehavior.php +++ b/Model/Behavior/BbsArticleBehavior.php @@ -167,8 +167,11 @@ public function getChildrenArticleCounts(Model $model, $bbsKey, $bbsArticles, $a ], 'group' => array('BbsArticleTree.root_id'), ); - $counts = $model->find('all', $query); - $counts = Hash::combine($counts, '{n}.BbsArticleTree.root_id', '{n}.0.bbs_article_child_count'); + $results = $model->find('all', $query); + $counts = []; + foreach ($results as $result) { + $counts[$result['BbsArticleTree']['root_id']] = $result[0]['bbs_article_child_count']; + } foreach ($bbsArticles as $i => $article) { if (isset($counts[$article['BbsArticleTree']['id']])) { diff --git a/View/BbsArticles/index.ctp b/View/BbsArticles/index.ctp index 339af30..c6df275 100644 --- a/View/BbsArticles/index.ctp +++ b/View/BbsArticles/index.ctp @@ -18,7 +18,7 @@ echo $this->NetCommonsHtml->css('/bbses/css/style.css');
'bbses', 'controller' => 'bbs_articles', 'action' => 'index', @@ -60,8 +60,12 @@ echo $this->NetCommonsHtml->css('/bbses/css/style.css');
element( - 'BbsArticles/' . Hash::get($bbsFrameSetting, ['display_type'], 'flat') . '/index_bbs_article', + 'BbsArticles/' . $type . '/index_bbs_article', array( 'bbsArticle' => $bbsArticle ) diff --git a/View/BbsArticles/view.ctp b/View/BbsArticles/view.ctp index f9d923a..822d589 100644 --- a/View/BbsArticles/view.ctp +++ b/View/BbsArticles/view.ctp @@ -21,7 +21,13 @@ echo $this->NetCommonsHtml->script([ ]); ?> -
+
NetCommonsHtml->script([ $linkId = sprintf(BbsArticlesController::LINK_ID_FORMAT, $childBbsArticle['BbsArticleTree']['id']); if (isset($bbsArticleChildren[$childBbsArticle['BbsArticleTree']['parent_id']])) { echo $this->element( - 'BbsArticles/' . Hash::get($bbsFrameSetting, ['display_type'], 'flat') . '/view_bbs_child_article', + 'BbsArticles/' . $type . '/view_bbs_child_article', array( 'bbsArticle' => $childBbsArticle, 'parentBbsArticle' => $bbsArticleChildren[$childBbsArticle['BbsArticleTree']['parent_id']], @@ -44,7 +50,7 @@ echo $this->NetCommonsHtml->script([ ); } else { echo $this->element( - 'BbsArticles/' . Hash::get($bbsFrameSetting, ['display_type'], 'flat') . '/view_bbs_child_article', + 'BbsArticles/' . $type . '/view_bbs_child_article', array( 'bbsArticle' => $childBbsArticle, 'parentBbsArticle' => $rootBbsArticle, diff --git a/View/Elements/BbsArticles/all/index_bbs_article.ctp b/View/Elements/BbsArticles/all/index_bbs_article.ctp index 76bb6d3..7ef1a67 100644 --- a/View/Elements/BbsArticles/all/index_bbs_article.ctp +++ b/View/Elements/BbsArticles/all/index_bbs_article.ctp @@ -26,13 +26,13 @@
- + @@ -62,9 +62,13 @@ //子記事 if (isset($treeLists[$bbsArticle['BbsArticleTree']['id']])) { echo '
'; + $type = 'flat'; + if (isset($bbsFrameSetting['display_type'])) { + $type = $bbsFrameSetting['display_type']; + } foreach ($treeLists[$bbsArticle['BbsArticleTree']['id']] as $treeId => $childArticle) { echo $this->element( - 'BbsArticles/' . Hash::get($bbsFrameSetting, ['display_type'], 'flat') . '/index_bbs_child_article', + 'BbsArticles/' . $type . '/index_bbs_child_article', array( 'bbsArticle' => $bbsArticleTitles[$treeId], 'indent' => substr_count($childArticle, '_') + 1 diff --git a/View/Elements/BbsArticles/edit_form.ctp b/View/Elements/BbsArticles/edit_form.ctp index 3900363..b601d30 100644 --- a/View/Elements/BbsArticles/edit_form.ctp +++ b/View/Elements/BbsArticles/edit_form.ctp @@ -55,12 +55,14 @@ echo $this->BbsesForm->replyEditButtons('BbsArticle.status'); } else { if ($this->params['action'] === 'reply') { + $key = isset($currentBbsArticle['BbsArticle']['key']) ? $currentBbsArticle['BbsArticle']['key'] : null; $cancelUrl = NetCommonsUrl::blockUrl( - array('action' => 'view', 'key' => Hash::get($currentBbsArticle, 'BbsArticle.key')) + array('action' => 'view', 'key' => $key) ); } elseif ($this->params['action'] === 'edit') { + $key = isset($currentBbsArticle['BbsArticle']['key']) ? $this->request->data['BbsArticle']['key'] : null; $cancelUrl = NetCommonsUrl::blockUrl( - array('action' => 'view', 'key' => Hash::get($this->request->data, 'BbsArticle.key')) + array('action' => 'view', 'key' => $key) ); } else { $cancelUrl = null; diff --git a/View/Elements/BbsArticles/flat/index_bbs_article.ctp b/View/Elements/BbsArticles/flat/index_bbs_article.ctp index 1254288..23244cc 100644 --- a/View/Elements/BbsArticles/flat/index_bbs_article.ctp +++ b/View/Elements/BbsArticles/flat/index_bbs_article.ctp @@ -33,13 +33,13 @@
- + diff --git a/View/Elements/BbsArticles/root/index_bbs_article.ctp b/View/Elements/BbsArticles/root/index_bbs_article.ctp index 5953c47..58bfafc 100644 --- a/View/Elements/BbsArticles/root/index_bbs_article.ctp +++ b/View/Elements/BbsArticles/root/index_bbs_article.ctp @@ -26,13 +26,13 @@
- + diff --git a/View/Helper/BbsesFormHelper.php b/View/Helper/BbsesFormHelper.php index a41c5a2..547d833 100644 --- a/View/Helper/BbsesFormHelper.php +++ b/View/Helper/BbsesFormHelper.php @@ -44,16 +44,23 @@ public function replyEditButtons($statusFieldName) { $output = ''; $output .= '