@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getReflectionClass($class_name) |
62 | 62 | { |
63 | - if (! is_string($class_name)) { |
|
63 | + if ( ! is_string($class_name)) { |
|
64 | 64 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
65 | 65 | } |
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
66 | + if ( ! isset($this->classes[$class_name])) { |
|
67 | + $this->classes[$class_name] = new ReflectionClass($class_name); |
|
68 | 68 | } |
69 | - return $this->classes[ $class_name ]; |
|
69 | + return $this->classes[$class_name]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getConstructor($class_name) |
80 | 80 | { |
81 | - if (! is_string($class_name)) { |
|
81 | + if ( ! is_string($class_name)) { |
|
82 | 82 | throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
83 | 83 | } |
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
84 | + if ( ! isset($this->constructors[$class_name])) { |
|
85 | 85 | $reflection_class = $this->getReflectionClass($class_name); |
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
86 | + $this->constructors[$class_name] = $reflection_class->getConstructor(); |
|
87 | 87 | } |
88 | - return $this->constructors[ $class_name ]; |
|
88 | + return $this->constructors[$class_name]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getParameters($class_name) |
111 | 111 | { |
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
112 | + if ( ! isset($this->parameters[$class_name])) { |
|
113 | 113 | $constructor = $this->getConstructor($class_name); |
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
114 | + $this->parameters[$class_name] = $constructor->getParameters(); |
|
115 | 115 | } |
116 | - return $this->parameters[ $class_name ]; |
|
116 | + return $this->parameters[$class_name]; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -149,27 +149,27 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
151 | 151 | { |
152 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
153 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
152 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) { |
|
153 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
154 | 154 | } |
155 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
156 | - $this->parameter_classes[ $class_name ] = array(); |
|
155 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
156 | + $this->parameter_classes[$class_name] = array(); |
|
157 | 157 | } |
158 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
159 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
158 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
159 | + $this->parameter_classes[$class_name][$index] = array(); |
|
160 | 160 | } |
161 | 161 | // ReflectionParameter::getClass() is deprecated in PHP 8+ |
162 | 162 | if (PHP_VERSION_ID >= 80000) { |
163 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = |
|
163 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = |
|
164 | 164 | $param->getType() instanceof ReflectionNamedType |
165 | 165 | ? $param->getType()->getName() |
166 | 166 | : null; |
167 | 167 | } else { |
168 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
168 | + $this->parameter_classes[$class_name][$index]['param_class_name'] = $param->getClass() |
|
169 | 169 | ? $param->getClass()->getName() |
170 | 170 | : null; |
171 | 171 | } |
172 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
172 | + return $this->parameter_classes[$class_name][$index]['param_class_name']; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | |
@@ -181,19 +181,19 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
183 | 183 | { |
184 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
185 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
184 | + if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) { |
|
185 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
186 | 186 | } |
187 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
188 | - $this->parameter_classes[ $class_name ] = array(); |
|
187 | + if ( ! isset($this->parameter_classes[$class_name])) { |
|
188 | + $this->parameter_classes[$class_name] = array(); |
|
189 | 189 | } |
190 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
191 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
190 | + if ( ! isset($this->parameter_classes[$class_name][$index])) { |
|
191 | + $this->parameter_classes[$class_name][$index] = array(); |
|
192 | 192 | } |
193 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
193 | + $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable() |
|
194 | 194 | ? $param->getDefaultValue() |
195 | 195 | : null; |
196 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
196 | + return $this->parameter_classes[$class_name][$index]['param_class_default']; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function getProperties($class_name) |
207 | 207 | { |
208 | - if (! isset($this->properties[ $class_name ])) { |
|
208 | + if ( ! isset($this->properties[$class_name])) { |
|
209 | 209 | $reflection_class = $this->getReflectionClass($class_name); |
210 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
210 | + $this->properties[$class_name] = $reflection_class->getProperties(); |
|
211 | 211 | } |
212 | - return $this->properties[ $class_name ]; |
|
212 | + return $this->properties[$class_name]; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function getMethods($class_name) |
235 | 235 | { |
236 | - if (! isset($this->methods[ $class_name ])) { |
|
236 | + if ( ! isset($this->methods[$class_name])) { |
|
237 | 237 | $reflection_class = $this->getReflectionClass($class_name); |
238 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
238 | + $this->methods[$class_name] = $reflection_class->getMethods(); |
|
239 | 239 | } |
240 | - return $this->methods[ $class_name ]; |
|
240 | + return $this->methods[$class_name]; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 |
@@ -21,255 +21,255 @@ |
||
21 | 21 | class Mirror |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var ReflectionClass[] $classes |
|
26 | - */ |
|
27 | - private $classes = array(); |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ReflectionMethod[] $constructors |
|
31 | - */ |
|
32 | - private $constructors = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * @var ReflectionParameter[][] $parameters |
|
36 | - */ |
|
37 | - private $parameters = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @var ReflectionParameter[][] $parameters |
|
41 | - */ |
|
42 | - private $parameter_classes = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var ReflectionProperty[][] $properties |
|
46 | - */ |
|
47 | - private $properties = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * @var ReflectionMethod[][] $methods |
|
51 | - */ |
|
52 | - private $methods = array(); |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $class_name |
|
57 | - * @return ReflectionClass |
|
58 | - * @throws ReflectionException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
61 | - public function getReflectionClass($class_name) |
|
62 | - { |
|
63 | - if (! is_string($class_name)) { |
|
64 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | - } |
|
66 | - if (! isset($this->classes[ $class_name ])) { |
|
67 | - $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | - } |
|
69 | - return $this->classes[ $class_name ]; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $class_name |
|
75 | - * @return ReflectionMethod |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function getConstructor($class_name) |
|
80 | - { |
|
81 | - if (! is_string($class_name)) { |
|
82 | - throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | - } |
|
84 | - if (! isset($this->constructors[ $class_name ])) { |
|
85 | - $reflection_class = $this->getReflectionClass($class_name); |
|
86 | - $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | - } |
|
88 | - return $this->constructors[ $class_name ]; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param ReflectionClass $reflection_class |
|
94 | - * @return ReflectionMethod |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | - { |
|
100 | - return $this->getConstructor($reflection_class->getName()); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param string $class_name |
|
106 | - * @return ReflectionParameter[] |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public function getParameters($class_name) |
|
111 | - { |
|
112 | - if (! isset($this->parameters[ $class_name ])) { |
|
113 | - $constructor = $this->getConstructor($class_name); |
|
114 | - $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | - } |
|
116 | - return $this->parameters[ $class_name ]; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param ReflectionClass $reflection_class |
|
122 | - * @return ReflectionParameter[] |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - * @throws ReflectionException |
|
125 | - */ |
|
126 | - public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | - { |
|
128 | - return $this->getParameters($reflection_class->getName()); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param ReflectionMethod $constructor |
|
134 | - * @return ReflectionParameter[] |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | - { |
|
140 | - return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * returns array of ReflectionParameter objects for parameters that are NOT optional |
|
146 | - * |
|
147 | - * @param string $class_name |
|
148 | - * @return ReflectionParameter[] |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function getRequiredParameters($class_name) |
|
153 | - { |
|
154 | - $required_parameters = []; |
|
155 | - $parameters = $this->getParameters($class_name); |
|
156 | - foreach ($parameters as $parameter) { |
|
157 | - if ($parameter instanceof ReflectionParameter && ! $parameter->isOptional()) { |
|
158 | - $required_parameters[] = $parameter; |
|
159 | - } |
|
160 | - } |
|
161 | - return $required_parameters; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param ReflectionParameter $param |
|
167 | - * @param string $class_name |
|
168 | - * @param string $index |
|
169 | - * @return string|null |
|
170 | - */ |
|
171 | - public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
172 | - { |
|
173 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
174 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
175 | - } |
|
176 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
177 | - $this->parameter_classes[ $class_name ] = array(); |
|
178 | - } |
|
179 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
180 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
181 | - } |
|
182 | - // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
183 | - if (PHP_VERSION_ID >= 80000) { |
|
184 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = |
|
185 | - $param->getType() instanceof ReflectionNamedType |
|
186 | - ? $param->getType()->getName() |
|
187 | - : null; |
|
188 | - } else { |
|
189 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
190 | - ? $param->getClass()->getName() |
|
191 | - : null; |
|
192 | - } |
|
193 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param ReflectionParameter $param |
|
199 | - * @param string $class_name |
|
200 | - * @param string $index |
|
201 | - * @return string|null |
|
202 | - */ |
|
203 | - public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
204 | - { |
|
205 | - if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
206 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
207 | - } |
|
208 | - if (! isset($this->parameter_classes[ $class_name ])) { |
|
209 | - $this->parameter_classes[ $class_name ] = array(); |
|
210 | - } |
|
211 | - if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
212 | - $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
213 | - } |
|
214 | - $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
215 | - ? $param->getDefaultValue() |
|
216 | - : null; |
|
217 | - return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param string $class_name |
|
223 | - * @return ReflectionProperty[] |
|
224 | - * @throws InvalidDataTypeException |
|
225 | - * @throws ReflectionException |
|
226 | - */ |
|
227 | - public function getProperties($class_name) |
|
228 | - { |
|
229 | - if (! isset($this->properties[ $class_name ])) { |
|
230 | - $reflection_class = $this->getReflectionClass($class_name); |
|
231 | - $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
232 | - } |
|
233 | - return $this->properties[ $class_name ]; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param ReflectionClass $reflection_class |
|
239 | - * @return ReflectionProperty[] |
|
240 | - * @throws InvalidDataTypeException |
|
241 | - * @throws ReflectionException |
|
242 | - */ |
|
243 | - public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
244 | - { |
|
245 | - return $this->getProperties($reflection_class->getName()); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param string $class_name |
|
251 | - * @return ReflectionMethod[] |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws ReflectionException |
|
254 | - */ |
|
255 | - public function getMethods($class_name) |
|
256 | - { |
|
257 | - if (! isset($this->methods[ $class_name ])) { |
|
258 | - $reflection_class = $this->getReflectionClass($class_name); |
|
259 | - $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
260 | - } |
|
261 | - return $this->methods[ $class_name ]; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param ReflectionClass $reflection_class ) |
|
267 | - * @return ReflectionMethod[] |
|
268 | - * @throws InvalidDataTypeException |
|
269 | - * @throws ReflectionException |
|
270 | - */ |
|
271 | - public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
272 | - { |
|
273 | - return $this->getMethods($reflection_class->getName()); |
|
274 | - } |
|
24 | + /** |
|
25 | + * @var ReflectionClass[] $classes |
|
26 | + */ |
|
27 | + private $classes = array(); |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ReflectionMethod[] $constructors |
|
31 | + */ |
|
32 | + private $constructors = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * @var ReflectionParameter[][] $parameters |
|
36 | + */ |
|
37 | + private $parameters = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @var ReflectionParameter[][] $parameters |
|
41 | + */ |
|
42 | + private $parameter_classes = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var ReflectionProperty[][] $properties |
|
46 | + */ |
|
47 | + private $properties = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * @var ReflectionMethod[][] $methods |
|
51 | + */ |
|
52 | + private $methods = array(); |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $class_name |
|
57 | + * @return ReflectionClass |
|
58 | + * @throws ReflectionException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | + public function getReflectionClass($class_name) |
|
62 | + { |
|
63 | + if (! is_string($class_name)) { |
|
64 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
65 | + } |
|
66 | + if (! isset($this->classes[ $class_name ])) { |
|
67 | + $this->classes[ $class_name ] = new ReflectionClass($class_name); |
|
68 | + } |
|
69 | + return $this->classes[ $class_name ]; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $class_name |
|
75 | + * @return ReflectionMethod |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function getConstructor($class_name) |
|
80 | + { |
|
81 | + if (! is_string($class_name)) { |
|
82 | + throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)'); |
|
83 | + } |
|
84 | + if (! isset($this->constructors[ $class_name ])) { |
|
85 | + $reflection_class = $this->getReflectionClass($class_name); |
|
86 | + $this->constructors[ $class_name ] = $reflection_class->getConstructor(); |
|
87 | + } |
|
88 | + return $this->constructors[ $class_name ]; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param ReflectionClass $reflection_class |
|
94 | + * @return ReflectionMethod |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getConstructorFromReflection(ReflectionClass $reflection_class) |
|
99 | + { |
|
100 | + return $this->getConstructor($reflection_class->getName()); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param string $class_name |
|
106 | + * @return ReflectionParameter[] |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public function getParameters($class_name) |
|
111 | + { |
|
112 | + if (! isset($this->parameters[ $class_name ])) { |
|
113 | + $constructor = $this->getConstructor($class_name); |
|
114 | + $this->parameters[ $class_name ] = $constructor->getParameters(); |
|
115 | + } |
|
116 | + return $this->parameters[ $class_name ]; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param ReflectionClass $reflection_class |
|
122 | + * @return ReflectionParameter[] |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + * @throws ReflectionException |
|
125 | + */ |
|
126 | + public function getParametersFromReflection(ReflectionClass $reflection_class) |
|
127 | + { |
|
128 | + return $this->getParameters($reflection_class->getName()); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param ReflectionMethod $constructor |
|
134 | + * @return ReflectionParameter[] |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function getParametersFromReflectionConstructor(ReflectionMethod $constructor) |
|
139 | + { |
|
140 | + return $this->getParameters($constructor->getDeclaringClass()); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * returns array of ReflectionParameter objects for parameters that are NOT optional |
|
146 | + * |
|
147 | + * @param string $class_name |
|
148 | + * @return ReflectionParameter[] |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function getRequiredParameters($class_name) |
|
153 | + { |
|
154 | + $required_parameters = []; |
|
155 | + $parameters = $this->getParameters($class_name); |
|
156 | + foreach ($parameters as $parameter) { |
|
157 | + if ($parameter instanceof ReflectionParameter && ! $parameter->isOptional()) { |
|
158 | + $required_parameters[] = $parameter; |
|
159 | + } |
|
160 | + } |
|
161 | + return $required_parameters; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param ReflectionParameter $param |
|
167 | + * @param string $class_name |
|
168 | + * @param string $index |
|
169 | + * @return string|null |
|
170 | + */ |
|
171 | + public function getParameterClassName(ReflectionParameter $param, $class_name, $index) |
|
172 | + { |
|
173 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) { |
|
174 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
175 | + } |
|
176 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
177 | + $this->parameter_classes[ $class_name ] = array(); |
|
178 | + } |
|
179 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
180 | + $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
181 | + } |
|
182 | + // ReflectionParameter::getClass() is deprecated in PHP 8+ |
|
183 | + if (PHP_VERSION_ID >= 80000) { |
|
184 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = |
|
185 | + $param->getType() instanceof ReflectionNamedType |
|
186 | + ? $param->getType()->getName() |
|
187 | + : null; |
|
188 | + } else { |
|
189 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass() |
|
190 | + ? $param->getClass()->getName() |
|
191 | + : null; |
|
192 | + } |
|
193 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_name']; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param ReflectionParameter $param |
|
199 | + * @param string $class_name |
|
200 | + * @param string $index |
|
201 | + * @return string|null |
|
202 | + */ |
|
203 | + public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index) |
|
204 | + { |
|
205 | + if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) { |
|
206 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
207 | + } |
|
208 | + if (! isset($this->parameter_classes[ $class_name ])) { |
|
209 | + $this->parameter_classes[ $class_name ] = array(); |
|
210 | + } |
|
211 | + if (! isset($this->parameter_classes[ $class_name ][ $index ])) { |
|
212 | + $this->parameter_classes[ $class_name ][ $index ] = array(); |
|
213 | + } |
|
214 | + $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable() |
|
215 | + ? $param->getDefaultValue() |
|
216 | + : null; |
|
217 | + return $this->parameter_classes[ $class_name ][ $index ]['param_class_default']; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @param string $class_name |
|
223 | + * @return ReflectionProperty[] |
|
224 | + * @throws InvalidDataTypeException |
|
225 | + * @throws ReflectionException |
|
226 | + */ |
|
227 | + public function getProperties($class_name) |
|
228 | + { |
|
229 | + if (! isset($this->properties[ $class_name ])) { |
|
230 | + $reflection_class = $this->getReflectionClass($class_name); |
|
231 | + $this->properties[ $class_name ] = $reflection_class->getProperties(); |
|
232 | + } |
|
233 | + return $this->properties[ $class_name ]; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param ReflectionClass $reflection_class |
|
239 | + * @return ReflectionProperty[] |
|
240 | + * @throws InvalidDataTypeException |
|
241 | + * @throws ReflectionException |
|
242 | + */ |
|
243 | + public function getPropertiesFromReflection(ReflectionClass $reflection_class) |
|
244 | + { |
|
245 | + return $this->getProperties($reflection_class->getName()); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param string $class_name |
|
251 | + * @return ReflectionMethod[] |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws ReflectionException |
|
254 | + */ |
|
255 | + public function getMethods($class_name) |
|
256 | + { |
|
257 | + if (! isset($this->methods[ $class_name ])) { |
|
258 | + $reflection_class = $this->getReflectionClass($class_name); |
|
259 | + $this->methods[ $class_name ] = $reflection_class->getMethods(); |
|
260 | + } |
|
261 | + return $this->methods[ $class_name ]; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param ReflectionClass $reflection_class ) |
|
267 | + * @return ReflectionMethod[] |
|
268 | + * @throws InvalidDataTypeException |
|
269 | + * @throws ReflectionException |
|
270 | + */ |
|
271 | + public function getMethodsFromReflection(ReflectionClass $reflection_class) |
|
272 | + { |
|
273 | + return $this->getMethods($reflection_class->getName()); |
|
274 | + } |
|
275 | 275 | } |
@@ -19,86 +19,86 @@ discard block |
||
19 | 19 | class Stats |
20 | 20 | { |
21 | 21 | |
22 | - const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Config |
|
26 | - */ |
|
27 | - private $config; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @var StatsGatherer |
|
32 | - */ |
|
33 | - private $stats_gatherer; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Maintenance_Mode |
|
38 | - */ |
|
39 | - private $maintenance_mode; |
|
40 | - |
|
41 | - public function __construct( |
|
42 | - Config $config, |
|
43 | - EE_Maintenance_Mode $maintenance_mode, |
|
44 | - StatsGatherer $stats_gatherer |
|
45 | - ) { |
|
46 | - $this->config = $config; |
|
47 | - $this->maintenance_mode = $maintenance_mode; |
|
48 | - $this->stats_gatherer = $stats_gatherer; |
|
49 | - $this->setUxipNotices(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Displays uxip opt-in notice if necessary. |
|
55 | - */ |
|
56 | - private function setUxipNotices() |
|
57 | - { |
|
58 | - if ($this->canDisplayNotices()) { |
|
59 | - add_action('admin_notices', array($this, 'optinNotice')); |
|
60 | - add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
61 | - add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * This returns the callback that PluginUpdateEngineChecker will use for getting any extra stats to send. |
|
68 | - * |
|
69 | - * @return Closure |
|
70 | - */ |
|
71 | - public function statsCallback() |
|
72 | - { |
|
73 | - // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
74 | - return function () { |
|
75 | - // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
76 | - if (! $this->sendStats()) { |
|
77 | - return array(); |
|
78 | - } |
|
79 | - return $this->stats_gatherer->stats(); |
|
80 | - }; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Return whether notices can be displayed or not |
|
86 | - * |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - private function canDisplayNotices() |
|
90 | - { |
|
91 | - return ! $this->config->hasNotifiedForUxip() |
|
92 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
98 | - */ |
|
99 | - public function optinNotice() |
|
100 | - { |
|
101 | - ?> |
|
22 | + const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Config |
|
26 | + */ |
|
27 | + private $config; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @var StatsGatherer |
|
32 | + */ |
|
33 | + private $stats_gatherer; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Maintenance_Mode |
|
38 | + */ |
|
39 | + private $maintenance_mode; |
|
40 | + |
|
41 | + public function __construct( |
|
42 | + Config $config, |
|
43 | + EE_Maintenance_Mode $maintenance_mode, |
|
44 | + StatsGatherer $stats_gatherer |
|
45 | + ) { |
|
46 | + $this->config = $config; |
|
47 | + $this->maintenance_mode = $maintenance_mode; |
|
48 | + $this->stats_gatherer = $stats_gatherer; |
|
49 | + $this->setUxipNotices(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Displays uxip opt-in notice if necessary. |
|
55 | + */ |
|
56 | + private function setUxipNotices() |
|
57 | + { |
|
58 | + if ($this->canDisplayNotices()) { |
|
59 | + add_action('admin_notices', array($this, 'optinNotice')); |
|
60 | + add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
61 | + add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * This returns the callback that PluginUpdateEngineChecker will use for getting any extra stats to send. |
|
68 | + * |
|
69 | + * @return Closure |
|
70 | + */ |
|
71 | + public function statsCallback() |
|
72 | + { |
|
73 | + // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
74 | + return function () { |
|
75 | + // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
76 | + if (! $this->sendStats()) { |
|
77 | + return array(); |
|
78 | + } |
|
79 | + return $this->stats_gatherer->stats(); |
|
80 | + }; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Return whether notices can be displayed or not |
|
86 | + * |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + private function canDisplayNotices() |
|
90 | + { |
|
91 | + return ! $this->config->hasNotifiedForUxip() |
|
92 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
98 | + */ |
|
99 | + public function optinNotice() |
|
100 | + { |
|
101 | + ?> |
|
102 | 102 | <div class="updated data-collect-optin" id="espresso-data-collect-optin-container"> |
103 | 103 | <div id="data-collect-optin-options-container"> |
104 | 104 | <span class="dashicons dashicons-admin-site"></span> |
@@ -111,125 +111,125 @@ discard block |
||
111 | 111 | </div> |
112 | 112 | </div> |
113 | 113 | <?php |
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
119 | - * |
|
120 | - * @param bool $extra |
|
121 | - */ |
|
122 | - public static function optinText($extra = true) |
|
123 | - { |
|
124 | - if (! $extra) { |
|
125 | - echo '<h2 class="ee-admin-settings-hdr" ' |
|
126 | - . (! $extra ? 'id="UXIP_settings"' : '') |
|
127 | - . '>' |
|
128 | - . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
129 | - . EEH_Template::get_help_tab_link('organization_logo_info') |
|
130 | - . '</h2>'; |
|
131 | - printf( |
|
132 | - esc_html__( |
|
133 | - '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - '<p><em>', |
|
137 | - '</em></p>', |
|
138 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
139 | - '</a>', |
|
140 | - '<br><br>', |
|
141 | - '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
142 | - '</a>' |
|
143 | - ); |
|
144 | - } else { |
|
145 | - $settings_url = EEH_URL::add_query_args_and_nonce( |
|
146 | - array('action' => 'default'), |
|
147 | - admin_url('admin.php?page=espresso_general_settings') |
|
148 | - ); |
|
149 | - $settings_url .= '#UXIP_settings'; |
|
150 | - printf( |
|
151 | - esc_html__( |
|
152 | - 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
153 | - 'event_espresso' |
|
154 | - ), |
|
155 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
156 | - '</a>', |
|
157 | - '<a href="' . $settings_url . '" target="_blank">', |
|
158 | - '</a>' |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
166 | - */ |
|
167 | - public function enqueueScripts() |
|
168 | - { |
|
169 | - wp_register_script( |
|
170 | - 'ee-data-optin-js', |
|
171 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
172 | - array('jquery'), |
|
173 | - EVENT_ESPRESSO_VERSION, |
|
174 | - true |
|
175 | - ); |
|
176 | - wp_register_style( |
|
177 | - 'ee-data-optin-css', |
|
178 | - EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
179 | - array(), |
|
180 | - EVENT_ESPRESSO_VERSION |
|
181 | - ); |
|
182 | - |
|
183 | - wp_enqueue_script('ee-data-optin-js'); |
|
184 | - wp_enqueue_style('ee-data-optin-css'); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
190 | - */ |
|
191 | - public function ajaxHandler() |
|
192 | - { |
|
193 | - // verify nonce |
|
194 | - if (! isset($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
195 | - exit(); |
|
196 | - } |
|
197 | - |
|
198 | - // update has notified option |
|
199 | - $this->config->setHasNotifiedAboutUxip(); |
|
200 | - exit(); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Used to determine whether additional stats are sent. |
|
206 | - */ |
|
207 | - private function sendStats() |
|
208 | - { |
|
209 | - return $this->config->isOptedInForUxip() |
|
210 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
211 | - && $this->statSendTimestampExpired(); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
217 | - * Returns false otherwise. |
|
218 | - * |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - private function statSendTimestampExpired() |
|
222 | - { |
|
223 | - $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
224 | - if ($current_expiry === null) { |
|
225 | - add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
226 | - return true; |
|
227 | - } |
|
228 | - |
|
229 | - if (time() > (int) $current_expiry) { |
|
230 | - update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
231 | - return true; |
|
232 | - } |
|
233 | - return false; |
|
234 | - } |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
119 | + * |
|
120 | + * @param bool $extra |
|
121 | + */ |
|
122 | + public static function optinText($extra = true) |
|
123 | + { |
|
124 | + if (! $extra) { |
|
125 | + echo '<h2 class="ee-admin-settings-hdr" ' |
|
126 | + . (! $extra ? 'id="UXIP_settings"' : '') |
|
127 | + . '>' |
|
128 | + . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
129 | + . EEH_Template::get_help_tab_link('organization_logo_info') |
|
130 | + . '</h2>'; |
|
131 | + printf( |
|
132 | + esc_html__( |
|
133 | + '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + '<p><em>', |
|
137 | + '</em></p>', |
|
138 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
139 | + '</a>', |
|
140 | + '<br><br>', |
|
141 | + '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
142 | + '</a>' |
|
143 | + ); |
|
144 | + } else { |
|
145 | + $settings_url = EEH_URL::add_query_args_and_nonce( |
|
146 | + array('action' => 'default'), |
|
147 | + admin_url('admin.php?page=espresso_general_settings') |
|
148 | + ); |
|
149 | + $settings_url .= '#UXIP_settings'; |
|
150 | + printf( |
|
151 | + esc_html__( |
|
152 | + 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
153 | + 'event_espresso' |
|
154 | + ), |
|
155 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
156 | + '</a>', |
|
157 | + '<a href="' . $settings_url . '" target="_blank">', |
|
158 | + '</a>' |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
166 | + */ |
|
167 | + public function enqueueScripts() |
|
168 | + { |
|
169 | + wp_register_script( |
|
170 | + 'ee-data-optin-js', |
|
171 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
172 | + array('jquery'), |
|
173 | + EVENT_ESPRESSO_VERSION, |
|
174 | + true |
|
175 | + ); |
|
176 | + wp_register_style( |
|
177 | + 'ee-data-optin-css', |
|
178 | + EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
179 | + array(), |
|
180 | + EVENT_ESPRESSO_VERSION |
|
181 | + ); |
|
182 | + |
|
183 | + wp_enqueue_script('ee-data-optin-js'); |
|
184 | + wp_enqueue_style('ee-data-optin-css'); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
190 | + */ |
|
191 | + public function ajaxHandler() |
|
192 | + { |
|
193 | + // verify nonce |
|
194 | + if (! isset($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
195 | + exit(); |
|
196 | + } |
|
197 | + |
|
198 | + // update has notified option |
|
199 | + $this->config->setHasNotifiedAboutUxip(); |
|
200 | + exit(); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Used to determine whether additional stats are sent. |
|
206 | + */ |
|
207 | + private function sendStats() |
|
208 | + { |
|
209 | + return $this->config->isOptedInForUxip() |
|
210 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
211 | + && $this->statSendTimestampExpired(); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
217 | + * Returns false otherwise. |
|
218 | + * |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + private function statSendTimestampExpired() |
|
222 | + { |
|
223 | + $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
224 | + if ($current_expiry === null) { |
|
225 | + add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
226 | + return true; |
|
227 | + } |
|
228 | + |
|
229 | + if (time() > (int) $current_expiry) { |
|
230 | + update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
231 | + return true; |
|
232 | + } |
|
233 | + return false; |
|
234 | + } |
|
235 | 235 | } |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | public function statsCallback() |
72 | 72 | { |
73 | 73 | // returns a callback that can is used to retrieve the stats to send along to the pue server. |
74 | - return function () { |
|
74 | + return function() { |
|
75 | 75 | // we only send stats one a week, so let's see if our stat timestamp has expired. |
76 | - if (! $this->sendStats()) { |
|
76 | + if ( ! $this->sendStats()) { |
|
77 | 77 | return array(); |
78 | 78 | } |
79 | 79 | return $this->stats_gatherer->stats(); |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public static function optinText($extra = true) |
123 | 123 | { |
124 | - if (! $extra) { |
|
124 | + if ( ! $extra) { |
|
125 | 125 | echo '<h2 class="ee-admin-settings-hdr" ' |
126 | - . (! $extra ? 'id="UXIP_settings"' : '') |
|
126 | + . ( ! $extra ? 'id="UXIP_settings"' : '') |
|
127 | 127 | . '>' |
128 | 128 | . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
129 | 129 | . EEH_Template::get_help_tab_link('organization_logo_info') |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | ), |
155 | 155 | '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
156 | 156 | '</a>', |
157 | - '<a href="' . $settings_url . '" target="_blank">', |
|
157 | + '<a href="'.$settings_url.'" target="_blank">', |
|
158 | 158 | '</a>' |
159 | 159 | ); |
160 | 160 | } |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | { |
169 | 169 | wp_register_script( |
170 | 170 | 'ee-data-optin-js', |
171 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
171 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-data-optin.js', |
|
172 | 172 | array('jquery'), |
173 | 173 | EVENT_ESPRESSO_VERSION, |
174 | 174 | true |
175 | 175 | ); |
176 | 176 | wp_register_style( |
177 | 177 | 'ee-data-optin-css', |
178 | - EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
178 | + EE_GLOBAL_ASSETS_URL.'css/ee-data-optin.css', |
|
179 | 179 | array(), |
180 | 180 | EVENT_ESPRESSO_VERSION |
181 | 181 | ); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | public function ajaxHandler() |
192 | 192 | { |
193 | 193 | // verify nonce |
194 | - if (! isset($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
194 | + if ( ! isset($_POST['nonce']) || ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
195 | 195 | exit(); |
196 | 196 | } |
197 | 197 |
@@ -13,90 +13,90 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * Will hold an EE_Messages_Queue object |
|
18 | - * @type EE_Messages_Queue |
|
19 | - */ |
|
20 | - public $queue = array(); |
|
16 | + /** |
|
17 | + * Will hold an EE_Messages_Queue object |
|
18 | + * @type EE_Messages_Queue |
|
19 | + */ |
|
20 | + public $queue = array(); |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $messenger_name The messenger being used to send the message |
|
24 | - * @param string $message_type_name The message type being used to grab variations etc. |
|
25 | - * @param EE_Messages_Queue $queue |
|
26 | - * @param string $custom_subject Used if a custom subject is desired for the generated aggregate EE_Message object |
|
27 | - */ |
|
28 | - public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '') |
|
29 | - { |
|
30 | - $this->queue = $queue; |
|
31 | - parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle); |
|
32 | - if ($this->valid()) { |
|
33 | - $this->_message->set_content($this->_get_content()); |
|
34 | - $this->_message->set_subject($this->_get_subject($custom_subject)); |
|
35 | - $this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo()); |
|
36 | - } |
|
37 | - } |
|
22 | + /** |
|
23 | + * @param string $messenger_name The messenger being used to send the message |
|
24 | + * @param string $message_type_name The message type being used to grab variations etc. |
|
25 | + * @param EE_Messages_Queue $queue |
|
26 | + * @param string $custom_subject Used if a custom subject is desired for the generated aggregate EE_Message object |
|
27 | + */ |
|
28 | + public function __construct($messenger_name, $message_type_name, EE_Messages_Queue $queue, $custom_subject = '') |
|
29 | + { |
|
30 | + $this->queue = $queue; |
|
31 | + parent::__construct($messenger_name, $message_type_name, array(), '', false, EEM_Message::status_idle); |
|
32 | + if ($this->valid()) { |
|
33 | + $this->_message->set_content($this->_get_content()); |
|
34 | + $this->_message->set_subject($this->_get_subject($custom_subject)); |
|
35 | + $this->_message->set_GRP_ID($this->getGroupIdFromMessageRepo()); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Uses the EE_Messages_Queue currently set on this object to generate the content |
|
43 | - * for the single EE_Message aggregate object returned by get_EE_Message |
|
44 | - * @return string; |
|
45 | - */ |
|
46 | - protected function _get_content() |
|
47 | - { |
|
48 | - $content = ''; |
|
49 | - $this->queue->get_message_repository()->rewind(); |
|
50 | - while ($this->queue->get_message_repository()->valid()) { |
|
51 | - $content .= $this->queue->get_message_repository()->current()->content(); |
|
52 | - $this->queue->get_message_repository()->next(); |
|
53 | - } |
|
54 | - return $content; |
|
55 | - } |
|
41 | + /** |
|
42 | + * Uses the EE_Messages_Queue currently set on this object to generate the content |
|
43 | + * for the single EE_Message aggregate object returned by get_EE_Message |
|
44 | + * @return string; |
|
45 | + */ |
|
46 | + protected function _get_content() |
|
47 | + { |
|
48 | + $content = ''; |
|
49 | + $this->queue->get_message_repository()->rewind(); |
|
50 | + while ($this->queue->get_message_repository()->valid()) { |
|
51 | + $content .= $this->queue->get_message_repository()->current()->content(); |
|
52 | + $this->queue->get_message_repository()->next(); |
|
53 | + } |
|
54 | + return $content; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object. |
|
60 | - * @param string $custom_subject |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function _get_subject($custom_subject = '') |
|
65 | - { |
|
66 | - if (! empty($custom_subject)) { |
|
67 | - return $custom_subject; |
|
68 | - } |
|
69 | - $this->queue->get_message_repository()->rewind(); |
|
70 | - $count_of_items = $this->queue->get_message_repository()->count(); |
|
58 | + /** |
|
59 | + * Return a subject string to use for `MSG_Subject` in the aggregate EE_Message object. |
|
60 | + * @param string $custom_subject |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function _get_subject($custom_subject = '') |
|
65 | + { |
|
66 | + if (! empty($custom_subject)) { |
|
67 | + return $custom_subject; |
|
68 | + } |
|
69 | + $this->queue->get_message_repository()->rewind(); |
|
70 | + $count_of_items = $this->queue->get_message_repository()->count(); |
|
71 | 71 | |
72 | - // if $count of items in queue == 1, then let's just return the subject for that item. |
|
73 | - if ($count_of_items === 1) { |
|
74 | - return $this->queue->get_message_repository()->current()->subject(); |
|
75 | - } |
|
76 | - // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder |
|
77 | - return sprintf( |
|
78 | - _n( |
|
79 | - 'Showing Aggregate output for 1 result', |
|
80 | - 'Showing Aggregate output for %d items', |
|
81 | - $count_of_items, |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $count_of_items |
|
85 | - ); |
|
86 | - // phpcs:enable |
|
87 | - } |
|
72 | + // if $count of items in queue == 1, then let's just return the subject for that item. |
|
73 | + if ($count_of_items === 1) { |
|
74 | + return $this->queue->get_message_repository()->current()->subject(); |
|
75 | + } |
|
76 | + // phpcs:disable WordPress.WP.I18n.MissingSingularPlaceholder |
|
77 | + return sprintf( |
|
78 | + _n( |
|
79 | + 'Showing Aggregate output for 1 result', |
|
80 | + 'Showing Aggregate output for %d items', |
|
81 | + $count_of_items, |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $count_of_items |
|
85 | + ); |
|
86 | + // phpcs:enable |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID |
|
92 | - * for the single EE_Message aggregate object returned by get_EE_Message |
|
93 | - * @return int; |
|
94 | - */ |
|
95 | - protected function getGroupIdFromMessageRepo() |
|
96 | - { |
|
97 | - $this->queue->get_message_repository()->rewind(); |
|
98 | - if ($this->queue->get_message_repository()->valid()) { |
|
99 | - return $this->queue->get_message_repository()->current()->GRP_ID(); |
|
100 | - } |
|
101 | - } |
|
90 | + /** |
|
91 | + * Uses the EE_Messages_Queue currently set on this object to set the GRP_ID |
|
92 | + * for the single EE_Message aggregate object returned by get_EE_Message |
|
93 | + * @return int; |
|
94 | + */ |
|
95 | + protected function getGroupIdFromMessageRepo() |
|
96 | + { |
|
97 | + $this->queue->get_message_repository()->rewind(); |
|
98 | + if ($this->queue->get_message_repository()->valid()) { |
|
99 | + return $this->queue->get_message_repository()->current()->GRP_ID(); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | } |
@@ -17,2121 +17,2121 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Used to reference when a registration has never been checked in. |
|
22 | - * |
|
23 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
24 | - * @type int |
|
25 | - */ |
|
26 | - const checkin_status_never = 2; |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to reference when a registration has been checked in. |
|
30 | - * |
|
31 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
32 | - * @type int |
|
33 | - */ |
|
34 | - const checkin_status_in = 1; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Used to reference when a registration has been checked out. |
|
39 | - * |
|
40 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
41 | - * @type int |
|
42 | - */ |
|
43 | - const checkin_status_out = 0; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * extra meta key for tracking reg status os trashed registrations |
|
48 | - * |
|
49 | - * @type string |
|
50 | - */ |
|
51 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * extra meta key for tracking if registration has reserved ticket |
|
56 | - * |
|
57 | - * @type string |
|
58 | - */ |
|
59 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param array $props_n_values incoming values |
|
64 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
65 | - * used.) |
|
66 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
67 | - * date_format and the second value is the time format |
|
68 | - * @return EE_Registration |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
72 | - { |
|
73 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
74 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param array $props_n_values incoming values from the database |
|
80 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
81 | - * the website will be used. |
|
82 | - * @return EE_Registration |
|
83 | - */ |
|
84 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
85 | - { |
|
86 | - return new self($props_n_values, true, $timezone); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Set Event ID |
|
92 | - * |
|
93 | - * @param int $EVT_ID Event ID |
|
94 | - * @throws EE_Error |
|
95 | - * @throws RuntimeException |
|
96 | - */ |
|
97 | - public function set_event($EVT_ID = 0) |
|
98 | - { |
|
99 | - $this->set('EVT_ID', $EVT_ID); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
105 | - * be routed to internal methods |
|
106 | - * |
|
107 | - * @param string $field_name |
|
108 | - * @param mixed $field_value |
|
109 | - * @param bool $use_default |
|
110 | - * @throws EE_Error |
|
111 | - * @throws EntityNotFoundException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws ReflectionException |
|
116 | - * @throws RuntimeException |
|
117 | - */ |
|
118 | - public function set($field_name, $field_value, $use_default = false) |
|
119 | - { |
|
120 | - switch ($field_name) { |
|
121 | - case 'REG_code': |
|
122 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
123 | - $this->set_reg_code($field_value, $use_default); |
|
124 | - } |
|
125 | - break; |
|
126 | - case 'STS_ID': |
|
127 | - $this->set_status($field_value, $use_default); |
|
128 | - break; |
|
129 | - default: |
|
130 | - parent::set($field_name, $field_value, $use_default); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Set Status ID |
|
137 | - * updates the registration status and ALSO... |
|
138 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
139 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
140 | - * |
|
141 | - * @param string $new_STS_ID |
|
142 | - * @param boolean $use_default |
|
143 | - * @param ContextInterface|null $context |
|
144 | - * @return bool |
|
145 | - * @throws DomainException |
|
146 | - * @throws EE_Error |
|
147 | - * @throws EntityNotFoundException |
|
148 | - * @throws InvalidArgumentException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidInterfaceException |
|
151 | - * @throws ReflectionException |
|
152 | - * @throws RuntimeException |
|
153 | - * @throws UnexpectedEntityException |
|
154 | - */ |
|
155 | - public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
156 | - { |
|
157 | - // get current REG_Status |
|
158 | - $old_STS_ID = $this->status_ID(); |
|
159 | - // if status has changed |
|
160 | - if ( |
|
161 | - $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
162 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
163 | - && ! empty($new_STS_ID) // as well as the new status |
|
164 | - && $this->ID() // ensure registration is in the db |
|
165 | - ) { |
|
166 | - // update internal status first |
|
167 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
168 | - // THEN handle other changes that occur when reg status changes |
|
169 | - // TO approved |
|
170 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | - // reserve a space by incrementing ticket and datetime sold values |
|
172 | - $this->reserveRegistrationSpace(); |
|
173 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
174 | - // OR FROM approved |
|
175 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
176 | - // release a space by decrementing ticket and datetime sold values |
|
177 | - $this->releaseRegistrationSpace(); |
|
178 | - do_action( |
|
179 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
180 | - $this, |
|
181 | - $old_STS_ID, |
|
182 | - $new_STS_ID, |
|
183 | - $context |
|
184 | - ); |
|
185 | - } |
|
186 | - // update status |
|
187 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
188 | - $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context); |
|
189 | - if ($this->statusChangeUpdatesTransaction($context)) { |
|
190 | - $this->updateTransactionAfterStatusChange(); |
|
191 | - } |
|
192 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
193 | - return true; |
|
194 | - } |
|
195 | - // even though the old value matches the new value, it's still good to |
|
196 | - // allow the parent set method to have a say |
|
197 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
198 | - return true; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * update REGs and TXN when cancelled or declined registrations involved |
|
204 | - * |
|
205 | - * @param string $new_STS_ID |
|
206 | - * @param string $old_STS_ID |
|
207 | - * @param ContextInterface|null $context |
|
208 | - * @throws EE_Error |
|
209 | - * @throws InvalidArgumentException |
|
210 | - * @throws InvalidDataTypeException |
|
211 | - * @throws InvalidInterfaceException |
|
212 | - * @throws ReflectionException |
|
213 | - * @throws RuntimeException |
|
214 | - */ |
|
215 | - private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
216 | - { |
|
217 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
218 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
219 | - // true if registration has been cancelled or declined |
|
220 | - $this->updateIfCanceled( |
|
221 | - $closed_reg_statuses, |
|
222 | - $new_STS_ID, |
|
223 | - $old_STS_ID, |
|
224 | - $context |
|
225 | - ); |
|
226 | - $this->updateIfReinstated( |
|
227 | - $closed_reg_statuses, |
|
228 | - $new_STS_ID, |
|
229 | - $old_STS_ID, |
|
230 | - $context |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * update REGs and TXN when cancelled or declined registrations involved |
|
237 | - * |
|
238 | - * @param array $closed_reg_statuses |
|
239 | - * @param string $new_STS_ID |
|
240 | - * @param string $old_STS_ID |
|
241 | - * @param ContextInterface|null $context |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws ReflectionException |
|
247 | - * @throws RuntimeException |
|
248 | - */ |
|
249 | - private function updateIfCanceled( |
|
250 | - array $closed_reg_statuses, |
|
251 | - $new_STS_ID, |
|
252 | - $old_STS_ID, |
|
253 | - ContextInterface $context = null |
|
254 | - ) { |
|
255 | - // true if registration has been cancelled or declined |
|
256 | - if ( |
|
257 | - in_array($new_STS_ID, $closed_reg_statuses, true) |
|
258 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
259 | - ) { |
|
260 | - /** @type EE_Registration_Processor $registration_processor */ |
|
261 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
262 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
263 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
264 | - // cancelled or declined registration |
|
265 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
266 | - $this, |
|
267 | - $closed_reg_statuses |
|
268 | - ); |
|
269 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
270 | - $this, |
|
271 | - $closed_reg_statuses, |
|
272 | - false |
|
273 | - ); |
|
274 | - do_action( |
|
275 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
276 | - $this, |
|
277 | - $old_STS_ID, |
|
278 | - $new_STS_ID, |
|
279 | - $context |
|
280 | - ); |
|
281 | - return; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * update REGs and TXN when cancelled or declined registrations involved |
|
288 | - * |
|
289 | - * @param array $closed_reg_statuses |
|
290 | - * @param string $new_STS_ID |
|
291 | - * @param string $old_STS_ID |
|
292 | - * @param ContextInterface|null $context |
|
293 | - * @throws EE_Error |
|
294 | - * @throws InvalidArgumentException |
|
295 | - * @throws InvalidDataTypeException |
|
296 | - * @throws InvalidInterfaceException |
|
297 | - * @throws ReflectionException |
|
298 | - */ |
|
299 | - private function updateIfReinstated( |
|
300 | - array $closed_reg_statuses, |
|
301 | - $new_STS_ID, |
|
302 | - $old_STS_ID, |
|
303 | - ContextInterface $context = null |
|
304 | - ) { |
|
305 | - // true if reinstating cancelled or declined registration |
|
306 | - if ( |
|
307 | - in_array($old_STS_ID, $closed_reg_statuses, true) |
|
308 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
309 | - ) { |
|
310 | - /** @type EE_Registration_Processor $registration_processor */ |
|
311 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
312 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
313 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
314 | - // reinstating cancelled or declined registration |
|
315 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
316 | - $this, |
|
317 | - $closed_reg_statuses |
|
318 | - ); |
|
319 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
320 | - $this, |
|
321 | - $closed_reg_statuses, |
|
322 | - false |
|
323 | - ); |
|
324 | - do_action( |
|
325 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
326 | - $this, |
|
327 | - $old_STS_ID, |
|
328 | - $new_STS_ID, |
|
329 | - $context |
|
330 | - ); |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param ContextInterface|null $context |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
340 | - { |
|
341 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
342 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
343 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
344 | - $context, |
|
345 | - $this |
|
346 | - ); |
|
347 | - return ! ( |
|
348 | - $context instanceof ContextInterface |
|
349 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
350 | - ); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @throws EE_Error |
|
356 | - * @throws EntityNotFoundException |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidDataTypeException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws ReflectionException |
|
361 | - * @throws RuntimeException |
|
362 | - */ |
|
363 | - private function updateTransactionAfterStatusChange() |
|
364 | - { |
|
365 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
366 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
367 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
368 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * get Status ID |
|
374 | - */ |
|
375 | - public function status_ID() |
|
376 | - { |
|
377 | - return $this->get('STS_ID'); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Gets the ticket this registration is for |
|
383 | - * |
|
384 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
385 | - * |
|
386 | - * @return EE_Ticket|EE_Base_Class |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function ticket($include_archived = true) |
|
390 | - { |
|
391 | - $query_params = array(); |
|
392 | - if ($include_archived) { |
|
393 | - $query_params['default_where_conditions'] = 'none'; |
|
394 | - } |
|
395 | - return $this->get_first_related('Ticket', $query_params); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * Gets the event this registration is for |
|
401 | - * |
|
402 | - * @return EE_Event |
|
403 | - * @throws EE_Error |
|
404 | - * @throws EntityNotFoundException |
|
405 | - */ |
|
406 | - public function event() |
|
407 | - { |
|
408 | - $event = $this->get_first_related('Event'); |
|
409 | - if (! $event instanceof \EE_Event) { |
|
410 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
411 | - } |
|
412 | - return $event; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
418 | - * with the author of the event this registration is for. |
|
419 | - * |
|
420 | - * @since 4.5.0 |
|
421 | - * @return int |
|
422 | - * @throws EE_Error |
|
423 | - * @throws EntityNotFoundException |
|
424 | - */ |
|
425 | - public function wp_user() |
|
426 | - { |
|
427 | - $event = $this->event(); |
|
428 | - if ($event instanceof EE_Event) { |
|
429 | - return $event->wp_user(); |
|
430 | - } |
|
431 | - return 0; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
437 | - * |
|
438 | - * @return void |
|
439 | - * @throws DomainException |
|
440 | - * @throws EE_Error |
|
441 | - * @throws EntityNotFoundException |
|
442 | - * @throws InvalidArgumentException |
|
443 | - * @throws InvalidDataTypeException |
|
444 | - * @throws InvalidInterfaceException |
|
445 | - * @throws ReflectionException |
|
446 | - * @throws UnexpectedEntityException |
|
447 | - */ |
|
448 | - private function reserveRegistrationSpace() |
|
449 | - { |
|
450 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
451 | - // so stop tracking that this reg has a ticket reserved |
|
452 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
453 | - $ticket = $this->ticket(); |
|
454 | - $ticket->increaseSold(); |
|
455 | - // possibly set event status to sold out |
|
456 | - $this->event()->perform_sold_out_status_check(); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
462 | - * |
|
463 | - * @return void |
|
464 | - * @throws DomainException |
|
465 | - * @throws EE_Error |
|
466 | - * @throws EntityNotFoundException |
|
467 | - * @throws InvalidArgumentException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - * @throws ReflectionException |
|
471 | - * @throws UnexpectedEntityException |
|
472 | - */ |
|
473 | - private function releaseRegistrationSpace() |
|
474 | - { |
|
475 | - $ticket = $this->ticket(); |
|
476 | - $ticket->decreaseSold(); |
|
477 | - // possibly change event status from sold out back to previous status |
|
478 | - $this->event()->perform_sold_out_status_check(); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * tracks this registration's ticket reservation in extra meta |
|
484 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
485 | - * |
|
486 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
487 | - * @return void |
|
488 | - * @throws EE_Error |
|
489 | - * @throws InvalidArgumentException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws InvalidInterfaceException |
|
492 | - * @throws ReflectionException |
|
493 | - */ |
|
494 | - public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
495 | - { |
|
496 | - // only reserve ticket if space is not currently reserved |
|
497 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
498 | - $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
499 | - // IMPORTANT !!! |
|
500 | - // although checking $update_ticket first would be more efficient, |
|
501 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
502 | - if ( |
|
503 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
504 | - && $update_ticket |
|
505 | - ) { |
|
506 | - $ticket = $this->ticket(); |
|
507 | - $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
508 | - $ticket->save(); |
|
509 | - } |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * stops tracking this registration's ticket reservation in extra meta |
|
516 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
517 | - * |
|
518 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
519 | - * @return void |
|
520 | - * @throws EE_Error |
|
521 | - * @throws InvalidArgumentException |
|
522 | - * @throws InvalidDataTypeException |
|
523 | - * @throws InvalidInterfaceException |
|
524 | - * @throws ReflectionException |
|
525 | - */ |
|
526 | - public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
527 | - { |
|
528 | - // only release ticket if space is currently reserved |
|
529 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
530 | - $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
531 | - // IMPORTANT !!! |
|
532 | - // although checking $update_ticket first would be more efficient, |
|
533 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
534 | - if ( |
|
535 | - $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
536 | - && $update_ticket |
|
537 | - ) { |
|
538 | - $ticket = $this->ticket(); |
|
539 | - $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Set Attendee ID |
|
547 | - * |
|
548 | - * @param int $ATT_ID Attendee ID |
|
549 | - * @throws EE_Error |
|
550 | - * @throws RuntimeException |
|
551 | - */ |
|
552 | - public function set_attendee_id($ATT_ID = 0) |
|
553 | - { |
|
554 | - $this->set('ATT_ID', $ATT_ID); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Set Transaction ID |
|
560 | - * |
|
561 | - * @param int $TXN_ID Transaction ID |
|
562 | - * @throws EE_Error |
|
563 | - * @throws RuntimeException |
|
564 | - */ |
|
565 | - public function set_transaction_id($TXN_ID = 0) |
|
566 | - { |
|
567 | - $this->set('TXN_ID', $TXN_ID); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Set Session |
|
573 | - * |
|
574 | - * @param string $REG_session PHP Session ID |
|
575 | - * @throws EE_Error |
|
576 | - * @throws RuntimeException |
|
577 | - */ |
|
578 | - public function set_session($REG_session = '') |
|
579 | - { |
|
580 | - $this->set('REG_session', $REG_session); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Set Registration URL Link |
|
586 | - * |
|
587 | - * @param string $REG_url_link Registration URL Link |
|
588 | - * @throws EE_Error |
|
589 | - * @throws RuntimeException |
|
590 | - */ |
|
591 | - public function set_reg_url_link($REG_url_link = '') |
|
592 | - { |
|
593 | - $this->set('REG_url_link', $REG_url_link); |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Set Attendee Counter |
|
599 | - * |
|
600 | - * @param int $REG_count Primary Attendee |
|
601 | - * @throws EE_Error |
|
602 | - * @throws RuntimeException |
|
603 | - */ |
|
604 | - public function set_count($REG_count = 1) |
|
605 | - { |
|
606 | - $this->set('REG_count', $REG_count); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Set Group Size |
|
612 | - * |
|
613 | - * @param boolean $REG_group_size Group Registration |
|
614 | - * @throws EE_Error |
|
615 | - * @throws RuntimeException |
|
616 | - */ |
|
617 | - public function set_group_size($REG_group_size = false) |
|
618 | - { |
|
619 | - $this->set('REG_group_size', $REG_group_size); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
625 | - * EEM_Registration::status_id_not_approved |
|
626 | - * |
|
627 | - * @return boolean |
|
628 | - */ |
|
629 | - public function is_not_approved() |
|
630 | - { |
|
631 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
637 | - * EEM_Registration::status_id_pending_payment |
|
638 | - * |
|
639 | - * @return boolean |
|
640 | - */ |
|
641 | - public function is_pending_payment() |
|
642 | - { |
|
643 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
649 | - * |
|
650 | - * @return boolean |
|
651 | - */ |
|
652 | - public function is_approved() |
|
653 | - { |
|
654 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
660 | - * |
|
661 | - * @return boolean |
|
662 | - */ |
|
663 | - public function is_cancelled() |
|
664 | - { |
|
665 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
671 | - * |
|
672 | - * @return boolean |
|
673 | - */ |
|
674 | - public function is_declined() |
|
675 | - { |
|
676 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
682 | - * EEM_Registration::status_id_incomplete |
|
683 | - * |
|
684 | - * @return boolean |
|
685 | - */ |
|
686 | - public function is_incomplete() |
|
687 | - { |
|
688 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * Set Registration Date |
|
694 | - * |
|
695 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
696 | - * Date |
|
697 | - * @throws EE_Error |
|
698 | - * @throws RuntimeException |
|
699 | - */ |
|
700 | - public function set_reg_date($REG_date = false) |
|
701 | - { |
|
702 | - $this->set('REG_date', $REG_date); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * Set final price owing for this registration after all ticket/price modifications |
|
708 | - * |
|
709 | - * @access public |
|
710 | - * @param float $REG_final_price |
|
711 | - * @throws EE_Error |
|
712 | - * @throws RuntimeException |
|
713 | - */ |
|
714 | - public function set_final_price($REG_final_price = 0.00) |
|
715 | - { |
|
716 | - $this->set('REG_final_price', $REG_final_price); |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Set amount paid towards this registration's final price |
|
722 | - * |
|
723 | - * @access public |
|
724 | - * @param float $REG_paid |
|
725 | - * @throws EE_Error |
|
726 | - * @throws RuntimeException |
|
727 | - */ |
|
728 | - public function set_paid($REG_paid = 0.00) |
|
729 | - { |
|
730 | - $this->set('REG_paid', $REG_paid); |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - /** |
|
735 | - * Attendee Is Going |
|
736 | - * |
|
737 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
738 | - * @throws EE_Error |
|
739 | - * @throws RuntimeException |
|
740 | - */ |
|
741 | - public function set_att_is_going($REG_att_is_going = false) |
|
742 | - { |
|
743 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * Gets the related attendee |
|
749 | - * |
|
750 | - * @return EE_Attendee |
|
751 | - * @throws EE_Error |
|
752 | - */ |
|
753 | - public function attendee() |
|
754 | - { |
|
755 | - return $this->get_first_related('Attendee'); |
|
756 | - } |
|
757 | - |
|
758 | - /** |
|
759 | - * Gets the name of the attendee. |
|
760 | - * @since 4.10.12.p |
|
761 | - * @param bool $apply_html_entities set to true if you want to use HTML entities. |
|
762 | - * @return string |
|
763 | - * @throws EE_Error |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws InvalidDataTypeException |
|
766 | - * @throws InvalidInterfaceException |
|
767 | - * @throws ReflectionException |
|
768 | - */ |
|
769 | - public function attendeeName($apply_html_entities = false) |
|
770 | - { |
|
771 | - $attendee = $this->get_first_related('Attendee'); |
|
772 | - if ($attendee instanceof EE_Attendee) { |
|
773 | - $attendee_name = $attendee->full_name($apply_html_entities); |
|
774 | - } else { |
|
775 | - $attendee_name = esc_html__('Unknown', 'event_espresso'); |
|
776 | - } |
|
777 | - return $attendee_name; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - /** |
|
782 | - * get Event ID |
|
783 | - */ |
|
784 | - public function event_ID() |
|
785 | - { |
|
786 | - return $this->get('EVT_ID'); |
|
787 | - } |
|
788 | - |
|
789 | - |
|
790 | - /** |
|
791 | - * get Event ID |
|
792 | - */ |
|
793 | - public function event_name() |
|
794 | - { |
|
795 | - $event = $this->event_obj(); |
|
796 | - if ($event) { |
|
797 | - return $event->name(); |
|
798 | - } else { |
|
799 | - return null; |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * Fetches the event this registration is for |
|
806 | - * |
|
807 | - * @return EE_Event |
|
808 | - * @throws EE_Error |
|
809 | - */ |
|
810 | - public function event_obj() |
|
811 | - { |
|
812 | - return $this->get_first_related('Event'); |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * get Attendee ID |
|
818 | - */ |
|
819 | - public function attendee_ID() |
|
820 | - { |
|
821 | - return $this->get('ATT_ID'); |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * get PHP Session ID |
|
827 | - */ |
|
828 | - public function session_ID() |
|
829 | - { |
|
830 | - return $this->get('REG_session'); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - /** |
|
835 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
836 | - * |
|
837 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
838 | - * @return string |
|
839 | - */ |
|
840 | - public function receipt_url($messenger = 'html') |
|
841 | - { |
|
842 | - |
|
843 | - /** |
|
844 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
845 | - * already in use on old system. If there is then we just return the standard url for it. |
|
846 | - * |
|
847 | - * @since 4.5.0 |
|
848 | - */ |
|
849 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
850 | - $has_custom = EEH_Template::locate_template( |
|
851 | - $template_relative_path, |
|
852 | - array(), |
|
853 | - true, |
|
854 | - true, |
|
855 | - true |
|
856 | - ); |
|
857 | - |
|
858 | - if ($has_custom) { |
|
859 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
860 | - } |
|
861 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
867 | - * |
|
868 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
869 | - * @return string |
|
870 | - * @throws EE_Error |
|
871 | - */ |
|
872 | - public function invoice_url($messenger = 'html') |
|
873 | - { |
|
874 | - /** |
|
875 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
876 | - * already in use on old system. If there is then we just return the standard url for it. |
|
877 | - * |
|
878 | - * @since 4.5.0 |
|
879 | - */ |
|
880 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
881 | - $has_custom = EEH_Template::locate_template( |
|
882 | - $template_relative_path, |
|
883 | - array(), |
|
884 | - true, |
|
885 | - true, |
|
886 | - true |
|
887 | - ); |
|
888 | - |
|
889 | - if ($has_custom) { |
|
890 | - if ($messenger == 'html') { |
|
891 | - return $this->invoice_url('launch'); |
|
892 | - } |
|
893 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
894 | - |
|
895 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
896 | - if ($messenger == 'html') { |
|
897 | - $query_args['html'] = true; |
|
898 | - } |
|
899 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
900 | - } |
|
901 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * get Registration URL Link |
|
907 | - * |
|
908 | - * @access public |
|
909 | - * @return string |
|
910 | - * @throws EE_Error |
|
911 | - */ |
|
912 | - public function reg_url_link() |
|
913 | - { |
|
914 | - return (string) $this->get('REG_url_link'); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * Echoes out invoice_url() |
|
920 | - * |
|
921 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
922 | - * @return void |
|
923 | - * @throws EE_Error |
|
924 | - */ |
|
925 | - public function e_invoice_url($type = 'launch') |
|
926 | - { |
|
927 | - echo $this->invoice_url($type); |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * Echoes out payment_overview_url |
|
933 | - */ |
|
934 | - public function e_payment_overview_url() |
|
935 | - { |
|
936 | - echo $this->payment_overview_url(); |
|
937 | - } |
|
938 | - |
|
939 | - |
|
940 | - /** |
|
941 | - * Gets the URL for the checkout payment options reg step |
|
942 | - * with this registration's REG_url_link added as a query parameter |
|
943 | - * |
|
944 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
945 | - * payment overview url. |
|
946 | - * @return string |
|
947 | - * @throws InvalidInterfaceException |
|
948 | - * @throws InvalidDataTypeException |
|
949 | - * @throws EE_Error |
|
950 | - * @throws InvalidArgumentException |
|
951 | - */ |
|
952 | - public function payment_overview_url($clear_session = false) |
|
953 | - { |
|
954 | - return add_query_arg( |
|
955 | - (array) apply_filters( |
|
956 | - 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
957 | - array( |
|
958 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
959 | - 'step' => 'payment_options', |
|
960 | - 'revisit' => true, |
|
961 | - 'clear_session' => (bool) $clear_session, |
|
962 | - ), |
|
963 | - $this |
|
964 | - ), |
|
965 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
966 | - ); |
|
967 | - } |
|
968 | - |
|
969 | - |
|
970 | - /** |
|
971 | - * Gets the URL for the checkout attendee information reg step |
|
972 | - * with this registration's REG_url_link added as a query parameter |
|
973 | - * |
|
974 | - * @return string |
|
975 | - * @throws InvalidInterfaceException |
|
976 | - * @throws InvalidDataTypeException |
|
977 | - * @throws EE_Error |
|
978 | - * @throws InvalidArgumentException |
|
979 | - */ |
|
980 | - public function edit_attendee_information_url() |
|
981 | - { |
|
982 | - return add_query_arg( |
|
983 | - (array) apply_filters( |
|
984 | - 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
985 | - array( |
|
986 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
987 | - 'step' => 'attendee_information', |
|
988 | - 'revisit' => true, |
|
989 | - ), |
|
990 | - $this |
|
991 | - ), |
|
992 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
993 | - ); |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
999 | - * |
|
1000 | - * @return string |
|
1001 | - * @throws EE_Error |
|
1002 | - */ |
|
1003 | - public function get_admin_edit_url() |
|
1004 | - { |
|
1005 | - return EEH_URL::add_query_args_and_nonce( |
|
1006 | - array( |
|
1007 | - 'page' => 'espresso_registrations', |
|
1008 | - 'action' => 'view_registration', |
|
1009 | - '_REG_ID' => $this->ID(), |
|
1010 | - ), |
|
1011 | - admin_url('admin.php') |
|
1012 | - ); |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * is_primary_registrant? |
|
1018 | - */ |
|
1019 | - public function is_primary_registrant() |
|
1020 | - { |
|
1021 | - return $this->get('REG_count') === 1 ? true : false; |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * This returns the primary registration object for this registration group (which may be this object). |
|
1027 | - * |
|
1028 | - * @return EE_Registration |
|
1029 | - * @throws EE_Error |
|
1030 | - */ |
|
1031 | - public function get_primary_registration() |
|
1032 | - { |
|
1033 | - if ($this->is_primary_registrant()) { |
|
1034 | - return $this; |
|
1035 | - } |
|
1036 | - |
|
1037 | - // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
1038 | - /** @var EE_Registration $primary_registrant */ |
|
1039 | - $primary_registrant = EEM_Registration::instance()->get_one( |
|
1040 | - array( |
|
1041 | - array( |
|
1042 | - 'TXN_ID' => $this->transaction_ID(), |
|
1043 | - 'REG_count' => 1, |
|
1044 | - ), |
|
1045 | - ) |
|
1046 | - ); |
|
1047 | - return $primary_registrant; |
|
1048 | - } |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * get Attendee Number |
|
1053 | - * |
|
1054 | - * @access public |
|
1055 | - */ |
|
1056 | - public function count() |
|
1057 | - { |
|
1058 | - return $this->get('REG_count'); |
|
1059 | - } |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * get Group Size |
|
1064 | - */ |
|
1065 | - public function group_size() |
|
1066 | - { |
|
1067 | - return $this->get('REG_group_size'); |
|
1068 | - } |
|
1069 | - |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * get Registration Date |
|
1073 | - */ |
|
1074 | - public function date() |
|
1075 | - { |
|
1076 | - return $this->get('REG_date'); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * gets a pretty date |
|
1082 | - * |
|
1083 | - * @param string $date_format |
|
1084 | - * @param string $time_format |
|
1085 | - * @return string |
|
1086 | - * @throws EE_Error |
|
1087 | - */ |
|
1088 | - public function pretty_date($date_format = null, $time_format = null) |
|
1089 | - { |
|
1090 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * final_price |
|
1096 | - * the registration's share of the transaction total, so that the |
|
1097 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1098 | - * |
|
1099 | - * @return float |
|
1100 | - * @throws EE_Error |
|
1101 | - */ |
|
1102 | - public function final_price() |
|
1103 | - { |
|
1104 | - return $this->get('REG_final_price'); |
|
1105 | - } |
|
1106 | - |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * pretty_final_price |
|
1110 | - * final price as formatted string, with correct decimal places and currency symbol |
|
1111 | - * |
|
1112 | - * @return string |
|
1113 | - * @throws EE_Error |
|
1114 | - */ |
|
1115 | - public function pretty_final_price() |
|
1116 | - { |
|
1117 | - return $this->get_pretty('REG_final_price'); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * get paid (yeah) |
|
1123 | - * |
|
1124 | - * @return float |
|
1125 | - * @throws EE_Error |
|
1126 | - */ |
|
1127 | - public function paid() |
|
1128 | - { |
|
1129 | - return $this->get('REG_paid'); |
|
1130 | - } |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * pretty_paid |
|
1135 | - * |
|
1136 | - * @return float |
|
1137 | - * @throws EE_Error |
|
1138 | - */ |
|
1139 | - public function pretty_paid() |
|
1140 | - { |
|
1141 | - return $this->get_pretty('REG_paid'); |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * owes_monies_and_can_pay |
|
1147 | - * whether or not this registration has monies owing and it's' status allows payment |
|
1148 | - * |
|
1149 | - * @param array $requires_payment |
|
1150 | - * @return bool |
|
1151 | - * @throws EE_Error |
|
1152 | - */ |
|
1153 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
1154 | - { |
|
1155 | - // these reg statuses require payment (if event is not free) |
|
1156 | - $requires_payment = ! empty($requires_payment) |
|
1157 | - ? $requires_payment |
|
1158 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1159 | - if ( |
|
1160 | - in_array($this->status_ID(), $requires_payment) && |
|
1161 | - $this->final_price() != 0 && |
|
1162 | - $this->final_price() != $this->paid() |
|
1163 | - ) { |
|
1164 | - return true; |
|
1165 | - } else { |
|
1166 | - return false; |
|
1167 | - } |
|
1168 | - } |
|
1169 | - |
|
1170 | - |
|
1171 | - /** |
|
1172 | - * Prints out the return value of $this->pretty_status() |
|
1173 | - * |
|
1174 | - * @param bool $show_icons |
|
1175 | - * @return void |
|
1176 | - * @throws EE_Error |
|
1177 | - */ |
|
1178 | - public function e_pretty_status($show_icons = false) |
|
1179 | - { |
|
1180 | - echo $this->pretty_status($show_icons); |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Returns a nice version of the status for displaying to customers |
|
1186 | - * |
|
1187 | - * @param bool $show_icons |
|
1188 | - * @return string |
|
1189 | - * @throws EE_Error |
|
1190 | - */ |
|
1191 | - public function pretty_status($show_icons = false) |
|
1192 | - { |
|
1193 | - $status = EEM_Status::instance()->localized_status( |
|
1194 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1195 | - false, |
|
1196 | - 'sentence' |
|
1197 | - ); |
|
1198 | - $icon = ''; |
|
1199 | - switch ($this->status_ID()) { |
|
1200 | - case EEM_Registration::status_id_approved: |
|
1201 | - $icon = $show_icons |
|
1202 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1203 | - : ''; |
|
1204 | - break; |
|
1205 | - case EEM_Registration::status_id_pending_payment: |
|
1206 | - $icon = $show_icons |
|
1207 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1208 | - : ''; |
|
1209 | - break; |
|
1210 | - case EEM_Registration::status_id_not_approved: |
|
1211 | - $icon = $show_icons |
|
1212 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1213 | - : ''; |
|
1214 | - break; |
|
1215 | - case EEM_Registration::status_id_cancelled: |
|
1216 | - $icon = $show_icons |
|
1217 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1218 | - : ''; |
|
1219 | - break; |
|
1220 | - case EEM_Registration::status_id_incomplete: |
|
1221 | - $icon = $show_icons |
|
1222 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1223 | - : ''; |
|
1224 | - break; |
|
1225 | - case EEM_Registration::status_id_declined: |
|
1226 | - $icon = $show_icons |
|
1227 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1228 | - : ''; |
|
1229 | - break; |
|
1230 | - case EEM_Registration::status_id_wait_list: |
|
1231 | - $icon = $show_icons |
|
1232 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1233 | - : ''; |
|
1234 | - break; |
|
1235 | - } |
|
1236 | - return $icon . $status[ $this->status_ID() ]; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * get Attendee Is Going |
|
1242 | - */ |
|
1243 | - public function att_is_going() |
|
1244 | - { |
|
1245 | - return $this->get('REG_att_is_going'); |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Gets related answers |
|
1251 | - * |
|
1252 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1253 | - * @return EE_Answer[] |
|
1254 | - * @throws EE_Error |
|
1255 | - */ |
|
1256 | - public function answers($query_params = null) |
|
1257 | - { |
|
1258 | - return $this->get_many_related('Answer', $query_params); |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Gets the registration's answer value to the specified question |
|
1264 | - * (either the question's ID or a question object) |
|
1265 | - * |
|
1266 | - * @param EE_Question|int $question |
|
1267 | - * @param bool $pretty_value |
|
1268 | - * @return array|string if pretty_value= true, the result will always be a string |
|
1269 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1270 | - * will convert it into some kind of string) |
|
1271 | - * @throws EE_Error |
|
1272 | - */ |
|
1273 | - public function answer_value_to_question($question, $pretty_value = true) |
|
1274 | - { |
|
1275 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1276 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1277 | - } |
|
1278 | - |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * question_groups |
|
1282 | - * returns an array of EE_Question_Group objects for this registration |
|
1283 | - * |
|
1284 | - * @return EE_Question_Group[] |
|
1285 | - * @throws EE_Error |
|
1286 | - * @throws InvalidArgumentException |
|
1287 | - * @throws InvalidDataTypeException |
|
1288 | - * @throws InvalidInterfaceException |
|
1289 | - * @throws ReflectionException |
|
1290 | - */ |
|
1291 | - public function question_groups() |
|
1292 | - { |
|
1293 | - return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this); |
|
1294 | - } |
|
1295 | - |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * count_question_groups |
|
1299 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
1300 | - * |
|
1301 | - * @return int |
|
1302 | - * @throws EE_Error |
|
1303 | - * @throws EntityNotFoundException |
|
1304 | - * @throws InvalidArgumentException |
|
1305 | - * @throws InvalidDataTypeException |
|
1306 | - * @throws InvalidInterfaceException |
|
1307 | - * @throws ReflectionException |
|
1308 | - */ |
|
1309 | - public function count_question_groups() |
|
1310 | - { |
|
1311 | - return EEM_Event::instance()->count_related( |
|
1312 | - $this->event_ID(), |
|
1313 | - 'Question_Group', |
|
1314 | - [ |
|
1315 | - [ |
|
1316 | - 'Event_Question_Group.' |
|
1317 | - . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true, |
|
1318 | - ] |
|
1319 | - ] |
|
1320 | - ); |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * Returns the registration date in the 'standard' string format |
|
1326 | - * (function may be improved in the future to allow for different formats and timezones) |
|
1327 | - * |
|
1328 | - * @return string |
|
1329 | - * @throws EE_Error |
|
1330 | - */ |
|
1331 | - public function reg_date() |
|
1332 | - { |
|
1333 | - return $this->get_datetime('REG_date'); |
|
1334 | - } |
|
1335 | - |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1339 | - * the ticket this registration purchased, or the datetime they have registered |
|
1340 | - * to attend) |
|
1341 | - * |
|
1342 | - * @return EE_Datetime_Ticket |
|
1343 | - * @throws EE_Error |
|
1344 | - */ |
|
1345 | - public function datetime_ticket() |
|
1346 | - { |
|
1347 | - return $this->get_first_related('Datetime_Ticket'); |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Sets the registration's datetime_ticket. |
|
1353 | - * |
|
1354 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
1355 | - * @return EE_Datetime_Ticket |
|
1356 | - * @throws EE_Error |
|
1357 | - */ |
|
1358 | - public function set_datetime_ticket($datetime_ticket) |
|
1359 | - { |
|
1360 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1361 | - } |
|
1362 | - |
|
1363 | - /** |
|
1364 | - * Gets deleted |
|
1365 | - * |
|
1366 | - * @return bool |
|
1367 | - * @throws EE_Error |
|
1368 | - */ |
|
1369 | - public function deleted() |
|
1370 | - { |
|
1371 | - return $this->get('REG_deleted'); |
|
1372 | - } |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * Sets deleted |
|
1376 | - * |
|
1377 | - * @param boolean $deleted |
|
1378 | - * @return bool |
|
1379 | - * @throws EE_Error |
|
1380 | - * @throws RuntimeException |
|
1381 | - */ |
|
1382 | - public function set_deleted($deleted) |
|
1383 | - { |
|
1384 | - if ($deleted) { |
|
1385 | - $this->delete(); |
|
1386 | - } else { |
|
1387 | - $this->restore(); |
|
1388 | - } |
|
1389 | - } |
|
1390 | - |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * Get the status object of this object |
|
1394 | - * |
|
1395 | - * @return EE_Status |
|
1396 | - * @throws EE_Error |
|
1397 | - */ |
|
1398 | - public function status_obj() |
|
1399 | - { |
|
1400 | - return $this->get_first_related('Status'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - /** |
|
1405 | - * Returns the number of times this registration has checked into any of the datetimes |
|
1406 | - * its available for |
|
1407 | - * |
|
1408 | - * @return int |
|
1409 | - * @throws EE_Error |
|
1410 | - */ |
|
1411 | - public function count_checkins() |
|
1412 | - { |
|
1413 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1419 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1420 | - * |
|
1421 | - * @return int |
|
1422 | - * @throws EE_Error |
|
1423 | - */ |
|
1424 | - public function count_checkins_not_checkedout() |
|
1425 | - { |
|
1426 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1427 | - } |
|
1428 | - |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1432 | - * |
|
1433 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1434 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1435 | - * consider registration status as well as datetime access. |
|
1436 | - * @return bool |
|
1437 | - * @throws EE_Error |
|
1438 | - */ |
|
1439 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1440 | - { |
|
1441 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1442 | - |
|
1443 | - // first check registration status |
|
1444 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1445 | - return false; |
|
1446 | - } |
|
1447 | - // is there a datetime ticket that matches this dtt_ID? |
|
1448 | - if ( |
|
1449 | - ! (EEM_Datetime_Ticket::instance()->exists( |
|
1450 | - array( |
|
1451 | - array( |
|
1452 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
1453 | - 'DTT_ID' => $DTT_ID, |
|
1454 | - ), |
|
1455 | - ) |
|
1456 | - )) |
|
1457 | - ) { |
|
1458 | - return false; |
|
1459 | - } |
|
1460 | - |
|
1461 | - // final check is against TKT_uses |
|
1462 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1463 | - } |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1468 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1469 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1470 | - * then return false. Otherwise return true. |
|
1471 | - * |
|
1472 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1473 | - * @return bool true means can checkin. false means cannot checkin. |
|
1474 | - * @throws EE_Error |
|
1475 | - */ |
|
1476 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1477 | - { |
|
1478 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1479 | - |
|
1480 | - if (! $DTT_ID) { |
|
1481 | - return false; |
|
1482 | - } |
|
1483 | - |
|
1484 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1485 | - |
|
1486 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1487 | - // check-in or not. |
|
1488 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1489 | - return true; |
|
1490 | - } |
|
1491 | - |
|
1492 | - // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1493 | - // go ahead and toggle. |
|
1494 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1495 | - return true; |
|
1496 | - } |
|
1497 | - |
|
1498 | - // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1499 | - // disallows further check-ins. |
|
1500 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
1501 | - array( |
|
1502 | - array( |
|
1503 | - 'REG_ID' => $this->ID(), |
|
1504 | - 'CHK_in' => true, |
|
1505 | - ), |
|
1506 | - ), |
|
1507 | - 'DTT_ID', |
|
1508 | - true |
|
1509 | - ); |
|
1510 | - // checkins have already reached their max number of uses |
|
1511 | - // so registrant can NOT checkin |
|
1512 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
1513 | - EE_Error::add_error( |
|
1514 | - esc_html__( |
|
1515 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1516 | - 'event_espresso' |
|
1517 | - ), |
|
1518 | - __FILE__, |
|
1519 | - __FUNCTION__, |
|
1520 | - __LINE__ |
|
1521 | - ); |
|
1522 | - return false; |
|
1523 | - } |
|
1524 | - return true; |
|
1525 | - } |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * toggle Check-in status for this registration |
|
1530 | - * Check-ins are toggled in the following order: |
|
1531 | - * never checked in -> checked in |
|
1532 | - * checked in -> checked out |
|
1533 | - * checked out -> checked in |
|
1534 | - * |
|
1535 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1536 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1537 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1538 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1539 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1540 | - * @throws EE_Error |
|
1541 | - */ |
|
1542 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1543 | - { |
|
1544 | - if (empty($DTT_ID)) { |
|
1545 | - $datetime = $this->get_latest_related_datetime(); |
|
1546 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1547 | - // verify the registration can checkin for the given DTT_ID |
|
1548 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1549 | - EE_Error::add_error( |
|
1550 | - sprintf( |
|
1551 | - esc_html__( |
|
1552 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1553 | - 'event_espresso' |
|
1554 | - ), |
|
1555 | - $this->ID(), |
|
1556 | - $DTT_ID |
|
1557 | - ), |
|
1558 | - __FILE__, |
|
1559 | - __FUNCTION__, |
|
1560 | - __LINE__ |
|
1561 | - ); |
|
1562 | - return false; |
|
1563 | - } |
|
1564 | - $status_paths = array( |
|
1565 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1566 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1567 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1568 | - ); |
|
1569 | - // start by getting the current status so we know what status we'll be changing to. |
|
1570 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1571 | - $status_to = $status_paths[ $cur_status ]; |
|
1572 | - // database only records true for checked IN or false for checked OUT |
|
1573 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1574 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1575 | - // add relation - note Check-ins are always creating new rows |
|
1576 | - // because we are keeping track of Check-ins over time. |
|
1577 | - // Eventually we'll probably want to show a list table |
|
1578 | - // for the individual Check-ins so that they can be managed. |
|
1579 | - $checkin = EE_Checkin::new_instance( |
|
1580 | - array( |
|
1581 | - 'REG_ID' => $this->ID(), |
|
1582 | - 'DTT_ID' => $DTT_ID, |
|
1583 | - 'CHK_in' => $new_status, |
|
1584 | - ) |
|
1585 | - ); |
|
1586 | - // if the record could not be saved then return false |
|
1587 | - if ($checkin->save() === 0) { |
|
1588 | - if (WP_DEBUG) { |
|
1589 | - global $wpdb; |
|
1590 | - $error = sprintf( |
|
1591 | - esc_html__( |
|
1592 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1593 | - 'event_espresso' |
|
1594 | - ), |
|
1595 | - '<br />', |
|
1596 | - $wpdb->last_error |
|
1597 | - ); |
|
1598 | - } else { |
|
1599 | - $error = esc_html__( |
|
1600 | - 'Registration check in update failed because of an unknown database error', |
|
1601 | - 'event_espresso' |
|
1602 | - ); |
|
1603 | - } |
|
1604 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1605 | - return false; |
|
1606 | - } |
|
1607 | - // Fire a checked_in and checkout_out action. |
|
1608 | - $checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out'; |
|
1609 | - do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID); |
|
1610 | - return $status_to; |
|
1611 | - } |
|
1612 | - |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1616 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1617 | - * |
|
1618 | - * @return EE_Datetime|null |
|
1619 | - * @throws EE_Error |
|
1620 | - */ |
|
1621 | - public function get_latest_related_datetime() |
|
1622 | - { |
|
1623 | - return EEM_Datetime::instance()->get_one( |
|
1624 | - array( |
|
1625 | - array( |
|
1626 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1627 | - ), |
|
1628 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1629 | - ) |
|
1630 | - ); |
|
1631 | - } |
|
1632 | - |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1636 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1637 | - * |
|
1638 | - * @throws EE_Error |
|
1639 | - */ |
|
1640 | - public function get_earliest_related_datetime() |
|
1641 | - { |
|
1642 | - return EEM_Datetime::instance()->get_one( |
|
1643 | - array( |
|
1644 | - array( |
|
1645 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1646 | - ), |
|
1647 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1648 | - ) |
|
1649 | - ); |
|
1650 | - } |
|
1651 | - |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1655 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1656 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1657 | - * |
|
1658 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1659 | - * (if empty we'll get the primary datetime for |
|
1660 | - * this registration (via event) and use it's ID); |
|
1661 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1662 | - * |
|
1663 | - * @return int Integer representing Check-in status. |
|
1664 | - * @throws EE_Error |
|
1665 | - */ |
|
1666 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1667 | - { |
|
1668 | - $checkin_query_params = array( |
|
1669 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1670 | - ); |
|
1671 | - |
|
1672 | - if ($DTT_ID > 0) { |
|
1673 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1674 | - } |
|
1675 | - |
|
1676 | - // get checkin object (if exists) |
|
1677 | - $checkin = $checkin instanceof EE_Checkin |
|
1678 | - ? $checkin |
|
1679 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
1680 | - if ($checkin instanceof EE_Checkin) { |
|
1681 | - if ($checkin->get('CHK_in')) { |
|
1682 | - return EE_Checkin::status_checked_in; // checked in |
|
1683 | - } |
|
1684 | - return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
1685 | - } |
|
1686 | - return EE_Checkin::status_checked_never; // never been checked in |
|
1687 | - } |
|
1688 | - |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * This method returns a localized message for the toggled Check-in message. |
|
1692 | - * |
|
1693 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1694 | - * then it is assumed Check-in for primary datetime was toggled. |
|
1695 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1696 | - * message can be customized with the attendee name. |
|
1697 | - * @return string internationalized message |
|
1698 | - * @throws EE_Error |
|
1699 | - */ |
|
1700 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
1701 | - { |
|
1702 | - // let's get the attendee first so we can include the name of the attendee |
|
1703 | - $attendee = $this->get_first_related('Attendee'); |
|
1704 | - if ($attendee instanceof EE_Attendee) { |
|
1705 | - if ($error) { |
|
1706 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1707 | - } |
|
1708 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1709 | - // what is the status message going to be? |
|
1710 | - switch ($cur_status) { |
|
1711 | - case EE_Checkin::status_checked_never: |
|
1712 | - return sprintf( |
|
1713 | - __("%s has been removed from Check-in records", "event_espresso"), |
|
1714 | - $attendee->full_name() |
|
1715 | - ); |
|
1716 | - break; |
|
1717 | - case EE_Checkin::status_checked_in: |
|
1718 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1719 | - break; |
|
1720 | - case EE_Checkin::status_checked_out: |
|
1721 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1722 | - break; |
|
1723 | - } |
|
1724 | - } |
|
1725 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1726 | - } |
|
1727 | - |
|
1728 | - |
|
1729 | - /** |
|
1730 | - * Returns the related EE_Transaction to this registration |
|
1731 | - * |
|
1732 | - * @return EE_Transaction |
|
1733 | - * @throws EE_Error |
|
1734 | - * @throws EntityNotFoundException |
|
1735 | - */ |
|
1736 | - public function transaction() |
|
1737 | - { |
|
1738 | - $transaction = $this->get_first_related('Transaction'); |
|
1739 | - if (! $transaction instanceof \EE_Transaction) { |
|
1740 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1741 | - } |
|
1742 | - return $transaction; |
|
1743 | - } |
|
1744 | - |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * get Registration Code |
|
1748 | - */ |
|
1749 | - public function reg_code() |
|
1750 | - { |
|
1751 | - return $this->get('REG_code'); |
|
1752 | - } |
|
1753 | - |
|
1754 | - |
|
1755 | - /** |
|
1756 | - * get Transaction ID |
|
1757 | - */ |
|
1758 | - public function transaction_ID() |
|
1759 | - { |
|
1760 | - return $this->get('TXN_ID'); |
|
1761 | - } |
|
1762 | - |
|
1763 | - |
|
1764 | - /** |
|
1765 | - * @return int |
|
1766 | - * @throws EE_Error |
|
1767 | - */ |
|
1768 | - public function ticket_ID() |
|
1769 | - { |
|
1770 | - return $this->get('TKT_ID'); |
|
1771 | - } |
|
1772 | - |
|
1773 | - |
|
1774 | - /** |
|
1775 | - * Set Registration Code |
|
1776 | - * |
|
1777 | - * @access public |
|
1778 | - * @param string $REG_code Registration Code |
|
1779 | - * @param boolean $use_default |
|
1780 | - * @throws EE_Error |
|
1781 | - */ |
|
1782 | - public function set_reg_code($REG_code, $use_default = false) |
|
1783 | - { |
|
1784 | - if (empty($REG_code)) { |
|
1785 | - EE_Error::add_error( |
|
1786 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1787 | - __FILE__, |
|
1788 | - __FUNCTION__, |
|
1789 | - __LINE__ |
|
1790 | - ); |
|
1791 | - return; |
|
1792 | - } |
|
1793 | - if (! $this->reg_code()) { |
|
1794 | - parent::set('REG_code', $REG_code, $use_default); |
|
1795 | - } else { |
|
1796 | - EE_Error::doing_it_wrong( |
|
1797 | - __CLASS__ . '::' . __FUNCTION__, |
|
1798 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1799 | - '4.6.0' |
|
1800 | - ); |
|
1801 | - } |
|
1802 | - } |
|
1803 | - |
|
1804 | - |
|
1805 | - /** |
|
1806 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1807 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1808 | - * $registration->transaction()->registrations(); |
|
1809 | - * |
|
1810 | - * @since 4.5.0 |
|
1811 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1812 | - * @throws EE_Error |
|
1813 | - */ |
|
1814 | - public function get_all_other_registrations_in_group() |
|
1815 | - { |
|
1816 | - if ($this->group_size() < 2) { |
|
1817 | - return array(); |
|
1818 | - } |
|
1819 | - |
|
1820 | - $query[0] = array( |
|
1821 | - 'TXN_ID' => $this->transaction_ID(), |
|
1822 | - 'REG_ID' => array('!=', $this->ID()), |
|
1823 | - 'TKT_ID' => $this->ticket_ID(), |
|
1824 | - ); |
|
1825 | - /** @var EE_Registration[] $registrations */ |
|
1826 | - $registrations = $this->get_model()->get_all($query); |
|
1827 | - return $registrations; |
|
1828 | - } |
|
1829 | - |
|
1830 | - /** |
|
1831 | - * Return the link to the admin details for the object. |
|
1832 | - * |
|
1833 | - * @return string |
|
1834 | - * @throws EE_Error |
|
1835 | - */ |
|
1836 | - public function get_admin_details_link() |
|
1837 | - { |
|
1838 | - EE_Registry::instance()->load_helper('URL'); |
|
1839 | - return EEH_URL::add_query_args_and_nonce( |
|
1840 | - array( |
|
1841 | - 'page' => 'espresso_registrations', |
|
1842 | - 'action' => 'view_registration', |
|
1843 | - '_REG_ID' => $this->ID(), |
|
1844 | - ), |
|
1845 | - admin_url('admin.php') |
|
1846 | - ); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1851 | - * |
|
1852 | - * @return string |
|
1853 | - * @throws EE_Error |
|
1854 | - */ |
|
1855 | - public function get_admin_edit_link() |
|
1856 | - { |
|
1857 | - return $this->get_admin_details_link(); |
|
1858 | - } |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * Returns the link to a settings page for the object. |
|
1862 | - * |
|
1863 | - * @return string |
|
1864 | - * @throws EE_Error |
|
1865 | - */ |
|
1866 | - public function get_admin_settings_link() |
|
1867 | - { |
|
1868 | - return $this->get_admin_details_link(); |
|
1869 | - } |
|
1870 | - |
|
1871 | - /** |
|
1872 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1873 | - * |
|
1874 | - * @return string |
|
1875 | - */ |
|
1876 | - public function get_admin_overview_link() |
|
1877 | - { |
|
1878 | - EE_Registry::instance()->load_helper('URL'); |
|
1879 | - return EEH_URL::add_query_args_and_nonce( |
|
1880 | - array( |
|
1881 | - 'page' => 'espresso_registrations', |
|
1882 | - ), |
|
1883 | - admin_url('admin.php') |
|
1884 | - ); |
|
1885 | - } |
|
1886 | - |
|
1887 | - |
|
1888 | - /** |
|
1889 | - * @param array $query_params |
|
1890 | - * |
|
1891 | - * @return \EE_Registration[] |
|
1892 | - * @throws EE_Error |
|
1893 | - */ |
|
1894 | - public function payments($query_params = array()) |
|
1895 | - { |
|
1896 | - return $this->get_many_related('Payment', $query_params); |
|
1897 | - } |
|
1898 | - |
|
1899 | - |
|
1900 | - /** |
|
1901 | - * @param array $query_params |
|
1902 | - * |
|
1903 | - * @return \EE_Registration_Payment[] |
|
1904 | - * @throws EE_Error |
|
1905 | - */ |
|
1906 | - public function registration_payments($query_params = array()) |
|
1907 | - { |
|
1908 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
1909 | - } |
|
1910 | - |
|
1911 | - |
|
1912 | - /** |
|
1913 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1914 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
1915 | - * |
|
1916 | - * @return EE_Payment_Method|null |
|
1917 | - */ |
|
1918 | - public function payment_method() |
|
1919 | - { |
|
1920 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1921 | - } |
|
1922 | - |
|
1923 | - |
|
1924 | - /** |
|
1925 | - * @return \EE_Line_Item |
|
1926 | - * @throws EntityNotFoundException |
|
1927 | - * @throws EE_Error |
|
1928 | - */ |
|
1929 | - public function ticket_line_item() |
|
1930 | - { |
|
1931 | - $ticket = $this->ticket(); |
|
1932 | - $transaction = $this->transaction(); |
|
1933 | - $line_item = null; |
|
1934 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1935 | - $transaction->total_line_item(), |
|
1936 | - 'Ticket', |
|
1937 | - array($ticket->ID()) |
|
1938 | - ); |
|
1939 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
1940 | - if ( |
|
1941 | - $ticket_line_item instanceof \EE_Line_Item |
|
1942 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1943 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1944 | - ) { |
|
1945 | - $line_item = $ticket_line_item; |
|
1946 | - break; |
|
1947 | - } |
|
1948 | - } |
|
1949 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1950 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1951 | - } |
|
1952 | - return $line_item; |
|
1953 | - } |
|
1954 | - |
|
1955 | - |
|
1956 | - /** |
|
1957 | - * Soft Deletes this model object. |
|
1958 | - * |
|
1959 | - * @return boolean | int |
|
1960 | - * @throws RuntimeException |
|
1961 | - * @throws EE_Error |
|
1962 | - */ |
|
1963 | - public function delete() |
|
1964 | - { |
|
1965 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1966 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
1967 | - } |
|
1968 | - return parent::delete(); |
|
1969 | - } |
|
1970 | - |
|
1971 | - |
|
1972 | - /** |
|
1973 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1974 | - * |
|
1975 | - * @throws EE_Error |
|
1976 | - * @throws RuntimeException |
|
1977 | - */ |
|
1978 | - public function restore() |
|
1979 | - { |
|
1980 | - $previous_status = $this->get_extra_meta( |
|
1981 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1982 | - true, |
|
1983 | - EEM_Registration::status_id_cancelled |
|
1984 | - ); |
|
1985 | - if ($previous_status) { |
|
1986 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1987 | - $this->set_status($previous_status); |
|
1988 | - } |
|
1989 | - return parent::restore(); |
|
1990 | - } |
|
1991 | - |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1995 | - * |
|
1996 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1997 | - * depending on whether the reg status changes to or from "Approved" |
|
1998 | - * @return boolean whether the Registration status was updated |
|
1999 | - * @throws EE_Error |
|
2000 | - * @throws RuntimeException |
|
2001 | - */ |
|
2002 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
2003 | - { |
|
2004 | - $paid = $this->paid(); |
|
2005 | - $price = $this->final_price(); |
|
2006 | - switch (true) { |
|
2007 | - // overpaid or paid |
|
2008 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
2009 | - case EEH_Money::compare_floats($paid, $price): |
|
2010 | - $new_status = EEM_Registration::status_id_approved; |
|
2011 | - break; |
|
2012 | - // underpaid |
|
2013 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
2014 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
2015 | - break; |
|
2016 | - // uhhh Houston... |
|
2017 | - default: |
|
2018 | - throw new RuntimeException( |
|
2019 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
2020 | - ); |
|
2021 | - } |
|
2022 | - if ($new_status !== $this->status_ID()) { |
|
2023 | - if ($trigger_set_status_logic) { |
|
2024 | - return $this->set_status($new_status); |
|
2025 | - } |
|
2026 | - parent::set('STS_ID', $new_status); |
|
2027 | - return true; |
|
2028 | - } |
|
2029 | - return false; |
|
2030 | - } |
|
2031 | - |
|
2032 | - |
|
2033 | - /*************************** DEPRECATED ***************************/ |
|
2034 | - |
|
2035 | - |
|
2036 | - /** |
|
2037 | - * @deprecated |
|
2038 | - * @since 4.7.0 |
|
2039 | - * @access public |
|
2040 | - */ |
|
2041 | - public function price_paid() |
|
2042 | - { |
|
2043 | - EE_Error::doing_it_wrong( |
|
2044 | - 'EE_Registration::price_paid()', |
|
2045 | - esc_html__( |
|
2046 | - 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
2047 | - 'event_espresso' |
|
2048 | - ), |
|
2049 | - '4.7.0' |
|
2050 | - ); |
|
2051 | - return $this->final_price(); |
|
2052 | - } |
|
2053 | - |
|
2054 | - |
|
2055 | - /** |
|
2056 | - * @deprecated |
|
2057 | - * @since 4.7.0 |
|
2058 | - * @access public |
|
2059 | - * @param float $REG_final_price |
|
2060 | - * @throws EE_Error |
|
2061 | - * @throws RuntimeException |
|
2062 | - */ |
|
2063 | - public function set_price_paid($REG_final_price = 0.00) |
|
2064 | - { |
|
2065 | - EE_Error::doing_it_wrong( |
|
2066 | - 'EE_Registration::set_price_paid()', |
|
2067 | - esc_html__( |
|
2068 | - 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
2069 | - 'event_espresso' |
|
2070 | - ), |
|
2071 | - '4.7.0' |
|
2072 | - ); |
|
2073 | - $this->set_final_price($REG_final_price); |
|
2074 | - } |
|
2075 | - |
|
2076 | - |
|
2077 | - /** |
|
2078 | - * @deprecated |
|
2079 | - * @since 4.7.0 |
|
2080 | - * @return string |
|
2081 | - * @throws EE_Error |
|
2082 | - */ |
|
2083 | - public function pretty_price_paid() |
|
2084 | - { |
|
2085 | - EE_Error::doing_it_wrong( |
|
2086 | - 'EE_Registration::pretty_price_paid()', |
|
2087 | - esc_html__( |
|
2088 | - 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
2089 | - 'event_espresso' |
|
2090 | - ), |
|
2091 | - '4.7.0' |
|
2092 | - ); |
|
2093 | - return $this->pretty_final_price(); |
|
2094 | - } |
|
2095 | - |
|
2096 | - |
|
2097 | - /** |
|
2098 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
2099 | - * |
|
2100 | - * @deprecated 4.9.17 |
|
2101 | - * @return EE_Datetime |
|
2102 | - * @throws EE_Error |
|
2103 | - * @throws EntityNotFoundException |
|
2104 | - */ |
|
2105 | - public function get_related_primary_datetime() |
|
2106 | - { |
|
2107 | - EE_Error::doing_it_wrong( |
|
2108 | - __METHOD__, |
|
2109 | - esc_html__( |
|
2110 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
2111 | - 'event_espresso' |
|
2112 | - ), |
|
2113 | - '4.9.17', |
|
2114 | - '5.0.0' |
|
2115 | - ); |
|
2116 | - return $this->event()->primary_datetime(); |
|
2117 | - } |
|
2118 | - |
|
2119 | - /** |
|
2120 | - * Returns the contact's name (or "Unknown" if there is no contact.) |
|
20 | + /** |
|
21 | + * Used to reference when a registration has never been checked in. |
|
22 | + * |
|
23 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
24 | + * @type int |
|
25 | + */ |
|
26 | + const checkin_status_never = 2; |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to reference when a registration has been checked in. |
|
30 | + * |
|
31 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
32 | + * @type int |
|
33 | + */ |
|
34 | + const checkin_status_in = 1; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Used to reference when a registration has been checked out. |
|
39 | + * |
|
40 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
41 | + * @type int |
|
42 | + */ |
|
43 | + const checkin_status_out = 0; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * extra meta key for tracking reg status os trashed registrations |
|
48 | + * |
|
49 | + * @type string |
|
50 | + */ |
|
51 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * extra meta key for tracking if registration has reserved ticket |
|
56 | + * |
|
57 | + * @type string |
|
58 | + */ |
|
59 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param array $props_n_values incoming values |
|
64 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
65 | + * used.) |
|
66 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
67 | + * date_format and the second value is the time format |
|
68 | + * @return EE_Registration |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
72 | + { |
|
73 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
74 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param array $props_n_values incoming values from the database |
|
80 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
81 | + * the website will be used. |
|
82 | + * @return EE_Registration |
|
83 | + */ |
|
84 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
85 | + { |
|
86 | + return new self($props_n_values, true, $timezone); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Set Event ID |
|
92 | + * |
|
93 | + * @param int $EVT_ID Event ID |
|
94 | + * @throws EE_Error |
|
95 | + * @throws RuntimeException |
|
96 | + */ |
|
97 | + public function set_event($EVT_ID = 0) |
|
98 | + { |
|
99 | + $this->set('EVT_ID', $EVT_ID); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
105 | + * be routed to internal methods |
|
106 | + * |
|
107 | + * @param string $field_name |
|
108 | + * @param mixed $field_value |
|
109 | + * @param bool $use_default |
|
110 | + * @throws EE_Error |
|
111 | + * @throws EntityNotFoundException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws ReflectionException |
|
116 | + * @throws RuntimeException |
|
117 | + */ |
|
118 | + public function set($field_name, $field_value, $use_default = false) |
|
119 | + { |
|
120 | + switch ($field_name) { |
|
121 | + case 'REG_code': |
|
122 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
123 | + $this->set_reg_code($field_value, $use_default); |
|
124 | + } |
|
125 | + break; |
|
126 | + case 'STS_ID': |
|
127 | + $this->set_status($field_value, $use_default); |
|
128 | + break; |
|
129 | + default: |
|
130 | + parent::set($field_name, $field_value, $use_default); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Set Status ID |
|
137 | + * updates the registration status and ALSO... |
|
138 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
139 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
140 | + * |
|
141 | + * @param string $new_STS_ID |
|
142 | + * @param boolean $use_default |
|
143 | + * @param ContextInterface|null $context |
|
144 | + * @return bool |
|
145 | + * @throws DomainException |
|
146 | + * @throws EE_Error |
|
147 | + * @throws EntityNotFoundException |
|
148 | + * @throws InvalidArgumentException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidInterfaceException |
|
151 | + * @throws ReflectionException |
|
152 | + * @throws RuntimeException |
|
153 | + * @throws UnexpectedEntityException |
|
154 | + */ |
|
155 | + public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
156 | + { |
|
157 | + // get current REG_Status |
|
158 | + $old_STS_ID = $this->status_ID(); |
|
159 | + // if status has changed |
|
160 | + if ( |
|
161 | + $old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
162 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
163 | + && ! empty($new_STS_ID) // as well as the new status |
|
164 | + && $this->ID() // ensure registration is in the db |
|
165 | + ) { |
|
166 | + // update internal status first |
|
167 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
168 | + // THEN handle other changes that occur when reg status changes |
|
169 | + // TO approved |
|
170 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | + // reserve a space by incrementing ticket and datetime sold values |
|
172 | + $this->reserveRegistrationSpace(); |
|
173 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
174 | + // OR FROM approved |
|
175 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
176 | + // release a space by decrementing ticket and datetime sold values |
|
177 | + $this->releaseRegistrationSpace(); |
|
178 | + do_action( |
|
179 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
180 | + $this, |
|
181 | + $old_STS_ID, |
|
182 | + $new_STS_ID, |
|
183 | + $context |
|
184 | + ); |
|
185 | + } |
|
186 | + // update status |
|
187 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
188 | + $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context); |
|
189 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
190 | + $this->updateTransactionAfterStatusChange(); |
|
191 | + } |
|
192 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
193 | + return true; |
|
194 | + } |
|
195 | + // even though the old value matches the new value, it's still good to |
|
196 | + // allow the parent set method to have a say |
|
197 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
198 | + return true; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * update REGs and TXN when cancelled or declined registrations involved |
|
204 | + * |
|
205 | + * @param string $new_STS_ID |
|
206 | + * @param string $old_STS_ID |
|
207 | + * @param ContextInterface|null $context |
|
208 | + * @throws EE_Error |
|
209 | + * @throws InvalidArgumentException |
|
210 | + * @throws InvalidDataTypeException |
|
211 | + * @throws InvalidInterfaceException |
|
212 | + * @throws ReflectionException |
|
213 | + * @throws RuntimeException |
|
214 | + */ |
|
215 | + private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
216 | + { |
|
217 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
218 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
219 | + // true if registration has been cancelled or declined |
|
220 | + $this->updateIfCanceled( |
|
221 | + $closed_reg_statuses, |
|
222 | + $new_STS_ID, |
|
223 | + $old_STS_ID, |
|
224 | + $context |
|
225 | + ); |
|
226 | + $this->updateIfReinstated( |
|
227 | + $closed_reg_statuses, |
|
228 | + $new_STS_ID, |
|
229 | + $old_STS_ID, |
|
230 | + $context |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * update REGs and TXN when cancelled or declined registrations involved |
|
237 | + * |
|
238 | + * @param array $closed_reg_statuses |
|
239 | + * @param string $new_STS_ID |
|
240 | + * @param string $old_STS_ID |
|
241 | + * @param ContextInterface|null $context |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws ReflectionException |
|
247 | + * @throws RuntimeException |
|
248 | + */ |
|
249 | + private function updateIfCanceled( |
|
250 | + array $closed_reg_statuses, |
|
251 | + $new_STS_ID, |
|
252 | + $old_STS_ID, |
|
253 | + ContextInterface $context = null |
|
254 | + ) { |
|
255 | + // true if registration has been cancelled or declined |
|
256 | + if ( |
|
257 | + in_array($new_STS_ID, $closed_reg_statuses, true) |
|
258 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
259 | + ) { |
|
260 | + /** @type EE_Registration_Processor $registration_processor */ |
|
261 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
262 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
263 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
264 | + // cancelled or declined registration |
|
265 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
266 | + $this, |
|
267 | + $closed_reg_statuses |
|
268 | + ); |
|
269 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
270 | + $this, |
|
271 | + $closed_reg_statuses, |
|
272 | + false |
|
273 | + ); |
|
274 | + do_action( |
|
275 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
276 | + $this, |
|
277 | + $old_STS_ID, |
|
278 | + $new_STS_ID, |
|
279 | + $context |
|
280 | + ); |
|
281 | + return; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * update REGs and TXN when cancelled or declined registrations involved |
|
288 | + * |
|
289 | + * @param array $closed_reg_statuses |
|
290 | + * @param string $new_STS_ID |
|
291 | + * @param string $old_STS_ID |
|
292 | + * @param ContextInterface|null $context |
|
293 | + * @throws EE_Error |
|
294 | + * @throws InvalidArgumentException |
|
295 | + * @throws InvalidDataTypeException |
|
296 | + * @throws InvalidInterfaceException |
|
297 | + * @throws ReflectionException |
|
298 | + */ |
|
299 | + private function updateIfReinstated( |
|
300 | + array $closed_reg_statuses, |
|
301 | + $new_STS_ID, |
|
302 | + $old_STS_ID, |
|
303 | + ContextInterface $context = null |
|
304 | + ) { |
|
305 | + // true if reinstating cancelled or declined registration |
|
306 | + if ( |
|
307 | + in_array($old_STS_ID, $closed_reg_statuses, true) |
|
308 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
309 | + ) { |
|
310 | + /** @type EE_Registration_Processor $registration_processor */ |
|
311 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
312 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
313 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
314 | + // reinstating cancelled or declined registration |
|
315 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
316 | + $this, |
|
317 | + $closed_reg_statuses |
|
318 | + ); |
|
319 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
320 | + $this, |
|
321 | + $closed_reg_statuses, |
|
322 | + false |
|
323 | + ); |
|
324 | + do_action( |
|
325 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
326 | + $this, |
|
327 | + $old_STS_ID, |
|
328 | + $new_STS_ID, |
|
329 | + $context |
|
330 | + ); |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param ContextInterface|null $context |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
340 | + { |
|
341 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
342 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
343 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
344 | + $context, |
|
345 | + $this |
|
346 | + ); |
|
347 | + return ! ( |
|
348 | + $context instanceof ContextInterface |
|
349 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
350 | + ); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @throws EE_Error |
|
356 | + * @throws EntityNotFoundException |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidDataTypeException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws ReflectionException |
|
361 | + * @throws RuntimeException |
|
362 | + */ |
|
363 | + private function updateTransactionAfterStatusChange() |
|
364 | + { |
|
365 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
366 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
367 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
368 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * get Status ID |
|
374 | + */ |
|
375 | + public function status_ID() |
|
376 | + { |
|
377 | + return $this->get('STS_ID'); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Gets the ticket this registration is for |
|
383 | + * |
|
384 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
385 | + * |
|
386 | + * @return EE_Ticket|EE_Base_Class |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function ticket($include_archived = true) |
|
390 | + { |
|
391 | + $query_params = array(); |
|
392 | + if ($include_archived) { |
|
393 | + $query_params['default_where_conditions'] = 'none'; |
|
394 | + } |
|
395 | + return $this->get_first_related('Ticket', $query_params); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * Gets the event this registration is for |
|
401 | + * |
|
402 | + * @return EE_Event |
|
403 | + * @throws EE_Error |
|
404 | + * @throws EntityNotFoundException |
|
405 | + */ |
|
406 | + public function event() |
|
407 | + { |
|
408 | + $event = $this->get_first_related('Event'); |
|
409 | + if (! $event instanceof \EE_Event) { |
|
410 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
411 | + } |
|
412 | + return $event; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
418 | + * with the author of the event this registration is for. |
|
419 | + * |
|
420 | + * @since 4.5.0 |
|
421 | + * @return int |
|
422 | + * @throws EE_Error |
|
423 | + * @throws EntityNotFoundException |
|
424 | + */ |
|
425 | + public function wp_user() |
|
426 | + { |
|
427 | + $event = $this->event(); |
|
428 | + if ($event instanceof EE_Event) { |
|
429 | + return $event->wp_user(); |
|
430 | + } |
|
431 | + return 0; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
437 | + * |
|
438 | + * @return void |
|
439 | + * @throws DomainException |
|
440 | + * @throws EE_Error |
|
441 | + * @throws EntityNotFoundException |
|
442 | + * @throws InvalidArgumentException |
|
443 | + * @throws InvalidDataTypeException |
|
444 | + * @throws InvalidInterfaceException |
|
445 | + * @throws ReflectionException |
|
446 | + * @throws UnexpectedEntityException |
|
447 | + */ |
|
448 | + private function reserveRegistrationSpace() |
|
449 | + { |
|
450 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
451 | + // so stop tracking that this reg has a ticket reserved |
|
452 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
453 | + $ticket = $this->ticket(); |
|
454 | + $ticket->increaseSold(); |
|
455 | + // possibly set event status to sold out |
|
456 | + $this->event()->perform_sold_out_status_check(); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
462 | + * |
|
463 | + * @return void |
|
464 | + * @throws DomainException |
|
465 | + * @throws EE_Error |
|
466 | + * @throws EntityNotFoundException |
|
467 | + * @throws InvalidArgumentException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + * @throws ReflectionException |
|
471 | + * @throws UnexpectedEntityException |
|
472 | + */ |
|
473 | + private function releaseRegistrationSpace() |
|
474 | + { |
|
475 | + $ticket = $this->ticket(); |
|
476 | + $ticket->decreaseSold(); |
|
477 | + // possibly change event status from sold out back to previous status |
|
478 | + $this->event()->perform_sold_out_status_check(); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * tracks this registration's ticket reservation in extra meta |
|
484 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
485 | + * |
|
486 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
487 | + * @return void |
|
488 | + * @throws EE_Error |
|
489 | + * @throws InvalidArgumentException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws InvalidInterfaceException |
|
492 | + * @throws ReflectionException |
|
493 | + */ |
|
494 | + public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
495 | + { |
|
496 | + // only reserve ticket if space is not currently reserved |
|
497 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
498 | + $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
499 | + // IMPORTANT !!! |
|
500 | + // although checking $update_ticket first would be more efficient, |
|
501 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
502 | + if ( |
|
503 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
504 | + && $update_ticket |
|
505 | + ) { |
|
506 | + $ticket = $this->ticket(); |
|
507 | + $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
508 | + $ticket->save(); |
|
509 | + } |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * stops tracking this registration's ticket reservation in extra meta |
|
516 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
517 | + * |
|
518 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
519 | + * @return void |
|
520 | + * @throws EE_Error |
|
521 | + * @throws InvalidArgumentException |
|
522 | + * @throws InvalidDataTypeException |
|
523 | + * @throws InvalidInterfaceException |
|
524 | + * @throws ReflectionException |
|
525 | + */ |
|
526 | + public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
527 | + { |
|
528 | + // only release ticket if space is currently reserved |
|
529 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
530 | + $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
531 | + // IMPORTANT !!! |
|
532 | + // although checking $update_ticket first would be more efficient, |
|
533 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
534 | + if ( |
|
535 | + $this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
536 | + && $update_ticket |
|
537 | + ) { |
|
538 | + $ticket = $this->ticket(); |
|
539 | + $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Set Attendee ID |
|
547 | + * |
|
548 | + * @param int $ATT_ID Attendee ID |
|
549 | + * @throws EE_Error |
|
550 | + * @throws RuntimeException |
|
551 | + */ |
|
552 | + public function set_attendee_id($ATT_ID = 0) |
|
553 | + { |
|
554 | + $this->set('ATT_ID', $ATT_ID); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Set Transaction ID |
|
560 | + * |
|
561 | + * @param int $TXN_ID Transaction ID |
|
562 | + * @throws EE_Error |
|
563 | + * @throws RuntimeException |
|
564 | + */ |
|
565 | + public function set_transaction_id($TXN_ID = 0) |
|
566 | + { |
|
567 | + $this->set('TXN_ID', $TXN_ID); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Set Session |
|
573 | + * |
|
574 | + * @param string $REG_session PHP Session ID |
|
575 | + * @throws EE_Error |
|
576 | + * @throws RuntimeException |
|
577 | + */ |
|
578 | + public function set_session($REG_session = '') |
|
579 | + { |
|
580 | + $this->set('REG_session', $REG_session); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Set Registration URL Link |
|
586 | + * |
|
587 | + * @param string $REG_url_link Registration URL Link |
|
588 | + * @throws EE_Error |
|
589 | + * @throws RuntimeException |
|
590 | + */ |
|
591 | + public function set_reg_url_link($REG_url_link = '') |
|
592 | + { |
|
593 | + $this->set('REG_url_link', $REG_url_link); |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Set Attendee Counter |
|
599 | + * |
|
600 | + * @param int $REG_count Primary Attendee |
|
601 | + * @throws EE_Error |
|
602 | + * @throws RuntimeException |
|
603 | + */ |
|
604 | + public function set_count($REG_count = 1) |
|
605 | + { |
|
606 | + $this->set('REG_count', $REG_count); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Set Group Size |
|
612 | + * |
|
613 | + * @param boolean $REG_group_size Group Registration |
|
614 | + * @throws EE_Error |
|
615 | + * @throws RuntimeException |
|
616 | + */ |
|
617 | + public function set_group_size($REG_group_size = false) |
|
618 | + { |
|
619 | + $this->set('REG_group_size', $REG_group_size); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
625 | + * EEM_Registration::status_id_not_approved |
|
626 | + * |
|
627 | + * @return boolean |
|
628 | + */ |
|
629 | + public function is_not_approved() |
|
630 | + { |
|
631 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
637 | + * EEM_Registration::status_id_pending_payment |
|
638 | + * |
|
639 | + * @return boolean |
|
640 | + */ |
|
641 | + public function is_pending_payment() |
|
642 | + { |
|
643 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
649 | + * |
|
650 | + * @return boolean |
|
651 | + */ |
|
652 | + public function is_approved() |
|
653 | + { |
|
654 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
660 | + * |
|
661 | + * @return boolean |
|
662 | + */ |
|
663 | + public function is_cancelled() |
|
664 | + { |
|
665 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
671 | + * |
|
672 | + * @return boolean |
|
673 | + */ |
|
674 | + public function is_declined() |
|
675 | + { |
|
676 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
682 | + * EEM_Registration::status_id_incomplete |
|
683 | + * |
|
684 | + * @return boolean |
|
685 | + */ |
|
686 | + public function is_incomplete() |
|
687 | + { |
|
688 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * Set Registration Date |
|
694 | + * |
|
695 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
696 | + * Date |
|
697 | + * @throws EE_Error |
|
698 | + * @throws RuntimeException |
|
699 | + */ |
|
700 | + public function set_reg_date($REG_date = false) |
|
701 | + { |
|
702 | + $this->set('REG_date', $REG_date); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * Set final price owing for this registration after all ticket/price modifications |
|
708 | + * |
|
709 | + * @access public |
|
710 | + * @param float $REG_final_price |
|
711 | + * @throws EE_Error |
|
712 | + * @throws RuntimeException |
|
713 | + */ |
|
714 | + public function set_final_price($REG_final_price = 0.00) |
|
715 | + { |
|
716 | + $this->set('REG_final_price', $REG_final_price); |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Set amount paid towards this registration's final price |
|
722 | + * |
|
723 | + * @access public |
|
724 | + * @param float $REG_paid |
|
725 | + * @throws EE_Error |
|
726 | + * @throws RuntimeException |
|
727 | + */ |
|
728 | + public function set_paid($REG_paid = 0.00) |
|
729 | + { |
|
730 | + $this->set('REG_paid', $REG_paid); |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + /** |
|
735 | + * Attendee Is Going |
|
736 | + * |
|
737 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
738 | + * @throws EE_Error |
|
739 | + * @throws RuntimeException |
|
740 | + */ |
|
741 | + public function set_att_is_going($REG_att_is_going = false) |
|
742 | + { |
|
743 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * Gets the related attendee |
|
749 | + * |
|
750 | + * @return EE_Attendee |
|
751 | + * @throws EE_Error |
|
752 | + */ |
|
753 | + public function attendee() |
|
754 | + { |
|
755 | + return $this->get_first_related('Attendee'); |
|
756 | + } |
|
757 | + |
|
758 | + /** |
|
759 | + * Gets the name of the attendee. |
|
760 | + * @since 4.10.12.p |
|
761 | + * @param bool $apply_html_entities set to true if you want to use HTML entities. |
|
762 | + * @return string |
|
763 | + * @throws EE_Error |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws InvalidDataTypeException |
|
766 | + * @throws InvalidInterfaceException |
|
767 | + * @throws ReflectionException |
|
768 | + */ |
|
769 | + public function attendeeName($apply_html_entities = false) |
|
770 | + { |
|
771 | + $attendee = $this->get_first_related('Attendee'); |
|
772 | + if ($attendee instanceof EE_Attendee) { |
|
773 | + $attendee_name = $attendee->full_name($apply_html_entities); |
|
774 | + } else { |
|
775 | + $attendee_name = esc_html__('Unknown', 'event_espresso'); |
|
776 | + } |
|
777 | + return $attendee_name; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + /** |
|
782 | + * get Event ID |
|
783 | + */ |
|
784 | + public function event_ID() |
|
785 | + { |
|
786 | + return $this->get('EVT_ID'); |
|
787 | + } |
|
788 | + |
|
789 | + |
|
790 | + /** |
|
791 | + * get Event ID |
|
792 | + */ |
|
793 | + public function event_name() |
|
794 | + { |
|
795 | + $event = $this->event_obj(); |
|
796 | + if ($event) { |
|
797 | + return $event->name(); |
|
798 | + } else { |
|
799 | + return null; |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * Fetches the event this registration is for |
|
806 | + * |
|
807 | + * @return EE_Event |
|
808 | + * @throws EE_Error |
|
809 | + */ |
|
810 | + public function event_obj() |
|
811 | + { |
|
812 | + return $this->get_first_related('Event'); |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * get Attendee ID |
|
818 | + */ |
|
819 | + public function attendee_ID() |
|
820 | + { |
|
821 | + return $this->get('ATT_ID'); |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * get PHP Session ID |
|
827 | + */ |
|
828 | + public function session_ID() |
|
829 | + { |
|
830 | + return $this->get('REG_session'); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + /** |
|
835 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
836 | + * |
|
837 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
838 | + * @return string |
|
839 | + */ |
|
840 | + public function receipt_url($messenger = 'html') |
|
841 | + { |
|
842 | + |
|
843 | + /** |
|
844 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
845 | + * already in use on old system. If there is then we just return the standard url for it. |
|
846 | + * |
|
847 | + * @since 4.5.0 |
|
848 | + */ |
|
849 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
850 | + $has_custom = EEH_Template::locate_template( |
|
851 | + $template_relative_path, |
|
852 | + array(), |
|
853 | + true, |
|
854 | + true, |
|
855 | + true |
|
856 | + ); |
|
857 | + |
|
858 | + if ($has_custom) { |
|
859 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
860 | + } |
|
861 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
867 | + * |
|
868 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
869 | + * @return string |
|
870 | + * @throws EE_Error |
|
871 | + */ |
|
872 | + public function invoice_url($messenger = 'html') |
|
873 | + { |
|
874 | + /** |
|
875 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
876 | + * already in use on old system. If there is then we just return the standard url for it. |
|
877 | + * |
|
878 | + * @since 4.5.0 |
|
879 | + */ |
|
880 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
881 | + $has_custom = EEH_Template::locate_template( |
|
882 | + $template_relative_path, |
|
883 | + array(), |
|
884 | + true, |
|
885 | + true, |
|
886 | + true |
|
887 | + ); |
|
888 | + |
|
889 | + if ($has_custom) { |
|
890 | + if ($messenger == 'html') { |
|
891 | + return $this->invoice_url('launch'); |
|
892 | + } |
|
893 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
894 | + |
|
895 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
896 | + if ($messenger == 'html') { |
|
897 | + $query_args['html'] = true; |
|
898 | + } |
|
899 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
900 | + } |
|
901 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * get Registration URL Link |
|
907 | + * |
|
908 | + * @access public |
|
909 | + * @return string |
|
910 | + * @throws EE_Error |
|
911 | + */ |
|
912 | + public function reg_url_link() |
|
913 | + { |
|
914 | + return (string) $this->get('REG_url_link'); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * Echoes out invoice_url() |
|
920 | + * |
|
921 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
922 | + * @return void |
|
923 | + * @throws EE_Error |
|
924 | + */ |
|
925 | + public function e_invoice_url($type = 'launch') |
|
926 | + { |
|
927 | + echo $this->invoice_url($type); |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * Echoes out payment_overview_url |
|
933 | + */ |
|
934 | + public function e_payment_overview_url() |
|
935 | + { |
|
936 | + echo $this->payment_overview_url(); |
|
937 | + } |
|
938 | + |
|
939 | + |
|
940 | + /** |
|
941 | + * Gets the URL for the checkout payment options reg step |
|
942 | + * with this registration's REG_url_link added as a query parameter |
|
943 | + * |
|
944 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
945 | + * payment overview url. |
|
946 | + * @return string |
|
947 | + * @throws InvalidInterfaceException |
|
948 | + * @throws InvalidDataTypeException |
|
949 | + * @throws EE_Error |
|
950 | + * @throws InvalidArgumentException |
|
951 | + */ |
|
952 | + public function payment_overview_url($clear_session = false) |
|
953 | + { |
|
954 | + return add_query_arg( |
|
955 | + (array) apply_filters( |
|
956 | + 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
957 | + array( |
|
958 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
959 | + 'step' => 'payment_options', |
|
960 | + 'revisit' => true, |
|
961 | + 'clear_session' => (bool) $clear_session, |
|
962 | + ), |
|
963 | + $this |
|
964 | + ), |
|
965 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
966 | + ); |
|
967 | + } |
|
968 | + |
|
969 | + |
|
970 | + /** |
|
971 | + * Gets the URL for the checkout attendee information reg step |
|
972 | + * with this registration's REG_url_link added as a query parameter |
|
973 | + * |
|
974 | + * @return string |
|
975 | + * @throws InvalidInterfaceException |
|
976 | + * @throws InvalidDataTypeException |
|
977 | + * @throws EE_Error |
|
978 | + * @throws InvalidArgumentException |
|
979 | + */ |
|
980 | + public function edit_attendee_information_url() |
|
981 | + { |
|
982 | + return add_query_arg( |
|
983 | + (array) apply_filters( |
|
984 | + 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
985 | + array( |
|
986 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
987 | + 'step' => 'attendee_information', |
|
988 | + 'revisit' => true, |
|
989 | + ), |
|
990 | + $this |
|
991 | + ), |
|
992 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
993 | + ); |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
999 | + * |
|
1000 | + * @return string |
|
1001 | + * @throws EE_Error |
|
1002 | + */ |
|
1003 | + public function get_admin_edit_url() |
|
1004 | + { |
|
1005 | + return EEH_URL::add_query_args_and_nonce( |
|
1006 | + array( |
|
1007 | + 'page' => 'espresso_registrations', |
|
1008 | + 'action' => 'view_registration', |
|
1009 | + '_REG_ID' => $this->ID(), |
|
1010 | + ), |
|
1011 | + admin_url('admin.php') |
|
1012 | + ); |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * is_primary_registrant? |
|
1018 | + */ |
|
1019 | + public function is_primary_registrant() |
|
1020 | + { |
|
1021 | + return $this->get('REG_count') === 1 ? true : false; |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * This returns the primary registration object for this registration group (which may be this object). |
|
1027 | + * |
|
1028 | + * @return EE_Registration |
|
1029 | + * @throws EE_Error |
|
1030 | + */ |
|
1031 | + public function get_primary_registration() |
|
1032 | + { |
|
1033 | + if ($this->is_primary_registrant()) { |
|
1034 | + return $this; |
|
1035 | + } |
|
1036 | + |
|
1037 | + // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
1038 | + /** @var EE_Registration $primary_registrant */ |
|
1039 | + $primary_registrant = EEM_Registration::instance()->get_one( |
|
1040 | + array( |
|
1041 | + array( |
|
1042 | + 'TXN_ID' => $this->transaction_ID(), |
|
1043 | + 'REG_count' => 1, |
|
1044 | + ), |
|
1045 | + ) |
|
1046 | + ); |
|
1047 | + return $primary_registrant; |
|
1048 | + } |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * get Attendee Number |
|
1053 | + * |
|
1054 | + * @access public |
|
1055 | + */ |
|
1056 | + public function count() |
|
1057 | + { |
|
1058 | + return $this->get('REG_count'); |
|
1059 | + } |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * get Group Size |
|
1064 | + */ |
|
1065 | + public function group_size() |
|
1066 | + { |
|
1067 | + return $this->get('REG_group_size'); |
|
1068 | + } |
|
1069 | + |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * get Registration Date |
|
1073 | + */ |
|
1074 | + public function date() |
|
1075 | + { |
|
1076 | + return $this->get('REG_date'); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * gets a pretty date |
|
1082 | + * |
|
1083 | + * @param string $date_format |
|
1084 | + * @param string $time_format |
|
1085 | + * @return string |
|
1086 | + * @throws EE_Error |
|
1087 | + */ |
|
1088 | + public function pretty_date($date_format = null, $time_format = null) |
|
1089 | + { |
|
1090 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * final_price |
|
1096 | + * the registration's share of the transaction total, so that the |
|
1097 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1098 | + * |
|
1099 | + * @return float |
|
1100 | + * @throws EE_Error |
|
1101 | + */ |
|
1102 | + public function final_price() |
|
1103 | + { |
|
1104 | + return $this->get('REG_final_price'); |
|
1105 | + } |
|
1106 | + |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * pretty_final_price |
|
1110 | + * final price as formatted string, with correct decimal places and currency symbol |
|
1111 | + * |
|
1112 | + * @return string |
|
1113 | + * @throws EE_Error |
|
1114 | + */ |
|
1115 | + public function pretty_final_price() |
|
1116 | + { |
|
1117 | + return $this->get_pretty('REG_final_price'); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * get paid (yeah) |
|
1123 | + * |
|
1124 | + * @return float |
|
1125 | + * @throws EE_Error |
|
1126 | + */ |
|
1127 | + public function paid() |
|
1128 | + { |
|
1129 | + return $this->get('REG_paid'); |
|
1130 | + } |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * pretty_paid |
|
1135 | + * |
|
1136 | + * @return float |
|
1137 | + * @throws EE_Error |
|
1138 | + */ |
|
1139 | + public function pretty_paid() |
|
1140 | + { |
|
1141 | + return $this->get_pretty('REG_paid'); |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * owes_monies_and_can_pay |
|
1147 | + * whether or not this registration has monies owing and it's' status allows payment |
|
1148 | + * |
|
1149 | + * @param array $requires_payment |
|
1150 | + * @return bool |
|
1151 | + * @throws EE_Error |
|
1152 | + */ |
|
1153 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
1154 | + { |
|
1155 | + // these reg statuses require payment (if event is not free) |
|
1156 | + $requires_payment = ! empty($requires_payment) |
|
1157 | + ? $requires_payment |
|
1158 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1159 | + if ( |
|
1160 | + in_array($this->status_ID(), $requires_payment) && |
|
1161 | + $this->final_price() != 0 && |
|
1162 | + $this->final_price() != $this->paid() |
|
1163 | + ) { |
|
1164 | + return true; |
|
1165 | + } else { |
|
1166 | + return false; |
|
1167 | + } |
|
1168 | + } |
|
1169 | + |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * Prints out the return value of $this->pretty_status() |
|
1173 | + * |
|
1174 | + * @param bool $show_icons |
|
1175 | + * @return void |
|
1176 | + * @throws EE_Error |
|
1177 | + */ |
|
1178 | + public function e_pretty_status($show_icons = false) |
|
1179 | + { |
|
1180 | + echo $this->pretty_status($show_icons); |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Returns a nice version of the status for displaying to customers |
|
1186 | + * |
|
1187 | + * @param bool $show_icons |
|
1188 | + * @return string |
|
1189 | + * @throws EE_Error |
|
1190 | + */ |
|
1191 | + public function pretty_status($show_icons = false) |
|
1192 | + { |
|
1193 | + $status = EEM_Status::instance()->localized_status( |
|
1194 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1195 | + false, |
|
1196 | + 'sentence' |
|
1197 | + ); |
|
1198 | + $icon = ''; |
|
1199 | + switch ($this->status_ID()) { |
|
1200 | + case EEM_Registration::status_id_approved: |
|
1201 | + $icon = $show_icons |
|
1202 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1203 | + : ''; |
|
1204 | + break; |
|
1205 | + case EEM_Registration::status_id_pending_payment: |
|
1206 | + $icon = $show_icons |
|
1207 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1208 | + : ''; |
|
1209 | + break; |
|
1210 | + case EEM_Registration::status_id_not_approved: |
|
1211 | + $icon = $show_icons |
|
1212 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1213 | + : ''; |
|
1214 | + break; |
|
1215 | + case EEM_Registration::status_id_cancelled: |
|
1216 | + $icon = $show_icons |
|
1217 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1218 | + : ''; |
|
1219 | + break; |
|
1220 | + case EEM_Registration::status_id_incomplete: |
|
1221 | + $icon = $show_icons |
|
1222 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1223 | + : ''; |
|
1224 | + break; |
|
1225 | + case EEM_Registration::status_id_declined: |
|
1226 | + $icon = $show_icons |
|
1227 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1228 | + : ''; |
|
1229 | + break; |
|
1230 | + case EEM_Registration::status_id_wait_list: |
|
1231 | + $icon = $show_icons |
|
1232 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1233 | + : ''; |
|
1234 | + break; |
|
1235 | + } |
|
1236 | + return $icon . $status[ $this->status_ID() ]; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * get Attendee Is Going |
|
1242 | + */ |
|
1243 | + public function att_is_going() |
|
1244 | + { |
|
1245 | + return $this->get('REG_att_is_going'); |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Gets related answers |
|
1251 | + * |
|
1252 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1253 | + * @return EE_Answer[] |
|
1254 | + * @throws EE_Error |
|
1255 | + */ |
|
1256 | + public function answers($query_params = null) |
|
1257 | + { |
|
1258 | + return $this->get_many_related('Answer', $query_params); |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Gets the registration's answer value to the specified question |
|
1264 | + * (either the question's ID or a question object) |
|
1265 | + * |
|
1266 | + * @param EE_Question|int $question |
|
1267 | + * @param bool $pretty_value |
|
1268 | + * @return array|string if pretty_value= true, the result will always be a string |
|
1269 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1270 | + * will convert it into some kind of string) |
|
1271 | + * @throws EE_Error |
|
1272 | + */ |
|
1273 | + public function answer_value_to_question($question, $pretty_value = true) |
|
1274 | + { |
|
1275 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1276 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1277 | + } |
|
1278 | + |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * question_groups |
|
1282 | + * returns an array of EE_Question_Group objects for this registration |
|
1283 | + * |
|
1284 | + * @return EE_Question_Group[] |
|
1285 | + * @throws EE_Error |
|
1286 | + * @throws InvalidArgumentException |
|
1287 | + * @throws InvalidDataTypeException |
|
1288 | + * @throws InvalidInterfaceException |
|
1289 | + * @throws ReflectionException |
|
1290 | + */ |
|
1291 | + public function question_groups() |
|
1292 | + { |
|
1293 | + return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this); |
|
1294 | + } |
|
1295 | + |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * count_question_groups |
|
1299 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
1300 | + * |
|
1301 | + * @return int |
|
1302 | + * @throws EE_Error |
|
1303 | + * @throws EntityNotFoundException |
|
1304 | + * @throws InvalidArgumentException |
|
1305 | + * @throws InvalidDataTypeException |
|
1306 | + * @throws InvalidInterfaceException |
|
1307 | + * @throws ReflectionException |
|
1308 | + */ |
|
1309 | + public function count_question_groups() |
|
1310 | + { |
|
1311 | + return EEM_Event::instance()->count_related( |
|
1312 | + $this->event_ID(), |
|
1313 | + 'Question_Group', |
|
1314 | + [ |
|
1315 | + [ |
|
1316 | + 'Event_Question_Group.' |
|
1317 | + . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true, |
|
1318 | + ] |
|
1319 | + ] |
|
1320 | + ); |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * Returns the registration date in the 'standard' string format |
|
1326 | + * (function may be improved in the future to allow for different formats and timezones) |
|
1327 | + * |
|
1328 | + * @return string |
|
1329 | + * @throws EE_Error |
|
1330 | + */ |
|
1331 | + public function reg_date() |
|
1332 | + { |
|
1333 | + return $this->get_datetime('REG_date'); |
|
1334 | + } |
|
1335 | + |
|
1336 | + |
|
1337 | + /** |
|
1338 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1339 | + * the ticket this registration purchased, or the datetime they have registered |
|
1340 | + * to attend) |
|
1341 | + * |
|
1342 | + * @return EE_Datetime_Ticket |
|
1343 | + * @throws EE_Error |
|
1344 | + */ |
|
1345 | + public function datetime_ticket() |
|
1346 | + { |
|
1347 | + return $this->get_first_related('Datetime_Ticket'); |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Sets the registration's datetime_ticket. |
|
1353 | + * |
|
1354 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
1355 | + * @return EE_Datetime_Ticket |
|
1356 | + * @throws EE_Error |
|
1357 | + */ |
|
1358 | + public function set_datetime_ticket($datetime_ticket) |
|
1359 | + { |
|
1360 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1361 | + } |
|
1362 | + |
|
1363 | + /** |
|
1364 | + * Gets deleted |
|
1365 | + * |
|
1366 | + * @return bool |
|
1367 | + * @throws EE_Error |
|
1368 | + */ |
|
1369 | + public function deleted() |
|
1370 | + { |
|
1371 | + return $this->get('REG_deleted'); |
|
1372 | + } |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * Sets deleted |
|
1376 | + * |
|
1377 | + * @param boolean $deleted |
|
1378 | + * @return bool |
|
1379 | + * @throws EE_Error |
|
1380 | + * @throws RuntimeException |
|
1381 | + */ |
|
1382 | + public function set_deleted($deleted) |
|
1383 | + { |
|
1384 | + if ($deleted) { |
|
1385 | + $this->delete(); |
|
1386 | + } else { |
|
1387 | + $this->restore(); |
|
1388 | + } |
|
1389 | + } |
|
1390 | + |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * Get the status object of this object |
|
1394 | + * |
|
1395 | + * @return EE_Status |
|
1396 | + * @throws EE_Error |
|
1397 | + */ |
|
1398 | + public function status_obj() |
|
1399 | + { |
|
1400 | + return $this->get_first_related('Status'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + /** |
|
1405 | + * Returns the number of times this registration has checked into any of the datetimes |
|
1406 | + * its available for |
|
1407 | + * |
|
1408 | + * @return int |
|
1409 | + * @throws EE_Error |
|
1410 | + */ |
|
1411 | + public function count_checkins() |
|
1412 | + { |
|
1413 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1419 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1420 | + * |
|
1421 | + * @return int |
|
1422 | + * @throws EE_Error |
|
1423 | + */ |
|
1424 | + public function count_checkins_not_checkedout() |
|
1425 | + { |
|
1426 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1427 | + } |
|
1428 | + |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1432 | + * |
|
1433 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1434 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1435 | + * consider registration status as well as datetime access. |
|
1436 | + * @return bool |
|
1437 | + * @throws EE_Error |
|
1438 | + */ |
|
1439 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1440 | + { |
|
1441 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1442 | + |
|
1443 | + // first check registration status |
|
1444 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1445 | + return false; |
|
1446 | + } |
|
1447 | + // is there a datetime ticket that matches this dtt_ID? |
|
1448 | + if ( |
|
1449 | + ! (EEM_Datetime_Ticket::instance()->exists( |
|
1450 | + array( |
|
1451 | + array( |
|
1452 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
1453 | + 'DTT_ID' => $DTT_ID, |
|
1454 | + ), |
|
1455 | + ) |
|
1456 | + )) |
|
1457 | + ) { |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + |
|
1461 | + // final check is against TKT_uses |
|
1462 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1463 | + } |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1468 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1469 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1470 | + * then return false. Otherwise return true. |
|
1471 | + * |
|
1472 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1473 | + * @return bool true means can checkin. false means cannot checkin. |
|
1474 | + * @throws EE_Error |
|
1475 | + */ |
|
1476 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1477 | + { |
|
1478 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1479 | + |
|
1480 | + if (! $DTT_ID) { |
|
1481 | + return false; |
|
1482 | + } |
|
1483 | + |
|
1484 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1485 | + |
|
1486 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1487 | + // check-in or not. |
|
1488 | + if (! $max_uses || $max_uses === EE_INF) { |
|
1489 | + return true; |
|
1490 | + } |
|
1491 | + |
|
1492 | + // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1493 | + // go ahead and toggle. |
|
1494 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1495 | + return true; |
|
1496 | + } |
|
1497 | + |
|
1498 | + // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1499 | + // disallows further check-ins. |
|
1500 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
1501 | + array( |
|
1502 | + array( |
|
1503 | + 'REG_ID' => $this->ID(), |
|
1504 | + 'CHK_in' => true, |
|
1505 | + ), |
|
1506 | + ), |
|
1507 | + 'DTT_ID', |
|
1508 | + true |
|
1509 | + ); |
|
1510 | + // checkins have already reached their max number of uses |
|
1511 | + // so registrant can NOT checkin |
|
1512 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1513 | + EE_Error::add_error( |
|
1514 | + esc_html__( |
|
1515 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1516 | + 'event_espresso' |
|
1517 | + ), |
|
1518 | + __FILE__, |
|
1519 | + __FUNCTION__, |
|
1520 | + __LINE__ |
|
1521 | + ); |
|
1522 | + return false; |
|
1523 | + } |
|
1524 | + return true; |
|
1525 | + } |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * toggle Check-in status for this registration |
|
1530 | + * Check-ins are toggled in the following order: |
|
1531 | + * never checked in -> checked in |
|
1532 | + * checked in -> checked out |
|
1533 | + * checked out -> checked in |
|
1534 | + * |
|
1535 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1536 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1537 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1538 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1539 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1540 | + * @throws EE_Error |
|
1541 | + */ |
|
1542 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1543 | + { |
|
1544 | + if (empty($DTT_ID)) { |
|
1545 | + $datetime = $this->get_latest_related_datetime(); |
|
1546 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1547 | + // verify the registration can checkin for the given DTT_ID |
|
1548 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1549 | + EE_Error::add_error( |
|
1550 | + sprintf( |
|
1551 | + esc_html__( |
|
1552 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1553 | + 'event_espresso' |
|
1554 | + ), |
|
1555 | + $this->ID(), |
|
1556 | + $DTT_ID |
|
1557 | + ), |
|
1558 | + __FILE__, |
|
1559 | + __FUNCTION__, |
|
1560 | + __LINE__ |
|
1561 | + ); |
|
1562 | + return false; |
|
1563 | + } |
|
1564 | + $status_paths = array( |
|
1565 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1566 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1567 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1568 | + ); |
|
1569 | + // start by getting the current status so we know what status we'll be changing to. |
|
1570 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1571 | + $status_to = $status_paths[ $cur_status ]; |
|
1572 | + // database only records true for checked IN or false for checked OUT |
|
1573 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1574 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1575 | + // add relation - note Check-ins are always creating new rows |
|
1576 | + // because we are keeping track of Check-ins over time. |
|
1577 | + // Eventually we'll probably want to show a list table |
|
1578 | + // for the individual Check-ins so that they can be managed. |
|
1579 | + $checkin = EE_Checkin::new_instance( |
|
1580 | + array( |
|
1581 | + 'REG_ID' => $this->ID(), |
|
1582 | + 'DTT_ID' => $DTT_ID, |
|
1583 | + 'CHK_in' => $new_status, |
|
1584 | + ) |
|
1585 | + ); |
|
1586 | + // if the record could not be saved then return false |
|
1587 | + if ($checkin->save() === 0) { |
|
1588 | + if (WP_DEBUG) { |
|
1589 | + global $wpdb; |
|
1590 | + $error = sprintf( |
|
1591 | + esc_html__( |
|
1592 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1593 | + 'event_espresso' |
|
1594 | + ), |
|
1595 | + '<br />', |
|
1596 | + $wpdb->last_error |
|
1597 | + ); |
|
1598 | + } else { |
|
1599 | + $error = esc_html__( |
|
1600 | + 'Registration check in update failed because of an unknown database error', |
|
1601 | + 'event_espresso' |
|
1602 | + ); |
|
1603 | + } |
|
1604 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1605 | + return false; |
|
1606 | + } |
|
1607 | + // Fire a checked_in and checkout_out action. |
|
1608 | + $checked_status = $status_to === EE_Checkin::status_checked_in ? 'checked_in' : 'checked_out'; |
|
1609 | + do_action("AHEE__EE_Registration__toggle_checkin_status__{$checked_status}", $this, $DTT_ID); |
|
1610 | + return $status_to; |
|
1611 | + } |
|
1612 | + |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1616 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1617 | + * |
|
1618 | + * @return EE_Datetime|null |
|
1619 | + * @throws EE_Error |
|
1620 | + */ |
|
1621 | + public function get_latest_related_datetime() |
|
1622 | + { |
|
1623 | + return EEM_Datetime::instance()->get_one( |
|
1624 | + array( |
|
1625 | + array( |
|
1626 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1627 | + ), |
|
1628 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1629 | + ) |
|
1630 | + ); |
|
1631 | + } |
|
1632 | + |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1636 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1637 | + * |
|
1638 | + * @throws EE_Error |
|
1639 | + */ |
|
1640 | + public function get_earliest_related_datetime() |
|
1641 | + { |
|
1642 | + return EEM_Datetime::instance()->get_one( |
|
1643 | + array( |
|
1644 | + array( |
|
1645 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1646 | + ), |
|
1647 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1648 | + ) |
|
1649 | + ); |
|
1650 | + } |
|
1651 | + |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1655 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1656 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1657 | + * |
|
1658 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1659 | + * (if empty we'll get the primary datetime for |
|
1660 | + * this registration (via event) and use it's ID); |
|
1661 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1662 | + * |
|
1663 | + * @return int Integer representing Check-in status. |
|
1664 | + * @throws EE_Error |
|
1665 | + */ |
|
1666 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1667 | + { |
|
1668 | + $checkin_query_params = array( |
|
1669 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1670 | + ); |
|
1671 | + |
|
1672 | + if ($DTT_ID > 0) { |
|
1673 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1674 | + } |
|
1675 | + |
|
1676 | + // get checkin object (if exists) |
|
1677 | + $checkin = $checkin instanceof EE_Checkin |
|
1678 | + ? $checkin |
|
1679 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1680 | + if ($checkin instanceof EE_Checkin) { |
|
1681 | + if ($checkin->get('CHK_in')) { |
|
1682 | + return EE_Checkin::status_checked_in; // checked in |
|
1683 | + } |
|
1684 | + return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
1685 | + } |
|
1686 | + return EE_Checkin::status_checked_never; // never been checked in |
|
1687 | + } |
|
1688 | + |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * This method returns a localized message for the toggled Check-in message. |
|
1692 | + * |
|
1693 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1694 | + * then it is assumed Check-in for primary datetime was toggled. |
|
1695 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1696 | + * message can be customized with the attendee name. |
|
1697 | + * @return string internationalized message |
|
1698 | + * @throws EE_Error |
|
1699 | + */ |
|
1700 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
1701 | + { |
|
1702 | + // let's get the attendee first so we can include the name of the attendee |
|
1703 | + $attendee = $this->get_first_related('Attendee'); |
|
1704 | + if ($attendee instanceof EE_Attendee) { |
|
1705 | + if ($error) { |
|
1706 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1707 | + } |
|
1708 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1709 | + // what is the status message going to be? |
|
1710 | + switch ($cur_status) { |
|
1711 | + case EE_Checkin::status_checked_never: |
|
1712 | + return sprintf( |
|
1713 | + __("%s has been removed from Check-in records", "event_espresso"), |
|
1714 | + $attendee->full_name() |
|
1715 | + ); |
|
1716 | + break; |
|
1717 | + case EE_Checkin::status_checked_in: |
|
1718 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1719 | + break; |
|
1720 | + case EE_Checkin::status_checked_out: |
|
1721 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1722 | + break; |
|
1723 | + } |
|
1724 | + } |
|
1725 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1726 | + } |
|
1727 | + |
|
1728 | + |
|
1729 | + /** |
|
1730 | + * Returns the related EE_Transaction to this registration |
|
1731 | + * |
|
1732 | + * @return EE_Transaction |
|
1733 | + * @throws EE_Error |
|
1734 | + * @throws EntityNotFoundException |
|
1735 | + */ |
|
1736 | + public function transaction() |
|
1737 | + { |
|
1738 | + $transaction = $this->get_first_related('Transaction'); |
|
1739 | + if (! $transaction instanceof \EE_Transaction) { |
|
1740 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1741 | + } |
|
1742 | + return $transaction; |
|
1743 | + } |
|
1744 | + |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * get Registration Code |
|
1748 | + */ |
|
1749 | + public function reg_code() |
|
1750 | + { |
|
1751 | + return $this->get('REG_code'); |
|
1752 | + } |
|
1753 | + |
|
1754 | + |
|
1755 | + /** |
|
1756 | + * get Transaction ID |
|
1757 | + */ |
|
1758 | + public function transaction_ID() |
|
1759 | + { |
|
1760 | + return $this->get('TXN_ID'); |
|
1761 | + } |
|
1762 | + |
|
1763 | + |
|
1764 | + /** |
|
1765 | + * @return int |
|
1766 | + * @throws EE_Error |
|
1767 | + */ |
|
1768 | + public function ticket_ID() |
|
1769 | + { |
|
1770 | + return $this->get('TKT_ID'); |
|
1771 | + } |
|
1772 | + |
|
1773 | + |
|
1774 | + /** |
|
1775 | + * Set Registration Code |
|
1776 | + * |
|
1777 | + * @access public |
|
1778 | + * @param string $REG_code Registration Code |
|
1779 | + * @param boolean $use_default |
|
1780 | + * @throws EE_Error |
|
1781 | + */ |
|
1782 | + public function set_reg_code($REG_code, $use_default = false) |
|
1783 | + { |
|
1784 | + if (empty($REG_code)) { |
|
1785 | + EE_Error::add_error( |
|
1786 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1787 | + __FILE__, |
|
1788 | + __FUNCTION__, |
|
1789 | + __LINE__ |
|
1790 | + ); |
|
1791 | + return; |
|
1792 | + } |
|
1793 | + if (! $this->reg_code()) { |
|
1794 | + parent::set('REG_code', $REG_code, $use_default); |
|
1795 | + } else { |
|
1796 | + EE_Error::doing_it_wrong( |
|
1797 | + __CLASS__ . '::' . __FUNCTION__, |
|
1798 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1799 | + '4.6.0' |
|
1800 | + ); |
|
1801 | + } |
|
1802 | + } |
|
1803 | + |
|
1804 | + |
|
1805 | + /** |
|
1806 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1807 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1808 | + * $registration->transaction()->registrations(); |
|
1809 | + * |
|
1810 | + * @since 4.5.0 |
|
1811 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1812 | + * @throws EE_Error |
|
1813 | + */ |
|
1814 | + public function get_all_other_registrations_in_group() |
|
1815 | + { |
|
1816 | + if ($this->group_size() < 2) { |
|
1817 | + return array(); |
|
1818 | + } |
|
1819 | + |
|
1820 | + $query[0] = array( |
|
1821 | + 'TXN_ID' => $this->transaction_ID(), |
|
1822 | + 'REG_ID' => array('!=', $this->ID()), |
|
1823 | + 'TKT_ID' => $this->ticket_ID(), |
|
1824 | + ); |
|
1825 | + /** @var EE_Registration[] $registrations */ |
|
1826 | + $registrations = $this->get_model()->get_all($query); |
|
1827 | + return $registrations; |
|
1828 | + } |
|
1829 | + |
|
1830 | + /** |
|
1831 | + * Return the link to the admin details for the object. |
|
1832 | + * |
|
1833 | + * @return string |
|
1834 | + * @throws EE_Error |
|
1835 | + */ |
|
1836 | + public function get_admin_details_link() |
|
1837 | + { |
|
1838 | + EE_Registry::instance()->load_helper('URL'); |
|
1839 | + return EEH_URL::add_query_args_and_nonce( |
|
1840 | + array( |
|
1841 | + 'page' => 'espresso_registrations', |
|
1842 | + 'action' => 'view_registration', |
|
1843 | + '_REG_ID' => $this->ID(), |
|
1844 | + ), |
|
1845 | + admin_url('admin.php') |
|
1846 | + ); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1851 | + * |
|
1852 | + * @return string |
|
1853 | + * @throws EE_Error |
|
1854 | + */ |
|
1855 | + public function get_admin_edit_link() |
|
1856 | + { |
|
1857 | + return $this->get_admin_details_link(); |
|
1858 | + } |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * Returns the link to a settings page for the object. |
|
1862 | + * |
|
1863 | + * @return string |
|
1864 | + * @throws EE_Error |
|
1865 | + */ |
|
1866 | + public function get_admin_settings_link() |
|
1867 | + { |
|
1868 | + return $this->get_admin_details_link(); |
|
1869 | + } |
|
1870 | + |
|
1871 | + /** |
|
1872 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1873 | + * |
|
1874 | + * @return string |
|
1875 | + */ |
|
1876 | + public function get_admin_overview_link() |
|
1877 | + { |
|
1878 | + EE_Registry::instance()->load_helper('URL'); |
|
1879 | + return EEH_URL::add_query_args_and_nonce( |
|
1880 | + array( |
|
1881 | + 'page' => 'espresso_registrations', |
|
1882 | + ), |
|
1883 | + admin_url('admin.php') |
|
1884 | + ); |
|
1885 | + } |
|
1886 | + |
|
1887 | + |
|
1888 | + /** |
|
1889 | + * @param array $query_params |
|
1890 | + * |
|
1891 | + * @return \EE_Registration[] |
|
1892 | + * @throws EE_Error |
|
1893 | + */ |
|
1894 | + public function payments($query_params = array()) |
|
1895 | + { |
|
1896 | + return $this->get_many_related('Payment', $query_params); |
|
1897 | + } |
|
1898 | + |
|
1899 | + |
|
1900 | + /** |
|
1901 | + * @param array $query_params |
|
1902 | + * |
|
1903 | + * @return \EE_Registration_Payment[] |
|
1904 | + * @throws EE_Error |
|
1905 | + */ |
|
1906 | + public function registration_payments($query_params = array()) |
|
1907 | + { |
|
1908 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1909 | + } |
|
1910 | + |
|
1911 | + |
|
1912 | + /** |
|
1913 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1914 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
1915 | + * |
|
1916 | + * @return EE_Payment_Method|null |
|
1917 | + */ |
|
1918 | + public function payment_method() |
|
1919 | + { |
|
1920 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1921 | + } |
|
1922 | + |
|
1923 | + |
|
1924 | + /** |
|
1925 | + * @return \EE_Line_Item |
|
1926 | + * @throws EntityNotFoundException |
|
1927 | + * @throws EE_Error |
|
1928 | + */ |
|
1929 | + public function ticket_line_item() |
|
1930 | + { |
|
1931 | + $ticket = $this->ticket(); |
|
1932 | + $transaction = $this->transaction(); |
|
1933 | + $line_item = null; |
|
1934 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1935 | + $transaction->total_line_item(), |
|
1936 | + 'Ticket', |
|
1937 | + array($ticket->ID()) |
|
1938 | + ); |
|
1939 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
1940 | + if ( |
|
1941 | + $ticket_line_item instanceof \EE_Line_Item |
|
1942 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1943 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1944 | + ) { |
|
1945 | + $line_item = $ticket_line_item; |
|
1946 | + break; |
|
1947 | + } |
|
1948 | + } |
|
1949 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1950 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1951 | + } |
|
1952 | + return $line_item; |
|
1953 | + } |
|
1954 | + |
|
1955 | + |
|
1956 | + /** |
|
1957 | + * Soft Deletes this model object. |
|
1958 | + * |
|
1959 | + * @return boolean | int |
|
1960 | + * @throws RuntimeException |
|
1961 | + * @throws EE_Error |
|
1962 | + */ |
|
1963 | + public function delete() |
|
1964 | + { |
|
1965 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1966 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
1967 | + } |
|
1968 | + return parent::delete(); |
|
1969 | + } |
|
1970 | + |
|
1971 | + |
|
1972 | + /** |
|
1973 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1974 | + * |
|
1975 | + * @throws EE_Error |
|
1976 | + * @throws RuntimeException |
|
1977 | + */ |
|
1978 | + public function restore() |
|
1979 | + { |
|
1980 | + $previous_status = $this->get_extra_meta( |
|
1981 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1982 | + true, |
|
1983 | + EEM_Registration::status_id_cancelled |
|
1984 | + ); |
|
1985 | + if ($previous_status) { |
|
1986 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1987 | + $this->set_status($previous_status); |
|
1988 | + } |
|
1989 | + return parent::restore(); |
|
1990 | + } |
|
1991 | + |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1995 | + * |
|
1996 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1997 | + * depending on whether the reg status changes to or from "Approved" |
|
1998 | + * @return boolean whether the Registration status was updated |
|
1999 | + * @throws EE_Error |
|
2000 | + * @throws RuntimeException |
|
2001 | + */ |
|
2002 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
2003 | + { |
|
2004 | + $paid = $this->paid(); |
|
2005 | + $price = $this->final_price(); |
|
2006 | + switch (true) { |
|
2007 | + // overpaid or paid |
|
2008 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
2009 | + case EEH_Money::compare_floats($paid, $price): |
|
2010 | + $new_status = EEM_Registration::status_id_approved; |
|
2011 | + break; |
|
2012 | + // underpaid |
|
2013 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
2014 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
2015 | + break; |
|
2016 | + // uhhh Houston... |
|
2017 | + default: |
|
2018 | + throw new RuntimeException( |
|
2019 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
2020 | + ); |
|
2021 | + } |
|
2022 | + if ($new_status !== $this->status_ID()) { |
|
2023 | + if ($trigger_set_status_logic) { |
|
2024 | + return $this->set_status($new_status); |
|
2025 | + } |
|
2026 | + parent::set('STS_ID', $new_status); |
|
2027 | + return true; |
|
2028 | + } |
|
2029 | + return false; |
|
2030 | + } |
|
2031 | + |
|
2032 | + |
|
2033 | + /*************************** DEPRECATED ***************************/ |
|
2034 | + |
|
2035 | + |
|
2036 | + /** |
|
2037 | + * @deprecated |
|
2038 | + * @since 4.7.0 |
|
2039 | + * @access public |
|
2040 | + */ |
|
2041 | + public function price_paid() |
|
2042 | + { |
|
2043 | + EE_Error::doing_it_wrong( |
|
2044 | + 'EE_Registration::price_paid()', |
|
2045 | + esc_html__( |
|
2046 | + 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
2047 | + 'event_espresso' |
|
2048 | + ), |
|
2049 | + '4.7.0' |
|
2050 | + ); |
|
2051 | + return $this->final_price(); |
|
2052 | + } |
|
2053 | + |
|
2054 | + |
|
2055 | + /** |
|
2056 | + * @deprecated |
|
2057 | + * @since 4.7.0 |
|
2058 | + * @access public |
|
2059 | + * @param float $REG_final_price |
|
2060 | + * @throws EE_Error |
|
2061 | + * @throws RuntimeException |
|
2062 | + */ |
|
2063 | + public function set_price_paid($REG_final_price = 0.00) |
|
2064 | + { |
|
2065 | + EE_Error::doing_it_wrong( |
|
2066 | + 'EE_Registration::set_price_paid()', |
|
2067 | + esc_html__( |
|
2068 | + 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
2069 | + 'event_espresso' |
|
2070 | + ), |
|
2071 | + '4.7.0' |
|
2072 | + ); |
|
2073 | + $this->set_final_price($REG_final_price); |
|
2074 | + } |
|
2075 | + |
|
2076 | + |
|
2077 | + /** |
|
2078 | + * @deprecated |
|
2079 | + * @since 4.7.0 |
|
2080 | + * @return string |
|
2081 | + * @throws EE_Error |
|
2082 | + */ |
|
2083 | + public function pretty_price_paid() |
|
2084 | + { |
|
2085 | + EE_Error::doing_it_wrong( |
|
2086 | + 'EE_Registration::pretty_price_paid()', |
|
2087 | + esc_html__( |
|
2088 | + 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
2089 | + 'event_espresso' |
|
2090 | + ), |
|
2091 | + '4.7.0' |
|
2092 | + ); |
|
2093 | + return $this->pretty_final_price(); |
|
2094 | + } |
|
2095 | + |
|
2096 | + |
|
2097 | + /** |
|
2098 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
2099 | + * |
|
2100 | + * @deprecated 4.9.17 |
|
2101 | + * @return EE_Datetime |
|
2102 | + * @throws EE_Error |
|
2103 | + * @throws EntityNotFoundException |
|
2104 | + */ |
|
2105 | + public function get_related_primary_datetime() |
|
2106 | + { |
|
2107 | + EE_Error::doing_it_wrong( |
|
2108 | + __METHOD__, |
|
2109 | + esc_html__( |
|
2110 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
2111 | + 'event_espresso' |
|
2112 | + ), |
|
2113 | + '4.9.17', |
|
2114 | + '5.0.0' |
|
2115 | + ); |
|
2116 | + return $this->event()->primary_datetime(); |
|
2117 | + } |
|
2118 | + |
|
2119 | + /** |
|
2120 | + * Returns the contact's name (or "Unknown" if there is no contact.) |
|
2121 | 2121 | <<<<<<< HEAD |
2122 | - * @since $VID:$ |
|
2122 | + * @since $VID:$ |
|
2123 | 2123 | ======= |
2124 | - * @since 4.10.12.p |
|
2124 | + * @since 4.10.12.p |
|
2125 | 2125 | >>>>>>> master |
2126 | - * @return string |
|
2127 | - * @throws EE_Error |
|
2128 | - * @throws InvalidArgumentException |
|
2129 | - * @throws InvalidDataTypeException |
|
2130 | - * @throws InvalidInterfaceException |
|
2131 | - * @throws ReflectionException |
|
2132 | - */ |
|
2133 | - public function name() |
|
2134 | - { |
|
2135 | - return $this->attendeeName(); |
|
2136 | - } |
|
2126 | + * @return string |
|
2127 | + * @throws EE_Error |
|
2128 | + * @throws InvalidArgumentException |
|
2129 | + * @throws InvalidDataTypeException |
|
2130 | + * @throws InvalidInterfaceException |
|
2131 | + * @throws ReflectionException |
|
2132 | + */ |
|
2133 | + public function name() |
|
2134 | + { |
|
2135 | + return $this->attendeeName(); |
|
2136 | + } |
|
2137 | 2137 | } |
@@ -31,105 +31,105 @@ |
||
31 | 31 | */ |
32 | 32 | abstract class BaseNode |
33 | 33 | { |
34 | - /** |
|
35 | - * @var boolean |
|
36 | - */ |
|
37 | - protected $complete; |
|
34 | + /** |
|
35 | + * @var boolean |
|
36 | + */ |
|
37 | + protected $complete; |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @var array of model names we don't want to traverse |
|
42 | - */ |
|
43 | - protected $dont_traverse_models; |
|
40 | + /** |
|
41 | + * @var array of model names we don't want to traverse |
|
42 | + */ |
|
43 | + protected $dont_traverse_models; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Whether this item has already been initialized |
|
47 | - */ |
|
48 | - abstract protected function isDiscovered(); |
|
45 | + /** |
|
46 | + * Whether this item has already been initialized |
|
47 | + */ |
|
48 | + abstract protected function isDiscovered(); |
|
49 | 49 | |
50 | - /** |
|
51 | - * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling |
|
52 | - * discover(). |
|
53 | - * @since 4.10.12.p |
|
54 | - * @return boolean |
|
55 | - */ |
|
56 | - abstract public function isComplete(); |
|
50 | + /** |
|
51 | + * Determines if the work is done yet or not. Requires you to have first discovered what work exists by calling |
|
52 | + * discover(). |
|
53 | + * @since 4.10.12.p |
|
54 | + * @return boolean |
|
55 | + */ |
|
56 | + abstract public function isComplete(); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Discovers what work needs to be done to complete traversing this node and its children. |
|
60 | - * Note that this is separate from the constructor, so we can create child nodes without |
|
61 | - * discovering them immediately. |
|
62 | - * @since 4.10.12.p |
|
63 | - * @return mixed |
|
64 | - */ |
|
65 | - abstract protected function discover(); |
|
58 | + /** |
|
59 | + * Discovers what work needs to be done to complete traversing this node and its children. |
|
60 | + * Note that this is separate from the constructor, so we can create child nodes without |
|
61 | + * discovering them immediately. |
|
62 | + * @since 4.10.12.p |
|
63 | + * @return mixed |
|
64 | + */ |
|
65 | + abstract protected function discover(); |
|
66 | 66 | |
67 | - /** |
|
68 | - * Identifies model objects, up to the limit $model_objects_to_identify. |
|
69 | - * @since 4.10.12.p |
|
70 | - * @param int $model_objects_to_identify |
|
71 | - * @return int units of work done |
|
72 | - */ |
|
73 | - abstract protected function work($model_objects_to_identify); |
|
67 | + /** |
|
68 | + * Identifies model objects, up to the limit $model_objects_to_identify. |
|
69 | + * @since 4.10.12.p |
|
70 | + * @param int $model_objects_to_identify |
|
71 | + * @return int units of work done |
|
72 | + */ |
|
73 | + abstract protected function work($model_objects_to_identify); |
|
74 | 74 | |
75 | - /** |
|
76 | - * Shows the entity/relation node as an array. |
|
77 | - * @since 4.10.12.p |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - abstract public function toArray(); |
|
75 | + /** |
|
76 | + * Shows the entity/relation node as an array. |
|
77 | + * @since 4.10.12.p |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + abstract public function toArray(); |
|
81 | 81 | |
82 | - /** |
|
83 | - * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work. |
|
84 | - * Note: do not call when site is in maintenance mode level 2. |
|
85 | - * |
|
86 | - * @since 4.10.12.p |
|
87 | - * @param $model_objects_to_identify |
|
88 | - * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue |
|
89 | - * where we left off. |
|
90 | - */ |
|
91 | - public function visit($model_objects_to_identify) |
|
92 | - { |
|
93 | - if (! $this->isDiscovered()) { |
|
94 | - $this->discover(); |
|
95 | - } |
|
96 | - if ($this->isComplete()) { |
|
97 | - return 0; |
|
98 | - } |
|
99 | - return $this->work($model_objects_to_identify); |
|
100 | - } |
|
82 | + /** |
|
83 | + * Discovers how much work there is to do, double-checks the work isn't already finished, and then does the work. |
|
84 | + * Note: do not call when site is in maintenance mode level 2. |
|
85 | + * |
|
86 | + * @since 4.10.12.p |
|
87 | + * @param $model_objects_to_identify |
|
88 | + * @return int number of model objects we want to identify during this call. On subsequent calls we'll continue |
|
89 | + * where we left off. |
|
90 | + */ |
|
91 | + public function visit($model_objects_to_identify) |
|
92 | + { |
|
93 | + if (! $this->isDiscovered()) { |
|
94 | + $this->discover(); |
|
95 | + } |
|
96 | + if ($this->isComplete()) { |
|
97 | + return 0; |
|
98 | + } |
|
99 | + return $this->work($model_objects_to_identify); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Gets the IDs of completely identified model objects that can be deleted. |
|
104 | - * @since 4.10.12.p |
|
105 | - * @return mixed |
|
106 | - */ |
|
107 | - abstract public function getIds(); |
|
102 | + /** |
|
103 | + * Gets the IDs of completely identified model objects that can be deleted. |
|
104 | + * @since 4.10.12.p |
|
105 | + * @return mixed |
|
106 | + */ |
|
107 | + abstract public function getIds(); |
|
108 | 108 | |
109 | - /** |
|
110 | - * Make sure we encode whether its complete or not, but don't use such a long name. |
|
111 | - * @since 4.10.12.p |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function __sleep() |
|
115 | - { |
|
116 | - $this->c = $this->complete; |
|
117 | - $this->dtm = $this->dont_traverse_models; |
|
118 | - return [ |
|
119 | - 'c', |
|
120 | - 'dtm' |
|
121 | - ]; |
|
122 | - } |
|
109 | + /** |
|
110 | + * Make sure we encode whether its complete or not, but don't use such a long name. |
|
111 | + * @since 4.10.12.p |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function __sleep() |
|
115 | + { |
|
116 | + $this->c = $this->complete; |
|
117 | + $this->dtm = $this->dont_traverse_models; |
|
118 | + return [ |
|
119 | + 'c', |
|
120 | + 'dtm' |
|
121 | + ]; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Use the dynamic property to set the "complete" property. |
|
126 | - * @since 4.10.12.p |
|
127 | - */ |
|
128 | - public function __wakeup() |
|
129 | - { |
|
130 | - $this->complete = $this->c; |
|
131 | - $this->dont_traverse_models = $this->dtm; |
|
132 | - } |
|
124 | + /** |
|
125 | + * Use the dynamic property to set the "complete" property. |
|
126 | + * @since 4.10.12.p |
|
127 | + */ |
|
128 | + public function __wakeup() |
|
129 | + { |
|
130 | + $this->complete = $this->c; |
|
131 | + $this->dont_traverse_models = $this->dtm; |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | // End of file BaseNode.php |
135 | 135 | // Location: EventEspresso\core\services\orm\tree_traversal/BaseNode.php |
@@ -28,287 +28,287 @@ |
||
28 | 28 | class RelationNode extends BaseNode |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var string|int |
|
33 | - */ |
|
34 | - protected $id; |
|
31 | + /** |
|
32 | + * @var string|int |
|
33 | + */ |
|
34 | + protected $id; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var EEM_Base |
|
38 | - */ |
|
39 | - protected $main_model; |
|
36 | + /** |
|
37 | + * @var EEM_Base |
|
38 | + */ |
|
39 | + protected $main_model; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - protected $count; |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + protected $count; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var EEM_Base |
|
48 | - */ |
|
49 | - protected $related_model; |
|
46 | + /** |
|
47 | + * @var EEM_Base |
|
48 | + */ |
|
49 | + protected $related_model; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var ModelObjNode[] |
|
53 | - */ |
|
54 | - protected $nodes; |
|
51 | + /** |
|
52 | + * @var ModelObjNode[] |
|
53 | + */ |
|
54 | + protected $nodes; |
|
55 | 55 | |
56 | - /** |
|
57 | - * RelationNode constructor. |
|
58 | - * @param $main_model_obj_id |
|
59 | - * @param EEM_Base $main_model |
|
60 | - * @param EEM_Base $related_model |
|
61 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - $main_model_obj_id, |
|
65 | - EEM_Base $main_model, |
|
66 | - EEM_Base $related_model, |
|
67 | - array $dont_traverse_models = [] |
|
68 | - ) { |
|
69 | - $this->id = $main_model_obj_id; |
|
70 | - $this->main_model = $main_model; |
|
71 | - $this->related_model = $related_model; |
|
72 | - $this->nodes = []; |
|
73 | - $this->dont_traverse_models = $dont_traverse_models; |
|
74 | - } |
|
56 | + /** |
|
57 | + * RelationNode constructor. |
|
58 | + * @param $main_model_obj_id |
|
59 | + * @param EEM_Base $main_model |
|
60 | + * @param EEM_Base $related_model |
|
61 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + $main_model_obj_id, |
|
65 | + EEM_Base $main_model, |
|
66 | + EEM_Base $related_model, |
|
67 | + array $dont_traverse_models = [] |
|
68 | + ) { |
|
69 | + $this->id = $main_model_obj_id; |
|
70 | + $this->main_model = $main_model; |
|
71 | + $this->related_model = $related_model; |
|
72 | + $this->nodes = []; |
|
73 | + $this->dont_traverse_models = $dont_traverse_models; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
79 | - * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
77 | + /** |
|
78 | + * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
79 | + * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
80 | 80 | * |
81 | - * @param int $model_objects_to_identify |
|
82 | - * @return int |
|
83 | - * @throws EE_Error |
|
84 | - * @throws InvalidArgumentException |
|
85 | - * @throws InvalidDataTypeException |
|
86 | - * @throws InvalidInterfaceException |
|
87 | - * @throws ReflectionException |
|
88 | - */ |
|
89 | - protected function work($model_objects_to_identify) |
|
90 | - { |
|
91 | - $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
92 | - if ($num_identified < $model_objects_to_identify) { |
|
93 | - $related_model_objs = $this->related_model->get_all( |
|
94 | - [ |
|
95 | - $this->whereQueryParams(), |
|
96 | - 'limit' => [ |
|
97 | - count($this->nodes), |
|
98 | - $model_objects_to_identify - $num_identified |
|
99 | - ] |
|
100 | - ] |
|
101 | - ); |
|
102 | - $new_item_nodes = []; |
|
81 | + * @param int $model_objects_to_identify |
|
82 | + * @return int |
|
83 | + * @throws EE_Error |
|
84 | + * @throws InvalidArgumentException |
|
85 | + * @throws InvalidDataTypeException |
|
86 | + * @throws InvalidInterfaceException |
|
87 | + * @throws ReflectionException |
|
88 | + */ |
|
89 | + protected function work($model_objects_to_identify) |
|
90 | + { |
|
91 | + $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
92 | + if ($num_identified < $model_objects_to_identify) { |
|
93 | + $related_model_objs = $this->related_model->get_all( |
|
94 | + [ |
|
95 | + $this->whereQueryParams(), |
|
96 | + 'limit' => [ |
|
97 | + count($this->nodes), |
|
98 | + $model_objects_to_identify - $num_identified |
|
99 | + ] |
|
100 | + ] |
|
101 | + ); |
|
102 | + $new_item_nodes = []; |
|
103 | 103 | |
104 | - // Add entity nodes for each of the model objects we fetched. |
|
105 | - foreach ($related_model_objs as $related_model_obj) { |
|
106 | - $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models); |
|
107 | - $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
108 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
109 | - } |
|
110 | - $num_identified += count($new_item_nodes); |
|
111 | - if ($num_identified < $model_objects_to_identify) { |
|
112 | - // And lastly do the work. |
|
113 | - $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
114 | - $new_item_nodes, |
|
115 | - $model_objects_to_identify - $num_identified |
|
116 | - ); |
|
117 | - } |
|
118 | - } |
|
104 | + // Add entity nodes for each of the model objects we fetched. |
|
105 | + foreach ($related_model_objs as $related_model_obj) { |
|
106 | + $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models); |
|
107 | + $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
108 | + $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
109 | + } |
|
110 | + $num_identified += count($new_item_nodes); |
|
111 | + if ($num_identified < $model_objects_to_identify) { |
|
112 | + // And lastly do the work. |
|
113 | + $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
114 | + $new_item_nodes, |
|
115 | + $model_objects_to_identify - $num_identified |
|
116 | + ); |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
121 | - $this->complete = true; |
|
122 | - } |
|
123 | - return $num_identified; |
|
124 | - } |
|
120 | + if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
121 | + $this->complete = true; |
|
122 | + } |
|
123 | + return $num_identified; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Checks if all the identified child nodes are complete or not. |
|
126 | + /** |
|
127 | + * Checks if all the identified child nodes are complete or not. |
|
128 | 128 | * |
129 | - * @return bool |
|
130 | - */ |
|
131 | - protected function allChildrenComplete() |
|
132 | - { |
|
133 | - foreach ($this->nodes as $model_obj_node) { |
|
134 | - if (! $model_obj_node->isComplete()) { |
|
135 | - return false; |
|
136 | - } |
|
137 | - } |
|
138 | - return true; |
|
139 | - } |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + protected function allChildrenComplete() |
|
132 | + { |
|
133 | + foreach ($this->nodes as $model_obj_node) { |
|
134 | + if (! $model_obj_node->isComplete()) { |
|
135 | + return false; |
|
136 | + } |
|
137 | + } |
|
138 | + return true; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
141 | + /** |
|
142 | + * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
143 | 143 | * |
144 | - * @param ModelObjNode[] $model_obj_nodes |
|
145 | - * @param $work_budget |
|
146 | - * @return int |
|
147 | - */ |
|
148 | - protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
149 | - { |
|
150 | - $work_done = 0; |
|
151 | - if (! $model_obj_nodes) { |
|
152 | - return 0; |
|
153 | - } |
|
154 | - foreach ($model_obj_nodes as $model_obj_node) { |
|
155 | - if ($work_done >= $work_budget) { |
|
156 | - break; |
|
157 | - } |
|
158 | - $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
159 | - } |
|
160 | - return $work_done; |
|
161 | - } |
|
144 | + * @param ModelObjNode[] $model_obj_nodes |
|
145 | + * @param $work_budget |
|
146 | + * @return int |
|
147 | + */ |
|
148 | + protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
149 | + { |
|
150 | + $work_done = 0; |
|
151 | + if (! $model_obj_nodes) { |
|
152 | + return 0; |
|
153 | + } |
|
154 | + foreach ($model_obj_nodes as $model_obj_node) { |
|
155 | + if ($work_done >= $work_budget) { |
|
156 | + break; |
|
157 | + } |
|
158 | + $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
159 | + } |
|
160 | + return $work_done; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Whether this item has already been initialized |
|
165 | - */ |
|
166 | - protected function isDiscovered() |
|
167 | - { |
|
168 | - return $this->count !== null; |
|
169 | - } |
|
163 | + /** |
|
164 | + * Whether this item has already been initialized |
|
165 | + */ |
|
166 | + protected function isDiscovered() |
|
167 | + { |
|
168 | + return $this->count !== null; |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @return boolean |
|
173 | - */ |
|
174 | - public function isComplete() |
|
175 | - { |
|
176 | - if ($this->complete === null) { |
|
177 | - if (count($this->nodes) === $this->count) { |
|
178 | - $this->complete = true; |
|
179 | - } else { |
|
180 | - $this->complete = false; |
|
181 | - } |
|
182 | - } |
|
183 | - return $this->complete; |
|
184 | - } |
|
171 | + /** |
|
172 | + * @return boolean |
|
173 | + */ |
|
174 | + public function isComplete() |
|
175 | + { |
|
176 | + if ($this->complete === null) { |
|
177 | + if (count($this->nodes) === $this->count) { |
|
178 | + $this->complete = true; |
|
179 | + } else { |
|
180 | + $this->complete = false; |
|
181 | + } |
|
182 | + } |
|
183 | + return $this->complete; |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Discovers how many related model objects exist. |
|
186 | + /** |
|
187 | + * Discovers how many related model objects exist. |
|
188 | 188 | * |
189 | - * @return mixed|void |
|
190 | - * @throws EE_Error |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - * @throws InvalidInterfaceException |
|
194 | - * @throws ReflectionException |
|
195 | - */ |
|
196 | - protected function discover() |
|
197 | - { |
|
198 | - $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
199 | - } |
|
189 | + * @return mixed|void |
|
190 | + * @throws EE_Error |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + * @throws InvalidInterfaceException |
|
194 | + * @throws ReflectionException |
|
195 | + */ |
|
196 | + protected function discover() |
|
197 | + { |
|
198 | + $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @return array |
|
203 | - * @throws EE_Error |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws InvalidArgumentException |
|
207 | - * @throws ReflectionException |
|
208 | - */ |
|
209 | - protected function whereQueryParams() |
|
210 | - { |
|
211 | - $where_params = [ |
|
212 | - $this->related_model->get_foreign_key_to( |
|
213 | - $this->main_model->get_this_model_name() |
|
214 | - )->get_name() => $this->id |
|
215 | - ]; |
|
216 | - try { |
|
217 | - $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
218 | - } catch (EE_Error $e) { |
|
219 | - // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
220 | - // which hasn't been explicitly declared in the main model object's model's relations. |
|
221 | - $relation_settings = null; |
|
222 | - } |
|
223 | - if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
224 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name(); |
|
225 | - } |
|
226 | - return $where_params; |
|
227 | - } |
|
228 | - /** |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - public function toArray() |
|
232 | - { |
|
233 | - $tree = [ |
|
234 | - 'count' => $this->count, |
|
235 | - 'complete' => $this->isComplete(), |
|
236 | - 'objs' => [] |
|
237 | - ]; |
|
238 | - foreach ($this->nodes as $id => $model_obj_node) { |
|
239 | - $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
240 | - } |
|
241 | - return $tree; |
|
242 | - } |
|
201 | + /** |
|
202 | + * @return array |
|
203 | + * @throws EE_Error |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws InvalidArgumentException |
|
207 | + * @throws ReflectionException |
|
208 | + */ |
|
209 | + protected function whereQueryParams() |
|
210 | + { |
|
211 | + $where_params = [ |
|
212 | + $this->related_model->get_foreign_key_to( |
|
213 | + $this->main_model->get_this_model_name() |
|
214 | + )->get_name() => $this->id |
|
215 | + ]; |
|
216 | + try { |
|
217 | + $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
218 | + } catch (EE_Error $e) { |
|
219 | + // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
220 | + // which hasn't been explicitly declared in the main model object's model's relations. |
|
221 | + $relation_settings = null; |
|
222 | + } |
|
223 | + if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
224 | + $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name(); |
|
225 | + } |
|
226 | + return $where_params; |
|
227 | + } |
|
228 | + /** |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + public function toArray() |
|
232 | + { |
|
233 | + $tree = [ |
|
234 | + 'count' => $this->count, |
|
235 | + 'complete' => $this->isComplete(), |
|
236 | + 'objs' => [] |
|
237 | + ]; |
|
238 | + foreach ($this->nodes as $id => $model_obj_node) { |
|
239 | + $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
240 | + } |
|
241 | + return $tree; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
244 | + /** |
|
245 | + * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
246 | 246 | * |
247 | - * @return array |
|
248 | - */ |
|
249 | - public function getIds() |
|
250 | - { |
|
251 | - if (empty($this->nodes)) { |
|
252 | - return []; |
|
253 | - } |
|
254 | - $ids = [ |
|
255 | - $this->related_model->get_this_model_name() => array_combine( |
|
256 | - array_keys($this->nodes), |
|
257 | - array_keys($this->nodes) |
|
258 | - ) |
|
259 | - ]; |
|
260 | - foreach ($this->nodes as $model_obj_node) { |
|
261 | - $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
262 | - } |
|
263 | - return $ids; |
|
264 | - } |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + public function getIds() |
|
250 | + { |
|
251 | + if (empty($this->nodes)) { |
|
252 | + return []; |
|
253 | + } |
|
254 | + $ids = [ |
|
255 | + $this->related_model->get_this_model_name() => array_combine( |
|
256 | + array_keys($this->nodes), |
|
257 | + array_keys($this->nodes) |
|
258 | + ) |
|
259 | + ]; |
|
260 | + foreach ($this->nodes as $model_obj_node) { |
|
261 | + $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
262 | + } |
|
263 | + return $ids; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
266 | + /** |
|
267 | + * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
268 | 268 | * |
269 | - * @return int |
|
270 | - */ |
|
271 | - public function countSubNodes() |
|
272 | - { |
|
273 | - return count($this->nodes); |
|
274 | - } |
|
269 | + * @return int |
|
270 | + */ |
|
271 | + public function countSubNodes() |
|
272 | + { |
|
273 | + return count($this->nodes); |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
276 | + /** |
|
277 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
278 | 278 | * |
279 | - * @return array |
|
280 | - */ |
|
281 | - public function __sleep() |
|
282 | - { |
|
283 | - $this->m = $this->main_model->get_this_model_name(); |
|
284 | - $this->rm = $this->related_model->get_this_model_name(); |
|
285 | - return array_merge( |
|
286 | - [ |
|
287 | - 'm', |
|
288 | - 'rm', |
|
289 | - 'id', |
|
290 | - 'count', |
|
291 | - 'nodes', |
|
292 | - ], |
|
293 | - parent::__sleep() |
|
294 | - ); |
|
295 | - } |
|
279 | + * @return array |
|
280 | + */ |
|
281 | + public function __sleep() |
|
282 | + { |
|
283 | + $this->m = $this->main_model->get_this_model_name(); |
|
284 | + $this->rm = $this->related_model->get_this_model_name(); |
|
285 | + return array_merge( |
|
286 | + [ |
|
287 | + 'm', |
|
288 | + 'rm', |
|
289 | + 'id', |
|
290 | + 'count', |
|
291 | + 'nodes', |
|
292 | + ], |
|
293 | + parent::__sleep() |
|
294 | + ); |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Use the dynamic properties to instantiate the models we use. |
|
297 | + /** |
|
298 | + * Use the dynamic properties to instantiate the models we use. |
|
299 | 299 | * |
300 | - * @throws EE_Error |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidDataTypeException |
|
303 | - * @throws InvalidInterfaceException |
|
304 | - * @throws ReflectionException |
|
305 | - */ |
|
306 | - public function __wakeup() |
|
307 | - { |
|
308 | - $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
309 | - $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
310 | - parent::__wakeup(); |
|
311 | - } |
|
300 | + * @throws EE_Error |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidDataTypeException |
|
303 | + * @throws InvalidInterfaceException |
|
304 | + * @throws ReflectionException |
|
305 | + */ |
|
306 | + public function __wakeup() |
|
307 | + { |
|
308 | + $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
309 | + $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
310 | + parent::__wakeup(); |
|
311 | + } |
|
312 | 312 | } |
313 | 313 | // End of file RelationNode.php |
314 | 314 | // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php |
@@ -22,110 +22,110 @@ |
||
22 | 22 | */ |
23 | 23 | class NodeGroupDao |
24 | 24 | { |
25 | - /** |
|
26 | - * @return mixed|void |
|
27 | - */ |
|
28 | - public function generateGroupCode() |
|
29 | - { |
|
30 | - return wp_generate_password(6, false); |
|
31 | - } |
|
25 | + /** |
|
26 | + * @return mixed|void |
|
27 | + */ |
|
28 | + public function generateGroupCode() |
|
29 | + { |
|
30 | + return wp_generate_password(6, false); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Gets the string we put in front of the WP Option name used to store the jobs. |
|
33 | + /** |
|
34 | + * Gets the string we put in front of the WP Option name used to store the jobs. |
|
35 | 35 | * |
36 | - * @return string |
|
37 | - */ |
|
38 | - private function getOptionPrefix() |
|
39 | - { |
|
40 | - return 'ee_deletion_'; |
|
41 | - } |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + private function getOptionPrefix() |
|
39 | + { |
|
40 | + return 'ee_deletion_'; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param $code |
|
45 | - * @return ModelObjNode[] |
|
46 | - * @throws UnexpectedEntityException |
|
47 | - */ |
|
48 | - public function getModelObjNodesInGroup($code) |
|
49 | - { |
|
50 | - if (! $code) { |
|
51 | - throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso')); |
|
52 | - } |
|
53 | - $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
54 | - foreach ($deletion_data as $root) { |
|
55 | - if (! $root instanceof ModelObjNode) { |
|
56 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
57 | - } |
|
58 | - } |
|
59 | - return $deletion_data; |
|
60 | - } |
|
43 | + /** |
|
44 | + * @param $code |
|
45 | + * @return ModelObjNode[] |
|
46 | + * @throws UnexpectedEntityException |
|
47 | + */ |
|
48 | + public function getModelObjNodesInGroup($code) |
|
49 | + { |
|
50 | + if (! $code) { |
|
51 | + throw new Exception(esc_html__('We aren’t sure which job you are performing. Please press back in your browser and try again.', 'event_espresso')); |
|
52 | + } |
|
53 | + $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
54 | + foreach ($deletion_data as $root) { |
|
55 | + if (! $root instanceof ModelObjNode) { |
|
56 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
57 | + } |
|
58 | + } |
|
59 | + return $deletion_data; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Gets an array indicating what database rows are contained in the job. |
|
64 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
62 | + /** |
|
63 | + * Gets an array indicating what database rows are contained in the job. |
|
64 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
65 | 65 | * |
66 | - * @param ModelObjNode[] $model_obj_nodes |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - * @throws InvalidArgumentException |
|
72 | - * @throws ReflectionException |
|
73 | - */ |
|
74 | - public function getModelsAndIdsContainedIn($model_obj_nodes) |
|
75 | - { |
|
76 | - $models_and_ids_to_delete = []; |
|
77 | - foreach ($model_obj_nodes as $root) { |
|
78 | - $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
79 | - } |
|
80 | - return $models_and_ids_to_delete; |
|
81 | - } |
|
66 | + * @param ModelObjNode[] $model_obj_nodes |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + * @throws InvalidArgumentException |
|
72 | + * @throws ReflectionException |
|
73 | + */ |
|
74 | + public function getModelsAndIdsContainedIn($model_obj_nodes) |
|
75 | + { |
|
76 | + $models_and_ids_to_delete = []; |
|
77 | + foreach ($model_obj_nodes as $root) { |
|
78 | + $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
79 | + } |
|
80 | + return $models_and_ids_to_delete; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Gets an array indicating what database rows are contained in the job. |
|
85 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
83 | + /** |
|
84 | + * Gets an array indicating what database rows are contained in the job. |
|
85 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
86 | 86 | * |
87 | - * @param string $code |
|
88 | - * @return array |
|
89 | - * @throws EE_Error |
|
90 | - * @throws InvalidArgumentException |
|
91 | - * @throws InvalidDataTypeException |
|
92 | - * @throws InvalidInterfaceException |
|
93 | - * @throws ReflectionException |
|
94 | - * @throws UnexpectedEntityException |
|
95 | - */ |
|
96 | - public function getModelsAndIdsFromGroup($code) |
|
97 | - { |
|
98 | - $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
99 | - return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
100 | - } |
|
87 | + * @param string $code |
|
88 | + * @return array |
|
89 | + * @throws EE_Error |
|
90 | + * @throws InvalidArgumentException |
|
91 | + * @throws InvalidDataTypeException |
|
92 | + * @throws InvalidInterfaceException |
|
93 | + * @throws ReflectionException |
|
94 | + * @throws UnexpectedEntityException |
|
95 | + */ |
|
96 | + public function getModelsAndIdsFromGroup($code) |
|
97 | + { |
|
98 | + $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
99 | + return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Persists the ModelObjNodes for future requests, using the code for reference. |
|
102 | + /** |
|
103 | + * Persists the ModelObjNodes for future requests, using the code for reference. |
|
104 | 104 | * |
105 | - * @param ModelObjNode[] $model_obj_nodes |
|
106 | - * @param string $code |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - public function persistModelObjNodesGroup($model_obj_nodes, $code) |
|
110 | - { |
|
111 | - return add_option( |
|
112 | - $this->getOptionPrefix() . $code, |
|
113 | - $model_obj_nodes, |
|
114 | - null, |
|
115 | - 'no' |
|
116 | - ); |
|
117 | - } |
|
105 | + * @param ModelObjNode[] $model_obj_nodes |
|
106 | + * @param string $code |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + public function persistModelObjNodesGroup($model_obj_nodes, $code) |
|
110 | + { |
|
111 | + return add_option( |
|
112 | + $this->getOptionPrefix() . $code, |
|
113 | + $model_obj_nodes, |
|
114 | + null, |
|
115 | + 'no' |
|
116 | + ); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
119 | + /** |
|
120 | + * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
121 | 121 | * |
122 | - * @param $code |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - public function deleteModelObjNodesInGroup($code) |
|
126 | - { |
|
127 | - return delete_option($this->getOptionPrefix() . $code); |
|
128 | - } |
|
122 | + * @param $code |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + public function deleteModelObjNodesInGroup($code) |
|
126 | + { |
|
127 | + return delete_option($this->getOptionPrefix() . $code); |
|
128 | + } |
|
129 | 129 | } |
130 | 130 | // End of file NodeGroupDao.php |
131 | 131 | // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php |
@@ -23,215 +23,215 @@ |
||
23 | 23 | */ |
24 | 24 | class ModelObjNode extends BaseNode |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int|string |
|
28 | - */ |
|
29 | - protected $id; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EEM_Base |
|
33 | - */ |
|
34 | - protected $model; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var RelationNode[] |
|
38 | - */ |
|
39 | - protected $nodes; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | - * |
|
45 | - * @param $model_obj_id |
|
46 | - * @param EEM_Base $model |
|
47 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | - */ |
|
49 | - public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | - { |
|
51 | - $this->id = $model_obj_id; |
|
52 | - $this->model = $model; |
|
53 | - $this->dont_traverse_models = $dont_traverse_models; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Creates a relation node for each relation of this model's relations. |
|
59 | - * Does NOT call `discover` on them yet though. |
|
60 | - * |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws ReflectionException |
|
66 | - * @since 4.10.12.p |
|
67 | - */ |
|
68 | - protected function discover() |
|
69 | - { |
|
70 | - $this->nodes = []; |
|
71 | - foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | - // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | - if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | - $this->nodes[ $relationName ] = new RelationNode( |
|
78 | - $this->id, |
|
79 | - $this->model, |
|
80 | - $relation->get_other_model(), |
|
81 | - $this->dont_traverse_models |
|
82 | - ); |
|
83 | - } elseif ( |
|
84 | - $relation instanceof EE_HABTM_Relation |
|
85 | - && ! in_array($relation->get_join_model()->get_this_model_name(), $this->dont_traverse_models) |
|
86 | - ) { |
|
87 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
88 | - $this->id, |
|
89 | - $this->model, |
|
90 | - $relation->get_join_model(), |
|
91 | - $this->dont_traverse_models |
|
92 | - ); |
|
93 | - } |
|
94 | - } |
|
95 | - ksort($this->nodes); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Whether this item has already been initialized |
|
101 | - */ |
|
102 | - protected function isDiscovered() |
|
103 | - { |
|
104 | - return $this->nodes !== null && is_array($this->nodes); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @since 4.10.12.p |
|
109 | - * @return boolean |
|
110 | - */ |
|
111 | - public function isComplete() |
|
112 | - { |
|
113 | - if ($this->complete === null) { |
|
114 | - $this->complete = false; |
|
115 | - } |
|
116 | - return $this->complete; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Triggers working on each child relation node that has work to do. |
|
122 | - * |
|
123 | - * @param $model_objects_to_identify |
|
124 | - * @return int units of work done |
|
125 | - * @since 4.10.12.p |
|
126 | - */ |
|
127 | - protected function work($model_objects_to_identify) |
|
128 | - { |
|
129 | - $num_identified = 0; |
|
130 | - // Begin assuming we'll finish all the work on this node and its children... |
|
131 | - $this->complete = true; |
|
132 | - foreach ($this->nodes as $model_name => $relation_node) { |
|
133 | - $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
134 | - // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
135 | - // related model objects. |
|
136 | - if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
137 | - unset($this->nodes[ $model_name ]); |
|
138 | - } |
|
139 | - if ($num_identified >= $model_objects_to_identify) { |
|
140 | - // ...but admit we're wrong if the work exceeded the budget. |
|
141 | - $this->complete = false; |
|
142 | - break; |
|
143 | - } |
|
144 | - } |
|
145 | - return $num_identified; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return array |
|
151 | - * @throws EE_Error |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidInterfaceException |
|
154 | - * @throws InvalidArgumentException |
|
155 | - * @throws ReflectionException |
|
156 | - * @since 4.10.12.p |
|
157 | - */ |
|
158 | - public function toArray() |
|
159 | - { |
|
160 | - $tree = [ |
|
161 | - 'id' => $this->id, |
|
162 | - 'complete' => $this->isComplete(), |
|
163 | - 'rels' => [], |
|
164 | - ]; |
|
165 | - if ($this->nodes === null) { |
|
166 | - $tree['rels'] = null; |
|
167 | - } else { |
|
168 | - foreach ($this->nodes as $relation_name => $relation_node) { |
|
169 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
170 | - } |
|
171 | - } |
|
172 | - return $tree; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return array|mixed |
|
178 | - * @throws InvalidArgumentException |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidInterfaceException |
|
181 | - * @throws ReflectionException |
|
182 | - * @throws EE_Error |
|
183 | - * @since 4.10.12.p |
|
184 | - */ |
|
185 | - public function getIds() |
|
186 | - { |
|
187 | - $ids = [ |
|
188 | - $this->model->get_this_model_name() => [ |
|
189 | - $this->id => $this->id, |
|
190 | - ], |
|
191 | - ]; |
|
192 | - if ($this->nodes && is_array($this->nodes)) { |
|
193 | - foreach ($this->nodes as $relation_node) { |
|
194 | - $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
195 | - } |
|
196 | - } |
|
197 | - return $ids; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
203 | - * |
|
204 | - * @since 4.10.12.p |
|
205 | - */ |
|
206 | - public function __sleep() |
|
207 | - { |
|
208 | - $this->m = $this->model->get_this_model_name(); |
|
209 | - return array_merge( |
|
210 | - [ |
|
211 | - 'm', |
|
212 | - 'id', |
|
213 | - 'nodes', |
|
214 | - ], |
|
215 | - parent::__sleep() |
|
216 | - ); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Use the dynamic properties to instantiate the models we use. |
|
222 | - * |
|
223 | - * @throws EE_Error |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @throws InvalidDataTypeException |
|
226 | - * @throws InvalidInterfaceException |
|
227 | - * @throws ReflectionException |
|
228 | - * @since 4.10.12.p |
|
229 | - */ |
|
230 | - public function __wakeup() |
|
231 | - { |
|
232 | - $this->model = EE_Registry::instance()->load_model($this->m); |
|
233 | - parent::__wakeup(); |
|
234 | - } |
|
26 | + /** |
|
27 | + * @var int|string |
|
28 | + */ |
|
29 | + protected $id; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EEM_Base |
|
33 | + */ |
|
34 | + protected $model; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var RelationNode[] |
|
38 | + */ |
|
39 | + protected $nodes; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | + * |
|
45 | + * @param $model_obj_id |
|
46 | + * @param EEM_Base $model |
|
47 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | + */ |
|
49 | + public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | + { |
|
51 | + $this->id = $model_obj_id; |
|
52 | + $this->model = $model; |
|
53 | + $this->dont_traverse_models = $dont_traverse_models; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Creates a relation node for each relation of this model's relations. |
|
59 | + * Does NOT call `discover` on them yet though. |
|
60 | + * |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws ReflectionException |
|
66 | + * @since 4.10.12.p |
|
67 | + */ |
|
68 | + protected function discover() |
|
69 | + { |
|
70 | + $this->nodes = []; |
|
71 | + foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | + // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | + if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | + $this->nodes[ $relationName ] = new RelationNode( |
|
78 | + $this->id, |
|
79 | + $this->model, |
|
80 | + $relation->get_other_model(), |
|
81 | + $this->dont_traverse_models |
|
82 | + ); |
|
83 | + } elseif ( |
|
84 | + $relation instanceof EE_HABTM_Relation |
|
85 | + && ! in_array($relation->get_join_model()->get_this_model_name(), $this->dont_traverse_models) |
|
86 | + ) { |
|
87 | + $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
88 | + $this->id, |
|
89 | + $this->model, |
|
90 | + $relation->get_join_model(), |
|
91 | + $this->dont_traverse_models |
|
92 | + ); |
|
93 | + } |
|
94 | + } |
|
95 | + ksort($this->nodes); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Whether this item has already been initialized |
|
101 | + */ |
|
102 | + protected function isDiscovered() |
|
103 | + { |
|
104 | + return $this->nodes !== null && is_array($this->nodes); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @since 4.10.12.p |
|
109 | + * @return boolean |
|
110 | + */ |
|
111 | + public function isComplete() |
|
112 | + { |
|
113 | + if ($this->complete === null) { |
|
114 | + $this->complete = false; |
|
115 | + } |
|
116 | + return $this->complete; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Triggers working on each child relation node that has work to do. |
|
122 | + * |
|
123 | + * @param $model_objects_to_identify |
|
124 | + * @return int units of work done |
|
125 | + * @since 4.10.12.p |
|
126 | + */ |
|
127 | + protected function work($model_objects_to_identify) |
|
128 | + { |
|
129 | + $num_identified = 0; |
|
130 | + // Begin assuming we'll finish all the work on this node and its children... |
|
131 | + $this->complete = true; |
|
132 | + foreach ($this->nodes as $model_name => $relation_node) { |
|
133 | + $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
134 | + // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
135 | + // related model objects. |
|
136 | + if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
137 | + unset($this->nodes[ $model_name ]); |
|
138 | + } |
|
139 | + if ($num_identified >= $model_objects_to_identify) { |
|
140 | + // ...but admit we're wrong if the work exceeded the budget. |
|
141 | + $this->complete = false; |
|
142 | + break; |
|
143 | + } |
|
144 | + } |
|
145 | + return $num_identified; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return array |
|
151 | + * @throws EE_Error |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidInterfaceException |
|
154 | + * @throws InvalidArgumentException |
|
155 | + * @throws ReflectionException |
|
156 | + * @since 4.10.12.p |
|
157 | + */ |
|
158 | + public function toArray() |
|
159 | + { |
|
160 | + $tree = [ |
|
161 | + 'id' => $this->id, |
|
162 | + 'complete' => $this->isComplete(), |
|
163 | + 'rels' => [], |
|
164 | + ]; |
|
165 | + if ($this->nodes === null) { |
|
166 | + $tree['rels'] = null; |
|
167 | + } else { |
|
168 | + foreach ($this->nodes as $relation_name => $relation_node) { |
|
169 | + $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
170 | + } |
|
171 | + } |
|
172 | + return $tree; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return array|mixed |
|
178 | + * @throws InvalidArgumentException |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidInterfaceException |
|
181 | + * @throws ReflectionException |
|
182 | + * @throws EE_Error |
|
183 | + * @since 4.10.12.p |
|
184 | + */ |
|
185 | + public function getIds() |
|
186 | + { |
|
187 | + $ids = [ |
|
188 | + $this->model->get_this_model_name() => [ |
|
189 | + $this->id => $this->id, |
|
190 | + ], |
|
191 | + ]; |
|
192 | + if ($this->nodes && is_array($this->nodes)) { |
|
193 | + foreach ($this->nodes as $relation_node) { |
|
194 | + $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
195 | + } |
|
196 | + } |
|
197 | + return $ids; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
203 | + * |
|
204 | + * @since 4.10.12.p |
|
205 | + */ |
|
206 | + public function __sleep() |
|
207 | + { |
|
208 | + $this->m = $this->model->get_this_model_name(); |
|
209 | + return array_merge( |
|
210 | + [ |
|
211 | + 'm', |
|
212 | + 'id', |
|
213 | + 'nodes', |
|
214 | + ], |
|
215 | + parent::__sleep() |
|
216 | + ); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Use the dynamic properties to instantiate the models we use. |
|
222 | + * |
|
223 | + * @throws EE_Error |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @throws InvalidDataTypeException |
|
226 | + * @throws InvalidInterfaceException |
|
227 | + * @throws ReflectionException |
|
228 | + * @since 4.10.12.p |
|
229 | + */ |
|
230 | + public function __wakeup() |
|
231 | + { |
|
232 | + $this->model = EE_Registry::instance()->load_model($this->m); |
|
233 | + parent::__wakeup(); |
|
234 | + } |
|
235 | 235 | } |
236 | 236 | // End of file Visitor.php |
237 | 237 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
@@ -17,194 +17,194 @@ |
||
17 | 17 | class Url |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $scheme |
|
22 | - */ |
|
23 | - private $scheme; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string $host |
|
27 | - */ |
|
28 | - private $host; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $path |
|
32 | - */ |
|
33 | - private $path; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $query |
|
37 | - */ |
|
38 | - private $query; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $fragment |
|
42 | - */ |
|
43 | - private $fragment; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Url constructor. |
|
48 | - * |
|
49 | - * @param $url |
|
50 | - * @throws InvalidArgumentException |
|
51 | - */ |
|
52 | - public function __construct($url) |
|
53 | - { |
|
54 | - if (! filter_var($url, FILTER_VALIDATE_URL)) { |
|
55 | - throw new InvalidArgumentException( |
|
56 | - esc_html__( |
|
57 | - 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
58 | - 'event_espresso' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
62 | - $url = parse_url($url); |
|
63 | - $this->setScheme($url); |
|
64 | - $this->setHost($url); |
|
65 | - $this->setPath($url); |
|
66 | - $this->setQuery($url); |
|
67 | - $this->setFragment($url); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
73 | - * will return a string like: 'abc://' |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function scheme() |
|
78 | - { |
|
79 | - return $this->scheme; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param array $url |
|
85 | - */ |
|
86 | - private function setScheme($url) |
|
87 | - { |
|
88 | - $this->scheme = $url['scheme'] . '://'; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
94 | - * will return a string like: 'example.com' |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function host() |
|
99 | - { |
|
100 | - return $this->host; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param array $url |
|
106 | - */ |
|
107 | - private function setHost($url) |
|
108 | - { |
|
109 | - $this->host = $url['host']; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
115 | - * will return a string like: '/path/data' |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function path() |
|
120 | - { |
|
121 | - return $this->path; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param array $url |
|
127 | - */ |
|
128 | - private function setPath($url) |
|
129 | - { |
|
130 | - $this->path = isset($url['path']) ? $url['path'] : ''; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
136 | - * will return a string like: '?key=value' |
|
137 | - * |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function queryString() |
|
141 | - { |
|
142 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
148 | - * will return an array like: array('key' => 'value') |
|
149 | - * |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function queryParams() |
|
153 | - { |
|
154 | - return wp_parse_args($this->query); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @param array $url |
|
160 | - */ |
|
161 | - private function setQuery($url) |
|
162 | - { |
|
163 | - $this->query = isset($url['query']) ? $url['query'] : ''; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
169 | - * will return a string like: '#id' |
|
170 | - * |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function fragment() |
|
174 | - { |
|
175 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param array $url |
|
181 | - */ |
|
182 | - private function setFragment($url) |
|
183 | - { |
|
184 | - $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
190 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
191 | - * |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public function getFullUrl() |
|
195 | - { |
|
196 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
202 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
203 | - * |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function __toString() |
|
207 | - { |
|
208 | - return $this->getFullUrl(); |
|
209 | - } |
|
20 | + /** |
|
21 | + * @var string $scheme |
|
22 | + */ |
|
23 | + private $scheme; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string $host |
|
27 | + */ |
|
28 | + private $host; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $path |
|
32 | + */ |
|
33 | + private $path; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $query |
|
37 | + */ |
|
38 | + private $query; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $fragment |
|
42 | + */ |
|
43 | + private $fragment; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Url constructor. |
|
48 | + * |
|
49 | + * @param $url |
|
50 | + * @throws InvalidArgumentException |
|
51 | + */ |
|
52 | + public function __construct($url) |
|
53 | + { |
|
54 | + if (! filter_var($url, FILTER_VALIDATE_URL)) { |
|
55 | + throw new InvalidArgumentException( |
|
56 | + esc_html__( |
|
57 | + 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
58 | + 'event_espresso' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | + $url = parse_url($url); |
|
63 | + $this->setScheme($url); |
|
64 | + $this->setHost($url); |
|
65 | + $this->setPath($url); |
|
66 | + $this->setQuery($url); |
|
67 | + $this->setFragment($url); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
73 | + * will return a string like: 'abc://' |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function scheme() |
|
78 | + { |
|
79 | + return $this->scheme; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param array $url |
|
85 | + */ |
|
86 | + private function setScheme($url) |
|
87 | + { |
|
88 | + $this->scheme = $url['scheme'] . '://'; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
94 | + * will return a string like: 'example.com' |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function host() |
|
99 | + { |
|
100 | + return $this->host; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param array $url |
|
106 | + */ |
|
107 | + private function setHost($url) |
|
108 | + { |
|
109 | + $this->host = $url['host']; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
115 | + * will return a string like: '/path/data' |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function path() |
|
120 | + { |
|
121 | + return $this->path; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param array $url |
|
127 | + */ |
|
128 | + private function setPath($url) |
|
129 | + { |
|
130 | + $this->path = isset($url['path']) ? $url['path'] : ''; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
136 | + * will return a string like: '?key=value' |
|
137 | + * |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function queryString() |
|
141 | + { |
|
142 | + return $this->query !== '' ? '?' . $this->query : ''; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
148 | + * will return an array like: array('key' => 'value') |
|
149 | + * |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function queryParams() |
|
153 | + { |
|
154 | + return wp_parse_args($this->query); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @param array $url |
|
160 | + */ |
|
161 | + private function setQuery($url) |
|
162 | + { |
|
163 | + $this->query = isset($url['query']) ? $url['query'] : ''; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
169 | + * will return a string like: '#id' |
|
170 | + * |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function fragment() |
|
174 | + { |
|
175 | + return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param array $url |
|
181 | + */ |
|
182 | + private function setFragment($url) |
|
183 | + { |
|
184 | + $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
190 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
191 | + * |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public function getFullUrl() |
|
195 | + { |
|
196 | + return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
202 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
203 | + * |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function __toString() |
|
207 | + { |
|
208 | + return $this->getFullUrl(); |
|
209 | + } |
|
210 | 210 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct($url) |
53 | 53 | { |
54 | - if (! filter_var($url, FILTER_VALIDATE_URL)) { |
|
54 | + if ( ! filter_var($url, FILTER_VALIDATE_URL)) { |
|
55 | 55 | throw new InvalidArgumentException( |
56 | 56 | esc_html__( |
57 | 57 | 'Invalid URL. Both the "Scheme" and "Host" are required.', |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private function setScheme($url) |
87 | 87 | { |
88 | - $this->scheme = $url['scheme'] . '://'; |
|
88 | + $this->scheme = $url['scheme'].'://'; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function queryString() |
141 | 141 | { |
142 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
142 | + return $this->query !== '' ? '?'.$this->query : ''; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function fragment() |
174 | 174 | { |
175 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
175 | + return $this->fragment !== '' ? '#'.$this->fragment : ''; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function getFullUrl() |
195 | 195 | { |
196 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
196 | + return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment(); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 |