-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskContent.php
More file actions
executable file
·829 lines (752 loc) · 23.2 KB
/
TaskContent.php
File metadata and controls
executable file
·829 lines (752 loc) · 23.2 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
<?php
/**
* TaskContent Model
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Yuto Kitatsuji <kitatsuji.yuto@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('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
*
* @property TaskCharge $TaskCharge
*
* 速度改善の修正に伴って発生したため抑制
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class TaskContent extends TasksAppModel {
/**
* @var int recursiveはデフォルトアソシエーションなしに
*/
public $recursive = -1;
/**
* @var array 進捗率のバリデーションルールinList用配列
*/
protected $_progressRates = array();
/**
* @var array カテゴリIDのバリデーションルールinList用配列
*/
protected $_categoryIds = array();
/**
* use behaviors
*
* @var array
*/
public $actsAs = array(
'NetCommons.Trackable',
'NetCommons.OriginalKey',
'Workflow.Workflow',
'Workflow.WorkflowComment',
'ContentComments.ContentComment',
'Topics.Topics' => array(
'fields' => array(
'title' => 'title',
'summary' => 'content',
'path' => '/:plugin_key/task_contents/view/:block_id/:content_key',
),
),
'Mails.MailQueue' => array(
'embedTags' => array(
'X-SUBJECT' => 'TaskContent.title',
'X-BODY' => 'TaskContent.content',
'X-URL' => array('controller' => 'task_contents'),
),
),
'Tasks.TaskCharge',
'Wysiwyg.Wysiwyg' => array(
'fields' => array('content'),
),
//多言語
'M17n.M17n' => array(
'commonFields' => array(
'category_id',
'priority',
'task_start_date',
'task_end_date',
'is_enable_mail',
'email_send_timing',
'use_calendar',
'is_completion',
'progress_rate'
),
'associations' => array(
'TaskCharge' => array(
'class' => 'Tasks.TaskCharge',
'foreignKey' => 'task_content_id',
),
),
'afterCallback' => false,
),
);
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Category' => array(
'className' => 'Categories.Category',
'foreignKey' => 'category_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'CategoryOrder' => array(
'className' => 'Categories.CategoryOrder',
'foreignKey' => false,
'conditions' => 'CategoryOrder.category_key=Category.key',
'fields' => '',
'order' => ''
),
'Block' => array(
'className' => 'Blocks.Block',
'foreignKey' => 'block_id',
'conditions' => '',
'fields' => '',
'order' => '',
'counterCache' => array(
'content_count' => array(
'TaskContent.is_origin' => true,
'TaskContent.is_latest' => true
),
),
),
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'TaskCharge' => array(
'className' => 'Tasks.TaskCharge',
'foreignKey' => 'task_content_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
);
/**
* Called before each find operation. Return false if you want to halt the find
* call, otherwise return the (modified) query data.
*
* @param array $query Data used to execute this query, i.e. conditions, order, etc.
* @return mixed true if the operation should continue, false if it should abort; or, modified
* $query to continue with new $query
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforefind
*/
public function beforeFind($query) {
$recursive = isset($query['recursive'])
? $query['recursive']
: null;
if ($recursive > -1 &&
! $this->id) {
$belongsTo = $this->Category->bindModelCategoryLang('TaskContent.category_id');
$this->bindModel($belongsTo, true);
}
return true;
}
/**
* バリデートメッセージ多言語化対応のためのラップ
*
* @param array $options options
* @return bool
*/
public function beforeValidate($options = array()) {
if ($options['only_progress']) {
$getValidate = $this->_getValidateOnlyProgress();
} else {
$getValidate = $this->_getValidateSpecification();
}
$this->validate = Hash::merge(
$this->validate, $getValidate
);
return parent::beforeValidate($options);
}
/**
* コンストラクタ
*
* @param bool|int|string|array $id Set this ID for this model on startup,
* can also be an array of options, see above.
* @param string $table Name of database table to use.
* @param string $ds DataSource connection name.
* @see Model::__construct()
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
for ($i = 0; $i <= TasksComponent::TASK_COMPLETION_PROGRESS_RATE;) {
$this->_progressRates[$i] = $i;
$i += TasksComponent::TASK_PROGRESS_RATE_INCREMENTS;
}
// 必要なモデル読み込み
$this->loadModels([
'Category' => 'Categories.Category',
]);
$conditions = array(
'Category.block_id' => Current::read('Block.id')
);
$categories = $this->Category->find('all', [
'recursive' => -1,
'fields' => ['Category.id'],
'conditions' => $conditions
]);
$this->_categoryIds = [];
foreach ($categories as $category) {
$this->_categoryIds[$category['Category']['id']] = $category['Category']['id'];
}
// カテゴリ未設定時の時にエラーとなるので0をinList条件に加える
$this->_categoryIds[0] = 0;
}
/**
* バリデーションルールを返す
*
* @return array
*/
protected function _getValidateSpecification() {
$validate = array(
'title' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => sprintf(__d('net_commons', 'Please input %s.'), __d('tasks', 'Title')),
'required' => true,
),
),
'category_id' => array(
'numeric' => array(
'rule' => array('inList', $this->_categoryIds),
'allowEmpty' => true,
'message' => __d('net_commons', 'Invalid request.')
),
),
'priority' => array(
'numeric' => array(
'rule' => array('inList', array(
TasksComponent::TASK_PRIORITY_UNDEFINED, TasksComponent::TASK_PRIORITY_LOW,
TasksComponent::TASK_PRIORITY_MEDIUM, TasksComponent::TASK_PRIORITY_HIGH
)),
'allowEmpty' => true,
'message' => __d('net_commons', 'Invalid request.')
),
),
'status' => array(
'numeric' => array(
'rule' => array('numeric'),
'message' => __d('net_commons', 'Invalid request.')
),
),
'is_enable_mail' => array(
'boolean' => array(
'rule' => array('boolean'),
'message' => __d('net_commons', 'Invalid request.')
),
),
'is_date_set' => array(
'boolean' => array(
'rule' => array('boolean'),
'message' => __d('net_commons', 'Invalid request.')
),
'isDateCheck' => array(
'rule' => array('validateIsDateCheck',
array('from' => $this->data['TaskContent']['task_start_date'],
'to' => $this->data['TaskContent']['task_end_date'])
),
'message' => __d('tasks', 'Please set the start date or end date.')
),
),
'use_calendar' => array(
'boolean' => array(
'rule' => array('boolean'),
'message' => __d('net_commons', 'Invalid request.')
),
),
'email_send_timing' => array(
'numeric' => array(
'rule' => array('numeric'),
'allowEmpty' => true,
'message' => __d('net_commons', 'Invalid request.')
),
'isSetReminderCheck' => array(
'rule' => array('validateIsSetReminderCheck',
array('to' => $this->data['TaskContent']['task_end_date'],
'is_enable_mail' => $this->data['TaskContent']['is_enable_mail']
)
),
'message' => __d('tasks', 'Please set the end date.')
),
),
'progress_rate' => array(
'numeric' => array(
'rule' => array('inList', $this->_progressRates),
'allowEmpty' => true,
'message' => __d('net_commons', 'Invalid request.')
),
),
);
$validate = $this->_getValidateTaskDate($validate);
return $validate;
}
/**
* 進捗率のみ更新時のバリデーションルールを返す
*
* @return array
*/
protected function _getValidateOnlyProgress() {
$validate = array(
'progress_rate' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => __d('net_commons', 'Invalid request.'),
),
'numeric' => array(
'rule' => array('inList', $this->_progressRates),
'allowEmpty' => true,
'message' => __d('net_commons', 'Invalid request.')
),
),
);
return $validate;
}
/**
* 実施日に関するバリデーションルールを返す
*
* @param array $validate validate
* @return array
*/
protected function _getValidateTaskDate($validate = array()) {
if ($this->data['TaskContent']['task_start_date']) {
$validate = array_merge($validate, array(
'task_start_date' => array(
'datetime' => array(
'rule' => array('datetime'),
'message' => __d('net_commons', 'Invalid request.'),
),
),
));
}
if ($this->data['TaskContent']['task_end_date']) {
$validate = array_merge($validate, array(
'task_end_date' => array(
'datetime' => array(
'rule' => array('datetime'),
'message' => __d('net_commons', 'Invalid request.'),
),
'fromTo' => array(
'rule' => array('validateDatetimeFromTo',
array('from' => $this->data['TaskContent']['task_start_date'])),
'message' => __d('net_commons', 'Invalid request.'),
)
),
));
}
return $validate;
}
/**
* ToDoの一覧データを返す
*
* @param array $params 絞り込み条件
* @param array $order 並べ替え条件
* @return array
*
* 速度改善の修正に伴って発生したため抑制
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getTaskContentList($params = array(), $order = array()) {
$results = array();
$conditions = $this->getConditions(Current::read('Block.id'), $params);
$taskContents = $this->find('all',
array('recursive' => 0, 'conditions' => $conditions, 'order' => $order));
if (! $taskContents) {
return array();
}
// コンテンツID配列を生成
$taskContentIdArr = [];
foreach ($taskContents as $taskContent) {
$taskContentIdArr[] = $taskContent['TaskContent']['id'];
}
// コンテンツIDがキーの担当者連想配列を生成
$taskCharges = $this->TaskCharge->find('all', [
'recursive' => -1,
'conditions' => ['task_content_id' => $taskContentIdArr]
]);
$sortedTaskCharges = [];
foreach ($taskCharges as $taskCharge) {
$taskCharge = $taskCharge['TaskCharge'];
$sortedTaskCharges[$taskCharge['task_content_id']][$taskCharge['user_id']] = $taskCharge;
}
// isDeadLine及びdate_colorを取得、担当者を設定
$addedTaskContents = [];
$deadLineTasks = [];
$sortedTaskContents = [];
$categories = [];
$categoryLangArr = [];
foreach ($taskContents as $taskContent) {
if (isset($sortedTaskCharges[$taskContent['TaskContent']['id']])) {
$taskContent['TaskCharge'] = $sortedTaskCharges[$taskContent['TaskContent']['id']];
}
// 現在実施中
$taskContent['TaskContent']['date_color'] = TasksComponent::TASK_BEING_PERFORMED;
// ここでdate_colorをセット&Controllerで期限間近判定用のフラグをセット
if (empty($taskContent['TaskContent']['is_completion'])
&& ! empty($taskContent['TaskContent']['is_date_set'])
) {
$taskContent['TaskContent']['date_color'] = $this->getTaskDateColor(
$taskContent['TaskContent']['task_start_date'],
$taskContent['TaskContent']['task_end_date']
);
}
$addedTaskContents[] = $taskContent;
if ($this->isDeadLine($taskContent['TaskContent']['date_color'])) {
// 期限間近・期限切れの一覧を取得
$deadLineTasks[] = $taskContent;
}
// カテゴリIDがキーのコンテンツ連想配列を生成
$categoryId = 0;
if (! empty($taskContent['Category']['id'])) {
$categoryId = $taskContent['Category']['id'];
}
$sortedTaskContents[$categoryId][$taskContent['TaskContent']['id']] = $taskContent;
$categories[$taskContent['CategoryOrder']['weight']] = $taskContent['Category'];
$categoryLangArr[$categoryId] = $taskContent['CategoriesLanguage'];
}
ksort($categories);
if (isset($categories[''])) {
array_unshift($categories, [
'id' => 0,
'name' => __d('tasks', 'No category')
]);
$categoryLangArr[0] = ['name' => __d('tasks', 'No category')];
unset($categories['']);
}
// カテゴリ毎の進捗率情報を取得
// カテゴリなしは進捗率を表示しないので条件から省く
$categoryRateParam = array('Not' => array('TaskContent.category_id' => 0));
$listConditions = array_merge($conditions, $categoryRateParam);
// バーチャルフィールドを追加
$this->virtualFields['cnt'] = 0;
$this->virtualFields['sum'] = 0;
// カテゴリ毎の全体のToDo数と進捗率を取得
$categoryData = $this->find('all', array(
'fields' => array(
'TaskContent.category_id', 'count(TaskContent.category_id) as TaskContent__cnt',
'TaskContent.progress_rate', 'sum(TaskContent.progress_rate) as TaskContent__sum'
),
'conditions' => $listConditions,
'group' => array('TaskContent.category_id'),
));
$categoryRates = [];
foreach ($categoryData as $categoryDatum) {
$categoryRates[$categoryDatum['TaskContent']['category_id']] = $categoryDatum['TaskContent'];
}
$resultArr = array();
foreach ($categories as $category) {
$result = array();
if (isset($sortedTaskContents[$category['id']])) {
$result['TaskContents'] = $sortedTaskContents[$category['id']];
// ToDoListカテゴリがある場合進捗率の平均値を取得する
$categoryPriority = 0;
if (isset($categoryRates[$category['id']])) {
$categoryPriority = $this->getCategoryPriority($categoryRates[$category['id']]);
}
$result['Category'] = $category;
$result['CategoriesLanguage'] = isset($categoryLangArr[$category['id']])
? $categoryLangArr[$category['id']]
: [];
$result['Category']['category_priority'] = $categoryPriority;
$resultArr[] = $result;
}
}
$results['deadLineTasks'] = $deadLineTasks;
$results['tasks'] = $resultArr;
return $results;
}
/**
* ToDoのデータを一件返す
*
* @param void $key key
*
* @return array
*/
public function getTask($key) {
$conditions = $this->getConditions(
Current::read('Block.id')
);
$conditions = array_merge($conditions, array('TaskContent.key' => $key));
$lists = $this->find('first', array(
'recursive' => 1,
'conditions' => $conditions
));
return $lists;
}
/**
* blockIdから参照可能なToDoを取得するCondition配列を返す
*
* @param int $blockId blockId
* @param array $conditions ソート絞り込み条件
* @return array condition
*/
public function getConditions($blockId, $conditions = array()) {
// デフォルト絞り込み条件にソート絞り込み条件をマージする
$conditions = array_merge($conditions, array('TaskContent.block_id' => $blockId));
$conditions = $this->getWorkflowConditions($conditions);
return $conditions;
}
/**
* カテゴリごとのToDoの進捗率の平均値を取得
*
* @param array $categoryData カテゴリデータ
* @return int
*/
public function getCategoryPriority($categoryData) {
// ToDoの進捗率の合計を求める
$total = $categoryData['sum'];
$count = $categoryData['cnt'];
// 実際の値より大きくならないよう小数点以下切り捨て
$categoryPriority = floor($total / $count);
return $categoryPriority;
}
/**
* ToDoの保存。
*
* @param array $data 登録データ
* @return bool
* @throws InternalErrorException
*
* 速度改善の修正に伴って発生したため抑制
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function saveContent($data) {
// 必要なモデル読み込み
$this->loadModels([
'TaskCharge' => 'Tasks.TaskCharge',
]);
$data['TaskCharges'] = [];
$mailSendUserIdArr = [];
if (isset($data['TaskCharge'])) {
foreach ($data['TaskCharge'] as $datum) {
$data['TaskCharges'][] = [
'TaskCharge' => [
'id' => null,
'user_id' => $datum['user_id'],
]
];
$mailSendUserIdArr[] = $datum['user_id'];
}
}
// メール送信用の必要パラメーター取得
$reminder = isset($data['is_reminder'])
? $data['is_reminder']
: false;
$makeReminder = isset($data['is_make_reminder'])
? $data['is_make_reminder']
: false;
$this->begin();
$isMakeReminder = false;
try {
$this->create(); // 常に新規登録
// 先にvalidate 失敗したらfalse返す
$this->set($data);
if (! $this->validates(array('only_progress' => false))) {
$this->rollback();
return false;
}
// リマインダーメール作成判断フラグ取得
$isMakeReminder = $this->isReminder($reminder, $makeReminder);
if ($makeReminder) {
// リマインダーメール設定
$this->setSetting('typeKey', 'reminder');
$this->setSetting('X-URL', array('controller' => 'task_contents'));
// 実施終了日の日時を0持00分に変更する
$taskEndDate = date('Y-m-d H:i:s',
strtotime($data['TaskContent']['task_end_date'] . ' -1day +1 second'));
$sendTimes[] = date(
'Y-m-d H:i:s', strtotime(
$taskEndDate . ' -' . $data['TaskContent']['email_send_timing'] . 'day'
)
);
$this->setAddEmbedTagValue('X-BODY',
__d('tasks', 'Now %s days in advance of the period end date.',
$data['TaskContent']['email_send_timing']
)
);
$this->setSendTimeReminder($sendTimes);
$this->setSetting(MailQueueBehavior::MAIL_QUEUE_SETTING_USER_IDS, $mailSendUserIdArr);
// 通常保存のメールと重複してしまうため投稿メールのOFF
$this->setSetting(MailQueueBehavior::MAIL_QUEUE_SETTING_IS_MAIL_SEND_POST, 0);
// グループ配信のみ
$this->setSetting(
MailQueueBehavior::MAIL_QUEUE_SETTING_WORKFLOW_TYPE,
MailQueueBehavior::MAIL_QUEUE_WORKFLOW_TYPE_GROUP_ONLY
);
} else {
$this->setSetting(MailQueueBehavior::MAIL_QUEUE_SETTING_USER_IDS, $mailSendUserIdArr);
}
$savedData = $this->save($data, false);
if ($savedData === false) {
//このsaveで失敗するならvalidate以外なので例外なげる
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
$data['TaskContent'] = $savedData['TaskContent'];
// 担当者を登録
if (! $this->TaskCharge->setCharges($data)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
$savedData = $this->calendarCollaboration($data, $savedData);
//多言語化の処理
$this->set($savedData);
$this->saveM17nData();
$this->commit();
} catch (Exception $e) {
$this->rollback($e);
}
$savedData['is_makeReminder'] = $isMakeReminder;
return $savedData;
}
/**
* 進捗率を更新
*
* @param array $key ToDoキー
* @param array $progressRate ToDo進捗率
* @return bool
* @throws InternalErrorException
*
* 速度改善の修正に伴って発生したため抑制
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function updateProgressRate($key, $progressRate) {
$this->begin();
try {
$isCompletion = false;
if ((int)$progressRate === TasksComponent::TASK_COMPLETION_PROGRESS_RATE) {
$isCompletion = true;
}
$conditions = array(
'TaskContent.key' => $key,
'TaskContent.status' => TasksComponent::TASK_CONTENT_STATUS_PUBLISHED,
);
if (! Current::permission('content_publishable')) {
$taskContents = $this->find('first',
array('recursive' => 1, 'conditions' => $conditions));
$isMyTask = false;
if (! empty($taskContents['TaskCharge'])) {
foreach ($taskContents['TaskCharge'] as $item) {
if ($item['user_id'] == Current::read('User.id')) {
$isMyTask = true;
break;
}
}
}
// 担当者でなくTODO作成者でもないのであればfalseを返す
$taskContent = isset($taskContents['TaskContent'])
? $taskContents['TaskContent']
: null;
if (! $taskContent
|| ! $isMyTask
&& $taskContent['created_user'] !== Current::read('User.id')
) {
return false;
}
}
$data = array(
'progress_rate' => $progressRate,
'is_completion' => $isCompletion,
'modified_user' => Current::read('User.id'),
);
// statusを一時保存の状態として設定しバリデーション処理を行う
$data['status'] = TasksComponent::TASK_CONTENT_STATUS_IN_DRAFT;
$this->set($data);
if (! $this->validates( array('only_progress' => true))) {
return false;
}
// statusは更新しないのでunsetする
unset($data['status']);
if (! $this->updateAll($data, $conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
$this->commit();
} catch (Exception $e) {
$this->rollback($e);
}
return true;
}
/**
* TODO削除
*
* @param void $key オリジンKey
* @throws InternalErrorException
* @return bool
*/
public function deleteContentByKey($key) {
$this->begin();
try {
// 削除対象となるIDを取得
$targetIds = $this->find('list', array(
'fields' => array('TaskContent.id', 'TaskContent.id'),
'recursive' => -1,
'conditions' => array(
'TaskContent.key' => $key,
)
));
// 関連するデータを一式削除
if (count($targetIds) > 0) {
$this->contentKey = $key;
if (! $this->TaskCharge->deleteAll(
array('TaskCharge.task_content_id' => $targetIds), false)
) {
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'));
}
}
$this->commit();
} catch (Exception $ex) {
$this->rollback();
CakeLog::error($ex);
throw $ex;
}
return true;
}
}