From 71bea958092710483ccb3b20fc6a7f84590a66a3 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Mon, 7 Sep 2015 16:28:55 +0900 Subject: [PATCH 01/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E9=96=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsFrameSettingsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index 56d134d..b5ffa00 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -84,7 +84,7 @@ public function edit() { $this->BbsFrameSetting->saveBbsFrameSetting($data); if ($this->handleValidationError($this->BbsFrameSetting->validationErrors)) { - $this->redirectByFrameId(); + $this->redirect(Current::backToPageUrl()); return; } } From a2845ee1e6ab43a2e150c46e7ebb3a9846d1686c Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 11:08:13 +0900 Subject: [PATCH 02/15] =?UTF-8?q?notEmpty=E3=82=92notBlank=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=88cakephp2.7=E5=AF=BE=E5=BF=9C?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Bbs.php | 8 ++++---- Model/BbsArticle.php | 8 ++++---- Model/BbsArticleTree.php | 8 ++++---- Model/BbsArticlesUser.php | 8 ++++---- Model/BbsFrameSetting.php | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Model/Bbs.php b/Model/Bbs.php index 1e13622..f9e29bf 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -92,8 +92,8 @@ public function beforeValidate($options = array()) { // ) //), 'key' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'allowEmpty' => false, 'required' => true, @@ -104,8 +104,8 @@ public function beforeValidate($options = array()) { //status to set in PublishableBehavior. 'name' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('bbses', 'Bbs name')), 'required' => true ), diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index 7f692a1..a7e937b 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -105,15 +105,15 @@ class BbsArticle extends BbsesAppModel { public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array( 'title' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('bbses', 'Title')), 'required' => true ), ), 'content' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('bbses', 'Content')), 'required' => true ), diff --git a/Model/BbsArticleTree.php b/Model/BbsArticleTree.php index e2967d2..e530af5 100644 --- a/Model/BbsArticleTree.php +++ b/Model/BbsArticleTree.php @@ -106,15 +106,15 @@ class BbsArticleTree extends BbsesAppModel { public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array( 'bbs_key' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ), ), 'bbs_article_key' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'on' => 'update', // Limit validation to 'create' or 'update' operations ), diff --git a/Model/BbsArticlesUser.php b/Model/BbsArticlesUser.php index c603cf3..9694677 100644 --- a/Model/BbsArticlesUser.php +++ b/Model/BbsArticlesUser.php @@ -58,15 +58,15 @@ class BbsArticlesUser extends BbsesAppModel { public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array( 'bbs_article_key' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ) ), 'user_id' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ) diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index 3400aea..54a5006 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -85,22 +85,22 @@ public function __construct($id = false, $table = null, $ds = null) { public function beforeValidate($options = array()) { $this->validate = Hash::merge($this->validate, array( 'frame_key' => array( - 'notEmpty' => array( - 'rule' => array('notEmpty'), + 'notBlank' => array( + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ) ), 'articles_per_page' => array( 'number' => array( - 'rule' => array('notEmpty'), + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ) ), 'comments_per_page' => array( 'number' => array( - 'rule' => array('notEmpty'), + 'rule' => array('notBlank'), 'message' => __d('net_commons', 'Invalid request.'), 'required' => true, ) From 6cf0dc2dcaca24189946f5c52a153f3b7eda6182 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 11:44:02 +0900 Subject: [PATCH 03/15] =?UTF-8?q?phpdoc=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/Migration/001_plugin_records.php | 2 +- Controller/BbsArticlesController.php | 4 ++-- Controller/BbsBlockRolePermissionsController.php | 4 ++-- Controller/BbsBlocksController.php | 4 ++-- Controller/BbsFrameSettingsController.php | 4 ++-- Controller/BbsesAppController.php | 4 ++-- Controller/Component/BbsArticlesComponent.php | 2 +- Model/Bbs.php | 4 ++-- Model/BbsArticle.php | 4 ++-- Model/BbsArticleTree.php | 4 ++-- Model/BbsArticlesUser.php | 4 ++-- Model/BbsFrameSetting.php | 4 ++-- Model/BbsSetting.php | 4 ++-- Model/BbsesAppModel.php | 4 ++-- Test/Case/AllBbsesTest.php | 4 ++-- Test/Case/Controller/BbsArticlesControllerTest.php | 5 ++++- Test/Case/Controller/BbsAuthoritySettingsControllerTest.php | 5 ++++- Test/Case/Controller/BbsCommentsControllerTest.php | 5 ++++- Test/Case/Controller/BbsFrameSettingsControllerTest.php | 5 ++++- Test/Case/Controller/BbsesControllerTest.php | 5 ++++- Test/Case/Controller/BbsesControllerTestBase.php | 4 ++-- Test/Case/Model/BbsArticleTest.php | 4 ++-- Test/Case/Model/BbsArticlesUserTest.php | 4 ++-- Test/Case/Model/BbsFrameSettingTest.php | 4 ++-- Test/Case/Model/BbsModelTestBase.php | 4 ++-- Test/Case/Model/BbsTest.php | 4 ++-- Test/Fixture/BbsFixture.php | 4 ++-- Test/Fixture/BbsFrameSettingFixture.php | 2 +- Test/Fixture/BbsSettingFixture.php | 2 +- View/Elements/BbsArticles/comment_status_label.ctp | 2 +- 30 files changed, 65 insertions(+), 50 deletions(-) diff --git a/Config/Migration/001_plugin_records.php b/Config/Migration/001_plugin_records.php index 1e3fb8d..6b59497 100644 --- a/Config/Migration/001_plugin_records.php +++ b/Config/Migration/001_plugin_records.php @@ -13,7 +13,7 @@ /** * Add plugin migration * - * @package NetCommons\PluginManager\Config\Migration + * @package NetCommons\Bbses\Config\Migration */ class PluginRecords extends NetCommonsMigration { diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index 29d54ba..606d1f2 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -3,7 +3,7 @@ * BbsArticles Controller * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -15,7 +15,7 @@ /** * BbsArticles Controller * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Controller */ class BbsArticlesController extends BbsesAppController { diff --git a/Controller/BbsBlockRolePermissionsController.php b/Controller/BbsBlockRolePermissionsController.php index 2b33a5b..cc40fd3 100644 --- a/Controller/BbsBlockRolePermissionsController.php +++ b/Controller/BbsBlockRolePermissionsController.php @@ -3,7 +3,7 @@ * BlockRolePermissions Controller * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,7 +14,7 @@ /** * BlockRolePermissions Controller * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Controller */ class BbsBlockRolePermissionsController extends BbsesAppController { diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index b3be86b..644071e 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -3,7 +3,7 @@ * Blocks Controller * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,7 +14,7 @@ /** * Blocks Controller * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Controller */ class BbsBlocksController extends BbsesAppController { diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index b5ffa00..0e4bbf1 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -3,7 +3,7 @@ * BbsFrameSettings Controller * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,7 +14,7 @@ /** * BbsFrameSettings Controller * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Controller */ class BbsFrameSettingsController extends BbsesAppController { diff --git a/Controller/BbsesAppController.php b/Controller/BbsesAppController.php index 18dcd81..8f3b99c 100644 --- a/Controller/BbsesAppController.php +++ b/Controller/BbsesAppController.php @@ -3,7 +3,7 @@ * BbsesApp Controller * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,7 +14,7 @@ /** * BbsesApp Controller * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Controller */ class BbsesAppController extends AppController { diff --git a/Controller/Component/BbsArticlesComponent.php b/Controller/Component/BbsArticlesComponent.php index b9a7242..cfedc3d 100644 --- a/Controller/Component/BbsArticlesComponent.php +++ b/Controller/Component/BbsArticlesComponent.php @@ -15,7 +15,7 @@ * BbsArticles Component * * @author Shohei Nakajima - * @package NetCommons\Files\Controller\Component + * @package NetCommons\Bbses\Controller\Component */ class BbsArticlesComponent extends Component { diff --git a/Model/Bbs.php b/Model/Bbs.php index f9e29bf..96ff9c6 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -5,7 +5,7 @@ * @property Block $Block * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -16,7 +16,7 @@ /** * Bbs Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class Bbs extends BbsesAppModel { diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index a7e937b..c79df43 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -7,7 +7,7 @@ * @property User $User * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -18,7 +18,7 @@ /** * BbsArticle Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsArticle extends BbsesAppModel { diff --git a/Model/BbsArticleTree.php b/Model/BbsArticleTree.php index e530af5..f7e8bcf 100644 --- a/Model/BbsArticleTree.php +++ b/Model/BbsArticleTree.php @@ -7,7 +7,7 @@ * @property BbsArticleTree $ChildBbsArticleTree * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -18,7 +18,7 @@ /** * BbsArticleTree Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsArticleTree extends BbsesAppModel { diff --git a/Model/BbsArticlesUser.php b/Model/BbsArticlesUser.php index 9694677..99e0ebc 100644 --- a/Model/BbsArticlesUser.php +++ b/Model/BbsArticlesUser.php @@ -6,7 +6,7 @@ * @property User $User * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * BbsArticlesUser Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsArticlesUser extends BbsesAppModel { diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index 54a5006..d2e72a7 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -5,7 +5,7 @@ * @property Block $Block * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -16,7 +16,7 @@ /** * BbsFrameSetting Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsFrameSetting extends BbsesAppModel { diff --git a/Model/BbsSetting.php b/Model/BbsSetting.php index 7b905e3..9a7a79e 100644 --- a/Model/BbsSetting.php +++ b/Model/BbsSetting.php @@ -5,7 +5,7 @@ * @property Block $Block * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -16,7 +16,7 @@ /** * BbsSetting Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsSetting extends BbsesAppModel { diff --git a/Model/BbsesAppModel.php b/Model/BbsesAppModel.php index d98bf0b..4b4c521 100644 --- a/Model/BbsesAppModel.php +++ b/Model/BbsesAppModel.php @@ -5,7 +5,7 @@ * @property Block $Block * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -16,7 +16,7 @@ /** * Bbses App Model * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Model */ class BbsesAppModel extends AppModel { diff --git a/Test/Case/AllBbsesTest.php b/Test/Case/AllBbsesTest.php index 466001e..276ff43 100644 --- a/Test/Case/AllBbsesTest.php +++ b/Test/Case/AllBbsesTest.php @@ -2,7 +2,7 @@ /** * Bbses All Test Suite * - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -11,7 +11,7 @@ /** * Bbses All Test Suite * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case * @codeCoverageIgnore */ diff --git a/Test/Case/Controller/BbsArticlesControllerTest.php b/Test/Case/Controller/BbsArticlesControllerTest.php index 3955958..92d4c4d 100644 --- a/Test/Case/Controller/BbsArticlesControllerTest.php +++ b/Test/Case/Controller/BbsArticlesControllerTest.php @@ -3,7 +3,7 @@ * BbsArticlesController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,6 +14,9 @@ /** * BbsArticlesController Test Case + * + * @author Shohei Nakajima + * @package NetCommons\Bbses\Test\Case\Controller */ class BbsArticlesControllerTest extends BbsesControllerTestBase { diff --git a/Test/Case/Controller/BbsAuthoritySettingsControllerTest.php b/Test/Case/Controller/BbsAuthoritySettingsControllerTest.php index d4551f7..ba8a52f 100644 --- a/Test/Case/Controller/BbsAuthoritySettingsControllerTest.php +++ b/Test/Case/Controller/BbsAuthoritySettingsControllerTest.php @@ -3,7 +3,7 @@ * BbsAuthoritySettingsController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,6 +14,9 @@ /** * BbsAuthoritySettingsController Test Case + * + * @author Shohei Nakajima + * @package NetCommons\Bbses\Test\Case\Controller */ class BbsAuthoritySettingsControllerTest extends BbsesControllerTestBase { diff --git a/Test/Case/Controller/BbsCommentsControllerTest.php b/Test/Case/Controller/BbsCommentsControllerTest.php index d003dc4..4908462 100644 --- a/Test/Case/Controller/BbsCommentsControllerTest.php +++ b/Test/Case/Controller/BbsCommentsControllerTest.php @@ -3,7 +3,7 @@ * BbsCommentsController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,6 +14,9 @@ /** * BbsCommentsController Test Case + * + * @author Shohei Nakajima + * @package NetCommons\Bbses\Test\Case\Controller */ class BbsCommentsControllerTest extends BbsesControllerTestBase { diff --git a/Test/Case/Controller/BbsFrameSettingsControllerTest.php b/Test/Case/Controller/BbsFrameSettingsControllerTest.php index d366e8c..1e42159 100644 --- a/Test/Case/Controller/BbsFrameSettingsControllerTest.php +++ b/Test/Case/Controller/BbsFrameSettingsControllerTest.php @@ -3,7 +3,7 @@ * BbsFrameSettingsController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,6 +14,9 @@ /** * BbsFrameSettingsController Test Case + * + * @author Shohei Nakajima + * @package NetCommons\Bbses\Test\Case\Controller */ class BbsFrameSettingsControllerTest extends BbsesControllerTestBase { diff --git a/Test/Case/Controller/BbsesControllerTest.php b/Test/Case/Controller/BbsesControllerTest.php index b8056fd..ca2019a 100644 --- a/Test/Case/Controller/BbsesControllerTest.php +++ b/Test/Case/Controller/BbsesControllerTest.php @@ -3,7 +3,7 @@ * BbsesController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -14,6 +14,9 @@ /** * BbsesController Test Case + * + * @author Shohei Nakajima + * @package NetCommons\Bbses\Test\Case\Controller */ class BbsesControllerTest extends BbsesControllerTestBase { diff --git a/Test/Case/Controller/BbsesControllerTestBase.php b/Test/Case/Controller/BbsesControllerTestBase.php index 7a6db57..682d797 100644 --- a/Test/Case/Controller/BbsesControllerTestBase.php +++ b/Test/Case/Controller/BbsesControllerTestBase.php @@ -3,7 +3,7 @@ * BbsesController Test Case * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * BbsesController Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Controller * @SuppressWarnings(PHPMD.LongVariable) */ diff --git a/Test/Case/Model/BbsArticleTest.php b/Test/Case/Model/BbsArticleTest.php index 6e7221b..0f2249e 100644 --- a/Test/Case/Model/BbsArticleTest.php +++ b/Test/Case/Model/BbsArticleTest.php @@ -5,7 +5,7 @@ * @property BbsArticle $BbsArticle * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * BbsArticle Model Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Model */ class BbsArticleTest extends BbsModelTestBase { diff --git a/Test/Case/Model/BbsArticlesUserTest.php b/Test/Case/Model/BbsArticlesUserTest.php index bd157a4..1ad4146 100644 --- a/Test/Case/Model/BbsArticlesUserTest.php +++ b/Test/Case/Model/BbsArticlesUserTest.php @@ -5,7 +5,7 @@ * @property BbsArticlesUser $BbsArticlesUser * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * BbsArticlesUser Model Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Model */ class BbsArticlesUserTest extends BbsModelTestBase { diff --git a/Test/Case/Model/BbsFrameSettingTest.php b/Test/Case/Model/BbsFrameSettingTest.php index b2b0c07..627fa32 100644 --- a/Test/Case/Model/BbsFrameSettingTest.php +++ b/Test/Case/Model/BbsFrameSettingTest.php @@ -5,7 +5,7 @@ * @property BbsFrameSetting $BbsFrameSetting * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * BbsFrameSetting Model Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Model */ class BbsFrameSettingTest extends BbsModelTestBase { diff --git a/Test/Case/Model/BbsModelTestBase.php b/Test/Case/Model/BbsModelTestBase.php index ae78a3c..01650ce 100644 --- a/Test/Case/Model/BbsModelTestBase.php +++ b/Test/Case/Model/BbsModelTestBase.php @@ -5,7 +5,7 @@ * @property Bbs $Bbs * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -18,7 +18,7 @@ /** * Bbs Model Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Model */ class BbsModelTestBase extends YACakeTestCase { diff --git a/Test/Case/Model/BbsTest.php b/Test/Case/Model/BbsTest.php index bdc666e..d8c9121 100644 --- a/Test/Case/Model/BbsTest.php +++ b/Test/Case/Model/BbsTest.php @@ -5,7 +5,7 @@ * @property Bbs $Bbs * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,7 +17,7 @@ /** * Bbs Model Test Case * - * @author Kotaro Hokada + * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Case\Model */ class BbsTest extends BbsModelTestBase { diff --git a/Test/Fixture/BbsFixture.php b/Test/Fixture/BbsFixture.php index e922b99..f3db96b 100644 --- a/Test/Fixture/BbsFixture.php +++ b/Test/Fixture/BbsFixture.php @@ -3,7 +3,7 @@ * BbsFixture * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License @@ -13,7 +13,7 @@ /** * BbsFixture * - * @author Kotaro Hokada + * @author Shohei Nakajima * @author Shohei Nakajima * @package NetCommons\Bbses\Test\Fixture */ diff --git a/Test/Fixture/BbsFrameSettingFixture.php b/Test/Fixture/BbsFrameSettingFixture.php index d0c8de7..1465a9b 100644 --- a/Test/Fixture/BbsFrameSettingFixture.php +++ b/Test/Fixture/BbsFrameSettingFixture.php @@ -3,7 +3,7 @@ * BbsFrameSettingFixture * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project diff --git a/Test/Fixture/BbsSettingFixture.php b/Test/Fixture/BbsSettingFixture.php index 8d02097..7c9a522 100644 --- a/Test/Fixture/BbsSettingFixture.php +++ b/Test/Fixture/BbsSettingFixture.php @@ -3,7 +3,7 @@ * BbsSettingFixture * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project diff --git a/View/Elements/BbsArticles/comment_status_label.ctp b/View/Elements/BbsArticles/comment_status_label.ctp index 8af8360..1886843 100644 --- a/View/Elements/BbsArticles/comment_status_label.ctp +++ b/View/Elements/BbsArticles/comment_status_label.ctp @@ -3,7 +3,7 @@ * comment status label element template * * @author Noriko Arai - * @author Kotaro Hokada + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project From 9ebae8fab1ad2a3700e0162ef4e88f5055b5ca94 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 11:44:28 +0900 Subject: [PATCH 04/15] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsesController.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 Controller/BbsesController.php diff --git a/Controller/BbsesController.php b/Controller/BbsesController.php deleted file mode 100644 index 6d7e862..0000000 --- a/Controller/BbsesController.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @author Kotaro Hokada - * @link http://www.netcommons.org NetCommons Project - * @license http://www.netcommons.org/license.txt NetCommons License - * @copyright Copyright 2014, NetCommons Project - */ - -App::uses('BbsesAppController', 'Bbses.Controller'); - -/** - * Bbses Controller - * - * @author Kotaro Hokada - * @package NetCommons\Bbses\Controller - */ -class BbsesController extends BbsesAppController { - -} From 560667da69b4a9d82d95a6767175a67b35aa9188 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 18:26:00 +0900 Subject: [PATCH 05/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsArticlesController.php | 32 +++-- Controller/BbsBlocksController.php | 137 +++++++++++-------- Controller/BbsFrameSettingsController.php | 63 +++++---- Controller/BbsesAppController.php | 30 ++-- Model/Bbs.php | 62 +++++---- Model/BbsFrameSetting.php | 39 +++--- View/BbsBlocks/edit.ctp | 18 +-- View/BbsBlocks/index.ctp | 2 +- View/BbsBlocks/not_found.ctp | 28 ---- View/BbsFrameSettings/edit.ctp | 14 +- View/Elements/BbsBlocks/edit_form.ctp | 88 ++---------- View/Elements/BbsFrameSettings/edit_form.ctp | 58 +++----- webroot/js/bbses.js | 36 ++--- 13 files changed, 276 insertions(+), 331 deletions(-) delete mode 100644 View/BbsBlocks/not_found.ctp diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index 606d1f2..e7df2d7 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -39,16 +39,24 @@ class BbsArticlesController extends BbsesAppController { * @var array */ public $components = array( - 'NetCommons.NetCommonsBlock', - 'NetCommons.NetCommonsWorkflow', - 'NetCommons.NetCommonsRoomRole' => array( - //コンテンツの権限設定 - 'allowedActions' => array( - 'contentCreatable' => array('add', 'edit', 'delete'), - 'contentCommentCreatable' => array('reply'), - 'contentCommentPublishable' => array('approve'), + 'NetCommons.Permission' => array( + //アクセスの権限 + 'allow' => array( + 'add,edit,delete' => 'content_creatable', + 'reply' => 'content_comment_creatable', + 'approve' => 'content_comment_publishable', ), ), +// 'NetCommons.NetCommonsBlock', +// 'NetCommons.NetCommonsWorkflow', +// 'NetCommons.NetCommonsRoomRole' => array( +// //コンテンツの権限設定 +// 'allowedActions' => array( +// 'contentCreatable' => array('add', 'edit', 'delete'), +// 'contentCommentCreatable' => array('reply'), +// 'contentCommentPublishable' => array('approve'), +// ), +// ), 'Paginator', 'Bbses.BbsArticles' ); @@ -58,9 +66,9 @@ class BbsArticlesController extends BbsesAppController { * * @var array */ - public $helpers = array( - 'NetCommons.Token', - ); +// public $helpers = array( +// 'NetCommons.Token', +// ); /** * index @@ -69,7 +77,7 @@ class BbsArticlesController extends BbsesAppController { * @throws Exception */ public function index() { - if (! $this->viewVars['blockId']) { + if (! Current::read('Block.id')) { $this->autoRender = false; return; } diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index 644071e..d2a0f2d 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -42,7 +42,8 @@ class BbsBlocksController extends BbsesAppController { * @var array */ public $helpers = array( - 'NetCommons.Date', +// 'NetCommons.Date', + 'Likes.Like', ); /** @@ -51,13 +52,19 @@ class BbsBlocksController extends BbsesAppController { * @var array */ public $components = array( - 'NetCommons.NetCommonsBlock', - 'NetCommons.NetCommonsRoomRole' => array( - //コンテンツの権限設定 - 'allowedActions' => array( - 'blockEditable' => array('index', 'add', 'edit', 'delete') + 'NetCommons.Permission' => array( + //アクセスの権限 + 'allow' => array( + 'index,add,edit,delete' => 'block_editable', ), ), +// 'NetCommons.NetCommonsBlock', +// 'NetCommons.NetCommonsRoomRole' => array( +// //コンテンツの権限設定 +// 'allowedActions' => array( +// 'blockEditable' => array('index', 'add', 'edit', 'delete') +// ), +// ), 'Paginator', ); @@ -68,7 +75,7 @@ class BbsBlocksController extends BbsesAppController { */ public function beforeFilter() { parent::beforeFilter(); - $this->Auth->deny('index'); +// $this->Auth->deny('index'); //タブの設定 $this->initTabs('block_index', 'block_settings'); @@ -83,25 +90,23 @@ public function index() { $this->Paginator->settings = array( 'Bbs' => array( 'order' => array('Bbs.id' => 'desc'), - 'conditions' => array( - 'Block.id = Bbs.block_id', - 'Block.language_id' => $this->viewVars['languageId'], - 'Block.room_id' => $this->viewVars['roomId'], - ), + 'conditions' => $this->Bbs->getBlockConditions(), ) ); $bbses = $this->Paginator->paginate('Bbs'); if (! $bbses) { - $this->view = 'not_found'; + $this->view = 'Blocks.Blocks/not_found'; return; } + $this->set('bbses', $bbses); + $this->request->data['Frame'] = Current::read('Frame'); - $results = array( - 'bbses' => $bbses, - ); - $results = $this->camelizeKeyRecursive($results); - $this->set($results); +// $results = array( +// 'bbses' => $bbses, +// ); +// $results = $this->camelizeKeyRecursive($results); +// $this->set($results); } /** @@ -112,50 +117,68 @@ public function index() { public function add() { $this->view = 'edit'; - $this->set('blockId', null); - $bbs = $this->Bbs->create( - array( - 'id' => null, - 'key' => null, - 'block_id' => null, - 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), - ) - ); - $bbsSetting = $this->BbsSetting->create( - array('id' => null) - ); - $block = $this->Block->create( - array('id' => null, 'key' => null) - ); - - $data = array(); if ($this->request->isPost()) { - $data = $this->__parseRequestData(); - - if (! isset($this->viewVars['bbsFrameSetting']['id'])) { - $bbsFrameSetting = $this->BbsFrameSetting->create( - array( - 'frame_key' => $this->viewVars['frameKey'] - ) - ); - $data['BbsFrameSetting'] = $bbsFrameSetting['BbsFrameSetting']; + if ($this->Bbs->saveBbs($this->data)) { + $this->redirect(Current::backToIndexUrl('default_setting_action')); } + $this->handleValidationError($this->Bbs->validationErrors); - $this->Bbs->saveBbs($data); - if ($this->handleValidationError($this->Bbs->validationErrors)) { - if (! $this->request->is('ajax')) { - $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); - } - return; - } - $data['Block']['id'] = null; - $data['Block']['key'] = null; - unset($data['Frame']); + } else { + //表示処理(初期データセット) + $this->request->data = $this->Bbs->createAll(array( + $this->Bbs->alias => array( + 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), + ) + )); + $this->request->data = Hash::merge($this->request->data, $this->BbsSetting->create()); + $this->request->data = Hash::merge($this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true)); + $this->request->data['Frame'] = Current::read('Frame'); } - $data = Hash::merge($bbs, $bbsSetting, $block, $data); - $results = $this->camelizeKeyRecursive($data); - $this->set($results); +// $this->set('blockId', null); +// $bbs = $this->Bbs->create( +// array( +// 'id' => null, +// 'key' => null, +// 'block_id' => null, +// 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), +// ) +// ); +// $bbsSetting = $this->BbsSetting->create( +// array('id' => null) +// ); +// $block = $this->Block->create( +// array('id' => null, 'key' => null) +// ); +// +// $data = array(); +// if ($this->request->isPost()) { +// $data = $this->__parseRequestData(); +// +// if (! isset($this->viewVars['bbsFrameSetting']['id'])) { +// $bbsFrameSetting = $this->BbsFrameSetting->create( +// array( +// 'frame_key' => $this->viewVars['frameKey'] +// ) +// ); +// $data['BbsFrameSetting'] = $bbsFrameSetting['BbsFrameSetting']; +// } +// +// $this->Bbs->saveBbs($data); +// if ($this->handleValidationError($this->Bbs->validationErrors)) { +// if (! $this->request->is('ajax')) { +// $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); +// } +// return; +// } +// $data['Block']['id'] = null; +// $data['Block']['key'] = null; +// unset($data['Frame']); +// } +// +// $data = Hash::merge($bbs, $bbsSetting, $block, $data); +// $results = $this->camelizeKeyRecursive($data); +// $this->set($results); } /** diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index 0e4bbf1..5ea3d5a 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -41,12 +41,18 @@ class BbsFrameSettingsController extends BbsesAppController { * @var array */ public $components = array( - 'NetCommons.NetCommonsRoomRole' => array( - //コンテンツの権限設定 - 'allowedActions' => array( - 'blockEditable' => array('edit'), + 'NetCommons.Permission' => array( + //アクセスの権限 + 'allow' => array( + 'edit' => 'page_editable', ), ), +// 'NetCommons.NetCommonsRoomRole' => array( +// //コンテンツの権限設定 +// 'allowedActions' => array( +// 'blockEditable' => array('edit'), +// ), +// ), ); /** @@ -67,33 +73,40 @@ public function beforeFilter() { * @return void */ public function edit() { - if (! $this->NetCommonsFrame->validateFrameId()) { - $this->throwBadRequest(); - return false; - } - - if (! $bbsFrameSetting = $this->BbsFrameSetting->getBbsFrameSetting($this->viewVars['frameKey'])) { - $bbsFrameSetting = $this->BbsFrameSetting->create(array( - 'frame_key' => $this->viewVars['frameKey'] - )); - } +// if (! $this->NetCommonsFrame->validateFrameId()) { +// $this->throwBadRequest(); +// return false; +// } - $data = array(); - if ($this->request->isPost()) { - $data = $this->data; - $this->BbsFrameSetting->saveBbsFrameSetting($data); - - if ($this->handleValidationError($this->BbsFrameSetting->validationErrors)) { + if ($this->request->isPut() || $this->request->isPost()) { + if ($this->BbsFrameSetting->saveBbsFrameSetting($this->data)) { $this->redirect(Current::backToPageUrl()); return; } + $this->handleValidationError($this->BbsFrameSetting->validationErrors); + + } else { + $this->request->data = $this->BbsFrameSetting->getBbsFrameSetting(true); + $this->request->data['Frame'] = Current::read('Frame'); } - $data = Hash::merge( - $bbsFrameSetting, $data - ); - $results = $this->camelizeKeyRecursive($data); - $this->set($results); + +// $data = array(); +// if ($this->request->isPost()) { +// $data = $this->data; +// $this->BbsFrameSetting->saveBbsFrameSetting($data); +// +// if ($this->handleValidationError($this->BbsFrameSetting->validationErrors)) { +// $this->redirect(Current::backToPageUrl()); +// return; +// } +// } +// +// $data = Hash::merge( +// $bbsFrameSetting, $data +// ); +// $results = $this->camelizeKeyRecursive($data); +// $this->set($results); } } diff --git a/Controller/BbsesAppController.php b/Controller/BbsesAppController.php index 8f3b99c..6bb02a2 100644 --- a/Controller/BbsesAppController.php +++ b/Controller/BbsesAppController.php @@ -25,7 +25,7 @@ class BbsesAppController extends AppController { * @var array */ public $components = array( - 'NetCommons.NetCommonsFrame', +// 'NetCommons.NetCommonsFrame', 'Pages.PageLayout', 'Security' ); @@ -45,9 +45,9 @@ class BbsesAppController extends AppController { * * @var array */ - public $helpers = array( - 'NetCommons.Date', - ); +// public $helpers = array( +// 'NetCommons.Date', +// ); /** * initBbs @@ -93,11 +93,11 @@ public function initBbs($contains = []) { * @return void */ public function initTabs($mainActiveTab, $blockActiveTab) { - if (isset($this->params['pass'][1])) { - $blockId = (int)$this->params['pass'][1]; - } else { - $blockId = null; - } +// if (isset($this->params['pass'][1])) { +// $blockId = (int)$this->params['pass'][1]; +// } else { +// $blockId = null; +// } //タブの設定 $settingTabs = array( @@ -107,7 +107,7 @@ public function initTabs($mainActiveTab, $blockActiveTab) { 'plugin' => $this->params['plugin'], 'controller' => 'bbs_blocks', 'action' => 'index', - $this->viewVars['frameId'], + Current::read('Frame.id'), ) ), 'frame_settings' => array( @@ -115,7 +115,7 @@ public function initTabs($mainActiveTab, $blockActiveTab) { 'plugin' => $this->params['plugin'], 'controller' => 'bbs_frame_settings', 'action' => 'edit', - $this->viewVars['frameId'], + Current::read('Frame.id'), ) ), ), @@ -130,8 +130,8 @@ public function initTabs($mainActiveTab, $blockActiveTab) { 'plugin' => $this->params['plugin'], 'controller' => 'bbs_blocks', 'action' => $this->params['action'], - $this->viewVars['frameId'], - $blockId + Current::read('Frame.id'), + Current::read('Block.id'), ) ), 'role_permissions' => array( @@ -139,8 +139,8 @@ public function initTabs($mainActiveTab, $blockActiveTab) { 'plugin' => $this->params['plugin'], 'controller' => 'bbs_block_role_permissions', 'action' => 'edit', - $this->viewVars['frameId'], - $blockId + Current::read('Frame.id'), + Current::read('Block.id'), ) ), ), diff --git a/Model/Bbs.php b/Model/Bbs.php index 96ff9c6..b2427cf 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -41,6 +41,13 @@ class Bbs extends BbsesAppModel { * @var array */ public $actsAs = array( + 'Blocks.Block' => array( + 'name' => 'Bbs.name', + 'loadModels' => array( + 'Like' => 'Likes.Like', + 'Comment' => 'Comments.Comment', + ) + ), 'NetCommons.OriginalKey', ); @@ -148,48 +155,51 @@ public function saveBbs($data) { 'Bbs' => 'Bbses.Bbs', 'BbsSetting' => 'Bbses.BbsSetting', 'BbsFrameSetting' => 'Bbses.BbsFrameSetting', - 'Block' => 'Blocks.Block', - 'Frame' => 'Frames.Frame', +// 'Block' => 'Blocks.Block', +// 'Frame' => 'Frames.Frame', ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); + + $this->set($data); + if (! $this->validates()) { + return false; + } try { - //バリデーション - if (! $this->validateBbs($data, ['bbsSetting', 'block', 'bbsFrameSetting'])) { - return false; - } +// //バリデーション +// if (! $this->validateBbs($data, ['bbsSetting', 'block', 'bbsFrameSetting'])) { +// return false; +// } - //ブロックの登録 - $block = $this->Block->saveByFrameId($data['Frame']['id']); +// //ブロックの登録 +// $block = $this->Block->saveByFrameId($data['Frame']['id']); //登録処理 - $this->data['Bbs']['block_id'] = (int)$block['Block']['id']; - if (! $bbs = $this->save(null, false)) { +// $this->data['Bbs']['block_id'] = (int)$block['Block']['id']; + if (! $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - $this->BbsSetting->data['BbsSetting']['bbs_key'] = $bbs['Bbs']['key']; - if (! $this->BbsSetting->save(null, false)) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - if (isset($data['BbsFrameSetting'])) { - if (! $this->BbsFrameSetting->save(null, false)) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - } +// $this->BbsSetting->data['BbsSetting']['bbs_key'] = $bbs['Bbs']['key']; +// if (! $this->BbsSetting->save(null, false)) { +// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); +// } +// if (isset($data['BbsFrameSetting'])) { +// if (! $this->BbsFrameSetting->save(null, false)) { +// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); +// } +// } //トランザクションCommit - $dataSource->commit(); + $this->commit(); } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); +// CakeLog::error($ex); +// throw $ex; } return true; diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index d2e72a7..da9c57c 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -26,7 +26,7 @@ class BbsFrameSetting extends BbsesAppModel { * * @var array */ - static public $displayNumberOptions = array(); +// static public $displayNumberOptions = array(); /** * Validation rules @@ -60,18 +60,18 @@ class BbsFrameSetting extends BbsesAppModel { * @see Model::__construct() * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function __construct($id = false, $table = null, $ds = null) { - parent::__construct($id, $table, $ds); - - self::$displayNumberOptions = array( - 1 => __d('bbses', '%s article', 1), - 5 => __d('bbses', '%s articles', 5), - 10 => __d('bbses', '%s articles', 10), - 20 => __d('bbses', '%s articles', 20), - 50 => __d('bbses', '%s articles', 50), - 100 => __d('bbses', '%s articles', 100), - ); - } +// public function __construct($id = false, $table = null, $ds = null) { +// parent::__construct($id, $table, $ds); +// +// self::$displayNumberOptions = array( +// 1 => __d('bbses', '%s article', 1), +// 5 => __d('bbses', '%s articles', 5), +// 10 => __d('bbses', '%s articles', 10), +// 20 => __d('bbses', '%s articles', 20), +// 50 => __d('bbses', '%s articles', 50), +// 100 => __d('bbses', '%s articles', 100), +// ); +// } /** * Called during validation operations, before validation. Please note that custom @@ -112,12 +112,11 @@ public function beforeValidate($options = array()) { /** * Get bbs frame setting data * - * @param string $frameKey frames.key - * @return array + * @return array BbsFrameSetting data */ - public function getBbsFrameSetting($frameKey) { + public function getBbsFrameSetting($created) { $conditions = array( - 'frame_key' => $frameKey + 'frame_key' => Current::read('Frame.key') ); $bbsFrameSetting = $this->find('first', array( @@ -126,6 +125,12 @@ public function getBbsFrameSetting($frameKey) { ) ); + if ($created && ! $bbsFrameSetting) { + $bbsFrameSetting = $this->create(array( + 'frame_key' => Current::read('Frame.key') + )); + } + return $bbsFrameSetting; } diff --git a/View/BbsBlocks/edit.ctp b/View/BbsBlocks/edit.ctp index 45d6966..e2c3ee0 100644 --- a/View/BbsBlocks/edit.ctp +++ b/View/BbsBlocks/edit.ctp @@ -8,29 +8,29 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ -?> -Html->script('/bbses/js/bbses.js', false); ?> +echo $this->NetCommonsHtml->script('/bbses/js/bbses.js'); +?> - + diff --git a/View/BbsBlocks/index.ctp b/View/BbsBlocks/index.ctp index ff9650f..2b05d48 100644 --- a/View/BbsBlocks/index.ctp +++ b/View/BbsBlocks/index.ctp @@ -3,7 +3,7 @@ * block index template * * @author Noriko Arai - * @author Ryo Ozawa + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project diff --git a/View/BbsBlocks/not_found.ctp b/View/BbsBlocks/not_found.ctp deleted file mode 100644 index 37e35fb..0000000 --- a/View/BbsBlocks/not_found.ctp +++ /dev/null @@ -1,28 +0,0 @@ - - * @author Shohei Nakajima - * @link http://www.netcommons.org NetCommons Project - * @license http://www.netcommons.org/license.txt NetCommons License - * @copyright Copyright 2014, NetCommons Project - */ -?> - - diff --git a/View/BbsFrameSettings/edit.ctp b/View/BbsFrameSettings/edit.ctp index 2361e63..1842fb0 100644 --- a/View/BbsFrameSettings/edit.ctp +++ b/View/BbsFrameSettings/edit.ctp @@ -1,24 +1,24 @@ - * @author Ryo Ozawa + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ ?> - + diff --git a/View/Elements/BbsBlocks/edit_form.ctp b/View/Elements/BbsBlocks/edit_form.ctp index 2a93e3f..f770c29 100644 --- a/View/Elements/BbsBlocks/edit_form.ctp +++ b/View/Elements/BbsBlocks/edit_form.ctp @@ -10,87 +10,23 @@ */ ?> -Form->hidden('id', array( - 'value' => isset($bbsSetting['id']) ? (int)$bbsSetting['id'] : null, - )); ?> - element('Blocks.form_hidden'); ?> -Form->hidden('Bbs.id', array( - 'value' => isset($bbs['id']) ? (int)$bbs['id'] : null, - )); ?> - -Form->hidden('Bbs.key', array( - 'value' => isset($bbs['key']) ? $bbs['key'] : null, - )); ?> +Form->hidden('Bbs.id'); ?> +Form->hidden('Bbs.key'); ?> +Form->hidden('BbsSetting.id'); ?> +Form->hidden('BbsFrameSetting.id'); ?> +Form->hidden('BbsFrameSetting.frame_key'); ?> -Form->hidden('BbsSetting.id', array( - 'value' => isset($bbsSetting['id']) ? (int)$bbsSetting['id'] : null, +NetCommonsForm->input('Bbs.name', array( + 'type' => 'text', + 'label' => __d('bbses', 'Bbs name'), )); ?> -
-
- Form->input( - 'Bbs.name', array( - 'type' => 'text', - 'label' => __d('bbses', 'Bbs name') . $this->element('NetCommons.required'), - 'error' => false, - 'class' => 'form-control', - 'value' => (isset($bbs['name']) ? $bbs['name'] : '') - ) - ); ?> -
- -
- element( - 'NetCommons.errors', [ - 'errors' => $this->validationErrors, - 'model' => 'Bbs', - 'field' => 'name', - ]); ?> -
-
- element('Blocks.public_type'); ?> -
-
- Form->checkbox('BbsSetting.use_comment', array( - 'div' => false, - //'hiddenField' => false, - 'checked' => (int)$bbsSetting['useComment'] - ) - ); ?> - Form->label('BbsSetting.use_comment', __d('bbses', 'Use comment')); ?> -
-
- -
-
- Form->checkbox('BbsSetting.use_like', array( - 'div' => false, - 'checked' => (int)$bbsSetting['useLike'], - 'ng-click' => 'useLike()' - ) - ); ?> - - Form->label('BbsSetting.use_like', - ' ' . - __d('likes', 'Use like button') - ); ?> -
- -
- Form->checkbox('BbsSetting.use_unlike', array( - 'div' => false, - 'checked' => (int)$bbsSetting['useUnlike'], - 'disabled' => ! (int)$bbsSetting['useLike'] - ) - ); ?> +NetCommonsForm->inlineCheckbox('BbsSetting.use_comment', array( + 'label' => __d('bbses', 'Use comment') + )); ?> - Form->label('BbsSetting.use_unlike', - ' ' . - __d('likes', 'Use unlike button') - ); ?> -
-
+Like->setting('BbsSetting.use_like', 'BbsSetting.use_unlike'); \ No newline at end of file diff --git a/View/Elements/BbsFrameSettings/edit_form.ctp b/View/Elements/BbsFrameSettings/edit_form.ctp index 7c80b7d..72b0746 100644 --- a/View/Elements/BbsFrameSettings/edit_form.ctp +++ b/View/Elements/BbsFrameSettings/edit_form.ctp @@ -1,53 +1,31 @@ - * @author Ryo Ozawa + * @author Shohei Nakajima * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ ?> -Form->hidden('Frame.id', array( - 'value' => $frameId, - )); ?> - -Form->hidden('BbsFrameSetting.id', array( - 'value' => isset($bbsFrameSetting['id']) ? (int)$bbsFrameSetting['id'] : null, - )); ?> +Form->hidden('Frame.id'); ?> +Form->hidden('BbsFrameSetting.id'); ?> +Form->hidden('BbsFrameSetting.frame_key'); ?> -Form->hidden('BbsFrameSetting.frame_key', array( - 'value' => $frameKey, +NetCommonsForm->selectDisplayNumber('BbsFrameSetting.articles_per_page', array( + 'label' => __d('bbses', 'Show articles per page'), + 'unit' => array( + 'single' => __d('bbses', '%s article'), + 'multiple' => __d('bbses', '%s articles') + ), )); ?> -
- Form->label(__d('bbses', 'Show articles per page')); ?> - Form->select('BbsFrameSetting.articles_per_page', - BbsFrameSetting::$displayNumberOptions, - array( - //'label' => false, - 'type' => 'select', - 'class' => 'form-control', - 'value' => $bbsFrameSetting['articlesPerPage'], - //'legend' => false, - 'empty' => false, - ) - ); ?> -
- -
- Form->label(__d('bbses', 'Show comments per page')); ?> - Form->select('BbsFrameSetting.comments_per_page', - BbsFrameSetting::$displayNumberOptions, - array( - //'label' => false, - 'type' => 'select', - 'class' => 'form-control', - 'value' => $bbsFrameSetting['commentsPerPage'], - //'legend' => false, - 'empty' => false, - ) - ); ?> -
+NetCommonsForm->selectDisplayNumber('BbsFrameSetting.comments_per_page', array( + 'label' => __d('bbses', 'Show comments per page'), + 'unit' => array( + 'single' => __d('bbses', '%s article'), + 'multiple' => __d('bbses', '%s articles') + ), + )); \ No newline at end of file diff --git a/webroot/js/bbses.js b/webroot/js/bbses.js index 7c46398..5a62bae 100644 --- a/webroot/js/bbses.js +++ b/webroot/js/bbses.js @@ -10,24 +10,24 @@ * @param {string} Controller name * @param {function($scope)} Controller */ -NetCommonsApp.controller('Bbses', function($scope) { - - /** - * Use like button - * - * @return {void} - */ - $scope.useLike = function() { - var likeElement = $('#BbsSettingUseLike'); - var unlikeElement = $('#BbsSettingUseUnlike'); - - if (likeElement[0].checked) { - unlikeElement[0].disabled = false; - } else { - unlikeElement[0].disabled = true; - } - }; -}); +//NetCommonsApp.controller('Bbses', function($scope) { +// +// /** +// * Use like button +// * +// * @return {void} +// */ +// $scope.useLike = function() { +// var likeElement = $('#BbsSettingUseLike'); +// var unlikeElement = $('#BbsSettingUseUnlike'); +// +// if (likeElement[0].checked) { +// unlikeElement[0].disabled = false; +// } else { +// unlikeElement[0].disabled = true; +// } +// }; +//}); /** From 2f1b4584b25ed0ec768c5c1a7616d70f06e7edaf Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 23:21:51 +0900 Subject: [PATCH 06/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsArticlesController.php | 41 ++--- Controller/BbsBlocksController.php | 104 ++++++------ Model/Bbs.php | 208 +++++++++++++----------- Model/BbsFrameSetting.php | 2 +- View/BbsBlocks/edit.ctp | 6 +- View/BbsBlocks/index.ctp | 114 +++++-------- View/Bbses/index.ctp | 13 -- View/Elements/BbsBlocks/delete_form.ctp | 23 +-- View/Elements/BbsBlocks/edit_form.ctp | 4 +- 9 files changed, 251 insertions(+), 264 deletions(-) delete mode 100644 View/Bbses/index.ctp diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index e7df2d7..17901d9 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -77,28 +77,29 @@ class BbsArticlesController extends BbsesAppController { * @throws Exception */ public function index() { - if (! Current::read('Block.id')) { + //if (! Current::read('Block.id')) { $this->autoRender = false; return; - } - $this->initBbs(['bbsFrameSetting']); - - //Paginatorの設定 - $this->Paginator->settings = $this->BbsArticles->paginatorSettings(); - - try { - $this->BbsArticle->bindModelBbsArticlesUser($this->viewVars['userId']); - $articles = $this->Paginator->paginate('BbsArticle'); - } catch (Exception $ex) { - CakeLog::error($ex); - throw $ex; - } - - $results = array( - 'bbsArticles' => $articles - ); - $results = $this->camelizeKeyRecursive($results); - $this->set($results); + //} + +// $this->initBbs(['bbsFrameSetting']); +// +// //Paginatorの設定 +// $this->Paginator->settings = $this->BbsArticles->paginatorSettings(); +// +// try { +// $this->BbsArticle->bindModelBbsArticlesUser($this->viewVars['userId']); +// $articles = $this->Paginator->paginate('BbsArticle'); +// } catch (Exception $ex) { +// CakeLog::error($ex); +// throw $ex; +// } +// +// $results = array( +// 'bbsArticles' => $articles +// ); +// $results = $this->camelizeKeyRecursive($results); +// $this->set($results); } /** diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index d2a0f2d..1e75c8c 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -125,12 +125,7 @@ public function add() { } else { //表示処理(初期データセット) - $this->request->data = $this->Bbs->createAll(array( - $this->Bbs->alias => array( - 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), - ) - )); - $this->request->data = Hash::merge($this->request->data, $this->BbsSetting->create()); + $this->request->data = $this->Bbs->createBbs(); $this->request->data = Hash::merge($this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true)); $this->request->data['Frame'] = Current::read('Frame'); } @@ -187,28 +182,46 @@ public function add() { * @return void */ public function edit() { - if (! $this->NetCommonsBlock->validateBlockId()) { - $this->throwBadRequest(); - return false; - } - $this->set('blockId', (int)$this->params['pass'][1]); - - $this->initBbs(['bbsFrameSetting']); - - if ($this->request->isPost()) { - $data = $this->__parseRequestData(); - - $this->Bbs->saveBbs($data); - if ($this->handleValidationError($this->Bbs->validationErrors)) { - if (! $this->request->is('ajax')) { - $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); - } - return; + if ($this->request->isPut()) { + if ($this->Bbs->saveBbs($this->data)) { + $this->redirect(Current::backToIndexUrl('default_setting_action')); } + $this->handleValidationError($this->Bbs->validationErrors); - $results = $this->camelizeKeyRecursive($data); - $this->set($results); + } else { + //表示処理(初期データセット) + CurrentFrame::setBlock($this->request->params['pass'][1]); + if (! $bbs = $this->Bbs->getBbs()) { + $this->throwBadRequest(); + return false; + } + $this->request->data = Hash::merge($this->request->data, $bbs); + $this->request->data = Hash::merge($this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true)); + $this->request->data['Frame'] = Current::read('Frame'); } + +// if (! $this->NetCommonsBlock->validateBlockId()) { +// $this->throwBadRequest(); +// return false; +// } +// $this->set('blockId', (int)$this->params['pass'][1]); +// +// $this->initBbs(['bbsFrameSetting']); +// +// if ($this->request->isPost()) { +// $data = $this->__parseRequestData(); +// +// $this->Bbs->saveBbs($data); +// if ($this->handleValidationError($this->Bbs->validationErrors)) { +// if (! $this->request->is('ajax')) { +// $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); +// } +// return; +// } +// +// $results = $this->camelizeKeyRecursive($data); +// $this->set($results); +// } } /** @@ -217,20 +230,17 @@ public function edit() { * @return void */ public function delete() { - if (! $this->NetCommonsBlock->validateBlockId()) { - $this->throwBadRequest(); - return false; - } - $this->set('blockId', (int)$this->params['pass'][1]); - - $this->initBbs(['bbsFrameSetting']); +// if (! $this->NetCommonsBlock->validateBlockId()) { +// $this->throwBadRequest(); +// return false; +// } +// $this->set('blockId', (int)$this->params['pass'][1]); +// +// $this->initBbs(['bbsFrameSetting']); if ($this->request->isDelete()) { if ($this->Bbs->deleteBbs($this->data)) { - if (! $this->request->is('ajax')) { - $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); - } - return; + $this->redirect(Current::backToIndexUrl('default_setting_action')); } } @@ -242,16 +252,16 @@ public function delete() { * * @return array */ - private function __parseRequestData() { - $data = $this->data; - if ($data['Block']['public_type'] === Block::TYPE_LIMITED) { - //$data['Block']['from'] = implode('-', $data['Block']['from']); - //$data['Block']['to'] = implode('-', $data['Block']['to']); - } else { - unset($data['Block']['from'], $data['Block']['to']); - } - - return $data; - } +// private function __parseRequestData() { +// $data = $this->data; +// if ($data['Block']['public_type'] === Block::TYPE_LIMITED) { +// //$data['Block']['from'] = implode('-', $data['Block']['from']); +// //$data['Block']['to'] = implode('-', $data['Block']['to']); +// } else { +// unset($data['Block']['from'], $data['Block']['to']); +// } +// +// return $data; +// } } diff --git a/Model/Bbs.php b/Model/Bbs.php index b2427cf..a1f601b 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -72,8 +72,8 @@ class Bbs extends BbsesAppModel { * @var array */ public $hasMany = array( - 'BbsSettings' => array( - 'className' => 'Bbses.BbsSettings', + 'BbsSetting' => array( + 'className' => 'Bbses.BbsSetting', 'foreignKey' => 'bbs_key', 'dependent' => false ), @@ -118,29 +118,117 @@ public function beforeValidate($options = array()) { ), ), )); - return parent::beforeValidate($options); + + if (! parent::beforeValidate($options)) { + return false; + } + + if (isset($this->data['BbsSetting'])) { + $this->BbsSetting->set($this->data['BbsSetting']); + if (! $this->BbsSetting->validates()) { + $this->validationErrors = Hash::merge($this->validationErrors, $this->BbsSetting->validationErrors); + return false; + } + } + + 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, $this->BbsFrameSetting->validationErrors); + return false; + } + } } /** - * Get bbs data + * Called after each successful save operation. + * + * @param bool $created True if this save created a new record + * @param array $options Options passed from Model::save(). + * @return void + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave + * @see Model::save() + */ + public function afterSave($created, $options = array()) { + //BbsSetting登録 + if (isset($this->BbsSetting->data['BbsSetting'])) { + if (! $this->BbsSetting->data['BbsSetting']['bbs_key']) { + $this->BbsSetting->data['BbsSetting']['bbs_key'] = $this->data[$this->alias]['key']; + } + if (! $this->BbsSetting->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + } + + //BbsFrameSetting登録 + if (isset($this->BbsFrameSetting->data['BbsFrameSetting']) && ! $this->BbsFrameSetting->data['BbsFrameSetting']['id']) { + if (! $this->BbsFrameSetting->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + } + + parent::afterSave($created, $options); + } + +/** + * Create bbs data * - * @param int $blockId blocks.id - * @param int $roomId rooms.id * @return array */ - public function getBbs($blockId, $roomId) { - $conditions = array( - 'Block.id' => $blockId, - 'Block.room_id' => $roomId, - ); + public function createBbs() { + $this->BbsSetting = ClassRegistry::init('Bbses.BbsSetting'); - $faq = $this->find('first', array( - 'recursive' => 0, - 'conditions' => $conditions, - ) - ); + $bbs = $this->createAll(array( + 'Bbs' => array( + 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), + ), + 'Block' => array( + 'room_id' => Current::read('Room.id'), + 'language_id' => Current::read('Language.id'), + ), + )); + $bbs = Hash::merge($bbs, $this->BbsSetting->create()); + + return $bbs; + } - return $faq; +/** + * Get bbs data + * + * @return array + */ + public function getBbs() { + $bbs = $this->find('all', array( + 'recursive' => -1, + 'fields' => array( + $this->alias . '.*', + $this->Block->alias . '.*', + $this->BbsSetting->alias . '.*', + ), + 'joins' => array( + array( + 'table' => $this->Block->table, + 'alias' => $this->Block->alias, + 'type' => 'INNER', + 'conditions' => array( + $this->alias . '.block_id' . ' = ' . $this->Block->alias . ' .id', + ), + ), + array( + 'table' => $this->BbsSetting->table, + 'alias' => $this->BbsSetting->alias, + 'type' => 'INNER', + 'conditions' => array( + $this->alias . '.key' . ' = ' . $this->BbsSetting->alias . ' .bbs_key', + ), + ), + ), + 'conditions' => $this->getBlockConditionById(), + )); + if (! $bbs) { + return $bbs; + } + return $bbs[0]; } /** @@ -155,90 +243,31 @@ public function saveBbs($data) { 'Bbs' => 'Bbses.Bbs', 'BbsSetting' => 'Bbses.BbsSetting', 'BbsFrameSetting' => 'Bbses.BbsFrameSetting', -// 'Block' => 'Blocks.Block', -// 'Frame' => 'Frames.Frame', ]); //トランザクションBegin $this->begin(); + //バリデーション $this->set($data); if (! $this->validates()) { return false; } try { -// //バリデーション -// if (! $this->validateBbs($data, ['bbsSetting', 'block', 'bbsFrameSetting'])) { -// return false; -// } - -// //ブロックの登録 -// $block = $this->Block->saveByFrameId($data['Frame']['id']); - //登録処理 -// $this->data['Bbs']['block_id'] = (int)$block['Block']['id']; if (! $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } -// $this->BbsSetting->data['BbsSetting']['bbs_key'] = $bbs['Bbs']['key']; -// if (! $this->BbsSetting->save(null, false)) { -// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); -// } -// if (isset($data['BbsFrameSetting'])) { -// if (! $this->BbsFrameSetting->save(null, false)) { -// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); -// } -// } - //トランザクションCommit $this->commit(); } catch (Exception $ex) { //トランザクションRollback $this->rollback($ex); -// CakeLog::error($ex); -// throw $ex; - } - - return true; - } - -/** - * validate bbs - * - * @param array $data received post data - * @param array $contains Optional validate sets - * @return bool True on success, false on validation errors - */ - public function validateBbs($data, $contains = []) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; } - if (in_array('bbsSetting', $contains, true)) { - if (! $this->BbsSetting->validateBbsSetting($data)) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->BbsSetting->validationErrors); - return false; - } - } - - if (in_array('block', $contains, true)) { - if (! $this->Block->validateBlock($data)) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->Block->validationErrors); - return false; - } - } - - if (in_array('bbsFrameSetting', $contains, true) && isset($data['BbsFrameSetting'])) { - if (! $this->BbsFrameSetting->validateBbsFrameSetting($data)) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->BbsFrameSetting->validationErrors); - return false; - } - } return true; } @@ -255,24 +284,18 @@ public function deleteBbs($data) { 'BbsSetting' => 'Bbses.BbsSetting', 'BbsArticle' => 'Bbses.BbsArticle', 'BbsArticleTree' => 'Bbses.BbsArticleTree', - 'Block' => 'Blocks.Block', - 'BlockRolePermission' => 'Blocks.BlockRolePermission', - 'Comment' => 'Comments.Comment', ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); $conditions = array( $this->alias . '.key' => $data['Bbs']['key'] ); $bbses = $this->find('list', array( - 'recursive' => -1, - 'conditions' => $conditions, - ) - ); + 'recursive' => -1, + 'conditions' => $conditions, + )); $bbsIds = array_keys($bbses); try { @@ -292,20 +315,15 @@ public function deleteBbs($data) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - //コメントの削除 - $this->Comment->deleteByBlockKey($data['Block']['key']); - //Blockデータ削除 - $this->Block->deleteBlock($data['Block']['key']); + $this->deleteBlock($data['Block']['key']); //トランザクションCommit - $dataSource->commit(); + $this->commit(); } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); } return true; diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index da9c57c..f07b795 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -127,7 +127,7 @@ public function getBbsFrameSetting($created) { if ($created && ! $bbsFrameSetting) { $bbsFrameSetting = $this->create(array( - 'frame_key' => Current::read('Frame.key') + 'frame_key' => Current::read('Frame.key'), )); } diff --git a/View/BbsBlocks/edit.ctp b/View/BbsBlocks/edit.ctp index e2c3ee0..7356179 100644 --- a/View/BbsBlocks/edit.ctp +++ b/View/BbsBlocks/edit.ctp @@ -8,11 +8,9 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ - -echo $this->NetCommonsHtml->script('/bbses/js/bbses.js'); ?> -
+
element('NetCommons.setting_tabs', $settingTabs); ?>
@@ -27,7 +25,7 @@ echo $this->NetCommonsHtml->script('/bbses/js/bbses.js'); request->params['action'] === 'edit') : ?> element('Blocks.delete_form', array( - 'controller' => 'BbsBlock', + 'model' => 'BbsBlock', 'action' => 'delete/' . Current::read('Frame.id') . '/' . Current::read('Block.id'), 'callback' => 'Bbses.BbsBlocks/delete_form' )); ?> diff --git a/View/BbsBlocks/index.ctp b/View/BbsBlocks/index.ctp index 2b05d48..155eccd 100644 --- a/View/BbsBlocks/index.ctp +++ b/View/BbsBlocks/index.ctp @@ -1,6 +1,6 @@ * @author Shohei Nakajima @@ -10,85 +10,61 @@ */ ?> - +
diff --git a/View/Bbses/index.ctp b/View/Bbses/index.ctp deleted file mode 100644 index 37da378..0000000 --- a/View/Bbses/index.ctp +++ /dev/null @@ -1,13 +0,0 @@ - - * @author Shohei Nakajima - * @link http://www.netcommons.org NetCommons Project - * @license http://www.netcommons.org/license.txt NetCommons License - * @copyright Copyright 2014, NetCommons Project - */ -?> - - -Form->hidden('Block.id', array( - 'value' => isset($block['id']) ? $block['id'] : null, - )); ?> -Form->hidden('Block.key', array( - 'value' => isset($block['key']) ? $block['key'] : null, - )); ?> -Form->hidden('Bbs.key', array( - 'value' => isset($bbs['key']) ? $bbs['key'] : null, - )); ?> -Form->button(' ' . __d('net_commons', 'Delete'), array( - 'name' => 'delete', - 'class' => 'btn btn-danger pull-right', - 'onclick' => 'return confirm(\'' . sprintf(__d('net_commons', 'Deleting the %s. Are you sure to proceed?'), __d('bbses', 'BBS')) . '\')' - )); +Form->hidden('Block.id'); ?> +Form->hidden('Block.key'); ?> +Form->hidden('Bbs.key'); ?> + +Button->delete( + __d('net_commons', 'Delete'), + sprintf(__d('net_commons', 'Deleting the %s. Are you sure to proceed?'), __d('bbses', 'BBS')), + array('addClass' => 'pull-right') + ); diff --git a/View/Elements/BbsBlocks/edit_form.ctp b/View/Elements/BbsBlocks/edit_form.ctp index f770c29..a5c63b3 100644 --- a/View/Elements/BbsBlocks/edit_form.ctp +++ b/View/Elements/BbsBlocks/edit_form.ctp @@ -17,6 +17,8 @@ Form->hidden('BbsSetting.id'); ?> Form->hidden('BbsFrameSetting.id'); ?> Form->hidden('BbsFrameSetting.frame_key'); ?> +Form->hidden('BbsFrameSetting.articles_per_page'); ?> +Form->hidden('BbsFrameSetting.comments_per_page'); ?> NetCommonsForm->input('Bbs.name', array( 'type' => 'text', @@ -29,4 +31,4 @@ 'label' => __d('bbses', 'Use comment') )); ?> -Like->setting('BbsSetting.use_like', 'BbsSetting.use_unlike'); \ No newline at end of file +Like->setting('BbsSetting.use_like', 'BbsSetting.use_unlike'); From e3efcc645a0777ff966eb073385b009205ee83d1 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 23:22:33 +0900 Subject: [PATCH 07/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- View/Elements/BbsBlocks/delete_form.ctp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/View/Elements/BbsBlocks/delete_form.ctp b/View/Elements/BbsBlocks/delete_form.ctp index eff5ecb..89c3748 100644 --- a/View/Elements/BbsBlocks/delete_form.ctp +++ b/View/Elements/BbsBlocks/delete_form.ctp @@ -10,7 +10,7 @@ */ ?> -
+
Form->hidden('Block.id'); ?> From 06f81b47f574a0551bfa7c2730a67e2f8d6cd7ab Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 23:31:53 +0900 Subject: [PATCH 08/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Bbs.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Model/Bbs.php b/Model/Bbs.php index a1f601b..bdc665c 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -259,7 +259,6 @@ public function saveBbs($data) { if (! $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - //トランザクションCommit $this->commit(); From 40e1d5ff195f42d40a6c77e0dfd797f1481e9d60 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Wed, 9 Sep 2015 23:38:11 +0900 Subject: [PATCH 09/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsBlocksController.php | 112 +--------------------- Controller/BbsFrameSettingsController.php | 31 ------ 2 files changed, 2 insertions(+), 141 deletions(-) diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index 1e75c8c..2898018 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -42,7 +42,6 @@ class BbsBlocksController extends BbsesAppController { * @var array */ public $helpers = array( -// 'NetCommons.Date', 'Likes.Like', ); @@ -58,13 +57,6 @@ class BbsBlocksController extends BbsesAppController { 'index,add,edit,delete' => 'block_editable', ), ), -// 'NetCommons.NetCommonsBlock', -// 'NetCommons.NetCommonsRoomRole' => array( -// //コンテンツの権限設定 -// 'allowedActions' => array( -// 'blockEditable' => array('index', 'add', 'edit', 'delete') -// ), -// ), 'Paginator', ); @@ -75,8 +67,6 @@ class BbsBlocksController extends BbsesAppController { */ public function beforeFilter() { parent::beforeFilter(); -// $this->Auth->deny('index'); - //タブの設定 $this->initTabs('block_index', 'block_settings'); } @@ -101,12 +91,6 @@ public function index() { } $this->set('bbses', $bbses); $this->request->data['Frame'] = Current::read('Frame'); - -// $results = array( -// 'bbses' => $bbses, -// ); -// $results = $this->camelizeKeyRecursive($results); -// $this->set($results); } /** @@ -118,6 +102,7 @@ public function add() { $this->view = 'edit'; if ($this->request->isPost()) { + //登録処理 if ($this->Bbs->saveBbs($this->data)) { $this->redirect(Current::backToIndexUrl('default_setting_action')); } @@ -129,51 +114,6 @@ public function add() { $this->request->data = Hash::merge($this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true)); $this->request->data['Frame'] = Current::read('Frame'); } - -// $this->set('blockId', null); -// $bbs = $this->Bbs->create( -// array( -// 'id' => null, -// 'key' => null, -// 'block_id' => null, -// 'name' => __d('bbses', 'New bbs %s', date('YmdHis')), -// ) -// ); -// $bbsSetting = $this->BbsSetting->create( -// array('id' => null) -// ); -// $block = $this->Block->create( -// array('id' => null, 'key' => null) -// ); -// -// $data = array(); -// if ($this->request->isPost()) { -// $data = $this->__parseRequestData(); -// -// if (! isset($this->viewVars['bbsFrameSetting']['id'])) { -// $bbsFrameSetting = $this->BbsFrameSetting->create( -// array( -// 'frame_key' => $this->viewVars['frameKey'] -// ) -// ); -// $data['BbsFrameSetting'] = $bbsFrameSetting['BbsFrameSetting']; -// } -// -// $this->Bbs->saveBbs($data); -// if ($this->handleValidationError($this->Bbs->validationErrors)) { -// if (! $this->request->is('ajax')) { -// $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); -// } -// return; -// } -// $data['Block']['id'] = null; -// $data['Block']['key'] = null; -// unset($data['Frame']); -// } -// -// $data = Hash::merge($bbs, $bbsSetting, $block, $data); -// $results = $this->camelizeKeyRecursive($data); -// $this->set($results); } /** @@ -183,6 +123,7 @@ public function add() { */ public function edit() { if ($this->request->isPut()) { + //登録処理 if ($this->Bbs->saveBbs($this->data)) { $this->redirect(Current::backToIndexUrl('default_setting_action')); } @@ -199,29 +140,6 @@ public function edit() { $this->request->data = Hash::merge($this->request->data, $this->BbsFrameSetting->getBbsFrameSetting(true)); $this->request->data['Frame'] = Current::read('Frame'); } - -// if (! $this->NetCommonsBlock->validateBlockId()) { -// $this->throwBadRequest(); -// return false; -// } -// $this->set('blockId', (int)$this->params['pass'][1]); -// -// $this->initBbs(['bbsFrameSetting']); -// -// if ($this->request->isPost()) { -// $data = $this->__parseRequestData(); -// -// $this->Bbs->saveBbs($data); -// if ($this->handleValidationError($this->Bbs->validationErrors)) { -// if (! $this->request->is('ajax')) { -// $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); -// } -// return; -// } -// -// $results = $this->camelizeKeyRecursive($data); -// $this->set($results); -// } } /** @@ -230,14 +148,6 @@ public function edit() { * @return void */ public function delete() { -// if (! $this->NetCommonsBlock->validateBlockId()) { -// $this->throwBadRequest(); -// return false; -// } -// $this->set('blockId', (int)$this->params['pass'][1]); -// -// $this->initBbs(['bbsFrameSetting']); - if ($this->request->isDelete()) { if ($this->Bbs->deleteBbs($this->data)) { $this->redirect(Current::backToIndexUrl('default_setting_action')); @@ -246,22 +156,4 @@ public function delete() { $this->throwBadRequest(); } - -/** - * Parse data from request - * - * @return array - */ -// private function __parseRequestData() { -// $data = $this->data; -// if ($data['Block']['public_type'] === Block::TYPE_LIMITED) { -// //$data['Block']['from'] = implode('-', $data['Block']['from']); -// //$data['Block']['to'] = implode('-', $data['Block']['to']); -// } else { -// unset($data['Block']['from'], $data['Block']['to']); -// } -// -// return $data; -// } - } diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index 5ea3d5a..85c4a81 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -47,12 +47,6 @@ class BbsFrameSettingsController extends BbsesAppController { 'edit' => 'page_editable', ), ), -// 'NetCommons.NetCommonsRoomRole' => array( -// //コンテンツの権限設定 -// 'allowedActions' => array( -// 'blockEditable' => array('edit'), -// ), -// ), ); /** @@ -62,7 +56,6 @@ class BbsFrameSettingsController extends BbsesAppController { */ public function beforeFilter() { parent::beforeFilter(); - //タブの設定 $this->initTabs('frame_settings', ''); } @@ -73,11 +66,6 @@ public function beforeFilter() { * @return void */ public function edit() { -// if (! $this->NetCommonsFrame->validateFrameId()) { -// $this->throwBadRequest(); -// return false; -// } - if ($this->request->isPut() || $this->request->isPost()) { if ($this->BbsFrameSetting->saveBbsFrameSetting($this->data)) { $this->redirect(Current::backToPageUrl()); @@ -89,24 +77,5 @@ public function edit() { $this->request->data = $this->BbsFrameSetting->getBbsFrameSetting(true); $this->request->data['Frame'] = Current::read('Frame'); } - - -// $data = array(); -// if ($this->request->isPost()) { -// $data = $this->data; -// $this->BbsFrameSetting->saveBbsFrameSetting($data); -// -// if ($this->handleValidationError($this->BbsFrameSetting->validationErrors)) { -// $this->redirect(Current::backToPageUrl()); -// return; -// } -// } -// -// $data = Hash::merge( -// $bbsFrameSetting, $data -// ); -// $results = $this->camelizeKeyRecursive($data); -// $this->set($results); } - } From 0ded2820684b1169038ffa6cf0f5c0d87540b2e6 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 10 Sep 2015 15:29:51 +0900 Subject: [PATCH 10/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/BbsArticlesController.php | 1 - .../BbsBlockRolePermissionsController.php | 71 ++++++------------- Controller/BbsBlocksController.php | 9 +-- Controller/BbsFrameSettingsController.php | 6 +- Model/BbsFrameSetting.php | 67 +++-------------- Model/BbsSetting.php | 58 ++++++--------- View/BbsBlockRolePermissions/edit.ctp | 11 ++- View/BbsBlocks/index.ctp | 6 +- .../BbsBlockRolePermissions/edit_form.ctp | 29 ++++---- 9 files changed, 78 insertions(+), 180 deletions(-) diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index 17901d9..edd02e7 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -10,7 +10,6 @@ */ App::uses('BbsesAppController', 'Bbses.Controller'); -App::uses('String', 'Utility'); /** * BbsArticles Controller diff --git a/Controller/BbsBlockRolePermissionsController.php b/Controller/BbsBlockRolePermissionsController.php index cc40fd3..5af9e5e 100644 --- a/Controller/BbsBlockRolePermissionsController.php +++ b/Controller/BbsBlockRolePermissionsController.php @@ -32,13 +32,7 @@ class BbsBlockRolePermissionsController extends BbsesAppController { * @var array */ public $uses = array( - 'Roles.Role', - 'Roles.DefaultRolePermission', 'Bbses.Bbs', - 'Bbses.BbsSetting', - 'Blocks.Block', - 'Blocks.BlockRolePermission', - 'Rooms.RolesRoom', ); /** @@ -47,11 +41,10 @@ class BbsBlockRolePermissionsController extends BbsesAppController { * @var array */ public $components = array( - 'NetCommons.NetCommonsBlock', - 'NetCommons.NetCommonsRoomRole' => array( - //コンテンツの権限設定 - 'allowedActions' => array( - 'blockPermissionEditable' => array('edit') + 'NetCommons.Permission' => array( + //アクセスの権限 + 'allow' => array( + 'edit' => 'block_permission_editable', ), ), ); @@ -62,19 +55,18 @@ class BbsBlockRolePermissionsController extends BbsesAppController { * @var array */ public $helpers = array( - 'NetCommons.Token' + 'Blocks.BlockRolePermissionForm' ); /** - * beforeFilter + * beforeRender * * @return void */ - public function beforeFilter() { - parent::beforeFilter(); - + public function beforeRender() { //タブの設定 $this->initTabs('block_index', 'role_permissions'); + parent::beforeRender(); } /** @@ -83,47 +75,30 @@ public function beforeFilter() { * @return void */ public function edit() { - if (! $this->NetCommonsBlock->validateBlockId()) { - $this->throwBadRequest(); - return false; - } - $this->set('blockId', (int)$this->params['pass'][1]); - - $this->initBbs(); + CurrentFrame::setBlock($this->request->params['pass'][1]); - if (! $block = $this->Block->find('first', array( - 'recursive' => -1, - 'conditions' => array( - 'Block.id' => $this->viewVars['blockId'], - ), - ))) { + if (! $bbs = $this->Bbs->getBbs()) { $this->throwBadRequest(); return false; - }; - $this->set('blockId', $block['Block']['id']); - $this->set('blockKey', $block['Block']['key']); + } - $permissions = $this->NetCommonsBlock->getBlockRolePermissions( - $this->viewVars['blockKey'], - ['content_creatable', 'content_publishable', 'content_comment_creatable', 'content_comment_publishable'] + $permissions = $this->Workflow->getBlockRolePermissions( + array('content_creatable', 'content_publishable', 'content_comment_creatable', 'content_comment_publishable') ); + $this->set('roles', $permissions['Roles']); if ($this->request->isPost()) { - $data = $this->data; - $this->BbsSetting->saveBbsSetting($data); - if ($this->handleValidationError($this->BbsSetting->validationErrors)) { - if (! $this->request->is('ajax')) { - $this->redirect('/bbses/bbs_blocks/index/' . $this->viewVars['frameId']); - } + if ($this->BbsSetting->saveBbsSetting($this->request->data)) { + $this->redirect(Current::backToIndexUrl('default_setting_action')); return; } - } + $this->handleValidationError($this->BbsSetting->validationErrors); - $results = array( - 'blockRolePermissions' => $permissions['BlockRolePermissions'], - 'roles' => $permissions['Roles'], - ); - $results = $this->camelizeKeyRecursive($results); - $this->set($results); + } else { + $this->request->data['BbsSetting'] = $bbs['BbsSetting']; + $this->request->data['Block'] = $bbs['Block']; + $this->request->data['BlockRolePermission'] = $permissions['BlockRolePermissions']; + $this->request->data['Frame'] = Current::read('Frame'); + } } } diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index 2898018..1d08303 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -1,6 +1,6 @@ * @author Shohei Nakajima @@ -12,7 +12,7 @@ App::uses('BbsesAppController', 'Bbses.Controller'); /** - * Blocks Controller + * BbsBlocks Controller * * @author Shohei Nakajima * @package NetCommons\Bbses\Controller @@ -42,6 +42,7 @@ class BbsBlocksController extends BbsesAppController { * @var array */ public $helpers = array( + 'Blocks.BlockForm', 'Likes.Like', ); @@ -65,10 +66,10 @@ class BbsBlocksController extends BbsesAppController { * * @return void */ - public function beforeFilter() { - parent::beforeFilter(); + public function beforeRender() { //タブの設定 $this->initTabs('block_index', 'block_settings'); + parent::beforeRender(); } /** diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index 85c4a81..f87bdaf 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -50,14 +50,14 @@ class BbsFrameSettingsController extends BbsesAppController { ); /** - * beforeFilter + * beforeRender * * @return void */ - public function beforeFilter() { - parent::beforeFilter(); + public function beforeRender() { //タブの設定 $this->initTabs('frame_settings', ''); + parent::beforeRender(); } /** diff --git a/Model/BbsFrameSetting.php b/Model/BbsFrameSetting.php index f07b795..b6a16e7 100644 --- a/Model/BbsFrameSetting.php +++ b/Model/BbsFrameSetting.php @@ -21,13 +21,6 @@ */ class BbsFrameSetting extends BbsesAppModel { -/** - * listStyle - * - * @var array - */ -// static public $displayNumberOptions = array(); - /** * Validation rules * @@ -50,29 +43,6 @@ class BbsFrameSetting extends BbsesAppModel { ), ); -/** - * Constructor. Binds the model's database table to the object. - * - * @param bool|int|string|array $id Set this ID for this model on startup, - * can also be an array of options, see above. - * @param string $table Name of database table to use. - * @param string $ds DataSource connection name. - * @see Model::__construct() - * @SuppressWarnings(PHPMD.BooleanArgumentFlag) - */ -// public function __construct($id = false, $table = null, $ds = null) { -// parent::__construct($id, $table, $ds); -// -// self::$displayNumberOptions = array( -// 1 => __d('bbses', '%s article', 1), -// 5 => __d('bbses', '%s articles', 5), -// 10 => __d('bbses', '%s articles', 10), -// 20 => __d('bbses', '%s articles', 20), -// 50 => __d('bbses', '%s articles', 50), -// 100 => __d('bbses', '%s articles', 100), -// ); -// } - /** * Called during validation operations, before validation. Please note that custom * validation rules can be defined in $validate. @@ -147,45 +117,28 @@ public function saveBbsFrameSetting($data) { ]); //トランザクションBegin - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); - try { - //バリデーション - if (!$this->validateBbsFrameSetting($data)) { - return false; - } + //バリデーション + $this->set($data); + if (! $this->validates()) { + $this->rollback(); + return false; + } + try { //登録処理 if (! $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - //トランザクションCommit - $dataSource->commit(); + $this->commit(); } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); } return true; } - -/** - * validate bbs_frame_setting - * - * @param array $data received post data - * @return bool True on success, false on error - */ - public function validateBbsFrameSetting($data) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; - } - return true; - } } diff --git a/Model/BbsSetting.php b/Model/BbsSetting.php index 9a7a79e..2ab596a 100644 --- a/Model/BbsSetting.php +++ b/Model/BbsSetting.php @@ -28,6 +28,15 @@ class BbsSetting extends BbsesAppModel { */ public $validate = array(); +/** + * use behaviors + * + * @var array + */ + public $actsAs = array( + 'Blocks.BlockRolePermission', + ); + /** * Get bbs setting data * @@ -58,59 +67,32 @@ public function getBbsSetting($bbsKey) { public function saveBbsSetting($data) { $this->loadModels([ 'BbsSetting' => 'Bbses.BbsSetting', - 'BlockRolePermission' => 'Blocks.BlockRolePermission', ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); - try { - if (! $this->validateBbsSetting($data)) { - return false; - } - foreach ($data[$this->BlockRolePermission->alias] as $value) { - if (! $this->BlockRolePermission->validateBlockRolePermissions($value)) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->BlockRolePermission->validationErrors); - return false; - } - } + //バリデーション + $this->set($data); + if (! $this->validates()) { + $this->rollback(); + return false; + } + try { if (! $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - foreach ($data[$this->BlockRolePermission->alias] as $value) { - if (! $this->BlockRolePermission->saveMany($value, ['validate' => false])) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - } //トランザクションCommit - $dataSource->commit(); + $this->commit(); + } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); } return true; } -/** - * validate bbs - * - * @param array $data received post data - * @return bool True on success, false on error - */ - public function validateBbsSetting($data) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; - } - return true; - } - } diff --git a/View/BbsBlockRolePermissions/edit.ctp b/View/BbsBlockRolePermissions/edit.ctp index d842063..30a61a5 100644 --- a/View/BbsBlockRolePermissions/edit.ctp +++ b/View/BbsBlockRolePermissions/edit.ctp @@ -10,20 +10,17 @@ */ ?> -Html->script('/bbses/js/bbses.js', false); ?> - - @@ -50,14 +46,7 @@
-
- element('NetCommons.paginator', array( - 'url' => Hash::merge( - array('controller' => 'bbs_articles', 'action' => 'index', $frameId), - $this->Paginator->params['named'] - ) - )); ?> -
+ element('NetCommons.paginator'); ?> diff --git a/View/BbsBlocks/edit.ctp b/View/BbsBlocks/edit.ctp index 7356179..9546dbd 100644 --- a/View/BbsBlocks/edit.ctp +++ b/View/BbsBlocks/edit.ctp @@ -18,7 +18,6 @@ element('Blocks.edit_form', array( 'model' => 'Bbs', -// 'action' => h($this->request->params['action']) . '/' . $frameId . '/' . $blockId, 'callback' => 'Bbses.BbsBlocks/edit_form', 'cancelUrl' => Current::backToIndexUrl('default_setting_action'), )); ?> diff --git a/View/BbsFrameSettings/edit.ctp b/View/BbsFrameSettings/edit.ctp index 1842fb0..c9d1e8a 100644 --- a/View/BbsFrameSettings/edit.ctp +++ b/View/BbsFrameSettings/edit.ctp @@ -16,7 +16,6 @@
element('Blocks.edit_form', array( 'model' => 'BbsFrameSetting', -// 'action' => 'edit' . '/' . Current::read('Frame.id'), 'callback' => 'Bbses.BbsFrameSettings/edit_form', 'cancelUrl' => Current::backToPageUrl(), )); ?> diff --git a/View/Elements/BbsArticles/select_limit.ctp b/View/Elements/BbsArticles/select_limit.ctp deleted file mode 100644 index 28f4daf..0000000 --- a/View/Elements/BbsArticles/select_limit.ctp +++ /dev/null @@ -1,33 +0,0 @@ - - * @author Shohei Nakajima - * @link http://www.netcommons.org NetCommons Project - * @license http://www.netcommons.org/license.txt NetCommons License - * @copyright Copyright 2014, NetCommons Project - */ - -$named = $this->Paginator->params['named']; -$named['page'] = '1'; - -$url = Hash::merge( - array('controller' => 'bbs_articles', 'action' => 'index', $frameId), - $named -); -?> - - - - - diff --git a/View/Elements/BbsArticles/select_sort.ctp b/View/Elements/BbsArticles/select_sort.ctp index d144a46..af68ffe 100644 --- a/View/Elements/BbsArticles/select_sort.ctp +++ b/View/Elements/BbsArticles/select_sort.ctp @@ -10,7 +10,7 @@ */ $url = Hash::merge( - array('controller' => 'bbs_articles', 'action' => 'index', $frameId), + array('controller' => 'bbs_articles', 'action' => 'index', Current::read('Frame.id')), $this->Paginator->params['named'] ); @@ -28,9 +28,9 @@ $options = array( 'sort' => 'BbsArticle.created', 'direction' => 'asc' ), - 'BbsArticleTree.published_comment_counts.desc' => array( + 'BbsArticleTree.bbs_article_counts.desc' => array( 'label' => __d('bbses', 'Descending order of comments'), - 'sort' => 'BbsArticleTree.published_comment_counts', + 'sort' => 'BbsArticleTree.bbs_article_counts', 'direction' => 'desc' ), ); diff --git a/View/Elements/BbsFrameSettings/edit_form.ctp b/View/Elements/BbsFrameSettings/edit_form.ctp index 72b0746..0713f66 100644 --- a/View/Elements/BbsFrameSettings/edit_form.ctp +++ b/View/Elements/BbsFrameSettings/edit_form.ctp @@ -14,7 +14,7 @@ Form->hidden('BbsFrameSetting.id'); ?> Form->hidden('BbsFrameSetting.frame_key'); ?> -NetCommonsForm->selectDisplayNumber('BbsFrameSetting.articles_per_page', array( +DisplayNumber->select('BbsFrameSetting.articles_per_page', array( 'label' => __d('bbses', 'Show articles per page'), 'unit' => array( 'single' => __d('bbses', '%s article'), @@ -22,7 +22,7 @@ ), )); ?> -NetCommonsForm->selectDisplayNumber('BbsFrameSetting.comments_per_page', array( +DisplayNumber->select('BbsFrameSetting.comments_per_page', array( 'label' => __d('bbses', 'Show comments per page'), 'unit' => array( 'single' => __d('bbses', '%s article'), From bf6fb1ba8922f307a30bf8f4a3318b0a5432a96f Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Fri, 11 Sep 2015 01:20:10 +0900 Subject: [PATCH 12/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/BbsArticle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index 0686569..96dcde6 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -52,7 +52,7 @@ class BbsArticle extends BbsesAppModel { public $actsAs = array( 'Workflow.Workflow', 'NetCommons.OriginalKey', - 'Likes.Like' +// 'Likes.Like' ); /** From 0ff4b64ffe3cc6abf4c666be1d420238927fcbcc Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sun, 13 Sep 2015 06:17:31 +0900 Subject: [PATCH 13/15] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AE=E8=A6=8B=E7=9B=B4=E3=81=97=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/Migration/1434983278_init.php | 6 +- Config/Schema/schema.php | 6 +- Controller/BbsArticlesController.php | 554 +++++++++--------- .../BbsBlockRolePermissionsController.php | 6 +- Controller/BbsBlocksController.php | 34 +- Controller/BbsFrameSettingsController.php | 4 +- Controller/BbsesAppController.php | 58 +- Controller/Component/BbsArticlesComponent.php | 213 ------- Model/Bbs.php | 85 +-- Model/BbsArticle.php | 283 ++++----- Model/BbsArticleTree.php | 108 +--- Model/BbsArticlesUser.php | 53 -- Model/Behavior/BbsArticleBehavior.php | 161 +++++ Model/Behavior/BbsArticlesUserBehavior.php | 103 ++++ Test/Fixture/BbsArticleTreeFixture.php | 4 +- Test/Fixture/BbsFixture.php | 4 +- View/BbsArticles/edit.ctp | 66 ++- View/BbsArticles/index.ctp | 2 + View/BbsArticles/view.ctp | 32 +- View/BbsBlockRolePermissions/edit.ctp | 2 +- View/BbsBlocks/edit.ctp | 2 +- View/BbsBlocks/index.ctp | 14 +- View/BbsFrameSettings/edit.ctp | 2 +- View/Elements/BbsArticles/breadcrumb.ctp | 49 +- .../BbsArticles/comment_approving_link.ctp | 30 +- .../BbsArticles/comment_status_label.ctp | 29 - View/Elements/BbsArticles/delete_form.ctp | 45 +- View/Elements/BbsArticles/edit_form.ctp | 121 +--- View/Elements/BbsArticles/edit_link.ctp | 31 - .../BbsArticles/index_bbs_article.ctp | 41 +- View/Elements/BbsArticles/reply_link.ctp | 18 +- View/Elements/BbsArticles/select_sort.ctp | 4 +- .../Elements/BbsArticles/view_bbs_article.ctp | 99 ++-- webroot/css/style.css | 4 + 34 files changed, 986 insertions(+), 1287 deletions(-) delete mode 100644 Controller/Component/BbsArticlesComponent.php create mode 100644 Model/Behavior/BbsArticleBehavior.php create mode 100644 Model/Behavior/BbsArticlesUserBehavior.php delete mode 100644 View/Elements/BbsArticles/comment_status_label.ctp delete mode 100644 View/Elements/BbsArticles/edit_link.ctp diff --git a/Config/Migration/1434983278_init.php b/Config/Migration/1434983278_init.php index 33ff997..0fc8ca4 100644 --- a/Config/Migration/1434983278_init.php +++ b/Config/Migration/1434983278_init.php @@ -40,7 +40,7 @@ class Init extends CakeMigration { 'lft' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'comment' => 'lft | treeビヘイビア必須カラム | | '), 'rght' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'comment' => 'rght | treeビヘイビア必須カラム | | '), 'article_no' => array('type' => 'integer', 'null' => false, 'default' => '1', 'unsigned' => false, 'comment' => 'comment index | 記事毎の採番 | | '), - 'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Published comment counts | 公開されたコメント数 | | '), + 'bbs_article_child_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Published comment counts | 公開されたコメント数 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '), @@ -118,8 +118,8 @@ class Init extends CakeMigration { 'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs key | 掲示板キー | Hash値 | ', 'charset' => 'utf8'), 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs name | 掲示板名称 | | ', 'charset' => 'utf8'), - 'article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Article count | 記事数 | | '), - 'article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Article modified datetime | 記事の最終更新日時 | | '), + 'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Article count | 記事数 | | '), + 'bbs_article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Article modified datetime | 記事の最終更新日時 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '), diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 2b04665..5db3600 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -59,7 +59,7 @@ public function after($event = array()) { 'lft' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'comment' => 'lft | treeビヘイビア必須カラム | | '), 'rght' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'comment' => 'rght | treeビヘイビア必須カラム | | '), 'article_no' => array('type' => 'integer', 'null' => false, 'default' => '1', 'unsigned' => false, 'comment' => 'comment index | 記事毎の採番 | | '), - 'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Published comment counts | 公開されたコメント数 | | '), + 'bbs_article_child_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Published comment counts | 公開されたコメント数 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '), @@ -167,8 +167,8 @@ public function after($event = array()) { 'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs key | 掲示板キー | Hash値 | ', 'charset' => 'utf8'), 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs name | 掲示板名称 | | ', 'charset' => 'utf8'), - 'article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Article count | 記事数 | | '), - 'article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Article modified datetime | 記事の最終更新日時 | | '), + 'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false, 'comment' => 'Article count | 記事数 | | '), + 'bbs_article_modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'Article modified datetime | 記事の最終更新日時 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '), diff --git a/Controller/BbsArticlesController.php b/Controller/BbsArticlesController.php index 56c39a6..caf08f2 100644 --- a/Controller/BbsArticlesController.php +++ b/Controller/BbsArticlesController.php @@ -10,6 +10,7 @@ */ App::uses('BbsesAppController', 'Bbses.Controller'); +App::uses('String', 'Utility'); /** * BbsArticles Controller @@ -27,9 +28,7 @@ class BbsArticlesController extends BbsesAppController { public $uses = array( 'Bbses.BbsFrameSetting', 'Bbses.BbsArticle', -// 'Bbses.BbsArticleTree', -// 'Bbses.BbsArticlesUser', -// 'Comments.Comment', + 'Bbses.BbsArticleTree', ); /** @@ -46,18 +45,7 @@ class BbsArticlesController extends BbsesAppController { 'approve' => 'content_comment_publishable', ), ), -// 'NetCommons.NetCommonsBlock', -// 'NetCommons.NetCommonsWorkflow', -// 'NetCommons.NetCommonsRoomRole' => array( -// //コンテンツの権限設定 -// 'allowedActions' => array( -// 'contentCreatable' => array('add', 'edit', 'delete'), -// 'contentCommentCreatable' => array('reply'), -// 'contentCommentPublishable' => array('approve'), -// ), -// ), 'Paginator', -// 'Bbses.BbsArticles' ); /** @@ -66,32 +54,49 @@ class BbsArticlesController extends BbsesAppController { * @var array */ public $helpers = array( + 'Likes.Like', 'NetCommons.DisplayNumber', + 'Workflow.Workflow', ); /** - * index + * beforeRender * * @return void - * @throws Exception */ - public function index() { + public function beforeFilter() { + parent::beforeFilter(); + if (! Current::read('Block.id')) { - $this->autoRender = false; - return; + $this->setAction('emptyRender'); + return false; } - if (! $bbs = $this->Bbs->getBbs()) { - $this->throwBadRequest(); + $this->setAction('throwBadRequest'); return false; } + $this->set('bbs', $bbs['Bbs']); + $this->set('bbsSetting', $bbs['BbsSetting']); + $bbsFrameSetting = $this->BbsFrameSetting->getBbsFrameSetting(true); + $this->set('bbsFrameSetting', $bbsFrameSetting['BbsFrameSetting']); + } + +/** + * index + * + * @return void + * @throws Exception + */ + public function index() { + $this->BbsArticle->bindModelBbsArticle(false); + $this->BbsArticle->bindModelBbsArticlesUser(false); $query = array(); //条件 $query['conditions'] = $this->BbsArticle->getWorkflowConditions(array( 'BbsArticleTree.parent_id' => null, - 'BbsArticle.bbs_id' => $bbs['Bbs']['id'], + 'BbsArticle.bbs_id' => $this->viewVars['bbs']['id'], )); //ソート if (isset($this->params['named']['sort']) && isset($this->params['named']['direction'])) { @@ -103,80 +108,105 @@ public function index() { if (isset($this->params['named']['limit'])) { $query['limit'] = (int)$this->params['named']['limit']; } else { - $query['limit'] = $bbsFrameSetting['BbsFrameSetting']['articles_per_page']; + $query['limit'] = $this->viewVars['bbsFrameSetting']['articles_per_page']; } $this->Paginator->settings = $query; try { - $this->BbsArticle->bindModelBbsArticlesUser(); $bbsArticles = $this->Paginator->paginate('BbsArticle'); } catch (Exception $ex) { CakeLog::error($ex); throw $ex; } - - $this->set('bbs', $bbs['Bbs']); $this->set('bbsArticles', $bbsArticles); - $this->set('bbsFrameSetting', $bbsFrameSetting['BbsFrameSetting']); - -// $this->initBbs(['bbsFrameSetting']); -// -// //Paginatorの設定 -// $this->Paginator->settings = $this->BbsArticles->paginatorSettings(); -// -// try { -// $this->BbsArticle->bindModelBbsArticlesUser($this->viewVars['userId']); -// $articles = $this->Paginator->paginate('BbsArticle'); -// } catch (Exception $ex) { -// CakeLog::error($ex); -// throw $ex; -// } -// -// $results = array( -// 'bbsArticles' => $articles -// ); -// $results = $this->camelizeKeyRecursive($results); -// $this->set($results); } /** * view * - * @param int $frameId frames.id - * @param string $bbsArticleKey bbs_articles.key * @return void - * @throws BadRequestException throw new + * @throws BadRequestException throw */ - public function view($frameId = null, $bbsArticleKey = null) { - $this->initBbs(['bbsFrameSetting']); - $this->BbsArticles->setBbsArticle($bbsArticleKey, ['rootBbsArticle', 'parentBbsArticle']); + public function view() { + //参照権限チェック + if (! $this->BbsArticle->canReadWorkflowContent()) { + $this->throwBadRequest(); + return false; + } - //既読 - if ($this->viewVars['userId'] && ! $this->viewVars['currentBbsArticle']['bbsArticlesUser']['id']) { - $data = $this->BbsArticlesUser->create(array( - 'bbs_article_key' => $bbsArticleKey, - 'user_id' => $this->viewVars['userId'] - )); - $result = $this->BbsArticlesUser->saveArticlesUser($data); - $result = $this->camelizeKeyRecursive($result); - $this->viewVars['currentBbsArticle']['bbsArticlesUser'] = $result; + $bbsArticleKey = null; + if (isset($this->params['pass'][1])) { + $bbsArticleKey = $this->params['pass'][1]; } - $conditions = $this->BbsArticles->setConditions(); - $this->BbsArticleTree->bindModelBbsArticlesUser($this->viewVars['userId']); - $this->BbsArticleTree->Behaviors->load('Tree', array( - 'scope' => array( - 'OR' => $conditions + $this->BbsArticle->bindModelBbsArticle(false); + $this->BbsArticle->bindModelBbsArticlesUser(false); + $this->BbsArticleTree->bindModelBbsArticle(false); + $this->BbsArticleTree->bindModelBbsArticlesUser(false); + + //カレント記事の取得 + $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticle->alias . '.bbs_id' => $this->viewVars['bbs']['id'], + $this->BbsArticle->alias . '.key' => $bbsArticleKey ) )); + if (! $bbsArticle) { + $this->throwBadRequest(); + return false; + } + $this->set('currentBbsArticle', $bbsArticle); + + $conditions = $this->BbsArticle->getWorkflowConditions(); + //根記事の取得 + if ($bbsArticle['BbsArticleTree']['root_id'] > 0) { + $rootBbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticleTree->alias . '.id' => $bbsArticle['BbsArticleTree']['root_id'], + ) + )); + if (! $rootBbsArticle) { + $this->throwBadRequest(); + return false; + } + $this->set('rootBbsArticle', $rootBbsArticle); + } + + //親記事の取得 + if ($bbsArticle['BbsArticleTree']['parent_id'] > 0) { + if ($bbsArticle['BbsArticleTree']['parent_id'] !== $bbsArticle['BbsArticleTree']['root_id']) { + $parentBbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticleTree->alias . '.id' => $bbsArticle['BbsArticleTree']['parent_id'], + ) + )); + if (! $parentBbsArticle) { + $this->throwBadRequest(); + return false; + } + $this->set('parentBbsArticle', $parentBbsArticle); + } else { + $this->set('parentBbsArticle', $rootBbsArticle); + } + } + + //子記事の取得 + $this->BbsArticleTree->Behaviors->load('Tree', array( + 'scope' => array('OR' => $conditions) + )); $children = $this->BbsArticleTree->children( - $this->viewVars['currentBbsArticle']['bbsArticleTree']['id'], false, null, 'BbsArticleTree.id DESC', null, 1, 1 + $bbsArticle['BbsArticleTree']['id'], false, null, 'BbsArticleTree.id DESC', null, 1, 1 ); - $children = $this->camelizeKeyRecursive($children); - $children = Hash::combine($children, '{n}.bbsArticleTree.id', '{n}'); + $children = Hash::combine($children, '{n}.BbsArticleTree.id', '{n}'); - $this->set(['bbsArticleChildren' => $children]); + $this->set('bbsArticleChildren', $children); + + //既読 + $this->BbsArticle->readToArticle($bbsArticle['BbsArticle']['key']); } /** @@ -186,281 +216,263 @@ public function view($frameId = null, $bbsArticleKey = null) { */ public function add() { $this->view = 'edit'; - $this->initBbs(['bbsFrameSetting']); - - $bbsArticle = $this->BbsArticle->create(array( - 'id' => null, - 'bbs_id' => $this->viewVars['bbs']['id'], - 'language_id' => $this->viewVars['languageId'], - 'key' => null, - 'title' => null, - 'content' => null, - )); - $bbsArticleTree = $this->BbsArticleTree->create(array( - 'id' => null, - 'key' => null, - 'bbs_key' => $this->viewVars['bbs']['key'], - 'root_id' => null, - 'parent_id' => null, - )); - $data = array(); if ($this->request->isPost()) { - if (! $status = $this->NetCommonsWorkflow->parseStatus()) { - return; - } - $data = Hash::merge( - $this->data, - ['BbsArticle' => ['status' => $status]] - ); - - $data['BbsArticleTree']['post_no'] = 1; + $data = $this->data; + $data['BbsArticle']['status'] = $this->Workflow->parseStatus(); + $data['BbsArticleTree']['article_no'] = 1; unset($data['BbsArticle']['id']); - if ($this->BbsArticles->saveBbsArticle($data)) { + if ($bbsArticle = $this->BbsArticle->saveBbsArticle($data)) { + $url = NetCommonsUrl::actionUrl(array( + 'controller' => $this->params['controller'], + 'action' => 'view', + 'frame_id' => $this->data['Frame']['id'], + 'key' => $bbsArticle['BbsArticle']['key'] + )); + $this->redirect($url); return; } - $data['contentStatus'] = null; - $data['comments'] = null; - } + $this->NetCommons->handleValidationError($this->BbsArticle->validationErrors); - $data = Hash::merge( - $bbsArticle, $bbsArticleTree, $data, - ['contentStatus' => null, 'comments' => []] - ); - $results = $this->camelizeKeyRecursive($data); - $this->set($results); + } else { + $this->request->data = Hash::merge($this->request->data, + $this->BbsArticle->create(array( + 'bbs_id' => $this->viewVars['bbs']['id'], + )), + $this->BbsArticleTree->create(array( + 'bbs_key' => $this->viewVars['bbs']['key'], + 'post_no' => 1, + )) + ); + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); + } } /** * reply * - * @param int $frameId frames.id - * @param string $bbsArticleKey bbs_articles.key * @return void */ - public function reply($frameId = null, $bbsArticleKey = null) { + public function reply() { $this->view = 'edit'; - $this->initBbs(['bbsFrameSetting']); - $this->BbsArticles->setBbsArticle($bbsArticleKey); - if ((int)$this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId'] > 0) { - $rootArticleTreeId = (int)$this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId']; - } else { - $rootArticleTreeId = (int)$this->viewVars['currentBbsArticle']['bbsArticleTree']['id']; - } - - $bbsArticleTree = $this->BbsArticleTree->create(array( - 'id' => null, - 'bbs_article_key' => null, - 'bbs_key' => $this->viewVars['bbs']['key'], - 'root_id' => $rootArticleTreeId, - 'parent_id' => (int)$this->viewVars['currentBbsArticle']['bbsArticleTree']['id'], - )); - $bbsArticle = $this->BbsArticle->create(array( - 'id' => null, - 'key' => null, - 'bbs_id' => $this->viewVars['bbs']['id'], - 'title' => null, - 'content' => '', - )); - - $bbsArticle['BbsArticle']['title'] = $this->__replyTitle($this->viewVars['currentBbsArticle']['bbsArticle']['title']); - if (isset($this->params->query['quote']) && $this->params->query['quote']) { - $bbsArticle['BbsArticle']['content'] = - '

' . - $this->viewVars['currentBbsArticle']['bbsArticle']['content'] . - '

'; - } - - $data = array(); if ($this->request->isPost()) { - if (! $status = $this->NetCommonsWorkflow->parseStatus()) { - return; - } - if ($status !== NetCommonsBlockComponent::STATUS_IN_DRAFT) { - $status = $this->viewVars['contentCommentPublishable'] ? - NetCommonsBlockComponent::STATUS_PUBLISHED : NetCommonsBlockComponent::STATUS_APPROVED; - } - - $data = Hash::merge( - $this->data, - ['BbsArticle' => ['status' => $status]] - ); - - $data['BbsArticleTree']['article_no'] = $this->BbsArticleTree->getMaxNo($rootArticleTreeId) + 1; + $data = $this->data; + $data['BbsArticle']['status'] = $this->Workflow->parseStatus(); + $data['BbsArticleTree']['article_no'] = $this->BbsArticleTree->getMaxNo($data['BbsArticleTree']['root_id']) + 1; unset($data['BbsArticle']['id']); - if ($this->BbsArticles->saveBbsArticle($data)) { + if ($bbsArticle = $this->BbsArticle->saveBbsArticle($data)) { + $url = NetCommonsUrl::actionUrl(array( + 'controller' => $this->params['controller'], + 'action' => 'view', + 'frame_id' => $this->data['Frame']['id'], + 'key' => $bbsArticle['BbsArticle']['key'] + )); + $this->redirect($url); return; } - $data['contentStatus'] = null; - $data['comments'] = null; - } + $this->NetCommons->handleValidationError($this->BbsArticle->validationErrors); - $data = Hash::merge( - $bbsArticle, $bbsArticleTree, $data, - ['contentStatus' => null, 'comments' => []] - ); - $results = $this->camelizeKeyRecursive($data); - $this->set($results); - } + } else { + $bbsArticleKey = $this->params['pass'][1]; + $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'fields' => array( + $this->BbsArticle->alias . '.title', + $this->BbsArticle->alias . '.content', + $this->BbsArticleTree->alias . '.id', + $this->BbsArticleTree->alias . '.root_id', + ), + 'conditions' => array( + $this->BbsArticle->alias . '.bbs_id' => $this->viewVars['bbs']['id'], + $this->BbsArticle->alias . '.key' => $bbsArticleKey + ) + )); + if (! $bbsArticle) { + $this->throwBadRequest(); + return false; + } -/** - * Title of reply - * - * @param string $title bbs_articles.title - * @return string bbs_articles.title - */ - private function __replyTitle($title) { - $result = ''; - if (isset($this->params->query['quote']) && $this->params->query['quote']) { - $matches = array(); - if (preg_match('/^Re(\d)?:/', $title, $matches)) { - if (isset($matches[1])) { - $count = (int)$matches[1]; - } else { - $count = 1; - } - $result = preg_replace('/^Re(\d)?:/', 'Re' . ($count + 1) . ': ', $title); + if ($bbsArticle['BbsArticleTree']['root_id'] > 0) { + $rootId = (int)$bbsArticle['BbsArticleTree']['root_id']; } else { - $result = 'Re: ' . $title; + $rootId = (int)$bbsArticle['BbsArticleTree']['id']; } - } + if (isset($this->params->query['quote']) && $this->params->query['quote']) { + $title = $this->BbsArticle->getReplyTitle($bbsArticle['BbsArticle']['title']); + $content = $this->BbsArticle->getReplyContent($bbsArticle['BbsArticle']['content']); + } else { + $title = null; + $content = null; + } + $this->request->data = Hash::merge($this->request->data, + $this->BbsArticle->create(array( + 'bbs_id' => $this->viewVars['bbs']['id'], + 'title' => $title, + 'content' => $content, + )), + $this->BbsArticleTree->create(array( + 'bbs_key' => $this->viewVars['bbs']['key'], + 'root_id' => $rootId, + 'parent_id' => $bbsArticle['BbsArticleTree']['id'], + )) + ); - return $result; + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); + } } /** * edit * - * @param int $frameId frames.id - * @param string $bbsArticleKey bbs_articles.key * @return void */ - public function edit($frameId = null, $bbsArticleKey = null) { + public function edit() { $this->view = 'edit'; - $this->initBbs(['bbsFrameSetting']); - $this->BbsArticles->setBbsArticle($bbsArticleKey); - $data = array(); - if ($this->request->isPost()) { - if (! $status = $this->NetCommonsWorkflow->parseStatus()) { + $bbsArticleKey = $this->params['pass'][1]; + if ($this->request->isPut()) { + $bbsArticleKey = $this->data['BbsArticle']['key']; + } + + $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticle->alias . '.bbs_id' => $this->viewVars['bbs']['id'], + $this->BbsArticle->alias . '.key' => $bbsArticleKey + ) + )); + + //掲示板の場合は、削除権限と同じ条件とする + if (! $this->BbsArticle->canDeleteWorkflowContent($bbsArticle)) { + $this->throwBadRequest(); + return false; + } + + if ($this->request->isPut()) { + $data = $this->data; + $data['BbsArticle']['status'] = $this->Workflow->parseStatus(); + unset($data['BbsArticle']['id']); + + if ($bbsArticle = $this->BbsArticle->saveBbsArticle($data)) { + $url = NetCommonsUrl::actionUrl(array( + 'controller' => $this->params['controller'], + 'action' => 'view', + 'frame_id' => $this->data['Frame']['id'], + 'key' => $bbsArticle['BbsArticle']['key'] + )); + $this->redirect($url); return; } - if ($this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId'] > 0 && $status !== NetCommonsBlockComponent::STATUS_IN_DRAFT) { - $status = $this->viewVars['contentCommentPublishable'] ? - NetCommonsBlockComponent::STATUS_PUBLISHED : NetCommonsBlockComponent::STATUS_APPROVED; - } - $data = Hash::merge( - $this->data, - ['BbsArticle' => ['status' => $status]] - ); + $this->NetCommons->handleValidationError($this->BbsArticle->validationErrors); - if (! $this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId']) { - unset($data['BbsArticle']['id']); - } - if ($this->BbsArticles->saveBbsArticle($data)) { - return; + } else { + $this->request->data = $bbsArticle; + if (! $this->request->data) { + $this->throwBadRequest(); + return false; } - } + $this->request->data['Frame'] = Current::read('Frame'); + $this->request->data['Block'] = Current::read('Block'); - $comments = $this->Comment->getComments( - array( - 'plugin_key' => $this->params['plugin'], - 'content_key' => $bbsArticleKey - ) - ); - $comments = $this->camelizeKeyRecursive($comments); - $this->set(['comments' => $comments]); + } - $data = $this->camelizeKeyRecursive(Hash::merge( - $data, - array('contentStatus' => $this->viewVars['currentBbsArticle']['bbsArticle']['status']) - )); - $results = Hash::merge( - $this->viewVars['currentBbsArticle'], $data - ); - $this->set($results); + $comments = $this->BbsArticle->getCommentsByContentKey($this->request->data['BbsArticle']['key']); + $this->set('comments', $comments); } /** * delete * - * @param int $frameId frames.id - * @param string $bbsArticleKey bbs_articles.key * @return void */ - public function delete($frameId = null, $bbsArticleKey = null) { - $this->initBbs(['bbsFrameSetting']); - $this->BbsArticles->setBbsArticle($bbsArticleKey, ['rootBbsArticle', 'parentBbsArticle']); - + public function delete() { if (! $this->request->isDelete()) { $this->throwBadRequest(); return; } - $data = Hash::merge( - $this->data, - ['BbsArticle' => ['status' => $this->viewVars['currentBbsArticle']['bbsArticle']['status']]] - ); - if (! $this->BbsArticle->deleteBbsArticle($data)) { + $bbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticle->alias . '.bbs_id' => $this->viewVars['bbs']['id'], + $this->BbsArticle->alias . '.key' => $this->data['BbsArticle']['key'] + ) + )); + + //削除権限チェック + if (! $this->BbsArticle->canDeleteWorkflowContent($bbsArticle)) { $this->throwBadRequest(); - return; + return false; } - if (! $this->request->is('ajax')) { - if ($this->viewVars['currentBbsArticle']['bbsArticleTree']['parentId']) { - $action = 'view'; - $articleKey = $this->viewVars['parentBbsArticle']['bbsArticle']['key']; - } else { - $action = 'index'; - $articleKey = ''; + + //親記事の取得 + if ($bbsArticle['BbsArticleTree']['parent_id'] > 0) { + $parentBbsArticle = $this->BbsArticle->getWorkflowContents('first', array( + 'recursive' => 0, + 'conditions' => array( + $this->BbsArticleTree->alias . '.id' => $bbsArticle['BbsArticleTree']['parent_id'], + ) + )); + if (! $parentBbsArticle) { + $this->throwBadRequest(); + return false; } - $this->redirect('/bbses/bbs_articles/' . $action . '/' . $this->viewVars['frameId'] . '/' . $articleKey); } + + if (! $this->BbsArticle->deleteBbsArticle($this->data)) { + $this->throwBadRequest(); + return; + } + + if (isset($parentBbsArticle)) { + $url = NetCommonsUrl::actionUrl(array( + 'controller' => $this->params['controller'], + 'action' => 'view', + 'frame_id' => $this->data['Frame']['id'], + 'key' => $parentBbsArticle['BbsArticle']['key'] + )); + } else { + $url = NetCommonsUrl::backToPageUrl(); + } + $this->redirect($url); } /** * approve * - * @param int $frameId frames.id - * @param string $bbsArticleKey bbs_articles.key * @return void */ - public function approve($frameId = null, $bbsArticleKey = null) { - $this->initBbs(['bbsFrameSetting']); - $this->BbsArticles->setBbsArticle($bbsArticleKey); - - if (! $this->request->isPost()) { - $this->throwBadRequest(); - return; - } - if (! $status = $this->NetCommonsWorkflow->parseStatus()) { + public function approve() { + if (! $this->request->isPut()) { $this->throwBadRequest(); return; } - if (! $this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId']) { + + $data = $this->data; + $data['BbsArticle']['status'] = $this->Workflow->parseStatus(); + if (! $data['BbsArticle']['status']) { $this->throwBadRequest(); return; } - $data = Hash::merge( - $this->data, - array('BbsArticle' => array( - 'status' => $status - )), - array('BbsArticleTree' => array( - 'root_id' => $this->viewVars['currentBbsArticle']['bbsArticleTree']['rootId'] - )) - ); + if ($this->BbsArticle->saveCommentAsPublish($data)) { + $this->NetCommons->setFlashNotification(__d('net_commons', 'Successfully saved.'), array('class' => 'success')); - $this->BbsArticle->saveCommentAsPublish($data); - if ($this->handleValidationError($this->BbsArticle->validationErrors)) { - if (! $this->request->is('ajax')) { - $this->redirect('/bbses/bbs_articles/view/' . $this->viewVars['frameId'] . '/' . $bbsArticleKey); - } + $url = NetCommonsUrl::actionUrl(array( + 'controller' => $this->params['controller'], + 'action' => 'view', + 'frame_id' => $this->data['Frame']['id'], + 'key' => $this->data['BbsArticle']['key'] + )); + $this->redirect($url); return; } + $this->NetCommons->handleValidationError($this->BbsArticle->validationErrors); $this->throwBadRequest(); } diff --git a/Controller/BbsBlockRolePermissionsController.php b/Controller/BbsBlockRolePermissionsController.php index 5af9e5e..b180a4c 100644 --- a/Controller/BbsBlockRolePermissionsController.php +++ b/Controller/BbsBlockRolePermissionsController.php @@ -78,7 +78,7 @@ public function edit() { CurrentFrame::setBlock($this->request->params['pass'][1]); if (! $bbs = $this->Bbs->getBbs()) { - $this->throwBadRequest(); + $this->setAction('throwBadRequest'); return false; } @@ -89,10 +89,10 @@ public function edit() { if ($this->request->isPost()) { if ($this->BbsSetting->saveBbsSetting($this->request->data)) { - $this->redirect(Current::backToIndexUrl('default_setting_action')); + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); return; } - $this->handleValidationError($this->BbsSetting->validationErrors); + $this->NetCommons->handleValidationError($this->BbsSetting->validationErrors); } else { $this->request->data['BbsSetting'] = $bbs['BbsSetting']; diff --git a/Controller/BbsBlocksController.php b/Controller/BbsBlocksController.php index 1d08303..aa1cafb 100644 --- a/Controller/BbsBlocksController.php +++ b/Controller/BbsBlocksController.php @@ -36,16 +36,6 @@ class BbsBlocksController extends BbsesAppController { 'Blocks.Block', ); -/** - * use helpers - * - * @var array - */ - public $helpers = array( - 'Blocks.BlockForm', - 'Likes.Like', - ); - /** * use components * @@ -61,6 +51,16 @@ class BbsBlocksController extends BbsesAppController { 'Paginator', ); +/** + * use helpers + * + * @var array + */ + public $helpers = array( + 'Blocks.BlockForm', + 'Likes.Like', + ); + /** * beforeFilter * @@ -105,9 +105,9 @@ public function add() { if ($this->request->isPost()) { //登録処理 if ($this->Bbs->saveBbs($this->data)) { - $this->redirect(Current::backToIndexUrl('default_setting_action')); + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); } - $this->handleValidationError($this->Bbs->validationErrors); + $this->NetCommons->handleValidationError($this->Bbs->validationErrors); } else { //表示処理(初期データセット) @@ -126,15 +126,15 @@ public function edit() { if ($this->request->isPut()) { //登録処理 if ($this->Bbs->saveBbs($this->data)) { - $this->redirect(Current::backToIndexUrl('default_setting_action')); + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); } - $this->handleValidationError($this->Bbs->validationErrors); + $this->NetCommons->handleValidationError($this->Bbs->validationErrors); } else { //表示処理(初期データセット) CurrentFrame::setBlock($this->request->params['pass'][1]); if (! $bbs = $this->Bbs->getBbs()) { - $this->throwBadRequest(); + $this->setAction('throwBadRequest'); return false; } $this->request->data = Hash::merge($this->request->data, $bbs); @@ -151,10 +151,10 @@ public function edit() { public function delete() { if ($this->request->isDelete()) { if ($this->Bbs->deleteBbs($this->data)) { - $this->redirect(Current::backToIndexUrl('default_setting_action')); + $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); } } - $this->throwBadRequest(); + $this->setAction('throwBadRequest'); } } diff --git a/Controller/BbsFrameSettingsController.php b/Controller/BbsFrameSettingsController.php index b60d2ba..6633d00 100644 --- a/Controller/BbsFrameSettingsController.php +++ b/Controller/BbsFrameSettingsController.php @@ -77,10 +77,10 @@ public function beforeRender() { public function edit() { if ($this->request->isPut() || $this->request->isPost()) { if ($this->BbsFrameSetting->saveBbsFrameSetting($this->data)) { - $this->redirect(Current::backToPageUrl()); + $this->redirect(NetCommonsUrl::backToPageUrl()); return; } - $this->handleValidationError($this->BbsFrameSetting->validationErrors); + $this->NetCommons->handleValidationError($this->BbsFrameSetting->validationErrors); } else { $this->request->data = $this->BbsFrameSetting->getBbsFrameSetting(true); diff --git a/Controller/BbsesAppController.php b/Controller/BbsesAppController.php index 6bb02a2..a6de94b 100644 --- a/Controller/BbsesAppController.php +++ b/Controller/BbsesAppController.php @@ -55,35 +55,35 @@ class BbsesAppController extends AppController { * @param array $contains Optional result sets * @return void */ - public function initBbs($contains = []) { - if (! $bbs = $this->Bbs->getBbs($this->viewVars['blockId'], $this->viewVars['roomId'])) { - $this->throwBadRequest(); - return false; - } - $bbs = $this->camelizeKeyRecursive($bbs); - $this->set($bbs); - - if (! $bbsSetting = $this->BbsSetting->getBbsSetting($bbs['bbs']['key'])) { - $bbsSetting = $this->BbsSetting->create(array( - 'id' => null, - 'bbs_key' => $bbs['bbs']['key'] - )); - } - $bbsSetting = $this->camelizeKeyRecursive($bbsSetting); - $this->set($bbsSetting); - - if (in_array('bbsFrameSetting', $contains, true)) { - if (! $bbsFrameSetting = $this->BbsFrameSetting->getBbsFrameSetting($this->viewVars['frameKey'])) { - $bbsFrameSetting = $this->BbsFrameSetting->create(array( - 'frame_key' => $this->viewVars['frameKey'] - )); - } - $bbsFrameSetting = $this->camelizeKeyRecursive($bbsFrameSetting); - $this->set($bbsFrameSetting); - } - - $this->set('userId', (int)$this->Auth->user('id')); - } +// public function initBbs($contains = []) { +// if (! $bbs = $this->Bbs->getBbs($this->viewVars['blockId'], $this->viewVars['roomId'])) { +// $this->throwBadRequest(); +// return false; +// } +// $bbs = $this->camelizeKeyRecursive($bbs); +// $this->set($bbs); +// +// if (! $bbsSetting = $this->BbsSetting->getBbsSetting($bbs['bbs']['key'])) { +// $bbsSetting = $this->BbsSetting->create(array( +// 'id' => null, +// 'bbs_key' => $bbs['bbs']['key'] +// )); +// } +// $bbsSetting = $this->camelizeKeyRecursive($bbsSetting); +// $this->set($bbsSetting); +// +// if (in_array('bbsFrameSetting', $contains, true)) { +// if (! $bbsFrameSetting = $this->BbsFrameSetting->getBbsFrameSetting($this->viewVars['frameKey'])) { +// $bbsFrameSetting = $this->BbsFrameSetting->create(array( +// 'frame_key' => $this->viewVars['frameKey'] +// )); +// } +// $bbsFrameSetting = $this->camelizeKeyRecursive($bbsFrameSetting); +// $this->set($bbsFrameSetting); +// } +// +// $this->set('userId', (int)$this->Auth->user('id')); +// } /** * initTabs diff --git a/Controller/Component/BbsArticlesComponent.php b/Controller/Component/BbsArticlesComponent.php deleted file mode 100644 index cfedc3d..0000000 --- a/Controller/Component/BbsArticlesComponent.php +++ /dev/null @@ -1,213 +0,0 @@ - - * @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('Component', 'Controller'); - -/** - * BbsArticles Component - * - * @author Shohei Nakajima - * @package NetCommons\Bbses\Controller\Component - */ -class BbsArticlesComponent extends Component { - -/** - * Called before the Controller::beforeFilter(). - * - * @param Controller $controller Instantiating controller - * @return void - */ - public function initialize(Controller $controller) { - $this->controller = $controller; - } - -/** - * paginatorSettings - * - * @return void - */ - public function setConditions() { - //条件 - $activeConditions = array( - 'BbsArticle.is_active' => true, - ); - $latestConditons = array(); - - if ($this->controller->viewVars['contentEditable']) { - $activeConditions = array(); - $latestConditons = array( - 'BbsArticle.is_latest' => true, - ); - } elseif ($this->controller->viewVars['contentCreatable']) { - $activeConditions = array( - 'BbsArticle.is_active' => true, - 'BbsArticle.created_user !=' => $this->controller->viewVars['userId'], - ); - $latestConditons = array( - 'BbsArticle.is_latest' => true, - 'BbsArticle.created_user' => $this->controller->viewVars['userId'], - ); - } - - $conditions = array( - 'BbsArticle.bbs_id' => $this->controller->viewVars['bbs']['id'], - 'BbsArticle.language_id' => $this->controller->viewVars['languageId'], - 'OR' => array($activeConditions, $latestConditons) - ); - - return $conditions; - } - -/** - * paginatorSettings - * - * @return void - */ - public function paginatorSettings() { - //条件 - $conditions = $this->setConditions(); - $conditions['BbsArticleTree.parent_id'] = null; - - //ソート - if (isset($this->controller->params['named']['sort']) && isset($this->controller->params['named']['direction'])) { - $order = array($this->controller->params['named']['sort'] => $this->controller->params['named']['direction']); - } else { - $order = array('BbsArticle.created' => 'desc'); - } - //表示件数 - if (isset($this->controller->params['named']['limit'])) { - $limit = (int)$this->controller->params['named']['limit']; - } else { - $limit = (int)$this->controller->viewVars['bbsFrameSetting']['articlesPerPage']; - } - - //Paginatorの設定 - return array( - 'BbsArticle' => array('conditions' => $conditions, 'order' => $order, 'limit' => $limit) - ); - } - -/** - * View set BbsArticle - * - * @param string $bbsArticleKey bbs_articles.key - * @param array $contains Optional result sets - * @return void - */ - public function setBbsArticle($bbsArticleKey, $contains = []) { - //カレントの記事を取得 - $conditions = $this->setConditions(); - $this->controller->BbsArticle->bindModelBbsArticlesUser($this->controller->viewVars['userId']); - $bbsArticle = $this->controller->BbsArticle->getBbsArticle( - $bbsArticleKey, - $conditions - ); - if (! $bbsArticle) { - $this->controller->throwBadRequest(); - return false; - } - $bbsArticle = $this->controller->camelizeKeyRecursive($bbsArticle); - $this->controller->set(['currentBbsArticle' => $bbsArticle]); - - //子記事の場合、根記事を取得する - if (in_array('rootBbsArticle', $contains, true)) { - $this->__setRootBbsArticle($bbsArticle); - } - - //子記事の場合、親記事を取得する - if (in_array('parentBbsArticle', $contains, true)) { - $this->__setParentBbsArticle($bbsArticle); - } - } - -/** - * View set root BbsArticle - * - * @param object $bbsArticle bbs_articles data - * @return void - */ - private function __setRootBbsArticle($bbsArticle) { - //子記事の場合、根記事を取得する - if ($bbsArticle['bbsArticleTree']['rootId'] > 0) { - $conditions = $this->setConditions(); - - $this->controller->BbsArticle->bindModelBbsArticlesUser($this->controller->viewVars['userId']); - $rootBbsArticle = $this->controller->BbsArticle->getBbsArticleByTreeId( - $bbsArticle['bbsArticleTree']['rootId'], - $conditions - ); - - if (! $rootBbsArticle) { - $this->controller->throwBadRequest(); - return false; - } - $rootBbsArticle = $this->controller->camelizeKeyRecursive($rootBbsArticle); - $this->controller->set(['rootBbsArticle' => $rootBbsArticle]); - } - } - -/** - * View set root BbsArticle - * - * @param object $bbsArticle bbs_articles data - * @return void - */ - private function __setParentBbsArticle($bbsArticle) { - //子記事の場合、親記事を取得する - if ($bbsArticle['bbsArticleTree']['parentId'] > 0) { - $conditions = $this->setConditions(); - - $parentBbsArticle = null; - if ($bbsArticle['bbsArticleTree']['parentId'] !== $bbsArticle['bbsArticleTree']['rootId']) { - $this->controller->BbsArticle->bindModelBbsArticlesUser($this->controller->viewVars['userId']); - $parentBbsArticle = $this->controller->BbsArticle->getBbsArticleByTreeId( - $bbsArticle['bbsArticleTree']['parentId'], - $conditions - ); - if (! $parentBbsArticle) { - $this->controller->throwBadRequest(); - return false; - } - } - if (! isset($parentBbsArticle) && isset($this->controller->viewVars['rootBbsArticle'])) { - $parentBbsArticle = $this->controller->viewVars['rootBbsArticle']; - } - $parentBbsArticle = $this->controller->camelizeKeyRecursive($parentBbsArticle); - $this->controller->set(['parentBbsArticle' => $parentBbsArticle]); - } - } - -/** - * saveBbsArticle - * - * @param array $data received post data - * @param string $bbsArticleKey bbs_articles.key - * @return bool true on success, false on error - */ - public function saveBbsArticle($data, $bbsArticleKey = null) { - $bbsArticle = $this->controller->BbsArticle->saveBbsArticle($data); - if ($this->controller->handleValidationError($this->controller->BbsArticle->validationErrors)) { - if ($this->controller->request->is('ajax')) { - return true; - } - if (! isset($bbsArticleKey)) { - $bbsArticleKey = $bbsArticle['BbsArticle']['key']; - } - - $this->controller->redirect( - '/bbses/bbs_articles/view/' . - $this->controller->viewVars['frameId'] . '/' . $bbsArticleKey - ); - } - return false; - } - -} diff --git a/Model/Bbs.php b/Model/Bbs.php index bdc665c..9594f83 100644 --- a/Model/Bbs.php +++ b/Model/Bbs.php @@ -329,7 +329,7 @@ public function deleteBbs($data) { } /** - * Update article_modified and article_count + * Update bbs_article_modified and bbs_article_count * * @param int $bbsId bbses.id * @param string $bbsKey bbses.key @@ -337,46 +337,47 @@ public function deleteBbs($data) { * @return bool True on success * @throws InternalErrorException */ - public function updateBbsArticle($bbsId, $bbsKey, $languageId) { - $this->loadModels([ - 'BbsArticle' => 'Bbses.BbsArticle', - ]); - $db = $this->getDataSource(); - - $conditions = array( - 'bbs_id' => $bbsId, - 'language_id' => $languageId, - 'is_latest' => true - ); - $count = $this->BbsArticle->find('count', array( - 'recursive' => -1, - 'conditions' => $conditions, - )); - if ($count === false) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - - $article = $this->BbsArticle->find('first', array( - 'recursive' => -1, - 'fields' => 'modified', - 'conditions' => $conditions, - 'order' => 'modified desc' - )); - if ($article === false) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } +// public function updateBbsArticle($bbsId, $bbsKey, $languageId) { +// $this->loadModels([ +// 'BbsArticle' => 'Bbses.BbsArticle', +// ]); +// $db = $this->getDataSource(); +// +// $conditions = array( +// 'bbs_id' => $bbsId, +// 'language_id' => $languageId, +// 'is_latest' => true +// ); +// $count = $this->BbsArticle->find('count', array( +// 'recursive' => -1, +// 'conditions' => $conditions, +// )); +// if ($count === false) { +// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); +// } +// +// $article = $this->BbsArticle->find('first', array( +// 'recursive' => -1, +// 'fields' => 'modified', +// 'conditions' => $conditions, +// 'order' => 'modified desc' +// )); +// if ($article === false) { +// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); +// } +// +// $update = array( +// 'bbs_article_count' => $count +// ); +// if ($article) { +// $update['bbs_article_modified'] = $db->value($article[$this->BbsArticle->alias]['modified'], 'string'); +// } +// +// if (! $this->updateAll($update, array('Bbs.key' => $bbsKey))) { +// throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); +// } +// +// return true; +// } - $update = array( - 'article_count' => $count - ); - if ($article) { - $update['article_modified'] = $db->value($article[$this->BbsArticle->alias]['modified'], 'string'); - } - - if (! $this->updateAll($update, array('Bbs.key' => $bbsKey))) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - - return true; - } } diff --git a/Model/BbsArticle.php b/Model/BbsArticle.php index 96dcde6..0123931 100644 --- a/Model/BbsArticle.php +++ b/Model/BbsArticle.php @@ -50,9 +50,12 @@ class BbsArticle extends BbsesAppModel { * @var array */ public $actsAs = array( - 'Workflow.Workflow', + 'Bbses.BbsArticle', + 'Bbses.BbsArticlesUser', + 'Comments.Comment', + 'Likes.Like', 'NetCommons.OriginalKey', -// 'Likes.Like' + 'Workflow.Workflow', ); /** @@ -70,27 +73,28 @@ class BbsArticle extends BbsesAppModel { * @var array */ public $belongsTo = array( - 'Bbs' => array( - 'className' => 'Bbses.Bbs', - 'foreignKey' => 'bbs_id', - 'conditions' => '', - 'fields' => '', - 'order' => '' - ), +// 'Bbs' => array( +// 'className' => 'Bbses.Bbs', +// 'foreignKey' => 'bbs_id', +// 'conditions' => '', +// 'fields' => '', +// 'order' => '' +// ), 'BbsArticleTree' => array( + 'type' => 'INNER', 'className' => 'Bbses.BbsArticleTree', 'foreignKey' => false, 'conditions' => 'BbsArticleTree.bbs_article_key=BbsArticle.key', 'fields' => '', 'order' => '' ), - 'CreatedUser' => array( - 'className' => 'Users.User', - 'foreignKey' => false, - 'conditions' => 'BbsArticle.created_user = CreatedUser.id', - 'fields' => 'CreatedUser.handlename', - 'order' => '' - ) +// 'CreatedUser' => array( +// 'className' => 'Users.User', +// 'foreignKey' => false, +// 'conditions' => 'BbsArticle.created_user = CreatedUser.id', +// 'fields' => 'CreatedUser.handlename', +// 'order' => '' +// ) ); /** @@ -122,79 +126,53 @@ public function beforeValidate($options = array()) { //status to set in PublishableBehavior. )); - return parent::beforeValidate($options); - } -/** - * Set bindModel BbsArticlesUser - * - * @param int $userId users.id - * @return void - */ - public function bindModelBbsArticlesUser() { - $this->bindModel(array('belongsTo' => array( - 'BbsArticlesUser' => array( - 'className' => 'Bbses.BbsArticlesUser', - 'foreignKey' => false, - 'conditions' => array( - 'BbsArticlesUser.bbs_article_key = BbsArticle.key', - 'BbsArticlesUser.user_id' => Current::read('User.id'), - ) - ), - )), true); - } - -/** - * Get BbsArticles - * - * @param array $conditions findAll conditions - * @return array BbsArticles - */ - public function getBbsArticles($conditions) { - $bbsArticles = $this->find('all', array( - 'recursive' => 0, - 'conditions' => $conditions, - ) - ); - return $bbsArticles; - } - -/** - * Get BbsArticle - * - * @param string $bbsArticleKey bbs_article.key - * @param array $conditions find conditions - * @return array BbsArticle - */ - public function getBbsArticle($bbsArticleKey, $conditions = []) { - $conditions[$this->alias . '.key'] = $bbsArticleKey; + if (! parent::beforeValidate($options)) { + return false; + } - $bbsArticle = $this->find('first', array( - 'recursive' => 0, - 'conditions' => $conditions, - ) - ); + if (isset($this->data['BbsArticleTree'])) { + $this->BbsArticleTree->set($this->data['BbsArticleTree']); + if (! $this->BbsArticleTree->validates()) { + $this->validationErrors = Hash::merge($this->validationErrors, $this->BbsArticleTree->validationErrors); + return false; + } + } - return $bbsArticle; + return true; } /** - * Get BbsArticle by bbs_article_trees.id + * Called after each successful save operation. * - * @param id $bbsArticleTreeId bbs_article_trees.id - * @param array $conditions find conditions - * @return array BbsArticle + * @param bool $created True if this save created a new record + * @param array $options Options passed from Model::save(). + * @return void + * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#aftersave + * @see Model::save() */ - public function getBbsArticleByTreeId($bbsArticleTreeId, $conditions = []) { - $conditions['BbsArticleTree.id'] = $bbsArticleTreeId; + public function afterSave($created, $options = array()) { + //BbsArticleTree登録 + if (isset($this->BbsArticleTree->data['BbsArticleTree'])) { + if (! $this->BbsArticleTree->data['BbsArticleTree']['bbs_article_key']) { + $this->BbsArticleTree->data['BbsArticleTree']['bbs_article_key'] = $this->data[$this->alias]['key']; + } + if (! $this->BbsArticleTree->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + } + + //Bbsのbbs_article_count、bbs_article_modified + if (isset($this->data['Bbs']['id']) && isset($this->data['Bbs']['key'])) { + $this->updateBbsByBbsArticle($this->data['Bbs']['id'], $this->data['Bbs']['key'], $this->data[$this->alias]['language_id']); + } - $bbsArticle = $this->find('first', array( - 'recursive' => 0, - 'conditions' => $conditions, - ) - ); + //コメント数の更新 + if (isset($this->data['BbsArticleTree']['root_id']) && $this->data['BbsArticleTree']['root_id']) { + $this->updateBbsArticleChildCount($this->data['BbsArticleTree']['root_id'], $this->data[$this->alias]['language_id']); + } - return $bbsArticle; + parent::afterSave($created, $options); } /** @@ -209,86 +187,33 @@ public function saveBbsArticle($data) { 'Bbs' => 'Bbses.Bbs', 'BbsArticle' => 'Bbses.BbsArticle', 'BbsArticleTree' => 'Bbses.BbsArticleTree', - 'Comment' => 'Comments.Comment', ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); - try { - if (! $this->validateBbsArticle($data, ['bbsArticleTree', 'comment'])) { - return false; - } + //バリデーション + $this->set($data); + if (! $this->validates()) { + $this->rollback(); + return false; + } - //BbsArticle登録処理 + try { + //登録処理 if (! $bbsArticle = $this->save(null, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - //BbsArticleTree登録処理 - $this->BbsArticleTree->data['BbsArticleTree']['bbs_article_key'] = $bbsArticle[$this->alias]['key']; - if (! $this->BbsArticleTree->save(null, false)) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - - //コメントの登録 - if (isset($data['Comment']) && $this->Comment->data) { - $this->Comment->data[$this->Comment->name]['block_key'] = $data['Block']['key']; - $this->Comment->data[$this->Comment->name]['content_key'] = $bbsArticle[$this->alias]['key']; - if (! $this->Comment->save(null, false)) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - } - - //Bbsのarticle_count、article_modified - $this->Bbs->updateBbsArticle($data['Bbs']['id'], $data['Bbs']['key'], $data['BbsArticle']['language_id']); - - //コメント数の更新 - $this->BbsArticleTree->updateCommentCounts($data['BbsArticleTree']['root_id'], $data['BbsArticle']['status']); - //トランザクションCommit - $dataSource->commit(); + $this->commit(); + } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - //エラー出力 - CakeLog::error($ex); - throw $ex; - } - return $bbsArticle; - } - -/** - * Validate BbsArticle - * - * @param array $data received post data - * @param array $contains Optional validate sets - * @return bool True on success, false on validation error - */ - public function validateBbsArticle($data, $contains = []) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; + $this->rollback($ex); } - if (in_array('bbsArticleTree', $contains, true)) { - if (! $this->BbsArticleTree->validateBbsArticleTree($data)) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->BbsArticleTree->validationErrors); - return false; - } - } - - if (in_array('comment', $contains, true) && isset($data['Comment'])) { - if (! $this->Comment->validateByStatus($data, array('plugin' => $this->plugin, 'caller' => $this->name))) { - $this->validationErrors = Hash::merge($this->validationErrors, $this->Comment->validationErrors); - return false; - } - } - - return true; + return $bbsArticle; } /** @@ -303,43 +228,59 @@ public function deleteBbsArticle($data) { 'Bbs' => 'Bbses.Bbs', 'BbsArticle' => 'Bbses.BbsArticle', 'BbsArticleTree' => 'Bbses.BbsArticleTree', - 'Comment' => 'Comments.Comment', ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); + $this->set($data); + + $bbsArticleTree = $this->BbsArticleTree->find('first', array( + 'recursive' => -1, + 'fields' => array('lft', 'rght'), + 'conditions' => array( + 'bbs_article_key' => $this->data['BbsArticle']['key'] + ), + )); + if (! $bbsArticleTree) { + $this->rollback(); + return false; + } + $bbsArticleTrees = $this->BbsArticleTree->find('list', array( + 'recursive' => -1, + 'fields' => array('id', 'bbs_article_key'), + 'conditions' => array( + 'lft >=' => $bbsArticleTree['BbsArticleTree']['lft'], + 'rght <=' => $bbsArticleTree['BbsArticleTree']['rght'], + ), + )); try { - //BbsArticleの削除 - if (! $this->deleteAll(array($this->alias . '.key' => $data['BbsArticle']['key']), false, false)) { + //Treeデータの削除 + $conditions = array($this->BbsArticleTree->alias . '.bbs_article_key' => $this->data['BbsArticle']['key']); + if (! $this->BbsArticleTree->deleteAll($conditions, false, true)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } - //Treeデータの削除 - $this->BbsArticleTree->unbindModelBbsArticleTree(); - if (! $this->BbsArticleTree->deleteAll(array($this->BbsArticleTree->alias . '.bbs_article_key' => $data['BbsArticle']['key']), false, true)) { + //BbsArticleの削除 + if (! $this->deleteAll(array($this->alias . '.key' => $bbsArticleTrees), false, false)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } //コメントの削除 - $this->Comment->deleteByContentKey($data['BbsArticle']['key']); + $this->deleteCommentsByContentKey($this->data['BbsArticle']['key']); - //Bbsのarticle_count、article_modified - $this->Bbs->updateBbsArticle($data['Bbs']['id'], $data['Bbs']['key'], $data['BbsArticle']['language_id']); + //Bbsのbbs_article_count、bbs_article_modified + $this->updateBbsByBbsArticle($this->data['Bbs']['id'], $data['Bbs']['key'], $this->data['BbsArticle']['language_id']); //コメント数の更新 - $this->BbsArticleTree->updateCommentCounts($data['BbsArticleTree']['root_id'], $data['BbsArticle']['status'], -1); + $this->updateBbsArticleChildCount($this->data['BbsArticleTree']['root_id'], $this->data['BbsArticle']['language_id']); //トランザクションCommit - $dataSource->commit(); + $this->commit(); + } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - //エラー出力 - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); } return true; @@ -359,9 +300,8 @@ public function saveCommentAsPublish($data) { ]); //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); + $this->begin(); + $this->set($data); try { //BbsArticle登録処理 @@ -374,17 +314,16 @@ public function saveCommentAsPublish($data) { } //コメント数の更新 - $this->BbsArticleTree->updateCommentCounts($data['BbsArticleTree']['root_id'], $data['BbsArticle']['status']); + $this->updateBbsArticleChildCount($data['BbsArticleTree']['root_id'], $data['BbsArticle']['language_id']); //トランザクションCommit - $dataSource->commit(); + $this->commit(); + } catch (Exception $ex) { //トランザクションRollback - $dataSource->rollback(); - //エラー出力 - CakeLog::error($ex); - throw $ex; + $this->rollback($ex); } + return true; } diff --git a/Model/BbsArticleTree.php b/Model/BbsArticleTree.php index 5749ce8..18a31eb 100644 --- a/Model/BbsArticleTree.php +++ b/Model/BbsArticleTree.php @@ -30,8 +30,10 @@ class BbsArticleTree extends BbsesAppModel { */ public $actsAs = array( 'Tree', + 'Bbses.BbsArticle', + 'Bbses.BbsArticlesUser', 'Likes.Like' => array( - 'model' => 'BbsArticle' + 'field' => 'bbs_article_key' ), ); @@ -57,41 +59,6 @@ class BbsArticleTree extends BbsesAppModel { 'fields' => '', 'order' => '' ), - 'CreatedUser' => array( - 'className' => 'Users.User', - 'foreignKey' => false, - 'conditions' => 'BbsArticle.created_user = CreatedUser.id', - 'fields' => 'CreatedUser.handlename', - 'order' => '' - ), - //'ParentBbsArticleTree' => array( - // 'className' => 'Bbses.BbsArticleTree', - // 'foreignKey' => 'parent_id', - // 'conditions' => '', - // 'fields' => '', - // 'order' => '' - //) - ); - -/** - * hasMany associations - * - * @var array - */ - public $hasMany = array( - //'ChildBbsArticleTree' => array( - // 'className' => 'Bbses.BbsArticleTree', - // 'foreignKey' => 'parent_id', - // 'dependent' => false, - // 'conditions' => '', - // 'fields' => '', - // 'order' => '', - // 'limit' => '', - // 'offset' => '', - // 'exclusive' => '', - // 'finderQuery' => '', - // 'counterQuery' => '' - //) ); /** @@ -141,36 +108,6 @@ public function beforeValidate($options = array()) { return parent::beforeValidate($options); } -/** - * Set bindModel BbsArticlesUser - * - * @param int $userId users.id - * @return void - */ - public function bindModelBbsArticlesUser($userId) { - $this->bindModel(array('belongsTo' => array( - 'BbsArticlesUser' => array( - 'className' => 'Bbses.BbsArticlesUser', - 'foreignKey' => false, - 'conditions' => array( - 'BbsArticlesUser.bbs_article_key=BbsArticleTree.bbs_article_key', - 'BbsArticlesUser.user_id' => $userId - ) - ), - )), false); - } - -/** - * Set unbindModel BbsArticleTree - * - * @return void - */ - public function unbindModelBbsArticleTree() { - $this->unbindModel( - array('belongsTo' => array_keys($this->belongsTo), - ), true); - } - /** * Get max article no * @@ -194,42 +131,11 @@ public function getMaxNo($rootArticleTreeId) { 'order' => $this->alias . '.article_no DESC', )); - return isset($bbsArticleTree[$this->alias]['article_no']) ? $bbsArticleTree[$this->alias]['article_no'] : 0; - } - -/** - * Update bbs_article_counts - * - * @param int $rootId RootId for bbs posts - * @param int $status status - * @param int $increment increment - * @return mixed On success Model::$data if its not empty or true, false on failure - * @throws InternalErrorException - */ - public function updateCommentCounts($rootId, $status, $increment = 1) { - if ((int)$rootId > 0 && (int)$status === (int)NetCommonsBlockComponent::STATUS_PUBLISHED) { - $update = array('BbsArticleTree.bbs_article_count' => 'BbsArticleTree.bbs_article_count + (' . (int)$increment . ')'); - $conditions = array('BbsArticleTree.id' => (int)$rootId); - - if (! $this->updateAll($update, $conditions)) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - } - } - -/** - * Validate BbsArticleTree - * - * @param array $data received post data - * @return bool|array True on success, validation errors array on error - */ - public function validateBbsArticleTree($data) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; + if (isset($bbsArticleTree[$this->alias]['article_no'])) { + return $bbsArticleTree[$this->alias]['article_no']; + } else { + return '0'; } - return true; } } diff --git a/Model/BbsArticlesUser.php b/Model/BbsArticlesUser.php index 99e0ebc..81e3ca5 100644 --- a/Model/BbsArticlesUser.php +++ b/Model/BbsArticlesUser.php @@ -75,57 +75,4 @@ public function beforeValidate($options = array()) { return parent::beforeValidate($options); } -/** - * Save BbsArticlesUser - * - * @param array $data received post data - * @return mixed On success Model::$data if its not empty or true, false on failure - * @throws InternalErrorException - */ - public function saveArticlesUser($data) { - $this->loadModels([ - 'BbsArticlesUser' => 'Bbses.BbsArticlesUser', - ]); - - //トランザクションBegin - $this->setDataSource('master'); - $dataSource = $this->getDataSource(); - $dataSource->begin(); - - try { - if (! $this->validateBbsArticlesUser($data)) { - return false; - } - - $bbsArticlesUser = $this->save(null, false); - if (! $bbsArticlesUser) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); - } - //トランザクションCommit - $dataSource->commit(); - } catch (Exception $ex) { - //トランザクションRollback - $dataSource->rollback(); - //エラー出力 - CakeLog::error($ex); - throw $ex; - } - return $bbsArticlesUser; - } - -/** - * Validate BbsArticlesUser - * - * @param array $data received post data - * @return bool True on success, false on error - */ - public function validateBbsArticlesUser($data) { - $this->set($data); - $this->validates(); - if ($this->validationErrors) { - return false; - } - return true; - } - } diff --git a/Model/Behavior/BbsArticleBehavior.php b/Model/Behavior/BbsArticleBehavior.php new file mode 100644 index 0000000..a347ffd --- /dev/null +++ b/Model/Behavior/BbsArticleBehavior.php @@ -0,0 +1,161 @@ + + * @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('ModelBehavior', 'Model'); + +/** + * BbsArticle Behavior + * + * @author Shohei Nakajima + * @package NetCommons\Categories\Model\Behavior + */ +class BbsArticleBehavior extends ModelBehavior { + +/** + * Update bbs_article_modified and bbs_article_count + * + * @param int $bbsId bbses.id + * @param string $bbsKey bbses.key + * @param int $languageId languages.id + * @return bool True on success + * @throws InternalErrorException + */ + public function updateBbsByBbsArticle(Model $model, $bbsId, $bbsKey, $languageId) { + $db = $model->getDataSource(); + + $conditions = array( + 'bbs_id' => $bbsId, + 'language_id' => $languageId, + 'is_latest' => true + ); + $count = $model->find('count', array( + 'recursive' => -1, + 'conditions' => $conditions, + )); + if ($count === false) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + $article = $model->find('first', array( + 'recursive' => -1, + 'fields' => 'modified', + 'conditions' => $conditions, + 'order' => array('modified' => 'desc'), + )); + if ($article === false) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + $update = array( + 'bbs_article_count' => $count + ); + if ($article) { + $update['bbs_article_modified'] = $db->value($article[$model->alias]['modified'], 'string'); + } + + if (! $model->Bbs->updateAll($update, array('Bbs.key' => $bbsKey))) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + return true; + } + +/** + * Update bbs_article_child_count + * + * @param int $rootId RootId for bbs posts + * @param int $status status + * @param int $increment increment + * @return mixed On success Model::$data if its not empty or true, false on failure + * @throws InternalErrorException + */ + public function updateBbsArticleChildCount(Model $model, $rootId, $languageId) { + $rootId = (int)$rootId; + + $conditions = array( + 'BbsArticleTree.root_id' => $rootId, + 'BbsArticle.language_id' => $languageId, + 'BbsArticle.is_active' => true + ); + $count = $model->find('count', array( + 'recursive' => 0, + 'conditions' => $conditions, + )); + if ($count === false) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + + $update = array('BbsArticleTree.bbs_article_child_count' => $count); + $conditions = array('BbsArticleTree.id' => $rootId); + if (! $model->updateAll($update, $conditions)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + } + +/** + * Title of reply + * + * @param string $title bbs_articles.title + * @return string bbs_articles.title + */ + public function getReplyTitle(Model $model, $title) { + $matches = array(); + if (preg_match('/^Re(\d)?:/', $title, $matches)) { + if (isset($matches[1])) { + $count = (int)$matches[1]; + } else { + $count = 1; + } + $result = preg_replace('/^Re(\d)?:/', 'Re' . ($count + 1) . ': ', $title); + } else { + $result = 'Re: ' . $title; + } + + return $result; + } + +/** + * Content of reply + * + * @param string $title bbs_articles.content + * @return string bbs_articles.content + */ + public function getReplyContent(Model $model, $content) { + $result = '

' . $content . '

'; + return $result; + } + +/** + * Set bindModel BbsArticlesUser + * + * @param object $model instance of model + * @param bool $reset Set to false to make the binding permanent + * @return void + */ + public function bindModelBbsArticle(Model $model, $reset) { + if ($model->hasField('bbs_article_key')) { + $field = 'bbs_article_key'; + } else { + $field = 'key'; + } + $model->bindModel(array('belongsTo' => array( + 'CreatedUser' => array( + 'className' => 'Users.User', + 'fields' => 'CreatedUser.handlename', + 'foreignKey' => false, + 'conditions' => array( + 'BbsArticle.created_user = CreatedUser.id', + ) + ), + )), $reset); + } + +} diff --git a/Model/Behavior/BbsArticlesUserBehavior.php b/Model/Behavior/BbsArticlesUserBehavior.php new file mode 100644 index 0000000..1b040a9 --- /dev/null +++ b/Model/Behavior/BbsArticlesUserBehavior.php @@ -0,0 +1,103 @@ + + * @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('ModelBehavior', 'Model'); + +/** + * BbsArticlesUser Behavior + * + * @author Shohei Nakajima + * @package NetCommons\Categories\Model\Behavior + */ +class BbsArticlesUserBehavior extends ModelBehavior { + +/** + * Set bindModel BbsArticlesUser + * + * @param object $model instance of model + * @param bool $reset Set to false to make the binding permanent + * @return void + */ + public function bindModelBbsArticlesUser(Model $model, $reset) { + if ($model->hasField('bbs_article_key')) { + $field = 'bbs_article_key'; + } else { + $field = 'key'; + } + $model->bindModel(array('belongsTo' => array( + 'BbsArticlesUser' => array( + 'className' => 'Bbses.BbsArticlesUser', + 'foreignKey' => false, + 'conditions' => array( + 'BbsArticlesUser.bbs_article_key = ' . $model->alias . '.' . $field, + 'BbsArticlesUser.user_id' => Current::read('User.id'), + ) + ), + )), $reset); + } + +/** + * Save BbsArticlesUser + * + * @param object $model instance of model + * @param array $bbsArticleKey received bbs_article_key + * @return mixed On success Model::$data if its not empty or true, false on failure + * @throws InternalErrorException + */ + public function readToArticle(Model $model, $bbsArticleKey) { + $model->loadModels([ + 'BbsArticlesUser' => 'Bbses.BbsArticlesUser', + ]); + + //既読チェック + if (! Current::read('User.id')) { + return true; + } + $count = $model->BbsArticlesUser->find('count', array( + 'recursive' => -1, + 'conditions' => array( + 'bbs_article_key' => $bbsArticleKey, + 'user_id' => Current::read('User.id') + ) + )); + if ($count > 0) { + return true; + } + + //トランザクションBegin + $model->BbsArticlesUser->begin(); + + //バリデーション + $data = $model->BbsArticlesUser->create(array( + 'bbs_article_key' => $bbsArticleKey, + 'user_id' => Current::read('User.id') + )); + $model->BbsArticlesUser->set($data); + if (! $model->BbsArticlesUser->validates()) { + $model->BbsArticlesUser->rollback(); + return false; + } + + try { + if (! $model->BbsArticlesUser->save(null, false)) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + //トランザクションCommit + $model->BbsArticlesUser->commit(); + + } catch (Exception $ex) { + //トランザクションRollback + $model->BbsArticlesUser->rollback($ex); + } + return true; + } + +} diff --git a/Test/Fixture/BbsArticleTreeFixture.php b/Test/Fixture/BbsArticleTreeFixture.php index ab5b3af..5cde112 100644 --- a/Test/Fixture/BbsArticleTreeFixture.php +++ b/Test/Fixture/BbsArticleTreeFixture.php @@ -31,7 +31,7 @@ class BbsArticleTreeFixture extends CakeTestFixture { 'lft' => array('type' => 'integer', 'null' => false, 'default' => null, 'comment' => 'lft | treeビヘイビア必須カラム | | '), 'rght' => array('type' => 'integer', 'null' => false, 'default' => null, 'comment' => 'rght | treeビヘイビア必須カラム | | '), 'article_no' => array('type' => 'integer', 'null' => false, 'default' => '1', 'comment' => 'comment index | 記事毎の採番 | | '), - 'bbs_article_counts' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'Published comment counts | 公開されたコメント数 | | '), + 'bbs_article_child_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'Published comment counts | 公開されたコメント数 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'modified user | 更新者 | users.id | '), @@ -57,7 +57,7 @@ class BbsArticleTreeFixture extends CakeTestFixture { 'lft' => 1, 'rght' => 1, 'article_no' => 1, - 'bbs_article_counts' => 1, + 'bbs_article_child_count' => 1, 'created_user' => 1, 'created' => '2015-05-14 07:09:02', 'modified_user' => 1, diff --git a/Test/Fixture/BbsFixture.php b/Test/Fixture/BbsFixture.php index f3db96b..c42dc39 100644 --- a/Test/Fixture/BbsFixture.php +++ b/Test/Fixture/BbsFixture.php @@ -29,7 +29,7 @@ class BbsFixture extends CakeTestFixture { 'key' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs key | 掲示板キー | Hash値 | ', 'charset' => 'utf8'), 'block_id' => array('type' => 'integer', 'null' => false, 'default' => null), 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'bbs name | 掲示板名称 | | ', 'charset' => 'utf8'), - 'article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'Article count | 記事数 | | '), + 'bbs_article_count' => array('type' => 'integer', 'null' => false, 'default' => '0', 'comment' => 'Article count | 記事数 | | '), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'created user | 作成者 | users.id | '), 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '), 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => '0', 'comment' => 'modified user | 更新者 | users.id | '), @@ -51,7 +51,7 @@ class BbsFixture extends CakeTestFixture { 'key' => 'bbs_1', 'block_id' => 1, 'name' => 'テスト掲示板1', - 'article_count' => 1, + 'bbs_article_count' => 1, 'created_user' => 1, 'created' => '2014-06-18 02:06:22', 'modified_user' => 1, diff --git a/View/BbsArticles/edit.ctp b/View/BbsArticles/edit.ctp index 0d5b3d5..c296108 100644 --- a/View/BbsArticles/edit.ctp +++ b/View/BbsArticles/edit.ctp @@ -8,46 +8,48 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ -?> -Html->script('/net_commons/js/wysiwyg.js', false); ?> -Html->script('/bbses/js/bbses.js', false); ?> +echo $this->NetCommonsHtml->script(array( + '/net_commons/js/wysiwyg.js', + '/bbses/js/bbses.js' +)); + +$bbsArticle = array(); +$bbsArticle['content'] = $this->data['BbsArticle']['content']; +?> -
-
+
-
-

- -

+
+

+ +

-
- Form->create('BbsArticle', array('novalidate' => true)); ?> -
+
+ Form->create('BbsArticle', array('novalidate' => true)); ?> +
- element('BbsArticles/edit_form'); ?> + element('BbsArticles/edit_form'); ?> - request->params['action'] === 'add' || $this->request->params['action'] === 'edit' && ! $bbsArticleTree['rootId']) : ?> -
- element('Comments.form'); ?> - + request->params['action'] === 'add' || + $this->request->params['action'] === 'edit' && ! $this->data['BbsArticleTree']['root_id']) : ?> +
-
- - Form->end(); ?> + Workflow->inputComment('BbsArticle.status'); ?> + +
- request->params['action'] === 'edit') : ?> - - -
+ Workflow->buttons('BbsArticle.status'); ?> + Form->end(); ?> - element('Comments.index'); ?> + request->params['action'] === 'edit' && $this->Workflow->canDelete('BbsArticle', $this->data)) : ?> + + +
-
-
+ Workflow->comments(); ?> +
diff --git a/View/BbsArticles/index.ctp b/View/BbsArticles/index.ctp index 877ef05..6e9fae8 100644 --- a/View/BbsArticles/index.ctp +++ b/View/BbsArticles/index.ctp @@ -8,6 +8,8 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ + +echo $this->NetCommonsHtml->css('/bbses/css/style.css'); ?>
diff --git a/View/BbsArticles/view.ctp b/View/BbsArticles/view.ctp index 114bed5..05b5680 100644 --- a/View/BbsArticles/view.ctp +++ b/View/BbsArticles/view.ctp @@ -8,28 +8,14 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ -?> -Html->css( - array( - '/bbses/css/style.css', - '/likes/css/style.css' - ), - array( - 'plugin' => false, - 'once' => true, - 'inline' => false - ) - ); - $this->Html->script( - '/likes/js/likes.js', - array( - 'plugin' => false, - 'once' => true, - 'inline' => false - ) - ); +echo $this->NetCommonsHtml->css(array( + '/bbses/css/style.css', + '/likes/css/style.css' +)); + +echo $this->NetCommonsHtml->script('/likes/js/likes.js'); + ?>
@@ -74,10 +60,10 @@
- + element('BbsArticles/view_bbs_article', array( 'bbsArticle' => $childBbsArticle, - 'parentBbsArticle' => $bbsArticleChildren[$childBbsArticle['bbsArticleTree']['parentId']], + 'parentBbsArticle' => $bbsArticleChildren[$childBbsArticle['BbsArticleTree']['parent_id']], )); ?> diff --git a/View/BbsBlockRolePermissions/edit.ctp b/View/BbsBlockRolePermissions/edit.ctp index 30a61a5..dcb9a17 100644 --- a/View/BbsBlockRolePermissions/edit.ctp +++ b/View/BbsBlockRolePermissions/edit.ctp @@ -20,7 +20,7 @@ 'model' => 'BbsBlockRolePermission', 'action' => 'edit' . '/' . $this->data['Frame']['id'] . '/' . $this->data['Block']['id'], 'callback' => 'Bbses.BbsBlockRolePermissions/edit_form', - 'cancelUrl' => Current::backToIndexUrl('default_setting_action'), + 'cancelUrl' => NetCommonsUrl::backToIndexUrl('default_setting_action'), )); ?>
diff --git a/View/BbsBlocks/edit.ctp b/View/BbsBlocks/edit.ctp index 9546dbd..db9d365 100644 --- a/View/BbsBlocks/edit.ctp +++ b/View/BbsBlocks/edit.ctp @@ -19,7 +19,7 @@ element('Blocks.edit_form', array( 'model' => 'Bbs', 'callback' => 'Bbses.BbsBlocks/edit_form', - 'cancelUrl' => Current::backToIndexUrl('default_setting_action'), + 'cancelUrl' => NetCommonsUrl::backToIndexUrl('default_setting_action'), )); ?> request->params['action'] === 'edit') : ?> diff --git a/View/BbsBlocks/index.ctp b/View/BbsBlocks/index.ctp index bb8665e..74921a5 100644 --- a/View/BbsBlocks/index.ctp +++ b/View/BbsBlocks/index.ctp @@ -18,7 +18,9 @@ Button->addLink(); ?>
- Form->create('', array('url' => '/frames/frames/edit/' . $this->data['Frame']['id'])); ?> + Form->create('', array( + 'url' => NetCommonsUrl::actionUrl(array('plugin' => 'frames', 'controller' => 'frames', 'action' => 'edit')) + )); ?> Form->hidden('Frame.id'); ?> @@ -30,10 +32,10 @@ Paginator->sort('Bbs.name', __d('bbses', 'Bbs name')); ?> - Paginator->sort('Bbs.article_count', __d('bbses', 'Article count')); ?> + Paginator->sort('Bbs.bbs_article_count', __d('bbses', 'Article count')); ?> - Paginator->sort('Bbs.article_modified', __d('bbses', 'Article modified')); ?> + Paginator->sort('Bbs.bbs_article_modified', __d('bbses', 'Article modified')); ?> @@ -44,13 +46,13 @@ BlockForm->displayFrame('Frame.block_id', $bbs['Block']['id']); ?> - NetCommonsForm->editLink($bbs['Block']['id'], $bbs['Bbs']['name']); ?> + NetCommonsHtml->editLink($bbs['Bbs']['name'], array('block_id' => $bbs['Block']['id'])); ?> - + - Date->dateFormat($bbs['Bbs']['article_modified']); ?> + Date->dateFormat($bbs['Bbs']['bbs_article_modified']); ?> diff --git a/View/BbsFrameSettings/edit.ctp b/View/BbsFrameSettings/edit.ctp index c9d1e8a..eb69d4f 100644 --- a/View/BbsFrameSettings/edit.ctp +++ b/View/BbsFrameSettings/edit.ctp @@ -17,7 +17,7 @@ element('Blocks.edit_form', array( 'model' => 'BbsFrameSetting', 'callback' => 'Bbses.BbsFrameSettings/edit_form', - 'cancelUrl' => Current::backToPageUrl(), + 'cancelUrl' => NetCommonsUrl::backToPageUrl(), )); ?>
diff --git a/View/Elements/BbsArticles/breadcrumb.ctp b/View/Elements/BbsArticles/breadcrumb.ctp index ad953aa..e210cfd 100644 --- a/View/Elements/BbsArticles/breadcrumb.ctp +++ b/View/Elements/BbsArticles/breadcrumb.ctp @@ -12,44 +12,43 @@