-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCircularNoticeComponent.php
More file actions
309 lines (277 loc) · 7.64 KB
/
CircularNoticeComponent.php
File metadata and controls
309 lines (277 loc) · 7.64 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
309
<?php
/**
* CircularNotice Component
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Hirohisa Kuwata <Kuwata.Hirohisa@withone.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('Component', 'Controller');
App::uses('WorkflowComponent', 'Workflow.Controller/Component');
App::uses('WorkflowBehavior', 'Workflow.Model/Behavior');
/**
* CircularNotice Component
*
* @author Hirohisa Kuwata <Kuwata.Hirohisa@withone.co.jp>
* @package NetCommons\CircularNotices\Controller\Component
* @property User $User
*/
class CircularNoticeComponent extends Component {
/**
* view status published
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_PUBLISHED = WorkflowComponent::STATUS_PUBLISHED;
/**
* view in draft status
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_IN_DRAFT = WorkflowComponent::STATUS_IN_DRAFT;
/**
* view status reserved
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_RESERVED = '5';
/**
* view status open
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_OPEN = '6';
/**
* view status fixed
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_FIXED = '7';
/**
* view status closed
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_CLOSED = '8';
/**
* view status unread
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_UNREAD = '10';
/**
* view status read yet
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_READ_YET = '11';
/**
* view status replied
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_REPLIED = '12';
/**
* view status not replied
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_STATUS_NOT_REPLIED = '13';
/**
* reply by text
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_REPLY_TYPE_TEXT = '1';
/**
* reply by selection
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_REPLY_TYPE_SELECTION = '2';
/**
* reply by multiple selection
*
* @var string
*/
const CIRCULAR_NOTICE_CONTENT_REPLY_TYPE_MULTIPLE_SELECTION = '3';
/**
* reply selection values delimiter
*
* @var string
*/
const SELECTION_VALUES_DELIMITER = '|';
/**
* export target users file extension
*
* @var string
*/
const EXPORT_FILE_EXTENSION = '.csv';
/**
* export target users compress file extension
*
* @var string
*/
const EXPORT_COMPRESS_FILE_EXTENSION = '.zip';
/**
* Initialize circular notices
*
* @param Controller $controller コントローラー
* @return bool
*/
public function initCircularNotice(Controller $controller) {
$this->controller = $controller;
$userId = Current::read('User.id');
if (! $userId) {
if ($this->controller->action === 'index') {
$this->controller->setAction('emptyRender');
} else {
$this->controller->redirect(NetCommonsUrl::backToPageUrl());
}
return false;
}
$this->controller->CircularNoticeSetting =
ClassRegistry::init('CircularNotices.CircularNoticeSetting');
$this->controller->CircularNoticeFrameSetting =
ClassRegistry::init('CircularNotices.CircularNoticeFrameSetting');
$frameId = Current::read('Frame.id');
$setting = $this->controller->CircularNoticeSetting->getCircularNoticeSetting($frameId);
if (! $setting) {
if ($this->controller->action === 'index') {
$this->controller->setAction('emptyRender');
} else {
$this->controller->redirect(NetCommonsUrl::backToPageUrl());
}
return false;
}
$this->controller->set('circularNoticeSetting', $setting);
$frameKey = Current::read('Frame.key');
$frameSetting =
$this->controller->CircularNoticeFrameSetting->getCircularNoticeFrameSetting($frameKey);
if (! $frameSetting) {
if ($this->controller->action === 'index') {
$this->controller->setAction('emptyRender');
} else {
$this->controller->redirect(NetCommonsUrl::backToPageUrl());
}
return false;
}
$this->controller->set('circularNoticeFrameSetting', $frameSetting);
// 一般権限で回覧登録を行えるようにするため、ステータス定義をオーバーライド
WorkflowBehavior::$statusesForEditor
= array(CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_PUBLISHED,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_IN_DRAFT,
);
return true;
}
/**
* 回覧先のヘッダ項目を取得
*
* @return array
*/
public function getTargetUserHeader() {
return array(
h(__d('circular_notices', 'Target User')),
h(__d('circular_notices', 'Read Datetime')),
h(__d('circular_notices', 'Reply Datetime')),
h(__d('circular_notices', 'Answer'))
);
}
/**
* 表示用日付フォーマットを取得
*
* @param string $dateTime date time
* @return array
*/
public function getDisplayDateFormat($dateTime) {
App::import('Helper', 'NetCommons.Date');
$dateHelper = new DateHelper(new View());
return $dateHelper->dateFormat($dateTime);
}
/**
* 選択済みユーザを設定
*
* @param array $targetUsers 対象ユーザ情報
* @return array
*/
public function getSelectUsers($targetUsers) {
$users = [];
if (! empty($targetUsers)) {
$userIdArr = [];
foreach ($targetUsers as $targetUser) {
$userIdArr[] = $targetUser['user_id'];
}
// 不要なイベントを発生させないためにBehaviorを除去
$this->controller->User->Behaviors->unload('Files.Attachment');
$users = $this->controller->User->find('all', [
'recursive' => -1,
'fields' => ['User.id', 'User.handlename'],
'conditions' => [
$this->controller->User->alias . '.id' => $userIdArr
],
]);
}
return $users;
}
/**
* エラー内容を保持
*
* @param Controller $controller コントローラー
* @return void
*/
public function setCircularNoticeErrors(Controller $controller) {
if ($controller->Session->read('circularNoticeErrors')) {
foreach ($controller->Session->read('circularNoticeErrors') as $model => $errors) {
if (! $controller->$model) {
$controller->loadModel($model);
}
$controller->$model->validationErrors = $errors;
}
$controller->Session->delete('circularNoticeErrors');
}
}
/**
* データを保持
*
* @param Controller $controller コントローラー
* @return void
*/
public function setCircularNoticeDatas(Controller $controller) {
if ($controller->Session->read('circularNoticeDatas')) {
$controller->set('circularNoticeDatas', $controller->Session->read('circularNoticeDatas'));
$controller->Session->delete('circularNoticeDatas');
}
}
/**
* コンテンツステータスの選択値存在チェック
*
* @param string $checkValue チェック対象値
* @return bool チェック結果(true:存在する, false:存在しない)
*/
public function existsContentStatus($checkValue) {
$contentStatusArr = array(
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_PUBLISHED,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_IN_DRAFT,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_RESERVED,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_OPEN,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_FIXED,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_CLOSED,
);
return in_array($checkValue, $contentStatusArr, true);
}
/**
* 回答状況の選択値存在チェック
*
* @param string $checkValue チェック対象値
* @return bool チェック結果(true:存在する, false:存在しない)
*/
public function existsReplyStatus($checkValue) {
$contentStatusArr = array(
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_REPLIED,
CircularNoticeComponent::CIRCULAR_NOTICE_CONTENT_STATUS_NOT_REPLIED,
);
return in_array($checkValue, $contentStatusArr, true);
}
}