1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\admin\events\data; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use EE_Admin_Page; |
7
|
|
|
use EE_Error; |
8
|
|
|
use EEH_Template; |
9
|
|
|
use EEM_Datetime; |
10
|
|
|
use EEM_Event; |
11
|
|
|
use EEM_Registration; |
12
|
|
|
use EventEspresso\admin_pages\events\form_sections\ConfirmEventDeletionForm; |
13
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
14
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
15
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
16
|
|
|
use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao; |
17
|
|
|
use Events_Admin_Page; |
18
|
|
|
use InvalidArgumentException; |
19
|
|
|
use ReflectionException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class PreviewDeletion |
23
|
|
|
* |
24
|
|
|
* Displays the important data that will be deleted. If the form had been submitted earlier but wasn't valid, the |
25
|
|
|
* user is redirected here, and the forms system takes care of populating the form with that invalid data. |
26
|
|
|
* |
27
|
|
|
* @package Event Espresso |
28
|
|
|
* @author Mike Nelson |
29
|
|
|
* @since $VID:$ |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
class PreviewDeletion |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var NodeGroupDao |
36
|
|
|
*/ |
37
|
|
|
protected $dao; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var EEM_Event |
41
|
|
|
*/ |
42
|
|
|
protected $event_model; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var EEM_Datetime |
46
|
|
|
*/ |
47
|
|
|
protected $datetime_model; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var EEM_Registration |
51
|
|
|
*/ |
52
|
|
|
protected $registration_model; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* PreviewDeletion constructor. |
56
|
|
|
* @param NodeGroupDao $dao |
57
|
|
|
* @param EEM_Event $event_model |
58
|
|
|
* @param EEM_Datetime $datetime_model |
59
|
|
|
* @param EEM_Registration $registration_model |
60
|
|
|
*/ |
61
|
|
|
public function __construct( |
62
|
|
|
NodeGroupDao $dao, |
63
|
|
|
EEM_Event $event_model, |
64
|
|
|
EEM_Datetime $datetime_model, |
65
|
|
|
EEM_Registration $registration_model |
66
|
|
|
) { |
67
|
|
|
$this->dao = $dao; |
68
|
|
|
$this->event_model = $event_model; |
69
|
|
|
$this->datetime_model = $datetime_model; |
70
|
|
|
$this->registration_model = $registration_model; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Renders the preview deletion page. |
75
|
|
|
* @since $VID:$ |
76
|
|
|
* @param $request_data |
77
|
|
|
* @param $admin_base_url |
78
|
|
|
* @return array |
79
|
|
|
* @throws UnexpectedEntityException |
80
|
|
|
* @throws DomainException |
81
|
|
|
* @throws EE_Error |
82
|
|
|
* @throws InvalidDataTypeException |
83
|
|
|
* @throws InvalidInterfaceException |
84
|
|
|
* @throws InvalidArgumentException |
85
|
|
|
* @throws ReflectionException |
86
|
|
|
*/ |
87
|
|
|
public function handle($request_data, $admin_base_url) |
88
|
|
|
{ |
89
|
|
|
$deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
90
|
|
|
$models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
91
|
|
|
$event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
92
|
|
|
if (empty($event_ids) || !is_array($event_ids)) { |
93
|
|
|
throw new EE_Error( |
94
|
|
|
esc_html__('No Events were found to delete.', 'event_espresso') |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
$datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
98
|
|
|
if (!is_array($datetime_ids)) { |
99
|
|
|
throw new UnexpectedEntityException($datetime_ids, 'array'); |
100
|
|
|
} |
101
|
|
|
$registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
102
|
|
|
if (!is_array($registration_ids)) { |
103
|
|
|
throw new UnexpectedEntityException($registration_ids, 'array'); |
104
|
|
|
} |
105
|
|
|
$num_registrations_to_show = 10; |
106
|
|
|
$reg_count = count($registration_ids); |
107
|
|
|
if ($reg_count > $num_registrations_to_show) { |
108
|
|
|
$registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
109
|
|
|
} |
110
|
|
|
$form = new ConfirmEventDeletionForm($event_ids); |
111
|
|
|
$events = $this->event_model->get_all_deleted_and_undeleted( |
112
|
|
|
[ |
113
|
|
|
[ |
114
|
|
|
'EVT_ID' => ['IN', $event_ids] |
115
|
|
|
] |
116
|
|
|
] |
117
|
|
|
); |
118
|
|
|
$datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
119
|
|
|
[ |
120
|
|
|
[ |
121
|
|
|
'DTT_ID' => ['IN', $datetime_ids] |
122
|
|
|
] |
123
|
|
|
] |
124
|
|
|
); |
125
|
|
|
$registrations = $this->registration_model->get_all_deleted_and_undeleted( |
126
|
|
|
[ |
127
|
|
|
[ |
128
|
|
|
'REG_ID' => ['IN', $registration_ids] |
129
|
|
|
] |
130
|
|
|
] |
131
|
|
|
); |
132
|
|
|
$confirm_deletion_args = [ |
133
|
|
|
'action' => 'confirm_deletion', |
134
|
|
|
'deletion_job_code' => $deletion_job_code |
135
|
|
|
]; |
136
|
|
|
return [ |
137
|
|
|
'admin_page_content' => EEH_Template::display_template( |
138
|
|
|
EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
139
|
|
|
[ |
140
|
|
|
'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
141
|
|
|
$confirm_deletion_args, |
142
|
|
|
$admin_base_url |
143
|
|
|
), |
144
|
|
|
'form' => $form, |
145
|
|
|
'events' => $events, |
146
|
|
|
'datetimes' => $datetimes, |
147
|
|
|
'registrations' => $registrations, |
148
|
|
|
'reg_count' => $reg_count, |
149
|
|
|
'num_registrations_to_show' => $num_registrations_to_show |
150
|
|
|
], |
151
|
|
|
true |
152
|
|
|
) |
153
|
|
|
]; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
// End of file PreviewDeletion.php |
157
|
|
|
// Location: EventEspresso\core\domain\services\admin\events\data/PreviewDeletion.php |
158
|
|
|
|