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