1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\core\services\commands\registration; |
3
|
|
|
|
4
|
|
|
use EE_Line_Item; |
5
|
|
|
use EE_Registration; |
6
|
|
|
use EE_Ticket; |
7
|
|
|
use EE_Transaction; |
8
|
|
|
use EEM_Registration; |
9
|
|
|
use EventEspresso\core\domain\services\capabilities\CapCheck; |
10
|
|
|
use EventEspresso\core\domain\services\capabilities\CapCheckInterface; |
11
|
|
|
use EventEspresso\core\exceptions\InvalidEntityException; |
12
|
|
|
use EventEspresso\core\services\commands\Command; |
13
|
|
|
use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
14
|
|
|
|
15
|
|
|
if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
16
|
|
|
exit('No direct script access allowed'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class CreateRegistrationCommand |
23
|
|
|
* DTO for passing data to a CreateRegistrationCommandHandler |
24
|
|
|
* |
25
|
|
|
* @package Event Espresso |
26
|
|
|
* @author Brent Christensen |
27
|
|
|
* @since 4.9.0 |
28
|
|
|
*/ |
29
|
|
|
class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EE_Transaction $transaction |
34
|
|
|
*/ |
35
|
|
|
private $transaction; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var EE_Ticket $ticket |
39
|
|
|
*/ |
40
|
|
|
private $ticket; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var EE_Line_Item $ticket_line_item |
44
|
|
|
*/ |
45
|
|
|
private $ticket_line_item; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var int $reg_count |
49
|
|
|
*/ |
50
|
|
|
private $reg_count; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var int $reg_group_size |
54
|
|
|
*/ |
55
|
|
|
private $reg_group_size; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string $reg_status |
59
|
|
|
*/ |
60
|
|
|
private $reg_status; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var EE_Registration $registration |
64
|
|
|
*/ |
65
|
|
|
protected $registration; |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* CreateRegistrationCommand constructor. |
71
|
|
|
* |
72
|
|
|
* @param EE_Transaction $transaction |
73
|
|
|
* @param EE_Line_Item $ticket_line_item |
74
|
|
|
* @param int $reg_count |
75
|
|
|
* @param int $reg_group_size |
76
|
|
|
* @param string $reg_status |
77
|
|
|
* @throws InvalidEntityException |
78
|
|
|
*/ |
79
|
|
|
public function __construct( |
80
|
|
|
EE_Transaction $transaction, |
81
|
|
|
EE_Line_Item $ticket_line_item, |
82
|
|
|
$reg_count = 1, |
83
|
|
|
$reg_group_size = 0, |
84
|
|
|
$reg_status = EEM_Registration::status_id_incomplete |
85
|
|
|
) { |
86
|
|
|
// grab the related ticket object for this line_item |
87
|
|
|
$this->ticket = $ticket_line_item->ticket(); |
88
|
|
View Code Duplication |
if ( ! $this->ticket instanceof EE_Ticket) { |
89
|
|
|
throw new InvalidEntityException( |
90
|
|
|
is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
91
|
|
|
'EE_Ticket', |
92
|
|
|
sprintf( |
93
|
|
|
__('Line item %s did not contain a valid ticket', 'event_espresso'), |
94
|
|
|
$ticket_line_item->ID() |
95
|
|
|
) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
$this->transaction = $transaction; |
99
|
|
|
$this->ticket_line_item = $ticket_line_item; |
100
|
|
|
$this->reg_count = absint($reg_count); |
101
|
|
|
$this->reg_group_size = absint($reg_group_size); |
102
|
|
|
$this->reg_status = $reg_status; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
109
|
|
|
* @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
110
|
|
|
*/ |
111
|
|
|
public function getCapCheck() |
112
|
|
|
{ |
113
|
|
|
if ( ! $this->cap_check instanceof CapCheckInterface) { |
114
|
|
|
return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
115
|
|
|
} |
116
|
|
|
return $this->cap_check; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return EE_Transaction |
123
|
|
|
*/ |
124
|
|
|
public function transaction() |
125
|
|
|
{ |
126
|
|
|
return $this->transaction; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return EE_Ticket |
133
|
|
|
*/ |
134
|
|
|
public function ticket() |
135
|
|
|
{ |
136
|
|
|
return $this->ticket; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return EE_Line_Item |
143
|
|
|
*/ |
144
|
|
|
public function ticketLineItem() |
145
|
|
|
{ |
146
|
|
|
return $this->ticket_line_item; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return int |
153
|
|
|
*/ |
154
|
|
|
public function regCount() |
155
|
|
|
{ |
156
|
|
|
return $this->reg_count; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return int |
163
|
|
|
*/ |
164
|
|
|
public function regGroupSize() |
165
|
|
|
{ |
166
|
|
|
return $this->reg_group_size; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function regStatus() |
175
|
|
|
{ |
176
|
|
|
return $this->reg_status; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return EE_Registration |
183
|
|
|
*/ |
184
|
|
|
public function registration() |
185
|
|
|
{ |
186
|
|
|
return $this->registration; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
// End of file CreateRegistrationCommand.php |
193
|
|
|
// Location: /CreateRegistrationCommand.php |