diff --git a/Config/Migration/1563059535_alter_event_add_target_person_and_belongings.php b/Config/Migration/1563059535_alter_event_add_target_person_and_belongings.php new file mode 100644 index 0000000..522a2a3 --- /dev/null +++ b/Config/Migration/1563059535_alter_event_add_target_person_and_belongings.php @@ -0,0 +1,58 @@ + array( + 'create_field' => array( + 'calendar_events' => array( + 'target_person' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '対象者(テキスト)', 'charset' => 'utf8', 'after' => 'location'), + 'belongings' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '持ち物', 'charset' => 'utf8', 'after' => 'target_person'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'calendar_events' => array('target_person', 'belongings'), + ), + ), + ); + +/** + * 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/Migration/1563168303_alter_event_change_target_person_columns.php b/Config/Migration/1563168303_alter_event_change_target_person_columns.php new file mode 100644 index 0000000..03bc224 --- /dev/null +++ b/Config/Migration/1563168303_alter_event_change_target_person_columns.php @@ -0,0 +1,66 @@ + array( + 'create_field' => array( + 'calendar_events' => array( + 'target_person_grade' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '対象者(テキスト)', 'charset' => 'utf8', 'after' => 'location'), + 'target_person_class_room' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'target_person_grade'), + ), + ), + 'drop_field' => array( + 'calendar_events' => array('target_person'), + ), + ), + 'down' => array( + 'drop_field' => array( + 'calendar_events' => array('target_person_grade', 'target_person_class_room'), + ), + 'create_field' => array( + 'calendar_events' => array( + 'target_person' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '対象者(テキスト)', 'charset' => 'utf8'), + ), + ), + ), + ); + +/** + * 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 5da139c..a5f5e6c 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -101,6 +101,9 @@ public function after($event = array()) { 'title' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'タイトル', 'charset' => 'utf8'), 'title_icon' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => 'タイトル アイコン', 'charset' => 'utf8'), 'location' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '場所', 'charset' => 'utf8'), + 'target_person_grade' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '対象者(テキスト)', 'charset' => 'utf8'), + 'target_person_class_room' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'belongings' => array('type' => 'string', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '持ち物', 'charset' => 'utf8'), 'contact' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '連絡先', 'charset' => 'utf8'), 'description' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'comment' => '詳細', 'charset' => 'utf8'), 'is_allday' => array('type' => 'boolean', 'null' => true, 'default' => '1', 'comment' => '終日かどうか | 0:終日ではない | 1:終日'), diff --git a/Config/related_blog.php b/Config/related_blog.php new file mode 100644 index 0000000..7547b00 --- /dev/null +++ b/Config/related_blog.php @@ -0,0 +1,8 @@ + 'school_blog' +]; diff --git a/Locale/jpn/LC_MESSAGES/calendars.po b/Locale/jpn/LC_MESSAGES/calendars.po index c04e4c4..3c112a3 100644 --- a/Locale/jpn/LC_MESSAGES/calendars.po +++ b/Locale/jpn/LC_MESSAGES/calendars.po @@ -1215,4 +1215,28 @@ msgid "End date and time" msgstr "終了日時" msgid "You can not set sharers." -msgstr "予定の共有者を設定する権限がありません。" \ No newline at end of file +msgstr "予定の共有者を設定する権限がありません。" + +msgid "Target Person" +msgstr "対象者" + +msgid "Grade" +msgstr "学年" + +msgid "Class room" +msgstr "クラス" + +msgid "Belongings" +msgstr "持ち物" + +msgid "%d character limited. (grade)" +msgstr "学年は最大 %d 文字です。" + +msgid "%d character limited. (class room)" +msgstr "クラスは最大 %d 文字です。" + +msgid "%d character limited. (belongings)" +msgstr "持ち物は最大 %d 文字です。" + +msgid "Add Achievement" +msgstr "実績の追加" \ No newline at end of file diff --git a/Model/Behavior/CalendarAppBehavior.php b/Model/Behavior/CalendarAppBehavior.php index e9f82a4..4da9490 100644 --- a/Model/Behavior/CalendarAppBehavior.php +++ b/Model/Behavior/CalendarAppBehavior.php @@ -381,6 +381,9 @@ public function setPlanParams2Params(&$planParams, &$params) { $keys = array( 'title', 'title_icon', + 'target_person_grade', + 'target_person_class_room', + 'belongings', 'location', 'contact', 'description', @@ -421,6 +424,9 @@ public function setEventData($planParams, $rruleData, &$eventData) { 'target_user' => Current::read('User.id'), 'title' => '', 'title_icon' => '', + 'target_person_grade' => '', + 'target_person_class_room' => '', + 'belongings' => '', 'location' => '', 'contact' => '', 'description' => '', @@ -454,6 +460,9 @@ public function setEventData($planParams, $rruleData, &$eventData) { $eventData['CalendarEvent']['target_user'] = $params['target_user']; $eventData['CalendarEvent']['title'] = $params['title']; $eventData['CalendarEvent']['title_icon'] = $params['title_icon']; + $eventData['CalendarEvent']['target_person_grade'] = $params['target_person_grade']; + $eventData['CalendarEvent']['target_person_class_room'] = $params['target_person_class_room']; + $eventData['CalendarEvent']['belongings'] = $params['belongings']; $eventData['CalendarEvent']['is_allday'] = $params['is_allday']; $eventData['CalendarEvent']['start_date'] = $params['start_date']; $eventData['CalendarEvent']['start_time'] = $params['start_time']; diff --git a/Model/Behavior/CalendarUpdatePlanBehavior.php b/Model/Behavior/CalendarUpdatePlanBehavior.php index 2b74f0d..ab4f4b4 100644 --- a/Model/Behavior/CalendarUpdatePlanBehavior.php +++ b/Model/Behavior/CalendarUpdatePlanBehavior.php @@ -719,6 +719,12 @@ private function __getEventDataForUpdateAllOrAfter($event, $eventData, $status) //タイトル、場所、連絡先、詳細は編集画面の値を使う $event['CalendarEvent']['title'] = $eventData['CalendarEvent']['title']; $event['CalendarEvent']['title_icon'] = $eventData['CalendarEvent']['title_icon']; + $event['CalendarEvent']['target_person_grade'] = + $eventData['CalendarEvent']['target_person_grade']; + $event['CalendarEvent']['target_person_class_room'] = + $eventData['CalendarEvent']['target_person_class_room']; + $event['CalendarEvent']['belongings'] = $eventData['CalendarEvent']['belongings']; + $event['CalendarEvent']['location'] = $eventData['CalendarEvent']['location']; $event['CalendarEvent']['contact'] = $eventData['CalendarEvent']['contact']; $event['CalendarEvent']['description'] = $eventData['CalendarEvent']['description']; diff --git a/Model/CalendarActionPlan.php b/Model/CalendarActionPlan.php index f6900e0..b7b4926 100644 --- a/Model/CalendarActionPlan.php +++ b/Model/CalendarActionPlan.php @@ -173,6 +173,10 @@ class CalendarActionPlan extends CalendarsAppModel { 'detail_end_datetime' => array( 'type' => 'string', 'default' => ''), //YYYY-MM-DD or YYYY-MM-DD hh:mm + 'target_person_grade' => ['type' => 'string', 'default' => ''], + 'target_person_class_room' => ['type' => 'string', 'default' => ''], + 'belongings' => ['type' => 'string', 'default' => ''], + //公開対象 'plan_room_id' => array( 'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false), @@ -454,6 +458,30 @@ public function beforeValidate($options = array()) { '%d character limited. (location)'), CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), ), ), + 'target_person_grade' => array( + 'max_length' => array( + 'rule' => array('maxLength', CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + 'required' => false, + 'message' => sprintf(__d('calendars', + '%d character limited. (grade)'), CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + ), + ), + 'target_person_class_room' => array( + 'max_length' => array( + 'rule' => array('maxLength', CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + 'required' => false, + 'message' => sprintf(__d('calendars', + '%d character limited. (class room)'), CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + ), + ), + 'belongings' => array( + 'max_length' => array( + 'rule' => array('maxLength', CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + 'required' => false, + 'message' => sprintf(__d('calendars', + '%d character limited. (belongings)'), CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), + ), + ), 'contact' => array( 'rule1' => array( 'rule' => array('maxLength', CalendarsComponent::CALENDAR_VALIDATOR_TITLE_LEN), @@ -649,6 +677,7 @@ public function convertToPlanParamFormat($data) { 'title', 'title_icon', //FIXME: insert/update側に追加実装しないといけない項目 'location', 'contact', 'description', 'enable_email', 'email_send_timing', 'status', + 'target_person_grade', 'target_person_class_room', 'belongings' ); foreach ($fields as $field) { $planParam[$field] = $data[$this->alias][$field]; diff --git a/Test/Case/Controller/CalendarPlans/AddTest.php b/Test/Case/Controller/CalendarPlans/AddTest.php index 9e364e7..fc23db1 100644 --- a/Test/Case/Controller/CalendarPlans/AddTest.php +++ b/Test/Case/Controller/CalendarPlans/AddTest.php @@ -151,6 +151,10 @@ private function __getData($originEventId = '0') { 'contact' => '', 'description' => '', 'timezone_offset' => 'Asia/Tokyo', + 'target_person_grade' => '学年', + 'target_person_class_room' => 'クラス', + 'belongings' => '持ち物', + ), 'WorkflowComment' => array( 'comment' => 'WorkflowComment save test' diff --git a/Test/Case/Controller/CalendarPlans/ViewTest.php b/Test/Case/Controller/CalendarPlans/ViewTest.php index 85d584c..6766630 100644 --- a/Test/Case/Controller/CalendarPlans/ViewTest.php +++ b/Test/Case/Controller/CalendarPlans/ViewTest.php @@ -47,6 +47,8 @@ class CalendarPlansControllerViewTest extends WorkflowControllerViewTest { 'plugin.rooms.room_role_permission4test', //test 'plugin.calendars.plugins_role4test', //add 'plugin.calendars.room4test', + + 'plugin.calendars.blog4test', ); /** diff --git a/Test/Case/Model/CalendarActionPlan/SaveCalendarPlanTest.php b/Test/Case/Model/CalendarActionPlan/SaveCalendarPlanTest.php index 84e47ab..fe92723 100644 --- a/Test/Case/Model/CalendarActionPlan/SaveCalendarPlanTest.php +++ b/Test/Case/Model/CalendarActionPlan/SaveCalendarPlanTest.php @@ -143,6 +143,10 @@ private function __getData($blockKey = 'block_1') { 'contact' => '', 'description' => '', 'timezone_offset' => 'Asia/Tokyo', + 'target_person_grade' => '学年', + 'target_person_class_room' => 'クラス', + 'belongings' => '持ち物', + ), 'CalendarActionPlanForDisp' => array( 'detail_start_datetime' => '2016-07-28 11:00', diff --git a/Test/Fixture/Blog4testFixture.php b/Test/Fixture/Blog4testFixture.php new file mode 100644 index 0000000..2a7d629 --- /dev/null +++ b/Test/Fixture/Blog4testFixture.php @@ -0,0 +1,71 @@ + + * @author Ryuji AMANO + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +/** + * Summary for BlogFixture + */ +class Blog4testFixture extends CakeTestFixture { + +/** + * Model name + * + * @var string + */ + public $name = 'Blog'; + +/** + * Full Table Name + * + * @var string + */ + public $table = 'blogs'; + +/** + * Records + * + * @see https://github.com/s-nakajima/MyShell/blob/master/unitTest/AboutFixture.md#ブロックidの紐付くfixture + * @var array + */ + public $records = array( + array( + 'id' => 2, + 'block_id' => '2', + 'name' => 'BlockId2Blog', + 'key' => 'content_block_1', + 'created_user' => 1, + 'created' => '2016-03-17 07:09:43', + 'modified_user' => 1, + 'modified' => '2016-03-17 07:09:43' + ), + array( + 'id' => 4, + 'block_id' => 4, + 'name' => 'Lorem ipsum dolor sit amet', + 'key' => 'content_block_2', + 'created_user' => 2, + 'created' => '2016-03-17 07:09:43', + 'modified_user' => 2, + 'modified' => '2016-03-17 07:09:43' + ), + ); + +/** + * Initialize the fixture. + * + * @return void + */ + public function init() { + require_once App::pluginPath('Blogs') . 'Config' . DS . 'Schema' . DS . 'schema.php'; + $this->fields = (new BlogsSchema())->tables[Inflector::tableize($this->name)]; + parent::init(); + } + +} diff --git a/Test/Fixture/CalendarEventFixture.php b/Test/Fixture/CalendarEventFixture.php index afe558d..e1b5dff 100644 --- a/Test/Fixture/CalendarEventFixture.php +++ b/Test/Fixture/CalendarEventFixture.php @@ -31,6 +31,11 @@ class CalendarEventFixture extends CakeTestFixture { 'title' => 'calendarplan1', 'title_icon' => '/net_commons/img/title_icon/10_010_new.svg', 'location' => 'Lorem ipsum dolor sit amet', + + 'target_person_grade' => '学年', + 'target_person_class_room' => 'クラス', + 'belongings' => '持ち物', + 'contact' => 'Lorem ipsum dolor sit amet', 'description' => 'testdescription', 'is_allday' => true, diff --git a/Utility/CalendarSupport.php b/Utility/CalendarSupport.php index 3956ef2..678a9fa 100644 --- a/Utility/CalendarSupport.php +++ b/Utility/CalendarSupport.php @@ -281,6 +281,9 @@ public function getInitialCalendarActionPlanForView($year, $month, $day, 'edit_rrule' => 0, 'title' => '', 'title_icon' => '', + 'target_person_grade' => '', + 'target_person_class_room' => '', + 'belongings' => '', 'enable_time' => $enableTime, //YYYY-MM-DD hh:mm 'detail_start_datetime' => @@ -412,6 +415,10 @@ private function __makeCapForViewSubset($event, $userStartDatetime, $userEndDate 'edit_rrule' => 0, //tableにはない項目なのでinitと同じ値 'title' => $event['CalendarEvent']['title'], 'title_icon' => $event['CalendarEvent']['title_icon'], + 'target_person_grade' => $event['CalendarEvent']['target_person_grade'], + 'target_person_class_room' => $event['CalendarEvent']['target_person_class_room'], + 'belongings' => $event['CalendarEvent']['belongings'], + 'enable_time' => ($event['CalendarEvent']['is_allday']) ? 0 : 1, 'easy_start_date' => substr($userStartDatetime, 0, 10), //YYYY-MM-DD 'easy_hour_minute_from' => substr($userStartDatetime, 11, 5), //hh:mm diff --git a/View/CalendarPlans/detail_edit.ctp b/View/CalendarPlans/detail_edit.ctp index 1fecd5a..84d4d7c 100644 --- a/View/CalendarPlans/detail_edit.ctp +++ b/View/CalendarPlans/detail_edit.ctp @@ -130,6 +130,49 @@ $jsParameters = array( + +
+
+ NetCommonsForm->input('CalendarActionPlan.location', array( + 'type' => 'text', + 'label' => __d('calendars', 'Location'), + 'div' => false, + )); ?> +
+
+ + +
+
+ NetCommonsForm->label(null, __d('calendars', 'Target Person'));?> +
+ NetCommonsForm->input('CalendarActionPlan.target_person_grade', [ + 'label' => false, + 'placeholder' => __d('calendars', 'Grade'), + 'div' => [ + 'class' => 'col-xs-6' + ] + ]);?> + NetCommonsForm->input('CalendarActionPlan.target_person_class_room', [ + 'label' => false, + 'placeholder' => __d('calendars', 'Class room'), + 'div' => [ + 'class' => 'col-xs-6' + ] + ]);?> +
+
+
+ +
+ NetCommonsForm->input('CalendarActionPlan.belongings', [ + 'label' => __d('calendars', 'Belongings'), + 'div' => [ + 'class' => 'col-xs-12' + ] + ]);?> +
+
diff --git a/View/CalendarPlans/view.ctp b/View/CalendarPlans/view.ctp index 44fb8b4..6f6026c 100644 --- a/View/CalendarPlans/view.ctp +++ b/View/CalendarPlans/view.ctp @@ -8,6 +8,7 @@ * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project */ + echo $this->element('Calendars.scripts'); ?> @@ -37,6 +38,12 @@ echo $this->element('Calendars.scripts');
CalendarButton->getEditButton($vars, $event);?> + + CalendarRelatedBlog->addAchievementButton($event); + ?> + +
@@ -79,11 +86,32 @@ echo $this->element('Calendars.scripts');
- -
-

-

CalendarCategory->getCategoryName($vars, $event); ?>

-
+ +
+

+

+
+ + + + +
+

+

+ +

+
+ + + + +
+

+

+ +

+
+ CalendarShareUsers->isShareEvent($event)): ?> @@ -93,13 +121,6 @@ echo $this->element('Calendars.scripts');
- -
-

-

-
- -

@@ -115,6 +136,7 @@ echo $this->element('Calendars.scripts');
+

DisplayUser->handleLink($event, array('avatar' => true)); ?>

@@ -131,6 +153,7 @@ echo $this->element('Calendars.scripts');

CalendarLink->getSourceLink($vars, $event); ?>

+ diff --git a/View/Elements/CalendarPlans/detail_edit_etc_details.ctp b/View/Elements/CalendarPlans/detail_edit_etc_details.ctp index 872fa8a..5cfb44d 100644 --- a/View/Elements/CalendarPlans/detail_edit_etc_details.ctp +++ b/View/Elements/CalendarPlans/detail_edit_etc_details.ctp @@ -17,16 +17,6 @@ - -
-
- NetCommonsForm->input('CalendarActionPlan.location', array( - 'type' => 'text', - 'label' => __d('calendars', 'Location'), - 'div' => false, - )); ?> -
-
diff --git a/View/Helper/CalendarButtonHelper.php b/View/Helper/CalendarButtonHelper.php index 1dfa745..991b97b 100644 --- a/View/Helper/CalendarButtonHelper.php +++ b/View/Helper/CalendarButtonHelper.php @@ -208,6 +208,7 @@ public function getEditButton($vars, $event) { 'day' => $vars['day'], ) )); + return $html; } diff --git a/View/Helper/CalendarExposeTargetHelper.php b/View/Helper/CalendarExposeTargetHelper.php index 4dbce24..818a0d6 100644 --- a/View/Helper/CalendarExposeTargetHelper.php +++ b/View/Helper/CalendarExposeTargetHelper.php @@ -79,40 +79,43 @@ public function makeSelectExposeTargetHtml($event, $frameId, $vars, $options, $m } } // 渡されたoptionから投稿権限のないものを外す - $rooms = CalendarPermissiveRooms::getCreatableRoomIdList(); - $targetRooms = array_intersect_key($options, $rooms); - - $html = $this->NetCommonsForm->label( - 'CalendarActionPlan.plan_room_id' . Inflector::camelize('room_id'), - __d('calendars', 'Category') . $this->_View->element('NetCommons.required')); - - // 発行権限がなくて、かつ、すでに発行済みデータの場合は空間変更を認めない - // 固定的な文字列と、hiddenを設定して返す - if (isset($event['CalendarEvent']['is_published']) && - $event['CalendarEvent']['is_published'] && - !$this->CalendarWorkflow->canDelete($event)) { - $html .= '
'; - $html .= $this->CalendarCategory->getCategoryName($vars, $event); - $html .= ''; - $html .= __d('calendars', 'You can not change the target space after published.'); - $html .= ''; - $html .= $this->NetCommonsForm->hidden('CalendarActionPlan.plan_room_id'); - $html .= '
'; - } else { - $html .= $this->NetCommonsForm->select('CalendarActionPlan.plan_room_id', $targetRooms, array( - //select-expose-targetクラスをもつ要素のchangeをjqで捕まえています - 'class' => 'form-control select-expose-target', - 'empty' => false, - 'required' => true, - //value値のoption要素がselectedになる。 - 'value' => $this->request->data['CalendarActionPlan']['plan_room_id'], - 'data-frame-id' => $frameId, - 'data-myself' => $myself, - 'escape' => false, - 'ng-model' => 'data.planRoomId' - )); - } + //$rooms = CalendarPermissiveRooms::getCreatableRoomIdList(); + //$targetRooms = array_intersect_key($options, $rooms); + $html = $this->NetCommonsForm->hidden('CalendarActionPlan.plan_room_id'); return $html; + // + //$html = $this->NetCommonsForm->label( + // 'CalendarActionPlan.plan_room_id' . Inflector::camelize('room_id'), + // __d('calendars', 'Category') . $this->_View->element('NetCommons.required')); + // + //// 発行権限がなくて、かつ、すでに発行済みデータの場合は空間変更を認めない + //// 固定的な文字列と、hiddenを設定して返す + //if (isset($event['CalendarEvent']['is_published']) && + // $event['CalendarEvent']['is_published'] && + // !$this->CalendarWorkflow->canDelete($event)) { + // $html .= '
'; + // $html .= $this->CalendarCategory->getCategoryName($vars, $event); + // $html .= ''; + // $html .= __d('calendars', 'You can not change the target space after published.'); + // $html .= ''; + // $html .= $this->NetCommonsForm->hidden('CalendarActionPlan.plan_room_id'); + // $html .= '
'; + //} else { + // $html .= $this->NetCommonsForm->select('CalendarActionPlan.plan_room_id', $targetRooms, array( + // //select-expose-targetクラスをもつ要素のchangeをjqで捕まえています + // 'class' => 'form-control select-expose-target', + // 'empty' => false, + // 'required' => true, + // //value値のoption要素がselectedになる。 + // 'value' => $this->request->data['CalendarActionPlan']['plan_room_id'], + // 'data-frame-id' => $frameId, + // 'data-myself' => $myself, + // 'escape' => false, + // 'ng-model' => 'data.planRoomId' + // )); + //} + // + //return $html; } } diff --git a/View/Helper/CalendarRelatedBlogHelper.php b/View/Helper/CalendarRelatedBlogHelper.php new file mode 100644 index 0000000..d5e9b76 --- /dev/null +++ b/View/Helper/CalendarRelatedBlogHelper.php @@ -0,0 +1,90 @@ +__findRelatedBlogBlockId(); + $blogFrameId = $this->__findRelatedBlogFrameIdByBlockId($blogBlockId); + if (!$blogFrameId) { + return ''; + } + + $roomId = $event['CalendarEvent']['room_id']; + $canEdit = CalendarPermissiveRooms::isEditable($roomId); + $canCreate = CalendarPermissiveRooms::isCreatable($roomId); + // 表示ルームにおける自分の権限がeditable以上なら無条件に編集可能 + // creatable のとき=自分が作ったデータならOK + if ($canEdit || + ($canCreate && $event['CalendarEvent']['created_user'] == Current::read('User.id'))) { + if ($blogBlockId !== null) { + // 実績の追加ボタン + return $this->LinkButton->add(__d('calendars', 'Add Achievement'), array( + 'plugin' => 'blogs', + 'controller' => 'blog_entries_edit', + 'action' => 'add', + 'block_id' => $blogBlockId, + //'frame_id' => $blogFrameId, + '?' => [ + 'page_id' => Current::read('Page.id'), + 'event_key' => $event['CalendarEvent']['key'] + ] + )); + } + } + return ''; + } + +/** + * __findRelatedBlogBlockId + * + * @return int|null + */ + private function __findRelatedBlogBlockId() { + $blogModel = ClassRegistry::init('Blogs.Blog'); + + Configure::load('Calendars.related_blog'); + + $blogKey = Configure::read('Calendars.relatedBlog.key'); + /** @var Blog $blogModel */ + $blogBlockId = null; + if ($blogKey) { + $blogBlockId = $blogModel->findBlockIdByKey($blogKey); + } + return $blogBlockId; + } + + private function __findRelatedBlogFrameIdByBlockId($blockId) { + $frameModel = ClassRegistry::init('Frames.Frame'); + $result = $frameModel->find('first', [ + 'conditions' => [ + 'Frame.block_id' => $blockId + ], + 'fields' => ['Frame.id'], + 'recursive' => -1, + ]); + if ($result) { + return $result['Frame']['id']; + } + return false; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index e5ccdc9..2d75491 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,8 @@ "netcommons/topics": "@dev", "netcommons/users": "@dev", "netcommons/workflow": "@dev", - "netcommons/wysiwyg": "@dev" + "netcommons/wysiwyg": "@dev", + "netcommons/blogs": "dev-nc3forEducation" }, "type": "cakephp-plugin", "keywords": [