diff --git a/Config/Migration/1565491879_add_calendar_event_key_by_blog_entries.php b/Config/Migration/1565491879_add_calendar_event_key_by_blog_entries.php new file mode 100644 index 0000000..6167e61 --- /dev/null +++ b/Config/Migration/1565491879_add_calendar_event_key_by_blog_entries.php @@ -0,0 +1,57 @@ + array( + 'create_field' => array( + 'blog_entries' => array( + 'calendar_event_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'body2'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'blog_entries' => array('calendar_event_key'), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + return true; + } +} diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index ba76c70..4b8373f 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -52,6 +52,7 @@ public function after($event = array()) { 'title_icon' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'body1' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '本文1', 'charset' => 'utf8'), 'body2' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '本文2', 'charset' => 'utf8'), + 'calendar_event_key' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'public_type' => array('type' => 'integer', 'null' => false, 'default' => '2', 'length' => 4, 'unsigned' => false), 'publish_start' => array('type' => 'datetime', 'null' => true, 'default' => null), 'publish_end' => array('type' => 'datetime', 'null' => true, 'default' => null), diff --git a/Config/do_not_delete_blogs.php b/Config/do_not_delete_blogs.php new file mode 100644 index 0000000..a3be2d6 --- /dev/null +++ b/Config/do_not_delete_blogs.php @@ -0,0 +1,8 @@ + 'school_blog' +]; \ No newline at end of file diff --git a/Controller/BlogBlocksController.php b/Controller/BlogBlocksController.php index e3d08c2..226700f 100644 --- a/Controller/BlogBlocksController.php +++ b/Controller/BlogBlocksController.php @@ -90,6 +90,8 @@ public function beforeFilter() { if ($this->params['action'] === 'index') { $this->Components->unload('Categories.CategoryEdit'); } + + Configure::load('Blogs.do_not_delete_blogs'); } /** @@ -165,6 +167,9 @@ public function edit() { */ public function delete() { if ($this->request->is('delete')) { + if (in_array($this->data['Blog']['key'], Configure::read('Blogs.doNotDeleteBlogs'), true)) { + return $this->throwBadRequest(__d('blogs', 'This blog cannot be deleted.')); + } if ($this->Blog->deleteBlog($this->data)) { return $this->redirect(NetCommonsUrl::backToIndexUrl('default_setting_action')); } diff --git a/Controller/BlogEntriesEditController.php b/Controller/BlogEntriesEditController.php index 7413d34..9b92754 100644 --- a/Controller/BlogEntriesEditController.php +++ b/Controller/BlogEntriesEditController.php @@ -99,13 +99,55 @@ public function add() { $this->NetCommons->handleValidationError($this->BlogEntry->validationErrors); } else { + //$this->set('cancelUrl', null); + $blogEntry['BlogEntry']['calendar_event_key'] = $this->request->query('event_key'); + if ($blogEntry['BlogEntry']['calendar_event_key'] !== null) { + // カレンダからの実績登録時 + $title = $this->__getTitleByCalendarEvent($blogEntry['BlogEntry']['calendar_event_key']); + $blogEntry['BlogEntry']['title'] = $title; + $cancelUrl = NetCommonsUrl::actionUrl([ + 'plugin' => 'calendars', + 'controller' => 'calendar_plans', + 'action' => 'view', + 'key' => $blogEntry['BlogEntry']['calendar_event_key'], + 'page_id' => $this->request->query('page_id') + ]); + $this->set('cancelUrl', $cancelUrl); + } $this->request->data = $blogEntry; $this->request->data['Tag'] = array(); + } $this->view = 'form'; } +/** + * 指定されたカレンダイベントの開始日とイベント名を組み合わせたタイトルを返す + * + * @param string $calendarEventKey CalendarEvent.key + * @return string n月j日イベント名 + */ + private function __getTitleByCalendarEvent($calendarEventKey) { + /** @var CalendarEvent $calendarEventModel */ + $calendarEventModel = ClassRegistry::init('Calendars.CalendarEvent'); + $roomPermRoles = $calendarEventModel->prepareCalRoleAndPerm(); + CalendarPermissiveRooms::setRoomPermRoles($roomPermRoles); + + $event = $calendarEventModel->getEventByKey($calendarEventKey); + if (!$event) { + $this->throwBadRequest('CalendarEvent Not Found'); + return ''; + } + $time = strtotime($event['CalendarEvent']['dtstart']) + + $event['CalendarEvent']['timezone_offset'] * HOUR; + $title = date(__d('blogs', 'EventDateFormat'), $time); + + $title .= $event['CalendarEvent']['title']; + + return $title; + } + /** * edit method * diff --git a/Locale/eng/LC_MESSAGES/blogs.po b/Locale/eng/LC_MESSAGES/blogs.po index d712b7e..d7ae737 100644 --- a/Locale/eng/LC_MESSAGES/blogs.po +++ b/Locale/eng/LC_MESSAGES/blogs.po @@ -135,3 +135,5 @@ msgstr "" msgid "%s articles" msgstr "" +msgid "EventDateFormat" +msgstr "M/j" \ No newline at end of file diff --git a/Locale/jpn/LC_MESSAGES/blogs.po b/Locale/jpn/LC_MESSAGES/blogs.po index 05af961..789e0fe 100644 --- a/Locale/jpn/LC_MESSAGES/blogs.po +++ b/Locale/jpn/LC_MESSAGES/blogs.po @@ -134,3 +134,9 @@ msgstr "%s 件" #: Blogs/View/Elements/BlogFrameSettings/edit_form.ctp:23 msgid "%s articles" msgstr "%s 件" + +msgid "This blog cannot be deleted." +msgstr "削除不可のブログです。" + +msgid "EventDateFormat" +msgstr "n月j日" \ No newline at end of file diff --git a/Model/Blog.php b/Model/Blog.php index aed5a2f..5d9ed70 100644 --- a/Model/Blog.php +++ b/Model/Blog.php @@ -292,4 +292,25 @@ public function deleteBlog($data) { return true; } +/** + * findBlockIdByKey + * + * @param string $blogKey Blog.key + * @return int|null + */ + public function findBlockIdByKey($blogKey) { + $options = [ + 'conditions' => [ + 'Blog.key' => $blogKey + ], + 'fields' => ['Blog.block_id'], + 'recursive' => -1 + ]; + $result = $this->find('first', $options); + if ($result) { + return $result['Blog']['block_id']; + } + return null; + } + } diff --git a/Model/BlogEntry.php b/Model/BlogEntry.php index 2b57a95..57ab8d9 100644 --- a/Model/BlogEntry.php +++ b/Model/BlogEntry.php @@ -457,4 +457,17 @@ public function yetPublish($blogEntry) { return ($count == 0); } +/** + * getByCalendarEventKey + * + * @param string $calendarEventKey calendar event.key + * @return array|int|null + */ + public function getByCalendarEventKey($calendarEventKey) { + $conditions = [ + 'BlogEntry.calendar_event_key' => $calendarEventKey + ]; + $conditions = $this->getWorkflowConditions($conditions); + return $this->find('first', ['conditions' => $conditions]); + } } diff --git a/Test/Fixture/BlogEntryFixture.php b/Test/Fixture/BlogEntryFixture.php index df7d9e2..a58cb51 100644 --- a/Test/Fixture/BlogEntryFixture.php +++ b/Test/Fixture/BlogEntryFixture.php @@ -44,6 +44,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '1', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), array( 'id' => '2', @@ -67,6 +68,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '2', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), // * 一般が書いたコンテンツ&一度も公開していない(承認待ち) array( @@ -91,6 +93,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '3', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), // * 一般が書いたコンテンツ&公開して、一時保存 // (id=4とid=5で区別できるものをセットする) @@ -116,6 +119,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '4', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), array( 'id' => '5', @@ -139,6 +143,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '5', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), // * 編集者が書いたコンテンツ&一度公開して、差し戻し // (id=6とid=7で区別できるものをセットする) @@ -164,6 +169,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '6', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), array( 'id' => '7', @@ -187,6 +193,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '7', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), array( 'id' => '8', @@ -210,6 +217,7 @@ class BlogEntryFixture extends CakeTestFixture { 'modified_user' => '8', 'modified' => '2016-03-17 07:10:12', 'title_icon' => '', + 'calendar_event_key' => null, ), ); diff --git a/View/BlogBlocks/edit.ctp b/View/BlogBlocks/edit.ctp index 481c33f..f638721 100644 --- a/View/BlogBlocks/edit.ctp +++ b/View/BlogBlocks/edit.ctp @@ -22,7 +22,12 @@ 'cancelUrl' => NetCommonsUrl::backToIndexUrl('default_setting_action'), )); ?> - request->params['action'] === 'edit') : ?> + request->params['action'] === 'edit' && + !in_array( + $this->request->data['Blog']['key'], + Configure::read('Blogs.doNotDeleteBlogs'), + true + )) : ?> element('Blocks.delete_form', array( 'model' => 'BlogBlock', 'action' => NetCommonsUrl::actionUrl(array( diff --git a/View/BlogEntriesEdit/form.ctp b/View/BlogEntriesEdit/form.ctp index 17121b8..6aa004e 100644 --- a/View/BlogEntriesEdit/form.ctp +++ b/View/BlogEntriesEdit/form.ctp @@ -34,6 +34,7 @@ $dataJson = json_encode( NetCommonsForm->hidden('Block.id', array( 'value' => Current::read('Block.id'), )); ?> + NetCommonsForm->hidden('BlogEntry.calendar_event_key');?>