-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskContentEditController.php
More file actions
308 lines (267 loc) · 8.12 KB
/
TaskContentEditController.php
File metadata and controls
308 lines (267 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
/**
* TaskContentEdit Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Yuto Kitatsuji <kitatsuji.yuto@wihtone.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('TasksAppController', 'Tasks.Controller');
/**
* TaskContentEdit Controller
*
* @author Yuto Kitatsuji <kitatsuji.yuto@wihtone.co.jp>
* @package NetCommons\Tasks\Controller
* @property TaskContent $TaskContent
* @property TaskCharge $TaskCharge
* @property MailSetting $MailSetting
* @property NetCommonsTime $NetCommonsTime
*/
class TaskContentEditController extends TasksAppController {
/**
* use models
*
* @var array
*/
public $uses = array(
'Tasks.TaskContent',
'Tasks.TaskCharge',
'Mails.MailSetting',
);
/**
* use components
*
* @var array
*/
public $components = array(
'NetCommons.Permission' => array(
//アクセスの権限
'allow' => array(
'add,edit,delete' => 'content_creatable',
),
),
'Categories.Categories',
'NetCommons.NetCommonsTime',
);
/**
* beforeFilters
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
}
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Workflow.Workflow',
'NetCommons.NetCommonsForm',
'Categories.Category',
'Users.DisplayUser',
'Users.UserSearch',
'Groups.GroupUserList',
);
/**
* index add
*
* @return void
*/
public function add() {
$this->_prepare();
$this->set('listTitle', $this->_taskTitle);
if ($this->request->is('post')) {
$data = $this->request->data;
$data['TaskContent']['task_key'] = $this->_taskSetting['TaskSetting']['task_key'];
// set status
$status = $this->Workflow->parseStatus();
$data['TaskContent']['status'] = $status;
// set block_id
$data['TaskContent']['block_id'] = Current::read('Block.id');
// set language_id
$data['TaskContent']['language_id'] = Current::read('Language.id');
// set task_end_date
$data = $this->__setTaskDate($data);
if (! $data['TaskContent']['is_enable_mail']) {
unset($data['TaskContent']['email_send_timing']);
} else {
$data['is_reminder'] = true;
}
if (($result = $this->TaskContent->saveContent($data))) {
$url = NetCommonsUrl::actionUrl(array(
'controller' => 'task_contents',
'action' => 'view',
'frame_id' => Current::read('Frame.id'),
'block_id' => Current::read('Block.id'),
'key' => $result['TaskContent']['key'],
'is_makeReminder' => $result['is_makeReminder']
));
return $this->redirect($url);
}
// ToDo担当者ユーザー保持
$this->request->data['selectUsers'] = $this->TaskCharge->getSelectUsers($data);
$this->NetCommons->handleValidationError($this->TaskContent->validationErrors);
} else {
$this->request->data += $this->TaskContent->create();
// ログインユーザの情報を設定
$this->request->data['TaskCharge'][] = [
'user_id' => Current::read('User.id'),
];
$this->request->data['selectUsers'][] = ['User' => [
'id' => Current::read('User.id'),
'handlename' => Current::read('User.handlename'),
]];
}
$this->request->data = $this->NetCommonsTime->toUserDatetimeArray(
$this->request->data,
array(
'TaskContent.task_start_date',
'TaskContent.task_end_date',
)
);
$mailSetting = $this->__getMailSetting();
$this->set('mailSetting', $mailSetting);
$this->view = 'edit';
}
/**
* index edit
*
* @return void
* @throws BadRequestException
*/
public function edit() {
$this->_prepare();
$this->set('listTitle', $this->_taskTitle);
$key = $this->params['key'];
$taskContent = $this->TaskContent->getTask($key);
if (empty($taskContent)) {
return $this->throwBadRequest();
}
//ADD カレンダ連携キーの取り出し
$calendarKey = $taskContent['TaskContent']['calendar_key'];
$taskContent['TaskContent']['use_calendar'] = ($calendarKey == "") ? 0 : 1;
if (! $this->request->data) {
$this->request->data = $taskContent;
}
// ToDo担当者ユーザー保持
$this->request->data['selectUsers'] = $this->TaskCharge->getSelectUsers($taskContent);
if ($this->TaskContent->canEditWorkflowContent($taskContent) === false) {
return $this->throwBadRequest();
}
$this->_prepare();
if ($this->request->is('put')) {
$this->TaskContent->create();
$this->request->data['TaskContent']['task_key'] =
$this->_taskSetting['TaskSetting']['task_key'];
$this->request->data['TaskContent']['key'] = $key;
//ADD カレンダー連携キー転写
$this->request->data['TaskContent']['calendar_key'] = $calendarKey;
// set status
$status = $this->Workflow->parseStatus();
$this->request->data['TaskContent']['status'] = $status;
// set block_id
$this->request->data['TaskContent']['block_id'] = Current::read('Block.id');
// set language_id
$this->request->data['TaskContent']['language_id'] = Current::read('Language.id');
$data = $this->request->data;
// set task_end_date
$data = $this->__setTaskDate($data);
if (! $data['TaskContent']['is_enable_mail']) {
unset($data['TaskContent']['email_send_timing']);
} else {
$data['is_reminder'] = true;
}
unset($data['TaskContent']['id']); // 常に新規保存
if ($result = $this->TaskContent->saveContent($data)) {
$url = NetCommonsUrl::actionUrl(
array(
'controller' => 'task_contents',
'action' => 'view',
'frame_id' => Current::read('Frame.id'),
'block_id' => Current::read('Block.id'),
'key' => $data['TaskContent']['key'],
'is_makeReminder' => $result['is_makeReminder']
)
);
return $this->redirect($url);
}
$this->NetCommons->handleValidationError($this->TaskContent->validationErrors);
}
$this->request->data = $this->NetCommonsTime->toUserDatetimeArray(
$this->request->data,
array(
'TaskContent.task_start_date',
'TaskContent.task_end_date',
));
$mailSetting = $this->__getMailSetting();
$this->set('taskContent', $taskContent);
$this->set('mailSetting', $mailSetting);
$this->set('isDeletable', $this->TaskContent->canDeleteWorkflowContent($taskContent));
$comments = $this->TaskContent->getCommentsByContentKey($taskContent['TaskContent']['key']);
$this->set('comments', $comments);
}
/**
* delete method
*
* @throws InternalErrorException
* @return void
*/
public function delete() {
$this->request->allowMethod('post', 'delete');
$key = $this->request->data['TaskContent']['key'];
$taskContent = $this->TaskContent->findByKeyAndIsLatest($key, 1);
// 権限チェック
if ($this->TaskContent->canDeleteWorkflowContent($taskContent) === false) {
return $this->throwBadRequest();
}
if ($this->TaskContent->deleteContentByKey($key) === false) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
$this->redirect(NetCommonsUrl::backToPageUrl());
}
/**
* Get Mail Setting
*
* メール設定情報の取得
*
* @return array メール設定情報の配列
*/
private function __getMailSetting() {
$mailSetting = $this->MailSetting->find('first', array(
'conditions' => array(
$this->MailSetting->alias . '.plugin_key' => 'tasks',
$this->MailSetting->alias . '.block_key' => Current::read('Block.key'),
),
'recursive' => -1,
)
);
return $mailSetting;
}
/**
* Set Task Date
*
* 実施日設定が選択されていない場合実施日を初期化する
* 実施日設定が選択されており実施終了日が設定されている場合ToDoの実施日終了日の時刻を23:59:59に設定する
*
* @param array $data POSTされたToDoデータ
* @return array
*/
private function __setTaskDate($data) {
if ($data['TaskContent']['is_date_set'] && $data['TaskContent']['task_end_date']) {
$endDate = $data['TaskContent']['task_end_date'];
if ($endDate) {
$data['TaskContent']['task_end_date'] = date(
'Y-m-d H:i:s', strtotime($endDate . '+1 days -1 second')
);
}
} elseif (! $data['TaskContent']['is_date_set']) {
$data['TaskContent']['task_start_date'] = null;
$data['TaskContent']['task_end_date'] = null;
}
return $data;
}
}