-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReservationLocationDeleteBehavior.php
More file actions
104 lines (95 loc) · 3.28 KB
/
ReservationLocationDeleteBehavior.php
File metadata and controls
104 lines (95 loc) · 3.28 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
<?php
/**
* ReservationLocationDeleteBehavior.php
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('ReservationAppBehavior', 'Reservations.Model/Behavior');
/**
* Class ReservationLocationDeleteBehavior
*/
class ReservationLocationDeleteBehavior extends ReservationAppBehavior {
/**
* 施設削除にともなう施設関係データの削除
*
* @param ReservationLocation $model ReservationLocation
* @param string $locationKey 施設キー
* @throws InternalErrorException
* @return void
*/
public function deleteLocationData(ReservationLocation $model, $locationKey) {
// ReservationLocation 削除
$conditions = [
$model->alias . '.key' => $locationKey
];
if (!$model->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
// ReservationLocationsRoom 削除
$conditions = [
$model->ReservationLocationsRoom->alias . '.reservation_location_key' => $locationKey
];
if (!$model->ReservationLocationsRoom->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
// ReservationLocationReservable 削除
$conditions = [
$model->ReservationLocationReservable->alias . '.location_key' => $locationKey
];
if (!$model->ReservationLocationReservable->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
// ReservationLocationsApprovalUser 削除
$conditions = [
$model->ReservationLocationsApprovalUser->alias . '.location_key' => $locationKey
];
if (!$model->ReservationLocationsApprovalUser->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
}
/**
* 施設削除にともなう予約データの削除
*
* @param ReservationLocation $model ReservationLocation
* @param string $locationKey 施設キー
* @throws InternalErrorException
* @return void
*/
public function deleteEventData(ReservationLocation $model, $locationKey) {
// 削除するReservationEvent.id 取得
$conditions = [
$model->ReservationEvent->alias . '.location_key' => $locationKey
];
$reserveIds = $model->ReservationEvent->find(
'list',
[
'recursive' => -1,
'conditions' => $conditions
]
);
$reserveIds = array_values($reserveIds);
//// ReservationEventContent 削除
//$conditions = [
// $model->ReservationEventContent->alias . '.reservation_event_id' => $reserveIds
//];
//if (!$model->ReservationEventContent->deleteAll($conditions)) {
// throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
//}
// ReservationEventShareUser 削除
$conditions = [
$model->ReservationEventShareUser->alias . '.reservation_event_id' => $reserveIds
];
if (!$model->ReservationEventShareUser->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
// ReservationEvent 削除
$conditions = [
$model->ReservationEvent->alias . '.location_key' => $locationKey
];
if (!$model->ReservationEvent->deleteAll($conditions)) {
throw new InternalErrorException(__d('net_commons', 'Internal Server Error'));
}
}
}