@@ -44,211 +44,211 @@ |
||
44 | 44 | abstract class EEME_Base |
45 | 45 | { |
46 | 46 | |
47 | - const extending_method_prefix = 'ext_'; |
|
48 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
49 | - |
|
50 | - protected $_extra_tables = array(); |
|
51 | - protected $_extra_fields = array(); |
|
52 | - protected $_extra_relations = array(); |
|
53 | - |
|
54 | - /** |
|
55 | - * The model name that is extended (not classname) |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_model_name_extended = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * The model this extends |
|
63 | - * |
|
64 | - * @var EEM_Base |
|
65 | - */ |
|
66 | - protected $_ = null; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @throws \EE_Error |
|
71 | - */ |
|
72 | - public function __construct() |
|
73 | - { |
|
74 | - if (! $this->_model_name_extended) { |
|
75 | - throw new EE_Error( |
|
76 | - __( |
|
77 | - "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
78 | - "event_espresso" |
|
79 | - ) |
|
80 | - ); |
|
81 | - } |
|
82 | - $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
83 | - if (did_action($construct_end_action)) { |
|
84 | - throw new EE_Error( |
|
85 | - sprintf( |
|
86 | - __( |
|
87 | - "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
88 | - "event_espresso" |
|
89 | - ), |
|
90 | - get_class($this), |
|
91 | - $this->_model_name_extended, |
|
92 | - $construct_end_action |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
96 | - add_filter( |
|
97 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
98 | - array($this, 'add_extra_tables_on_filter') |
|
99 | - ); |
|
100 | - add_filter( |
|
101 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
102 | - array($this, 'add_extra_fields_on_filter') |
|
103 | - ); |
|
104 | - add_filter( |
|
105 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
106 | - array($this, 'add_extra_relations_on_filter') |
|
107 | - ); |
|
108 | - $this->_register_extending_methods(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @param array $existing_tables |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - public function add_extra_tables_on_filter($existing_tables) |
|
117 | - { |
|
118 | - return array_merge((array) $existing_tables, $this->_extra_tables); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param array $existing_fields |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function add_extra_fields_on_filter($existing_fields) |
|
127 | - { |
|
128 | - if ($this->_extra_fields) { |
|
129 | - foreach ($this->_extra_fields as $table_alias => $fields) { |
|
130 | - if (! isset($existing_fields[ $table_alias ])) { |
|
131 | - $existing_fields[ $table_alias ] = array(); |
|
132 | - } |
|
133 | - $existing_fields[ $table_alias ] = array_merge( |
|
134 | - (array) $existing_fields[ $table_alias ], |
|
135 | - $this->_extra_fields[ $table_alias ] |
|
136 | - ); |
|
137 | - } |
|
138 | - } |
|
139 | - return $existing_fields; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param array $existing_relations |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - public function add_extra_relations_on_filter($existing_relations) |
|
148 | - { |
|
149 | - return array_merge((array) $existing_relations, $this->_extra_relations); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
155 | - * model extended. (Internally uses filters, and the __call magic method) |
|
156 | - */ |
|
157 | - protected function _register_extending_methods() |
|
158 | - { |
|
159 | - $all_methods = get_class_methods(get_class($this)); |
|
160 | - foreach ($all_methods as $method_name) { |
|
161 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
162 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
163 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
164 | - add_filter( |
|
165 | - $callback_name, |
|
166 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
167 | - 10, |
|
168 | - 10 |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
176 | - * model extended. (Internally uses filters, and the __call magic method) |
|
177 | - */ |
|
178 | - public function deregister() |
|
179 | - { |
|
180 | - remove_filter( |
|
181 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
182 | - array($this, 'add_extra_tables_on_filter') |
|
183 | - ); |
|
184 | - remove_filter( |
|
185 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
186 | - array($this, 'add_extra_fields_on_filter') |
|
187 | - ); |
|
188 | - remove_filter( |
|
189 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
190 | - array($this, 'add_extra_relations_on_filter') |
|
191 | - ); |
|
192 | - $all_methods = get_class_methods(get_class($this)); |
|
193 | - foreach ($all_methods as $method_name) { |
|
194 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
195 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
196 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
197 | - remove_filter( |
|
198 | - $callback_name, |
|
199 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
200 | - 10 |
|
201 | - ); |
|
202 | - } |
|
203 | - } |
|
204 | - /** @var EEM_Base $model_to_reset */ |
|
205 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
206 | - if (class_exists($model_to_reset)) { |
|
207 | - $model_to_reset::reset(); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $callback_method_name |
|
214 | - * @param array $args |
|
215 | - * @return mixed |
|
216 | - * @throws EE_Error |
|
217 | - */ |
|
218 | - public function __call($callback_method_name, $args) |
|
219 | - { |
|
220 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
221 | - // it's a dynamic callback for a method name |
|
222 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
223 | - list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
224 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
225 | - $this->_ = $model_called; |
|
226 | - // phpcs:enable |
|
227 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
228 | - if (method_exists($this, $extending_method)) { |
|
229 | - return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
230 | - } else { |
|
231 | - throw new EE_Error( |
|
232 | - sprintf( |
|
233 | - __( |
|
234 | - "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
235 | - "event_espresso" |
|
236 | - ), |
|
237 | - $this->_model_name_extended, |
|
238 | - get_class($this), |
|
239 | - $extending_method, |
|
240 | - $extending_method |
|
241 | - ) |
|
242 | - ); |
|
243 | - } |
|
244 | - } else { |
|
245 | - throw new EE_Error( |
|
246 | - sprintf( |
|
247 | - __("There is no method named '%s' on '%s'", "event_espresso"), |
|
248 | - $callback_method_name, |
|
249 | - get_class($this) |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - } |
|
47 | + const extending_method_prefix = 'ext_'; |
|
48 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
49 | + |
|
50 | + protected $_extra_tables = array(); |
|
51 | + protected $_extra_fields = array(); |
|
52 | + protected $_extra_relations = array(); |
|
53 | + |
|
54 | + /** |
|
55 | + * The model name that is extended (not classname) |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_model_name_extended = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * The model this extends |
|
63 | + * |
|
64 | + * @var EEM_Base |
|
65 | + */ |
|
66 | + protected $_ = null; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @throws \EE_Error |
|
71 | + */ |
|
72 | + public function __construct() |
|
73 | + { |
|
74 | + if (! $this->_model_name_extended) { |
|
75 | + throw new EE_Error( |
|
76 | + __( |
|
77 | + "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
78 | + "event_espresso" |
|
79 | + ) |
|
80 | + ); |
|
81 | + } |
|
82 | + $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
83 | + if (did_action($construct_end_action)) { |
|
84 | + throw new EE_Error( |
|
85 | + sprintf( |
|
86 | + __( |
|
87 | + "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
88 | + "event_espresso" |
|
89 | + ), |
|
90 | + get_class($this), |
|
91 | + $this->_model_name_extended, |
|
92 | + $construct_end_action |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | + add_filter( |
|
97 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
98 | + array($this, 'add_extra_tables_on_filter') |
|
99 | + ); |
|
100 | + add_filter( |
|
101 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
102 | + array($this, 'add_extra_fields_on_filter') |
|
103 | + ); |
|
104 | + add_filter( |
|
105 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
106 | + array($this, 'add_extra_relations_on_filter') |
|
107 | + ); |
|
108 | + $this->_register_extending_methods(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @param array $existing_tables |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + public function add_extra_tables_on_filter($existing_tables) |
|
117 | + { |
|
118 | + return array_merge((array) $existing_tables, $this->_extra_tables); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param array $existing_fields |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function add_extra_fields_on_filter($existing_fields) |
|
127 | + { |
|
128 | + if ($this->_extra_fields) { |
|
129 | + foreach ($this->_extra_fields as $table_alias => $fields) { |
|
130 | + if (! isset($existing_fields[ $table_alias ])) { |
|
131 | + $existing_fields[ $table_alias ] = array(); |
|
132 | + } |
|
133 | + $existing_fields[ $table_alias ] = array_merge( |
|
134 | + (array) $existing_fields[ $table_alias ], |
|
135 | + $this->_extra_fields[ $table_alias ] |
|
136 | + ); |
|
137 | + } |
|
138 | + } |
|
139 | + return $existing_fields; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param array $existing_relations |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + public function add_extra_relations_on_filter($existing_relations) |
|
148 | + { |
|
149 | + return array_merge((array) $existing_relations, $this->_extra_relations); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
155 | + * model extended. (Internally uses filters, and the __call magic method) |
|
156 | + */ |
|
157 | + protected function _register_extending_methods() |
|
158 | + { |
|
159 | + $all_methods = get_class_methods(get_class($this)); |
|
160 | + foreach ($all_methods as $method_name) { |
|
161 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
162 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
163 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
164 | + add_filter( |
|
165 | + $callback_name, |
|
166 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
167 | + 10, |
|
168 | + 10 |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
176 | + * model extended. (Internally uses filters, and the __call magic method) |
|
177 | + */ |
|
178 | + public function deregister() |
|
179 | + { |
|
180 | + remove_filter( |
|
181 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
182 | + array($this, 'add_extra_tables_on_filter') |
|
183 | + ); |
|
184 | + remove_filter( |
|
185 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
186 | + array($this, 'add_extra_fields_on_filter') |
|
187 | + ); |
|
188 | + remove_filter( |
|
189 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
190 | + array($this, 'add_extra_relations_on_filter') |
|
191 | + ); |
|
192 | + $all_methods = get_class_methods(get_class($this)); |
|
193 | + foreach ($all_methods as $method_name) { |
|
194 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
195 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
196 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
197 | + remove_filter( |
|
198 | + $callback_name, |
|
199 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
200 | + 10 |
|
201 | + ); |
|
202 | + } |
|
203 | + } |
|
204 | + /** @var EEM_Base $model_to_reset */ |
|
205 | + $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
206 | + if (class_exists($model_to_reset)) { |
|
207 | + $model_to_reset::reset(); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $callback_method_name |
|
214 | + * @param array $args |
|
215 | + * @return mixed |
|
216 | + * @throws EE_Error |
|
217 | + */ |
|
218 | + public function __call($callback_method_name, $args) |
|
219 | + { |
|
220 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
221 | + // it's a dynamic callback for a method name |
|
222 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
223 | + list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
224 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
225 | + $this->_ = $model_called; |
|
226 | + // phpcs:enable |
|
227 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
228 | + if (method_exists($this, $extending_method)) { |
|
229 | + return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
230 | + } else { |
|
231 | + throw new EE_Error( |
|
232 | + sprintf( |
|
233 | + __( |
|
234 | + "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
235 | + "event_espresso" |
|
236 | + ), |
|
237 | + $this->_model_name_extended, |
|
238 | + get_class($this), |
|
239 | + $extending_method, |
|
240 | + $extending_method |
|
241 | + ) |
|
242 | + ); |
|
243 | + } |
|
244 | + } else { |
|
245 | + throw new EE_Error( |
|
246 | + sprintf( |
|
247 | + __("There is no method named '%s' on '%s'", "event_espresso"), |
|
248 | + $callback_method_name, |
|
249 | + get_class($this) |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() |
73 | 73 | { |
74 | - if (! $this->_model_name_extended) { |
|
74 | + if ( ! $this->_model_name_extended) { |
|
75 | 75 | throw new EE_Error( |
76 | 76 | __( |
77 | 77 | "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | } |
82 | - $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
82 | + $construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end'; |
|
83 | 83 | if (did_action($construct_end_action)) { |
84 | 84 | throw new EE_Error( |
85 | 85 | sprintf( |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | ); |
95 | 95 | } |
96 | 96 | add_filter( |
97 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
97 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', |
|
98 | 98 | array($this, 'add_extra_tables_on_filter') |
99 | 99 | ); |
100 | 100 | add_filter( |
101 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
101 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', |
|
102 | 102 | array($this, 'add_extra_fields_on_filter') |
103 | 103 | ); |
104 | 104 | add_filter( |
105 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
105 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', |
|
106 | 106 | array($this, 'add_extra_relations_on_filter') |
107 | 107 | ); |
108 | 108 | $this->_register_extending_methods(); |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | { |
128 | 128 | if ($this->_extra_fields) { |
129 | 129 | foreach ($this->_extra_fields as $table_alias => $fields) { |
130 | - if (! isset($existing_fields[ $table_alias ])) { |
|
131 | - $existing_fields[ $table_alias ] = array(); |
|
130 | + if ( ! isset($existing_fields[$table_alias])) { |
|
131 | + $existing_fields[$table_alias] = array(); |
|
132 | 132 | } |
133 | - $existing_fields[ $table_alias ] = array_merge( |
|
134 | - (array) $existing_fields[ $table_alias ], |
|
135 | - $this->_extra_fields[ $table_alias ] |
|
133 | + $existing_fields[$table_alias] = array_merge( |
|
134 | + (array) $existing_fields[$table_alias], |
|
135 | + $this->_extra_fields[$table_alias] |
|
136 | 136 | ); |
137 | 137 | } |
138 | 138 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
164 | 164 | add_filter( |
165 | 165 | $callback_name, |
166 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
166 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
167 | 167 | 10, |
168 | 168 | 10 |
169 | 169 | ); |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | public function deregister() |
179 | 179 | { |
180 | 180 | remove_filter( |
181 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
181 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', |
|
182 | 182 | array($this, 'add_extra_tables_on_filter') |
183 | 183 | ); |
184 | 184 | remove_filter( |
185 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
185 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', |
|
186 | 186 | array($this, 'add_extra_fields_on_filter') |
187 | 187 | ); |
188 | 188 | remove_filter( |
189 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
189 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', |
|
190 | 190 | array($this, 'add_extra_relations_on_filter') |
191 | 191 | ); |
192 | 192 | $all_methods = get_class_methods(get_class($this)); |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
197 | 197 | remove_filter( |
198 | 198 | $callback_name, |
199 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
199 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
200 | 200 | 10 |
201 | 201 | ); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | /** @var EEM_Base $model_to_reset */ |
205 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
205 | + $model_to_reset = 'EEM_'.$this->_model_name_extended; |
|
206 | 206 | if (class_exists($model_to_reset)) { |
207 | 207 | $model_to_reset::reset(); |
208 | 208 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
225 | 225 | $this->_ = $model_called; |
226 | 226 | // phpcs:enable |
227 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
227 | + $extending_method = self::extending_method_prefix.$method_called_on_model; |
|
228 | 228 | if (method_exists($this, $extending_method)) { |
229 | 229 | return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
230 | 230 | } else { |
@@ -12,111 +12,111 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Sending messenger |
|
17 | - * |
|
18 | - * @type EE_messenger | string |
|
19 | - */ |
|
20 | - protected $_sending_messenger = ''; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Holds the incoming token; |
|
25 | - * @type string |
|
26 | - */ |
|
27 | - public $token = ''; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructor |
|
32 | - * |
|
33 | - * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
34 | - * the EE_Message retrieved from the DB via the given token. |
|
35 | - * @param string $token This is a token for a Message that should already exist int the db. |
|
36 | - * This is then used to populate the properties in here. |
|
37 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
38 | - */ |
|
39 | - public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager) |
|
40 | - { |
|
41 | - $this->token = $token; |
|
42 | - $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
43 | - $this->_message = $this->_generate_message(); |
|
44 | - // set params for parent from the message object |
|
45 | - parent::__construct( |
|
46 | - $this->_message->messenger(), |
|
47 | - $this->_message->message_type(), |
|
48 | - array(), |
|
49 | - $this->_message->context(), |
|
50 | - false |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $sending_messenger_slug |
|
58 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
59 | - * @return \EE_messenger | string |
|
60 | - */ |
|
61 | - protected function _set_sending_messenger( |
|
62 | - $sending_messenger_slug, |
|
63 | - EE_Message_Resource_Manager $message_resource_manager |
|
64 | - ) { |
|
65 | - $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
66 | - return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return EE_messenger |
|
73 | - */ |
|
74 | - public function sending_messenger() |
|
75 | - { |
|
76 | - return $this->_sending_messenger; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * generates an EE_Message using the supplied arguments and some defaults |
|
83 | - * |
|
84 | - * @param array $properties |
|
85 | - * @return EE_Message |
|
86 | - * @throws \EE_Error |
|
87 | - */ |
|
88 | - protected function _generate_message($properties = array()) |
|
89 | - { |
|
90 | - // a message was generated immediately but the parent class will call this again |
|
91 | - if ($this->_message instanceof EE_Message) { |
|
92 | - return $this->_message; |
|
93 | - } |
|
94 | - $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
95 | - if (! $message instanceof EE_Message) { |
|
96 | - throw new EE_Error( |
|
97 | - sprintf( |
|
98 | - __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
99 | - $this->token |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
104 | - |
|
105 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
107 | - $message->set_error_message( |
|
108 | - sprintf( |
|
109 | - __('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
110 | - $this->_sending_messenger |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - // set properties |
|
116 | - $this->_valid = true; |
|
117 | - $this->_messenger = $message->messenger_object(); |
|
118 | - $this->_message_type = $message->message_type_object(); |
|
119 | - $this->_send_now = $message->send_now(); |
|
120 | - return $message; |
|
121 | - } |
|
15 | + /** |
|
16 | + * Sending messenger |
|
17 | + * |
|
18 | + * @type EE_messenger | string |
|
19 | + */ |
|
20 | + protected $_sending_messenger = ''; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Holds the incoming token; |
|
25 | + * @type string |
|
26 | + */ |
|
27 | + public $token = ''; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructor |
|
32 | + * |
|
33 | + * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
34 | + * the EE_Message retrieved from the DB via the given token. |
|
35 | + * @param string $token This is a token for a Message that should already exist int the db. |
|
36 | + * This is then used to populate the properties in here. |
|
37 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
38 | + */ |
|
39 | + public function __construct($token, $sending_messenger_slug = 'html', EE_Message_Resource_Manager $message_resource_manager) |
|
40 | + { |
|
41 | + $this->token = $token; |
|
42 | + $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
43 | + $this->_message = $this->_generate_message(); |
|
44 | + // set params for parent from the message object |
|
45 | + parent::__construct( |
|
46 | + $this->_message->messenger(), |
|
47 | + $this->_message->message_type(), |
|
48 | + array(), |
|
49 | + $this->_message->context(), |
|
50 | + false |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $sending_messenger_slug |
|
58 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
59 | + * @return \EE_messenger | string |
|
60 | + */ |
|
61 | + protected function _set_sending_messenger( |
|
62 | + $sending_messenger_slug, |
|
63 | + EE_Message_Resource_Manager $message_resource_manager |
|
64 | + ) { |
|
65 | + $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
66 | + return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return EE_messenger |
|
73 | + */ |
|
74 | + public function sending_messenger() |
|
75 | + { |
|
76 | + return $this->_sending_messenger; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * generates an EE_Message using the supplied arguments and some defaults |
|
83 | + * |
|
84 | + * @param array $properties |
|
85 | + * @return EE_Message |
|
86 | + * @throws \EE_Error |
|
87 | + */ |
|
88 | + protected function _generate_message($properties = array()) |
|
89 | + { |
|
90 | + // a message was generated immediately but the parent class will call this again |
|
91 | + if ($this->_message instanceof EE_Message) { |
|
92 | + return $this->_message; |
|
93 | + } |
|
94 | + $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
95 | + if (! $message instanceof EE_Message) { |
|
96 | + throw new EE_Error( |
|
97 | + sprintf( |
|
98 | + __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
99 | + $this->token |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
104 | + |
|
105 | + if (! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
107 | + $message->set_error_message( |
|
108 | + sprintf( |
|
109 | + __('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
110 | + $this->_sending_messenger |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + // set properties |
|
116 | + $this->_valid = true; |
|
117 | + $this->_messenger = $message->messenger_object(); |
|
118 | + $this->_message_type = $message->message_type_object(); |
|
119 | + $this->_send_now = $message->send_now(); |
|
120 | + return $message; |
|
121 | + } |
|
122 | 122 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return $this->_message; |
93 | 93 | } |
94 | 94 | $message = EEM_Message::instance()->get_one_by_token($this->token); |
95 | - if (! $message instanceof EE_Message) { |
|
95 | + if ( ! $message instanceof EE_Message) { |
|
96 | 96 | throw new EE_Error( |
97 | 97 | sprintf( |
98 | 98 | __('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | $message->set_STS_ID(EEM_Message::status_idle); |
104 | 104 | |
105 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
105 | + if ( ! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | 106 | $message->set_STS_ID(EEM_Message::status_failed); |
107 | 107 | $message->set_error_message( |
108 | 108 | sprintf( |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
101 | 101 | |
102 | - if (! $do_hooks_only) { |
|
102 | + if ( ! $do_hooks_only) { |
|
103 | 103 | $this->rewind(); |
104 | 104 | // exit early if there is nothing to save. |
105 | 105 | if ($this->count() < 1) { |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | public function get_generation_data() |
156 | 156 | { |
157 | 157 | // first verify we're at a valid iterator point. |
158 | - if (! $this->valid()) { |
|
158 | + if ( ! $this->valid()) { |
|
159 | 159 | return array(); |
160 | 160 | } |
161 | 161 | $info = $this->getInfo(); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function get_data_handler() |
172 | 172 | { |
173 | - if (! $this->valid()) { |
|
173 | + if ( ! $this->valid()) { |
|
174 | 174 | return ''; |
175 | 175 | } |
176 | 176 | $info = $this->getInfo(); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function is_preview() |
187 | 187 | { |
188 | - if (! $this->valid()) { |
|
188 | + if ( ! $this->valid()) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | $info = $this->getInfo(); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function is_test_send() |
202 | 202 | { |
203 | - if (! $this->valid()) { |
|
203 | + if ( ! $this->valid()) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | $info = $this->getInfo(); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | protected function _maybe_persist_attached_data() |
216 | 216 | { |
217 | - if (! $this->valid()) { |
|
217 | + if ( ! $this->valid()) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function count_by_priority_and_status($priority, $status = array()) |
239 | 239 | { |
240 | - if (! empty($status)) { |
|
240 | + if ( ! empty($status)) { |
|
241 | 241 | $status = is_array($status) ? $status : array($status); |
242 | 242 | } |
243 | 243 |
@@ -12,257 +12,257 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * EE_Message_Repository constructor |
|
17 | - */ |
|
18 | - public function __construct() |
|
19 | - { |
|
20 | - $this->interface = 'EE_Message'; |
|
21 | - parent::__construct(); |
|
22 | - } |
|
15 | + /** |
|
16 | + * EE_Message_Repository constructor |
|
17 | + */ |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + $this->interface = 'EE_Message'; |
|
21 | + parent::__construct(); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Add the EE_Message to the repository. |
|
27 | - * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
28 | - * |
|
29 | - * @param EE_Message $message |
|
30 | - * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function add($message, $info = null) |
|
34 | - { |
|
35 | - $attached = parent::add($message); |
|
36 | - // ensure $info is an array if not already |
|
37 | - $info = $info === null ? $info = array() : (array) $info; |
|
38 | - $data = $this->_init_data($info, $attached, $message); |
|
39 | - if ($attached) { |
|
40 | - $this->set_info($message, $data); |
|
41 | - } |
|
42 | - return $attached; |
|
43 | - } |
|
25 | + /** |
|
26 | + * Add the EE_Message to the repository. |
|
27 | + * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
28 | + * |
|
29 | + * @param EE_Message $message |
|
30 | + * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function add($message, $info = null) |
|
34 | + { |
|
35 | + $attached = parent::add($message); |
|
36 | + // ensure $info is an array if not already |
|
37 | + $info = $info === null ? $info = array() : (array) $info; |
|
38 | + $data = $this->_init_data($info, $attached, $message); |
|
39 | + if ($attached) { |
|
40 | + $this->set_info($message, $data); |
|
41 | + } |
|
42 | + return $attached; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Initializes the data from the incoming info. |
|
48 | - * |
|
49 | - * @param array $info incoming data. |
|
50 | - * @param bool $attached Indicates whether the object was attached successfully. |
|
51 | - * @param EE_Message $message |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - protected function _init_data($info, $attached, $message) |
|
55 | - { |
|
56 | - $data = array( |
|
57 | - 'test_send' => false, |
|
58 | - 'preview' => false, |
|
59 | - 'data_handler_class_name' => '', |
|
60 | - 'data' => array( |
|
61 | - 'MSG_generation_data' => array(), |
|
62 | - ), |
|
63 | - ); |
|
64 | - if (isset($info['preview'])) { |
|
65 | - $data['preview'] = $info['preview']; |
|
66 | - unset($info['preview']); |
|
67 | - } |
|
68 | - if (isset($info['test_send'])) { |
|
69 | - $data['test_send'] = $info['test_send']; |
|
70 | - unset($info['test_send']); |
|
71 | - } |
|
72 | - if (isset($info['data_handler_class_name'])) { |
|
73 | - $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
74 | - unset($info['data_handler_class_name']); |
|
75 | - } |
|
76 | - if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
77 | - $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
78 | - // if data isn't in $info...let's see if its available via the message object |
|
79 | - $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
80 | - // still empty then let's just use info |
|
81 | - $generation_data = ! $generation_data ? $info : $generation_data; |
|
82 | - $data['data']['MSG_generation_data'] = $generation_data; |
|
83 | - } |
|
84 | - return $data; |
|
85 | - } |
|
46 | + /** |
|
47 | + * Initializes the data from the incoming info. |
|
48 | + * |
|
49 | + * @param array $info incoming data. |
|
50 | + * @param bool $attached Indicates whether the object was attached successfully. |
|
51 | + * @param EE_Message $message |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + protected function _init_data($info, $attached, $message) |
|
55 | + { |
|
56 | + $data = array( |
|
57 | + 'test_send' => false, |
|
58 | + 'preview' => false, |
|
59 | + 'data_handler_class_name' => '', |
|
60 | + 'data' => array( |
|
61 | + 'MSG_generation_data' => array(), |
|
62 | + ), |
|
63 | + ); |
|
64 | + if (isset($info['preview'])) { |
|
65 | + $data['preview'] = $info['preview']; |
|
66 | + unset($info['preview']); |
|
67 | + } |
|
68 | + if (isset($info['test_send'])) { |
|
69 | + $data['test_send'] = $info['test_send']; |
|
70 | + unset($info['test_send']); |
|
71 | + } |
|
72 | + if (isset($info['data_handler_class_name'])) { |
|
73 | + $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
74 | + unset($info['data_handler_class_name']); |
|
75 | + } |
|
76 | + if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
77 | + $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
78 | + // if data isn't in $info...let's see if its available via the message object |
|
79 | + $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
80 | + // still empty then let's just use info |
|
81 | + $generation_data = ! $generation_data ? $info : $generation_data; |
|
82 | + $data['data']['MSG_generation_data'] = $generation_data; |
|
83 | + } |
|
84 | + return $data; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * Save all EE_Message objects to the db. |
|
90 | - * |
|
91 | - * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
92 | - * @return array array( |
|
93 | - * 'updated' => 0, //count of how many messages updated |
|
94 | - * 'notupdated' => 0, //count of how many messages not updated. |
|
95 | - * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
96 | - * ) |
|
97 | - */ |
|
98 | - public function saveAll($do_hooks_only = false) |
|
99 | - { |
|
100 | - $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
88 | + /** |
|
89 | + * Save all EE_Message objects to the db. |
|
90 | + * |
|
91 | + * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
92 | + * @return array array( |
|
93 | + * 'updated' => 0, //count of how many messages updated |
|
94 | + * 'notupdated' => 0, //count of how many messages not updated. |
|
95 | + * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
96 | + * ) |
|
97 | + */ |
|
98 | + public function saveAll($do_hooks_only = false) |
|
99 | + { |
|
100 | + $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
101 | 101 | |
102 | - if (! $do_hooks_only) { |
|
103 | - $this->rewind(); |
|
104 | - // exit early if there is nothing to save. |
|
105 | - if ($this->count() < 1) { |
|
106 | - return $save_tracking; |
|
107 | - } |
|
102 | + if (! $do_hooks_only) { |
|
103 | + $this->rewind(); |
|
104 | + // exit early if there is nothing to save. |
|
105 | + if ($this->count() < 1) { |
|
106 | + return $save_tracking; |
|
107 | + } |
|
108 | 108 | |
109 | - while ($this->valid()) { |
|
110 | - $saved = $this->current()->save(); |
|
111 | - if ($saved === false) { |
|
112 | - $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
113 | - } elseif ($saved) { |
|
114 | - $save_tracking['updated']++; |
|
115 | - } else { |
|
116 | - $save_tracking['notupdated']++; |
|
117 | - } |
|
118 | - // maybe persist generation data if this is an incomplete EE_Message. |
|
119 | - $this->_maybe_persist_attached_data(); |
|
109 | + while ($this->valid()) { |
|
110 | + $saved = $this->current()->save(); |
|
111 | + if ($saved === false) { |
|
112 | + $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
113 | + } elseif ($saved) { |
|
114 | + $save_tracking['updated']++; |
|
115 | + } else { |
|
116 | + $save_tracking['notupdated']++; |
|
117 | + } |
|
118 | + // maybe persist generation data if this is an incomplete EE_Message. |
|
119 | + $this->_maybe_persist_attached_data(); |
|
120 | 120 | |
121 | - $this->next(); |
|
122 | - } |
|
123 | - } |
|
124 | - do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
125 | - return $save_tracking; |
|
126 | - } |
|
121 | + $this->next(); |
|
122 | + } |
|
123 | + } |
|
124 | + do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
125 | + return $save_tracking; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * Retrieves a EE_Message from the repository that matches the given token. |
|
131 | - * |
|
132 | - * @param string $token Token. |
|
133 | - * @return EE_Message | null |
|
134 | - */ |
|
135 | - public function getMessageByToken($token) |
|
136 | - { |
|
137 | - $this->rewind(); |
|
138 | - while ($this->valid()) { |
|
139 | - if ($this->current()->MSG_token() === $token) { |
|
140 | - $message = $this->current(); |
|
141 | - $this->rewind(); |
|
142 | - return $message; |
|
143 | - } |
|
144 | - $this->next(); |
|
145 | - } |
|
146 | - return null; |
|
147 | - } |
|
129 | + /** |
|
130 | + * Retrieves a EE_Message from the repository that matches the given token. |
|
131 | + * |
|
132 | + * @param string $token Token. |
|
133 | + * @return EE_Message | null |
|
134 | + */ |
|
135 | + public function getMessageByToken($token) |
|
136 | + { |
|
137 | + $this->rewind(); |
|
138 | + while ($this->valid()) { |
|
139 | + if ($this->current()->MSG_token() === $token) { |
|
140 | + $message = $this->current(); |
|
141 | + $this->rewind(); |
|
142 | + return $message; |
|
143 | + } |
|
144 | + $this->next(); |
|
145 | + } |
|
146 | + return null; |
|
147 | + } |
|
148 | 148 | |
149 | 149 | |
150 | - /** |
|
151 | - * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
152 | - * |
|
153 | - * @return array(); |
|
154 | - */ |
|
155 | - public function get_generation_data() |
|
156 | - { |
|
157 | - // first verify we're at a valid iterator point. |
|
158 | - if (! $this->valid()) { |
|
159 | - return array(); |
|
160 | - } |
|
161 | - $info = $this->getInfo(); |
|
162 | - return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
163 | - } |
|
150 | + /** |
|
151 | + * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
152 | + * |
|
153 | + * @return array(); |
|
154 | + */ |
|
155 | + public function get_generation_data() |
|
156 | + { |
|
157 | + // first verify we're at a valid iterator point. |
|
158 | + if (! $this->valid()) { |
|
159 | + return array(); |
|
160 | + } |
|
161 | + $info = $this->getInfo(); |
|
162 | + return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_data_handler() |
|
172 | - { |
|
173 | - if (! $this->valid()) { |
|
174 | - return ''; |
|
175 | - } |
|
176 | - $info = $this->getInfo(); |
|
177 | - return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
178 | - } |
|
166 | + /** |
|
167 | + * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_data_handler() |
|
172 | + { |
|
173 | + if (! $this->valid()) { |
|
174 | + return ''; |
|
175 | + } |
|
176 | + $info = $this->getInfo(); |
|
177 | + return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * Returns whether this EE_Message is for a preview or not. |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function is_preview() |
|
187 | - { |
|
188 | - if (! $this->valid()) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - $info = $this->getInfo(); |
|
192 | - return $info['preview']; |
|
193 | - } |
|
181 | + /** |
|
182 | + * Returns whether this EE_Message is for a preview or not. |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function is_preview() |
|
187 | + { |
|
188 | + if (! $this->valid()) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + $info = $this->getInfo(); |
|
192 | + return $info['preview']; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Returns whether the current message pointed to is for a test send. |
|
198 | - * |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function is_test_send() |
|
202 | - { |
|
203 | - if (! $this->valid()) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - $info = $this->getInfo(); |
|
207 | - return $info['test_send']; |
|
208 | - } |
|
196 | + /** |
|
197 | + * Returns whether the current message pointed to is for a test send. |
|
198 | + * |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function is_test_send() |
|
202 | + { |
|
203 | + if (! $this->valid()) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + $info = $this->getInfo(); |
|
207 | + return $info['test_send']; |
|
208 | + } |
|
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
213 | - * data is attached for later retrieval (batch generation). |
|
214 | - */ |
|
215 | - protected function _maybe_persist_attached_data() |
|
216 | - { |
|
217 | - if (! $this->valid()) { |
|
218 | - return; |
|
219 | - } |
|
211 | + /** |
|
212 | + * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
213 | + * data is attached for later retrieval (batch generation). |
|
214 | + */ |
|
215 | + protected function _maybe_persist_attached_data() |
|
216 | + { |
|
217 | + if (! $this->valid()) { |
|
218 | + return; |
|
219 | + } |
|
220 | 220 | |
221 | - $info = $this->getInfo(); |
|
222 | - $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
223 | - $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
224 | - if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
225 | - $this->current()->set_generation_data($data); |
|
226 | - $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
227 | - } |
|
228 | - } |
|
221 | + $info = $this->getInfo(); |
|
222 | + $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
223 | + $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
224 | + if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
225 | + $this->current()->set_generation_data($data); |
|
226 | + $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * This method returns a count of messages in the repository that have a given priority. |
|
233 | - * |
|
234 | - * @param int $priority the priority that is being filtered for the count. |
|
235 | - * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
236 | - * @return int count of messages in the queue matching the conditions. |
|
237 | - */ |
|
238 | - public function count_by_priority_and_status($priority, $status = array()) |
|
239 | - { |
|
240 | - if (! empty($status)) { |
|
241 | - $status = is_array($status) ? $status : array($status); |
|
242 | - } |
|
231 | + /** |
|
232 | + * This method returns a count of messages in the repository that have a given priority. |
|
233 | + * |
|
234 | + * @param int $priority the priority that is being filtered for the count. |
|
235 | + * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
236 | + * @return int count of messages in the queue matching the conditions. |
|
237 | + */ |
|
238 | + public function count_by_priority_and_status($priority, $status = array()) |
|
239 | + { |
|
240 | + if (! empty($status)) { |
|
241 | + $status = is_array($status) ? $status : array($status); |
|
242 | + } |
|
243 | 243 | |
244 | - $count = 0; |
|
245 | - $this->rewind(); |
|
246 | - while ($this->valid()) { |
|
247 | - if ( |
|
248 | - $this->current()->priority() === $priority && (($status && in_array( |
|
249 | - $this->current()->STS_ID(), |
|
250 | - $status |
|
251 | - )) || ! $status) |
|
252 | - ) { |
|
253 | - $count++; |
|
254 | - } |
|
255 | - $this->next(); |
|
256 | - } |
|
257 | - return $count; |
|
258 | - } |
|
244 | + $count = 0; |
|
245 | + $this->rewind(); |
|
246 | + while ($this->valid()) { |
|
247 | + if ( |
|
248 | + $this->current()->priority() === $priority && (($status && in_array( |
|
249 | + $this->current()->STS_ID(), |
|
250 | + $status |
|
251 | + )) || ! $status) |
|
252 | + ) { |
|
253 | + $count++; |
|
254 | + } |
|
255 | + $this->next(); |
|
256 | + } |
|
257 | + return $count; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * @return EE_Message |
|
263 | - */ |
|
264 | - public function current() |
|
265 | - { |
|
266 | - return parent::current(); |
|
267 | - } |
|
261 | + /** |
|
262 | + * @return EE_Message |
|
263 | + */ |
|
264 | + public function current() |
|
265 | + { |
|
266 | + return parent::current(); |
|
267 | + } |
|
268 | 268 | } |
@@ -14,168 +14,168 @@ |
||
14 | 14 | class EE_Message_Type_Collection extends EE_Object_Collection |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * EE_Message_Type_Collection constructor. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - $this->interface = 'EE_message_type'; |
|
23 | - } |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * add |
|
29 | - * |
|
30 | - * attaches an object to the Collection |
|
31 | - * and sets any supplied data associated with the current iterator entry |
|
32 | - * by calling EE_Object_Collection::set_info() |
|
33 | - * |
|
34 | - * @access public |
|
35 | - * @param object $object |
|
36 | - * @param mixed $info |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function add($object, $info = null) |
|
40 | - { |
|
41 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
42 | - return parent::add($object, $info); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * set_info |
|
49 | - * |
|
50 | - * Sets the data associated with an object in the Collection |
|
51 | - * if no $info is supplied, then the spl_object_hash() is used |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param object $object |
|
55 | - * @param mixed $info |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function set_info($object, $info = null) |
|
59 | - { |
|
60 | - $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
61 | - return parent::set_info($object, $info); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * get_by_info |
|
68 | - * |
|
69 | - * finds and returns an object in the Collection based on the info that was set using addObject() |
|
70 | - * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @param mixed |
|
74 | - * @return null | object |
|
75 | - */ |
|
76 | - public function get_by_info($info) |
|
77 | - { |
|
78 | - return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * has |
|
85 | - * |
|
86 | - * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @param object $object |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function has($object) |
|
93 | - { |
|
94 | - return parent::has($object); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * has_by_name |
|
101 | - * |
|
102 | - * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
103 | - * |
|
104 | - * @access public |
|
105 | - * @param string $message_type_name |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function has_by_name($message_type_name) |
|
109 | - { |
|
110 | - return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * remove |
|
117 | - * |
|
118 | - * detaches an object from the Collection |
|
119 | - * |
|
120 | - * @access public |
|
121 | - * @param $object |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - public function remove($object) |
|
125 | - { |
|
126 | - return parent::remove($object); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * set_current |
|
133 | - * |
|
134 | - * advances pointer to the provided object |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param $object |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public function set_current($object) |
|
141 | - { |
|
142 | - parent::set_current($object); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * set_current_by_info |
|
149 | - * |
|
150 | - * advances pointer to the object whose info matches that which was provided |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param $info |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - public function set_current_by_info($info) |
|
157 | - { |
|
158 | - parent::set_current_by_info($info); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * show_collection_classes |
|
165 | - * |
|
166 | - * displays list of collection classes if WP_DEBUG is on |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public function show_collection_classes() |
|
172 | - { |
|
173 | - if (WP_DEBUG) { |
|
174 | - $this->rewind(); |
|
175 | - while ($this->valid()) { |
|
176 | - echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
177 | - $this->next(); |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
17 | + /** |
|
18 | + * EE_Message_Type_Collection constructor. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + $this->interface = 'EE_message_type'; |
|
23 | + } |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * add |
|
29 | + * |
|
30 | + * attaches an object to the Collection |
|
31 | + * and sets any supplied data associated with the current iterator entry |
|
32 | + * by calling EE_Object_Collection::set_info() |
|
33 | + * |
|
34 | + * @access public |
|
35 | + * @param object $object |
|
36 | + * @param mixed $info |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function add($object, $info = null) |
|
40 | + { |
|
41 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
42 | + return parent::add($object, $info); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * set_info |
|
49 | + * |
|
50 | + * Sets the data associated with an object in the Collection |
|
51 | + * if no $info is supplied, then the spl_object_hash() is used |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param object $object |
|
55 | + * @param mixed $info |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function set_info($object, $info = null) |
|
59 | + { |
|
60 | + $info = empty($info) && $object instanceof $this->interface ? $object->name : $info; |
|
61 | + return parent::set_info($object, $info); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * get_by_info |
|
68 | + * |
|
69 | + * finds and returns an object in the Collection based on the info that was set using addObject() |
|
70 | + * PLZ NOTE: the pointer is reset to the beginning of the collection before returning |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @param mixed |
|
74 | + * @return null | object |
|
75 | + */ |
|
76 | + public function get_by_info($info) |
|
77 | + { |
|
78 | + return parent::get_by_info(str_replace(' ', '_', strtolower($info))); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * has |
|
85 | + * |
|
86 | + * returns TRUE or FALSE depending on whether the supplied object is within the Collection |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @param object $object |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function has($object) |
|
93 | + { |
|
94 | + return parent::has($object); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * has_by_name |
|
101 | + * |
|
102 | + * returns TRUE or FALSE depending on whether the supplied message_type classname is within the Collection |
|
103 | + * |
|
104 | + * @access public |
|
105 | + * @param string $message_type_name |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function has_by_name($message_type_name) |
|
109 | + { |
|
110 | + return $this->get_by_info($message_type_name) instanceof $this->interface ? true : false; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * remove |
|
117 | + * |
|
118 | + * detaches an object from the Collection |
|
119 | + * |
|
120 | + * @access public |
|
121 | + * @param $object |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + public function remove($object) |
|
125 | + { |
|
126 | + return parent::remove($object); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * set_current |
|
133 | + * |
|
134 | + * advances pointer to the provided object |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param $object |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public function set_current($object) |
|
141 | + { |
|
142 | + parent::set_current($object); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * set_current_by_info |
|
149 | + * |
|
150 | + * advances pointer to the object whose info matches that which was provided |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param $info |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + public function set_current_by_info($info) |
|
157 | + { |
|
158 | + parent::set_current_by_info($info); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * show_collection_classes |
|
165 | + * |
|
166 | + * displays list of collection classes if WP_DEBUG is on |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public function show_collection_classes() |
|
172 | + { |
|
173 | + if (WP_DEBUG) { |
|
174 | + $this->rewind(); |
|
175 | + while ($this->valid()) { |
|
176 | + echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
177 | + $this->next(); |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | 181 | } |
@@ -173,7 +173,7 @@ |
||
173 | 173 | if (WP_DEBUG) { |
174 | 174 | $this->rewind(); |
175 | 175 | while ($this->valid()) { |
176 | - echo '<h5 style="color:#2EA2CC;">' . __CLASS__ . ' class : <span style="color:#E76700">' . $this->getInfo() . '</span></h5>'; |
|
176 | + echo '<h5 style="color:#2EA2CC;">'.__CLASS__.' class : <span style="color:#E76700">'.$this->getInfo().'</span></h5>'; |
|
177 | 177 | $this->next(); |
178 | 178 | } |
179 | 179 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | <tr class="item"> |
7 | 7 | <td>[LINE_ITEM_NAME][LINE_ITEM_TAXABLE_*]</td> |
8 | 8 | <td colspan="2">[LINE_ITEM_DESCRIPTION] |
9 | - <p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema=' . __('any', 'event_espresso') . ']'); ?></p> |
|
9 | + <p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema='.__('any', 'event_espresso').']'); ?></p> |
|
10 | 10 | </td> |
11 | 11 | <td class="item_c">[LINE_ITEM_QUANTITY]</td> |
12 | 12 | <td class="item_c">[LINE_ITEM_AMOUNT]</td> |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | <div class="ticket-time-and-place-details"> |
23 | 23 | <div class="ticket-time-details"> |
24 | 24 | <h4 class="sub-section-title no-bottom-margin"> |
25 | - <img class="icon" src="<?php echo EE_IMAGES_URL . 'clock-16x16.png'; ?>"><?php _e('Date/Time:', 'event_espresso'); ?> |
|
25 | + <img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png'; ?>"><?php _e('Date/Time:', 'event_espresso'); ?> |
|
26 | 26 | </h4> |
27 | 27 | <ul class="event-dates">[DATETIME_LIST]</ul> |
28 | 28 | </div> |
29 | 29 | <div class="ticket-place-details"> |
30 | 30 | <h4 class="sub-section-title no-bottom-margin"> |
31 | - <img class="icon" src="<?php echo EE_IMAGES_URL . 'location-pin-16x16.png'; ?>"><?php _e('Venue', 'event_espresso'); ?> |
|
31 | + <img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png'; ?>"><?php _e('Venue', 'event_espresso'); ?> |
|
32 | 32 | </h4> |
33 | 33 | <ul class="event-venues"> |
34 | 34 | <li>[VENUE_TITLE] |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | </div> |
40 | 40 | <div class="ticket-registrations-area"> |
41 | 41 | <h4 class="sub-section-title"> |
42 | - <img class="icon" src="<?php echo EE_IMAGES_URL . 'users-16x16.png'; ?>"><?php _e("Registration Details", "event_espresso"); ?> |
|
42 | + <img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png'; ?>"><?php _e("Registration Details", "event_espresso"); ?> |
|
43 | 43 | <span class="small-text link">( <a class="print_button noPrint" href="[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]"><?php _e('edit', 'event_espresso'); ?></a> )</span> |
44 | 44 | </h4> |
45 | 45 | <ul class="ticket-registrations-list">[ATTENDEE_LIST]</ul> |
@@ -6,11 +6,11 @@ |
||
6 | 6 | <li class="ticket-registration"> |
7 | 7 | <table class="registration-details"> |
8 | 8 | <tr class="odd"> |
9 | - <th><?php _e('Attendee', 'event_espresso');?></th> |
|
9 | + <th><?php _e('Attendee', 'event_espresso'); ?></th> |
|
10 | 10 | <td>[FNAME] [LNAME] ([ATTENDEE_EMAIL])</td> |
11 | 11 | </tr> |
12 | 12 | <tr> |
13 | - <th><?php _e("Registration Code:", "event_espresso");?></th> |
|
13 | + <th><?php _e("Registration Code:", "event_espresso"); ?></th> |
|
14 | 14 | <td>[REGISTRATION_CODE] - <span class="[REGISTRATION_STATUS_ID]">[REGISTRATION_STATUS_LABEL]</span></td> |
15 | 15 | </tr> |
16 | 16 | </table> |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | // get the corresponding template pack object (if present. If not then we just load the default and add a |
114 | 114 | // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
115 | 115 | // the incoming template pack reference. |
116 | - $class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
116 | + $class_name = 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
117 | 117 | |
118 | - if (! class_exists($class_name)) { |
|
118 | + if ( ! class_exists($class_name)) { |
|
119 | 119 | EE_Error::add_error( |
120 | 120 | sprintf( |
121 | 121 | __( |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | { |
161 | 161 | $template_pack = 'default'; |
162 | 162 | // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
163 | - if (! empty($this->_GRP_ID)) { |
|
163 | + if ( ! empty($this->_GRP_ID)) { |
|
164 | 164 | $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
165 | 165 | $template_pack = $message_template_group instanceof EE_Message_Template_Group |
166 | 166 | ? $message_template_group->get_template_pack_name() |
@@ -206,17 +206,17 @@ discard block |
||
206 | 206 | $this->_GRP_ID = $grp_id; |
207 | 207 | } |
208 | 208 | |
209 | - $template_data = array( 'GRP_ID' => $this->_GRP_ID ); |
|
209 | + $template_data = array('GRP_ID' => $this->_GRP_ID); |
|
210 | 210 | |
211 | 211 | foreach ($this->_contexts as $context => $details) { |
212 | 212 | foreach ($this->_fields as $field => $field_type) { |
213 | 213 | if ($field != 'extra') { |
214 | 214 | $template_data['MTP_context'] = $context; |
215 | 215 | $template_data['MTP_template_field'] = $field; |
216 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
216 | + $template_data['MTP_content'] = $this->_templates[$context][$field]; |
|
217 | 217 | |
218 | 218 | $MTP = $this->_message_template_model->insert($template_data); |
219 | - if (! $MTP) { |
|
219 | + if ( ! $MTP) { |
|
220 | 220 | EE_Error::add_error( |
221 | 221 | sprintf( |
222 | 222 | __( |
@@ -15,232 +15,232 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Used for holding the EE_Message_Template GRP_ID field value. |
|
20 | - * @var [type] |
|
21 | - */ |
|
22 | - protected $_GRP_ID; |
|
23 | - |
|
24 | - /** |
|
25 | - * holds the messenger object |
|
26 | - * |
|
27 | - * @var EE_messenger |
|
28 | - */ |
|
29 | - protected $_messenger; |
|
30 | - |
|
31 | - /** |
|
32 | - * holds the message type object |
|
33 | - * |
|
34 | - * @var EE_message_type |
|
35 | - */ |
|
36 | - protected $_message_type; |
|
37 | - |
|
38 | - /** |
|
39 | - * holds the fields used (this is retrieved from the messenger) |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $_fields; |
|
44 | - |
|
45 | - /** |
|
46 | - * holds the assembled template (with defaults) for creation in the database |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $_templates; |
|
51 | - |
|
52 | - /** |
|
53 | - * holds the contexts used (this is retrieved from the message type) |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - protected $_contexts; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @var EEM_Message_Template_Group |
|
62 | - */ |
|
63 | - protected $_message_template_group_model; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EEM_Message_Template |
|
68 | - */ |
|
69 | - protected $_message_template_model; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * EE_Messages_Template_Defaults constructor. |
|
74 | - * |
|
75 | - * @param EE_messenger $messenger |
|
76 | - * @param EE_message_type $message_type |
|
77 | - * @param int $GRP_ID Optional. If included then we're just regenerating |
|
78 | - * the template fields for the given group not the |
|
79 | - * message template group itself |
|
80 | - * @param EEM_Message_Template_Group $message_template_group_model |
|
81 | - * @param EEM_Message_Template $message_template_model |
|
82 | - * @throws EE_Error |
|
83 | - */ |
|
84 | - public function __construct( |
|
85 | - EE_messenger $messenger, |
|
86 | - EE_message_type $message_type, |
|
87 | - $GRP_ID = 0, |
|
88 | - EEM_Message_Template_Group $message_template_group_model, |
|
89 | - EEM_Message_Template $message_template_model |
|
90 | - ) { |
|
91 | - $this->_messenger = $messenger; |
|
92 | - $this->_message_type = $message_type; |
|
93 | - $this->_GRP_ID = $GRP_ID; |
|
94 | - // set the model object |
|
95 | - $this->_message_template_group_model = $message_template_group_model; |
|
96 | - $this->_message_template_model = $message_template_model; |
|
97 | - $this->_fields = $this->_messenger->get_template_fields(); |
|
98 | - $this->_contexts = $this->_message_type->get_contexts(); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Setup the _template_data property. |
|
104 | - * This method sets the _templates property array before templates are created. |
|
105 | - * |
|
106 | - * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
107 | - * about where to obtain the templates. |
|
108 | - * |
|
109 | - */ |
|
110 | - final private function _set_templates($template_pack) |
|
111 | - { |
|
112 | - |
|
113 | - // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
114 | - // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
115 | - // the incoming template pack reference. |
|
116 | - $class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
117 | - |
|
118 | - if (! class_exists($class_name)) { |
|
119 | - EE_Error::add_error( |
|
120 | - sprintf( |
|
121 | - __( |
|
122 | - 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
123 | - 'event_espresso' |
|
124 | - ), |
|
125 | - $class_name |
|
126 | - ), |
|
127 | - __FILE__, |
|
128 | - __FUNCTION__, |
|
129 | - __LINE__ |
|
130 | - ); |
|
131 | - $class_name = 'EE_Messages_Template_Pack_Default'; |
|
132 | - } |
|
133 | - /** @type EE_Messages_Template_Pack $template_pack */ |
|
134 | - $template_pack = new $class_name(); |
|
135 | - |
|
136 | - // get all the templates from the template pack. |
|
137 | - $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Return the contexts for the message type as cached on this instance. |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function get_contexts() |
|
146 | - { |
|
147 | - return $this->_contexts; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * public facing create new templates method |
|
156 | - * |
|
157 | - * @return mixed (array|bool) success array or false. |
|
158 | - */ |
|
159 | - public function create_new_templates() |
|
160 | - { |
|
161 | - $template_pack = 'default'; |
|
162 | - // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
163 | - if (! empty($this->_GRP_ID)) { |
|
164 | - $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
165 | - $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
166 | - ? $message_template_group->get_template_pack_name() |
|
167 | - : 'default'; |
|
168 | - // we also need to reset the template variation to default |
|
169 | - $message_template_group->set_template_pack_variation('default'); |
|
170 | - } |
|
171 | - return $this->_create_new_templates($template_pack); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Handles creating new default templates. |
|
180 | - * |
|
181 | - * @param string $template_pack This corresponds to a template pack class reference |
|
182 | - * which will contain information about where to obtain the templates. |
|
183 | - * @return mixed (array|bool) success array or false. |
|
184 | - */ |
|
185 | - protected function _create_new_templates($template_pack) |
|
186 | - { |
|
187 | - |
|
188 | - $this->_set_templates($template_pack); |
|
189 | - |
|
190 | - // necessary properties are set, let's save the default templates |
|
191 | - if (empty($this->_GRP_ID)) { |
|
192 | - $main_template_data = array( |
|
193 | - 'MTP_messenger' => $this->_messenger->name, |
|
194 | - 'MTP_message_type' => $this->_message_type->name, |
|
195 | - 'MTP_is_override' => 0, |
|
196 | - 'MTP_deleted' => 0, |
|
197 | - 'MTP_is_global' => 1, |
|
198 | - 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
199 | - 'MTP_is_active' => 1, |
|
200 | - ); |
|
201 | - // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
202 | - $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
203 | - if (empty($grp_id)) { |
|
204 | - return $grp_id; |
|
205 | - } |
|
206 | - $this->_GRP_ID = $grp_id; |
|
207 | - } |
|
208 | - |
|
209 | - $template_data = array( 'GRP_ID' => $this->_GRP_ID ); |
|
210 | - |
|
211 | - foreach ($this->_contexts as $context => $details) { |
|
212 | - foreach ($this->_fields as $field => $field_type) { |
|
213 | - if ($field != 'extra') { |
|
214 | - $template_data['MTP_context'] = $context; |
|
215 | - $template_data['MTP_template_field'] = $field; |
|
216 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
217 | - |
|
218 | - $MTP = $this->_message_template_model->insert($template_data); |
|
219 | - if (! $MTP) { |
|
220 | - EE_Error::add_error( |
|
221 | - sprintf( |
|
222 | - __( |
|
223 | - 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
224 | - 'event_espresso' |
|
225 | - ), |
|
226 | - $this->_messenger->name, |
|
227 | - $this->_message_type->name, |
|
228 | - $context, |
|
229 | - $field |
|
230 | - ), |
|
231 | - __FILE__, |
|
232 | - __FUNCTION__, |
|
233 | - __LINE__ |
|
234 | - ); |
|
235 | - return false; |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return array( |
|
242 | - 'GRP_ID' => $this->_GRP_ID, |
|
243 | - 'MTP_context' => key($this->_contexts) |
|
244 | - ); |
|
245 | - } |
|
18 | + /** |
|
19 | + * Used for holding the EE_Message_Template GRP_ID field value. |
|
20 | + * @var [type] |
|
21 | + */ |
|
22 | + protected $_GRP_ID; |
|
23 | + |
|
24 | + /** |
|
25 | + * holds the messenger object |
|
26 | + * |
|
27 | + * @var EE_messenger |
|
28 | + */ |
|
29 | + protected $_messenger; |
|
30 | + |
|
31 | + /** |
|
32 | + * holds the message type object |
|
33 | + * |
|
34 | + * @var EE_message_type |
|
35 | + */ |
|
36 | + protected $_message_type; |
|
37 | + |
|
38 | + /** |
|
39 | + * holds the fields used (this is retrieved from the messenger) |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $_fields; |
|
44 | + |
|
45 | + /** |
|
46 | + * holds the assembled template (with defaults) for creation in the database |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $_templates; |
|
51 | + |
|
52 | + /** |
|
53 | + * holds the contexts used (this is retrieved from the message type) |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + protected $_contexts; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @var EEM_Message_Template_Group |
|
62 | + */ |
|
63 | + protected $_message_template_group_model; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EEM_Message_Template |
|
68 | + */ |
|
69 | + protected $_message_template_model; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * EE_Messages_Template_Defaults constructor. |
|
74 | + * |
|
75 | + * @param EE_messenger $messenger |
|
76 | + * @param EE_message_type $message_type |
|
77 | + * @param int $GRP_ID Optional. If included then we're just regenerating |
|
78 | + * the template fields for the given group not the |
|
79 | + * message template group itself |
|
80 | + * @param EEM_Message_Template_Group $message_template_group_model |
|
81 | + * @param EEM_Message_Template $message_template_model |
|
82 | + * @throws EE_Error |
|
83 | + */ |
|
84 | + public function __construct( |
|
85 | + EE_messenger $messenger, |
|
86 | + EE_message_type $message_type, |
|
87 | + $GRP_ID = 0, |
|
88 | + EEM_Message_Template_Group $message_template_group_model, |
|
89 | + EEM_Message_Template $message_template_model |
|
90 | + ) { |
|
91 | + $this->_messenger = $messenger; |
|
92 | + $this->_message_type = $message_type; |
|
93 | + $this->_GRP_ID = $GRP_ID; |
|
94 | + // set the model object |
|
95 | + $this->_message_template_group_model = $message_template_group_model; |
|
96 | + $this->_message_template_model = $message_template_model; |
|
97 | + $this->_fields = $this->_messenger->get_template_fields(); |
|
98 | + $this->_contexts = $this->_message_type->get_contexts(); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Setup the _template_data property. |
|
104 | + * This method sets the _templates property array before templates are created. |
|
105 | + * |
|
106 | + * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
107 | + * about where to obtain the templates. |
|
108 | + * |
|
109 | + */ |
|
110 | + final private function _set_templates($template_pack) |
|
111 | + { |
|
112 | + |
|
113 | + // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
114 | + // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
115 | + // the incoming template pack reference. |
|
116 | + $class_name = 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
117 | + |
|
118 | + if (! class_exists($class_name)) { |
|
119 | + EE_Error::add_error( |
|
120 | + sprintf( |
|
121 | + __( |
|
122 | + 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
123 | + 'event_espresso' |
|
124 | + ), |
|
125 | + $class_name |
|
126 | + ), |
|
127 | + __FILE__, |
|
128 | + __FUNCTION__, |
|
129 | + __LINE__ |
|
130 | + ); |
|
131 | + $class_name = 'EE_Messages_Template_Pack_Default'; |
|
132 | + } |
|
133 | + /** @type EE_Messages_Template_Pack $template_pack */ |
|
134 | + $template_pack = new $class_name(); |
|
135 | + |
|
136 | + // get all the templates from the template pack. |
|
137 | + $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Return the contexts for the message type as cached on this instance. |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function get_contexts() |
|
146 | + { |
|
147 | + return $this->_contexts; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * public facing create new templates method |
|
156 | + * |
|
157 | + * @return mixed (array|bool) success array or false. |
|
158 | + */ |
|
159 | + public function create_new_templates() |
|
160 | + { |
|
161 | + $template_pack = 'default'; |
|
162 | + // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
163 | + if (! empty($this->_GRP_ID)) { |
|
164 | + $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
165 | + $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
166 | + ? $message_template_group->get_template_pack_name() |
|
167 | + : 'default'; |
|
168 | + // we also need to reset the template variation to default |
|
169 | + $message_template_group->set_template_pack_variation('default'); |
|
170 | + } |
|
171 | + return $this->_create_new_templates($template_pack); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Handles creating new default templates. |
|
180 | + * |
|
181 | + * @param string $template_pack This corresponds to a template pack class reference |
|
182 | + * which will contain information about where to obtain the templates. |
|
183 | + * @return mixed (array|bool) success array or false. |
|
184 | + */ |
|
185 | + protected function _create_new_templates($template_pack) |
|
186 | + { |
|
187 | + |
|
188 | + $this->_set_templates($template_pack); |
|
189 | + |
|
190 | + // necessary properties are set, let's save the default templates |
|
191 | + if (empty($this->_GRP_ID)) { |
|
192 | + $main_template_data = array( |
|
193 | + 'MTP_messenger' => $this->_messenger->name, |
|
194 | + 'MTP_message_type' => $this->_message_type->name, |
|
195 | + 'MTP_is_override' => 0, |
|
196 | + 'MTP_deleted' => 0, |
|
197 | + 'MTP_is_global' => 1, |
|
198 | + 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
199 | + 'MTP_is_active' => 1, |
|
200 | + ); |
|
201 | + // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
202 | + $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
203 | + if (empty($grp_id)) { |
|
204 | + return $grp_id; |
|
205 | + } |
|
206 | + $this->_GRP_ID = $grp_id; |
|
207 | + } |
|
208 | + |
|
209 | + $template_data = array( 'GRP_ID' => $this->_GRP_ID ); |
|
210 | + |
|
211 | + foreach ($this->_contexts as $context => $details) { |
|
212 | + foreach ($this->_fields as $field => $field_type) { |
|
213 | + if ($field != 'extra') { |
|
214 | + $template_data['MTP_context'] = $context; |
|
215 | + $template_data['MTP_template_field'] = $field; |
|
216 | + $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
217 | + |
|
218 | + $MTP = $this->_message_template_model->insert($template_data); |
|
219 | + if (! $MTP) { |
|
220 | + EE_Error::add_error( |
|
221 | + sprintf( |
|
222 | + __( |
|
223 | + 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
224 | + 'event_espresso' |
|
225 | + ), |
|
226 | + $this->_messenger->name, |
|
227 | + $this->_message_type->name, |
|
228 | + $context, |
|
229 | + $field |
|
230 | + ), |
|
231 | + __FILE__, |
|
232 | + __FUNCTION__, |
|
233 | + __LINE__ |
|
234 | + ); |
|
235 | + return false; |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return array( |
|
242 | + 'GRP_ID' => $this->_GRP_ID, |
|
243 | + 'MTP_context' => key($this->_contexts) |
|
244 | + ); |
|
245 | + } |
|
246 | 246 | } |
@@ -11,19 +11,19 @@ |
||
11 | 11 | { |
12 | 12 | |
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - $this->interface = 'EE_Messages_Template_Pack'; |
|
17 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + $this->interface = 'EE_Messages_Template_Pack'; |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_by_name($template_pack_name) |
|
20 | - { |
|
21 | - $this->rewind(); |
|
22 | - while ($this->valid()) { |
|
23 | - if ($this->current()->dbref == $template_pack_name) { |
|
24 | - return $this->current(); |
|
25 | - } |
|
26 | - $this->next(); |
|
27 | - } |
|
28 | - } |
|
19 | + public function get_by_name($template_pack_name) |
|
20 | + { |
|
21 | + $this->rewind(); |
|
22 | + while ($this->valid()) { |
|
23 | + if ($this->current()->dbref == $template_pack_name) { |
|
24 | + return $this->current(); |
|
25 | + } |
|
26 | + $this->next(); |
|
27 | + } |
|
28 | + } |
|
29 | 29 | } |