@@ -31,8 +31,8 @@ |
||
31 | 31 | "price": "<?php echo $ticket['price'] ?>", |
32 | 32 | "priceCurrency": "<?php echo $currency ?>" |
33 | 33 | }<?php if (is_array($event_tickets) && end($event_tickets) !== $ticket) { echo ','; } |
34 | - } |
|
35 | - ?> |
|
34 | + } |
|
35 | + ?> |
|
36 | 36 | ]<?php if ($venue_name) { ?>, |
37 | 37 | "location": { |
38 | 38 | "@type": "Place", |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @param \EE_Datetime_Field $datetime_field |
576 | 576 | * @param bool $pretty |
577 | - * @param null $date_or_time |
|
577 | + * @param string|null $date_or_time |
|
578 | 578 | * @return void |
579 | 579 | * @throws \EE_Error |
580 | 580 | */ |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | * |
893 | 893 | * @param null $field_to_order_by What field is being used as the reference point. |
894 | 894 | * @param array $query_params Any additional conditions on the query. |
895 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
895 | + * @param string $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
896 | 896 | * you can indicate just the columns you want returned |
897 | 897 | * @return array|EE_Base_Class |
898 | 898 | * @throws \EE_Error |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * |
918 | 918 | * @param null $field_to_order_by What field is being used as the reference point. |
919 | 919 | * @param array $query_params Any additional conditions on the query. |
920 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
920 | + * @param string $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
921 | 921 | * you can indicate just the column you want returned |
922 | 922 | * @return array|EE_Base_Class |
923 | 923 | * @throws \EE_Error |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | * This method simply returns the RAW unprocessed value for the given property in this class |
991 | 991 | * |
992 | 992 | * @param string $field_name A valid fieldname |
993 | - * @return mixed Whatever the raw value stored on the property is. |
|
993 | + * @return integer|null Whatever the raw value stored on the property is. |
|
994 | 994 | * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
995 | 995 | */ |
996 | 996 | public function get_raw($field_name) |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | * sets the time on a datetime property |
1257 | 1257 | * |
1258 | 1258 | * @access protected |
1259 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1259 | + * @param string $time a valid time string for php datetime functions (or DateTime object) |
|
1260 | 1260 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1261 | 1261 | * @throws \EE_Error |
1262 | 1262 | */ |
@@ -1271,7 +1271,7 @@ discard block |
||
1271 | 1271 | * sets the date on a datetime property |
1272 | 1272 | * |
1273 | 1273 | * @access protected |
1274 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1274 | + * @param string $date a valid date string for php datetime functions ( or DateTime object) |
|
1275 | 1275 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1276 | 1276 | * @throws \EE_Error |
1277 | 1277 | */ |
@@ -1329,6 +1329,7 @@ discard block |
||
1329 | 1329 | * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
1330 | 1330 | * @param string $prepend You can include something to prepend on the timestamp |
1331 | 1331 | * @param string $append You can include something to append on the timestamp |
1332 | + * @param string $args |
|
1332 | 1333 | * @throws EE_Error |
1333 | 1334 | * @return string timestamp |
1334 | 1335 | */ |
@@ -1699,7 +1700,7 @@ discard block |
||
1699 | 1700 | * |
1700 | 1701 | * @param array $props_n_values incoming array of properties and their values |
1701 | 1702 | * @param string $classname the classname of the child class |
1702 | - * @param null $timezone |
|
1703 | + * @param string|null $timezone |
|
1703 | 1704 | * @param array $date_formats incoming date_formats in an array where the first value is the |
1704 | 1705 | * date_format and the second value is the time format |
1705 | 1706 | * @return mixed (EE_Base_Class|bool) |
@@ -1777,7 +1778,7 @@ discard block |
||
1777 | 1778 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
1778 | 1779 | * |
1779 | 1780 | * @param string $model_classname |
1780 | - * @param null $timezone |
|
1781 | + * @param string|null $timezone |
|
1781 | 1782 | * @return EEM_Base |
1782 | 1783 | */ |
1783 | 1784 | protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
5 | 5 | |
@@ -25,2555 +25,2555 @@ discard block |
||
25 | 25 | abstract class EE_Base_Class |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * This is an array of the original properties and values provided during construction |
|
30 | - * of this model object. (keys are model field names, values are their values). |
|
31 | - * This list is important to remember so that when we are merging data from the db, we know |
|
32 | - * which values to override and which to not override. |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $_props_n_values_provided_in_constructor; |
|
37 | - |
|
38 | - /** |
|
39 | - * Timezone |
|
40 | - * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT all |
|
41 | - * EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have access to it. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_timezone; |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * date format |
|
51 | - * pattern or format for displaying dates |
|
52 | - * |
|
53 | - * @var string $_dt_frmt |
|
54 | - */ |
|
55 | - protected $_dt_frmt; |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * time format |
|
61 | - * pattern or format for displaying time |
|
62 | - * |
|
63 | - * @var string $_tm_frmt |
|
64 | - */ |
|
65 | - protected $_tm_frmt; |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * This property is for holding a cached array of object properties indexed by property name as the key. |
|
71 | - * The purpose of this is for setting a cache on properties that may have calculated values after a prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having to recalculate. |
|
72 | - * Used by _set_cached_property() and _get_cached_property() methods. |
|
73 | - * |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $_cached_properties = array(); |
|
77 | - |
|
78 | - /** |
|
79 | - * An array containing keys of the related model, and values are either an array of related mode objects or a single |
|
80 | - * related model object. see the model's _model_relations. The keys should match those specified. And if the relation |
|
81 | - * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array) |
|
82 | - * |
|
83 | - * @var array |
|
84 | - */ |
|
85 | - protected $_model_relations = array(); |
|
86 | - |
|
87 | - /** |
|
88 | - * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
89 | - * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
90 | - * |
|
91 | - * @var array |
|
92 | - */ |
|
93 | - protected $_fields = array(); |
|
94 | - |
|
95 | - /** |
|
96 | - * @var boolean indicating whether or not this model object is intended to ever be saved |
|
97 | - * For example, we might create model objects intended to only be used for the duration |
|
98 | - * of this request and to be thrown away, and if they were accidentally saved |
|
99 | - * it would be a bug. |
|
100 | - */ |
|
101 | - protected $_allow_persist = true; |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children play nice |
|
107 | - * |
|
108 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their values |
|
109 | - * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model or not. |
|
110 | - * @param string $timezone indicate what timezone you want any datetime fields to be in when instantiating a EE_Base_Class object. |
|
111 | - * @param array $date_formats An array of date formats to set on construct where first |
|
112 | - * value is the date_format and second value is the time |
|
113 | - * format. |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
117 | - { |
|
118 | - $className = get_class($this); |
|
119 | - do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
120 | - $model = $this->get_model(); |
|
121 | - $model_fields = $model->field_settings(false); |
|
122 | - // ensure $fieldValues is an array |
|
123 | - $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
124 | - // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
125 | - // verify client code has not passed any invalid field names |
|
126 | - foreach ($fieldValues as $field_name => $field_value) { |
|
127 | - if ( ! isset($model_fields[$field_name])) { |
|
128 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
129 | - } |
|
130 | - } |
|
131 | - // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
132 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
133 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
134 | - list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
135 | - } else { |
|
136 | - //set default formats for date and time |
|
137 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
138 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
139 | - } |
|
140 | - //if db model is instantiating |
|
141 | - if ($bydb) { |
|
142 | - //client code has indicated these field values are from the database |
|
143 | - foreach ($model_fields as $fieldName => $field) { |
|
144 | - $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
145 | - } |
|
146 | - } else { |
|
147 | - //we're constructing a brand |
|
148 | - //new instance of the model object. Generally, this means we'll need to do more field validation |
|
149 | - foreach ($model_fields as $fieldName => $field) { |
|
150 | - $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
151 | - } |
|
152 | - } |
|
153 | - //remember what values were passed to this constructor |
|
154 | - $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
155 | - //remember in entity mapper |
|
156 | - if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
157 | - $model->add_to_entity_map($this); |
|
158 | - } |
|
159 | - //setup all the relations |
|
160 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
161 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
162 | - $this->_model_relations[$relation_name] = null; |
|
163 | - } else { |
|
164 | - $this->_model_relations[$relation_name] = array(); |
|
165 | - } |
|
166 | - } |
|
167 | - /** |
|
168 | - * Action done at the end of each model object construction |
|
169 | - * |
|
170 | - * @param EE_Base_Class $this the model object just created |
|
171 | - */ |
|
172 | - do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
179 | - * |
|
180 | - * @return boolean |
|
181 | - */ |
|
182 | - public function allow_persist() |
|
183 | - { |
|
184 | - return $this->_allow_persist; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Sets whether or not this model object should be allowed to be saved to the DB. |
|
191 | - * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
192 | - * you got new information that somehow made you change your mind. |
|
193 | - * |
|
194 | - * @param boolean $allow_persist |
|
195 | - * @return boolean |
|
196 | - */ |
|
197 | - public function set_allow_persist($allow_persist) |
|
198 | - { |
|
199 | - return $this->_allow_persist = $allow_persist; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Gets the field's original value when this object was constructed during this request. |
|
206 | - * This can be helpful when determining if a model object has changed or not |
|
207 | - * |
|
208 | - * @param string $field_name |
|
209 | - * @return mixed|null |
|
210 | - * @throws \EE_Error |
|
211 | - */ |
|
212 | - public function get_original($field_name) |
|
213 | - { |
|
214 | - if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
215 | - && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
216 | - ) { |
|
217 | - return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | - } else { |
|
219 | - return null; |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @param EE_Base_Class $obj |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_class($obj) |
|
230 | - { |
|
231 | - return get_class($obj); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Overrides parent because parent expects old models. |
|
238 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
239 | - * |
|
240 | - * @param string $field_name |
|
241 | - * @param mixed $field_value |
|
242 | - * @param bool $use_default |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function set($field_name, $field_value, $use_default = false) |
|
246 | - { |
|
247 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
248 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
249 | - // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
250 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
251 | - $field_obj->set_timezone($this->_timezone); |
|
252 | - $field_obj->set_date_format($this->_dt_frmt); |
|
253 | - $field_obj->set_time_format($this->_tm_frmt); |
|
254 | - } |
|
255 | - $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
256 | - //should the value be null? |
|
257 | - if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
258 | - $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
259 | - /** |
|
260 | - * To save having to refactor all the models, if a default value is used for a |
|
261 | - * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
262 | - * object. Then let's do a set again to ensure that it becomes a DateTime |
|
263 | - * object. |
|
264 | - * |
|
265 | - * @since 4.6.10+ |
|
266 | - */ |
|
267 | - if ( |
|
268 | - $field_obj instanceof EE_Datetime_Field |
|
269 | - && $this->_fields[$field_name] !== null |
|
270 | - && ! $this->_fields[$field_name] instanceof DateTime |
|
271 | - ) { |
|
272 | - empty($this->_fields[$field_name]) |
|
273 | - ? $this->set($field_name, time()) |
|
274 | - : $this->set($field_name, $this->_fields[$field_name]); |
|
275 | - } |
|
276 | - } else { |
|
277 | - $this->_fields[$field_name] = $holder_of_value; |
|
278 | - } |
|
279 | - //if we're not in the constructor... |
|
280 | - //now check if what we set was a primary key |
|
281 | - if ( |
|
282 | - //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
283 | - $this->_props_n_values_provided_in_constructor |
|
284 | - && $field_value |
|
285 | - && $field_name === self::_get_primary_key_name(get_class($this)) |
|
286 | - ) { |
|
287 | - //if so, we want all this object's fields to be filled either with |
|
288 | - //what we've explicitly set on this model |
|
289 | - //or what we have in the db |
|
290 | - // echo "setting primary key!"; |
|
291 | - $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
292 | - $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
293 | - foreach ($fields_on_model as $field_obj) { |
|
294 | - if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
295 | - && $field_obj->get_name() !== $field_name |
|
296 | - ) { |
|
297 | - $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
298 | - } |
|
299 | - } |
|
300 | - //oh this model object has an ID? well make sure its in the entity mapper |
|
301 | - $this->get_model()->add_to_entity_map($this); |
|
302 | - } |
|
303 | - //let's unset any cache for this field_name from the $_cached_properties property. |
|
304 | - $this->_clear_cached_property($field_name); |
|
305 | - } else { |
|
306 | - throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * This sets the field value on the db column if it exists for the given $column_name or |
|
314 | - * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
315 | - * |
|
316 | - * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
317 | - * @param string $field_name Must be the exact column name. |
|
318 | - * @param mixed $field_value The value to set. |
|
319 | - * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
320 | - * @throws \EE_Error |
|
321 | - */ |
|
322 | - public function set_field_or_extra_meta($field_name, $field_value) |
|
323 | - { |
|
324 | - if ($this->get_model()->has_field($field_name)) { |
|
325 | - $this->set($field_name, $field_value); |
|
326 | - return true; |
|
327 | - } else { |
|
328 | - //ensure this object is saved first so that extra meta can be properly related. |
|
329 | - $this->save(); |
|
330 | - return $this->update_extra_meta($field_name, $field_value); |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * This retrieves the value of the db column set on this class or if that's not present |
|
338 | - * it will attempt to retrieve from extra_meta if found. |
|
339 | - * Example Usage: |
|
340 | - * Via EE_Message child class: |
|
341 | - * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
342 | - * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
343 | - * also have additional main fields specific to the messenger. The system accommodates those extra |
|
344 | - * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
345 | - * value for those extra fields dynamically via the EE_message object. |
|
346 | - * |
|
347 | - * @param string $field_name expecting the fully qualified field name. |
|
348 | - * @return mixed|null value for the field if found. null if not found. |
|
349 | - * @throws \EE_Error |
|
350 | - */ |
|
351 | - public function get_field_or_extra_meta($field_name) |
|
352 | - { |
|
353 | - if ($this->get_model()->has_field($field_name)) { |
|
354 | - $column_value = $this->get($field_name); |
|
355 | - } else { |
|
356 | - //This isn't a column in the main table, let's see if it is in the extra meta. |
|
357 | - $column_value = $this->get_extra_meta($field_name, true, null); |
|
358 | - } |
|
359 | - return $column_value; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally for being able to reference what timezone we are running conversions on when converting TO the internal timezone (UTC |
|
366 | - * Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
370 | - * @return void |
|
371 | - * @throws \EE_Error |
|
372 | - */ |
|
373 | - public function set_timezone($timezone = '') |
|
374 | - { |
|
375 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
376 | - //make sure we clear all cached properties because they won't be relevant now |
|
377 | - $this->_clear_cached_properties(); |
|
378 | - //make sure we update field settings and the date for all EE_Datetime_Fields |
|
379 | - $model_fields = $this->get_model()->field_settings(false); |
|
380 | - foreach ($model_fields as $field_name => $field_obj) { |
|
381 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
382 | - $field_obj->set_timezone($this->_timezone); |
|
383 | - if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
384 | - $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
385 | - } |
|
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * This just returns whatever is set for the current timezone. |
|
394 | - * |
|
395 | - * @access public |
|
396 | - * @return string timezone string |
|
397 | - */ |
|
398 | - public function get_timezone() |
|
399 | - { |
|
400 | - return $this->_timezone; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * This sets the internal date format to what is sent in to be used as the new default for the class |
|
407 | - * internally instead of wp set date format options |
|
408 | - * |
|
409 | - * @since 4.6 |
|
410 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
411 | - */ |
|
412 | - public function set_date_format($format) |
|
413 | - { |
|
414 | - $this->_dt_frmt = $format; |
|
415 | - //clear cached_properties because they won't be relevant now. |
|
416 | - $this->_clear_cached_properties(); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * This sets the internal time format string to what is sent in to be used as the new default for the |
|
423 | - * class internally instead of wp set time format options. |
|
424 | - * |
|
425 | - * @since 4.6 |
|
426 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
427 | - */ |
|
428 | - public function set_time_format($format) |
|
429 | - { |
|
430 | - $this->_tm_frmt = $format; |
|
431 | - //clear cached_properties because they won't be relevant now. |
|
432 | - $this->_clear_cached_properties(); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * This returns the current internal set format for the date and time formats. |
|
439 | - * |
|
440 | - * @param bool $full if true (default), then return the full format. Otherwise will return an array where the |
|
441 | - * first value is the date format and the second value is the time format. |
|
442 | - * @return mixed string|array |
|
443 | - */ |
|
444 | - public function get_format($full = true) |
|
445 | - { |
|
446 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * cache |
|
453 | - * stores the passed model object on the current model object. |
|
454 | - * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
455 | - * |
|
456 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' associated with this model object |
|
457 | - * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, that could be a payment or a registration) |
|
458 | - * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many items which will be stored in an array on this object |
|
459 | - * @throws EE_Error |
|
460 | - * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
|
461 | - */ |
|
462 | - public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
463 | - { |
|
464 | - // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
465 | - if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
466 | - return false; |
|
467 | - } |
|
468 | - // also get "how" the object is related, or throw an error |
|
469 | - if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
470 | - throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
471 | - } |
|
472 | - // how many things are related ? |
|
473 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
474 | - // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
|
475 | - // so for these model objects just set it to be cached |
|
476 | - $this->_model_relations[$relationName] = $object_to_cache; |
|
477 | - $return = true; |
|
478 | - } else { |
|
479 | - // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
|
480 | - // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
481 | - if ( ! is_array($this->_model_relations[$relationName])) { |
|
482 | - // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
483 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
484 | - } |
|
485 | - // first check for a cache_id which is normally empty |
|
486 | - if ( ! empty($cache_id)) { |
|
487 | - // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
|
488 | - $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
489 | - $return = $cache_id; |
|
490 | - } elseif ($object_to_cache->ID()) { |
|
491 | - // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
492 | - $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
493 | - $return = $object_to_cache->ID(); |
|
494 | - } else { |
|
495 | - // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
496 | - $this->_model_relations[$relationName][] = $object_to_cache; |
|
497 | - // move the internal pointer to the end of the array |
|
498 | - end($this->_model_relations[$relationName]); |
|
499 | - // and grab the key so that we can return it |
|
500 | - $return = key($this->_model_relations[$relationName]); |
|
501 | - } |
|
502 | - } |
|
503 | - return $return; |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * For adding an item to the cached_properties property. |
|
510 | - * |
|
511 | - * @access protected |
|
512 | - * @param string $fieldname the property item the corresponding value is for. |
|
513 | - * @param mixed $value The value we are caching. |
|
514 | - * @param string|null $cache_type |
|
515 | - * @return void |
|
516 | - * @throws \EE_Error |
|
517 | - */ |
|
518 | - protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
519 | - { |
|
520 | - //first make sure this property exists |
|
521 | - $this->get_model()->field_settings_for($fieldname); |
|
522 | - $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
523 | - $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
530 | - * This also SETS the cache if we return the actual property! |
|
531 | - * |
|
532 | - * @param string $fieldname the name of the property we're trying to retrieve |
|
533 | - * @param bool $pretty |
|
534 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
535 | - * (in cases where the same property may be used for different outputs |
|
536 | - * - i.e. datetime, money etc.) |
|
537 | - * It can also accept certain pre-defined "schema" strings |
|
538 | - * to define how to output the property. |
|
539 | - * see the field's prepare_for_pretty_echoing for what strings can be used |
|
540 | - * @return mixed whatever the value for the property is we're retrieving |
|
541 | - * @throws \EE_Error |
|
542 | - */ |
|
543 | - protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
544 | - { |
|
545 | - //verify the field exists |
|
546 | - $this->get_model()->field_settings_for($fieldname); |
|
547 | - $cache_type = $pretty ? 'pretty' : 'standard'; |
|
548 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
549 | - if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
550 | - return $this->_cached_properties[$fieldname][$cache_type]; |
|
551 | - } |
|
552 | - $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
553 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
554 | - // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
555 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
556 | - $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
557 | - } |
|
558 | - if ( ! isset($this->_fields[$fieldname])) { |
|
559 | - $this->_fields[$fieldname] = null; |
|
560 | - } |
|
561 | - $value = $pretty |
|
562 | - ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
563 | - : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
564 | - $this->_set_cached_property($fieldname, $value, $cache_type); |
|
565 | - return $value; |
|
566 | - } |
|
567 | - return null; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * set timezone, formats, and output for EE_Datetime_Field objects |
|
574 | - * |
|
575 | - * @param \EE_Datetime_Field $datetime_field |
|
576 | - * @param bool $pretty |
|
577 | - * @param null $date_or_time |
|
578 | - * @return void |
|
579 | - * @throws \EE_Error |
|
580 | - */ |
|
581 | - protected function _prepare_datetime_field( |
|
582 | - EE_Datetime_Field $datetime_field, |
|
583 | - $pretty = false, |
|
584 | - $date_or_time = null |
|
585 | - ) { |
|
586 | - $datetime_field->set_timezone($this->_timezone); |
|
587 | - $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
588 | - $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
589 | - //set the output returned |
|
590 | - switch ($date_or_time) { |
|
591 | - case 'D' : |
|
592 | - $datetime_field->set_date_time_output('date'); |
|
593 | - break; |
|
594 | - case 'T' : |
|
595 | - $datetime_field->set_date_time_output('time'); |
|
596 | - break; |
|
597 | - default : |
|
598 | - $datetime_field->set_date_time_output(); |
|
599 | - } |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * This just takes care of clearing out the cached_properties |
|
606 | - * |
|
607 | - * @return void |
|
608 | - */ |
|
609 | - protected function _clear_cached_properties() |
|
610 | - { |
|
611 | - $this->_cached_properties = array(); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This just clears out ONE property if it exists in the cache |
|
618 | - * |
|
619 | - * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
620 | - * @return void |
|
621 | - */ |
|
622 | - protected function _clear_cached_property($property_name) |
|
623 | - { |
|
624 | - if (isset($this->_cached_properties[$property_name])) { |
|
625 | - unset($this->_cached_properties[$property_name]); |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * Ensures that this related thing is a model object. |
|
633 | - * |
|
634 | - * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
635 | - * @param string $model_name name of the related thing, eg 'Attendee', |
|
636 | - * @return EE_Base_Class |
|
637 | - * @throws \EE_Error |
|
638 | - */ |
|
639 | - protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
640 | - { |
|
641 | - $other_model_instance = self::_get_model_instance_with_name( |
|
642 | - self::_get_model_classname($model_name), |
|
643 | - $this->_timezone |
|
644 | - ); |
|
645 | - return $other_model_instance->ensure_is_obj($object_or_id); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Forgets the cached model of the given relation Name. So the next time we request it, |
|
652 | - * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
653 | - * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
654 | - * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
655 | - * |
|
656 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' |
|
657 | - * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
658 | - * if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation) |
|
659 | - * @param bool $clear_all This flags clearing the entire cache relation property if this is HasMany or HABTM. |
|
660 | - * @throws EE_Error |
|
661 | - * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
|
662 | - */ |
|
663 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
664 | - { |
|
665 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
666 | - $index_in_cache = ''; |
|
667 | - if ( ! $relationship_to_model) { |
|
668 | - throw new EE_Error( |
|
669 | - sprintf( |
|
670 | - __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
671 | - $relationName, |
|
672 | - get_class($this) |
|
673 | - ) |
|
674 | - ); |
|
675 | - } |
|
676 | - if ($clear_all) { |
|
677 | - $obj_removed = true; |
|
678 | - $this->_model_relations[$relationName] = null; |
|
679 | - } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
680 | - $obj_removed = $this->_model_relations[$relationName]; |
|
681 | - $this->_model_relations[$relationName] = null; |
|
682 | - } else { |
|
683 | - if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
684 | - $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
685 | - if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
686 | - $index_found_at = null; |
|
687 | - //find this object in the array even though it has a different key |
|
688 | - foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
689 | - if ( |
|
690 | - $obj instanceof EE_Base_Class |
|
691 | - && ( |
|
692 | - $obj == $object_to_remove_or_index_into_array |
|
693 | - || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
694 | - ) |
|
695 | - ) { |
|
696 | - $index_found_at = $index; |
|
697 | - break; |
|
698 | - } |
|
699 | - } |
|
700 | - if ($index_found_at) { |
|
701 | - $index_in_cache = $index_found_at; |
|
702 | - } else { |
|
703 | - //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
704 | - //if it wasn't in it to begin with. So we're done |
|
705 | - return $object_to_remove_or_index_into_array; |
|
706 | - } |
|
707 | - } |
|
708 | - } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
709 | - //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
710 | - foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
711 | - if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
712 | - $index_in_cache = $index; |
|
713 | - } |
|
714 | - } |
|
715 | - } else { |
|
716 | - $index_in_cache = $object_to_remove_or_index_into_array; |
|
717 | - } |
|
718 | - //supposedly we've found it. But it could just be that the client code |
|
719 | - //provided a bad index/object |
|
720 | - if ( |
|
721 | - isset( |
|
722 | - $this->_model_relations[$relationName], |
|
723 | - $this->_model_relations[$relationName][$index_in_cache] |
|
724 | - ) |
|
725 | - ) { |
|
726 | - $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
727 | - unset($this->_model_relations[$relationName][$index_in_cache]); |
|
728 | - } else { |
|
729 | - //that thing was never cached anyways. |
|
730 | - $obj_removed = null; |
|
731 | - } |
|
732 | - } |
|
733 | - return $obj_removed; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * update_cache_after_object_save |
|
740 | - * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has obtained after being saved to the db |
|
741 | - * |
|
742 | - * @param string $relationName - the type of object that is cached |
|
743 | - * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
744 | - * @param string $current_cache_id - the ID that was used when originally caching the object |
|
745 | - * @return boolean TRUE on success, FALSE on fail |
|
746 | - * @throws \EE_Error |
|
747 | - */ |
|
748 | - public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') |
|
749 | - { |
|
750 | - // verify that incoming object is of the correct type |
|
751 | - $obj_class = 'EE_' . $relationName; |
|
752 | - if ($newly_saved_object instanceof $obj_class) { |
|
753 | - /* @type EE_Base_Class $newly_saved_object */ |
|
754 | - // now get the type of relation |
|
755 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
756 | - // if this is a 1:1 relationship |
|
757 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
758 | - // then just replace the cached object with the newly saved object |
|
759 | - $this->_model_relations[$relationName] = $newly_saved_object; |
|
760 | - return true; |
|
761 | - // or if it's some kind of sordid feral polyamorous relationship... |
|
762 | - } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
763 | - // then remove the current cached item |
|
764 | - unset($this->_model_relations[$relationName][$current_cache_id]); |
|
765 | - // and cache the newly saved object using it's new ID |
|
766 | - $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
767 | - return true; |
|
768 | - } |
|
769 | - } |
|
770 | - return false; |
|
771 | - } |
|
772 | - |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
777 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
778 | - * |
|
779 | - * @param string $relationName |
|
780 | - * @return EE_Base_Class |
|
781 | - */ |
|
782 | - public function get_one_from_cache($relationName) |
|
783 | - { |
|
784 | - $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
785 | - if (is_array($cached_array_or_object)) { |
|
786 | - return array_shift($cached_array_or_object); |
|
787 | - } else { |
|
788 | - return $cached_array_or_object; |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
796 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
797 | - * |
|
798 | - * @param string $relationName |
|
799 | - * @throws \EE_Error |
|
800 | - * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
801 | - */ |
|
802 | - public function get_all_from_cache($relationName) |
|
803 | - { |
|
804 | - $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
805 | - // if the result is not an array, but exists, make it an array |
|
806 | - $objects = is_array($objects) ? $objects : array($objects); |
|
807 | - //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
808 | - //basically, if this model object was stored in the session, and these cached model objects |
|
809 | - //already have IDs, let's make sure they're in their model's entity mapper |
|
810 | - //otherwise we will have duplicates next time we call |
|
811 | - // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
812 | - $model = EE_Registry::instance()->load_model($relationName); |
|
813 | - foreach ($objects as $model_object) { |
|
814 | - if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
815 | - //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
816 | - if ($model_object->ID()) { |
|
817 | - $model->add_to_entity_map($model_object); |
|
818 | - } |
|
819 | - } else { |
|
820 | - throw new EE_Error( |
|
821 | - sprintf( |
|
822 | - __( |
|
823 | - 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
824 | - 'event_espresso' |
|
825 | - ), |
|
826 | - $relationName, |
|
827 | - gettype($model_object) |
|
828 | - ) |
|
829 | - ); |
|
830 | - } |
|
831 | - } |
|
832 | - return $objects; |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
839 | - * matching the given query conditions. |
|
840 | - * |
|
841 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
842 | - * @param int $limit How many objects to return. |
|
843 | - * @param array $query_params Any additional conditions on the query. |
|
844 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
845 | - * you can indicate just the columns you want returned |
|
846 | - * @return array|EE_Base_Class[] |
|
847 | - * @throws \EE_Error |
|
848 | - */ |
|
849 | - public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
850 | - { |
|
851 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
852 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
853 | - : $field_to_order_by; |
|
854 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
855 | - if (empty($field) || empty($current_value)) { |
|
856 | - return array(); |
|
857 | - } |
|
858 | - return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
865 | - * matching the given query conditions. |
|
866 | - * |
|
867 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
868 | - * @param int $limit How many objects to return. |
|
869 | - * @param array $query_params Any additional conditions on the query. |
|
870 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
871 | - * you can indicate just the columns you want returned |
|
872 | - * @return array|EE_Base_Class[] |
|
873 | - * @throws \EE_Error |
|
874 | - */ |
|
875 | - public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
876 | - { |
|
877 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
878 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
879 | - : $field_to_order_by; |
|
880 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
881 | - if (empty($field) || empty($current_value)) { |
|
882 | - return array(); |
|
883 | - } |
|
884 | - return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
891 | - * matching the given query conditions. |
|
892 | - * |
|
893 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
894 | - * @param array $query_params Any additional conditions on the query. |
|
895 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
896 | - * you can indicate just the columns you want returned |
|
897 | - * @return array|EE_Base_Class |
|
898 | - * @throws \EE_Error |
|
899 | - */ |
|
900 | - public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
901 | - { |
|
902 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
903 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
904 | - : $field_to_order_by; |
|
905 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
906 | - if (empty($field) || empty($current_value)) { |
|
907 | - return array(); |
|
908 | - } |
|
909 | - return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
916 | - * matching the given query conditions. |
|
917 | - * |
|
918 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
919 | - * @param array $query_params Any additional conditions on the query. |
|
920 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
921 | - * you can indicate just the column you want returned |
|
922 | - * @return array|EE_Base_Class |
|
923 | - * @throws \EE_Error |
|
924 | - */ |
|
925 | - public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
926 | - { |
|
927 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
928 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
929 | - : $field_to_order_by; |
|
930 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
931 | - if (empty($field) || empty($current_value)) { |
|
932 | - return array(); |
|
933 | - } |
|
934 | - return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - |
|
939 | - /** |
|
940 | - * Overrides parent because parent expects old models. |
|
941 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
942 | - * |
|
943 | - * @param string $field_name |
|
944 | - * @param mixed $field_value_from_db |
|
945 | - * @throws \EE_Error |
|
946 | - */ |
|
947 | - public function set_from_db($field_name, $field_value_from_db) |
|
948 | - { |
|
949 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
950 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
951 | - //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
952 | - //eg, a CPT model object could have an entry in the posts table, but no |
|
953 | - //entry in the meta table. Meaning that all its columns in the meta table |
|
954 | - //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
955 | - if ($field_value_from_db === null) { |
|
956 | - if ($field_obj->is_nullable()) { |
|
957 | - //if the field allows nulls, then let it be null |
|
958 | - $field_value = null; |
|
959 | - } else { |
|
960 | - $field_value = $field_obj->get_default_value(); |
|
961 | - } |
|
962 | - } else { |
|
963 | - $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
964 | - } |
|
965 | - $this->_fields[$field_name] = $field_value; |
|
966 | - $this->_clear_cached_property($field_name); |
|
967 | - } |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * verifies that the specified field is of the correct type |
|
974 | - * |
|
975 | - * @param string $field_name |
|
976 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
977 | - * (in cases where the same property may be used for different outputs |
|
978 | - * - i.e. datetime, money etc.) |
|
979 | - * @return mixed |
|
980 | - * @throws \EE_Error |
|
981 | - */ |
|
982 | - public function get($field_name, $extra_cache_ref = null) |
|
983 | - { |
|
984 | - return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - |
|
989 | - /** |
|
990 | - * This method simply returns the RAW unprocessed value for the given property in this class |
|
991 | - * |
|
992 | - * @param string $field_name A valid fieldname |
|
993 | - * @return mixed Whatever the raw value stored on the property is. |
|
994 | - * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
995 | - */ |
|
996 | - public function get_raw($field_name) |
|
997 | - { |
|
998 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
999 | - return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
1000 | - ? $this->_fields[$field_name]->format('U') |
|
1001 | - : $this->_fields[$field_name]; |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * This is used to return the internal DateTime object used for a field that is a |
|
1008 | - * EE_Datetime_Field. |
|
1009 | - * |
|
1010 | - * @param string $field_name The field name retrieving the DateTime object. |
|
1011 | - * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
1012 | - * @throws \EE_Error |
|
1013 | - * an error is set and false returned. If the field IS an |
|
1014 | - * EE_Datetime_Field and but the field value is null, then |
|
1015 | - * just null is returned (because that indicates that likely |
|
1016 | - * this field is nullable). |
|
1017 | - */ |
|
1018 | - public function get_DateTime_object($field_name) |
|
1019 | - { |
|
1020 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
1021 | - if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1022 | - EE_Error::add_error( |
|
1023 | - sprintf( |
|
1024 | - __( |
|
1025 | - 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
1026 | - 'event_espresso' |
|
1027 | - ), |
|
1028 | - $field_name |
|
1029 | - ), |
|
1030 | - __FILE__, |
|
1031 | - __FUNCTION__, |
|
1032 | - __LINE__ |
|
1033 | - ); |
|
1034 | - return false; |
|
1035 | - } |
|
1036 | - return $this->_fields[$field_name]; |
|
1037 | - } |
|
1038 | - |
|
1039 | - |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * To be used in template to immediately echo out the value, and format it for output. |
|
1043 | - * Eg, should call stripslashes and whatnot before echoing |
|
1044 | - * |
|
1045 | - * @param string $field_name the name of the field as it appears in the DB |
|
1046 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
1047 | - * (in cases where the same property may be used for different outputs |
|
1048 | - * - i.e. datetime, money etc.) |
|
1049 | - * @return void |
|
1050 | - * @throws \EE_Error |
|
1051 | - */ |
|
1052 | - public function e($field_name, $extra_cache_ref = null) |
|
1053 | - { |
|
1054 | - echo $this->get_pretty($field_name, $extra_cache_ref); |
|
1055 | - } |
|
1056 | - |
|
1057 | - |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
1061 | - * can be easily used as the value of form input. |
|
1062 | - * |
|
1063 | - * @param string $field_name |
|
1064 | - * @return void |
|
1065 | - * @throws \EE_Error |
|
1066 | - */ |
|
1067 | - public function f($field_name) |
|
1068 | - { |
|
1069 | - $this->e($field_name, 'form_input'); |
|
1070 | - } |
|
1071 | - |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * @param string $field_name |
|
1076 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
1077 | - * (in cases where the same property may be used for different outputs |
|
1078 | - * - i.e. datetime, money etc.) |
|
1079 | - * @return mixed |
|
1080 | - * @throws \EE_Error |
|
1081 | - */ |
|
1082 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
1083 | - { |
|
1084 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * This simply returns the datetime for the given field name |
|
1091 | - * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
1092 | - * (and the equivalent e_date, e_time, e_datetime). |
|
1093 | - * |
|
1094 | - * @access protected |
|
1095 | - * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
1096 | - * @param string $dt_frmt valid datetime format used for date |
|
1097 | - * (if '' then we just use the default on the field, |
|
1098 | - * if NULL we use the last-used format) |
|
1099 | - * @param string $tm_frmt Same as above except this is for time format |
|
1100 | - * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
1101 | - * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
1102 | - * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
1103 | - * if field is not a valid dtt field, or void if echoing |
|
1104 | - * @throws \EE_Error |
|
1105 | - */ |
|
1106 | - protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
1107 | - { |
|
1108 | - // clear cached property |
|
1109 | - $this->_clear_cached_property($field_name); |
|
1110 | - //reset format properties because they are used in get() |
|
1111 | - $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
1112 | - $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
1113 | - if ($echo) { |
|
1114 | - $this->e($field_name, $date_or_time); |
|
1115 | - return ''; |
|
1116 | - } |
|
1117 | - return $this->get($field_name, $date_or_time); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes |
|
1124 | - * the pretty value for dtt) |
|
1125 | - * |
|
1126 | - * @param string $field_name name of model object datetime field holding the value |
|
1127 | - * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
1128 | - * @return string datetime value formatted |
|
1129 | - * @throws \EE_Error |
|
1130 | - */ |
|
1131 | - public function get_date($field_name, $format = '') |
|
1132 | - { |
|
1133 | - return $this->_get_datetime($field_name, $format, null, 'D'); |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * @param $field_name |
|
1140 | - * @param string $format |
|
1141 | - * @throws \EE_Error |
|
1142 | - */ |
|
1143 | - public function e_date($field_name, $format = '') |
|
1144 | - { |
|
1145 | - $this->_get_datetime($field_name, $format, null, 'D', true); |
|
1146 | - } |
|
1147 | - |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes |
|
1152 | - * the pretty value for dtt) |
|
1153 | - * |
|
1154 | - * @param string $field_name name of model object datetime field holding the value |
|
1155 | - * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
1156 | - * @return string datetime value formatted |
|
1157 | - * @throws \EE_Error |
|
1158 | - */ |
|
1159 | - public function get_time($field_name, $format = '') |
|
1160 | - { |
|
1161 | - return $this->_get_datetime($field_name, null, $format, 'T'); |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @param $field_name |
|
1168 | - * @param string $format |
|
1169 | - * @throws \EE_Error |
|
1170 | - */ |
|
1171 | - public function e_time($field_name, $format = '') |
|
1172 | - { |
|
1173 | - $this->_get_datetime($field_name, null, $format, 'T', true); |
|
1174 | - } |
|
1175 | - |
|
1176 | - |
|
1177 | - |
|
1178 | - /** |
|
1179 | - * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other |
|
1180 | - * echoes the pretty value for dtt) |
|
1181 | - * |
|
1182 | - * @param string $field_name name of model object datetime field holding the value |
|
1183 | - * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
1184 | - * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
1185 | - * @return string datetime value formatted |
|
1186 | - * @throws \EE_Error |
|
1187 | - */ |
|
1188 | - public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
1189 | - { |
|
1190 | - return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1191 | - } |
|
1192 | - |
|
1193 | - |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * @param string $field_name |
|
1197 | - * @param string $dt_frmt |
|
1198 | - * @param string $tm_frmt |
|
1199 | - * @throws \EE_Error |
|
1200 | - */ |
|
1201 | - public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
1202 | - { |
|
1203 | - $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
1210 | - * |
|
1211 | - * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
1212 | - * @param string $format PHP valid date/time string format. If none is provided then the internal set format on the object will be used. |
|
1213 | - * @return string Date and time string in set locale or false if no field exists for the given |
|
1214 | - * @throws \EE_Error |
|
1215 | - * field name. |
|
1216 | - */ |
|
1217 | - public function get_i18n_datetime($field_name, $format = '') |
|
1218 | - { |
|
1219 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1220 | - return date_i18n( |
|
1221 | - $format, |
|
1222 | - EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
1223 | - ); |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - |
|
1228 | - /** |
|
1229 | - * This method validates whether the given field name is a valid field on the model object as well as it is of a type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is thrown. |
|
1230 | - * |
|
1231 | - * @param string $field_name The field name being checked |
|
1232 | - * @throws EE_Error |
|
1233 | - * @return EE_Datetime_Field |
|
1234 | - */ |
|
1235 | - protected function _get_dtt_field_settings($field_name) |
|
1236 | - { |
|
1237 | - $field = $this->get_model()->field_settings_for($field_name); |
|
1238 | - //check if field is dtt |
|
1239 | - if ($field instanceof EE_Datetime_Field) { |
|
1240 | - return $field; |
|
1241 | - } else { |
|
1242 | - throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', |
|
1243 | - 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1244 | - } |
|
1245 | - } |
|
1246 | - |
|
1247 | - |
|
1248 | - |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * NOTE ABOUT BELOW: |
|
1252 | - * These convenience date and time setters are for setting date and time independently. In other words you might want to change the time on a datetime_field but leave the date the same (or vice versa). |
|
1253 | - * IF on the other hand you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) method and make sure you send the entire datetime value for setting. |
|
1254 | - */ |
|
1255 | - /** |
|
1256 | - * sets the time on a datetime property |
|
1257 | - * |
|
1258 | - * @access protected |
|
1259 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1260 | - * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
1261 | - * @throws \EE_Error |
|
1262 | - */ |
|
1263 | - protected function _set_time_for($time, $fieldname) |
|
1264 | - { |
|
1265 | - $this->_set_date_time('T', $time, $fieldname); |
|
1266 | - } |
|
1267 | - |
|
1268 | - |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * sets the date on a datetime property |
|
1272 | - * |
|
1273 | - * @access protected |
|
1274 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1275 | - * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
1276 | - * @throws \EE_Error |
|
1277 | - */ |
|
1278 | - protected function _set_date_for($date, $fieldname) |
|
1279 | - { |
|
1280 | - $this->_set_date_time('D', $date, $fieldname); |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * This takes care of setting a date or time independently on a given model object property. This method also verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
1287 | - * |
|
1288 | - * @access protected |
|
1289 | - * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
1290 | - * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
1291 | - * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
|
1292 | - * @throws \EE_Error |
|
1293 | - */ |
|
1294 | - protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
1295 | - { |
|
1296 | - $field = $this->_get_dtt_field_settings($fieldname); |
|
1297 | - $field->set_timezone($this->_timezone); |
|
1298 | - $field->set_date_format($this->_dt_frmt); |
|
1299 | - $field->set_time_format($this->_tm_frmt); |
|
1300 | - switch ($what) { |
|
1301 | - case 'T' : |
|
1302 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
1303 | - $datetime_value, |
|
1304 | - $this->_fields[$fieldname] |
|
1305 | - ); |
|
1306 | - break; |
|
1307 | - case 'D' : |
|
1308 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
1309 | - $datetime_value, |
|
1310 | - $this->_fields[$fieldname] |
|
1311 | - ); |
|
1312 | - break; |
|
1313 | - case 'B' : |
|
1314 | - $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1315 | - break; |
|
1316 | - } |
|
1317 | - $this->_clear_cached_property($fieldname); |
|
1318 | - } |
|
1319 | - |
|
1320 | - |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * This will return a timestamp for the website timezone but ONLY when the current website timezone is different than the timezone set for the website. |
|
1324 | - * NOTE, this currently only works well with methods that return values. If you use it with methods that echo values the $_timestamp property may not get reset to its original value and that could lead to some unexpected results! |
|
1325 | - * |
|
1326 | - * @access public |
|
1327 | - * @param string $field_name This is the name of the field on the object that contains the date/time value being returned. |
|
1328 | - * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
1329 | - * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
1330 | - * @param string $prepend You can include something to prepend on the timestamp |
|
1331 | - * @param string $append You can include something to append on the timestamp |
|
1332 | - * @throws EE_Error |
|
1333 | - * @return string timestamp |
|
1334 | - */ |
|
1335 | - public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '') |
|
1336 | - { |
|
1337 | - $timezone = EEH_DTT_Helper::get_timezone(); |
|
1338 | - if ($timezone === $this->_timezone) { |
|
1339 | - return ''; |
|
1340 | - } |
|
1341 | - $original_timezone = $this->_timezone; |
|
1342 | - $this->set_timezone($timezone); |
|
1343 | - $fn = (array)$field_name; |
|
1344 | - $args = array_merge($fn, (array)$args); |
|
1345 | - if ( ! method_exists($this, $callback)) { |
|
1346 | - throw new EE_Error( |
|
1347 | - sprintf( |
|
1348 | - __( |
|
1349 | - 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
1350 | - 'event_espresso' |
|
1351 | - ), |
|
1352 | - $callback |
|
1353 | - ) |
|
1354 | - ); |
|
1355 | - } |
|
1356 | - $args = (array)$args; |
|
1357 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
1358 | - $this->set_timezone($original_timezone); |
|
1359 | - return $return; |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - |
|
1364 | - /** |
|
1365 | - * Deletes this model object. |
|
1366 | - * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should override |
|
1367 | - * `EE_Base_Class::_delete` NOT this class. |
|
1368 | - * |
|
1369 | - * @return boolean | int |
|
1370 | - * @throws \EE_Error |
|
1371 | - */ |
|
1372 | - public function delete() |
|
1373 | - { |
|
1374 | - /** |
|
1375 | - * Called just before the `EE_Base_Class::_delete` method call. |
|
1376 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
1377 | - * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
1378 | - * soft deletes (trash) the object and does not permanently delete it. |
|
1379 | - * |
|
1380 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
1381 | - */ |
|
1382 | - do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1383 | - $result = $this->_delete(); |
|
1384 | - /** |
|
1385 | - * Called just after the `EE_Base_Class::_delete` method call. |
|
1386 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
1387 | - * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
1388 | - * soft deletes (trash) the object and does not permanently delete it. |
|
1389 | - * |
|
1390 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
1391 | - * @param boolean $result |
|
1392 | - */ |
|
1393 | - do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1394 | - return $result; |
|
1395 | - } |
|
1396 | - |
|
1397 | - |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * Calls the specific delete method for the instantiated class. |
|
1401 | - * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override default |
|
1402 | - * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete` |
|
1403 | - * |
|
1404 | - * @return bool|int |
|
1405 | - * @throws \EE_Error |
|
1406 | - */ |
|
1407 | - protected function _delete() |
|
1408 | - { |
|
1409 | - return $this->delete_permanently(); |
|
1410 | - } |
|
1411 | - |
|
1412 | - |
|
1413 | - |
|
1414 | - /** |
|
1415 | - * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
|
1416 | - * |
|
1417 | - * @return bool | int |
|
1418 | - * @throws \EE_Error |
|
1419 | - */ |
|
1420 | - public function delete_permanently() |
|
1421 | - { |
|
1422 | - /** |
|
1423 | - * Called just before HARD deleting a model object |
|
1424 | - * |
|
1425 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
1426 | - */ |
|
1427 | - do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
1428 | - $model = $this->get_model(); |
|
1429 | - $result = $model->delete_permanently_by_ID($this->ID()); |
|
1430 | - $this->refresh_cache_of_related_objects(); |
|
1431 | - /** |
|
1432 | - * Called just after HARD deleting a model object |
|
1433 | - * |
|
1434 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
1435 | - * @param boolean $result |
|
1436 | - */ |
|
1437 | - do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
1438 | - return $result; |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - |
|
1443 | - /** |
|
1444 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1445 | - * related model objects |
|
1446 | - * |
|
1447 | - * @throws \EE_Error |
|
1448 | - */ |
|
1449 | - public function refresh_cache_of_related_objects() |
|
1450 | - { |
|
1451 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1452 | - if ( ! empty($this->_model_relations[$relation_name])) { |
|
1453 | - $related_objects = $this->_model_relations[$relation_name]; |
|
1454 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1455 | - //this relation only stores a single model object, not an array |
|
1456 | - //but let's make it consistent |
|
1457 | - $related_objects = array($related_objects); |
|
1458 | - } |
|
1459 | - foreach ($related_objects as $related_object) { |
|
1460 | - //only refresh their cache if they're in memory |
|
1461 | - if ($related_object instanceof EE_Base_Class) { |
|
1462 | - $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1463 | - } |
|
1464 | - } |
|
1465 | - } |
|
1466 | - } |
|
1467 | - } |
|
1468 | - |
|
1469 | - |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Saves this object to the database. An array may be supplied to set some values on this |
|
1473 | - * object just before saving. |
|
1474 | - * |
|
1475 | - * @access public |
|
1476 | - * @param array $set_cols_n_values keys are field names, values are their new values, |
|
1477 | - * if provided during the save() method (often client code will change the fields' values before calling save) |
|
1478 | - * @throws \EE_Error |
|
1479 | - * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
1480 | - * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
1481 | - */ |
|
1482 | - public function save($set_cols_n_values = array()) |
|
1483 | - { |
|
1484 | - /** |
|
1485 | - * Filters the fields we're about to save on the model object |
|
1486 | - * |
|
1487 | - * @param array $set_cols_n_values |
|
1488 | - * @param EE_Base_Class $model_object |
|
1489 | - */ |
|
1490 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1491 | - //set attributes as provided in $set_cols_n_values |
|
1492 | - foreach ($set_cols_n_values as $column => $value) { |
|
1493 | - $this->set($column, $value); |
|
1494 | - } |
|
1495 | - /** |
|
1496 | - * Saving a model object. |
|
1497 | - * Before we perform a save, this action is fired. |
|
1498 | - * |
|
1499 | - * @param EE_Base_Class $model_object the model object about to be saved. |
|
1500 | - */ |
|
1501 | - do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1502 | - if ( ! $this->allow_persist()) { |
|
1503 | - return 0; |
|
1504 | - } |
|
1505 | - //now get current attribute values |
|
1506 | - $save_cols_n_values = $this->_fields; |
|
1507 | - //if the object already has an ID, update it. Otherwise, insert it |
|
1508 | - //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
1509 | - $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
1510 | - $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
1511 | - //does this model have an autoincrement PK? |
|
1512 | - if ($this->get_model()->has_primary_key_field()) { |
|
1513 | - if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1514 | - //ok check if it's set, if so: update; if not, insert |
|
1515 | - if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1516 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1517 | - } else { |
|
1518 | - unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1519 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
1520 | - if ($results) { |
|
1521 | - //if successful, set the primary key |
|
1522 | - //but don't use the normal SET method, because it will check if |
|
1523 | - //an item with the same ID exists in the mapper & db, then |
|
1524 | - //will find it in the db (because we just added it) and THAT object |
|
1525 | - //will get added to the mapper before we can add this one! |
|
1526 | - //but if we just avoid using the SET method, all that headache can be avoided |
|
1527 | - $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1528 | - $this->_fields[$pk_field_name] = $results; |
|
1529 | - $this->_clear_cached_property($pk_field_name); |
|
1530 | - $this->get_model()->add_to_entity_map($this); |
|
1531 | - $this->_update_cached_related_model_objs_fks(); |
|
1532 | - } |
|
1533 | - } |
|
1534 | - } else {//PK is NOT auto-increment |
|
1535 | - //so check if one like it already exists in the db |
|
1536 | - if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1537 | - if (WP_DEBUG && ! $this->in_entity_map()) { |
|
1538 | - throw new EE_Error( |
|
1539 | - sprintf( |
|
1540 | - __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', |
|
1541 | - 'event_espresso'), |
|
1542 | - get_class($this), |
|
1543 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
1544 | - get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
1545 | - '<br />' |
|
1546 | - ) |
|
1547 | - ); |
|
1548 | - } |
|
1549 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1550 | - } else { |
|
1551 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
1552 | - $this->_update_cached_related_model_objs_fks(); |
|
1553 | - } |
|
1554 | - } |
|
1555 | - } else {//there is NO primary key |
|
1556 | - $already_in_db = false; |
|
1557 | - foreach ($this->get_model()->unique_indexes() as $index) { |
|
1558 | - $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
1559 | - if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1560 | - $already_in_db = true; |
|
1561 | - } |
|
1562 | - } |
|
1563 | - if ($already_in_db) { |
|
1564 | - $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1565 | - $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1566 | - } else { |
|
1567 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
1568 | - } |
|
1569 | - } |
|
1570 | - //restore the old assumption about values being prepared by the model object |
|
1571 | - $this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
1572 | - /** |
|
1573 | - * After saving the model object this action is called |
|
1574 | - * |
|
1575 | - * @param EE_Base_Class $model_object which was just saved |
|
1576 | - * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
1577 | - * the new ID (or 0 if an error occurred and it wasn't updated) |
|
1578 | - */ |
|
1579 | - do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1580 | - return $results; |
|
1581 | - } |
|
1582 | - |
|
1583 | - |
|
1584 | - |
|
1585 | - /** |
|
1586 | - * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
1587 | - * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB is consistent) |
|
1588 | - * Especially useful in case we JUST added this model object ot the database |
|
1589 | - * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on |
|
1590 | - * the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
1591 | - * |
|
1592 | - * @return void |
|
1593 | - * @throws \EE_Error |
|
1594 | - */ |
|
1595 | - protected function _update_cached_related_model_objs_fks() |
|
1596 | - { |
|
1597 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1598 | - if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1599 | - foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1600 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
1601 | - $this->get_model()->get_this_model_name() |
|
1602 | - ); |
|
1603 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1604 | - if ($related_model_obj_in_cache->ID()) { |
|
1605 | - $related_model_obj_in_cache->save(); |
|
1606 | - } |
|
1607 | - } |
|
1608 | - } |
|
1609 | - } |
|
1610 | - } |
|
1611 | - |
|
1612 | - |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * Saves this model object and its NEW cached relations to the database. |
|
1616 | - * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
1617 | - * In order for that to work, we would need to mark model objects as dirty/clean... |
|
1618 | - * because otherwise, there's a potential for infinite looping of saving |
|
1619 | - * Saves the cached related model objects, and ensures the relation between them |
|
1620 | - * and this object and properly setup |
|
1621 | - * |
|
1622 | - * @return int ID of new model object on save; 0 on failure+ |
|
1623 | - * @throws \EE_Error |
|
1624 | - */ |
|
1625 | - public function save_new_cached_related_model_objs() |
|
1626 | - { |
|
1627 | - //make sure this has been saved |
|
1628 | - if ( ! $this->ID()) { |
|
1629 | - $id = $this->save(); |
|
1630 | - } else { |
|
1631 | - $id = $this->ID(); |
|
1632 | - } |
|
1633 | - //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
1634 | - foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1635 | - if ($this->_model_relations[$relationName]) { |
|
1636 | - //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
1637 | - //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
1638 | - if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1639 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
1640 | - //but ONLY if it DOES NOT exist in the DB |
|
1641 | - /* @var $related_model_obj EE_Base_Class */ |
|
1642 | - $related_model_obj = $this->_model_relations[$relationName]; |
|
1643 | - // if( ! $related_model_obj->ID()){ |
|
1644 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
1645 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
1646 | - // } |
|
1647 | - } else { |
|
1648 | - foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1649 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
1650 | - //but ONLY if it DOES NOT exist in the DB |
|
1651 | - // if( ! $related_model_obj->ID()){ |
|
1652 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
1653 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
1654 | - // } |
|
1655 | - } |
|
1656 | - } |
|
1657 | - } |
|
1658 | - } |
|
1659 | - return $id; |
|
1660 | - } |
|
1661 | - |
|
1662 | - |
|
1663 | - |
|
1664 | - /** |
|
1665 | - * for getting a model while instantiated. |
|
1666 | - * |
|
1667 | - * @return \EEM_Base | \EEM_CPT_Base |
|
1668 | - */ |
|
1669 | - public function get_model() |
|
1670 | - { |
|
1671 | - $modelName = self::_get_model_classname(get_class($this)); |
|
1672 | - return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1673 | - } |
|
1674 | - |
|
1675 | - |
|
1676 | - |
|
1677 | - /** |
|
1678 | - * @param $props_n_values |
|
1679 | - * @param $classname |
|
1680 | - * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
1681 | - * @throws \EE_Error |
|
1682 | - */ |
|
1683 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
1684 | - { |
|
1685 | - //TODO: will not work for Term_Relationships because they have no PK! |
|
1686 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
1687 | - if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1688 | - $id = $props_n_values[$primary_id_ref]; |
|
1689 | - return self::_get_model($classname)->get_from_entity_map($id); |
|
1690 | - } |
|
1691 | - return false; |
|
1692 | - } |
|
1693 | - |
|
1694 | - |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for the primary key (if present in incoming values). |
|
1698 | - * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
|
1699 | - * |
|
1700 | - * @param array $props_n_values incoming array of properties and their values |
|
1701 | - * @param string $classname the classname of the child class |
|
1702 | - * @param null $timezone |
|
1703 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
1704 | - * date_format and the second value is the time format |
|
1705 | - * @return mixed (EE_Base_Class|bool) |
|
1706 | - * @throws \EE_Error |
|
1707 | - */ |
|
1708 | - protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
1709 | - { |
|
1710 | - $existing = null; |
|
1711 | - if (self::_get_model($classname)->has_primary_key_field()) { |
|
1712 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
1713 | - if (array_key_exists($primary_id_ref, $props_n_values) |
|
1714 | - && ! empty($props_n_values[$primary_id_ref]) |
|
1715 | - ) { |
|
1716 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1717 | - $props_n_values[$primary_id_ref] |
|
1718 | - ); |
|
1719 | - } |
|
1720 | - } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1721 | - //no primary key on this model, but there's still a matching item in the DB |
|
1722 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1723 | - self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
1724 | - ); |
|
1725 | - } |
|
1726 | - if ($existing) { |
|
1727 | - //set date formats if present before setting values |
|
1728 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
1729 | - $existing->set_date_format($date_formats[0]); |
|
1730 | - $existing->set_time_format($date_formats[1]); |
|
1731 | - } else { |
|
1732 | - //set default formats for date and time |
|
1733 | - $existing->set_date_format(get_option('date_format')); |
|
1734 | - $existing->set_time_format(get_option('time_format')); |
|
1735 | - } |
|
1736 | - foreach ($props_n_values as $property => $field_value) { |
|
1737 | - $existing->set($property, $field_value); |
|
1738 | - } |
|
1739 | - return $existing; |
|
1740 | - } else { |
|
1741 | - return false; |
|
1742 | - } |
|
1743 | - } |
|
1744 | - |
|
1745 | - |
|
1746 | - |
|
1747 | - /** |
|
1748 | - * Gets the EEM_*_Model for this class |
|
1749 | - * |
|
1750 | - * @access public now, as this is more convenient |
|
1751 | - * @param $classname |
|
1752 | - * @param null $timezone |
|
1753 | - * @throws EE_Error |
|
1754 | - * @return EEM_Base |
|
1755 | - */ |
|
1756 | - protected static function _get_model($classname, $timezone = null) |
|
1757 | - { |
|
1758 | - //find model for this class |
|
1759 | - if ( ! $classname) { |
|
1760 | - throw new EE_Error( |
|
1761 | - sprintf( |
|
1762 | - __( |
|
1763 | - "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
1764 | - "event_espresso" |
|
1765 | - ), |
|
1766 | - $classname |
|
1767 | - ) |
|
1768 | - ); |
|
1769 | - } |
|
1770 | - $modelName = self::_get_model_classname($classname); |
|
1771 | - return self::_get_model_instance_with_name($modelName, $timezone); |
|
1772 | - } |
|
1773 | - |
|
1774 | - |
|
1775 | - |
|
1776 | - /** |
|
1777 | - * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
1778 | - * |
|
1779 | - * @param string $model_classname |
|
1780 | - * @param null $timezone |
|
1781 | - * @return EEM_Base |
|
1782 | - */ |
|
1783 | - protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
1784 | - { |
|
1785 | - $model_classname = str_replace('EEM_', '', $model_classname); |
|
1786 | - $model = EE_Registry::instance()->load_model($model_classname); |
|
1787 | - $model->set_timezone($timezone); |
|
1788 | - return $model; |
|
1789 | - } |
|
1790 | - |
|
1791 | - |
|
1792 | - |
|
1793 | - /** |
|
1794 | - * If a model name is provided (eg Registration), gets the model classname for that model. |
|
1795 | - * Also works if a model class's classname is provided (eg EE_Registration). |
|
1796 | - * |
|
1797 | - * @param null $model_name |
|
1798 | - * @return string like EEM_Attendee |
|
1799 | - */ |
|
1800 | - private static function _get_model_classname($model_name = null) |
|
1801 | - { |
|
1802 | - if (strpos($model_name, "EE_") === 0) { |
|
1803 | - $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1804 | - } else { |
|
1805 | - $model_classname = "EEM_" . $model_name; |
|
1806 | - } |
|
1807 | - return $model_classname; |
|
1808 | - } |
|
1809 | - |
|
1810 | - |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * returns the name of the primary key attribute |
|
1814 | - * |
|
1815 | - * @param null $classname |
|
1816 | - * @throws EE_Error |
|
1817 | - * @return string |
|
1818 | - */ |
|
1819 | - protected static function _get_primary_key_name($classname = null) |
|
1820 | - { |
|
1821 | - if ( ! $classname) { |
|
1822 | - throw new EE_Error( |
|
1823 | - sprintf( |
|
1824 | - __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
1825 | - $classname |
|
1826 | - ) |
|
1827 | - ); |
|
1828 | - } |
|
1829 | - return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1830 | - } |
|
1831 | - |
|
1832 | - |
|
1833 | - |
|
1834 | - /** |
|
1835 | - * Gets the value of the primary key. |
|
1836 | - * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
1837 | - * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is. |
|
1838 | - * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
1839 | - * |
|
1840 | - * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
1841 | - * @throws \EE_Error |
|
1842 | - */ |
|
1843 | - public function ID() |
|
1844 | - { |
|
1845 | - //now that we know the name of the variable, use a variable variable to get its value and return its |
|
1846 | - if ($this->get_model()->has_primary_key_field()) { |
|
1847 | - return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1848 | - } else { |
|
1849 | - return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1850 | - } |
|
1851 | - } |
|
1852 | - |
|
1853 | - |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related |
|
1857 | - * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array. |
|
1858 | - * If this model object doesn't exist in the DB, just caches the related thing |
|
1859 | - * |
|
1860 | - * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
1861 | - * @param string $relationName eg 'Events','Question',etc. |
|
1862 | - * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
|
1863 | - * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added. However, keep in mind that the columns (keys) given must match |
|
1864 | - * a column on the JOIN table and currently only the HABTM models accept these additional conditions. Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
1865 | - * then a NEW row is created in the join table. |
|
1866 | - * @param null $cache_id |
|
1867 | - * @throws EE_Error |
|
1868 | - * @return EE_Base_Class the object the relation was added to |
|
1869 | - */ |
|
1870 | - public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null) |
|
1871 | - { |
|
1872 | - //if this thing exists in the DB, save the relation to the DB |
|
1873 | - if ($this->ID()) { |
|
1874 | - $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1875 | - //clear cache so future get_many_related and get_first_related() return new results. |
|
1876 | - $this->clear_cache($relationName, $otherObject, true); |
|
1877 | - if ($otherObject instanceof EE_Base_Class) { |
|
1878 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1879 | - } |
|
1880 | - } else { |
|
1881 | - //this thing doesn't exist in the DB, so just cache it |
|
1882 | - if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1883 | - throw new EE_Error(sprintf( |
|
1884 | - __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1885 | - $otherObjectModelObjectOrID, |
|
1886 | - get_class($this) |
|
1887 | - )); |
|
1888 | - } else { |
|
1889 | - $otherObject = $otherObjectModelObjectOrID; |
|
1890 | - } |
|
1891 | - $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1892 | - } |
|
1893 | - if ($otherObject instanceof EE_Base_Class) { |
|
1894 | - //fix the reciprocal relation too |
|
1895 | - if ($otherObject->ID()) { |
|
1896 | - //its saved so assumed relations exist in the DB, so we can just |
|
1897 | - //clear the cache so future queries use the updated info in the DB |
|
1898 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1899 | - } else { |
|
1900 | - //it's not saved, so it caches relations like this |
|
1901 | - $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1902 | - } |
|
1903 | - } |
|
1904 | - return $otherObject; |
|
1905 | - } |
|
1906 | - |
|
1907 | - |
|
1908 | - |
|
1909 | - /** |
|
1910 | - * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related |
|
1911 | - * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array. |
|
1912 | - * If this model object doesn't exist in the DB, just removes the related thing from the cache |
|
1913 | - * |
|
1914 | - * @param mixed $otherObjectModelObjectOrID |
|
1915 | - * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved to the DB yet |
|
1916 | - * @param string $relationName |
|
1917 | - * @param array $where_query |
|
1918 | - * You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added. |
|
1919 | - * However, keep in mind that the columns (keys) given must match a column on the JOIN table |
|
1920 | - * and currently only the HABTM models accept these additional conditions. |
|
1921 | - * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
|
1922 | - * @return EE_Base_Class the relation was removed from |
|
1923 | - * @throws \EE_Error |
|
1924 | - */ |
|
1925 | - public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
1926 | - { |
|
1927 | - if ($this->ID()) { |
|
1928 | - //if this exists in the DB, save the relation change to the DB too |
|
1929 | - $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1930 | - $this->clear_cache($relationName, $otherObject); |
|
1931 | - } else { |
|
1932 | - //this doesn't exist in the DB, just remove it from the cache |
|
1933 | - $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1934 | - } |
|
1935 | - if ($otherObject instanceof EE_Base_Class) { |
|
1936 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1937 | - } |
|
1938 | - return $otherObject; |
|
1939 | - } |
|
1940 | - |
|
1941 | - |
|
1942 | - |
|
1943 | - /** |
|
1944 | - * Removes ALL the related things for the $relationName. |
|
1945 | - * |
|
1946 | - * @param string $relationName |
|
1947 | - * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
1948 | - * @return EE_Base_Class |
|
1949 | - * @throws \EE_Error |
|
1950 | - */ |
|
1951 | - public function _remove_relations($relationName, $where_query_params = array()) |
|
1952 | - { |
|
1953 | - if ($this->ID()) { |
|
1954 | - //if this exists in the DB, save the relation change to the DB too |
|
1955 | - $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1956 | - $this->clear_cache($relationName, null, true); |
|
1957 | - } else { |
|
1958 | - //this doesn't exist in the DB, just remove it from the cache |
|
1959 | - $otherObjects = $this->clear_cache($relationName, null, true); |
|
1960 | - } |
|
1961 | - if (is_array($otherObjects)) { |
|
1962 | - foreach ($otherObjects as $otherObject) { |
|
1963 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1964 | - } |
|
1965 | - } |
|
1966 | - return $otherObjects; |
|
1967 | - } |
|
1968 | - |
|
1969 | - |
|
1970 | - |
|
1971 | - /** |
|
1972 | - * Gets all the related model objects of the specified type. Eg, if the current class if |
|
1973 | - * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
1974 | - * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
1975 | - * because we want to get even deleted items etc. |
|
1976 | - * |
|
1977 | - * @param string $relationName key in the model's _model_relations array |
|
1978 | - * @param array $query_params like EEM_Base::get_all |
|
1979 | - * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
1980 | - * @throws \EE_Error |
|
1981 | - * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
|
1982 | - */ |
|
1983 | - public function get_many_related($relationName, $query_params = array()) |
|
1984 | - { |
|
1985 | - if ($this->ID()) { |
|
1986 | - //this exists in the DB, so get the related things from either the cache or the DB |
|
1987 | - //if there are query parameters, forget about caching the related model objects. |
|
1988 | - if ($query_params) { |
|
1989 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
1990 | - } else { |
|
1991 | - //did we already cache the result of this query? |
|
1992 | - $cached_results = $this->get_all_from_cache($relationName); |
|
1993 | - if ( ! $cached_results) { |
|
1994 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
1995 | - //if no query parameters were passed, then we got all the related model objects |
|
1996 | - //for that relation. We can cache them then. |
|
1997 | - foreach ($related_model_objects as $related_model_object) { |
|
1998 | - $this->cache($relationName, $related_model_object); |
|
1999 | - } |
|
2000 | - } else { |
|
2001 | - $related_model_objects = $cached_results; |
|
2002 | - } |
|
2003 | - } |
|
2004 | - } else { |
|
2005 | - //this doesn't exist in the DB, so just get the related things from the cache |
|
2006 | - $related_model_objects = $this->get_all_from_cache($relationName); |
|
2007 | - } |
|
2008 | - return $related_model_objects; |
|
2009 | - } |
|
2010 | - |
|
2011 | - |
|
2012 | - |
|
2013 | - /** |
|
2014 | - * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
2015 | - * unless otherwise specified in the $query_params |
|
2016 | - * |
|
2017 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
2018 | - * @param array $query_params like EEM_Base::get_all's |
|
2019 | - * @param string $field_to_count name of field to count by. By default, uses primary key |
|
2020 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
2021 | - * @return int |
|
2022 | - */ |
|
2023 | - public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
2024 | - { |
|
2025 | - return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
2026 | - } |
|
2027 | - |
|
2028 | - |
|
2029 | - |
|
2030 | - /** |
|
2031 | - * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
2032 | - * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
2033 | - * |
|
2034 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
2035 | - * @param array $query_params like EEM_Base::get_all's |
|
2036 | - * @param string $field_to_sum name of field to count by. |
|
2037 | - * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
|
2038 | - * @return int |
|
2039 | - */ |
|
2040 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
2041 | - { |
|
2042 | - return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
2043 | - } |
|
2044 | - |
|
2045 | - |
|
2046 | - |
|
2047 | - /** |
|
2048 | - * Gets the first (ie, one) related model object of the specified type. |
|
2049 | - * |
|
2050 | - * @param string $relationName key in the model's _model_relations array |
|
2051 | - * @param array $query_params like EEM_Base::get_all |
|
2052 | - * @return EE_Base_Class (not an array, a single object) |
|
2053 | - * @throws \EE_Error |
|
2054 | - */ |
|
2055 | - public function get_first_related($relationName, $query_params = array()) |
|
2056 | - { |
|
2057 | - if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
2058 | - //if they've provided some query parameters, don't bother trying to cache the result |
|
2059 | - //also make sure we're not caching the result of get_first_related |
|
2060 | - //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
2061 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2062 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2063 | - } else { |
|
2064 | - //first, check if we've already cached the result of this query |
|
2065 | - $cached_result = $this->get_one_from_cache($relationName); |
|
2066 | - if ( ! $cached_result) { |
|
2067 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2068 | - $this->cache($relationName, $related_model_object); |
|
2069 | - } else { |
|
2070 | - $related_model_object = $cached_result; |
|
2071 | - } |
|
2072 | - } |
|
2073 | - } else { |
|
2074 | - $related_model_object = null; |
|
2075 | - //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
2076 | - if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2077 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2078 | - } |
|
2079 | - //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
|
2080 | - if ( ! $related_model_object) { |
|
2081 | - $related_model_object = $this->get_one_from_cache($relationName); |
|
2082 | - } |
|
2083 | - } |
|
2084 | - return $related_model_object; |
|
2085 | - } |
|
2086 | - |
|
2087 | - |
|
2088 | - |
|
2089 | - /** |
|
2090 | - * Does a delete on all related objects of type $relationName and removes |
|
2091 | - * the current model object's relation to them. If they can't be deleted (because |
|
2092 | - * of blocking related model objects) does nothing. If the related model objects are |
|
2093 | - * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
2094 | - * If this model object doesn't exist yet in the DB, just removes its related things |
|
2095 | - * |
|
2096 | - * @param string $relationName |
|
2097 | - * @param array $query_params like EEM_Base::get_all's |
|
2098 | - * @return int how many deleted |
|
2099 | - * @throws \EE_Error |
|
2100 | - */ |
|
2101 | - public function delete_related($relationName, $query_params = array()) |
|
2102 | - { |
|
2103 | - if ($this->ID()) { |
|
2104 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
2105 | - } else { |
|
2106 | - $count = count($this->get_all_from_cache($relationName)); |
|
2107 | - $this->clear_cache($relationName, null, true); |
|
2108 | - } |
|
2109 | - return $count; |
|
2110 | - } |
|
2111 | - |
|
2112 | - |
|
2113 | - |
|
2114 | - /** |
|
2115 | - * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
2116 | - * the current model object's relation to them. If they can't be deleted (because |
|
2117 | - * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
2118 | - * If the related thing isn't a soft-deletable model object, this function is identical |
|
2119 | - * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
2120 | - * |
|
2121 | - * @param string $relationName |
|
2122 | - * @param array $query_params like EEM_Base::get_all's |
|
2123 | - * @return int how many deleted (including those soft deleted) |
|
2124 | - * @throws \EE_Error |
|
2125 | - */ |
|
2126 | - public function delete_related_permanently($relationName, $query_params = array()) |
|
2127 | - { |
|
2128 | - if ($this->ID()) { |
|
2129 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
2130 | - } else { |
|
2131 | - $count = count($this->get_all_from_cache($relationName)); |
|
2132 | - } |
|
2133 | - $this->clear_cache($relationName, null, true); |
|
2134 | - return $count; |
|
2135 | - } |
|
2136 | - |
|
2137 | - |
|
2138 | - |
|
2139 | - /** |
|
2140 | - * is_set |
|
2141 | - * Just a simple utility function children can use for checking if property exists |
|
2142 | - * |
|
2143 | - * @access public |
|
2144 | - * @param string $field_name property to check |
|
2145 | - * @return bool TRUE if existing,FALSE if not. |
|
2146 | - */ |
|
2147 | - public function is_set($field_name) |
|
2148 | - { |
|
2149 | - return isset($this->_fields[$field_name]); |
|
2150 | - } |
|
2151 | - |
|
2152 | - |
|
2153 | - |
|
2154 | - /** |
|
2155 | - * Just a simple utility function children can use for checking if property (or properties) exists and throwing an EE_Error exception if they don't |
|
2156 | - * |
|
2157 | - * @param mixed (string|array) $properties properties to check |
|
2158 | - * @throws EE_Error |
|
2159 | - * @return bool TRUE if existing, throw EE_Error if not. |
|
2160 | - */ |
|
2161 | - protected function _property_exists($properties) |
|
2162 | - { |
|
2163 | - foreach ((array)$properties as $property_name) { |
|
2164 | - //first make sure this property exists |
|
2165 | - if ( ! $this->_fields[$property_name]) { |
|
2166 | - throw new EE_Error( |
|
2167 | - sprintf( |
|
2168 | - __( |
|
2169 | - 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
2170 | - 'event_espresso' |
|
2171 | - ), |
|
2172 | - $property_name |
|
2173 | - ) |
|
2174 | - ); |
|
2175 | - } |
|
2176 | - } |
|
2177 | - return true; |
|
2178 | - } |
|
2179 | - |
|
2180 | - |
|
2181 | - |
|
2182 | - /** |
|
2183 | - * This simply returns an array of model fields for this object |
|
2184 | - * |
|
2185 | - * @return array |
|
2186 | - * @throws \EE_Error |
|
2187 | - */ |
|
2188 | - public function model_field_array() |
|
2189 | - { |
|
2190 | - $fields = $this->get_model()->field_settings(false); |
|
2191 | - $properties = array(); |
|
2192 | - //remove prepended underscore |
|
2193 | - foreach ($fields as $field_name => $settings) { |
|
2194 | - $properties[$field_name] = $this->get($field_name); |
|
2195 | - } |
|
2196 | - return $properties; |
|
2197 | - } |
|
2198 | - |
|
2199 | - |
|
2200 | - |
|
2201 | - /** |
|
2202 | - * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
2203 | - * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called (http://www.garfieldtech.com/blog/php-magic-call) |
|
2204 | - * and passed the method's name and arguments. |
|
2205 | - * Instead of requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that happen?) |
|
2206 | - * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function) |
|
2207 | - * and accepts 2 arguments: the object on which the function was called, and an array of the original arguments passed to the function. Whatever their callback function returns will be returned by this function. |
|
2208 | - * Example: in functions.php (or in a plugin): |
|
2209 | - * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); |
|
2210 | - * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
2211 | - * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
2212 | - * return $previousReturnValue.$returnString; |
|
2213 | - * } |
|
2214 | - * require('EE_Answer.class.php'); |
|
2215 | - * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
2216 | - * echo $answer->my_callback('monkeys',100); |
|
2217 | - * //will output "you called my_callback! and passed args:monkeys,100" |
|
2218 | - * |
|
2219 | - * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
2220 | - * @param array $args array of original arguments passed to the function |
|
2221 | - * @throws EE_Error |
|
2222 | - * @return mixed whatever the plugin which calls add_filter decides |
|
2223 | - */ |
|
2224 | - public function __call($methodName, $args) |
|
2225 | - { |
|
2226 | - $className = get_class($this); |
|
2227 | - $tagName = "FHEE__{$className}__{$methodName}"; |
|
2228 | - if ( ! has_filter($tagName)) { |
|
2229 | - throw new EE_Error( |
|
2230 | - sprintf( |
|
2231 | - __( |
|
2232 | - "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", |
|
2233 | - "event_espresso" |
|
2234 | - ), |
|
2235 | - $methodName, |
|
2236 | - $className, |
|
2237 | - $tagName |
|
2238 | - ) |
|
2239 | - ); |
|
2240 | - } |
|
2241 | - return apply_filters($tagName, null, $this, $args); |
|
2242 | - } |
|
2243 | - |
|
2244 | - |
|
2245 | - |
|
2246 | - /** |
|
2247 | - * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
2248 | - * A $previous_value can be specified in case there are many meta rows with the same key |
|
2249 | - * |
|
2250 | - * @param string $meta_key |
|
2251 | - * @param string $meta_value |
|
2252 | - * @param string $previous_value |
|
2253 | - * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
2254 | - * @throws \EE_Error |
|
2255 | - * NOTE: if the values haven't changed, returns 0 |
|
2256 | - */ |
|
2257 | - public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
2258 | - { |
|
2259 | - $query_params = array( |
|
2260 | - array( |
|
2261 | - 'EXM_key' => $meta_key, |
|
2262 | - 'OBJ_ID' => $this->ID(), |
|
2263 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2264 | - ), |
|
2265 | - ); |
|
2266 | - if ($previous_value !== null) { |
|
2267 | - $query_params[0]['EXM_value'] = $meta_value; |
|
2268 | - } |
|
2269 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
2270 | - if ( ! $existing_rows_like_that) { |
|
2271 | - return $this->add_extra_meta($meta_key, $meta_value); |
|
2272 | - } else { |
|
2273 | - foreach ($existing_rows_like_that as $existing_row) { |
|
2274 | - $existing_row->save(array('EXM_value' => $meta_value)); |
|
2275 | - } |
|
2276 | - return count($existing_rows_like_that); |
|
2277 | - } |
|
2278 | - } |
|
2279 | - |
|
2280 | - |
|
2281 | - |
|
2282 | - /** |
|
2283 | - * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
2284 | - * no other extra meta for this model object have the same key. Returns TRUE if the |
|
2285 | - * extra meta row was entered, false if not |
|
2286 | - * |
|
2287 | - * @param string $meta_key |
|
2288 | - * @param string $meta_value |
|
2289 | - * @param boolean $unique |
|
2290 | - * @return boolean |
|
2291 | - * @throws \EE_Error |
|
2292 | - */ |
|
2293 | - public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
2294 | - { |
|
2295 | - if ($unique) { |
|
2296 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
2297 | - array( |
|
2298 | - array( |
|
2299 | - 'EXM_key' => $meta_key, |
|
2300 | - 'OBJ_ID' => $this->ID(), |
|
2301 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2302 | - ), |
|
2303 | - ) |
|
2304 | - ); |
|
2305 | - if ($existing_extra_meta) { |
|
2306 | - return false; |
|
2307 | - } |
|
2308 | - } |
|
2309 | - $new_extra_meta = EE_Extra_Meta::new_instance( |
|
2310 | - array( |
|
2311 | - 'EXM_key' => $meta_key, |
|
2312 | - 'EXM_value' => $meta_value, |
|
2313 | - 'OBJ_ID' => $this->ID(), |
|
2314 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2315 | - ) |
|
2316 | - ); |
|
2317 | - $new_extra_meta->save(); |
|
2318 | - return true; |
|
2319 | - } |
|
2320 | - |
|
2321 | - |
|
2322 | - |
|
2323 | - /** |
|
2324 | - * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
2325 | - * is specified, only deletes extra meta records with that value. |
|
2326 | - * |
|
2327 | - * @param string $meta_key |
|
2328 | - * @param string $meta_value |
|
2329 | - * @return int number of extra meta rows deleted |
|
2330 | - * @throws \EE_Error |
|
2331 | - */ |
|
2332 | - public function delete_extra_meta($meta_key, $meta_value = null) |
|
2333 | - { |
|
2334 | - $query_params = array( |
|
2335 | - array( |
|
2336 | - 'EXM_key' => $meta_key, |
|
2337 | - 'OBJ_ID' => $this->ID(), |
|
2338 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2339 | - ), |
|
2340 | - ); |
|
2341 | - if ($meta_value !== null) { |
|
2342 | - $query_params[0]['EXM_value'] = $meta_value; |
|
2343 | - } |
|
2344 | - return EEM_Extra_Meta::instance()->delete($query_params); |
|
2345 | - } |
|
2346 | - |
|
2347 | - |
|
2348 | - |
|
2349 | - /** |
|
2350 | - * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
2351 | - * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
2352 | - * You can specify $default is case you haven't found the extra meta |
|
2353 | - * |
|
2354 | - * @param string $meta_key |
|
2355 | - * @param boolean $single |
|
2356 | - * @param mixed $default if we don't find anything, what should we return? |
|
2357 | - * @return mixed single value if $single; array if ! $single |
|
2358 | - * @throws \EE_Error |
|
2359 | - */ |
|
2360 | - public function get_extra_meta($meta_key, $single = false, $default = null) |
|
2361 | - { |
|
2362 | - if ($single) { |
|
2363 | - $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
2364 | - if ($result instanceof EE_Extra_Meta) { |
|
2365 | - return $result->value(); |
|
2366 | - } else { |
|
2367 | - return $default; |
|
2368 | - } |
|
2369 | - } else { |
|
2370 | - $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
2371 | - if ($results) { |
|
2372 | - $values = array(); |
|
2373 | - foreach ($results as $result) { |
|
2374 | - if ($result instanceof EE_Extra_Meta) { |
|
2375 | - $values[$result->ID()] = $result->value(); |
|
2376 | - } |
|
2377 | - } |
|
2378 | - return $values; |
|
2379 | - } else { |
|
2380 | - return $default; |
|
2381 | - } |
|
2382 | - } |
|
2383 | - } |
|
2384 | - |
|
2385 | - |
|
2386 | - |
|
2387 | - /** |
|
2388 | - * Returns a simple array of all the extra meta associated with this model object. |
|
2389 | - * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
2390 | - * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
2391 | - * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
2392 | - * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
2393 | - * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
2394 | - * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
2395 | - * |
|
2396 | - * @param boolean $one_of_each_key |
|
2397 | - * @return array |
|
2398 | - * @throws \EE_Error |
|
2399 | - */ |
|
2400 | - public function all_extra_meta_array($one_of_each_key = true) |
|
2401 | - { |
|
2402 | - $return_array = array(); |
|
2403 | - if ($one_of_each_key) { |
|
2404 | - $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
2405 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2406 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2407 | - $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
2408 | - } |
|
2409 | - } |
|
2410 | - } else { |
|
2411 | - $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
2412 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2413 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2414 | - if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2415 | - $return_array[$extra_meta_obj->key()] = array(); |
|
2416 | - } |
|
2417 | - $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
2418 | - } |
|
2419 | - } |
|
2420 | - } |
|
2421 | - return $return_array; |
|
2422 | - } |
|
2423 | - |
|
2424 | - |
|
2425 | - |
|
2426 | - /** |
|
2427 | - * Gets a pretty nice displayable nice for this model object. Often overridden |
|
2428 | - * |
|
2429 | - * @return string |
|
2430 | - * @throws \EE_Error |
|
2431 | - */ |
|
2432 | - public function name() |
|
2433 | - { |
|
2434 | - //find a field that's not a text field |
|
2435 | - $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
2436 | - if ($field_we_can_use) { |
|
2437 | - return $this->get($field_we_can_use->get_name()); |
|
2438 | - } else { |
|
2439 | - $first_few_properties = $this->model_field_array(); |
|
2440 | - $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2441 | - $name_parts = array(); |
|
2442 | - foreach ($first_few_properties as $name => $value) { |
|
2443 | - $name_parts[] = "$name:$value"; |
|
2444 | - } |
|
2445 | - return implode(",", $name_parts); |
|
2446 | - } |
|
2447 | - } |
|
2448 | - |
|
2449 | - |
|
2450 | - |
|
2451 | - /** |
|
2452 | - * in_entity_map |
|
2453 | - * Checks if this model object has been proven to already be in the entity map |
|
2454 | - * |
|
2455 | - * @return boolean |
|
2456 | - * @throws \EE_Error |
|
2457 | - */ |
|
2458 | - public function in_entity_map() |
|
2459 | - { |
|
2460 | - if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2461 | - //well, if we looked, did we find it in the entity map? |
|
2462 | - return true; |
|
2463 | - } else { |
|
2464 | - return false; |
|
2465 | - } |
|
2466 | - } |
|
2467 | - |
|
2468 | - |
|
2469 | - |
|
2470 | - /** |
|
2471 | - * refresh_from_db |
|
2472 | - * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
2473 | - * |
|
2474 | - * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
2475 | - * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
2476 | - */ |
|
2477 | - public function refresh_from_db() |
|
2478 | - { |
|
2479 | - if ($this->ID() && $this->in_entity_map()) { |
|
2480 | - $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2481 | - } else { |
|
2482 | - //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
2483 | - //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
2484 | - //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
2485 | - //absolutely nothing in it for this ID |
|
2486 | - if (WP_DEBUG) { |
|
2487 | - throw new EE_Error( |
|
2488 | - sprintf( |
|
2489 | - __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', |
|
2490 | - 'event_espresso'), |
|
2491 | - $this->ID(), |
|
2492 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
2493 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
2494 | - ) |
|
2495 | - ); |
|
2496 | - } |
|
2497 | - } |
|
2498 | - } |
|
2499 | - |
|
2500 | - |
|
2501 | - |
|
2502 | - /** |
|
2503 | - * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
2504 | - * (probably a bad assumption they have made, oh well) |
|
2505 | - * |
|
2506 | - * @return string |
|
2507 | - */ |
|
2508 | - public function __toString() |
|
2509 | - { |
|
2510 | - try { |
|
2511 | - return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2512 | - } catch (Exception $e) { |
|
2513 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
2514 | - return ''; |
|
2515 | - } |
|
2516 | - } |
|
2517 | - |
|
2518 | - |
|
2519 | - |
|
2520 | - /** |
|
2521 | - * Clear related model objects if they're already in the DB, because otherwise when we |
|
2522 | - * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
2523 | - * This means if we have made changes to those related model objects, and want to unserialize |
|
2524 | - * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
2525 | - * Instead, those related model objects should be directly serialized and stored. |
|
2526 | - * Eg, the following won't work: |
|
2527 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
2528 | - * $att = $reg->attendee(); |
|
2529 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
2530 | - * update_option( 'my_option', serialize( $reg ) ); |
|
2531 | - * //END REQUEST |
|
2532 | - * //START NEXT REQUEST |
|
2533 | - * $reg = get_option( 'my_option' ); |
|
2534 | - * $reg->attendee()->save(); |
|
2535 | - * And would need to be replace with: |
|
2536 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
2537 | - * $att = $reg->attendee(); |
|
2538 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
2539 | - * update_option( 'my_option', serialize( $reg ) ); |
|
2540 | - * //END REQUEST |
|
2541 | - * //START NEXT REQUEST |
|
2542 | - * $att = get_option( 'my_option' ); |
|
2543 | - * $att->save(); |
|
2544 | - * |
|
2545 | - * @return array |
|
2546 | - * @throws \EE_Error |
|
2547 | - */ |
|
2548 | - public function __sleep() |
|
2549 | - { |
|
2550 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2551 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2552 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2553 | - if ( |
|
2554 | - $this->get_one_from_cache($relation_name) instanceof $classname |
|
2555 | - && $this->get_one_from_cache($relation_name)->ID() |
|
2556 | - ) { |
|
2557 | - $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2558 | - } |
|
2559 | - } |
|
2560 | - } |
|
2561 | - $this->_props_n_values_provided_in_constructor = array(); |
|
2562 | - return array_keys(get_object_vars($this)); |
|
2563 | - } |
|
2564 | - |
|
2565 | - |
|
2566 | - |
|
2567 | - /** |
|
2568 | - * restore _props_n_values_provided_in_constructor |
|
2569 | - * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
2570 | - * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
2571 | - * At best, you would only be able to detect if state change has occurred during THIS request. |
|
2572 | - */ |
|
2573 | - public function __wakeup() |
|
2574 | - { |
|
2575 | - $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
2576 | - } |
|
28 | + /** |
|
29 | + * This is an array of the original properties and values provided during construction |
|
30 | + * of this model object. (keys are model field names, values are their values). |
|
31 | + * This list is important to remember so that when we are merging data from the db, we know |
|
32 | + * which values to override and which to not override. |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $_props_n_values_provided_in_constructor; |
|
37 | + |
|
38 | + /** |
|
39 | + * Timezone |
|
40 | + * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT all |
|
41 | + * EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have access to it. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_timezone; |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * date format |
|
51 | + * pattern or format for displaying dates |
|
52 | + * |
|
53 | + * @var string $_dt_frmt |
|
54 | + */ |
|
55 | + protected $_dt_frmt; |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * time format |
|
61 | + * pattern or format for displaying time |
|
62 | + * |
|
63 | + * @var string $_tm_frmt |
|
64 | + */ |
|
65 | + protected $_tm_frmt; |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * This property is for holding a cached array of object properties indexed by property name as the key. |
|
71 | + * The purpose of this is for setting a cache on properties that may have calculated values after a prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having to recalculate. |
|
72 | + * Used by _set_cached_property() and _get_cached_property() methods. |
|
73 | + * |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $_cached_properties = array(); |
|
77 | + |
|
78 | + /** |
|
79 | + * An array containing keys of the related model, and values are either an array of related mode objects or a single |
|
80 | + * related model object. see the model's _model_relations. The keys should match those specified. And if the relation |
|
81 | + * is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, all others have an array) |
|
82 | + * |
|
83 | + * @var array |
|
84 | + */ |
|
85 | + protected $_model_relations = array(); |
|
86 | + |
|
87 | + /** |
|
88 | + * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
89 | + * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
90 | + * |
|
91 | + * @var array |
|
92 | + */ |
|
93 | + protected $_fields = array(); |
|
94 | + |
|
95 | + /** |
|
96 | + * @var boolean indicating whether or not this model object is intended to ever be saved |
|
97 | + * For example, we might create model objects intended to only be used for the duration |
|
98 | + * of this request and to be thrown away, and if they were accidentally saved |
|
99 | + * it would be a bug. |
|
100 | + */ |
|
101 | + protected $_allow_persist = true; |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children play nice |
|
107 | + * |
|
108 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their values |
|
109 | + * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model or not. |
|
110 | + * @param string $timezone indicate what timezone you want any datetime fields to be in when instantiating a EE_Base_Class object. |
|
111 | + * @param array $date_formats An array of date formats to set on construct where first |
|
112 | + * value is the date_format and second value is the time |
|
113 | + * format. |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
117 | + { |
|
118 | + $className = get_class($this); |
|
119 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
120 | + $model = $this->get_model(); |
|
121 | + $model_fields = $model->field_settings(false); |
|
122 | + // ensure $fieldValues is an array |
|
123 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
124 | + // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
125 | + // verify client code has not passed any invalid field names |
|
126 | + foreach ($fieldValues as $field_name => $field_value) { |
|
127 | + if ( ! isset($model_fields[$field_name])) { |
|
128 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
129 | + } |
|
130 | + } |
|
131 | + // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
132 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
133 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
134 | + list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
135 | + } else { |
|
136 | + //set default formats for date and time |
|
137 | + $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
138 | + $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
139 | + } |
|
140 | + //if db model is instantiating |
|
141 | + if ($bydb) { |
|
142 | + //client code has indicated these field values are from the database |
|
143 | + foreach ($model_fields as $fieldName => $field) { |
|
144 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
145 | + } |
|
146 | + } else { |
|
147 | + //we're constructing a brand |
|
148 | + //new instance of the model object. Generally, this means we'll need to do more field validation |
|
149 | + foreach ($model_fields as $fieldName => $field) { |
|
150 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
151 | + } |
|
152 | + } |
|
153 | + //remember what values were passed to this constructor |
|
154 | + $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
155 | + //remember in entity mapper |
|
156 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
157 | + $model->add_to_entity_map($this); |
|
158 | + } |
|
159 | + //setup all the relations |
|
160 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
161 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
162 | + $this->_model_relations[$relation_name] = null; |
|
163 | + } else { |
|
164 | + $this->_model_relations[$relation_name] = array(); |
|
165 | + } |
|
166 | + } |
|
167 | + /** |
|
168 | + * Action done at the end of each model object construction |
|
169 | + * |
|
170 | + * @param EE_Base_Class $this the model object just created |
|
171 | + */ |
|
172 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
179 | + * |
|
180 | + * @return boolean |
|
181 | + */ |
|
182 | + public function allow_persist() |
|
183 | + { |
|
184 | + return $this->_allow_persist; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Sets whether or not this model object should be allowed to be saved to the DB. |
|
191 | + * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
192 | + * you got new information that somehow made you change your mind. |
|
193 | + * |
|
194 | + * @param boolean $allow_persist |
|
195 | + * @return boolean |
|
196 | + */ |
|
197 | + public function set_allow_persist($allow_persist) |
|
198 | + { |
|
199 | + return $this->_allow_persist = $allow_persist; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Gets the field's original value when this object was constructed during this request. |
|
206 | + * This can be helpful when determining if a model object has changed or not |
|
207 | + * |
|
208 | + * @param string $field_name |
|
209 | + * @return mixed|null |
|
210 | + * @throws \EE_Error |
|
211 | + */ |
|
212 | + public function get_original($field_name) |
|
213 | + { |
|
214 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
215 | + && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
216 | + ) { |
|
217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | + } else { |
|
219 | + return null; |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @param EE_Base_Class $obj |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_class($obj) |
|
230 | + { |
|
231 | + return get_class($obj); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Overrides parent because parent expects old models. |
|
238 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
239 | + * |
|
240 | + * @param string $field_name |
|
241 | + * @param mixed $field_value |
|
242 | + * @param bool $use_default |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function set($field_name, $field_value, $use_default = false) |
|
246 | + { |
|
247 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
248 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
249 | + // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
250 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
251 | + $field_obj->set_timezone($this->_timezone); |
|
252 | + $field_obj->set_date_format($this->_dt_frmt); |
|
253 | + $field_obj->set_time_format($this->_tm_frmt); |
|
254 | + } |
|
255 | + $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
256 | + //should the value be null? |
|
257 | + if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
258 | + $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
259 | + /** |
|
260 | + * To save having to refactor all the models, if a default value is used for a |
|
261 | + * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
262 | + * object. Then let's do a set again to ensure that it becomes a DateTime |
|
263 | + * object. |
|
264 | + * |
|
265 | + * @since 4.6.10+ |
|
266 | + */ |
|
267 | + if ( |
|
268 | + $field_obj instanceof EE_Datetime_Field |
|
269 | + && $this->_fields[$field_name] !== null |
|
270 | + && ! $this->_fields[$field_name] instanceof DateTime |
|
271 | + ) { |
|
272 | + empty($this->_fields[$field_name]) |
|
273 | + ? $this->set($field_name, time()) |
|
274 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
275 | + } |
|
276 | + } else { |
|
277 | + $this->_fields[$field_name] = $holder_of_value; |
|
278 | + } |
|
279 | + //if we're not in the constructor... |
|
280 | + //now check if what we set was a primary key |
|
281 | + if ( |
|
282 | + //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
283 | + $this->_props_n_values_provided_in_constructor |
|
284 | + && $field_value |
|
285 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
286 | + ) { |
|
287 | + //if so, we want all this object's fields to be filled either with |
|
288 | + //what we've explicitly set on this model |
|
289 | + //or what we have in the db |
|
290 | + // echo "setting primary key!"; |
|
291 | + $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
292 | + $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
293 | + foreach ($fields_on_model as $field_obj) { |
|
294 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
295 | + && $field_obj->get_name() !== $field_name |
|
296 | + ) { |
|
297 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
298 | + } |
|
299 | + } |
|
300 | + //oh this model object has an ID? well make sure its in the entity mapper |
|
301 | + $this->get_model()->add_to_entity_map($this); |
|
302 | + } |
|
303 | + //let's unset any cache for this field_name from the $_cached_properties property. |
|
304 | + $this->_clear_cached_property($field_name); |
|
305 | + } else { |
|
306 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * This sets the field value on the db column if it exists for the given $column_name or |
|
314 | + * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
315 | + * |
|
316 | + * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
317 | + * @param string $field_name Must be the exact column name. |
|
318 | + * @param mixed $field_value The value to set. |
|
319 | + * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
320 | + * @throws \EE_Error |
|
321 | + */ |
|
322 | + public function set_field_or_extra_meta($field_name, $field_value) |
|
323 | + { |
|
324 | + if ($this->get_model()->has_field($field_name)) { |
|
325 | + $this->set($field_name, $field_value); |
|
326 | + return true; |
|
327 | + } else { |
|
328 | + //ensure this object is saved first so that extra meta can be properly related. |
|
329 | + $this->save(); |
|
330 | + return $this->update_extra_meta($field_name, $field_value); |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * This retrieves the value of the db column set on this class or if that's not present |
|
338 | + * it will attempt to retrieve from extra_meta if found. |
|
339 | + * Example Usage: |
|
340 | + * Via EE_Message child class: |
|
341 | + * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
342 | + * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
343 | + * also have additional main fields specific to the messenger. The system accommodates those extra |
|
344 | + * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
345 | + * value for those extra fields dynamically via the EE_message object. |
|
346 | + * |
|
347 | + * @param string $field_name expecting the fully qualified field name. |
|
348 | + * @return mixed|null value for the field if found. null if not found. |
|
349 | + * @throws \EE_Error |
|
350 | + */ |
|
351 | + public function get_field_or_extra_meta($field_name) |
|
352 | + { |
|
353 | + if ($this->get_model()->has_field($field_name)) { |
|
354 | + $column_value = $this->get($field_name); |
|
355 | + } else { |
|
356 | + //This isn't a column in the main table, let's see if it is in the extra meta. |
|
357 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
358 | + } |
|
359 | + return $column_value; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally for being able to reference what timezone we are running conversions on when converting TO the internal timezone (UTC |
|
366 | + * Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
370 | + * @return void |
|
371 | + * @throws \EE_Error |
|
372 | + */ |
|
373 | + public function set_timezone($timezone = '') |
|
374 | + { |
|
375 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
376 | + //make sure we clear all cached properties because they won't be relevant now |
|
377 | + $this->_clear_cached_properties(); |
|
378 | + //make sure we update field settings and the date for all EE_Datetime_Fields |
|
379 | + $model_fields = $this->get_model()->field_settings(false); |
|
380 | + foreach ($model_fields as $field_name => $field_obj) { |
|
381 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
382 | + $field_obj->set_timezone($this->_timezone); |
|
383 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
384 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
385 | + } |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * This just returns whatever is set for the current timezone. |
|
394 | + * |
|
395 | + * @access public |
|
396 | + * @return string timezone string |
|
397 | + */ |
|
398 | + public function get_timezone() |
|
399 | + { |
|
400 | + return $this->_timezone; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * This sets the internal date format to what is sent in to be used as the new default for the class |
|
407 | + * internally instead of wp set date format options |
|
408 | + * |
|
409 | + * @since 4.6 |
|
410 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
411 | + */ |
|
412 | + public function set_date_format($format) |
|
413 | + { |
|
414 | + $this->_dt_frmt = $format; |
|
415 | + //clear cached_properties because they won't be relevant now. |
|
416 | + $this->_clear_cached_properties(); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * This sets the internal time format string to what is sent in to be used as the new default for the |
|
423 | + * class internally instead of wp set time format options. |
|
424 | + * |
|
425 | + * @since 4.6 |
|
426 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
427 | + */ |
|
428 | + public function set_time_format($format) |
|
429 | + { |
|
430 | + $this->_tm_frmt = $format; |
|
431 | + //clear cached_properties because they won't be relevant now. |
|
432 | + $this->_clear_cached_properties(); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * This returns the current internal set format for the date and time formats. |
|
439 | + * |
|
440 | + * @param bool $full if true (default), then return the full format. Otherwise will return an array where the |
|
441 | + * first value is the date format and the second value is the time format. |
|
442 | + * @return mixed string|array |
|
443 | + */ |
|
444 | + public function get_format($full = true) |
|
445 | + { |
|
446 | + return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * cache |
|
453 | + * stores the passed model object on the current model object. |
|
454 | + * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
455 | + * |
|
456 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' associated with this model object |
|
457 | + * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, that could be a payment or a registration) |
|
458 | + * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many items which will be stored in an array on this object |
|
459 | + * @throws EE_Error |
|
460 | + * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
|
461 | + */ |
|
462 | + public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
463 | + { |
|
464 | + // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
465 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
466 | + return false; |
|
467 | + } |
|
468 | + // also get "how" the object is related, or throw an error |
|
469 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
470 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
471 | + } |
|
472 | + // how many things are related ? |
|
473 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
474 | + // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
|
475 | + // so for these model objects just set it to be cached |
|
476 | + $this->_model_relations[$relationName] = $object_to_cache; |
|
477 | + $return = true; |
|
478 | + } else { |
|
479 | + // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
|
480 | + // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
481 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
482 | + // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
483 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
484 | + } |
|
485 | + // first check for a cache_id which is normally empty |
|
486 | + if ( ! empty($cache_id)) { |
|
487 | + // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
|
488 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
489 | + $return = $cache_id; |
|
490 | + } elseif ($object_to_cache->ID()) { |
|
491 | + // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
492 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
493 | + $return = $object_to_cache->ID(); |
|
494 | + } else { |
|
495 | + // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
496 | + $this->_model_relations[$relationName][] = $object_to_cache; |
|
497 | + // move the internal pointer to the end of the array |
|
498 | + end($this->_model_relations[$relationName]); |
|
499 | + // and grab the key so that we can return it |
|
500 | + $return = key($this->_model_relations[$relationName]); |
|
501 | + } |
|
502 | + } |
|
503 | + return $return; |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * For adding an item to the cached_properties property. |
|
510 | + * |
|
511 | + * @access protected |
|
512 | + * @param string $fieldname the property item the corresponding value is for. |
|
513 | + * @param mixed $value The value we are caching. |
|
514 | + * @param string|null $cache_type |
|
515 | + * @return void |
|
516 | + * @throws \EE_Error |
|
517 | + */ |
|
518 | + protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
519 | + { |
|
520 | + //first make sure this property exists |
|
521 | + $this->get_model()->field_settings_for($fieldname); |
|
522 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
523 | + $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
530 | + * This also SETS the cache if we return the actual property! |
|
531 | + * |
|
532 | + * @param string $fieldname the name of the property we're trying to retrieve |
|
533 | + * @param bool $pretty |
|
534 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
535 | + * (in cases where the same property may be used for different outputs |
|
536 | + * - i.e. datetime, money etc.) |
|
537 | + * It can also accept certain pre-defined "schema" strings |
|
538 | + * to define how to output the property. |
|
539 | + * see the field's prepare_for_pretty_echoing for what strings can be used |
|
540 | + * @return mixed whatever the value for the property is we're retrieving |
|
541 | + * @throws \EE_Error |
|
542 | + */ |
|
543 | + protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
544 | + { |
|
545 | + //verify the field exists |
|
546 | + $this->get_model()->field_settings_for($fieldname); |
|
547 | + $cache_type = $pretty ? 'pretty' : 'standard'; |
|
548 | + $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
549 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
550 | + return $this->_cached_properties[$fieldname][$cache_type]; |
|
551 | + } |
|
552 | + $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
553 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
554 | + // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
555 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
556 | + $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
557 | + } |
|
558 | + if ( ! isset($this->_fields[$fieldname])) { |
|
559 | + $this->_fields[$fieldname] = null; |
|
560 | + } |
|
561 | + $value = $pretty |
|
562 | + ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
563 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
564 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
565 | + return $value; |
|
566 | + } |
|
567 | + return null; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * set timezone, formats, and output for EE_Datetime_Field objects |
|
574 | + * |
|
575 | + * @param \EE_Datetime_Field $datetime_field |
|
576 | + * @param bool $pretty |
|
577 | + * @param null $date_or_time |
|
578 | + * @return void |
|
579 | + * @throws \EE_Error |
|
580 | + */ |
|
581 | + protected function _prepare_datetime_field( |
|
582 | + EE_Datetime_Field $datetime_field, |
|
583 | + $pretty = false, |
|
584 | + $date_or_time = null |
|
585 | + ) { |
|
586 | + $datetime_field->set_timezone($this->_timezone); |
|
587 | + $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
588 | + $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
589 | + //set the output returned |
|
590 | + switch ($date_or_time) { |
|
591 | + case 'D' : |
|
592 | + $datetime_field->set_date_time_output('date'); |
|
593 | + break; |
|
594 | + case 'T' : |
|
595 | + $datetime_field->set_date_time_output('time'); |
|
596 | + break; |
|
597 | + default : |
|
598 | + $datetime_field->set_date_time_output(); |
|
599 | + } |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * This just takes care of clearing out the cached_properties |
|
606 | + * |
|
607 | + * @return void |
|
608 | + */ |
|
609 | + protected function _clear_cached_properties() |
|
610 | + { |
|
611 | + $this->_cached_properties = array(); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This just clears out ONE property if it exists in the cache |
|
618 | + * |
|
619 | + * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
620 | + * @return void |
|
621 | + */ |
|
622 | + protected function _clear_cached_property($property_name) |
|
623 | + { |
|
624 | + if (isset($this->_cached_properties[$property_name])) { |
|
625 | + unset($this->_cached_properties[$property_name]); |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * Ensures that this related thing is a model object. |
|
633 | + * |
|
634 | + * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
635 | + * @param string $model_name name of the related thing, eg 'Attendee', |
|
636 | + * @return EE_Base_Class |
|
637 | + * @throws \EE_Error |
|
638 | + */ |
|
639 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
640 | + { |
|
641 | + $other_model_instance = self::_get_model_instance_with_name( |
|
642 | + self::_get_model_classname($model_name), |
|
643 | + $this->_timezone |
|
644 | + ); |
|
645 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Forgets the cached model of the given relation Name. So the next time we request it, |
|
652 | + * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
653 | + * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
654 | + * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
655 | + * |
|
656 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' |
|
657 | + * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
658 | + * if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation) |
|
659 | + * @param bool $clear_all This flags clearing the entire cache relation property if this is HasMany or HABTM. |
|
660 | + * @throws EE_Error |
|
661 | + * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
|
662 | + */ |
|
663 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
664 | + { |
|
665 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
666 | + $index_in_cache = ''; |
|
667 | + if ( ! $relationship_to_model) { |
|
668 | + throw new EE_Error( |
|
669 | + sprintf( |
|
670 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
671 | + $relationName, |
|
672 | + get_class($this) |
|
673 | + ) |
|
674 | + ); |
|
675 | + } |
|
676 | + if ($clear_all) { |
|
677 | + $obj_removed = true; |
|
678 | + $this->_model_relations[$relationName] = null; |
|
679 | + } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
680 | + $obj_removed = $this->_model_relations[$relationName]; |
|
681 | + $this->_model_relations[$relationName] = null; |
|
682 | + } else { |
|
683 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
684 | + $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
685 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
686 | + $index_found_at = null; |
|
687 | + //find this object in the array even though it has a different key |
|
688 | + foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
689 | + if ( |
|
690 | + $obj instanceof EE_Base_Class |
|
691 | + && ( |
|
692 | + $obj == $object_to_remove_or_index_into_array |
|
693 | + || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
694 | + ) |
|
695 | + ) { |
|
696 | + $index_found_at = $index; |
|
697 | + break; |
|
698 | + } |
|
699 | + } |
|
700 | + if ($index_found_at) { |
|
701 | + $index_in_cache = $index_found_at; |
|
702 | + } else { |
|
703 | + //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
704 | + //if it wasn't in it to begin with. So we're done |
|
705 | + return $object_to_remove_or_index_into_array; |
|
706 | + } |
|
707 | + } |
|
708 | + } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
709 | + //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
710 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
711 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
712 | + $index_in_cache = $index; |
|
713 | + } |
|
714 | + } |
|
715 | + } else { |
|
716 | + $index_in_cache = $object_to_remove_or_index_into_array; |
|
717 | + } |
|
718 | + //supposedly we've found it. But it could just be that the client code |
|
719 | + //provided a bad index/object |
|
720 | + if ( |
|
721 | + isset( |
|
722 | + $this->_model_relations[$relationName], |
|
723 | + $this->_model_relations[$relationName][$index_in_cache] |
|
724 | + ) |
|
725 | + ) { |
|
726 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
727 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
728 | + } else { |
|
729 | + //that thing was never cached anyways. |
|
730 | + $obj_removed = null; |
|
731 | + } |
|
732 | + } |
|
733 | + return $obj_removed; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * update_cache_after_object_save |
|
740 | + * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has obtained after being saved to the db |
|
741 | + * |
|
742 | + * @param string $relationName - the type of object that is cached |
|
743 | + * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
744 | + * @param string $current_cache_id - the ID that was used when originally caching the object |
|
745 | + * @return boolean TRUE on success, FALSE on fail |
|
746 | + * @throws \EE_Error |
|
747 | + */ |
|
748 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') |
|
749 | + { |
|
750 | + // verify that incoming object is of the correct type |
|
751 | + $obj_class = 'EE_' . $relationName; |
|
752 | + if ($newly_saved_object instanceof $obj_class) { |
|
753 | + /* @type EE_Base_Class $newly_saved_object */ |
|
754 | + // now get the type of relation |
|
755 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
756 | + // if this is a 1:1 relationship |
|
757 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
758 | + // then just replace the cached object with the newly saved object |
|
759 | + $this->_model_relations[$relationName] = $newly_saved_object; |
|
760 | + return true; |
|
761 | + // or if it's some kind of sordid feral polyamorous relationship... |
|
762 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
763 | + // then remove the current cached item |
|
764 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
765 | + // and cache the newly saved object using it's new ID |
|
766 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
767 | + return true; |
|
768 | + } |
|
769 | + } |
|
770 | + return false; |
|
771 | + } |
|
772 | + |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
777 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
778 | + * |
|
779 | + * @param string $relationName |
|
780 | + * @return EE_Base_Class |
|
781 | + */ |
|
782 | + public function get_one_from_cache($relationName) |
|
783 | + { |
|
784 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
785 | + if (is_array($cached_array_or_object)) { |
|
786 | + return array_shift($cached_array_or_object); |
|
787 | + } else { |
|
788 | + return $cached_array_or_object; |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
796 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
797 | + * |
|
798 | + * @param string $relationName |
|
799 | + * @throws \EE_Error |
|
800 | + * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
801 | + */ |
|
802 | + public function get_all_from_cache($relationName) |
|
803 | + { |
|
804 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
805 | + // if the result is not an array, but exists, make it an array |
|
806 | + $objects = is_array($objects) ? $objects : array($objects); |
|
807 | + //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
808 | + //basically, if this model object was stored in the session, and these cached model objects |
|
809 | + //already have IDs, let's make sure they're in their model's entity mapper |
|
810 | + //otherwise we will have duplicates next time we call |
|
811 | + // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
812 | + $model = EE_Registry::instance()->load_model($relationName); |
|
813 | + foreach ($objects as $model_object) { |
|
814 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
815 | + //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
816 | + if ($model_object->ID()) { |
|
817 | + $model->add_to_entity_map($model_object); |
|
818 | + } |
|
819 | + } else { |
|
820 | + throw new EE_Error( |
|
821 | + sprintf( |
|
822 | + __( |
|
823 | + 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
824 | + 'event_espresso' |
|
825 | + ), |
|
826 | + $relationName, |
|
827 | + gettype($model_object) |
|
828 | + ) |
|
829 | + ); |
|
830 | + } |
|
831 | + } |
|
832 | + return $objects; |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
839 | + * matching the given query conditions. |
|
840 | + * |
|
841 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
842 | + * @param int $limit How many objects to return. |
|
843 | + * @param array $query_params Any additional conditions on the query. |
|
844 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
845 | + * you can indicate just the columns you want returned |
|
846 | + * @return array|EE_Base_Class[] |
|
847 | + * @throws \EE_Error |
|
848 | + */ |
|
849 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
850 | + { |
|
851 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
852 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
853 | + : $field_to_order_by; |
|
854 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
855 | + if (empty($field) || empty($current_value)) { |
|
856 | + return array(); |
|
857 | + } |
|
858 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
865 | + * matching the given query conditions. |
|
866 | + * |
|
867 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
868 | + * @param int $limit How many objects to return. |
|
869 | + * @param array $query_params Any additional conditions on the query. |
|
870 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
871 | + * you can indicate just the columns you want returned |
|
872 | + * @return array|EE_Base_Class[] |
|
873 | + * @throws \EE_Error |
|
874 | + */ |
|
875 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
876 | + { |
|
877 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
878 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
879 | + : $field_to_order_by; |
|
880 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
881 | + if (empty($field) || empty($current_value)) { |
|
882 | + return array(); |
|
883 | + } |
|
884 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
891 | + * matching the given query conditions. |
|
892 | + * |
|
893 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
894 | + * @param array $query_params Any additional conditions on the query. |
|
895 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
896 | + * you can indicate just the columns you want returned |
|
897 | + * @return array|EE_Base_Class |
|
898 | + * @throws \EE_Error |
|
899 | + */ |
|
900 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
901 | + { |
|
902 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
903 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
904 | + : $field_to_order_by; |
|
905 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
906 | + if (empty($field) || empty($current_value)) { |
|
907 | + return array(); |
|
908 | + } |
|
909 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
916 | + * matching the given query conditions. |
|
917 | + * |
|
918 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
919 | + * @param array $query_params Any additional conditions on the query. |
|
920 | + * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
921 | + * you can indicate just the column you want returned |
|
922 | + * @return array|EE_Base_Class |
|
923 | + * @throws \EE_Error |
|
924 | + */ |
|
925 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
926 | + { |
|
927 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
928 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
929 | + : $field_to_order_by; |
|
930 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
931 | + if (empty($field) || empty($current_value)) { |
|
932 | + return array(); |
|
933 | + } |
|
934 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + |
|
939 | + /** |
|
940 | + * Overrides parent because parent expects old models. |
|
941 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
942 | + * |
|
943 | + * @param string $field_name |
|
944 | + * @param mixed $field_value_from_db |
|
945 | + * @throws \EE_Error |
|
946 | + */ |
|
947 | + public function set_from_db($field_name, $field_value_from_db) |
|
948 | + { |
|
949 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
950 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
951 | + //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
952 | + //eg, a CPT model object could have an entry in the posts table, but no |
|
953 | + //entry in the meta table. Meaning that all its columns in the meta table |
|
954 | + //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
955 | + if ($field_value_from_db === null) { |
|
956 | + if ($field_obj->is_nullable()) { |
|
957 | + //if the field allows nulls, then let it be null |
|
958 | + $field_value = null; |
|
959 | + } else { |
|
960 | + $field_value = $field_obj->get_default_value(); |
|
961 | + } |
|
962 | + } else { |
|
963 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
964 | + } |
|
965 | + $this->_fields[$field_name] = $field_value; |
|
966 | + $this->_clear_cached_property($field_name); |
|
967 | + } |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * verifies that the specified field is of the correct type |
|
974 | + * |
|
975 | + * @param string $field_name |
|
976 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
977 | + * (in cases where the same property may be used for different outputs |
|
978 | + * - i.e. datetime, money etc.) |
|
979 | + * @return mixed |
|
980 | + * @throws \EE_Error |
|
981 | + */ |
|
982 | + public function get($field_name, $extra_cache_ref = null) |
|
983 | + { |
|
984 | + return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + |
|
989 | + /** |
|
990 | + * This method simply returns the RAW unprocessed value for the given property in this class |
|
991 | + * |
|
992 | + * @param string $field_name A valid fieldname |
|
993 | + * @return mixed Whatever the raw value stored on the property is. |
|
994 | + * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
995 | + */ |
|
996 | + public function get_raw($field_name) |
|
997 | + { |
|
998 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
999 | + return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
1000 | + ? $this->_fields[$field_name]->format('U') |
|
1001 | + : $this->_fields[$field_name]; |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * This is used to return the internal DateTime object used for a field that is a |
|
1008 | + * EE_Datetime_Field. |
|
1009 | + * |
|
1010 | + * @param string $field_name The field name retrieving the DateTime object. |
|
1011 | + * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
1012 | + * @throws \EE_Error |
|
1013 | + * an error is set and false returned. If the field IS an |
|
1014 | + * EE_Datetime_Field and but the field value is null, then |
|
1015 | + * just null is returned (because that indicates that likely |
|
1016 | + * this field is nullable). |
|
1017 | + */ |
|
1018 | + public function get_DateTime_object($field_name) |
|
1019 | + { |
|
1020 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
1021 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1022 | + EE_Error::add_error( |
|
1023 | + sprintf( |
|
1024 | + __( |
|
1025 | + 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
1026 | + 'event_espresso' |
|
1027 | + ), |
|
1028 | + $field_name |
|
1029 | + ), |
|
1030 | + __FILE__, |
|
1031 | + __FUNCTION__, |
|
1032 | + __LINE__ |
|
1033 | + ); |
|
1034 | + return false; |
|
1035 | + } |
|
1036 | + return $this->_fields[$field_name]; |
|
1037 | + } |
|
1038 | + |
|
1039 | + |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * To be used in template to immediately echo out the value, and format it for output. |
|
1043 | + * Eg, should call stripslashes and whatnot before echoing |
|
1044 | + * |
|
1045 | + * @param string $field_name the name of the field as it appears in the DB |
|
1046 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
1047 | + * (in cases where the same property may be used for different outputs |
|
1048 | + * - i.e. datetime, money etc.) |
|
1049 | + * @return void |
|
1050 | + * @throws \EE_Error |
|
1051 | + */ |
|
1052 | + public function e($field_name, $extra_cache_ref = null) |
|
1053 | + { |
|
1054 | + echo $this->get_pretty($field_name, $extra_cache_ref); |
|
1055 | + } |
|
1056 | + |
|
1057 | + |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
1061 | + * can be easily used as the value of form input. |
|
1062 | + * |
|
1063 | + * @param string $field_name |
|
1064 | + * @return void |
|
1065 | + * @throws \EE_Error |
|
1066 | + */ |
|
1067 | + public function f($field_name) |
|
1068 | + { |
|
1069 | + $this->e($field_name, 'form_input'); |
|
1070 | + } |
|
1071 | + |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * @param string $field_name |
|
1076 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
1077 | + * (in cases where the same property may be used for different outputs |
|
1078 | + * - i.e. datetime, money etc.) |
|
1079 | + * @return mixed |
|
1080 | + * @throws \EE_Error |
|
1081 | + */ |
|
1082 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
1083 | + { |
|
1084 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * This simply returns the datetime for the given field name |
|
1091 | + * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
1092 | + * (and the equivalent e_date, e_time, e_datetime). |
|
1093 | + * |
|
1094 | + * @access protected |
|
1095 | + * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
1096 | + * @param string $dt_frmt valid datetime format used for date |
|
1097 | + * (if '' then we just use the default on the field, |
|
1098 | + * if NULL we use the last-used format) |
|
1099 | + * @param string $tm_frmt Same as above except this is for time format |
|
1100 | + * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
1101 | + * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
1102 | + * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
1103 | + * if field is not a valid dtt field, or void if echoing |
|
1104 | + * @throws \EE_Error |
|
1105 | + */ |
|
1106 | + protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
1107 | + { |
|
1108 | + // clear cached property |
|
1109 | + $this->_clear_cached_property($field_name); |
|
1110 | + //reset format properties because they are used in get() |
|
1111 | + $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
1112 | + $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
1113 | + if ($echo) { |
|
1114 | + $this->e($field_name, $date_or_time); |
|
1115 | + return ''; |
|
1116 | + } |
|
1117 | + return $this->get($field_name, $date_or_time); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes |
|
1124 | + * the pretty value for dtt) |
|
1125 | + * |
|
1126 | + * @param string $field_name name of model object datetime field holding the value |
|
1127 | + * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
1128 | + * @return string datetime value formatted |
|
1129 | + * @throws \EE_Error |
|
1130 | + */ |
|
1131 | + public function get_date($field_name, $format = '') |
|
1132 | + { |
|
1133 | + return $this->_get_datetime($field_name, $format, null, 'D'); |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * @param $field_name |
|
1140 | + * @param string $format |
|
1141 | + * @throws \EE_Error |
|
1142 | + */ |
|
1143 | + public function e_date($field_name, $format = '') |
|
1144 | + { |
|
1145 | + $this->_get_datetime($field_name, $format, null, 'D', true); |
|
1146 | + } |
|
1147 | + |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other echoes |
|
1152 | + * the pretty value for dtt) |
|
1153 | + * |
|
1154 | + * @param string $field_name name of model object datetime field holding the value |
|
1155 | + * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
1156 | + * @return string datetime value formatted |
|
1157 | + * @throws \EE_Error |
|
1158 | + */ |
|
1159 | + public function get_time($field_name, $format = '') |
|
1160 | + { |
|
1161 | + return $this->_get_datetime($field_name, null, $format, 'T'); |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @param $field_name |
|
1168 | + * @param string $format |
|
1169 | + * @throws \EE_Error |
|
1170 | + */ |
|
1171 | + public function e_time($field_name, $format = '') |
|
1172 | + { |
|
1173 | + $this->_get_datetime($field_name, null, $format, 'T', true); |
|
1174 | + } |
|
1175 | + |
|
1176 | + |
|
1177 | + |
|
1178 | + /** |
|
1179 | + * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the other |
|
1180 | + * echoes the pretty value for dtt) |
|
1181 | + * |
|
1182 | + * @param string $field_name name of model object datetime field holding the value |
|
1183 | + * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
1184 | + * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
1185 | + * @return string datetime value formatted |
|
1186 | + * @throws \EE_Error |
|
1187 | + */ |
|
1188 | + public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
1189 | + { |
|
1190 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1191 | + } |
|
1192 | + |
|
1193 | + |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * @param string $field_name |
|
1197 | + * @param string $dt_frmt |
|
1198 | + * @param string $tm_frmt |
|
1199 | + * @throws \EE_Error |
|
1200 | + */ |
|
1201 | + public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
1202 | + { |
|
1203 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
1210 | + * |
|
1211 | + * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
1212 | + * @param string $format PHP valid date/time string format. If none is provided then the internal set format on the object will be used. |
|
1213 | + * @return string Date and time string in set locale or false if no field exists for the given |
|
1214 | + * @throws \EE_Error |
|
1215 | + * field name. |
|
1216 | + */ |
|
1217 | + public function get_i18n_datetime($field_name, $format = '') |
|
1218 | + { |
|
1219 | + $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1220 | + return date_i18n( |
|
1221 | + $format, |
|
1222 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
1223 | + ); |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + |
|
1228 | + /** |
|
1229 | + * This method validates whether the given field name is a valid field on the model object as well as it is of a type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is thrown. |
|
1230 | + * |
|
1231 | + * @param string $field_name The field name being checked |
|
1232 | + * @throws EE_Error |
|
1233 | + * @return EE_Datetime_Field |
|
1234 | + */ |
|
1235 | + protected function _get_dtt_field_settings($field_name) |
|
1236 | + { |
|
1237 | + $field = $this->get_model()->field_settings_for($field_name); |
|
1238 | + //check if field is dtt |
|
1239 | + if ($field instanceof EE_Datetime_Field) { |
|
1240 | + return $field; |
|
1241 | + } else { |
|
1242 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', |
|
1243 | + 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1244 | + } |
|
1245 | + } |
|
1246 | + |
|
1247 | + |
|
1248 | + |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * NOTE ABOUT BELOW: |
|
1252 | + * These convenience date and time setters are for setting date and time independently. In other words you might want to change the time on a datetime_field but leave the date the same (or vice versa). |
|
1253 | + * IF on the other hand you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) method and make sure you send the entire datetime value for setting. |
|
1254 | + */ |
|
1255 | + /** |
|
1256 | + * sets the time on a datetime property |
|
1257 | + * |
|
1258 | + * @access protected |
|
1259 | + * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1260 | + * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
1261 | + * @throws \EE_Error |
|
1262 | + */ |
|
1263 | + protected function _set_time_for($time, $fieldname) |
|
1264 | + { |
|
1265 | + $this->_set_date_time('T', $time, $fieldname); |
|
1266 | + } |
|
1267 | + |
|
1268 | + |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * sets the date on a datetime property |
|
1272 | + * |
|
1273 | + * @access protected |
|
1274 | + * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1275 | + * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
1276 | + * @throws \EE_Error |
|
1277 | + */ |
|
1278 | + protected function _set_date_for($date, $fieldname) |
|
1279 | + { |
|
1280 | + $this->_set_date_time('D', $date, $fieldname); |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * This takes care of setting a date or time independently on a given model object property. This method also verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
1287 | + * |
|
1288 | + * @access protected |
|
1289 | + * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
1290 | + * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
1291 | + * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
|
1292 | + * @throws \EE_Error |
|
1293 | + */ |
|
1294 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
1295 | + { |
|
1296 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1297 | + $field->set_timezone($this->_timezone); |
|
1298 | + $field->set_date_format($this->_dt_frmt); |
|
1299 | + $field->set_time_format($this->_tm_frmt); |
|
1300 | + switch ($what) { |
|
1301 | + case 'T' : |
|
1302 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
1303 | + $datetime_value, |
|
1304 | + $this->_fields[$fieldname] |
|
1305 | + ); |
|
1306 | + break; |
|
1307 | + case 'D' : |
|
1308 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
1309 | + $datetime_value, |
|
1310 | + $this->_fields[$fieldname] |
|
1311 | + ); |
|
1312 | + break; |
|
1313 | + case 'B' : |
|
1314 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1315 | + break; |
|
1316 | + } |
|
1317 | + $this->_clear_cached_property($fieldname); |
|
1318 | + } |
|
1319 | + |
|
1320 | + |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * This will return a timestamp for the website timezone but ONLY when the current website timezone is different than the timezone set for the website. |
|
1324 | + * NOTE, this currently only works well with methods that return values. If you use it with methods that echo values the $_timestamp property may not get reset to its original value and that could lead to some unexpected results! |
|
1325 | + * |
|
1326 | + * @access public |
|
1327 | + * @param string $field_name This is the name of the field on the object that contains the date/time value being returned. |
|
1328 | + * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
1329 | + * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
1330 | + * @param string $prepend You can include something to prepend on the timestamp |
|
1331 | + * @param string $append You can include something to append on the timestamp |
|
1332 | + * @throws EE_Error |
|
1333 | + * @return string timestamp |
|
1334 | + */ |
|
1335 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = null, $prepend = '', $append = '') |
|
1336 | + { |
|
1337 | + $timezone = EEH_DTT_Helper::get_timezone(); |
|
1338 | + if ($timezone === $this->_timezone) { |
|
1339 | + return ''; |
|
1340 | + } |
|
1341 | + $original_timezone = $this->_timezone; |
|
1342 | + $this->set_timezone($timezone); |
|
1343 | + $fn = (array)$field_name; |
|
1344 | + $args = array_merge($fn, (array)$args); |
|
1345 | + if ( ! method_exists($this, $callback)) { |
|
1346 | + throw new EE_Error( |
|
1347 | + sprintf( |
|
1348 | + __( |
|
1349 | + 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
1350 | + 'event_espresso' |
|
1351 | + ), |
|
1352 | + $callback |
|
1353 | + ) |
|
1354 | + ); |
|
1355 | + } |
|
1356 | + $args = (array)$args; |
|
1357 | + $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
1358 | + $this->set_timezone($original_timezone); |
|
1359 | + return $return; |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + |
|
1364 | + /** |
|
1365 | + * Deletes this model object. |
|
1366 | + * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should override |
|
1367 | + * `EE_Base_Class::_delete` NOT this class. |
|
1368 | + * |
|
1369 | + * @return boolean | int |
|
1370 | + * @throws \EE_Error |
|
1371 | + */ |
|
1372 | + public function delete() |
|
1373 | + { |
|
1374 | + /** |
|
1375 | + * Called just before the `EE_Base_Class::_delete` method call. |
|
1376 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
1377 | + * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
1378 | + * soft deletes (trash) the object and does not permanently delete it. |
|
1379 | + * |
|
1380 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
1381 | + */ |
|
1382 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1383 | + $result = $this->_delete(); |
|
1384 | + /** |
|
1385 | + * Called just after the `EE_Base_Class::_delete` method call. |
|
1386 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
1387 | + * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
1388 | + * soft deletes (trash) the object and does not permanently delete it. |
|
1389 | + * |
|
1390 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
1391 | + * @param boolean $result |
|
1392 | + */ |
|
1393 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1394 | + return $result; |
|
1395 | + } |
|
1396 | + |
|
1397 | + |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * Calls the specific delete method for the instantiated class. |
|
1401 | + * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override default |
|
1402 | + * functionality for "delete" (which is to call `permanently_delete`) should override this method NOT `EE_Base_Class::delete` |
|
1403 | + * |
|
1404 | + * @return bool|int |
|
1405 | + * @throws \EE_Error |
|
1406 | + */ |
|
1407 | + protected function _delete() |
|
1408 | + { |
|
1409 | + return $this->delete_permanently(); |
|
1410 | + } |
|
1411 | + |
|
1412 | + |
|
1413 | + |
|
1414 | + /** |
|
1415 | + * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
|
1416 | + * |
|
1417 | + * @return bool | int |
|
1418 | + * @throws \EE_Error |
|
1419 | + */ |
|
1420 | + public function delete_permanently() |
|
1421 | + { |
|
1422 | + /** |
|
1423 | + * Called just before HARD deleting a model object |
|
1424 | + * |
|
1425 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
1426 | + */ |
|
1427 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
1428 | + $model = $this->get_model(); |
|
1429 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1430 | + $this->refresh_cache_of_related_objects(); |
|
1431 | + /** |
|
1432 | + * Called just after HARD deleting a model object |
|
1433 | + * |
|
1434 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
1435 | + * @param boolean $result |
|
1436 | + */ |
|
1437 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
1438 | + return $result; |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + |
|
1443 | + /** |
|
1444 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1445 | + * related model objects |
|
1446 | + * |
|
1447 | + * @throws \EE_Error |
|
1448 | + */ |
|
1449 | + public function refresh_cache_of_related_objects() |
|
1450 | + { |
|
1451 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1452 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
1453 | + $related_objects = $this->_model_relations[$relation_name]; |
|
1454 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1455 | + //this relation only stores a single model object, not an array |
|
1456 | + //but let's make it consistent |
|
1457 | + $related_objects = array($related_objects); |
|
1458 | + } |
|
1459 | + foreach ($related_objects as $related_object) { |
|
1460 | + //only refresh their cache if they're in memory |
|
1461 | + if ($related_object instanceof EE_Base_Class) { |
|
1462 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1463 | + } |
|
1464 | + } |
|
1465 | + } |
|
1466 | + } |
|
1467 | + } |
|
1468 | + |
|
1469 | + |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Saves this object to the database. An array may be supplied to set some values on this |
|
1473 | + * object just before saving. |
|
1474 | + * |
|
1475 | + * @access public |
|
1476 | + * @param array $set_cols_n_values keys are field names, values are their new values, |
|
1477 | + * if provided during the save() method (often client code will change the fields' values before calling save) |
|
1478 | + * @throws \EE_Error |
|
1479 | + * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
1480 | + * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
1481 | + */ |
|
1482 | + public function save($set_cols_n_values = array()) |
|
1483 | + { |
|
1484 | + /** |
|
1485 | + * Filters the fields we're about to save on the model object |
|
1486 | + * |
|
1487 | + * @param array $set_cols_n_values |
|
1488 | + * @param EE_Base_Class $model_object |
|
1489 | + */ |
|
1490 | + $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1491 | + //set attributes as provided in $set_cols_n_values |
|
1492 | + foreach ($set_cols_n_values as $column => $value) { |
|
1493 | + $this->set($column, $value); |
|
1494 | + } |
|
1495 | + /** |
|
1496 | + * Saving a model object. |
|
1497 | + * Before we perform a save, this action is fired. |
|
1498 | + * |
|
1499 | + * @param EE_Base_Class $model_object the model object about to be saved. |
|
1500 | + */ |
|
1501 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1502 | + if ( ! $this->allow_persist()) { |
|
1503 | + return 0; |
|
1504 | + } |
|
1505 | + //now get current attribute values |
|
1506 | + $save_cols_n_values = $this->_fields; |
|
1507 | + //if the object already has an ID, update it. Otherwise, insert it |
|
1508 | + //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
1509 | + $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
1510 | + $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
1511 | + //does this model have an autoincrement PK? |
|
1512 | + if ($this->get_model()->has_primary_key_field()) { |
|
1513 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1514 | + //ok check if it's set, if so: update; if not, insert |
|
1515 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1516 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1517 | + } else { |
|
1518 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1519 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1520 | + if ($results) { |
|
1521 | + //if successful, set the primary key |
|
1522 | + //but don't use the normal SET method, because it will check if |
|
1523 | + //an item with the same ID exists in the mapper & db, then |
|
1524 | + //will find it in the db (because we just added it) and THAT object |
|
1525 | + //will get added to the mapper before we can add this one! |
|
1526 | + //but if we just avoid using the SET method, all that headache can be avoided |
|
1527 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1528 | + $this->_fields[$pk_field_name] = $results; |
|
1529 | + $this->_clear_cached_property($pk_field_name); |
|
1530 | + $this->get_model()->add_to_entity_map($this); |
|
1531 | + $this->_update_cached_related_model_objs_fks(); |
|
1532 | + } |
|
1533 | + } |
|
1534 | + } else {//PK is NOT auto-increment |
|
1535 | + //so check if one like it already exists in the db |
|
1536 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1537 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
1538 | + throw new EE_Error( |
|
1539 | + sprintf( |
|
1540 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', |
|
1541 | + 'event_espresso'), |
|
1542 | + get_class($this), |
|
1543 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
1544 | + get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
1545 | + '<br />' |
|
1546 | + ) |
|
1547 | + ); |
|
1548 | + } |
|
1549 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1550 | + } else { |
|
1551 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1552 | + $this->_update_cached_related_model_objs_fks(); |
|
1553 | + } |
|
1554 | + } |
|
1555 | + } else {//there is NO primary key |
|
1556 | + $already_in_db = false; |
|
1557 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1558 | + $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
1559 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1560 | + $already_in_db = true; |
|
1561 | + } |
|
1562 | + } |
|
1563 | + if ($already_in_db) { |
|
1564 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1565 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1566 | + } else { |
|
1567 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1568 | + } |
|
1569 | + } |
|
1570 | + //restore the old assumption about values being prepared by the model object |
|
1571 | + $this->get_model()->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
1572 | + /** |
|
1573 | + * After saving the model object this action is called |
|
1574 | + * |
|
1575 | + * @param EE_Base_Class $model_object which was just saved |
|
1576 | + * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
1577 | + * the new ID (or 0 if an error occurred and it wasn't updated) |
|
1578 | + */ |
|
1579 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1580 | + return $results; |
|
1581 | + } |
|
1582 | + |
|
1583 | + |
|
1584 | + |
|
1585 | + /** |
|
1586 | + * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
1587 | + * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB is consistent) |
|
1588 | + * Especially useful in case we JUST added this model object ot the database |
|
1589 | + * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on |
|
1590 | + * the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
1591 | + * |
|
1592 | + * @return void |
|
1593 | + * @throws \EE_Error |
|
1594 | + */ |
|
1595 | + protected function _update_cached_related_model_objs_fks() |
|
1596 | + { |
|
1597 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1598 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1599 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1600 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
1601 | + $this->get_model()->get_this_model_name() |
|
1602 | + ); |
|
1603 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1604 | + if ($related_model_obj_in_cache->ID()) { |
|
1605 | + $related_model_obj_in_cache->save(); |
|
1606 | + } |
|
1607 | + } |
|
1608 | + } |
|
1609 | + } |
|
1610 | + } |
|
1611 | + |
|
1612 | + |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * Saves this model object and its NEW cached relations to the database. |
|
1616 | + * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
1617 | + * In order for that to work, we would need to mark model objects as dirty/clean... |
|
1618 | + * because otherwise, there's a potential for infinite looping of saving |
|
1619 | + * Saves the cached related model objects, and ensures the relation between them |
|
1620 | + * and this object and properly setup |
|
1621 | + * |
|
1622 | + * @return int ID of new model object on save; 0 on failure+ |
|
1623 | + * @throws \EE_Error |
|
1624 | + */ |
|
1625 | + public function save_new_cached_related_model_objs() |
|
1626 | + { |
|
1627 | + //make sure this has been saved |
|
1628 | + if ( ! $this->ID()) { |
|
1629 | + $id = $this->save(); |
|
1630 | + } else { |
|
1631 | + $id = $this->ID(); |
|
1632 | + } |
|
1633 | + //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
1634 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1635 | + if ($this->_model_relations[$relationName]) { |
|
1636 | + //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
1637 | + //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
1638 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1639 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
1640 | + //but ONLY if it DOES NOT exist in the DB |
|
1641 | + /* @var $related_model_obj EE_Base_Class */ |
|
1642 | + $related_model_obj = $this->_model_relations[$relationName]; |
|
1643 | + // if( ! $related_model_obj->ID()){ |
|
1644 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
1645 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
1646 | + // } |
|
1647 | + } else { |
|
1648 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1649 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
1650 | + //but ONLY if it DOES NOT exist in the DB |
|
1651 | + // if( ! $related_model_obj->ID()){ |
|
1652 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
1653 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
1654 | + // } |
|
1655 | + } |
|
1656 | + } |
|
1657 | + } |
|
1658 | + } |
|
1659 | + return $id; |
|
1660 | + } |
|
1661 | + |
|
1662 | + |
|
1663 | + |
|
1664 | + /** |
|
1665 | + * for getting a model while instantiated. |
|
1666 | + * |
|
1667 | + * @return \EEM_Base | \EEM_CPT_Base |
|
1668 | + */ |
|
1669 | + public function get_model() |
|
1670 | + { |
|
1671 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1672 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1673 | + } |
|
1674 | + |
|
1675 | + |
|
1676 | + |
|
1677 | + /** |
|
1678 | + * @param $props_n_values |
|
1679 | + * @param $classname |
|
1680 | + * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
1681 | + * @throws \EE_Error |
|
1682 | + */ |
|
1683 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
1684 | + { |
|
1685 | + //TODO: will not work for Term_Relationships because they have no PK! |
|
1686 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1687 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1688 | + $id = $props_n_values[$primary_id_ref]; |
|
1689 | + return self::_get_model($classname)->get_from_entity_map($id); |
|
1690 | + } |
|
1691 | + return false; |
|
1692 | + } |
|
1693 | + |
|
1694 | + |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for the primary key (if present in incoming values). |
|
1698 | + * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
|
1699 | + * |
|
1700 | + * @param array $props_n_values incoming array of properties and their values |
|
1701 | + * @param string $classname the classname of the child class |
|
1702 | + * @param null $timezone |
|
1703 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
1704 | + * date_format and the second value is the time format |
|
1705 | + * @return mixed (EE_Base_Class|bool) |
|
1706 | + * @throws \EE_Error |
|
1707 | + */ |
|
1708 | + protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
1709 | + { |
|
1710 | + $existing = null; |
|
1711 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1712 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1713 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
1714 | + && ! empty($props_n_values[$primary_id_ref]) |
|
1715 | + ) { |
|
1716 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1717 | + $props_n_values[$primary_id_ref] |
|
1718 | + ); |
|
1719 | + } |
|
1720 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1721 | + //no primary key on this model, but there's still a matching item in the DB |
|
1722 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
1723 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
1724 | + ); |
|
1725 | + } |
|
1726 | + if ($existing) { |
|
1727 | + //set date formats if present before setting values |
|
1728 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
1729 | + $existing->set_date_format($date_formats[0]); |
|
1730 | + $existing->set_time_format($date_formats[1]); |
|
1731 | + } else { |
|
1732 | + //set default formats for date and time |
|
1733 | + $existing->set_date_format(get_option('date_format')); |
|
1734 | + $existing->set_time_format(get_option('time_format')); |
|
1735 | + } |
|
1736 | + foreach ($props_n_values as $property => $field_value) { |
|
1737 | + $existing->set($property, $field_value); |
|
1738 | + } |
|
1739 | + return $existing; |
|
1740 | + } else { |
|
1741 | + return false; |
|
1742 | + } |
|
1743 | + } |
|
1744 | + |
|
1745 | + |
|
1746 | + |
|
1747 | + /** |
|
1748 | + * Gets the EEM_*_Model for this class |
|
1749 | + * |
|
1750 | + * @access public now, as this is more convenient |
|
1751 | + * @param $classname |
|
1752 | + * @param null $timezone |
|
1753 | + * @throws EE_Error |
|
1754 | + * @return EEM_Base |
|
1755 | + */ |
|
1756 | + protected static function _get_model($classname, $timezone = null) |
|
1757 | + { |
|
1758 | + //find model for this class |
|
1759 | + if ( ! $classname) { |
|
1760 | + throw new EE_Error( |
|
1761 | + sprintf( |
|
1762 | + __( |
|
1763 | + "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
1764 | + "event_espresso" |
|
1765 | + ), |
|
1766 | + $classname |
|
1767 | + ) |
|
1768 | + ); |
|
1769 | + } |
|
1770 | + $modelName = self::_get_model_classname($classname); |
|
1771 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1772 | + } |
|
1773 | + |
|
1774 | + |
|
1775 | + |
|
1776 | + /** |
|
1777 | + * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
1778 | + * |
|
1779 | + * @param string $model_classname |
|
1780 | + * @param null $timezone |
|
1781 | + * @return EEM_Base |
|
1782 | + */ |
|
1783 | + protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
1784 | + { |
|
1785 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1786 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1787 | + $model->set_timezone($timezone); |
|
1788 | + return $model; |
|
1789 | + } |
|
1790 | + |
|
1791 | + |
|
1792 | + |
|
1793 | + /** |
|
1794 | + * If a model name is provided (eg Registration), gets the model classname for that model. |
|
1795 | + * Also works if a model class's classname is provided (eg EE_Registration). |
|
1796 | + * |
|
1797 | + * @param null $model_name |
|
1798 | + * @return string like EEM_Attendee |
|
1799 | + */ |
|
1800 | + private static function _get_model_classname($model_name = null) |
|
1801 | + { |
|
1802 | + if (strpos($model_name, "EE_") === 0) { |
|
1803 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1804 | + } else { |
|
1805 | + $model_classname = "EEM_" . $model_name; |
|
1806 | + } |
|
1807 | + return $model_classname; |
|
1808 | + } |
|
1809 | + |
|
1810 | + |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * returns the name of the primary key attribute |
|
1814 | + * |
|
1815 | + * @param null $classname |
|
1816 | + * @throws EE_Error |
|
1817 | + * @return string |
|
1818 | + */ |
|
1819 | + protected static function _get_primary_key_name($classname = null) |
|
1820 | + { |
|
1821 | + if ( ! $classname) { |
|
1822 | + throw new EE_Error( |
|
1823 | + sprintf( |
|
1824 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
1825 | + $classname |
|
1826 | + ) |
|
1827 | + ); |
|
1828 | + } |
|
1829 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1830 | + } |
|
1831 | + |
|
1832 | + |
|
1833 | + |
|
1834 | + /** |
|
1835 | + * Gets the value of the primary key. |
|
1836 | + * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
1837 | + * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value is. |
|
1838 | + * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
1839 | + * |
|
1840 | + * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
1841 | + * @throws \EE_Error |
|
1842 | + */ |
|
1843 | + public function ID() |
|
1844 | + { |
|
1845 | + //now that we know the name of the variable, use a variable variable to get its value and return its |
|
1846 | + if ($this->get_model()->has_primary_key_field()) { |
|
1847 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1848 | + } else { |
|
1849 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1850 | + } |
|
1851 | + } |
|
1852 | + |
|
1853 | + |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current model is related |
|
1857 | + * to a group of events, the $relationName should be 'Event', and should be a key in the EE Model's $_model_relations array. |
|
1858 | + * If this model object doesn't exist in the DB, just caches the related thing |
|
1859 | + * |
|
1860 | + * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
1861 | + * @param string $relationName eg 'Events','Question',etc. |
|
1862 | + * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
|
1863 | + * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added. However, keep in mind that the columns (keys) given must match |
|
1864 | + * a column on the JOIN table and currently only the HABTM models accept these additional conditions. Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
1865 | + * then a NEW row is created in the join table. |
|
1866 | + * @param null $cache_id |
|
1867 | + * @throws EE_Error |
|
1868 | + * @return EE_Base_Class the object the relation was added to |
|
1869 | + */ |
|
1870 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = null) |
|
1871 | + { |
|
1872 | + //if this thing exists in the DB, save the relation to the DB |
|
1873 | + if ($this->ID()) { |
|
1874 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1875 | + //clear cache so future get_many_related and get_first_related() return new results. |
|
1876 | + $this->clear_cache($relationName, $otherObject, true); |
|
1877 | + if ($otherObject instanceof EE_Base_Class) { |
|
1878 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1879 | + } |
|
1880 | + } else { |
|
1881 | + //this thing doesn't exist in the DB, so just cache it |
|
1882 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1883 | + throw new EE_Error(sprintf( |
|
1884 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1885 | + $otherObjectModelObjectOrID, |
|
1886 | + get_class($this) |
|
1887 | + )); |
|
1888 | + } else { |
|
1889 | + $otherObject = $otherObjectModelObjectOrID; |
|
1890 | + } |
|
1891 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1892 | + } |
|
1893 | + if ($otherObject instanceof EE_Base_Class) { |
|
1894 | + //fix the reciprocal relation too |
|
1895 | + if ($otherObject->ID()) { |
|
1896 | + //its saved so assumed relations exist in the DB, so we can just |
|
1897 | + //clear the cache so future queries use the updated info in the DB |
|
1898 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1899 | + } else { |
|
1900 | + //it's not saved, so it caches relations like this |
|
1901 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1902 | + } |
|
1903 | + } |
|
1904 | + return $otherObject; |
|
1905 | + } |
|
1906 | + |
|
1907 | + |
|
1908 | + |
|
1909 | + /** |
|
1910 | + * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current model is related |
|
1911 | + * to a group of events, the $relationName should be 'Events', and should be a key in the EE Model's $_model_relations array. |
|
1912 | + * If this model object doesn't exist in the DB, just removes the related thing from the cache |
|
1913 | + * |
|
1914 | + * @param mixed $otherObjectModelObjectOrID |
|
1915 | + * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved to the DB yet |
|
1916 | + * @param string $relationName |
|
1917 | + * @param array $where_query |
|
1918 | + * You can optionally include an array of key=>value pairs that allow you to further constrict the relation to being added. |
|
1919 | + * However, keep in mind that the columns (keys) given must match a column on the JOIN table |
|
1920 | + * and currently only the HABTM models accept these additional conditions. |
|
1921 | + * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
|
1922 | + * @return EE_Base_Class the relation was removed from |
|
1923 | + * @throws \EE_Error |
|
1924 | + */ |
|
1925 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
1926 | + { |
|
1927 | + if ($this->ID()) { |
|
1928 | + //if this exists in the DB, save the relation change to the DB too |
|
1929 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1930 | + $this->clear_cache($relationName, $otherObject); |
|
1931 | + } else { |
|
1932 | + //this doesn't exist in the DB, just remove it from the cache |
|
1933 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1934 | + } |
|
1935 | + if ($otherObject instanceof EE_Base_Class) { |
|
1936 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1937 | + } |
|
1938 | + return $otherObject; |
|
1939 | + } |
|
1940 | + |
|
1941 | + |
|
1942 | + |
|
1943 | + /** |
|
1944 | + * Removes ALL the related things for the $relationName. |
|
1945 | + * |
|
1946 | + * @param string $relationName |
|
1947 | + * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
1948 | + * @return EE_Base_Class |
|
1949 | + * @throws \EE_Error |
|
1950 | + */ |
|
1951 | + public function _remove_relations($relationName, $where_query_params = array()) |
|
1952 | + { |
|
1953 | + if ($this->ID()) { |
|
1954 | + //if this exists in the DB, save the relation change to the DB too |
|
1955 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1956 | + $this->clear_cache($relationName, null, true); |
|
1957 | + } else { |
|
1958 | + //this doesn't exist in the DB, just remove it from the cache |
|
1959 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1960 | + } |
|
1961 | + if (is_array($otherObjects)) { |
|
1962 | + foreach ($otherObjects as $otherObject) { |
|
1963 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1964 | + } |
|
1965 | + } |
|
1966 | + return $otherObjects; |
|
1967 | + } |
|
1968 | + |
|
1969 | + |
|
1970 | + |
|
1971 | + /** |
|
1972 | + * Gets all the related model objects of the specified type. Eg, if the current class if |
|
1973 | + * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
1974 | + * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
1975 | + * because we want to get even deleted items etc. |
|
1976 | + * |
|
1977 | + * @param string $relationName key in the model's _model_relations array |
|
1978 | + * @param array $query_params like EEM_Base::get_all |
|
1979 | + * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
1980 | + * @throws \EE_Error |
|
1981 | + * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
|
1982 | + */ |
|
1983 | + public function get_many_related($relationName, $query_params = array()) |
|
1984 | + { |
|
1985 | + if ($this->ID()) { |
|
1986 | + //this exists in the DB, so get the related things from either the cache or the DB |
|
1987 | + //if there are query parameters, forget about caching the related model objects. |
|
1988 | + if ($query_params) { |
|
1989 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
1990 | + } else { |
|
1991 | + //did we already cache the result of this query? |
|
1992 | + $cached_results = $this->get_all_from_cache($relationName); |
|
1993 | + if ( ! $cached_results) { |
|
1994 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
1995 | + //if no query parameters were passed, then we got all the related model objects |
|
1996 | + //for that relation. We can cache them then. |
|
1997 | + foreach ($related_model_objects as $related_model_object) { |
|
1998 | + $this->cache($relationName, $related_model_object); |
|
1999 | + } |
|
2000 | + } else { |
|
2001 | + $related_model_objects = $cached_results; |
|
2002 | + } |
|
2003 | + } |
|
2004 | + } else { |
|
2005 | + //this doesn't exist in the DB, so just get the related things from the cache |
|
2006 | + $related_model_objects = $this->get_all_from_cache($relationName); |
|
2007 | + } |
|
2008 | + return $related_model_objects; |
|
2009 | + } |
|
2010 | + |
|
2011 | + |
|
2012 | + |
|
2013 | + /** |
|
2014 | + * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
2015 | + * unless otherwise specified in the $query_params |
|
2016 | + * |
|
2017 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
2018 | + * @param array $query_params like EEM_Base::get_all's |
|
2019 | + * @param string $field_to_count name of field to count by. By default, uses primary key |
|
2020 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
|
2021 | + * @return int |
|
2022 | + */ |
|
2023 | + public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
2024 | + { |
|
2025 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
2026 | + } |
|
2027 | + |
|
2028 | + |
|
2029 | + |
|
2030 | + /** |
|
2031 | + * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
2032 | + * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
2033 | + * |
|
2034 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
2035 | + * @param array $query_params like EEM_Base::get_all's |
|
2036 | + * @param string $field_to_sum name of field to count by. |
|
2037 | + * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
|
2038 | + * @return int |
|
2039 | + */ |
|
2040 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
2041 | + { |
|
2042 | + return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
2043 | + } |
|
2044 | + |
|
2045 | + |
|
2046 | + |
|
2047 | + /** |
|
2048 | + * Gets the first (ie, one) related model object of the specified type. |
|
2049 | + * |
|
2050 | + * @param string $relationName key in the model's _model_relations array |
|
2051 | + * @param array $query_params like EEM_Base::get_all |
|
2052 | + * @return EE_Base_Class (not an array, a single object) |
|
2053 | + * @throws \EE_Error |
|
2054 | + */ |
|
2055 | + public function get_first_related($relationName, $query_params = array()) |
|
2056 | + { |
|
2057 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
2058 | + //if they've provided some query parameters, don't bother trying to cache the result |
|
2059 | + //also make sure we're not caching the result of get_first_related |
|
2060 | + //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
2061 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2062 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2063 | + } else { |
|
2064 | + //first, check if we've already cached the result of this query |
|
2065 | + $cached_result = $this->get_one_from_cache($relationName); |
|
2066 | + if ( ! $cached_result) { |
|
2067 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2068 | + $this->cache($relationName, $related_model_object); |
|
2069 | + } else { |
|
2070 | + $related_model_object = $cached_result; |
|
2071 | + } |
|
2072 | + } |
|
2073 | + } else { |
|
2074 | + $related_model_object = null; |
|
2075 | + //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
2076 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
2077 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
2078 | + } |
|
2079 | + //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
|
2080 | + if ( ! $related_model_object) { |
|
2081 | + $related_model_object = $this->get_one_from_cache($relationName); |
|
2082 | + } |
|
2083 | + } |
|
2084 | + return $related_model_object; |
|
2085 | + } |
|
2086 | + |
|
2087 | + |
|
2088 | + |
|
2089 | + /** |
|
2090 | + * Does a delete on all related objects of type $relationName and removes |
|
2091 | + * the current model object's relation to them. If they can't be deleted (because |
|
2092 | + * of blocking related model objects) does nothing. If the related model objects are |
|
2093 | + * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
2094 | + * If this model object doesn't exist yet in the DB, just removes its related things |
|
2095 | + * |
|
2096 | + * @param string $relationName |
|
2097 | + * @param array $query_params like EEM_Base::get_all's |
|
2098 | + * @return int how many deleted |
|
2099 | + * @throws \EE_Error |
|
2100 | + */ |
|
2101 | + public function delete_related($relationName, $query_params = array()) |
|
2102 | + { |
|
2103 | + if ($this->ID()) { |
|
2104 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
2105 | + } else { |
|
2106 | + $count = count($this->get_all_from_cache($relationName)); |
|
2107 | + $this->clear_cache($relationName, null, true); |
|
2108 | + } |
|
2109 | + return $count; |
|
2110 | + } |
|
2111 | + |
|
2112 | + |
|
2113 | + |
|
2114 | + /** |
|
2115 | + * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
2116 | + * the current model object's relation to them. If they can't be deleted (because |
|
2117 | + * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
2118 | + * If the related thing isn't a soft-deletable model object, this function is identical |
|
2119 | + * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
2120 | + * |
|
2121 | + * @param string $relationName |
|
2122 | + * @param array $query_params like EEM_Base::get_all's |
|
2123 | + * @return int how many deleted (including those soft deleted) |
|
2124 | + * @throws \EE_Error |
|
2125 | + */ |
|
2126 | + public function delete_related_permanently($relationName, $query_params = array()) |
|
2127 | + { |
|
2128 | + if ($this->ID()) { |
|
2129 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
2130 | + } else { |
|
2131 | + $count = count($this->get_all_from_cache($relationName)); |
|
2132 | + } |
|
2133 | + $this->clear_cache($relationName, null, true); |
|
2134 | + return $count; |
|
2135 | + } |
|
2136 | + |
|
2137 | + |
|
2138 | + |
|
2139 | + /** |
|
2140 | + * is_set |
|
2141 | + * Just a simple utility function children can use for checking if property exists |
|
2142 | + * |
|
2143 | + * @access public |
|
2144 | + * @param string $field_name property to check |
|
2145 | + * @return bool TRUE if existing,FALSE if not. |
|
2146 | + */ |
|
2147 | + public function is_set($field_name) |
|
2148 | + { |
|
2149 | + return isset($this->_fields[$field_name]); |
|
2150 | + } |
|
2151 | + |
|
2152 | + |
|
2153 | + |
|
2154 | + /** |
|
2155 | + * Just a simple utility function children can use for checking if property (or properties) exists and throwing an EE_Error exception if they don't |
|
2156 | + * |
|
2157 | + * @param mixed (string|array) $properties properties to check |
|
2158 | + * @throws EE_Error |
|
2159 | + * @return bool TRUE if existing, throw EE_Error if not. |
|
2160 | + */ |
|
2161 | + protected function _property_exists($properties) |
|
2162 | + { |
|
2163 | + foreach ((array)$properties as $property_name) { |
|
2164 | + //first make sure this property exists |
|
2165 | + if ( ! $this->_fields[$property_name]) { |
|
2166 | + throw new EE_Error( |
|
2167 | + sprintf( |
|
2168 | + __( |
|
2169 | + 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
2170 | + 'event_espresso' |
|
2171 | + ), |
|
2172 | + $property_name |
|
2173 | + ) |
|
2174 | + ); |
|
2175 | + } |
|
2176 | + } |
|
2177 | + return true; |
|
2178 | + } |
|
2179 | + |
|
2180 | + |
|
2181 | + |
|
2182 | + /** |
|
2183 | + * This simply returns an array of model fields for this object |
|
2184 | + * |
|
2185 | + * @return array |
|
2186 | + * @throws \EE_Error |
|
2187 | + */ |
|
2188 | + public function model_field_array() |
|
2189 | + { |
|
2190 | + $fields = $this->get_model()->field_settings(false); |
|
2191 | + $properties = array(); |
|
2192 | + //remove prepended underscore |
|
2193 | + foreach ($fields as $field_name => $settings) { |
|
2194 | + $properties[$field_name] = $this->get($field_name); |
|
2195 | + } |
|
2196 | + return $properties; |
|
2197 | + } |
|
2198 | + |
|
2199 | + |
|
2200 | + |
|
2201 | + /** |
|
2202 | + * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
2203 | + * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called (http://www.garfieldtech.com/blog/php-magic-call) |
|
2204 | + * and passed the method's name and arguments. |
|
2205 | + * Instead of requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that happen?) |
|
2206 | + * they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, filters_hook_espresso__EE_Answer__my_great_function) |
|
2207 | + * and accepts 2 arguments: the object on which the function was called, and an array of the original arguments passed to the function. Whatever their callback function returns will be returned by this function. |
|
2208 | + * Example: in functions.php (or in a plugin): |
|
2209 | + * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); |
|
2210 | + * function my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
2211 | + * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
2212 | + * return $previousReturnValue.$returnString; |
|
2213 | + * } |
|
2214 | + * require('EE_Answer.class.php'); |
|
2215 | + * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
2216 | + * echo $answer->my_callback('monkeys',100); |
|
2217 | + * //will output "you called my_callback! and passed args:monkeys,100" |
|
2218 | + * |
|
2219 | + * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
2220 | + * @param array $args array of original arguments passed to the function |
|
2221 | + * @throws EE_Error |
|
2222 | + * @return mixed whatever the plugin which calls add_filter decides |
|
2223 | + */ |
|
2224 | + public function __call($methodName, $args) |
|
2225 | + { |
|
2226 | + $className = get_class($this); |
|
2227 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
2228 | + if ( ! has_filter($tagName)) { |
|
2229 | + throw new EE_Error( |
|
2230 | + sprintf( |
|
2231 | + __( |
|
2232 | + "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", |
|
2233 | + "event_espresso" |
|
2234 | + ), |
|
2235 | + $methodName, |
|
2236 | + $className, |
|
2237 | + $tagName |
|
2238 | + ) |
|
2239 | + ); |
|
2240 | + } |
|
2241 | + return apply_filters($tagName, null, $this, $args); |
|
2242 | + } |
|
2243 | + |
|
2244 | + |
|
2245 | + |
|
2246 | + /** |
|
2247 | + * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
2248 | + * A $previous_value can be specified in case there are many meta rows with the same key |
|
2249 | + * |
|
2250 | + * @param string $meta_key |
|
2251 | + * @param string $meta_value |
|
2252 | + * @param string $previous_value |
|
2253 | + * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
2254 | + * @throws \EE_Error |
|
2255 | + * NOTE: if the values haven't changed, returns 0 |
|
2256 | + */ |
|
2257 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
2258 | + { |
|
2259 | + $query_params = array( |
|
2260 | + array( |
|
2261 | + 'EXM_key' => $meta_key, |
|
2262 | + 'OBJ_ID' => $this->ID(), |
|
2263 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2264 | + ), |
|
2265 | + ); |
|
2266 | + if ($previous_value !== null) { |
|
2267 | + $query_params[0]['EXM_value'] = $meta_value; |
|
2268 | + } |
|
2269 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
2270 | + if ( ! $existing_rows_like_that) { |
|
2271 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
2272 | + } else { |
|
2273 | + foreach ($existing_rows_like_that as $existing_row) { |
|
2274 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
2275 | + } |
|
2276 | + return count($existing_rows_like_that); |
|
2277 | + } |
|
2278 | + } |
|
2279 | + |
|
2280 | + |
|
2281 | + |
|
2282 | + /** |
|
2283 | + * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
2284 | + * no other extra meta for this model object have the same key. Returns TRUE if the |
|
2285 | + * extra meta row was entered, false if not |
|
2286 | + * |
|
2287 | + * @param string $meta_key |
|
2288 | + * @param string $meta_value |
|
2289 | + * @param boolean $unique |
|
2290 | + * @return boolean |
|
2291 | + * @throws \EE_Error |
|
2292 | + */ |
|
2293 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
2294 | + { |
|
2295 | + if ($unique) { |
|
2296 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
2297 | + array( |
|
2298 | + array( |
|
2299 | + 'EXM_key' => $meta_key, |
|
2300 | + 'OBJ_ID' => $this->ID(), |
|
2301 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2302 | + ), |
|
2303 | + ) |
|
2304 | + ); |
|
2305 | + if ($existing_extra_meta) { |
|
2306 | + return false; |
|
2307 | + } |
|
2308 | + } |
|
2309 | + $new_extra_meta = EE_Extra_Meta::new_instance( |
|
2310 | + array( |
|
2311 | + 'EXM_key' => $meta_key, |
|
2312 | + 'EXM_value' => $meta_value, |
|
2313 | + 'OBJ_ID' => $this->ID(), |
|
2314 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2315 | + ) |
|
2316 | + ); |
|
2317 | + $new_extra_meta->save(); |
|
2318 | + return true; |
|
2319 | + } |
|
2320 | + |
|
2321 | + |
|
2322 | + |
|
2323 | + /** |
|
2324 | + * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
2325 | + * is specified, only deletes extra meta records with that value. |
|
2326 | + * |
|
2327 | + * @param string $meta_key |
|
2328 | + * @param string $meta_value |
|
2329 | + * @return int number of extra meta rows deleted |
|
2330 | + * @throws \EE_Error |
|
2331 | + */ |
|
2332 | + public function delete_extra_meta($meta_key, $meta_value = null) |
|
2333 | + { |
|
2334 | + $query_params = array( |
|
2335 | + array( |
|
2336 | + 'EXM_key' => $meta_key, |
|
2337 | + 'OBJ_ID' => $this->ID(), |
|
2338 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
2339 | + ), |
|
2340 | + ); |
|
2341 | + if ($meta_value !== null) { |
|
2342 | + $query_params[0]['EXM_value'] = $meta_value; |
|
2343 | + } |
|
2344 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
2345 | + } |
|
2346 | + |
|
2347 | + |
|
2348 | + |
|
2349 | + /** |
|
2350 | + * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
2351 | + * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
2352 | + * You can specify $default is case you haven't found the extra meta |
|
2353 | + * |
|
2354 | + * @param string $meta_key |
|
2355 | + * @param boolean $single |
|
2356 | + * @param mixed $default if we don't find anything, what should we return? |
|
2357 | + * @return mixed single value if $single; array if ! $single |
|
2358 | + * @throws \EE_Error |
|
2359 | + */ |
|
2360 | + public function get_extra_meta($meta_key, $single = false, $default = null) |
|
2361 | + { |
|
2362 | + if ($single) { |
|
2363 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
2364 | + if ($result instanceof EE_Extra_Meta) { |
|
2365 | + return $result->value(); |
|
2366 | + } else { |
|
2367 | + return $default; |
|
2368 | + } |
|
2369 | + } else { |
|
2370 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
2371 | + if ($results) { |
|
2372 | + $values = array(); |
|
2373 | + foreach ($results as $result) { |
|
2374 | + if ($result instanceof EE_Extra_Meta) { |
|
2375 | + $values[$result->ID()] = $result->value(); |
|
2376 | + } |
|
2377 | + } |
|
2378 | + return $values; |
|
2379 | + } else { |
|
2380 | + return $default; |
|
2381 | + } |
|
2382 | + } |
|
2383 | + } |
|
2384 | + |
|
2385 | + |
|
2386 | + |
|
2387 | + /** |
|
2388 | + * Returns a simple array of all the extra meta associated with this model object. |
|
2389 | + * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
2390 | + * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
2391 | + * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
2392 | + * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
2393 | + * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
2394 | + * finally the extra meta's value as each sub-value. (eg array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
2395 | + * |
|
2396 | + * @param boolean $one_of_each_key |
|
2397 | + * @return array |
|
2398 | + * @throws \EE_Error |
|
2399 | + */ |
|
2400 | + public function all_extra_meta_array($one_of_each_key = true) |
|
2401 | + { |
|
2402 | + $return_array = array(); |
|
2403 | + if ($one_of_each_key) { |
|
2404 | + $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
2405 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2406 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2407 | + $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
2408 | + } |
|
2409 | + } |
|
2410 | + } else { |
|
2411 | + $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
2412 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2413 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2414 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2415 | + $return_array[$extra_meta_obj->key()] = array(); |
|
2416 | + } |
|
2417 | + $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
2418 | + } |
|
2419 | + } |
|
2420 | + } |
|
2421 | + return $return_array; |
|
2422 | + } |
|
2423 | + |
|
2424 | + |
|
2425 | + |
|
2426 | + /** |
|
2427 | + * Gets a pretty nice displayable nice for this model object. Often overridden |
|
2428 | + * |
|
2429 | + * @return string |
|
2430 | + * @throws \EE_Error |
|
2431 | + */ |
|
2432 | + public function name() |
|
2433 | + { |
|
2434 | + //find a field that's not a text field |
|
2435 | + $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
2436 | + if ($field_we_can_use) { |
|
2437 | + return $this->get($field_we_can_use->get_name()); |
|
2438 | + } else { |
|
2439 | + $first_few_properties = $this->model_field_array(); |
|
2440 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2441 | + $name_parts = array(); |
|
2442 | + foreach ($first_few_properties as $name => $value) { |
|
2443 | + $name_parts[] = "$name:$value"; |
|
2444 | + } |
|
2445 | + return implode(",", $name_parts); |
|
2446 | + } |
|
2447 | + } |
|
2448 | + |
|
2449 | + |
|
2450 | + |
|
2451 | + /** |
|
2452 | + * in_entity_map |
|
2453 | + * Checks if this model object has been proven to already be in the entity map |
|
2454 | + * |
|
2455 | + * @return boolean |
|
2456 | + * @throws \EE_Error |
|
2457 | + */ |
|
2458 | + public function in_entity_map() |
|
2459 | + { |
|
2460 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2461 | + //well, if we looked, did we find it in the entity map? |
|
2462 | + return true; |
|
2463 | + } else { |
|
2464 | + return false; |
|
2465 | + } |
|
2466 | + } |
|
2467 | + |
|
2468 | + |
|
2469 | + |
|
2470 | + /** |
|
2471 | + * refresh_from_db |
|
2472 | + * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
2473 | + * |
|
2474 | + * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
2475 | + * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
2476 | + */ |
|
2477 | + public function refresh_from_db() |
|
2478 | + { |
|
2479 | + if ($this->ID() && $this->in_entity_map()) { |
|
2480 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2481 | + } else { |
|
2482 | + //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
2483 | + //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
2484 | + //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
2485 | + //absolutely nothing in it for this ID |
|
2486 | + if (WP_DEBUG) { |
|
2487 | + throw new EE_Error( |
|
2488 | + sprintf( |
|
2489 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', |
|
2490 | + 'event_espresso'), |
|
2491 | + $this->ID(), |
|
2492 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
2493 | + get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
2494 | + ) |
|
2495 | + ); |
|
2496 | + } |
|
2497 | + } |
|
2498 | + } |
|
2499 | + |
|
2500 | + |
|
2501 | + |
|
2502 | + /** |
|
2503 | + * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
2504 | + * (probably a bad assumption they have made, oh well) |
|
2505 | + * |
|
2506 | + * @return string |
|
2507 | + */ |
|
2508 | + public function __toString() |
|
2509 | + { |
|
2510 | + try { |
|
2511 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2512 | + } catch (Exception $e) { |
|
2513 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
2514 | + return ''; |
|
2515 | + } |
|
2516 | + } |
|
2517 | + |
|
2518 | + |
|
2519 | + |
|
2520 | + /** |
|
2521 | + * Clear related model objects if they're already in the DB, because otherwise when we |
|
2522 | + * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
2523 | + * This means if we have made changes to those related model objects, and want to unserialize |
|
2524 | + * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
2525 | + * Instead, those related model objects should be directly serialized and stored. |
|
2526 | + * Eg, the following won't work: |
|
2527 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
2528 | + * $att = $reg->attendee(); |
|
2529 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
2530 | + * update_option( 'my_option', serialize( $reg ) ); |
|
2531 | + * //END REQUEST |
|
2532 | + * //START NEXT REQUEST |
|
2533 | + * $reg = get_option( 'my_option' ); |
|
2534 | + * $reg->attendee()->save(); |
|
2535 | + * And would need to be replace with: |
|
2536 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
2537 | + * $att = $reg->attendee(); |
|
2538 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
2539 | + * update_option( 'my_option', serialize( $reg ) ); |
|
2540 | + * //END REQUEST |
|
2541 | + * //START NEXT REQUEST |
|
2542 | + * $att = get_option( 'my_option' ); |
|
2543 | + * $att->save(); |
|
2544 | + * |
|
2545 | + * @return array |
|
2546 | + * @throws \EE_Error |
|
2547 | + */ |
|
2548 | + public function __sleep() |
|
2549 | + { |
|
2550 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2551 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2552 | + $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2553 | + if ( |
|
2554 | + $this->get_one_from_cache($relation_name) instanceof $classname |
|
2555 | + && $this->get_one_from_cache($relation_name)->ID() |
|
2556 | + ) { |
|
2557 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2558 | + } |
|
2559 | + } |
|
2560 | + } |
|
2561 | + $this->_props_n_values_provided_in_constructor = array(); |
|
2562 | + return array_keys(get_object_vars($this)); |
|
2563 | + } |
|
2564 | + |
|
2565 | + |
|
2566 | + |
|
2567 | + /** |
|
2568 | + * restore _props_n_values_provided_in_constructor |
|
2569 | + * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
2570 | + * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
2571 | + * At best, you would only be able to detect if state change has occurred during THIS request. |
|
2572 | + */ |
|
2573 | + public function __wakeup() |
|
2574 | + { |
|
2575 | + $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
2576 | + } |
|
2577 | 2577 | |
2578 | 2578 | |
2579 | 2579 |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
135 | 135 | } else { |
136 | 136 | //set default formats for date and time |
137 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
138 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
137 | + $this->_dt_frmt = (string) get_option('date_format', 'Y-m-d'); |
|
138 | + $this->_tm_frmt = (string) get_option('time_format', 'g:i a'); |
|
139 | 139 | } |
140 | 140 | //if db model is instantiating |
141 | 141 | if ($bydb) { |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function get_format($full = true) |
445 | 445 | { |
446 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
446 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | //verify the field exists |
546 | 546 | $this->get_model()->field_settings_for($fieldname); |
547 | 547 | $cache_type = $pretty ? 'pretty' : 'standard'; |
548 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
548 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
549 | 549 | if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
550 | 550 | return $this->_cached_properties[$fieldname][$cache_type]; |
551 | 551 | } |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') |
749 | 749 | { |
750 | 750 | // verify that incoming object is of the correct type |
751 | - $obj_class = 'EE_' . $relationName; |
|
751 | + $obj_class = 'EE_'.$relationName; |
|
752 | 752 | if ($newly_saved_object instanceof $obj_class) { |
753 | 753 | /* @type EE_Base_Class $newly_saved_object */ |
754 | 754 | // now get the type of relation |
@@ -1216,7 +1216,7 @@ discard block |
||
1216 | 1216 | */ |
1217 | 1217 | public function get_i18n_datetime($field_name, $format = '') |
1218 | 1218 | { |
1219 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1219 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
1220 | 1220 | return date_i18n( |
1221 | 1221 | $format, |
1222 | 1222 | EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
@@ -1340,8 +1340,8 @@ discard block |
||
1340 | 1340 | } |
1341 | 1341 | $original_timezone = $this->_timezone; |
1342 | 1342 | $this->set_timezone($timezone); |
1343 | - $fn = (array)$field_name; |
|
1344 | - $args = array_merge($fn, (array)$args); |
|
1343 | + $fn = (array) $field_name; |
|
1344 | + $args = array_merge($fn, (array) $args); |
|
1345 | 1345 | if ( ! method_exists($this, $callback)) { |
1346 | 1346 | throw new EE_Error( |
1347 | 1347 | sprintf( |
@@ -1353,8 +1353,8 @@ discard block |
||
1353 | 1353 | ) |
1354 | 1354 | ); |
1355 | 1355 | } |
1356 | - $args = (array)$args; |
|
1357 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
1356 | + $args = (array) $args; |
|
1357 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1358 | 1358 | $this->set_timezone($original_timezone); |
1359 | 1359 | return $return; |
1360 | 1360 | } |
@@ -1487,7 +1487,7 @@ discard block |
||
1487 | 1487 | * @param array $set_cols_n_values |
1488 | 1488 | * @param EE_Base_Class $model_object |
1489 | 1489 | */ |
1490 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1490 | + $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1491 | 1491 | //set attributes as provided in $set_cols_n_values |
1492 | 1492 | foreach ($set_cols_n_values as $column => $value) { |
1493 | 1493 | $this->set($column, $value); |
@@ -1540,8 +1540,8 @@ discard block |
||
1540 | 1540 | __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', |
1541 | 1541 | 'event_espresso'), |
1542 | 1542 | get_class($this), |
1543 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
1544 | - get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
1543 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1544 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1545 | 1545 | '<br />' |
1546 | 1546 | ) |
1547 | 1547 | ); |
@@ -1802,7 +1802,7 @@ discard block |
||
1802 | 1802 | if (strpos($model_name, "EE_") === 0) { |
1803 | 1803 | $model_classname = str_replace("EE_", "EEM_", $model_name); |
1804 | 1804 | } else { |
1805 | - $model_classname = "EEM_" . $model_name; |
|
1805 | + $model_classname = "EEM_".$model_name; |
|
1806 | 1806 | } |
1807 | 1807 | return $model_classname; |
1808 | 1808 | } |
@@ -2160,7 +2160,7 @@ discard block |
||
2160 | 2160 | */ |
2161 | 2161 | protected function _property_exists($properties) |
2162 | 2162 | { |
2163 | - foreach ((array)$properties as $property_name) { |
|
2163 | + foreach ((array) $properties as $property_name) { |
|
2164 | 2164 | //first make sure this property exists |
2165 | 2165 | if ( ! $this->_fields[$property_name]) { |
2166 | 2166 | throw new EE_Error( |
@@ -2489,8 +2489,8 @@ discard block |
||
2489 | 2489 | __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', |
2490 | 2490 | 'event_espresso'), |
2491 | 2491 | $this->ID(), |
2492 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
2493 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
2492 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
2493 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
2494 | 2494 | ) |
2495 | 2495 | ); |
2496 | 2496 | } |
@@ -2549,7 +2549,7 @@ discard block |
||
2549 | 2549 | { |
2550 | 2550 | foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
2551 | 2551 | if ($relation_obj instanceof EE_Belongs_To_Relation) { |
2552 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2552 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
2553 | 2553 | if ( |
2554 | 2554 | $this->get_one_from_cache($relation_name) instanceof $classname |
2555 | 2555 | && $this->get_one_from_cache($relation_name)->ID() |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param string $min_core_version |
62 | 62 | * @return string always like '4.3.0.rc.000' |
63 | 63 | */ |
64 | - protected static function _effective_version( $min_core_version ) { |
|
64 | + protected static function _effective_version($min_core_version) { |
|
65 | 65 | // versions: 4 . 3 . 1 . p . 123 |
66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
67 | - $version_parts = explode( '.', $min_core_version ); |
|
67 | + $version_parts = explode('.', $min_core_version); |
|
68 | 68 | //check they specified the micro version (after 2nd period) |
69 | - if ( ! isset( $version_parts[2] ) ) { |
|
69 | + if ( ! isset($version_parts[2])) { |
|
70 | 70 | $version_parts[2] = '0'; |
71 | 71 | } |
72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
74 | - if ( ! isset( $version_parts[3] ) ) { |
|
74 | + if ( ! isset($version_parts[3])) { |
|
75 | 75 | $version_parts[3] = 'dev'; |
76 | 76 | } |
77 | - if ( ! isset( $version_parts[4] ) ) { |
|
77 | + if ( ! isset($version_parts[4])) { |
|
78 | 78 | $version_parts[4] = '000'; |
79 | 79 | } |
80 | - return implode( '.', $version_parts ); |
|
80 | + return implode('.', $version_parts); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $actual_core_version = EVENT_ESPRESSO_VERSION |
95 | 95 | ) { |
96 | 96 | return version_compare( |
97 | - self::_effective_version( $actual_core_version ), |
|
98 | - self::_effective_version( $min_core_version ), |
|
97 | + self::_effective_version($actual_core_version), |
|
98 | + self::_effective_version($min_core_version), |
|
99 | 99 | '>=' |
100 | 100 | ); |
101 | 101 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @throws EE_Error |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public static function register( $addon_name = '', $setup_args = array() ) { |
|
220 | + public static function register($addon_name = '', $setup_args = array()) { |
|
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | 222 | \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
223 | 223 | // get class name for addon |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | // setup PUE |
228 | 228 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
229 | 229 | // does this addon work with this version of core or WordPress ? |
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
231 | 231 | return; |
232 | 232 | } |
233 | 233 | // register namespaces |
234 | 234 | \EE_Register_Addon::_setup_namespaces($addon_settings); |
235 | 235 | // check if this is an activation request |
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
236 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | 237 | // dont bother setting up the rest of the addon atm |
238 | 238 | return; |
239 | 239 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | } else { |
327 | 327 | $class_name = $setup_args['class_name']; |
328 | 328 | } |
329 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
329 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -344,105 +344,105 @@ discard block |
||
344 | 344 | 'class_name' => $class_name, |
345 | 345 | // the addon slug for use in URLs, etc |
346 | 346 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
347 | - ? (string)$setup_args['plugin_slug'] |
|
347 | + ? (string) $setup_args['plugin_slug'] |
|
348 | 348 | : '', |
349 | 349 | // page slug to be used when generating the "Settings" link on the WP plugin page |
350 | 350 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
351 | - ? (string)$setup_args['plugin_action_slug'] |
|
351 | + ? (string) $setup_args['plugin_action_slug'] |
|
352 | 352 | : '', |
353 | 353 | // the "software" version for the addon |
354 | 354 | 'version' => isset($setup_args['version']) |
355 | - ? (string)$setup_args['version'] |
|
355 | + ? (string) $setup_args['version'] |
|
356 | 356 | : '', |
357 | 357 | // the minimum version of EE Core that the addon will work with |
358 | 358 | 'min_core_version' => isset($setup_args['min_core_version']) |
359 | - ? (string)$setup_args['min_core_version'] |
|
359 | + ? (string) $setup_args['min_core_version'] |
|
360 | 360 | : '', |
361 | 361 | // the minimum version of WordPress that the addon will work with |
362 | 362 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
363 | - ? (string)$setup_args['min_wp_version'] |
|
363 | + ? (string) $setup_args['min_wp_version'] |
|
364 | 364 | : EE_MIN_WP_VER_REQUIRED, |
365 | 365 | // full server path to main file (file loaded directly by WP) |
366 | 366 | 'main_file_path' => isset($setup_args['main_file_path']) |
367 | - ? (string)$setup_args['main_file_path'] |
|
367 | + ? (string) $setup_args['main_file_path'] |
|
368 | 368 | : '', |
369 | 369 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
370 | 370 | 'admin_path' => isset($setup_args['admin_path']) |
371 | - ? (string)$setup_args['admin_path'] : '', |
|
371 | + ? (string) $setup_args['admin_path'] : '', |
|
372 | 372 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
373 | 373 | 'admin_callback' => isset($setup_args['admin_callback']) |
374 | - ? (string)$setup_args['admin_callback'] |
|
374 | + ? (string) $setup_args['admin_callback'] |
|
375 | 375 | : '', |
376 | 376 | // the section name for this addon's configuration settings section (defaults to "addons") |
377 | 377 | 'config_section' => isset($setup_args['config_section']) |
378 | - ? (string)$setup_args['config_section'] |
|
378 | + ? (string) $setup_args['config_section'] |
|
379 | 379 | : 'addons', |
380 | 380 | // the class name for this addon's configuration settings object |
381 | 381 | 'config_class' => isset($setup_args['config_class']) |
382 | - ? (string)$setup_args['config_class'] : '', |
|
382 | + ? (string) $setup_args['config_class'] : '', |
|
383 | 383 | //the name given to the config for this addons' configuration settings object (optional) |
384 | 384 | 'config_name' => isset($setup_args['config_name']) |
385 | - ? (string)$setup_args['config_name'] : '', |
|
385 | + ? (string) $setup_args['config_name'] : '', |
|
386 | 386 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
387 | 387 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
388 | - ? (array)$setup_args['autoloader_paths'] |
|
388 | + ? (array) $setup_args['autoloader_paths'] |
|
389 | 389 | : array(), |
390 | 390 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
391 | 391 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
392 | - ? (array)$setup_args['autoloader_folders'] |
|
392 | + ? (array) $setup_args['autoloader_folders'] |
|
393 | 393 | : array(), |
394 | 394 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
395 | 395 | 'dms_paths' => isset($setup_args['dms_paths']) |
396 | - ? (array)$setup_args['dms_paths'] |
|
396 | + ? (array) $setup_args['dms_paths'] |
|
397 | 397 | : array(), |
398 | 398 | // array of full server paths to any EED_Modules used by the addon |
399 | 399 | 'module_paths' => isset($setup_args['module_paths']) |
400 | - ? (array)$setup_args['module_paths'] |
|
400 | + ? (array) $setup_args['module_paths'] |
|
401 | 401 | : array(), |
402 | 402 | // array of full server paths to any EES_Shortcodes used by the addon |
403 | 403 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
404 | - ? (array)$setup_args['shortcode_paths'] |
|
404 | + ? (array) $setup_args['shortcode_paths'] |
|
405 | 405 | : array(), |
406 | 406 | // array of full server paths to any WP_Widgets used by the addon |
407 | 407 | 'widget_paths' => isset($setup_args['widget_paths']) |
408 | - ? (array)$setup_args['widget_paths'] |
|
408 | + ? (array) $setup_args['widget_paths'] |
|
409 | 409 | : array(), |
410 | 410 | // array of PUE options used by the addon |
411 | 411 | 'pue_options' => isset($setup_args['pue_options']) |
412 | - ? (array)$setup_args['pue_options'] |
|
412 | + ? (array) $setup_args['pue_options'] |
|
413 | 413 | : array(), |
414 | 414 | 'message_types' => isset($setup_args['message_types']) |
415 | - ? (array)$setup_args['message_types'] |
|
415 | + ? (array) $setup_args['message_types'] |
|
416 | 416 | : array(), |
417 | 417 | 'capabilities' => isset($setup_args['capabilities']) |
418 | - ? (array)$setup_args['capabilities'] |
|
418 | + ? (array) $setup_args['capabilities'] |
|
419 | 419 | : array(), |
420 | 420 | 'capability_maps' => isset($setup_args['capability_maps']) |
421 | - ? (array)$setup_args['capability_maps'] |
|
421 | + ? (array) $setup_args['capability_maps'] |
|
422 | 422 | : array(), |
423 | 423 | 'model_paths' => isset($setup_args['model_paths']) |
424 | - ? (array)$setup_args['model_paths'] |
|
424 | + ? (array) $setup_args['model_paths'] |
|
425 | 425 | : array(), |
426 | 426 | 'class_paths' => isset($setup_args['class_paths']) |
427 | - ? (array)$setup_args['class_paths'] |
|
427 | + ? (array) $setup_args['class_paths'] |
|
428 | 428 | : array(), |
429 | 429 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
430 | - ? (array)$setup_args['model_extension_paths'] |
|
430 | + ? (array) $setup_args['model_extension_paths'] |
|
431 | 431 | : array(), |
432 | 432 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
433 | - ? (array)$setup_args['class_extension_paths'] |
|
433 | + ? (array) $setup_args['class_extension_paths'] |
|
434 | 434 | : array(), |
435 | 435 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
436 | - ? (array)$setup_args['custom_post_types'] |
|
436 | + ? (array) $setup_args['custom_post_types'] |
|
437 | 437 | : array(), |
438 | 438 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
439 | - ? (array)$setup_args['custom_taxonomies'] |
|
439 | + ? (array) $setup_args['custom_taxonomies'] |
|
440 | 440 | : array(), |
441 | 441 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
442 | - ? (array)$setup_args['payment_method_paths'] |
|
442 | + ? (array) $setup_args['payment_method_paths'] |
|
443 | 443 | : array(), |
444 | 444 | 'default_terms' => isset($setup_args['default_terms']) |
445 | - ? (array)$setup_args['default_terms'] |
|
445 | + ? (array) $setup_args['default_terms'] |
|
446 | 446 | : array(), |
447 | 447 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
448 | 448 | // that can be used for adding upgrading/marketing info |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $setup_args['namespace']['FQNS'], |
455 | 455 | $setup_args['namespace']['DIR'] |
456 | 456 | ) |
457 | - ? (array)$setup_args['namespace'] |
|
457 | + ? (array) $setup_args['namespace'] |
|
458 | 458 | : array(), |
459 | 459 | ); |
460 | 460 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * @param array $addon_settings |
476 | 476 | * @return boolean |
477 | 477 | */ |
478 | - private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
|
478 | + private static function _addon_is_compatible($addon_name, array $addon_settings) { |
|
479 | 479 | global $wp_version; |
480 | 480 | $incompatibility_message = ''; |
481 | 481 | //check whether this addon version is compatible with EE core |
@@ -551,20 +551,20 @@ discard block |
||
551 | 551 | * @param array $setup_args |
552 | 552 | * @return void |
553 | 553 | */ |
554 | - private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
|
554 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) { |
|
555 | 555 | if ( ! empty($setup_args['pue_options'])) { |
556 | 556 | self::$_settings[$addon_name]['pue_options'] = array( |
557 | 557 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
558 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
559 | - : 'espresso_' . strtolower($class_name), |
|
558 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
559 | + : 'espresso_'.strtolower($class_name), |
|
560 | 560 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
561 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
561 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
562 | 562 | : plugin_basename($setup_args['main_file_path']), |
563 | 563 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
564 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
564 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
565 | 565 | : '24', |
566 | 566 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
567 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
567 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
568 | 568 | : false, |
569 | 569 | ); |
570 | 570 | add_action( |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * @param array $addon_settings |
607 | 607 | * @return bool |
608 | 608 | */ |
609 | - private static function _addon_activation( $addon_name, array $addon_settings ) { |
|
609 | + private static function _addon_activation($addon_name, array $addon_settings) { |
|
610 | 610 | // this is an activation request |
611 | 611 | if (did_action('activate_plugin')) { |
612 | 612 | //to find if THIS is the addon that was activated, |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | } |
664 | 664 | // setup autoloaders for folders |
665 | 665 | if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
666 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
666 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
667 | 667 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
668 | 668 | } |
669 | 669 | } |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | * @return void |
679 | 679 | * @throws \EE_Error |
680 | 680 | */ |
681 | - private static function _register_models_and_extensions( $addon_name ) { |
|
681 | + private static function _register_models_and_extensions($addon_name) { |
|
682 | 682 | // register new models |
683 | 683 | if ( |
684 | 684 | ! empty(self::$_settings[$addon_name]['model_paths']) |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | * @return void |
715 | 715 | * @throws \EE_Error |
716 | 716 | */ |
717 | - private static function _register_data_migration_scripts( $addon_name ) { |
|
717 | + private static function _register_data_migration_scripts($addon_name) { |
|
718 | 718 | // setup DMS |
719 | 719 | if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
720 | 720 | EE_Register_Data_Migration_Scripts::register( |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @return void |
731 | 731 | * @throws \EE_Error |
732 | 732 | */ |
733 | - private static function _register_config( $addon_name ) { |
|
733 | + private static function _register_config($addon_name) { |
|
734 | 734 | // if config_class is present let's register config. |
735 | 735 | if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
736 | 736 | EE_Register_Config::register( |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @return void |
750 | 750 | * @throws \EE_Error |
751 | 751 | */ |
752 | - private static function _register_admin_pages( $addon_name ) { |
|
752 | + private static function _register_admin_pages($addon_name) { |
|
753 | 753 | if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
754 | 754 | EE_Register_Admin_Page::register( |
755 | 755 | $addon_name, |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * @return void |
765 | 765 | * @throws \EE_Error |
766 | 766 | */ |
767 | - private static function _register_modules( $addon_name ) { |
|
767 | + private static function _register_modules($addon_name) { |
|
768 | 768 | if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
769 | 769 | EE_Register_Module::register( |
770 | 770 | $addon_name, |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | * @return void |
780 | 780 | * @throws \EE_Error |
781 | 781 | */ |
782 | - private static function _register_shortcodes( $addon_name ) { |
|
782 | + private static function _register_shortcodes($addon_name) { |
|
783 | 783 | if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
784 | 784 | EE_Register_Shortcode::register( |
785 | 785 | $addon_name, |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | * @return void |
795 | 795 | * @throws \EE_Error |
796 | 796 | */ |
797 | - private static function _register_widgets( $addon_name ) { |
|
797 | + private static function _register_widgets($addon_name) { |
|
798 | 798 | if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
799 | 799 | EE_Register_Widget::register( |
800 | 800 | $addon_name, |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return void |
810 | 810 | * @throws \EE_Error |
811 | 811 | */ |
812 | - private static function _register_capabilities( $addon_name ) { |
|
812 | + private static function _register_capabilities($addon_name) { |
|
813 | 813 | if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
814 | 814 | EE_Register_Capabilities::register( |
815 | 815 | $addon_name, |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | * @return void |
828 | 828 | * @throws \EE_Error |
829 | 829 | */ |
830 | - private static function _register_message_types( $addon_name ) { |
|
830 | + private static function _register_message_types($addon_name) { |
|
831 | 831 | if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
832 | 832 | add_action( |
833 | 833 | 'EE_Brewing_Regular___messages_caf', |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | * @return void |
843 | 843 | * @throws \EE_Error |
844 | 844 | */ |
845 | - private static function _register_custom_post_types( $addon_name ) { |
|
845 | + private static function _register_custom_post_types($addon_name) { |
|
846 | 846 | if ( |
847 | 847 | ! empty(self::$_settings[$addon_name]['custom_post_types']) |
848 | 848 | || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | * @return void |
865 | 865 | * @throws \EE_Error |
866 | 866 | */ |
867 | - private static function _register_payment_methods( $addon_name ) { |
|
867 | + private static function _register_payment_methods($addon_name) { |
|
868 | 868 | if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
869 | 869 | EE_Register_Payment_Method::register( |
870 | 870 | $addon_name, |
@@ -881,25 +881,25 @@ discard block |
||
881 | 881 | * @param string $addon_name |
882 | 882 | * @return EE_Addon |
883 | 883 | */ |
884 | - private static function _load_and_init_addon_class( $addon_name ) { |
|
884 | + private static function _load_and_init_addon_class($addon_name) { |
|
885 | 885 | $addon = EE_Registry::instance()->load_addon( |
886 | - dirname( self::$_settings[ $addon_name ]['main_file_path'] ), |
|
887 | - self::$_settings[ $addon_name ]['class_name'] |
|
886 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
887 | + self::$_settings[$addon_name]['class_name'] |
|
888 | 888 | ); |
889 | - $addon->set_name( $addon_name ); |
|
890 | - $addon->set_plugin_slug( self::$_settings[ $addon_name ]['plugin_slug'] ); |
|
891 | - $addon->set_plugin_basename( self::$_settings[ $addon_name ]['plugin_basename'] ); |
|
892 | - $addon->set_main_plugin_file( self::$_settings[ $addon_name ]['main_file_path'] ); |
|
893 | - $addon->set_plugin_action_slug( self::$_settings[ $addon_name ]['plugin_action_slug'] ); |
|
894 | - $addon->set_plugins_page_row( self::$_settings[ $addon_name ]['plugins_page_row'] ); |
|
895 | - $addon->set_version( self::$_settings[ $addon_name ]['version'] ); |
|
896 | - $addon->set_min_core_version( self::_effective_version( self::$_settings[ $addon_name ]['min_core_version'] ) ); |
|
897 | - $addon->set_config_section( self::$_settings[ $addon_name ]['config_section'] ); |
|
898 | - $addon->set_config_class( self::$_settings[ $addon_name ]['config_class'] ); |
|
899 | - $addon->set_config_name( self::$_settings[ $addon_name ]['config_name'] ); |
|
889 | + $addon->set_name($addon_name); |
|
890 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
891 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
892 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
893 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
894 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
895 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
896 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
897 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
898 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
899 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
900 | 900 | //unfortunately this can't be hooked in upon construction, because we don't have |
901 | 901 | //the plugin mainfile's path upon construction. |
902 | - register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
|
902 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
903 | 903 | // call any additional admin_callback functions during load_admin_controller hook |
904 | 904 | if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
905 | 905 | add_action( |
@@ -919,18 +919,18 @@ discard block |
||
919 | 919 | */ |
920 | 920 | public static function load_pue_update() { |
921 | 921 | // load PUE client |
922 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
922 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
923 | 923 | // cycle thru settings |
924 | - foreach ( self::$_settings as $settings ) { |
|
925 | - if ( ! empty( $settings['pue_options'] ) ) { |
|
924 | + foreach (self::$_settings as $settings) { |
|
925 | + if ( ! empty($settings['pue_options'])) { |
|
926 | 926 | // initiate the class and start the plugin update engine! |
927 | 927 | new PluginUpdateEngineChecker( |
928 | 928 | // host file URL |
929 | 929 | 'https://eventespresso.com', |
930 | 930 | // plugin slug(s) |
931 | 931 | array( |
932 | - 'premium' => array( 'p' => $settings['pue_options']['pue_plugin_slug'] ), |
|
933 | - 'prerelease' => array( 'beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr' ), |
|
932 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
933 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
934 | 934 | ), |
935 | 935 | // options |
936 | 936 | array( |
@@ -958,9 +958,9 @@ discard block |
||
958 | 958 | * @throws \EE_Error |
959 | 959 | */ |
960 | 960 | public static function register_message_types() { |
961 | - foreach ( self::$_settings as $addon_name => $settings ) { |
|
961 | + foreach (self::$_settings as $addon_name => $settings) { |
|
962 | 962 | if ( ! empty($settings['message_types'])) { |
963 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
963 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
964 | 964 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
965 | 965 | } |
966 | 966 | } |
@@ -977,73 +977,73 @@ discard block |
||
977 | 977 | * @throws EE_Error |
978 | 978 | * @return void |
979 | 979 | */ |
980 | - public static function deregister( $addon_name = null ) { |
|
981 | - if ( isset( self::$_settings[ $addon_name ] ) ) { |
|
982 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
983 | - if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
|
980 | + public static function deregister($addon_name = null) { |
|
981 | + if (isset(self::$_settings[$addon_name])) { |
|
982 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
983 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
984 | 984 | // setup DMS |
985 | - EE_Register_Data_Migration_Scripts::deregister( $addon_name ); |
|
985 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
986 | 986 | } |
987 | - if ( ! empty( self::$_settings[ $addon_name ]['admin_path'] ) ) { |
|
987 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
988 | 988 | // register admin page |
989 | - EE_Register_Admin_Page::deregister( $addon_name ); |
|
989 | + EE_Register_Admin_Page::deregister($addon_name); |
|
990 | 990 | } |
991 | - if ( ! empty( self::$_settings[ $addon_name ]['module_paths'] ) ) { |
|
991 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
992 | 992 | // add to list of modules to be registered |
993 | - EE_Register_Module::deregister( $addon_name ); |
|
993 | + EE_Register_Module::deregister($addon_name); |
|
994 | 994 | } |
995 | - if ( ! empty( self::$_settings[ $addon_name ]['shortcode_paths'] ) ) { |
|
995 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
996 | 996 | // add to list of shortcodes to be registered |
997 | - EE_Register_Shortcode::deregister( $addon_name ); |
|
997 | + EE_Register_Shortcode::deregister($addon_name); |
|
998 | 998 | } |
999 | - if ( ! empty( self::$_settings[ $addon_name ]['config_class'] ) ) { |
|
999 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1000 | 1000 | // if config_class present let's register config. |
1001 | - EE_Register_Config::deregister( self::$_settings[ $addon_name ]['config_class'] ); |
|
1001 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1002 | 1002 | } |
1003 | - if ( ! empty( self::$_settings[ $addon_name ]['widget_paths'] ) ) { |
|
1003 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1004 | 1004 | // add to list of widgets to be registered |
1005 | - EE_Register_Widget::deregister( $addon_name ); |
|
1005 | + EE_Register_Widget::deregister($addon_name); |
|
1006 | 1006 | } |
1007 | - if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
|
1007 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1008 | 1008 | || |
1009 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1009 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1010 | 1010 | ) { |
1011 | 1011 | // add to list of shortcodes to be registered |
1012 | - EE_Register_Model::deregister( $addon_name ); |
|
1012 | + EE_Register_Model::deregister($addon_name); |
|
1013 | 1013 | } |
1014 | - if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
|
1014 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1015 | 1015 | || |
1016 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1016 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1017 | 1017 | ) { |
1018 | 1018 | // add to list of shortcodes to be registered |
1019 | - EE_Register_Model_Extensions::deregister( $addon_name ); |
|
1019 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1020 | 1020 | } |
1021 | - if ( ! empty( self::$_settings[ $addon_name ]['message_types'] ) ) { |
|
1022 | - foreach ((array)self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings ) |
|
1021 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1022 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) |
|
1023 | 1023 | { |
1024 | - EE_Register_Message_Type::deregister( $message_type ); |
|
1024 | + EE_Register_Message_Type::deregister($message_type); |
|
1025 | 1025 | } |
1026 | 1026 | } |
1027 | 1027 | //deregister capabilities for addon |
1028 | 1028 | if ( |
1029 | - ! empty( self::$_settings[ $addon_name ]['capabilities'] ) |
|
1030 | - || ! empty( self::$_settings[ $addon_name ]['capability_maps'] ) |
|
1029 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1030 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1031 | 1031 | ) { |
1032 | - EE_Register_Capabilities::deregister( $addon_name ); |
|
1032 | + EE_Register_Capabilities::deregister($addon_name); |
|
1033 | 1033 | } |
1034 | 1034 | //deregister custom_post_types for addon |
1035 | - if ( ! empty( self::$_settings[ $addon_name ]['custom_post_types'] ) ) { |
|
1036 | - EE_Register_CPT::deregister( $addon_name ); |
|
1035 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1036 | + EE_Register_CPT::deregister($addon_name); |
|
1037 | 1037 | } |
1038 | 1038 | remove_action( |
1039 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1040 | - array( EE_Registry::instance()->addons->{$class_name}, 'deactivation' ) |
|
1039 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1040 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
1041 | 1041 | ); |
1042 | 1042 | remove_action( |
1043 | 1043 | 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
1044 | - array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
|
1044 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
1045 | 1045 | ); |
1046 | - unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
|
1046 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected static $_incompatible_addons = array( |
49 | 49 | 'Multi_Event_Registration' => '2.0.11.rc.002', |
50 | 50 | 'Promotions' => '1.0.0.rc.084', |
51 | - ); |
|
51 | + ); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
@@ -219,660 +219,660 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public static function register( $addon_name = '', $setup_args = array() ) { |
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | - // get class name for addon |
|
222 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | + // get class name for addon |
|
224 | 224 | $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
225 | 225 | //setup $_settings array from incoming values. |
226 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | - // setup PUE |
|
228 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | - // does this addon work with this version of core or WordPress ? |
|
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | - return; |
|
226 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | + // setup PUE |
|
228 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | + // does this addon work with this version of core or WordPress ? |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | + return; |
|
232 | 232 | } |
233 | 233 | // register namespaces |
234 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | - // check if this is an activation request |
|
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | - // dont bother setting up the rest of the addon atm |
|
238 | - return; |
|
239 | - } |
|
240 | - // we need cars |
|
241 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | - // register new models and extensions |
|
243 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | - // setup DMS |
|
245 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | - // if config_class is present let's register config. |
|
247 | - \EE_Register_Addon::_register_config($addon_name); |
|
248 | - // register admin pages |
|
249 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | - // add to list of modules to be registered |
|
251 | - \EE_Register_Addon::_register_modules($addon_name); |
|
252 | - // add to list of shortcodes to be registered |
|
253 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | - // add to list of widgets to be registered |
|
255 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | - // register capability related stuff. |
|
257 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | - // any message type to register? |
|
259 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
234 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | + // check if this is an activation request |
|
236 | + if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | + // dont bother setting up the rest of the addon atm |
|
238 | + return; |
|
239 | + } |
|
240 | + // we need cars |
|
241 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | + // register new models and extensions |
|
243 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | + // setup DMS |
|
245 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | + // if config_class is present let's register config. |
|
247 | + \EE_Register_Addon::_register_config($addon_name); |
|
248 | + // register admin pages |
|
249 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | + // add to list of modules to be registered |
|
251 | + \EE_Register_Addon::_register_modules($addon_name); |
|
252 | + // add to list of shortcodes to be registered |
|
253 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | + // add to list of widgets to be registered |
|
255 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | + // register capability related stuff. |
|
257 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | + // any message type to register? |
|
259 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
260 | 260 | // any custom post type/ custom capabilities or default terms to register |
261 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | - // and any payment methods |
|
263 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
261 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | + // and any payment methods |
|
263 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
264 | 264 | // load and instantiate main addon class |
265 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | - $addon->after_registration(); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $addon_name |
|
273 | - * @param array $setup_args |
|
274 | - * @return void |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
277 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | - { |
|
279 | - // required fields MUST be present, so let's make sure they are. |
|
280 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | - throw new EE_Error( |
|
282 | - __( |
|
283 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | - 'event_espresso' |
|
285 | - ) |
|
286 | - ); |
|
287 | - } |
|
288 | - if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | - throw new EE_Error( |
|
290 | - sprintf( |
|
291 | - __( |
|
292 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | - 'event_espresso' |
|
294 | - ), |
|
295 | - implode(',', array_keys($setup_args)) |
|
296 | - ) |
|
297 | - ); |
|
298 | - } |
|
299 | - // check that addon has not already been registered with that name |
|
300 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | - throw new EE_Error( |
|
302 | - sprintf( |
|
303 | - __( |
|
304 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - $addon_name |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
265 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | + $addon->after_registration(); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $addon_name |
|
273 | + * @param array $setup_args |
|
274 | + * @return void |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | + { |
|
279 | + // required fields MUST be present, so let's make sure they are. |
|
280 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | + throw new EE_Error( |
|
282 | + __( |
|
283 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | + 'event_espresso' |
|
285 | + ) |
|
286 | + ); |
|
287 | + } |
|
288 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | + throw new EE_Error( |
|
290 | + sprintf( |
|
291 | + __( |
|
292 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | + 'event_espresso' |
|
294 | + ), |
|
295 | + implode(',', array_keys($setup_args)) |
|
296 | + ) |
|
297 | + ); |
|
298 | + } |
|
299 | + // check that addon has not already been registered with that name |
|
300 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | + throw new EE_Error( |
|
302 | + sprintf( |
|
303 | + __( |
|
304 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + $addon_name |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | |
314 | 314 | |
315 | - /** |
|
316 | - * @param string $addon_name |
|
317 | - * @param array $setup_args |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - if (empty($setup_args['class_name'])) { |
|
323 | - // generate one by first separating name with spaces |
|
324 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | - //capitalize, then replace spaces with underscores |
|
326 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | - } else { |
|
328 | - $class_name = $setup_args['class_name']; |
|
329 | - } |
|
330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param string $class_name |
|
337 | - * @param array $setup_args |
|
338 | - * @return array |
|
339 | - */ |
|
340 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | - { |
|
342 | - //setup $_settings array from incoming values. |
|
343 | - $addon_settings = array( |
|
344 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | - 'class_name' => $class_name, |
|
346 | - // the addon slug for use in URLs, etc |
|
347 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | - ? (string)$setup_args['plugin_slug'] |
|
349 | - : '', |
|
350 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | - ? (string)$setup_args['plugin_action_slug'] |
|
353 | - : '', |
|
354 | - // the "software" version for the addon |
|
355 | - 'version' => isset($setup_args['version']) |
|
356 | - ? (string)$setup_args['version'] |
|
357 | - : '', |
|
358 | - // the minimum version of EE Core that the addon will work with |
|
359 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | - ? (string)$setup_args['min_core_version'] |
|
361 | - : '', |
|
362 | - // the minimum version of WordPress that the addon will work with |
|
363 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | - ? (string)$setup_args['min_wp_version'] |
|
365 | - : EE_MIN_WP_VER_REQUIRED, |
|
366 | - // full server path to main file (file loaded directly by WP) |
|
367 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | - ? (string)$setup_args['main_file_path'] |
|
369 | - : '', |
|
370 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | - 'admin_path' => isset($setup_args['admin_path']) |
|
372 | - ? (string)$setup_args['admin_path'] : '', |
|
373 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | - ? (string)$setup_args['admin_callback'] |
|
376 | - : '', |
|
377 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | - 'config_section' => isset($setup_args['config_section']) |
|
379 | - ? (string)$setup_args['config_section'] |
|
380 | - : 'addons', |
|
381 | - // the class name for this addon's configuration settings object |
|
382 | - 'config_class' => isset($setup_args['config_class']) |
|
383 | - ? (string)$setup_args['config_class'] : '', |
|
384 | - //the name given to the config for this addons' configuration settings object (optional) |
|
385 | - 'config_name' => isset($setup_args['config_name']) |
|
386 | - ? (string)$setup_args['config_name'] : '', |
|
387 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | - ? (array)$setup_args['autoloader_paths'] |
|
390 | - : array(), |
|
391 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | - ? (array)$setup_args['autoloader_folders'] |
|
394 | - : array(), |
|
395 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | - ? (array)$setup_args['dms_paths'] |
|
398 | - : array(), |
|
399 | - // array of full server paths to any EED_Modules used by the addon |
|
400 | - 'module_paths' => isset($setup_args['module_paths']) |
|
401 | - ? (array)$setup_args['module_paths'] |
|
402 | - : array(), |
|
403 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | - ? (array)$setup_args['shortcode_paths'] |
|
406 | - : array(), |
|
407 | - // array of full server paths to any WP_Widgets used by the addon |
|
408 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | - ? (array)$setup_args['widget_paths'] |
|
410 | - : array(), |
|
411 | - // array of PUE options used by the addon |
|
412 | - 'pue_options' => isset($setup_args['pue_options']) |
|
413 | - ? (array)$setup_args['pue_options'] |
|
414 | - : array(), |
|
415 | - 'message_types' => isset($setup_args['message_types']) |
|
416 | - ? (array)$setup_args['message_types'] |
|
417 | - : array(), |
|
418 | - 'capabilities' => isset($setup_args['capabilities']) |
|
419 | - ? (array)$setup_args['capabilities'] |
|
420 | - : array(), |
|
421 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | - ? (array)$setup_args['capability_maps'] |
|
423 | - : array(), |
|
424 | - 'model_paths' => isset($setup_args['model_paths']) |
|
425 | - ? (array)$setup_args['model_paths'] |
|
426 | - : array(), |
|
427 | - 'class_paths' => isset($setup_args['class_paths']) |
|
428 | - ? (array)$setup_args['class_paths'] |
|
429 | - : array(), |
|
430 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | - ? (array)$setup_args['model_extension_paths'] |
|
432 | - : array(), |
|
433 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | - ? (array)$setup_args['class_extension_paths'] |
|
435 | - : array(), |
|
436 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | - ? (array)$setup_args['custom_post_types'] |
|
438 | - : array(), |
|
439 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | - ? (array)$setup_args['custom_taxonomies'] |
|
441 | - : array(), |
|
442 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | - ? (array)$setup_args['payment_method_paths'] |
|
444 | - : array(), |
|
445 | - 'default_terms' => isset($setup_args['default_terms']) |
|
446 | - ? (array)$setup_args['default_terms'] |
|
447 | - : array(), |
|
448 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | - // that can be used for adding upgrading/marketing info |
|
450 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | - ? $setup_args['plugins_page_row'] |
|
452 | - : '', |
|
453 | - 'namespace' => isset( |
|
454 | - $setup_args['namespace'], |
|
455 | - $setup_args['namespace']['FQNS'], |
|
456 | - $setup_args['namespace']['DIR'] |
|
457 | - ) |
|
458 | - ? (array)$setup_args['namespace'] |
|
459 | - : array(), |
|
460 | - ); |
|
461 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | - && ! empty($addon_settings['admin_path']) |
|
465 | - ? $addon_settings['plugin_slug'] |
|
466 | - : $addon_settings['plugin_action_slug']; |
|
467 | - // full server path to main file (file loaded directly by WP) |
|
468 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | - return $addon_settings; |
|
315 | + /** |
|
316 | + * @param string $addon_name |
|
317 | + * @param array $setup_args |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + if (empty($setup_args['class_name'])) { |
|
323 | + // generate one by first separating name with spaces |
|
324 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | + //capitalize, then replace spaces with underscores |
|
326 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | + } else { |
|
328 | + $class_name = $setup_args['class_name']; |
|
329 | + } |
|
330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
470 | 331 | } |
471 | 332 | |
472 | 333 | |
473 | 334 | |
474 | - /** |
|
475 | - * @param string $addon_name |
|
476 | - * @param array $addon_settings |
|
477 | - * @return boolean |
|
478 | - */ |
|
335 | + /** |
|
336 | + * @param string $class_name |
|
337 | + * @param array $setup_args |
|
338 | + * @return array |
|
339 | + */ |
|
340 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | + { |
|
342 | + //setup $_settings array from incoming values. |
|
343 | + $addon_settings = array( |
|
344 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | + 'class_name' => $class_name, |
|
346 | + // the addon slug for use in URLs, etc |
|
347 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | + ? (string)$setup_args['plugin_slug'] |
|
349 | + : '', |
|
350 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | + ? (string)$setup_args['plugin_action_slug'] |
|
353 | + : '', |
|
354 | + // the "software" version for the addon |
|
355 | + 'version' => isset($setup_args['version']) |
|
356 | + ? (string)$setup_args['version'] |
|
357 | + : '', |
|
358 | + // the minimum version of EE Core that the addon will work with |
|
359 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | + ? (string)$setup_args['min_core_version'] |
|
361 | + : '', |
|
362 | + // the minimum version of WordPress that the addon will work with |
|
363 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | + ? (string)$setup_args['min_wp_version'] |
|
365 | + : EE_MIN_WP_VER_REQUIRED, |
|
366 | + // full server path to main file (file loaded directly by WP) |
|
367 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | + ? (string)$setup_args['main_file_path'] |
|
369 | + : '', |
|
370 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | + 'admin_path' => isset($setup_args['admin_path']) |
|
372 | + ? (string)$setup_args['admin_path'] : '', |
|
373 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | + ? (string)$setup_args['admin_callback'] |
|
376 | + : '', |
|
377 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | + 'config_section' => isset($setup_args['config_section']) |
|
379 | + ? (string)$setup_args['config_section'] |
|
380 | + : 'addons', |
|
381 | + // the class name for this addon's configuration settings object |
|
382 | + 'config_class' => isset($setup_args['config_class']) |
|
383 | + ? (string)$setup_args['config_class'] : '', |
|
384 | + //the name given to the config for this addons' configuration settings object (optional) |
|
385 | + 'config_name' => isset($setup_args['config_name']) |
|
386 | + ? (string)$setup_args['config_name'] : '', |
|
387 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | + ? (array)$setup_args['autoloader_paths'] |
|
390 | + : array(), |
|
391 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | + ? (array)$setup_args['autoloader_folders'] |
|
394 | + : array(), |
|
395 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | + ? (array)$setup_args['dms_paths'] |
|
398 | + : array(), |
|
399 | + // array of full server paths to any EED_Modules used by the addon |
|
400 | + 'module_paths' => isset($setup_args['module_paths']) |
|
401 | + ? (array)$setup_args['module_paths'] |
|
402 | + : array(), |
|
403 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | + ? (array)$setup_args['shortcode_paths'] |
|
406 | + : array(), |
|
407 | + // array of full server paths to any WP_Widgets used by the addon |
|
408 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | + ? (array)$setup_args['widget_paths'] |
|
410 | + : array(), |
|
411 | + // array of PUE options used by the addon |
|
412 | + 'pue_options' => isset($setup_args['pue_options']) |
|
413 | + ? (array)$setup_args['pue_options'] |
|
414 | + : array(), |
|
415 | + 'message_types' => isset($setup_args['message_types']) |
|
416 | + ? (array)$setup_args['message_types'] |
|
417 | + : array(), |
|
418 | + 'capabilities' => isset($setup_args['capabilities']) |
|
419 | + ? (array)$setup_args['capabilities'] |
|
420 | + : array(), |
|
421 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | + ? (array)$setup_args['capability_maps'] |
|
423 | + : array(), |
|
424 | + 'model_paths' => isset($setup_args['model_paths']) |
|
425 | + ? (array)$setup_args['model_paths'] |
|
426 | + : array(), |
|
427 | + 'class_paths' => isset($setup_args['class_paths']) |
|
428 | + ? (array)$setup_args['class_paths'] |
|
429 | + : array(), |
|
430 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | + ? (array)$setup_args['model_extension_paths'] |
|
432 | + : array(), |
|
433 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | + ? (array)$setup_args['class_extension_paths'] |
|
435 | + : array(), |
|
436 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | + ? (array)$setup_args['custom_post_types'] |
|
438 | + : array(), |
|
439 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | + ? (array)$setup_args['custom_taxonomies'] |
|
441 | + : array(), |
|
442 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | + ? (array)$setup_args['payment_method_paths'] |
|
444 | + : array(), |
|
445 | + 'default_terms' => isset($setup_args['default_terms']) |
|
446 | + ? (array)$setup_args['default_terms'] |
|
447 | + : array(), |
|
448 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | + // that can be used for adding upgrading/marketing info |
|
450 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | + ? $setup_args['plugins_page_row'] |
|
452 | + : '', |
|
453 | + 'namespace' => isset( |
|
454 | + $setup_args['namespace'], |
|
455 | + $setup_args['namespace']['FQNS'], |
|
456 | + $setup_args['namespace']['DIR'] |
|
457 | + ) |
|
458 | + ? (array)$setup_args['namespace'] |
|
459 | + : array(), |
|
460 | + ); |
|
461 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | + && ! empty($addon_settings['admin_path']) |
|
465 | + ? $addon_settings['plugin_slug'] |
|
466 | + : $addon_settings['plugin_action_slug']; |
|
467 | + // full server path to main file (file loaded directly by WP) |
|
468 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | + return $addon_settings; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @param string $addon_name |
|
476 | + * @param array $addon_settings |
|
477 | + * @return boolean |
|
478 | + */ |
|
479 | 479 | private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
480 | - global $wp_version; |
|
481 | - $incompatibility_message = ''; |
|
482 | - //check whether this addon version is compatible with EE core |
|
483 | - if ( |
|
484 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | - && ! self::_meets_min_core_version_requirement( |
|
486 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | - $addon_settings['version'] |
|
488 | - ) |
|
489 | - ) { |
|
490 | - $incompatibility_message = sprintf( |
|
491 | - __( |
|
492 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | - ), |
|
494 | - $addon_name, |
|
495 | - '<br />', |
|
496 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | - '</span><br />' |
|
499 | - ); |
|
500 | - } else if ( |
|
501 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | - ) { |
|
503 | - $incompatibility_message = sprintf( |
|
504 | - __( |
|
505 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - $addon_name, |
|
509 | - self::_effective_version($addon_settings['min_core_version']), |
|
510 | - self::_effective_version(espresso_version()), |
|
511 | - '<br />', |
|
512 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | - '</span><br />' |
|
514 | - ); |
|
515 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | - $incompatibility_message = sprintf( |
|
517 | - __( |
|
518 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | - 'event_espresso' |
|
520 | - ), |
|
521 | - $addon_name, |
|
522 | - $addon_settings['min_wp_version'], |
|
523 | - '<br />', |
|
524 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | - '</span><br />' |
|
526 | - ); |
|
527 | - } |
|
528 | - if ( ! empty($incompatibility_message)) { |
|
529 | - // remove 'activate' from the REQUEST |
|
530 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | - if (current_user_can('activate_plugins')) { |
|
533 | - // show an error message indicating the plugin didn't activate properly |
|
534 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | - } |
|
536 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | - return false; |
|
538 | - } |
|
539 | - // addon IS compatible |
|
540 | - return true; |
|
480 | + global $wp_version; |
|
481 | + $incompatibility_message = ''; |
|
482 | + //check whether this addon version is compatible with EE core |
|
483 | + if ( |
|
484 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | + && ! self::_meets_min_core_version_requirement( |
|
486 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | + $addon_settings['version'] |
|
488 | + ) |
|
489 | + ) { |
|
490 | + $incompatibility_message = sprintf( |
|
491 | + __( |
|
492 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | + ), |
|
494 | + $addon_name, |
|
495 | + '<br />', |
|
496 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | + '</span><br />' |
|
499 | + ); |
|
500 | + } else if ( |
|
501 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | + ) { |
|
503 | + $incompatibility_message = sprintf( |
|
504 | + __( |
|
505 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + $addon_name, |
|
509 | + self::_effective_version($addon_settings['min_core_version']), |
|
510 | + self::_effective_version(espresso_version()), |
|
511 | + '<br />', |
|
512 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | + '</span><br />' |
|
514 | + ); |
|
515 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | + $incompatibility_message = sprintf( |
|
517 | + __( |
|
518 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | + 'event_espresso' |
|
520 | + ), |
|
521 | + $addon_name, |
|
522 | + $addon_settings['min_wp_version'], |
|
523 | + '<br />', |
|
524 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | + '</span><br />' |
|
526 | + ); |
|
527 | + } |
|
528 | + if ( ! empty($incompatibility_message)) { |
|
529 | + // remove 'activate' from the REQUEST |
|
530 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | + if (current_user_can('activate_plugins')) { |
|
533 | + // show an error message indicating the plugin didn't activate properly |
|
534 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | + } |
|
536 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | + return false; |
|
538 | + } |
|
539 | + // addon IS compatible |
|
540 | + return true; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | |
544 | 544 | |
545 | - /** |
|
546 | - * if plugin update engine is being used for auto-updates, |
|
547 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | - * (not needed if PUE is not being used) |
|
549 | - * |
|
550 | - * @param string $addon_name |
|
551 | - * @param string $class_name |
|
552 | - * @param array $setup_args |
|
553 | - * @return void |
|
554 | - */ |
|
545 | + /** |
|
546 | + * if plugin update engine is being used for auto-updates, |
|
547 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | + * (not needed if PUE is not being used) |
|
549 | + * |
|
550 | + * @param string $addon_name |
|
551 | + * @param string $class_name |
|
552 | + * @param array $setup_args |
|
553 | + * @return void |
|
554 | + */ |
|
555 | 555 | private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
556 | - if ( ! empty($setup_args['pue_options'])) { |
|
557 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | - : 'espresso_' . strtolower($class_name), |
|
561 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | - : plugin_basename($setup_args['main_file_path']), |
|
564 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | - : '24', |
|
567 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | - : false, |
|
570 | - ); |
|
571 | - add_action( |
|
572 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | - array('EE_Register_Addon', 'load_pue_update') |
|
574 | - ); |
|
575 | - } |
|
556 | + if ( ! empty($setup_args['pue_options'])) { |
|
557 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | + : 'espresso_' . strtolower($class_name), |
|
561 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | + : plugin_basename($setup_args['main_file_path']), |
|
564 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | + : '24', |
|
567 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | + : false, |
|
570 | + ); |
|
571 | + add_action( |
|
572 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | + array('EE_Register_Addon', 'load_pue_update') |
|
574 | + ); |
|
575 | + } |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | |
579 | 579 | |
580 | - /** |
|
581 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | - * |
|
583 | - * @param array $addon_settings |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - private static function _setup_namespaces(array $addon_settings) |
|
587 | - { |
|
588 | - // |
|
589 | - if ( |
|
590 | - isset( |
|
591 | - $addon_settings['namespace'], |
|
592 | - $addon_settings['namespace']['FQNS'], |
|
593 | - $addon_settings['namespace']['DIR'] |
|
594 | - ) |
|
595 | - ) { |
|
596 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | - $addon_settings['namespace']['FQNS'], |
|
598 | - $addon_settings['namespace']['DIR'] |
|
599 | - ); |
|
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * @param string $addon_name |
|
607 | - * @param array $addon_settings |
|
608 | - * @return bool |
|
609 | - */ |
|
580 | + /** |
|
581 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | + * |
|
583 | + * @param array $addon_settings |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + private static function _setup_namespaces(array $addon_settings) |
|
587 | + { |
|
588 | + // |
|
589 | + if ( |
|
590 | + isset( |
|
591 | + $addon_settings['namespace'], |
|
592 | + $addon_settings['namespace']['FQNS'], |
|
593 | + $addon_settings['namespace']['DIR'] |
|
594 | + ) |
|
595 | + ) { |
|
596 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | + $addon_settings['namespace']['FQNS'], |
|
598 | + $addon_settings['namespace']['DIR'] |
|
599 | + ); |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * @param string $addon_name |
|
607 | + * @param array $addon_settings |
|
608 | + * @return bool |
|
609 | + */ |
|
610 | 610 | private static function _addon_activation( $addon_name, array $addon_settings ) { |
611 | - // this is an activation request |
|
612 | - if (did_action('activate_plugin')) { |
|
613 | - //to find if THIS is the addon that was activated, |
|
614 | - //just check if we have already registered it or not |
|
615 | - //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | - if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | - self::$_settings[$addon_name] = $addon_settings; |
|
618 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | - $addon->set_activation_indicator_option(); |
|
620 | - // dont bother setting up the rest of the addon. |
|
621 | - // we know it was just activated and the request will end soon |
|
622 | - } |
|
623 | - return true; |
|
624 | - } else { |
|
625 | - // make sure this was called in the right place! |
|
626 | - if ( |
|
627 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | - ) { |
|
630 | - EE_Error::doing_it_wrong( |
|
631 | - __METHOD__, |
|
632 | - sprintf( |
|
633 | - __( |
|
634 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | - 'event_espresso' |
|
636 | - ), |
|
637 | - $addon_name |
|
638 | - ), |
|
639 | - '4.3.0' |
|
640 | - ); |
|
641 | - } |
|
642 | - // make sure addon settings are set correctly without overwriting anything existing |
|
643 | - if (isset(self::$_settings[$addon_name])) { |
|
644 | - self::$_settings[$addon_name] += $addon_settings; |
|
645 | - } else { |
|
646 | - self::$_settings[$addon_name] = $addon_settings; |
|
647 | - } |
|
648 | - } |
|
649 | - return false; |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * @param string $addon_name |
|
656 | - * @return void |
|
657 | - * @throws \EE_Error |
|
658 | - */ |
|
659 | - private static function _setup_autoloaders($addon_name) |
|
660 | - { |
|
661 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | - // setup autoloader for single file |
|
663 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | - } |
|
665 | - // setup autoloaders for folders |
|
666 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * register new models and extensions |
|
677 | - * |
|
678 | - * @param string $addon_name |
|
679 | - * @return void |
|
680 | - * @throws \EE_Error |
|
681 | - */ |
|
611 | + // this is an activation request |
|
612 | + if (did_action('activate_plugin')) { |
|
613 | + //to find if THIS is the addon that was activated, |
|
614 | + //just check if we have already registered it or not |
|
615 | + //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | + if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | + self::$_settings[$addon_name] = $addon_settings; |
|
618 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | + $addon->set_activation_indicator_option(); |
|
620 | + // dont bother setting up the rest of the addon. |
|
621 | + // we know it was just activated and the request will end soon |
|
622 | + } |
|
623 | + return true; |
|
624 | + } else { |
|
625 | + // make sure this was called in the right place! |
|
626 | + if ( |
|
627 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | + ) { |
|
630 | + EE_Error::doing_it_wrong( |
|
631 | + __METHOD__, |
|
632 | + sprintf( |
|
633 | + __( |
|
634 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | + 'event_espresso' |
|
636 | + ), |
|
637 | + $addon_name |
|
638 | + ), |
|
639 | + '4.3.0' |
|
640 | + ); |
|
641 | + } |
|
642 | + // make sure addon settings are set correctly without overwriting anything existing |
|
643 | + if (isset(self::$_settings[$addon_name])) { |
|
644 | + self::$_settings[$addon_name] += $addon_settings; |
|
645 | + } else { |
|
646 | + self::$_settings[$addon_name] = $addon_settings; |
|
647 | + } |
|
648 | + } |
|
649 | + return false; |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * @param string $addon_name |
|
656 | + * @return void |
|
657 | + * @throws \EE_Error |
|
658 | + */ |
|
659 | + private static function _setup_autoloaders($addon_name) |
|
660 | + { |
|
661 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | + // setup autoloader for single file |
|
663 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | + } |
|
665 | + // setup autoloaders for folders |
|
666 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * register new models and extensions |
|
677 | + * |
|
678 | + * @param string $addon_name |
|
679 | + * @return void |
|
680 | + * @throws \EE_Error |
|
681 | + */ |
|
682 | 682 | private static function _register_models_and_extensions( $addon_name ) { |
683 | - // register new models |
|
684 | - if ( |
|
685 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | - ) { |
|
688 | - EE_Register_Model::register( |
|
689 | - $addon_name, |
|
690 | - array( |
|
691 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - // register model extensions |
|
697 | - if ( |
|
698 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | - ) { |
|
701 | - EE_Register_Model_Extensions::register( |
|
702 | - $addon_name, |
|
703 | - array( |
|
704 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | - ) |
|
707 | - ); |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * @param string $addon_name |
|
715 | - * @return void |
|
716 | - * @throws \EE_Error |
|
717 | - */ |
|
683 | + // register new models |
|
684 | + if ( |
|
685 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | + ) { |
|
688 | + EE_Register_Model::register( |
|
689 | + $addon_name, |
|
690 | + array( |
|
691 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + // register model extensions |
|
697 | + if ( |
|
698 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | + ) { |
|
701 | + EE_Register_Model_Extensions::register( |
|
702 | + $addon_name, |
|
703 | + array( |
|
704 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | + ) |
|
707 | + ); |
|
708 | + } |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * @param string $addon_name |
|
715 | + * @return void |
|
716 | + * @throws \EE_Error |
|
717 | + */ |
|
718 | 718 | private static function _register_data_migration_scripts( $addon_name ) { |
719 | - // setup DMS |
|
720 | - if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | - EE_Register_Data_Migration_Scripts::register( |
|
722 | - $addon_name, |
|
723 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | - ); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * @param string $addon_name |
|
731 | - * @return void |
|
732 | - * @throws \EE_Error |
|
733 | - */ |
|
719 | + // setup DMS |
|
720 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | + EE_Register_Data_Migration_Scripts::register( |
|
722 | + $addon_name, |
|
723 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | + ); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * @param string $addon_name |
|
731 | + * @return void |
|
732 | + * @throws \EE_Error |
|
733 | + */ |
|
734 | 734 | private static function _register_config( $addon_name ) { |
735 | - // if config_class is present let's register config. |
|
736 | - if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | - EE_Register_Config::register( |
|
738 | - self::$_settings[$addon_name]['config_class'], |
|
739 | - array( |
|
740 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | - ) |
|
743 | - ); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * @param string $addon_name |
|
750 | - * @return void |
|
751 | - * @throws \EE_Error |
|
752 | - */ |
|
735 | + // if config_class is present let's register config. |
|
736 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | + EE_Register_Config::register( |
|
738 | + self::$_settings[$addon_name]['config_class'], |
|
739 | + array( |
|
740 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | + ) |
|
743 | + ); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * @param string $addon_name |
|
750 | + * @return void |
|
751 | + * @throws \EE_Error |
|
752 | + */ |
|
753 | 753 | private static function _register_admin_pages( $addon_name ) { |
754 | - if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | - EE_Register_Admin_Page::register( |
|
756 | - $addon_name, |
|
757 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | - ); |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * @param string $addon_name |
|
765 | - * @return void |
|
766 | - * @throws \EE_Error |
|
767 | - */ |
|
754 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | + EE_Register_Admin_Page::register( |
|
756 | + $addon_name, |
|
757 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | + ); |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * @param string $addon_name |
|
765 | + * @return void |
|
766 | + * @throws \EE_Error |
|
767 | + */ |
|
768 | 768 | private static function _register_modules( $addon_name ) { |
769 | - if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | - EE_Register_Module::register( |
|
771 | - $addon_name, |
|
772 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | - ); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * @param string $addon_name |
|
780 | - * @return void |
|
781 | - * @throws \EE_Error |
|
782 | - */ |
|
769 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | + EE_Register_Module::register( |
|
771 | + $addon_name, |
|
772 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | + ); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * @param string $addon_name |
|
780 | + * @return void |
|
781 | + * @throws \EE_Error |
|
782 | + */ |
|
783 | 783 | private static function _register_shortcodes( $addon_name ) { |
784 | - if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | - EE_Register_Shortcode::register( |
|
786 | - $addon_name, |
|
787 | - array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | - ); |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * @param string $addon_name |
|
795 | - * @return void |
|
796 | - * @throws \EE_Error |
|
797 | - */ |
|
784 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | + EE_Register_Shortcode::register( |
|
786 | + $addon_name, |
|
787 | + array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | + ); |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * @param string $addon_name |
|
795 | + * @return void |
|
796 | + * @throws \EE_Error |
|
797 | + */ |
|
798 | 798 | private static function _register_widgets( $addon_name ) { |
799 | - if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | - EE_Register_Widget::register( |
|
801 | - $addon_name, |
|
802 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | - ); |
|
804 | - } |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * @param string $addon_name |
|
810 | - * @return void |
|
811 | - * @throws \EE_Error |
|
812 | - */ |
|
799 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | + EE_Register_Widget::register( |
|
801 | + $addon_name, |
|
802 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | + ); |
|
804 | + } |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * @param string $addon_name |
|
810 | + * @return void |
|
811 | + * @throws \EE_Error |
|
812 | + */ |
|
813 | 813 | private static function _register_capabilities( $addon_name ) { |
814 | - if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | - EE_Register_Capabilities::register( |
|
816 | - $addon_name, |
|
817 | - array( |
|
818 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | - ) |
|
821 | - ); |
|
822 | - } |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * @param string $addon_name |
|
828 | - * @return void |
|
829 | - * @throws \EE_Error |
|
830 | - */ |
|
814 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | + EE_Register_Capabilities::register( |
|
816 | + $addon_name, |
|
817 | + array( |
|
818 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | + ) |
|
821 | + ); |
|
822 | + } |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * @param string $addon_name |
|
828 | + * @return void |
|
829 | + * @throws \EE_Error |
|
830 | + */ |
|
831 | 831 | private static function _register_message_types( $addon_name ) { |
832 | - if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | - add_action( |
|
834 | - 'EE_Brewing_Regular___messages_caf', |
|
835 | - array('EE_Register_Addon', 'register_message_types') |
|
836 | - ); |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * @param string $addon_name |
|
843 | - * @return void |
|
844 | - * @throws \EE_Error |
|
845 | - */ |
|
832 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | + add_action( |
|
834 | + 'EE_Brewing_Regular___messages_caf', |
|
835 | + array('EE_Register_Addon', 'register_message_types') |
|
836 | + ); |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * @param string $addon_name |
|
843 | + * @return void |
|
844 | + * @throws \EE_Error |
|
845 | + */ |
|
846 | 846 | private static function _register_custom_post_types( $addon_name ) { |
847 | - if ( |
|
848 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | - ) { |
|
851 | - EE_Register_CPT::register( |
|
852 | - $addon_name, |
|
853 | - array( |
|
854 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | - ) |
|
858 | - ); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * @param string $addon_name |
|
865 | - * @return void |
|
866 | - * @throws \EE_Error |
|
867 | - */ |
|
847 | + if ( |
|
848 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | + ) { |
|
851 | + EE_Register_CPT::register( |
|
852 | + $addon_name, |
|
853 | + array( |
|
854 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | + ) |
|
858 | + ); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * @param string $addon_name |
|
865 | + * @return void |
|
866 | + * @throws \EE_Error |
|
867 | + */ |
|
868 | 868 | private static function _register_payment_methods( $addon_name ) { |
869 | - if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | - EE_Register_Payment_Method::register( |
|
871 | - $addon_name, |
|
872 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | - ); |
|
874 | - } |
|
875 | - } |
|
869 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | + EE_Register_Payment_Method::register( |
|
871 | + $addon_name, |
|
872 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | + ); |
|
874 | + } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | |
878 | 878 | |
@@ -901,14 +901,14 @@ discard block |
||
901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
902 | 902 | //the plugin mainfile's path upon construction. |
903 | 903 | register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
904 | - // call any additional admin_callback functions during load_admin_controller hook |
|
905 | - if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | - add_action( |
|
907 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | - ); |
|
910 | - } |
|
911 | - return $addon; |
|
904 | + // call any additional admin_callback functions during load_admin_controller hook |
|
905 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | + add_action( |
|
907 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | + ); |
|
910 | + } |
|
911 | + return $addon; |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | // cycle thru settings |
925 | 925 | foreach ( self::$_settings as $settings ) { |
926 | 926 | if ( ! empty( $settings['pue_options'] ) ) { |
927 | - // initiate the class and start the plugin update engine! |
|
927 | + // initiate the class and start the plugin update engine! |
|
928 | 928 | new PluginUpdateEngineChecker( |
929 | 929 | // host file URL |
930 | 930 | 'https://eventespresso.com', |
@@ -960,11 +960,11 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public static function register_message_types() { |
962 | 962 | foreach ( self::$_settings as $addon_name => $settings ) { |
963 | - if ( ! empty($settings['message_types'])) { |
|
964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | - } |
|
967 | - } |
|
963 | + if ( ! empty($settings['message_types'])) { |
|
964 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | + } |
|
967 | + } |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
@@ -1006,15 +1006,15 @@ discard block |
||
1006 | 1006 | EE_Register_Widget::deregister( $addon_name ); |
1007 | 1007 | } |
1008 | 1008 | if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
1009 | - || |
|
1010 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1009 | + || |
|
1010 | + ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1011 | 1011 | ) { |
1012 | 1012 | // add to list of shortcodes to be registered |
1013 | 1013 | EE_Register_Model::deregister( $addon_name ); |
1014 | 1014 | } |
1015 | 1015 | if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
1016 | - || |
|
1017 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1016 | + || |
|
1017 | + ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1018 | 1018 | ) { |
1019 | 1019 | // add to list of shortcodes to be registered |
1020 | 1020 | EE_Register_Model_Extensions::deregister( $addon_name ); |
@@ -187,6 +187,7 @@ |
||
187 | 187 | * when retrieving cached registrations from a transaction |
188 | 188 | * @param bool $trigger_notifications whether or not to call |
189 | 189 | * \EE_Registration_Processor::trigger_registration_update_notifications() |
190 | + * @param EE_Payment $payment |
|
190 | 191 | * @return array |
191 | 192 | * @throws \EE_Error |
192 | 193 | */ |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * the interaction of EE_Transaction and EE_Registration model objects |
8 | 8 | * Provides methods for manipulating and processing changes to an EE_Transaction |
9 | 9 | * and it's related EE_Registrations with regards to the checkout/registration process |
10 | - |
|
11 | -* |
|
10 | + * |
|
12 | 11 | *@package Event Espresso |
13 | 12 | * @subpackage core |
14 | 13 | * @author Brent Christensen |
@@ -177,24 +176,24 @@ discard block |
||
177 | 176 | |
178 | 177 | |
179 | 178 | |
180 | - /** |
|
181 | - * update_transaction_and_registrations_after_checkout_or_payment |
|
182 | - * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
183 | - * |
|
184 | - * @param EE_Transaction $transaction |
|
185 | - * @param \EE_Payment | NULL $payment |
|
186 | - * @param array $registration_query_params array of query WHERE params to use |
|
187 | - * when retrieving cached registrations from a transaction |
|
188 | - * @param bool $trigger_notifications whether or not to call |
|
189 | - * \EE_Registration_Processor::trigger_registration_update_notifications() |
|
190 | - * @return array |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
179 | + /** |
|
180 | + * update_transaction_and_registrations_after_checkout_or_payment |
|
181 | + * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
182 | + * |
|
183 | + * @param EE_Transaction $transaction |
|
184 | + * @param \EE_Payment | NULL $payment |
|
185 | + * @param array $registration_query_params array of query WHERE params to use |
|
186 | + * when retrieving cached registrations from a transaction |
|
187 | + * @param bool $trigger_notifications whether or not to call |
|
188 | + * \EE_Registration_Processor::trigger_registration_update_notifications() |
|
189 | + * @return array |
|
190 | + * @throws \EE_Error |
|
191 | + */ |
|
193 | 192 | public function update_transaction_and_registrations_after_checkout_or_payment( |
194 | 193 | EE_Transaction $transaction, |
195 | 194 | $payment = null, |
196 | 195 | $registration_query_params = array(), |
197 | - $trigger_notifications = true |
|
196 | + $trigger_notifications = true |
|
198 | 197 | ) { |
199 | 198 | // make sure some query params are set for retrieving registrations |
200 | 199 | $this->_set_registration_query_params( $registration_query_params ); |
@@ -224,15 +223,15 @@ discard block |
||
224 | 223 | $update_params |
225 | 224 | ); |
226 | 225 | if ($trigger_notifications) { |
227 | - // send messages |
|
228 | - /** @type EE_Registration_Processor $registration_processor */ |
|
229 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
230 | - $registration_processor->trigger_registration_update_notifications( |
|
231 | - $transaction->primary_registration(), |
|
232 | - $update_params |
|
233 | - ); |
|
234 | - } |
|
235 | - do_action( |
|
226 | + // send messages |
|
227 | + /** @type EE_Registration_Processor $registration_processor */ |
|
228 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
229 | + $registration_processor->trigger_registration_update_notifications( |
|
230 | + $transaction->primary_registration(), |
|
231 | + $update_params |
|
232 | + ); |
|
233 | + } |
|
234 | + do_action( |
|
236 | 235 | 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', |
237 | 236 | $transaction, |
238 | 237 | $update_params |
@@ -522,7 +521,7 @@ discard block |
||
522 | 521 | foreach ( $available_payment_methods as $available_payment_method ) { |
523 | 522 | if ( |
524 | 523 | $available_payment_method instanceof EE_Payment_Method |
525 | - && $available_payment_method->open_by_default() |
|
524 | + && $available_payment_method->open_by_default() |
|
526 | 525 | ) { |
527 | 526 | $PMD_ID = $available_payment_method->ID(); |
528 | 527 | break; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
2 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class EE_Transaction_Processor |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * @param array $registration_query_params |
51 | 51 | *@return EE_Transaction_Processor instance |
52 | 52 | */ |
53 | - public static function instance( $registration_query_params = array() ) { |
|
53 | + public static function instance($registration_query_params = array()) { |
|
54 | 54 | // check if class object is instantiated |
55 | - if ( ! self::$_instance instanceof EE_Transaction_Processor ) { |
|
56 | - self::$_instance = new self( $registration_query_params ); |
|
55 | + if ( ! self::$_instance instanceof EE_Transaction_Processor) { |
|
56 | + self::$_instance = new self($registration_query_params); |
|
57 | 57 | } |
58 | 58 | return self::$_instance; |
59 | 59 | } |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @param array $registration_query_params |
65 | 65 | */ |
66 | - private function __construct( $registration_query_params = array() ) { |
|
66 | + private function __construct($registration_query_params = array()) { |
|
67 | 67 | // make sure some query params are set for retrieving registrations |
68 | - $this->_set_registration_query_params( $registration_query_params ); |
|
68 | + $this->_set_registration_query_params($registration_query_params); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @access private |
75 | 75 | * @param array $registration_query_params |
76 | 76 | */ |
77 | - private function _set_registration_query_params( $registration_query_params ) { |
|
78 | - $this->_registration_query_params = ! empty( $registration_query_params ) ? $registration_query_params : array( 'order_by' => array( 'REG_count' => 'ASC' )); |
|
77 | + private function _set_registration_query_params($registration_query_params) { |
|
78 | + $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params : array('order_by' => array('REG_count' => 'ASC')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | ); |
105 | 105 | // send messages |
106 | 106 | /** @type EE_Registration_Processor $registration_processor */ |
107 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
107 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
108 | 108 | $registration_processor->trigger_registration_update_notifications( |
109 | 109 | $transaction->primary_registration(), |
110 | - array( 'manually_updated' => true ) |
|
110 | + array('manually_updated' => true) |
|
111 | 111 | ); |
112 | 112 | do_action( |
113 | 113 | 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | $trigger_notifications = true |
198 | 198 | ) { |
199 | 199 | // make sure some query params are set for retrieving registrations |
200 | - $this->_set_registration_query_params( $registration_query_params ); |
|
200 | + $this->_set_registration_query_params($registration_query_params); |
|
201 | 201 | // get final reg step status |
202 | 202 | $finalized = $transaction->final_reg_step_completed(); |
203 | 203 | // if the 'finalize_registration' step has been initiated (has a timestamp) |
204 | 204 | // but has not yet been fully completed (TRUE) |
205 | - if ( is_int( $finalized ) && $finalized !== false && $finalized !== true ) { |
|
206 | - $transaction->set_reg_step_completed( 'finalize_registration' ); |
|
205 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
206 | + $transaction->set_reg_step_completed('finalize_registration'); |
|
207 | 207 | $finalized = true; |
208 | 208 | } |
209 | 209 | $transaction->save(); |
@@ -258,22 +258,22 @@ discard block |
||
258 | 258 | $update_txn = true |
259 | 259 | ) { |
260 | 260 | // these reg statuses should not be considered in any calculations involving monies owing |
261 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
262 | - if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
261 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
262 | + if (in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | try { |
266 | - $transaction = $this->get_transaction_for_registration( $registration ); |
|
266 | + $transaction = $this->get_transaction_for_registration($registration); |
|
267 | 267 | $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( |
268 | 268 | $transaction, |
269 | 269 | $registration |
270 | 270 | ); |
271 | 271 | // un-cancel the ticket |
272 | - $success = EEH_Line_Item::reinstate_canceled_ticket_line_item( $ticket_line_item ); |
|
273 | - } catch ( EE_Error $e ) { |
|
272 | + $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item); |
|
273 | + } catch (EE_Error $e) { |
|
274 | 274 | EE_Error::add_error( |
275 | 275 | sprintf( |
276 | - __( 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso' ), |
|
276 | + __('The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', 'event_espresso'), |
|
277 | 277 | $registration->ID(), |
278 | 278 | '<br />', |
279 | 279 | $e->getMessage() |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | ); |
283 | 283 | return false; |
284 | 284 | } |
285 | - if ( $update_txn ) { |
|
285 | + if ($update_txn) { |
|
286 | 286 | return $transaction->save() ? $success : false; |
287 | 287 | } |
288 | 288 | return $success; |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | $update_txn = true |
307 | 307 | ) { |
308 | 308 | // these reg statuses should not be considered in any calculations involving monies owing |
309 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
310 | - if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
309 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
310 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | try { |
314 | - $transaction = $this->get_transaction_for_registration( $registration ); |
|
315 | - $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration( $transaction, $registration ); |
|
316 | - EEH_Line_Item::cancel_ticket_line_item( $ticket_line_item ); |
|
317 | - } catch ( EE_Error $e ) { |
|
314 | + $transaction = $this->get_transaction_for_registration($registration); |
|
315 | + $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration($transaction, $registration); |
|
316 | + EEH_Line_Item::cancel_ticket_line_item($ticket_line_item); |
|
317 | + } catch (EE_Error $e) { |
|
318 | 318 | EE_Error::add_error( |
319 | 319 | sprintf( |
320 | - __( 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso' ), |
|
320 | + __('The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', 'event_espresso'), |
|
321 | 321 | $registration->ID(), |
322 | 322 | '<br />', |
323 | 323 | $e->getMessage() |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ); |
327 | 327 | return false; |
328 | 328 | } |
329 | - if ( $update_txn ) { |
|
329 | + if ($update_txn) { |
|
330 | 330 | return $transaction->save() ? true : false; |
331 | 331 | } |
332 | 332 | return true; |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | * @return EE_Transaction |
343 | 343 | * @throws EE_Error |
344 | 344 | */ |
345 | - public function get_transaction_for_registration( EE_Registration $registration ) { |
|
345 | + public function get_transaction_for_registration(EE_Registration $registration) { |
|
346 | 346 | $transaction = $registration->transaction(); |
347 | - if ( ! $transaction instanceof EE_Transaction ) { |
|
347 | + if ( ! $transaction instanceof EE_Transaction) { |
|
348 | 348 | throw new EE_Error( |
349 | 349 | sprintf( |
350 | - __( 'The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso' ), |
|
350 | + __('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'), |
|
351 | 351 | $registration->ID() |
352 | 352 | ) |
353 | 353 | ); |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | EE_Transaction $transaction, |
371 | 371 | EE_Registration $registration |
372 | 372 | ) { |
373 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
373 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
374 | 374 | $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction( |
375 | 375 | $transaction->ID(), |
376 | 376 | $registration->ticket_ID() |
377 | 377 | ); |
378 | - if ( ! $ticket_line_item instanceof EE_Line_Item ) { |
|
378 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
379 | 379 | throw new EE_Error( |
380 | 380 | sprintf( |
381 | - __( 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
382 | - 'event_espresso' ), |
|
381 | + __('The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
382 | + 'event_espresso'), |
|
383 | 383 | $transaction->ID(), |
384 | 384 | $registration->ticket_ID() |
385 | 385 | ) |
@@ -412,22 +412,22 @@ discard block |
||
412 | 412 | $update_txn = true |
413 | 413 | ) { |
414 | 414 | // make sure some query params are set for retrieving registrations |
415 | - $this->_set_registration_query_params( $registration_query_params ); |
|
415 | + $this->_set_registration_query_params($registration_query_params); |
|
416 | 416 | // these reg statuses should not be considered in any calculations involving monies owing |
417 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
417 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses : EEM_Registration::closed_reg_statuses(); |
|
418 | 418 | // loop through cached registrations |
419 | - foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) { |
|
419 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
420 | 420 | if ( |
421 | 421 | $registration instanceof EE_Registration |
422 | - && ! in_array( $registration->status_ID(), $closed_reg_statuses ) |
|
422 | + && ! in_array($registration->status_ID(), $closed_reg_statuses) |
|
423 | 423 | ) { |
424 | 424 | return false; |
425 | 425 | } |
426 | 426 | } |
427 | - if ( in_array( $new_TXN_status, EEM_Transaction::txn_status_array() ) ) { |
|
428 | - $transaction->set_status( $new_TXN_status ); |
|
427 | + if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) { |
|
428 | + $transaction->set_status($new_TXN_status); |
|
429 | 429 | } |
430 | - if ( $update_txn ) { |
|
430 | + if ($update_txn) { |
|
431 | 431 | return $transaction->save() ? true : false; |
432 | 432 | } |
433 | 433 | return true; |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | ) { |
457 | 457 | $response = false; |
458 | 458 | /** @type EE_Registration_Processor $registration_processor */ |
459 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
459 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
460 | 460 | // check that method exists |
461 | - if ( ! method_exists( $registration_processor, $method_name )) { |
|
462 | - throw new EE_Error( __( 'Method does not exist.', 'event_espresso' )); |
|
461 | + if ( ! method_exists($registration_processor, $method_name)) { |
|
462 | + throw new EE_Error(__('Method does not exist.', 'event_espresso')); |
|
463 | 463 | } |
464 | 464 | // make sure some query params are set for retrieving registrations |
465 | - $this->_set_registration_query_params( $registration_query_params ); |
|
465 | + $this->_set_registration_query_params($registration_query_params); |
|
466 | 466 | // loop through cached registrations |
467 | - foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) { |
|
468 | - if ( $registration instanceof EE_Registration ) { |
|
469 | - if ( $additional_param ) { |
|
470 | - $response = $registration_processor->{$method_name}( $registration, $additional_param ) |
|
467 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
468 | + if ($registration instanceof EE_Registration) { |
|
469 | + if ($additional_param) { |
|
470 | + $response = $registration_processor->{$method_name}($registration, $additional_param) |
|
471 | 471 | ? true |
472 | 472 | : $response; |
473 | 473 | } else { |
474 | - $response = $registration_processor->{$method_name}( $registration ) |
|
474 | + $response = $registration_processor->{$method_name}($registration) |
|
475 | 475 | ? true |
476 | 476 | : $response; |
477 | 477 | } |
@@ -498,28 +498,28 @@ discard block |
||
498 | 498 | public function set_transaction_payment_method_based_on_registration_statuses( |
499 | 499 | EE_Registration $edited_registration |
500 | 500 | ) { |
501 | - if ( $edited_registration instanceof EE_Registration ) { |
|
501 | + if ($edited_registration instanceof EE_Registration) { |
|
502 | 502 | $transaction = $edited_registration->transaction(); |
503 | - if ( $transaction instanceof EE_Transaction ) { |
|
503 | + if ($transaction instanceof EE_Transaction) { |
|
504 | 504 | $all_not_approved = true; |
505 | - foreach ( $transaction->registrations() as $registration ) { |
|
506 | - if ( $registration instanceof EE_Registration ) { |
|
505 | + foreach ($transaction->registrations() as $registration) { |
|
506 | + if ($registration instanceof EE_Registration) { |
|
507 | 507 | // if any REG != "Not Approved" then toggle to false |
508 | 508 | $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false; |
509 | 509 | } |
510 | 510 | } |
511 | 511 | // if ALL Registrations are "Not Approved" |
512 | - if ( $all_not_approved ) { |
|
513 | - $transaction->set_payment_method_ID( null ); |
|
512 | + if ($all_not_approved) { |
|
513 | + $transaction->set_payment_method_ID(null); |
|
514 | 514 | $transaction->save(); |
515 | 515 | } else { |
516 | 516 | $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
517 | 517 | $transaction, |
518 | 518 | EEM_Payment_Method::scope_cart |
519 | 519 | ); |
520 | - if ( ! empty( $available_payment_methods ) ) { |
|
520 | + if ( ! empty($available_payment_methods)) { |
|
521 | 521 | $PMD_ID = 0; |
522 | - foreach ( $available_payment_methods as $available_payment_method ) { |
|
522 | + foreach ($available_payment_methods as $available_payment_method) { |
|
523 | 523 | if ( |
524 | 524 | $available_payment_method instanceof EE_Payment_Method |
525 | 525 | && $available_payment_method->open_by_default() |
@@ -528,22 +528,22 @@ discard block |
||
528 | 528 | break; |
529 | 529 | } |
530 | 530 | } |
531 | - if ( ! $PMD_ID ) { |
|
532 | - $first_payment_method = reset( $available_payment_methods ); |
|
533 | - if ( $first_payment_method instanceof EE_Payment_Method ) { |
|
531 | + if ( ! $PMD_ID) { |
|
532 | + $first_payment_method = reset($available_payment_methods); |
|
533 | + if ($first_payment_method instanceof EE_Payment_Method) { |
|
534 | 534 | $PMD_ID = $first_payment_method->ID(); |
535 | 535 | } else { |
536 | 536 | EE_Error::add_error( |
537 | - __( 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso' ), |
|
537 | + __('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'), |
|
538 | 538 | __FILE__, __LINE__, __FUNCTION__ |
539 | 539 | ); |
540 | 540 | } |
541 | 541 | } |
542 | - $transaction->set_payment_method_ID( $PMD_ID ); |
|
542 | + $transaction->set_payment_method_ID($PMD_ID); |
|
543 | 543 | $transaction->save(); |
544 | 544 | } else { |
545 | 545 | EE_Error::add_error( |
546 | - __( 'Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso' ), |
|
546 | + __('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'), |
|
547 | 547 | __FILE__, __LINE__, __FUNCTION__ |
548 | 548 | ); |
549 | 549 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @deprecated 4.9.12 |
581 | 581 | * @param string $old_txn_status |
582 | 582 | */ |
583 | - public function set_old_txn_status( $old_txn_status ) { |
|
583 | + public function set_old_txn_status($old_txn_status) { |
|
584 | 584 | EE_Error::doing_it_wrong( |
585 | 585 | __METHOD__, |
586 | 586 | esc_html__( |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | '4.9.12' |
591 | 591 | ); |
592 | 592 | // only set the first time |
593 | - if ( $this->_old_txn_status === null ) { |
|
593 | + if ($this->_old_txn_status === null) { |
|
594 | 594 | $this->_old_txn_status = $old_txn_status; |
595 | 595 | } |
596 | 596 | } |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | * @deprecated 4.9.12 |
620 | 620 | * @param string $new_txn_status |
621 | 621 | */ |
622 | - public function set_new_txn_status( $new_txn_status ) { |
|
622 | + public function set_new_txn_status($new_txn_status) { |
|
623 | 623 | EE_Error::doing_it_wrong( |
624 | 624 | __METHOD__, |
625 | 625 | esc_html__( |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | * @param EE_Transaction $transaction |
664 | 664 | * @return boolean |
665 | 665 | */ |
666 | - public function all_reg_steps_completed( EE_Transaction $transaction ) { |
|
666 | + public function all_reg_steps_completed(EE_Transaction $transaction) { |
|
667 | 667 | EE_Error::doing_it_wrong( |
668 | 668 | __METHOD__, |
669 | 669 | esc_html__( |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | * @param string $exception |
691 | 691 | * @return boolean |
692 | 692 | */ |
693 | - public function all_reg_steps_completed_except( EE_Transaction $transaction, $exception = '' ) { |
|
693 | + public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') { |
|
694 | 694 | EE_Error::doing_it_wrong( |
695 | 695 | __METHOD__, |
696 | 696 | esc_html__( |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | '4.9.12', |
701 | 701 | '5.0.0' |
702 | 702 | ); |
703 | - return $transaction->all_reg_steps_completed_except( $exception ); |
|
703 | + return $transaction->all_reg_steps_completed_except($exception); |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | * @param EE_Transaction $transaction |
717 | 717 | * @return boolean |
718 | 718 | */ |
719 | - public function all_reg_steps_completed_except_final_step( EE_Transaction $transaction ) { |
|
719 | + public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) { |
|
720 | 720 | EE_Error::doing_it_wrong( |
721 | 721 | __METHOD__, |
722 | 722 | esc_html__( |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | * @param string $reg_step_slug |
744 | 744 | * @return boolean | int |
745 | 745 | */ |
746 | - public function reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
746 | + public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
747 | 747 | EE_Error::doing_it_wrong( |
748 | 748 | __METHOD__, |
749 | 749 | esc_html__( |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | '4.9.12', |
754 | 754 | '5.0.0' |
755 | 755 | ); |
756 | - return $transaction->reg_step_completed( $reg_step_slug ); |
|
756 | + return $transaction->reg_step_completed($reg_step_slug); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | * @param EE_Transaction $transaction |
770 | 770 | * @return boolean | int |
771 | 771 | */ |
772 | - public function final_reg_step_completed( EE_Transaction $transaction ) { |
|
772 | + public function final_reg_step_completed(EE_Transaction $transaction) { |
|
773 | 773 | EE_Error::doing_it_wrong( |
774 | 774 | __METHOD__, |
775 | 775 | esc_html__( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @return boolean |
796 | 796 | * @throws \EE_Error |
797 | 797 | */ |
798 | - public function set_reg_step_initiated( EE_Transaction $transaction, $reg_step_slug ) { |
|
798 | + public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) { |
|
799 | 799 | EE_Error::doing_it_wrong( |
800 | 800 | __METHOD__, |
801 | 801 | esc_html__( |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | '4.9.12', |
806 | 806 | '5.0.0' |
807 | 807 | ); |
808 | - return $transaction->set_reg_step_initiated( $reg_step_slug ); |
|
808 | + return $transaction->set_reg_step_initiated($reg_step_slug); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @return boolean |
822 | 822 | * @throws \EE_Error |
823 | 823 | */ |
824 | - public function set_reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
824 | + public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
825 | 825 | EE_Error::doing_it_wrong( |
826 | 826 | __METHOD__, |
827 | 827 | esc_html__( |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | '4.9.12', |
832 | 832 | '5.0.0' |
833 | 833 | ); |
834 | - return $transaction->set_reg_step_completed( $reg_step_slug ); |
|
834 | + return $transaction->set_reg_step_completed($reg_step_slug); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * @return boolean |
848 | 848 | * @throws \EE_Error |
849 | 849 | */ |
850 | - public function set_reg_step_not_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
850 | + public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
851 | 851 | EE_Error::doing_it_wrong( |
852 | 852 | __METHOD__, |
853 | 853 | esc_html__( |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | '4.9.12', |
858 | 858 | '5.0.0' |
859 | 859 | ); |
860 | - return $transaction->set_reg_step_not_completed( $reg_step_slug ); |
|
860 | + return $transaction->set_reg_step_not_completed($reg_step_slug); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | * @param string $reg_step_slug |
875 | 875 | * @return void |
876 | 876 | */ |
877 | - public function remove_reg_step( EE_Transaction $transaction, $reg_step_slug ) { |
|
877 | + public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) { |
|
878 | 878 | EE_Error::doing_it_wrong( |
879 | 879 | __METHOD__, |
880 | 880 | esc_html__( |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | '4.9.12', |
885 | 885 | '5.0.0' |
886 | 886 | ); |
887 | - $transaction->remove_reg_step( $reg_step_slug ); |
|
887 | + $transaction->remove_reg_step($reg_step_slug); |
|
888 | 888 | } |
889 | 889 | |
890 | 890 | |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | * @return boolean |
901 | 901 | * @throws \EE_Error |
902 | 902 | */ |
903 | - public function toggle_failed_transaction_status( EE_Transaction $transaction ) { |
|
903 | + public function toggle_failed_transaction_status(EE_Transaction $transaction) { |
|
904 | 904 | EE_Error::doing_it_wrong( |
905 | 905 | __METHOD__, |
906 | 906 | esc_html__( |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | * @param EE_Transaction $transaction |
925 | 925 | * @return boolean |
926 | 926 | */ |
927 | - public function toggle_abandoned_transaction_status( EE_Transaction $transaction ) { |
|
927 | + public function toggle_abandoned_transaction_status(EE_Transaction $transaction) { |
|
928 | 928 | EE_Error::doing_it_wrong( |
929 | 929 | __METHOD__, |
930 | 930 | esc_html__( |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | } |
216 | 216 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
217 | 217 | if ( ! EE_Processor_Base::$IPN ) { |
218 | - // otherwise, send out notifications |
|
218 | + // otherwise, send out notifications |
|
219 | 219 | add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
220 | 220 | } |
221 | 221 | // DEBUG LOG |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } |
263 | 263 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
264 | 264 | if ( ! EE_Processor_Base::$IPN ) { |
265 | - // otherwise, send out notifications |
|
265 | + // otherwise, send out notifications |
|
266 | 266 | add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
267 | 267 | } |
268 | 268 | // DEBUG LOG |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | } |
350 | 350 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
351 | 351 | if ( ! EE_Processor_Base::$IPN ) { |
352 | - // otherwise, send out notifications |
|
352 | + // otherwise, send out notifications |
|
353 | 353 | add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
354 | 354 | } |
355 | 355 | // DEBUG LOG |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | // false, |
391 | 391 | // 'EE_Transaction: ' . $registration->transaction()->ID() |
392 | 392 | // ); |
393 | - if ( ! $registration->is_primary_registrant()) { |
|
394 | - return; |
|
395 | - } |
|
396 | - do_action( |
|
393 | + if ( ! $registration->is_primary_registrant()) { |
|
394 | + return; |
|
395 | + } |
|
396 | + do_action( |
|
397 | 397 | 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
398 | 398 | $registration, |
399 | 399 | $additional_details |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | // set new REG_Status |
429 | 429 | $this->set_new_reg_status( $registration->ID(), $registration->status_ID() ); |
430 | 430 | return $this->reg_status_updated( $registration->ID() ) |
431 | - && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
431 | + && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
432 | 432 | ? true |
433 | 433 | : false; |
434 | 434 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | use EventEspresso\core\domain\entities\RegUrlLink; |
4 | 4 | use EventEspresso\core\domain\services\registration\CreateRegistrationService; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
7 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
7 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Class EE_Registration_Processor |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function instance() { |
68 | 68 | // check if class object is instantiated |
69 | - if ( ! self::$_instance instanceof EE_Registration_Processor ) { |
|
69 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @param int $REG_ID |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function old_reg_status( $REG_ID ) { |
|
90 | - return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
89 | + public function old_reg_status($REG_ID) { |
|
90 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * @param int $REG_ID |
97 | 97 | * @param string $old_reg_status |
98 | 98 | */ |
99 | - public function set_old_reg_status( $REG_ID, $old_reg_status ) { |
|
99 | + public function set_old_reg_status($REG_ID, $old_reg_status) { |
|
100 | 100 | // only set the first time |
101 | - if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) { |
|
102 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
101 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
102 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @param int $REG_ID |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function new_reg_status( $REG_ID ) { |
|
113 | - return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
112 | + public function new_reg_status($REG_ID) { |
|
113 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param int $REG_ID |
120 | 120 | * @param string $new_reg_status |
121 | 121 | */ |
122 | - public function set_new_reg_status( $REG_ID, $new_reg_status ) { |
|
123 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
122 | + public function set_new_reg_status($REG_ID, $new_reg_status) { |
|
123 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param int $REG_ID |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function reg_status_updated( $REG_ID ) { |
|
135 | - return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false; |
|
134 | + public function reg_status_updated($REG_ID) { |
|
135 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param \EE_Registration $registration |
142 | 142 | * @throws \EE_Error |
143 | 143 | */ |
144 | - public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) { |
|
145 | - $this->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
146 | - $this->toggle_registration_status_for_default_approved_events( $registration, false ); |
|
147 | - $this->toggle_registration_status_if_no_monies_owing( $registration, false ); |
|
144 | + public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) { |
|
145 | + $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
146 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
147 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
148 | 148 | $registration->save(); |
149 | 149 | // trigger notifications |
150 | - $this->trigger_registration_update_notifications( $registration ); |
|
150 | + $this->trigger_registration_update_notifications($registration); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -162,18 +162,18 @@ discard block |
||
162 | 162 | * @return boolean |
163 | 163 | * @throws \EE_Error |
164 | 164 | */ |
165 | - public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) { |
|
165 | + public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) { |
|
166 | 166 | // set initial REG_Status |
167 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
167 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
168 | 168 | // set incoming REG_Status |
169 | - $this->set_new_reg_status( $registration->ID(), $new_reg_status ); |
|
169 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
170 | 170 | // toggle reg status but only if it has changed and the user can do so |
171 | 171 | if ( |
172 | - $this->reg_status_updated( $registration->ID() ) && |
|
173 | - EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() ) |
|
172 | + $this->reg_status_updated($registration->ID()) && |
|
173 | + EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID()) |
|
174 | 174 | ) { |
175 | 175 | // change status to new value |
176 | - if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) { |
|
176 | + if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) { |
|
177 | 177 | $registration->save(); |
178 | 178 | } |
179 | 179 | return TRUE; |
@@ -193,30 +193,30 @@ discard block |
||
193 | 193 | * @return void |
194 | 194 | * @throws \EE_Error |
195 | 195 | */ |
196 | - public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) { |
|
196 | + public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) { |
|
197 | 197 | $existing_reg_status = $registration->status_ID(); |
198 | 198 | // set initial REG_Status |
199 | - $this->set_old_reg_status( $registration->ID(), $existing_reg_status ); |
|
199 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
200 | 200 | // is the registration currently incomplete ? |
201 | - if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) { |
|
201 | + if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
202 | 202 | // grab default reg status for the event, if set |
203 | 203 | $event_default_registration_status = $registration->event()->default_registration_status(); |
204 | 204 | // if no default reg status is set for the event, then use the global value |
205 | - $STS_ID = ! empty( $event_default_registration_status ) |
|
205 | + $STS_ID = ! empty($event_default_registration_status) |
|
206 | 206 | ? $event_default_registration_status |
207 | 207 | : EE_Registry::instance()->CFG->registration->default_STS_ID; |
208 | 208 | // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
209 | 209 | $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID; |
210 | 210 | // set incoming REG_Status |
211 | - $this->set_new_reg_status( $registration->ID(), $STS_ID ); |
|
212 | - $registration->set_status( $STS_ID ); |
|
213 | - if ( $save ) { |
|
211 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
212 | + $registration->set_status($STS_ID); |
|
213 | + if ($save) { |
|
214 | 214 | $registration->save(); |
215 | 215 | } |
216 | 216 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
217 | - if ( ! EE_Processor_Base::$IPN ) { |
|
217 | + if ( ! EE_Processor_Base::$IPN) { |
|
218 | 218 | // otherwise, send out notifications |
219 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
219 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
220 | 220 | } |
221 | 221 | // DEBUG LOG |
222 | 222 | //$this->log( |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | * @return boolean |
242 | 242 | * @throws \EE_Error |
243 | 243 | */ |
244 | - public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) { |
|
244 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) { |
|
245 | 245 | $reg_status = $registration->status_ID(); |
246 | 246 | // set initial REG_Status |
247 | - $this->set_old_reg_status( $registration->ID(), $reg_status ); |
|
247 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
248 | 248 | // if not already, toggle reg status to approved IF the event default reg status is approved |
249 | 249 | // ( as long as the registration wasn't cancelled or declined at some point ) |
250 | 250 | if ( |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
255 | 255 | ) { |
256 | 256 | // set incoming REG_Status |
257 | - $this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved ); |
|
257 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
258 | 258 | // toggle status to approved |
259 | - $registration->set_status( EEM_Registration::status_id_approved ); |
|
260 | - if ( $save ) { |
|
259 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
260 | + if ($save) { |
|
261 | 261 | $registration->save(); |
262 | 262 | } |
263 | 263 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
264 | - if ( ! EE_Processor_Base::$IPN ) { |
|
264 | + if ( ! EE_Processor_Base::$IPN) { |
|
265 | 265 | // otherwise, send out notifications |
266 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
266 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
267 | 267 | } |
268 | 268 | // DEBUG LOG |
269 | 269 | //$this->log( |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | * @throws \EE_Error |
293 | 293 | */ |
294 | - public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) { |
|
294 | + public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) { |
|
295 | 295 | // set initial REG_Status |
296 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
296 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
297 | 297 | //EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ ); |
298 | 298 | // was a payment just made ? |
299 | 299 | if ( |
300 | - isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) && |
|
301 | - $additional_details[ 'payment_updates' ] && |
|
302 | - $additional_details[ 'last_payment' ] instanceof EE_Payment |
|
300 | + isset($additional_details['payment_updates'], $additional_details['last_payment']) && |
|
301 | + $additional_details['payment_updates'] && |
|
302 | + $additional_details['last_payment'] instanceof EE_Payment |
|
303 | 303 | ) { |
304 | - $payment = $additional_details[ 'last_payment' ]; |
|
304 | + $payment = $additional_details['last_payment']; |
|
305 | 305 | $total_paid = 0; |
306 | - foreach ( self::$_amount_paid as $reg => $amount_paid ) { |
|
306 | + foreach (self::$_amount_paid as $reg => $amount_paid) { |
|
307 | 307 | $total_paid += $amount_paid; |
308 | 308 | } |
309 | 309 | } else { |
@@ -327,30 +327,30 @@ discard block |
||
327 | 327 | $registration->transaction()->is_completed() || |
328 | 328 | $registration->transaction()->is_overpaid() || |
329 | 329 | $registration->transaction()->is_free() || |
330 | - apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration ) |
|
330 | + apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration) |
|
331 | 331 | ) || ( |
332 | 332 | $payment instanceof EE_Payment && |
333 | 333 | $payment->is_approved() && |
334 | 334 | // this specific registration has not yet been paid for |
335 | - ! isset( self::$_amount_paid[ $registration->ID() ] ) && |
|
335 | + ! isset(self::$_amount_paid[$registration->ID()]) && |
|
336 | 336 | // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
337 | 337 | $payment->amount() - $total_paid >= $registration->final_price() |
338 | 338 | ) |
339 | 339 | ) |
340 | 340 | ) { |
341 | 341 | // mark as paid |
342 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
342 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
343 | 343 | // track new REG_Status |
344 | - $this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved ); |
|
344 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
345 | 345 | // toggle status to approved |
346 | - $registration->set_status( EEM_Registration::status_id_approved ); |
|
347 | - if ( $save ) { |
|
346 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
347 | + if ($save) { |
|
348 | 348 | $registration->save(); |
349 | 349 | } |
350 | 350 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
351 | - if ( ! EE_Processor_Base::$IPN ) { |
|
351 | + if ( ! EE_Processor_Base::$IPN) { |
|
352 | 352 | // otherwise, send out notifications |
353 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
353 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
354 | 354 | } |
355 | 355 | // DEBUG LOG |
356 | 356 | //$this->log( |
@@ -376,10 +376,10 @@ discard block |
||
376 | 376 | * @param array $additional_details |
377 | 377 | * @return void |
378 | 378 | */ |
379 | - public function trigger_registration_update_notifications( $registration, $additional_details = array() ) { |
|
379 | + public function trigger_registration_update_notifications($registration, $additional_details = array()) { |
|
380 | 380 | try { |
381 | - if ( ! $registration instanceof EE_Registration ) { |
|
382 | - throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) ); |
|
381 | + if ( ! $registration instanceof EE_Registration) { |
|
382 | + throw new EE_Error(__('An invalid registration was received.', 'event_espresso')); |
|
383 | 383 | } |
384 | 384 | // EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
385 | 385 | // EEH_Debug_Tools::log( |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | $registration, |
399 | 399 | $additional_details |
400 | 400 | ); |
401 | - } catch( Exception $e ) { |
|
402 | - EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() ); |
|
401 | + } catch (Exception $e) { |
|
402 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
@@ -413,22 +413,22 @@ discard block |
||
413 | 413 | * @return bool |
414 | 414 | * @throws \EE_Error |
415 | 415 | */ |
416 | - public function update_registration_after_checkout_or_payment( EE_Registration $registration, $additional_details = array() ) { |
|
416 | + public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) { |
|
417 | 417 | // set initial REG_Status |
418 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
418 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
419 | 419 | |
420 | 420 | // if the registration status gets updated, then save the registration |
421 | 421 | if ( |
422 | - $this->toggle_registration_status_for_default_approved_events( $registration, false ) |
|
423 | - || $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details ) |
|
422 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
423 | + || $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details) |
|
424 | 424 | ) { |
425 | 425 | $registration->save(); |
426 | 426 | } |
427 | 427 | |
428 | 428 | // set new REG_Status |
429 | - $this->set_new_reg_status( $registration->ID(), $registration->status_ID() ); |
|
430 | - return $this->reg_status_updated( $registration->ID() ) |
|
431 | - && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
429 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
430 | + return $this->reg_status_updated($registration->ID()) |
|
431 | + && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved |
|
432 | 432 | ? true |
433 | 433 | : false; |
434 | 434 | } |
@@ -444,20 +444,20 @@ discard block |
||
444 | 444 | * @return void |
445 | 445 | * @throws \EE_Error |
446 | 446 | */ |
447 | - public function update_registration_final_prices( $transaction, $save_regs = true ) { |
|
448 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() ); |
|
449 | - foreach( $transaction->registrations() as $registration ) { |
|
447 | + public function update_registration_final_prices($transaction, $save_regs = true) { |
|
448 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item()); |
|
449 | + foreach ($transaction->registrations() as $registration) { |
|
450 | 450 | /** @var EE_Line_Item $line_item */ |
451 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration ); |
|
452 | - if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) { |
|
453 | - $registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ); |
|
454 | - if( $save_regs ) { |
|
451 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
452 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
453 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
454 | + if ($save_regs) { |
|
455 | 455 | $registration->save(); |
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
459 | 459 | //and make sure there's no rounding problem |
460 | - $this->fix_reg_final_price_rounding_issue( $transaction ); |
|
460 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return boolean success verifying that there is NO difference after this method is done |
478 | 478 | * @throws \EE_Error |
479 | 479 | */ |
480 | - public function fix_reg_final_price_rounding_issue( $transaction ) { |
|
480 | + public function fix_reg_final_price_rounding_issue($transaction) { |
|
481 | 481 | $reg_final_price_sum = EEM_Registration::instance()->sum( |
482 | 482 | array( |
483 | 483 | array( |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | ), |
487 | 487 | 'REG_final_price' |
488 | 488 | ); |
489 | - $diff = $transaction->total() - (float) $reg_final_price_sum; |
|
489 | + $diff = $transaction->total() - (float) $reg_final_price_sum; |
|
490 | 490 | //ok then, just grab one of the registrations |
491 | - if( $diff !== 0 ) { |
|
491 | + if ($diff !== 0) { |
|
492 | 492 | $a_reg = EEM_Registration::instance()->get_one( |
493 | 493 | array( |
494 | 494 | array( |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | )); |
498 | 498 | $success = $a_reg instanceof EE_Registration |
499 | 499 | ? $a_reg->save( |
500 | - array( 'REG_final_price' => $a_reg->final_price() + $diff ) |
|
500 | + array('REG_final_price' => $a_reg->final_price() + $diff) |
|
501 | 501 | ) |
502 | 502 | : false; |
503 | 503 | return $success ? true : false; |
@@ -522,13 +522,13 @@ discard block |
||
522 | 522 | $update_reg = true |
523 | 523 | ) { |
524 | 524 | // these reg statuses should not be considered in any calculations involving monies owing |
525 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses |
|
525 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
526 | 526 | : EEM_Registration::closed_reg_statuses(); |
527 | - if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
527 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
528 | 528 | return false; |
529 | 529 | } |
530 | 530 | $registration->set_final_price(0); |
531 | - if ( $update_reg ) { |
|
531 | + if ($update_reg) { |
|
532 | 532 | $registration->save(); |
533 | 533 | } |
534 | 534 | return true; |
@@ -551,23 +551,23 @@ discard block |
||
551 | 551 | $update_reg = true |
552 | 552 | ) { |
553 | 553 | // these reg statuses should not be considered in any calculations involving monies owing |
554 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses |
|
554 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
555 | 555 | : EEM_Registration::closed_reg_statuses(); |
556 | - if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
556 | + if (in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | $ticket = $registration->ticket(); |
560 | - if ( ! $ticket instanceof EE_Ticket ) { |
|
560 | + if ( ! $ticket instanceof EE_Ticket) { |
|
561 | 561 | throw new EE_Error( |
562 | 562 | sprintf( |
563 | - __( 'The Ticket for Registration %1$d was not found or is invalid.', |
|
564 | - 'event_espresso' ), |
|
563 | + __('The Ticket for Registration %1$d was not found or is invalid.', |
|
564 | + 'event_espresso'), |
|
565 | 565 | $registration->ticket_ID() |
566 | 566 | ) |
567 | 567 | ); |
568 | 568 | } |
569 | - $registration->set_final_price( $ticket->price() ); |
|
570 | - if ( $update_reg ) { |
|
569 | + $registration->set_final_price($ticket->price()); |
|
570 | + if ($update_reg) { |
|
571 | 571 | $registration->save(); |
572 | 572 | } |
573 | 573 | return true; |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $total_ticket_count = 1 |
606 | 606 | ) { |
607 | 607 | EE_Error::doing_it_wrong( |
608 | - __CLASS__ . '::' . __FUNCTION__, |
|
608 | + __CLASS__.'::'.__FUNCTION__, |
|
609 | 609 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
610 | 610 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'), |
611 | 611 | '4.9.1', |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | public function generate_reg_url_link($att_nmbr, $item) |
649 | 649 | { |
650 | 650 | EE_Error::doing_it_wrong( |
651 | - __CLASS__ . '::' . __FUNCTION__, |
|
651 | + __CLASS__.'::'.__FUNCTION__, |
|
652 | 652 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
653 | 653 | 'EventEspresso\core\domain\entities\RegUrlLink'), |
654 | 654 | '4.9.1', |
@@ -668,11 +668,11 @@ discard block |
||
668 | 668 | * @return string |
669 | 669 | * @throws \EE_Error |
670 | 670 | */ |
671 | - public function generate_reg_code( EE_Registration $registration ) { |
|
671 | + public function generate_reg_code(EE_Registration $registration) { |
|
672 | 672 | EE_Error::doing_it_wrong( |
673 | - __CLASS__ . '::' . __FUNCTION__, |
|
673 | + __CLASS__.'::'.__FUNCTION__, |
|
674 | 674 | sprintf( |
675 | - __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), |
|
675 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
676 | 676 | 'EventEspresso\core\domain\entities\RegCode' |
677 | 677 | ), |
678 | 678 | '4.9.1', |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | return apply_filters( |
682 | 682 | 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
683 | 683 | new RegCode( |
684 | - RegUrlLink::fromRegistration( $registration ), |
|
684 | + RegUrlLink::fromRegistration($registration), |
|
685 | 685 | $registration->transaction(), |
686 | 686 | $registration->ticket() |
687 | 687 | ), |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - * @throws \EE_Error |
|
62 | - */ |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + * @throws \EE_Error |
|
62 | + */ |
|
63 | 63 | public function generate_reg_form() { |
64 | 64 | // create empty form so that things don't break |
65 | 65 | $this->reg_form = new EE_Form_Section_Proper(); |
@@ -68,26 +68,26 @@ discard block |
||
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return boolean |
|
73 | - * @throws \RuntimeException |
|
74 | - * @throws \EE_Error |
|
75 | - */ |
|
71 | + /** |
|
72 | + * @return boolean |
|
73 | + * @throws \RuntimeException |
|
74 | + * @throws \EE_Error |
|
75 | + */ |
|
76 | 76 | public function process_reg_step() { |
77 | - // ensure all data gets refreshed from the db |
|
77 | + // ensure all data gets refreshed from the db |
|
78 | 78 | $this->checkout->refresh_all_entities( true ); |
79 | 79 | // ensures that all details and statuses for transaction, registration, and payments are updated |
80 | 80 | $txn_update_params = $this->_finalize_transaction(); |
81 | - // maybe send messages |
|
82 | - $this->_set_notification_triggers(); |
|
83 | - // send messages |
|
84 | - /** @type EE_Registration_Processor $registration_processor */ |
|
85 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
86 | - $registration_processor->trigger_registration_update_notifications( |
|
87 | - $this->checkout->transaction->primary_registration(), |
|
88 | - $txn_update_params |
|
89 | - ); |
|
90 | - // set a hook point |
|
81 | + // maybe send messages |
|
82 | + $this->_set_notification_triggers(); |
|
83 | + // send messages |
|
84 | + /** @type EE_Registration_Processor $registration_processor */ |
|
85 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
86 | + $registration_processor->trigger_registration_update_notifications( |
|
87 | + $this->checkout->transaction->primary_registration(), |
|
88 | + $txn_update_params |
|
89 | + ); |
|
90 | + // set a hook point |
|
91 | 91 | do_action( |
92 | 92 | 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', |
93 | 93 | $this->checkout, |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | if ( |
105 | 105 | ! ( |
106 | 106 | $this->checkout->payment_method instanceof EE_Payment_Method |
107 | - && $this->checkout->payment_method->is_off_site() |
|
107 | + && $this->checkout->payment_method->is_off_site() |
|
108 | 108 | ) |
109 | 109 | ) { |
110 | 110 | // mark this reg step as completed |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | - /** |
|
120 | - * _finalize_transaction |
|
121 | - * ensures that all details and statuses for transaction, registration, and payments are updated |
|
122 | - * |
|
123 | - * @return array |
|
124 | - * @throws \RuntimeException |
|
125 | - * @throws \EE_Error |
|
126 | - */ |
|
119 | + /** |
|
120 | + * _finalize_transaction |
|
121 | + * ensures that all details and statuses for transaction, registration, and payments are updated |
|
122 | + * |
|
123 | + * @return array |
|
124 | + * @throws \RuntimeException |
|
125 | + * @throws \EE_Error |
|
126 | + */ |
|
127 | 127 | protected function _finalize_transaction() { |
128 | 128 | /** @type EE_Transaction_Processor $transaction_processor */ |
129 | 129 | $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
@@ -139,17 +139,17 @@ discard block |
||
139 | 139 | } |
140 | 140 | // maybe update status, but don't save transaction just yet |
141 | 141 | $this->checkout->transaction->update_status_based_on_total_paid( false ); |
142 | - // this will result in the base session properties getting saved to the TXN_Session_data field |
|
142 | + // this will result in the base session properties getting saved to the TXN_Session_data field |
|
143 | 143 | $this->checkout->transaction->set_txn_session_data( |
144 | 144 | EE_Registry::instance()->SSN->get_session_data( null, true ) |
145 | 145 | ); |
146 | - // update the TXN if payment conditions have changed, but do NOT trigger notifications, |
|
147 | - // because we will do that in process_reg_step() after setting some more triggers |
|
146 | + // update the TXN if payment conditions have changed, but do NOT trigger notifications, |
|
147 | + // because we will do that in process_reg_step() after setting some more triggers |
|
148 | 148 | return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
149 | 149 | $this->checkout->transaction, |
150 | 150 | $this->checkout->payment, |
151 | 151 | $this->checkout->reg_cache_where_params, |
152 | - false |
|
152 | + false |
|
153 | 153 | ); |
154 | 154 | } |
155 | 155 | |
@@ -167,43 +167,43 @@ discard block |
||
167 | 167 | protected function _set_notification_triggers() { |
168 | 168 | |
169 | 169 | if ( $this->checkout->payment_method instanceof EE_Payment_Method ) { |
170 | - // let's start with the assumption that we need to trigger notifications |
|
171 | - // then toggle this to false for conditions where we know we don't need to |
|
172 | - $deliver_notifications = true; |
|
173 | - if ( |
|
174 | - // if SPCO revisit |
|
175 | - filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN) |
|
176 | - // and TXN or REG statuses have NOT changed due to a payment |
|
177 | - && ! ( |
|
178 | - $this->checkout->transaction->txn_status_updated() |
|
179 | - || $this->checkout->any_reg_status_updated() |
|
180 | - ) |
|
181 | - ) { |
|
182 | - $deliver_notifications = false; |
|
183 | - } |
|
184 | - if ($this->checkout->payment_method->is_off_site()) { |
|
185 | - /** @var EE_Gateway $gateway */ |
|
186 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
187 | - // and the gateway uses a separate request to process the IPN |
|
188 | - if ( |
|
189 | - $gateway instanceof EE_Offsite_Gateway |
|
190 | - && $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true) |
|
191 | - ) { |
|
192 | - // IPN request will handle triggering notifications |
|
193 | - $deliver_notifications = false; |
|
194 | - // no really... don't send any notices in this request |
|
195 | - remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications'); |
|
196 | - add_filter( |
|
197 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications', |
|
198 | - '__return_false', |
|
199 | - 15 |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - if ($deliver_notifications) { |
|
204 | - // send out notifications |
|
205 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
206 | - } |
|
170 | + // let's start with the assumption that we need to trigger notifications |
|
171 | + // then toggle this to false for conditions where we know we don't need to |
|
172 | + $deliver_notifications = true; |
|
173 | + if ( |
|
174 | + // if SPCO revisit |
|
175 | + filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN) |
|
176 | + // and TXN or REG statuses have NOT changed due to a payment |
|
177 | + && ! ( |
|
178 | + $this->checkout->transaction->txn_status_updated() |
|
179 | + || $this->checkout->any_reg_status_updated() |
|
180 | + ) |
|
181 | + ) { |
|
182 | + $deliver_notifications = false; |
|
183 | + } |
|
184 | + if ($this->checkout->payment_method->is_off_site()) { |
|
185 | + /** @var EE_Gateway $gateway */ |
|
186 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
187 | + // and the gateway uses a separate request to process the IPN |
|
188 | + if ( |
|
189 | + $gateway instanceof EE_Offsite_Gateway |
|
190 | + && $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true) |
|
191 | + ) { |
|
192 | + // IPN request will handle triggering notifications |
|
193 | + $deliver_notifications = false; |
|
194 | + // no really... don't send any notices in this request |
|
195 | + remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications'); |
|
196 | + add_filter( |
|
197 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications', |
|
198 | + '__return_false', |
|
199 | + 15 |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + if ($deliver_notifications) { |
|
204 | + // send out notifications |
|
205 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
206 | + } |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * @access public |
22 | 22 | * @param EE_Checkout $checkout |
23 | 23 | */ |
24 | - public function __construct( EE_Checkout $checkout ) { |
|
24 | + public function __construct(EE_Checkout $checkout) { |
|
25 | 25 | $this->_slug = 'finalize_registration'; |
26 | - $this->_name = __( 'Finalize Registration', 'event_espresso' ); |
|
26 | + $this->_name = __('Finalize Registration', 'event_espresso'); |
|
27 | 27 | $this->_submit_button_text = $this->_name; |
28 | 28 | $this->_template = ''; |
29 | 29 | $this->checkout = $checkout; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function initialize_reg_step() { |
48 | 48 | // there's actually no reg form to process if this is the final step |
49 | - if ( $this->is_current_step() ) { |
|
49 | + if ($this->is_current_step()) { |
|
50 | 50 | $this->checkout->step = $_REQUEST['step'] = $this->slug(); |
51 | 51 | $this->checkout->action = $_REQUEST['action'] = 'process_reg_step'; |
52 | 52 | $this->checkout->generate_reg_form = false; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function process_reg_step() { |
77 | 77 | // ensure all data gets refreshed from the db |
78 | - $this->checkout->refresh_all_entities( true ); |
|
78 | + $this->checkout->refresh_all_entities(true); |
|
79 | 79 | // ensures that all details and statuses for transaction, registration, and payments are updated |
80 | 80 | $txn_update_params = $this->_finalize_transaction(); |
81 | 81 | // maybe send messages |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | $txn_update_params |
95 | 95 | ); |
96 | 96 | // check if transaction has a primary registrant and that it has a related Attendee object |
97 | - if ( ! $this->_validate_primary_registrant() ) { |
|
97 | + if ( ! $this->_validate_primary_registrant()) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | // you don't have to go home but you can't stay here ! |
101 | 101 | $this->checkout->redirect = true; |
102 | 102 | $this->checkout->continue_reg = true; |
103 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
103 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
104 | 104 | if ( |
105 | 105 | ! ( |
106 | 106 | $this->checkout->payment_method instanceof EE_Payment_Method |
@@ -126,22 +126,22 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function _finalize_transaction() { |
128 | 128 | /** @type EE_Transaction_Processor $transaction_processor */ |
129 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
129 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
130 | 130 | //set revisit flag in txn processor |
131 | - $transaction_processor->set_revisit( $this->checkout->revisit ); |
|
131 | + $transaction_processor->set_revisit($this->checkout->revisit); |
|
132 | 132 | // at this point we'll consider a TXN to not have been abandoned |
133 | 133 | $this->checkout->transaction->toggle_abandoned_transaction_status(); |
134 | - if ( $this->checkout->cart instanceof EE_Cart ) { |
|
134 | + if ($this->checkout->cart instanceof EE_Cart) { |
|
135 | 135 | // save TXN data to the cart |
136 | 136 | $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
137 | 137 | $this->checkout->transaction->ID() |
138 | 138 | ); |
139 | 139 | } |
140 | 140 | // maybe update status, but don't save transaction just yet |
141 | - $this->checkout->transaction->update_status_based_on_total_paid( false ); |
|
141 | + $this->checkout->transaction->update_status_based_on_total_paid(false); |
|
142 | 142 | // this will result in the base session properties getting saved to the TXN_Session_data field |
143 | 143 | $this->checkout->transaction->set_txn_session_data( |
144 | - EE_Registry::instance()->SSN->get_session_data( null, true ) |
|
144 | + EE_Registry::instance()->SSN->get_session_data(null, true) |
|
145 | 145 | ); |
146 | 146 | // update the TXN if payment conditions have changed, but do NOT trigger notifications, |
147 | 147 | // because we will do that in process_reg_step() after setting some more triggers |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | protected function _set_notification_triggers() { |
168 | 168 | |
169 | - if ( $this->checkout->payment_method instanceof EE_Payment_Method ) { |
|
169 | + if ($this->checkout->payment_method instanceof EE_Payment_Method) { |
|
170 | 170 | // let's start with the assumption that we need to trigger notifications |
171 | 171 | // then toggle this to false for conditions where we know we don't need to |
172 | 172 | $deliver_notifications = true; |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @throws \EE_Error |
217 | 217 | */ |
218 | 218 | protected function _validate_primary_registrant() { |
219 | - if ( ! $this->checkout->transaction_has_primary_registrant() ) { |
|
219 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
220 | 220 | EE_Error::add_error( |
221 | - __( 'A valid Primary Registration for this Transaction could not be found.', 'event_espresso' ), |
|
221 | + __('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'), |
|
222 | 222 | __FILE__, |
223 | 223 | __FUNCTION__, |
224 | 224 | __LINE__ |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | } |
230 | 230 | // setup URL for redirect |
231 | 231 | $this->checkout->redirect_url = add_query_arg( |
232 | - array( 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link() ), |
|
232 | + array('e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link()), |
|
233 | 233 | $this->checkout->thank_you_page_url |
234 | 234 | ); |
235 | 235 | return true; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function update_reg_step() { |
244 | 244 | EE_Error::doing_it_wrong( |
245 | - __CLASS__ . '::' . __FILE__, |
|
245 | + __CLASS__.'::'.__FILE__, |
|
246 | 246 | __( |
247 | 247 | 'Can not call update_reg_step() on the Finalize Registration reg step.', |
248 | 248 | 'event_espresso' |
@@ -39,7 +39,6 @@ discard block |
||
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Return the schema for a given model from a given model. |
42 | - * @param \EEM_Base $model |
|
43 | 42 | * @return array |
44 | 43 | */ |
45 | 44 | public function getModelSchema() |
@@ -103,7 +102,6 @@ discard block |
||
103 | 102 | |
104 | 103 | /** |
105 | 104 | * Outputs the schema header for a model. |
106 | - * @param \EEM_Base $model |
|
107 | 105 | * @return array |
108 | 106 | */ |
109 | 107 | public function getInitialSchemaStructure() |
@@ -24,116 +24,116 @@ |
||
24 | 24 | class JsonModelSchema |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var \EEM_Base |
|
29 | - */ |
|
30 | - protected $model; |
|
31 | - |
|
32 | - /** |
|
33 | - * JsonModelSchema constructor. |
|
34 | - * |
|
35 | - * @param \EEM_Base $model |
|
36 | - */ |
|
37 | - public function __construct(EEM_Base $model){ |
|
38 | - $this->model = $model; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Return the schema for a given model from a given model. |
|
43 | - * @param \EEM_Base $model |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function getModelSchema() |
|
47 | - { |
|
48 | - return $this->getModelSchemaForRelations( |
|
49 | - $this->model->relation_settings(), |
|
50 | - $this->getModelSchemaForFields( |
|
51 | - $this->model->field_settings(), |
|
52 | - $this->getInitialSchemaStructure() |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Get the schema for a given set of model fields. |
|
60 | - * @param \EE_Model_Field_Base[] $model_fields |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
64 | - { |
|
65 | - foreach ($model_fields as $field => $model_field) { |
|
66 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
67 | - continue; |
|
68 | - } |
|
69 | - $schema['properties'][$field] = $model_field->getSchema(); |
|
70 | - |
|
71 | - //if this is a primary key field add the primary key item |
|
72 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
73 | - $schema['properties'][$field]['primary_key'] = true; |
|
74 | - } |
|
75 | - |
|
76 | - //if this is a foreign key field add the foreign key item |
|
77 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
78 | - $schema['properties'][$field]['foreign_key'] = array( |
|
79 | - 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
80 | - 'type' => 'array', |
|
81 | - 'enum' => $model_field->get_model_class_names_pointed_to() |
|
82 | - ); |
|
83 | - } |
|
84 | - } |
|
85 | - return $schema; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Get the schema for a given set of model relations |
|
91 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
95 | - { |
|
96 | - foreach ($relations_on_model as $model_name => $relation) { |
|
97 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
98 | - continue; |
|
99 | - } |
|
100 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
101 | - ? strtolower($model_name) |
|
102 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
103 | - $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
104 | - $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
105 | - } |
|
106 | - return $schema; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Outputs the schema header for a model. |
|
112 | - * @param \EEM_Base $model |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public function getInitialSchemaStructure() |
|
116 | - { |
|
117 | - return array( |
|
118 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
119 | - 'title' => $this->model->get_this_model_name(), |
|
120 | - 'type' => 'object', |
|
121 | - 'properties' => array() |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Allows one to just use the object as a string to get the json. |
|
128 | - * eg. |
|
129 | - * |
|
130 | - * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
131 | - * echo $json_schema; //outputs the schema as a json formatted string. |
|
132 | - * |
|
133 | - * @return bool|false|mixed|string |
|
134 | - */ |
|
135 | - public function __toString() |
|
136 | - { |
|
137 | - return wp_json_encode($this->getModelSchema()); |
|
138 | - } |
|
27 | + /** |
|
28 | + * @var \EEM_Base |
|
29 | + */ |
|
30 | + protected $model; |
|
31 | + |
|
32 | + /** |
|
33 | + * JsonModelSchema constructor. |
|
34 | + * |
|
35 | + * @param \EEM_Base $model |
|
36 | + */ |
|
37 | + public function __construct(EEM_Base $model){ |
|
38 | + $this->model = $model; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Return the schema for a given model from a given model. |
|
43 | + * @param \EEM_Base $model |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function getModelSchema() |
|
47 | + { |
|
48 | + return $this->getModelSchemaForRelations( |
|
49 | + $this->model->relation_settings(), |
|
50 | + $this->getModelSchemaForFields( |
|
51 | + $this->model->field_settings(), |
|
52 | + $this->getInitialSchemaStructure() |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Get the schema for a given set of model fields. |
|
60 | + * @param \EE_Model_Field_Base[] $model_fields |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
64 | + { |
|
65 | + foreach ($model_fields as $field => $model_field) { |
|
66 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
67 | + continue; |
|
68 | + } |
|
69 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
70 | + |
|
71 | + //if this is a primary key field add the primary key item |
|
72 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
73 | + $schema['properties'][$field]['primary_key'] = true; |
|
74 | + } |
|
75 | + |
|
76 | + //if this is a foreign key field add the foreign key item |
|
77 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
78 | + $schema['properties'][$field]['foreign_key'] = array( |
|
79 | + 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
80 | + 'type' => 'array', |
|
81 | + 'enum' => $model_field->get_model_class_names_pointed_to() |
|
82 | + ); |
|
83 | + } |
|
84 | + } |
|
85 | + return $schema; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Get the schema for a given set of model relations |
|
91 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
95 | + { |
|
96 | + foreach ($relations_on_model as $model_name => $relation) { |
|
97 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
98 | + continue; |
|
99 | + } |
|
100 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
101 | + ? strtolower($model_name) |
|
102 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
103 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
104 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
105 | + } |
|
106 | + return $schema; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Outputs the schema header for a model. |
|
112 | + * @param \EEM_Base $model |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public function getInitialSchemaStructure() |
|
116 | + { |
|
117 | + return array( |
|
118 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
119 | + 'title' => $this->model->get_this_model_name(), |
|
120 | + 'type' => 'object', |
|
121 | + 'properties' => array() |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Allows one to just use the object as a string to get the json. |
|
128 | + * eg. |
|
129 | + * |
|
130 | + * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
131 | + * echo $json_schema; //outputs the schema as a json formatted string. |
|
132 | + * |
|
133 | + * @return bool|false|mixed|string |
|
134 | + */ |
|
135 | + public function __toString() |
|
136 | + { |
|
137 | + return wp_json_encode($this->getModelSchema()); |
|
138 | + } |
|
139 | 139 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param \EEM_Base $model |
36 | 36 | */ |
37 | - public function __construct(EEM_Base $model){ |
|
37 | + public function __construct(EEM_Base $model) { |
|
38 | 38 | $this->model = $model; |
39 | 39 | } |
40 | 40 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function getModelSchemaForFields(array $model_fields, array $schema) |
64 | 64 | { |
65 | 65 | foreach ($model_fields as $field => $model_field) { |
66 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
66 | + if ( ! $model_field instanceof EE_Model_Field_Base) { |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | $schema['properties'][$field] = $model_field->getSchema(); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
95 | 95 | { |
96 | 96 | foreach ($relations_on_model as $model_name => $relation) { |
97 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
97 | + if ( ! $relation instanceof EE_Model_Relation_Base) { |
|
98 | 98 | continue; |
99 | 99 | } |
100 | 100 | $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
@@ -5,63 +5,63 @@ |
||
5 | 5 | |
6 | 6 | interface HasSchemaInterface |
7 | 7 | { |
8 | - /** |
|
9 | - * Returns whatever is set as the nicename for the object. |
|
10 | - * |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public function getSchemaDescription(); |
|
8 | + /** |
|
9 | + * Returns whatever is set as the nicename for the object. |
|
10 | + * |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public function getSchemaDescription(); |
|
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * Returns whatever is set as the $_schema_type property for the object. |
|
18 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
19 | - * |
|
20 | - * @return string|array |
|
21 | - */ |
|
22 | - public function getSchemaType(); |
|
16 | + /** |
|
17 | + * Returns whatever is set as the $_schema_type property for the object. |
|
18 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
19 | + * |
|
20 | + * @return string|array |
|
21 | + */ |
|
22 | + public function getSchemaType(); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
27 | - * this method and return the properties for the schema. |
|
28 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
29 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
30 | - * |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function getSchemaProperties(); |
|
25 | + /** |
|
26 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
27 | + * this method and return the properties for the schema. |
|
28 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
29 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
30 | + * |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function getSchemaProperties(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * If a child class has enum values, they should override this method and provide a simple array |
|
37 | - * of the enum values. |
|
38 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
39 | - * are set on the instantiated object that could be filtered after construct. |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function getSchemaEnum(); |
|
35 | + /** |
|
36 | + * If a child class has enum values, they should override this method and provide a simple array |
|
37 | + * of the enum values. |
|
38 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
39 | + * are set on the instantiated object that could be filtered after construct. |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function getSchemaEnum(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * This returns the value of the $_schema_format property on the object. |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getSchemaFormat(); |
|
45 | + /** |
|
46 | + * This returns the value of the $_schema_format property on the object. |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getSchemaFormat(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * This returns the value of the $_schema_readonly property on the object. |
|
54 | - * |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function getSchemaReadonly(); |
|
52 | + /** |
|
53 | + * This returns the value of the $_schema_readonly property on the object. |
|
54 | + * |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function getSchemaReadonly(); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * This returns elements used to represent this field in the json schema. |
|
62 | - * |
|
63 | - * @link http://json-schema.org/ |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getSchema(); |
|
60 | + /** |
|
61 | + * This returns elements used to represent this field in the json schema. |
|
62 | + * |
|
63 | + * @link http://json-schema.org/ |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getSchema(); |
|
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -7,36 +7,36 @@ |
||
7 | 7 | abstract class EE_Text_Field_Base extends EE_Model_Field_Base |
8 | 8 | { |
9 | 9 | |
10 | - function prepare_for_get($value_of_field_on_model_object) |
|
11 | - { |
|
12 | - return is_string($value_of_field_on_model_object) ? stripslashes($value_of_field_on_model_object) : $value_of_field_on_model_object; |
|
13 | - } |
|
10 | + function prepare_for_get($value_of_field_on_model_object) |
|
11 | + { |
|
12 | + return is_string($value_of_field_on_model_object) ? stripslashes($value_of_field_on_model_object) : $value_of_field_on_model_object; |
|
13 | + } |
|
14 | 14 | |
15 | - /** |
|
16 | - * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
17 | - * |
|
18 | - * @param string $value_on_field_to_be_outputted |
|
19 | - * @param string $schema |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
23 | - { |
|
24 | - if ($schema == 'form_input') { |
|
25 | - $value_on_field_to_be_outputted = htmlentities($value_on_field_to_be_outputted, ENT_QUOTES, 'UTF-8'); |
|
26 | - } |
|
27 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
28 | - } |
|
15 | + /** |
|
16 | + * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
17 | + * |
|
18 | + * @param string $value_on_field_to_be_outputted |
|
19 | + * @param string $schema |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
23 | + { |
|
24 | + if ($schema == 'form_input') { |
|
25 | + $value_on_field_to_be_outputted = htmlentities($value_on_field_to_be_outputted, ENT_QUOTES, 'UTF-8'); |
|
26 | + } |
|
27 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * In form inputs, we should have called htmlentities and addslashes on form inputs, |
|
32 | - * so we need to undo that on setting of these fields |
|
33 | - * |
|
34 | - * @param string $value_inputted_for_field_on_model_object |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
38 | - { |
|
39 | - return stripslashes(html_entity_decode(parent::prepare_for_set($value_inputted_for_field_on_model_object), |
|
40 | - ENT_QUOTES, 'UTF-8')); |
|
41 | - } |
|
30 | + /** |
|
31 | + * In form inputs, we should have called htmlentities and addslashes on form inputs, |
|
32 | + * so we need to undo that on setting of these fields |
|
33 | + * |
|
34 | + * @param string $value_inputted_for_field_on_model_object |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
38 | + { |
|
39 | + return stripslashes(html_entity_decode(parent::prepare_for_set($value_inputted_for_field_on_model_object), |
|
40 | + ENT_QUOTES, 'UTF-8')); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |