diff --git a/Controller/TaskContentEditController.php b/Controller/TaskContentEditController.php index dd15f9c..07b16bf 100644 --- a/Controller/TaskContentEditController.php +++ b/Controller/TaskContentEditController.php @@ -149,6 +149,8 @@ public function edit() { $key = $this->params['key']; $taskContent = $this->TaskContent->getTask($key); + $calendarKey = $taskContent['TaskContent']['calendar_key']; //ADD カレンダ連携キーの取り出し + $taskContent['TaskContent']['use_calendar'] = ($calendarKey == "") ? 0 : 1; if (! $this->request->data) { $this->request->data = $taskContent; } @@ -172,6 +174,8 @@ public function edit() { $this->_taskSetting['TaskSetting']['task_key']; $this->request->data['TaskContent']['key'] = $key; + $this->request->data['TaskContent']['calendar_key'] = $calendarKey; //ADD カレンダー連携キー転写 + // set status $status = $this->Workflow->parseStatus(); $this->request->data['TaskContent']['status'] = $status; diff --git a/Locale/eng/LC_MESSAGES/tasks.po b/Locale/eng/LC_MESSAGES/tasks.po index 6f886a8..45a79ff 100644 --- a/Locale/eng/LC_MESSAGES/tasks.po +++ b/Locale/eng/LC_MESSAGES/tasks.po @@ -242,6 +242,14 @@ msgstr "Progress rate: " msgid "Person in charge" msgstr "Person in charge: " +#: Tasks/View/TaskContents/view.ctp:50 +msgid "Calendar registered" +msgstr "Calendar registered" + +#: Tasks/View/TaskContents/view.ctp:54 +msgid "Calendar not registered" +msgstr "Calendar not registered" + #: Tasks/View/TaskMailSettings/edit.ctp:22 msgid "MailSetting.mail_fixed_phrase_body.popover" msgstr "" diff --git a/Locale/jpn/LC_MESSAGES/tasks.po b/Locale/jpn/LC_MESSAGES/tasks.po index a6e53d4..1ec5c8d 100644 --- a/Locale/jpn/LC_MESSAGES/tasks.po +++ b/Locale/jpn/LC_MESSAGES/tasks.po @@ -294,6 +294,16 @@ msgstr "進捗率:" msgid "Person in charge" msgstr "担当者:" +# 詳細画面で使用 +#: Tasks/View/TaskContents/view.ctp:50 +msgid "Calendar registered" +msgstr "カレンダー登録済み" + +# 詳細画面で使用 +#: Tasks/View/TaskContents/view.ctp:54 +msgid "Calendar not registered" +msgstr "カレンダー未登録" + # 投稿メール基本文で使用 #: Tasks/View/TaskMailSettings/edit.ctp:22 msgid "MailSetting.mail_fixed_phrase_body.popover" diff --git a/Locale/tasks.pot b/Locale/tasks.pot index b1c5c7a..6374cf2 100644 --- a/Locale/tasks.pot +++ b/Locale/tasks.pot @@ -242,6 +242,14 @@ msgstr "" msgid "Person in charge" msgstr "" +#: Tasks/View/TaskContents/view.ctp:50 +msgid "Calendar registered" +msgstr "" + +#: Tasks/View/TaskContents/view.ctp:54 +msgid "Calendar not registered" +msgstr "" + #: Tasks/View/TaskMailSettings/edit.ctp:22 msgid "MailSetting.mail_fixed_phrase_body.popover" msgstr "" diff --git a/Model/TaskContent.php b/Model/TaskContent.php index 59692cc..09f4552 100644 --- a/Model/TaskContent.php +++ b/Model/TaskContent.php @@ -11,6 +11,8 @@ App::uses('TasksAppModel', 'Tasks.Model'); App::uses('MailQueueBehavior', 'Mails.Model/Behavior'); +App::uses('CalendarActionPlan', 'Calendars.Model'); //ADD +App::uses('CalendarDeleteActionPlan', 'Calendars.Model'); //ADD /** * Summary for TaskContent Model @@ -647,6 +649,93 @@ public function saveContent($data) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + //カレンダー連携ここから ADD + $cmd = 'del'; + if ($data['TaskContent']['is_date_set']) { + $cmd =($data['TaskContent']['use_calendar']) ? 'save' : 'del'; + } + if ($cmd==='save') { + //実施期間設定あり&&カレンダー登録する + $this->loadModels([ + 'CalendarActionPlan' => 'Calendars.CalendarActionPlan', + ]); + + //登録・変更用settings指定付きでbehaviorロード + $this->CalendarActionPlan->Behaviors->load('Calendars.CalendarLink', array( + 'linkPlugin' => Current::read('Plugin.key'), + 'table' => $this->alias, //fieldsの対象テーブル + 'inputFields' => array( + 'title' => 'title', + 'description' => 'content', + ), + 'sysFields' => array( + 'key' => 'key', //tasksの場合、task_contentsテーブルのkey + 'calendar_key' => 'calendar_key', //tasksの場合、task_contentsテーブルのcalendar_key + ), + 'startendFields' => array( + 'start_datetime' => 'task_start_date', + 'end_datetime' => 'task_end_date', + ), + 'isServerTime' => true, + 'useStartendComplete' => true, + 'isLessthanOfEnd' => false, + 'isRepeat' => false, + 'isPlanRoomId' => false, + )); + + $calendarKey = $this->CalendarActionPlan->savePlanForLink($data); + if (is_string($calendarKey) && ! empty($calendarKey)) { + //カレンダ登録成功 + //calenar_keyを TaskContentにsave(update)しておく。 + $data['TaskContent']['calendar_key'] = $calendarKey; + $savedData = $this->save($data, false); + if ($savedData === false) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + $data['TaskContent'] = $savedData['TaskContent']; + } elseif ($calendarKey === '') { + //未承認や一時保存はカレンダー登録条件を満たさないのでスルー(通常) + } else { //false + //カレンダー登録時にエラー発生(エラー) + //例外なげる + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + $this->CalendarActionPlan->Behaviors->unload('Calendars.CalendarLink'); + } else { //cmd===del + if (! empty($data['TaskContent']['calendar_key'])) { + //calendar_keyが記録されているので、消しにいく。 + $this->loadModels([ + 'CalendarDeleteActionPlan' => 'Calendars.CalendarDeleteActionPlan', + ]); + //削除用settings指定 + $this->CalendarDeleteActionPlan->Behaviors->load('Calendars.CalendarLink', array( + 'linkPlugin' => Current::read('Plugin.key'), + 'table' => $this->alias, //fieldsの対象テーブル + 'sysFields' => array( + 'key' => 'key', //tasksの場合、task_contentsテーブルのkey + 'calendar_key' => 'calendar_key', //tasksの場合、task_contentsテーブルのcalendar_key + ), + 'isDelRepeat' => false, //tasksはfalse固定 + )); + $delCalendarKey = $this->CalendarDeleteActionPlan->deletePlanForLink($data); +// if ($data['TaskContent']['calendar_key'] == $delCalendarKey) { + //削除が成功したので、calenar_keyをクリアし、use_calendarをOFFにして、 + //TaskContentにsave(update)しておく。 + $data['TaskContent']['calendar_key'] = ''; + $data['TaskContent']['use_calendar'] = 0; + $savedData = $this->save($data, false); + if ($savedData === false) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } + $data['TaskContent'] = $savedData['TaskContent']; +// } + $this->CalendarDeleteActionPlan->Behaviors->unload('Calendars.CalendarLink'); + } else { + //calendar_keyが記録されていないので、なにもしない + } + } + //カレンダー連携ここまで ADD + //多言語化の処理 $this->set($savedData); $this->saveM17nData(); @@ -770,6 +859,33 @@ public function deleteContentByKey($key) { ) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } + + //カレンダー連携ここから ADD + $this->loadModels([ + 'CalendarDeleteActionPlan' => 'Calendars.CalendarDeleteActionPlan', + ]); + //削除用settings指定 + $this->CalendarDeleteActionPlan->Behaviors->load('Calendars.CalendarLink', array( + 'linkPlugin' => Current::read('Plugin.key'), + 'table' => $this->alias, //fieldsの対象テーブル + 'sysFields' => array( + 'key' => 'key', //tasksの場合、task_contentsテーブルのkey + 'calendar_key' => 'calendar_key', //tasksの場合、task_contentsテーブルのcalendar_key + ), + 'isDelRepeat' => false, //tasksはfalse固定 + )); + $datas = $this->find('all', array( + 'recursive' => -1, + 'conditions' => array( + 'TaskContent.key' => $key, + ) + )); + foreach ($datas as $data) { + $this->CalendarDeleteActionPlan->deletePlanForLink($data); + } + $this->CalendarDeleteActionPlan->Behaviors->unload('Calendars.CalendarLink'); + //カレンダー連携ここまで ADD + if (! $this->deleteAll(array($this->alias . '.key' => $key), false, true)) { throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); } diff --git a/View/Elements/TaskContentEdit/task_period_edit_form.ctp b/View/Elements/TaskContentEdit/task_period_edit_form.ctp index 1b91b5f..bc9ee61 100644 --- a/View/Elements/TaskContentEdit/task_period_edit_form.ctp +++ b/View/Elements/TaskContentEdit/task_period_edit_form.ctp @@ -83,5 +83,25 @@ } ?> + + NetCommonsForm->checkbox('TaskContent.use_calendar', array( + 'class' => 'text-left pull-left', + )); + ?> + NetCommonsForm->label( + 'TaskContent.use_calendar', + __d('tasks', 'Use calendar') + ); + ?> + NetCommonsForm->error('TaskContent.use_calendar'); + //ADD + ?> diff --git a/View/TaskContents/view.ctp b/View/TaskContents/view.ctp index a6750d2..a2b568f 100644 --- a/View/TaskContents/view.ctp +++ b/View/TaskContents/view.ctp @@ -45,6 +45,16 @@ echo $this->NetCommonsHtml->css('/tasks/css/tasks.css'); ); ?> + +
+ +
+ +
+ +
+ +