-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReservationActionPlan.php
More file actions
1407 lines (1278 loc) · 50.4 KB
/
ReservationActionPlan.php
File metadata and controls
1407 lines (1278 loc) · 50.4 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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* ReservationActionPlan Model
*
* @property Block $Block
* @property Room $Room
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author AllCreator Co., Ltd. <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('ReservationsAppModel', 'Reservations.Model');
App::uses('ReservationsComponent', 'Reservations.Controller/Component');
App::uses('ReservationSupport', 'Reservations.Utility');
App::uses('ReservationService', 'Reservations.Service');
App::uses('ReservationRruleParameter', 'Reservations.Parameter');
/**
* Reservation Action Plan Model
*
* @author AllCreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Reservations\Model
* @SuppressWarnings(PHPMD)
*/
class ReservationActionPlan extends ReservationsAppModel {
/**
* アクセスユーザが予約可能な施設
*
* @var array
*/
protected $_locations = null;
/**
* use table
*
* このモデルはvalidateと
* insert/update/deletePlan()呼び出しが主目的なのでテーブルを使用しない。
* @var array
*/
public $useTable = false;
/**
* use behaviors
*
* @var array
*/
public $actsAs = array(
'NetCommons.OriginalKey',
'NetCommons.Trackable',
//FUJI'Workflow.Workflow',
'Workflow.WorkflowComment',
'Reservations.ReservationValidate',
'Reservations.ReservationApp', //baseビヘイビア
'Reservations.ReservationInsertPlan', //Insert用
'Reservations.ReservationUpdatePlan', //Update用
'Reservations.ReservationDeletePlan', //Delete用
'Reservations.ReservationExposeRoom', //ルーム表示・選択用
'Reservations.ReservationPlanOption', //予定CRUD画面の各種選択用
'Reservations.ReservationPlanTimeValidate', //予定(時間関連)バリデーション専用
'Reservations.ReservationPlanRruleValidate', //予定(Rrule関連)バリデーション専用
'Reservations.ReservationPlanValidate', //予定バリデーション専用
////'Reservations.ReservationRruleHandle', //concatRrule()など
'Reservations.ReservationPlanGeneration', //元予定の新世代予定生成関連
/*
// 自動でメールキューの登録, 削除。ワークフロー利用時はWorkflow.Workflowより下に記述する
'Mails.MailQueue' => array(
'embedTags' => array(
'X-SUBJECT' => 'ReservationActionPlan.title',
'X-LOCATION' => 'ReservationActionPlan.location',
'X-CONTACT' => 'ReservationActionPlan.contact',
'X-BODY' => 'ReservationActionPlan.description',
'X-URL' => array(
'controller' => 'reservation_plans'
)
),
'workflowType' => 'workflow',
),
'Mails.MailQueueDelete',
*/
'Reservations.ReservationMail',
'Reservations.ReservationTopics',
// 'Reservations.RegistCalendar',
);
// @codingStandardsIgnoreStart
// $_schemaはcakePHP2の予約語だが、宣言するとphpcsが警告を出すので抑止する。
// ただし、$_schemaの直前にIgnoreStartを入れると、今度はphpdocが直前の
// property説明がないと警告を出す。よって、この位置にIgnoreStartを挿入した。
/**
* use _schema
*
* @var array
*/
public $_schema = array (
// @codingStandardsIgnoreEnd
// 入力カラムの定義、データ型とdefault値、必要ならlength値
//繰返し編集の指定(0/1/2). このフィールドは渡ってこない時もあるので
//ViewにてunlockField指定しておくこと。
'edit_rrule' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//施設予約元eventId
'origin_event_id' => array(
'type' => 'integer', 'null' => false, 'default' => 0, 'unsigned' => false),
//施設予約元eventKey
'origin_event_key' => array(
'type' => 'string', 'default' => ''),
//施設予約元eventRecurrence
'origin_event_recurrence' => array(
'type' => 'integer', 'null' => false, 'default' => 0, 'unsigned' => false),
//施設予約元eventException
'origin_event_exception' => array(
'type' => 'integer', 'null' => false, 'default' => 0, 'unsigned' => false),
//施設予約元rruleId
'origin_rrule_id' => array(
'type' => 'integer', 'null' => false, 'default' => 0, 'unsigned' => false),
//施設予約元rruleKey
'origin_rrule_key' => array(
'type' => 'string', 'default' => ''),
//施設予約元rruleを共有する兄弟eventの数
'origin_num_of_event_siblings' => array(
'type' => 'integer', 'null' => false, 'default' => 0, 'unsigned' => false),
// 全変更選択時、繰返し先頭eventのeditボタンを擬似クリックする方式用の項目
// editLink()を呼ぶときの必要パラメータ
'first_sib_year' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
'first_sib_month' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
'first_sib_day' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
'first_sib_event_id' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
/*
// -- 以下のcapForViewOf1stSibによるデータすり替え方式用の項目(first_sib_cap_xxx)は、--
// -- 全変更選択時、繰返し先頭eventのeditボタンを擬似クリックする方式にかえたので、削除. --
//先頭兄弟(繰返しの先頭)capForView(表示用ReservationActionPlan)の情報
'first_sib_cap_enable_time' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
'first_sib_cap_easy_start_date' => array('type' => 'string', 'default' => ''), //YYYY-MM-DD
'first_sib_cap_easy_hour_minute_from' => array('type' => 'string', 'default' => ''), //hh:mm
'first_sib_cap_easy_hour_minute_to' => array(
'type' => 'string', 'default' => ''), //hh:mm
'first_sib_cap_detail_start_datetime' => array(
'type' => 'string', 'default' => ''), //YYYY-MM-DD or YYYY-MM-DD hh:mm
'first_sib_cap_detail_end_datetime' => array(
'type' => 'string', 'default' => ''), //YYYY-MM-DD or YYYY-MM-DD hh:mm
'first_sib_cap_timezone' => array('type' => 'string', 'default' => ''),
*/
//タイトル
'title' => array('type' => 'string', 'default' => ''),
//タイトルアイコン
//注)タイトルアイコンは、ReservationActionPlanモデルを指定することで、以下の形式で渡ってくる。
//<input id="PlanTitleIcon" class="ng-scope" type="hidden" value="/net_commons/img/title_icon/10_040_left.svg" name="data[ReservationActionPlan][title_icon]">
'title_icon' => array('type' => 'string', 'default' => ''),
//時間の指定(1/0)
'enable_time' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
////完全なる開始日付時刻と終了日付時刻(hidden)
////'full_start_datetime' => array('type' => 'string', 'default' => ''), //hidden
////'full_end_datetime' => array('type' => 'string', 'default' => ''), //hidden
//簡易編集の日付時刻エリア
'easy_start_date' => array('type' => 'string', 'default' => ''), //YYYY-MM-DD
'easy_hour_minute_from' => array('type' => 'string', 'default' => ''), //hh:mm
'easy_hour_minute_to' => array('type' => 'string', 'default' => ''), //hh:mm
//詳細編集の日付時刻エリア
'detail_start_datetime' => array(
'type' => 'string', 'default' => ''), //YYYY-MM-DD or YYYY-MM-DD hh:mm
'detail_end_datetime' => array(
'type' => 'string', 'default' => ''), //YYYY-MM-DD or YYYY-MM-DD hh:mm
//公開対象
'plan_room_id' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//注)共有するユーザ群は、ReservationActionPlanモデルではなく、GroupsUserモデルの配列として以下形式で渡ってくる。
//<input type="hidden" value="2" name="data[GroupsUser][0][user_id]">
//<input type="hidden" value="3" name="data[GroupsUser][1][user_id]">
//タイムゾーン
'timezone' => array('type' => 'string', 'default' => ''),
'timezone' => array('type' => 'string', 'default' => ''),
//詳細フラグ(1/0) (hidden. 画面表示時点で、detail(or easy)かはわかるので値を指定しておく。
'is_detail' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//場所
'location' => array('type' => 'string', 'default' => ''),
//連絡先
'contact' => array('type' => 'string', 'default' => ''),
//内容(wysiwyg)
'description' => array('type' => 'string', 'default' => ''),
//予定を繰り返す(1/0)
'is_repeat' => array('type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//繰返し周期 DAILY, WEEKLY, MONTHLY, YEARLY
'repeat_freq' => array('type' => 'string', 'default' => ''),
//繰返し間隔 rrule_interval[DAILY], rrule_interval[WEEKLY], rrule_interval[MONTHLY], rrule_interval[YEARLY]
// rrule_interval[DAILY] inList => array(1, 2, 3, 4, 5, 6) //n日ごと
// rrule_interval[WEEKLY] inList => array(1, 2, 3, 4, 5) //n週ごと
// rrule_interval[MONTHLY] inList => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) //nヶ月ごと
// rrule_interval[YEARLY] inList => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) //n年ごと
'rrule_interval' => array('type' => 'string', 'default' => ''),
//週単位or月単位 rrule_byday[WEEKLY], rrule_byday[MONTHLY], rrule_byday[YEARLY]
// rrule_byday[WEEKLY] inList => array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA')
// rrule_byday[MONTHLY] inList => array('', '1SU', '1MO', '1TU', ... , '4FR, '4SA', '-1SU', '-2SU', ..., '-1SA')
// rrule_byday[YEARLY] inList => array('', '1SU', '1MO', '1TU', ... , '4FR, '4SA', '-1SU', '-2SU', ..., '-1SA')
'rrule_byday' => array('type' => 'string', 'default' => ''),
//月単位 rrule_bymonthday[MONTHLY]
// rrule_bymonthday[MONTHLY] inList => array('', 1, 2, ..., 31 );
'rrule_bymonthday' => array('type' => 'string', 'default' => ''),
//年単位 rrule_bymonth[YEARLY]
// rrule_bymonth[YEARLY] inList => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) //n月
'rrule_bymonth' => array('type' => 'string', 'default' => ''),
//繰返しの終了指定
// rrule_term inList('COUNT', 'UNTIL')
'rrule_term' => array('type' => 'string', 'default' => ''),
//繰返し回数
'rrule_count' => array('type' => 'string', 'default' => ''),
//繰返し終了日
'rrule_until' => array('type' => 'string', 'default' => ''),
//メールで通知(1/0)
'enable_email' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//メール通知タイミング
'email_send_timing' => array(
'type' => 'integer', 'null' => false, 'default' => '0', 'unsigned' => false),
//承認ステータス
//statusは 施設予約独自stauts取得関数getStatusで取ってくるので、ここからは外す。
//'status' => array('type' => 'integer', 'null' => false, 'unsigned' => false),
);
/**
* Validation rules
*
* @var array
*/
public $validate = array(
);
/**
* Constructor. Binds the model's database table to the object.
*
* @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);
$this->loadModels([
'Frame' => 'Frames.Frame',
'Reservation' => 'Reservations.Reservation',
]);
}
/**
* _doMergeDisplayParamValidate
*
* 画面パラメータ関連バリデーションのマージ
*
* @param bool $isDetailEdit 詳細画面かどうか true=詳細(detail)画面, false=簡易(easy)画面
* @return void
*/
// 未使用
//protected function _doMergeDisplayParamValidate($isDetailEdit) {
// $this->validate = Hash::merge($this->validate, array(
// 'return_style' => array(
// 'rule1' => array(
// 'rule' => array('inList', array(
// ReservationsComponent::CALENDAR_STYLE_SMALL_MONTHLY,
// ReservationsComponent::CALENDAR_STYLE_LARGE_MONTHLY,
// ReservationsComponent::CALENDAR_STYLE_WEEKLY,
// ReservationsComponent::CALENDAR_STYLE_DAILY,
// ReservationsComponent::CALENDAR_STYLE_SCHEDULE,
// )),
// 'required' => false,
// 'allowEmpty' => true,
// 'message' => __d('reservations', '戻り先のスタイル指定が不正です。'),
// ),
// ),
// 'return_sort' => array(
// 'rule1' => array(
// 'rule' => array('inList', array(
// ReservationsComponent::CALENDAR_SCHEDULE_SORT_TIME,
// ReservationsComponent::CALENDAR_SCHEDULE_SORT_MEMBER,
// )),
// 'required' => false, //sort指定はスケジュールの時だけ
// 'allowEmpty' => true,
// 'message' => __d('reservations', '戻り先のソート指定が不正です。'),
// ),
// ),
// 'return_tab' => array(
// 'rule1' => array(
// 'rule' => array('inList', array(
// ReservationsComponent::CALENDAR_DAILY_TAB_LIST,
// ReservationsComponent::CALENDAR_DAILY_TAB_TIMELINE,
// )),
// 'required' => false, //tab指定は単一日の時だけ
// 'allowEmpty' => true,
// 'message' => __d('reservations', '戻り先のタブ指定が不正です。'),
// ),
// ),
// ));
//}
/**
* _doMergeRruleValidate
*
* 繰返し関連バリデーションのマージ
*
* @param bool $isDetailEdit 詳細画面かどうか true=詳細(detail)画面, false=簡易(easy)画面
* @return void
*/
protected function _doMergeRruleValidate($isDetailEdit) {
$this->validate = Hash::merge($this->validate, array(
'edit_rrule' => array(
'rule1' => array(
'rule' => array('inList', array(0, 1, 2)),
'required' => false,
'message' => __d('reservations', 'Invalid input. (change of repetition)'),
),
),
'is_repeat' => array(
'rule1' => array(
'rule' => array('inList', array(0, 1)),
'required' => false,
'message' => __d('reservations', 'Invalid input. (repetition)'),
),
),
'repeat_freq' => array(
'rule1' => array(
'rule' => array('checkRrule'),
'required' => false,
'message' => ReservationsComponent::CALENDAR_RRULE_ERROR_HAPPEND,
),
),
));
}
/**
* _doMergeDatetimeValidate
*
* 日付時刻関連バリデーションのマージ
*
* @param bool $isDetailEdit 詳細画面かどうか true=詳細(detail)画面, false=簡易(easy)画面
* @return void
*/
protected function _doMergeDatetimeValidate($isDetailEdit) {
$this->validate = Hash::merge($this->validate, array(
'enable_time' => array(
'rule1' => array(
'rule' => array('inList', array(0, 1)),
'required' => false,
'message' => __d('reservations', 'Invalid input. (time)'),
),
),
'easy_start_date' => array(
'rule1' => array(
'rule' => array('date', 'ymd'), //YYYY-MM-DD
'required' => !$isDetailEdit,
'allowEmpty' => $isDetailEdit,
'message' => __d('reservations', 'Invalid input. (year/month/day)'),
),
),
'easy_hour_minute_from' => array(
'rule1' => array(
'rule' => array('datetime'), //YYYY-MM-DD hh:mm
'required' => false,
'allowEmpty' => true,
'message' => __d('reservations', 'Invalid input. (start time)(easy edit mode)'),
),
'rule2' => array(
'rule' => array('checkReverseStartEndTime', 'easy'), //YYYY-MM-DD hh:mm
'message' => __d('reservations', 'Invalid input. (start time and end time)(easy edit mode)'),
),
),
'easy_hour_minute_to' => array(
'rule1' => array(
'rule' => array('datetime'), //YYYY-MM-DD hh:mm
'required' => false,
'allowEmpty' => true,
'message' => __d('reservations', 'Invalid input. (end time)'),
),
),
'detail_start_datetime' => array(
'rule1' => array(
'rule' => array('customDatetime', 'detail'), //YYYY-MM-DD or YYYY-MM-DD hh:mm
'message' => __d('reservations', 'Invalid input. (start time)'),
),
'rule2' => array(
'rule' => array('checkReverseStartEndDateTime', 'detail'),
'message' => __d('reservations', 'Invalid input. (start day (time) and end day (time))'),
),
'rule3' => array(
'rule' => array('validteNotExistReservation'),
'message' =>
__d('reservations', 'It has been alreay reserved by someone else.Try different time and date.'),
// NC2では予約の入ってる日付を表示してた(繰り返し用だが、単発予約でも表示)
),
'rule4' => array(
'rule' => array('validteUseLocationTimeRange'),
'message' =>
__d('reservations',
'Invalid reservation time range.'),
),
),
'detail_end_datetime' => array(
'rule1' => array(
'rule' => array('customDatetime', 'detail'), //YYYY-MM-DD or YYYY-MM-DD hh:mm
'message' => __d('reservations', 'Invalid input. (end date)'),
),
),
));
}
/**
* 施設利用時間内の予約になっているか
*
* @param array $check チェック対象
* @return bool
*/
public function validteUseLocationTimeRange($check) {
$locationKey = $this->data[$this->alias]['location_key'];
$startDateTime = $this->data[$this->alias]['detail_start_datetime'] . ':00';
$endDateTime = $this->data[$this->alias]['detail_end_datetime'] . ':00';
// 施設情報を取得
$this->loadModels(
[
'ReservationLocation' => 'Reservations.ReservationLocation'
]
);
$location = $this->ReservationLocation->findByKeyAndLanguageId(
$locationKey,
Current::read('Language.id')
);
$reservableTimeTable = explode('|', $location['ReservationLocation']['time_table']);
$locationTimeZone = new DateTimeZone($location['ReservationLocation']['timezone']);
// 予約時間を施設のタイムゾーンの時間に変換
// This timezone offset is id.
$planTimeZone = new DateTimeZone($this->data[$this->alias]['timezone']);
$startDateTime = new DateTime($startDateTime, $planTimeZone);
$startDateTime->setTimezone($locationTimeZone);
$startDateTime = $startDateTime->format('Y-m-d H:i:s');
$endDateTime = new DateTime($endDateTime, $planTimeZone);
$endDateTime->setTimezone($locationTimeZone);
$endDateTime = $endDateTime->format('Y-m-d H:i:s');
// 施設の利用可能時刻をUTCから施設のタイムゾーンに変換
$locationStartTime = new DateTime($location['ReservationLocation']['start_time'],
new DateTimeZone('UTC'));
$locationStartTime->setTimezone($locationTimeZone);
$locationStartTime = $locationStartTime->format('H:i');
$locationEndTime = new DateTime($location['ReservationLocation']['end_time'],
new DateTimeZone('UTC'));
$locationEndTime->setTimezone($locationTimeZone);
$locationEndTime = $locationEndTime->format('H:i');
if ($locationStartTime == '00:00' && $locationStartTime == $locationEndTime) {
// 00:00-00:00は00:00-24:00にする
$locationEndTime = '24:00';
}
//
//$length = strtotime($locationEndTime) = strtotime($locationStartTime);
//$locationEndTime = strtotime($locationStartTime) + $length;
//
// 予約を日付毎に分割する
// 以下、日付毎にチェックする
// 曜日の制約OKかをチェック
// 施設の利用可能時刻におさまってるかチェック
$startDate = date('Y-m-d', strtotime($startDateTime));
$endDate = date('Y-m-d', strtotime($endDateTime));
if ($startDate != $endDate) {
// 日付またぎの予約なら日付毎に分割してチェックする
// $startDateから1日ずつたして$endDateまで
$endDateUnixtime = strtotime($endDate);
$current = strtotime($startDate);
for ($current = $current; $current <= $endDateUnixtime; $current = $current + (24 * 60 * 60)) {
if ($current == strtotime($startDate)) {
// 開始日
$startUnixTime = strtotime($startDateTime);
} else {
$startUnixTime = $current;
}
if ($current == strtotime($endDate)) {
// 終了日
$endUnixTime = strtotime($endDateTime);
} else {
$endUnixTime = $current + (24 * 60 * 60);
}
$result = $this->_isReservableLocationTimeRane(
$startUnixTime,
$endUnixTime,
$locationStartTime,
$locationEndTime,
$reservableTimeTable
);
if (!$result) {
return false;
}
}
return true;
} else {
// 予約OKな曜日か
$startUnixTime = strtotime($startDateTime);
$endUnixTime = strtotime($endDateTime);
return $this->_isReservableLocationTimeRane(
$startUnixTime,
$endUnixTime,
$locationStartTime,
$locationEndTime,
$reservableTimeTable
);
}
}
/**
* 重複予約のチェック
*
* @param array $check チェック対象
* @return bool
*/
public function validteNotExistReservation($check) {
$startDateTime = $this->data[$this->alias]['detail_start_datetime'];
$endDateTime = $this->data[$this->alias]['detail_end_datetime'];
// This timezone offset is id.
$inputTimeZone = $this->data[$this->alias]['timezone'];
$locationKey = $this->data[$this->alias]['location_key'];
$rruleParameter = new ReservationRruleParameter();
$rruleParameter->setData($this->data);
$rrule = $rruleParameter->getRrule();
// 繰り返しでないか、設定した全ての予定の変更時は$rruleIdを渡す(この繰り返し予約は重複チェック対象外になるので)
$ignoreConditions = [];
if (Hash::get($this->data, 'ReservationActionPlan.origin_event_id')) {
if (empty($rrule)) {
// 繰り返しでないなら、keyが同じ予約は編集元レコードなので重複チェック時は無視
$ignoreConditions = [
'ReservationEvent.key != ' => Hash::get($this->data, 'ReservationActionPlan.origin_event_key')
];
} else {
switch (Hash::get($this->data, 'ReservationActionPlan.edit_rrule')){
case 0:
// 一つの予約だけ更新
$ignoreConditions = [
'ReservationEvent.key != ' =>
Hash::get($this->data, 'ReservationActionPlan.origin_event_key')
];
// ひとつだけの変更なので重複チェックでは繰り返しさせない
$rrule = [];
break;
case 1:
// 以降の予約を更新
$this->loadModels(['ReservationEvent' => 'Reservations.ReservationEvent']);
$origin = $this->ReservationEvent->findById(
Hash::get($this->data, 'ReservationActionPlan.origin_event_id'));
$ignoreConditions = [
'NOT' => [
'ReservationEvent.reservation_rrule_id' => Hash::get($this->data,
'ReservationActionPlan.origin_rrule_id'),
'ReservationEvent.recurrence_event_id !=' => 0,
'ReservationEvent.exception_event_id !=' => 0,
],
'ReservationEvent.dtstart > ' => $origin['ReservationEvent']['dtstart']
];
break;
case 2:
// 全ての予約を更新
$ignoreConditions = [
'NOT' => [
'ReservationEvent.rrule_id' =>
Hash::get($this->data, 'ReservationActionPlan.origin_rrule_id'),
'ReservationEvent.recurrence_event_id !=' => 0,
'ReservationEvent.exception_event_id !=' => 0,
]
];
break;
}
}
}
$reservationService = new ReservationService();
$result = $reservationService->getOverlapReservationDate(
$locationKey,
$startDateTime,
$endDateTime,
$inputTimeZone,
$rrule,
$ignoreConditions
);
if (count($result) > 0) {
$ret = __d(
'reservations',
'It has been alreay reserved by someone else.Try different time and date.'
);
foreach ($result as $date) {
$ret .= "<br />" . $date;
}
return $ret;
} else {
return true;
}
}
/**
* _doMergeTitleValidate
*
* タイトル関連バリデーションのマージ
*
* @param bool $isDetailEdit 詳細画面かどうか true=詳細(detail)画面, false=簡易(easy)画面
* @return void
*/
protected function _doMergeTitleValidate($isDetailEdit) {
$this->validate = Hash::merge($this->validate, array(
'title' => array(
'rule1' => array(
'rule' => array('notBlank'),
'required' => true,
'message' => __d('reservations', 'Invalid input. (plan title)'),
),
'rule2' => array(
'rule' => array('maxLength', ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
'message' => sprintf(__d('reservations',
'%d character limited. (plan title)'), ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
),
),
'title_icon' => array(
'rule2' => array(
'rule' => array('maxLength', ReservationsComponent::CALENDAR_VALIDATOR_GENERAL_VCHAR_LEN),
'required' => false,
'allowEmpty' => true,
'message' => sprintf(__d('reservations',
'%d character limited. (title icon)'),
ReservationsComponent::CALENDAR_VALIDATOR_GENERAL_VCHAR_LEN),
),
),
));
}
/**
* Called during validation operations, before validation. Please note that custom
* validation rules can be defined in $validate.
*
* @param array $options Options passed from Model::save().
* @return bool True if validate operation should continue, false to abort
* @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforevalidate
* @see Model::save()
*/
public function beforeValidate($options = array()) {
$isDetailEdit = (isset($this->data['ReservationActionPlan']['is_detail']) &&
$this->data['ReservationActionPlan']['is_detail']) ? true : false;
//$this->_doMergeDisplayParamValidate($isDetailEdit); //画面パラメータ関連validation
$this->_doMergeTitleValidate($isDetailEdit); //タイトル関連validation
$this->_doMergeDatetimeValidate($isDetailEdit); //日付時刻関連validation
$this->validate = Hash::merge($this->validate, array( //コンテンツ関連validation
'status' => [
'rule1' => [
'rule' => ['validateStatus'],
'message' => __d('net_commons', 'Invalid request.'),
]
],
'plan_room_id' => array(
'rule1' => array(
'rule' => array('allowedRoomId'),
'required' => true,
'allowEmpty' => false,
'message' => __d('reservations', 'Invalid input. (authority)'),
),
),
'location_key' => [
'rule1' => [
'rule' => ['allowedLocationKey'],
'required' => true,
'allowEmpty' => false,
'message' => __d('reservations', 'Invalid input location')
]
],
//'plan_room_id' => array(
// 'rule1' => array(
// 'rule' => array('allowedRoomId'),
// 'required' => true,
// 'allowEmpty' => false,
// 'message' => __d('reservations', 'Invalid input. (authority)'),
// ),
//),
// This timezone offset is id.
'timezone' => array(
'rule1' => array(
'rule' => array('allowedTimezoneOffset'),
'required' => false,
'message' => __d('reservations', 'Invalid input. (timezone)'),
),
),
'is_detail' => array(
'rule1' => array(
'rule' => array('inList', array(0, 1)),
'required' => false,
'message' => __d('reservations', 'Invalid input. (detail)'),
),
),
'location' => array(
'rule1' => array(
'rule' => array('maxLength', ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
'required' => false,
'message' => sprintf(__d('reservations',
'%d character limited. (location)'), ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
),
),
'contact' => array(
'rule1' => array(
'rule' => array('maxLength', ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
'required' => false,
'message' => sprintf(__d('reservations', '%d character limited. (contact)'),
ReservationsComponent::CALENDAR_VALIDATOR_TITLE_LEN),
),
),
'description' => array(
'rule1' => array(
'rule' => array('maxLength', ReservationsComponent::CALENDAR_VALIDATOR_TEXTAREA_LEN),
'required' => false,
//'message' => sprintf(__d('reservations', '連絡先は最大 %d 文字です。'),
'message' => sprintf(__d('reservations', '%d character limited. (detail)'),
ReservationsComponent::CALENDAR_VALIDATOR_TEXTAREA_LEN),
),
),
//statusの値は 施設予約独自status取得関数getStatusで取ってくるので省略
));
$this->_doMergeRruleValidate($isDetailEdit); //繰返し関連validation
return parent::beforeValidate($options);
}
/**
* statusのチェック
*
* @param array $check checkする値
* @return bool
*/
public function validateStatus($check) {
// 選ばれた施設による
$locations = $this->_getLocations();
$statusesForEditor = array(
WorkflowComponent::STATUS_APPROVAL_WAITING,
WorkflowComponent::STATUS_IN_DRAFT
);
$statusesForPublisher = array(
WorkflowComponent::STATUS_PUBLISHED,
WorkflowComponent::STATUS_IN_DRAFT,
WorkflowComponent::STATUS_DISAPPROVED
);
foreach ($locations as $location) {
if ($this->data['ReservationActionPlan']['location_key'] ==
$location['ReservationLocation']['key']) {
// 承認必要か
if ($location['ReservationLocation']['use_workflow']) {
// 承認必要
// 承認者か
if (in_array(Current::read('User.id'), $location['approvalUserIds'])) {
//承認者
$allowList = $statusesForPublisher;
} else {
//承認権限無し
$allowList = $statusesForEditor;
}
} else {
// 承認不要
$allowList = $statusesForPublisher;
}
$stauts = $check['status'];
return in_array($stauts, $allowList);
}
}
}
/**
* 予約可能な施設を返す
* 何度も呼び出すことを考慮して内部キャッシュ
* ε( v ゚ω゚) <ReservationLocation内でキャッシュすればOKなのでは?
*
* @return array
*/
protected function _getLocations() {
if (is_null($this->_locations)) {
$this->loadModels(
[
'ReservationLocation' => 'Reservations.ReservationLocation',
]
);
$userId = Hash::get($this->data,
'ReservationActionPlan.origin_created_user',
Current::read('User.id'));
$this->_locations = $this->ReservationLocation->getReservableLocations(null, $userId);
}
return $this->_locations;
}
/**
* 選択した施設が予約可能な施設かチェックする
*
* @param array $check 入力値 location_key
* @return bool
*/
public function allowedLocationKey($check) {
//
$locationKey = $check['location_key'];
$locations = $this->_getLocations();
$locationKeys = Hash::combine($locations, '{n}.ReservationLocation.key', '{n}.ReservableRoom');
return array_key_exists($locationKey, $locationKeys);
}
/**
* allowedRoomId
*
* 許可されたルームIDかどうか
* 予約しようとするユーザのロール、予約する施設により予約可能なルームはことなる。
*
* @param array $check 入力配列(room_id)
* @return bool 成功時true, 失敗時false
*/
public function allowedRoomId($check) {
$roomId = $check['plan_room_id'];
$locations = $this->_getLocations();
$locationRooms = Hash::combine($locations, '{n}.ReservationLocation.key', '{n}.ReservableRoom');
$locationKey = $this->data[$this->alias]['location_key'];
$rooms = $locationRooms[$locationKey];
$reservableRoomIds = Hash::combine($rooms, '{n}.Room.id', '{n}.Room.id');
return in_array($roomId, $reservableRoomIds);
}
/**
* saveReservationPlan
*
* 予定データ登録
*
* @param array $data POSTされたデータ
* @param string $procMode procMode
* @param bool $isOriginRepeat isOriginRepeat
* @param bool $isTimeMod isTimeMod
* @param bool $isRepeatMod isRepeatMod
* @param int $createdUserWhenUpd createdUserWhenUpd
* @param bool $isMyPrivateRoom isMyPrivateRoom
* @return bool 成功時true, 失敗時false
* @throws InternalErrorException
*/
public function saveReservationPlan($data, $procMode,
$isOriginRepeat, $isTimeMod, $isRepeatMod, $createdUserWhenUpd, $isMyPrivateRoom) {
// 設定画面を表示する前にこのルームのアンケートブロックがあるか確認
// 万が一、まだ存在しない場合には作成しておく
$this->Reservation->afterFrameSave(Current::read());
$this->begin();
$eventId = 0;
$this->aditionalData = $data['WorkflowComment'];
try {
//備忘)
//選択したTZを考慮したUTCへの変換は、この
//convertToPlanParamFormat()の中でcallしている、
//_setAndMergeDateTime()がさらにcallしている、
//_setAndMergeDateTimeDetail()で行っています。
//
$planParam = $this->convertToPlanParamFormat($data);
//CakeLog::debug("DBG: request_data[" . print_r($data, true) . "]");
//call元の_reservationPost()の最初でgetStatus($data)の結果が
//$data['ReservationActionPlan']['status']に代入されているので
//ここは、その値を引っ張ってくるだけに直す。
////$status = $this->getStatus($data);
$status = $data['ReservationActionPlan']['status'];
//if ($status === false) { getStatus内でInternalErrorExceptionしている
// CakeLog::error("save_Nより、statusが決定できませんでした。data[" .
// serialize($data) . "]");
// throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
//}
if ($procMode === ReservationsComponent::PLAN_ADD) {
//新規追加処理
//CakeLog::debug("DBG: PLAN_ADD case.");
//$this->insertPlan($planParam);
$eventId = $this->insertPlan($planParam, $isMyPrivateRoom);
//$this->updateCalendar($planParam);
} else { //PLAN_EDIT
//変更処理
//CakeLog::debug("DBG: PLAN_MODIFY case.");
//現予定を元に、新世代予定を作成する
//1. statusは、cal用新statusである。
//2. createdUserWhenUpdは、変更後の公開ルームidが「元予定生成者の*ルーム」から「編集者・承認者
//(=ログイン者)のプライベート」に変化していた場合、created_userを元予定生成者から編集者・承認者
//(=ログイン者)に変更する例外処理用。
//3. isMyPrivateRoomは、変更後の公開ルームidが「編集者・承認者(=ログイン者)のプライベート」以外の場合、
//仲間の予定はプライベートの時のみ許される子情報なので、これらはcopy対象から外す(stripする)例外処理用。
//
$newPlan = $this->makeNewGenPlan($data, $status, $createdUserWhenUpd, $isMyPrivateRoom);
$editRrule = $this->getEditRruleForUpdate($data);
$isInfoArray = array($isOriginRepeat, $isTimeMod, $isRepeatMod, $isMyPrivateRoom);
$eventId = $this->updatePlan($planParam, $newPlan, $status, $isInfoArray, $editRrule,
$createdUserWhenUpd);
}
if ($this->isOverMaxRruleIndex) {
CakeLog::info("save(ReservationPlanの内部で施設予約のrruleIndex回数超過が" .
"発生している。強制rollbackし、画面にINDEXオーバーであることを" .
"出す流れに乗せ、例外は投げないようにする。");
$this->rollback();
return false;
}
// メールやらなんやらが動作する前にはブロックをちゃんと用意しておかねばならない
$this->Reservation->prepareBlock(
$data['ReservationActionPlan']['plan_room_id'],
Current::read('Language.id'),
'reservations');
// 承認メール、公開通知メールの送信
$this->sendWorkflowAndNoticeMail($eventId, $isMyPrivateRoom);
$this->saveReservationTopics($eventId);
$this->_enqueueEmail($data);
$this->commit();
} catch (Exception $ex) {
$this->rollback($ex);
return false;
}
return $eventId;
}
/**
* saveReservationPlan
*
* 予定データ登録
*
* @param array $data POSTされたデータ
* @param bool $isMyPrivateRoom isMyPrivateRoom
* @return bool 成功時true, 失敗時false
* @throws InternalErrorException
*/
public function saveImportRecord($data, $isMyPrivateRoom) {
$eventId = 0;
//$this->aditionalData = $data['WorkflowComment'];
try {
//備忘)
//選択したTZを考慮したUTCへの変換は、この
//convertToPlanParamFormat()の中でcallしている、
//_setAndMergeDateTime()がさらにcallしている、
//_setAndMergeDateTimeDetail()で行っています。