|
1
|
|
|
<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2
|
|
|
exit( 'No direct script access allowed' ); |
|
3
|
|
|
} |
|
4
|
|
|
/** |
|
5
|
|
|
* EE_Message class |
|
6
|
|
|
* |
|
7
|
|
|
* @package Event Espresso |
|
8
|
|
|
* @subpackage db classes |
|
9
|
|
|
* @author Darren Ethier |
|
10
|
|
|
*/ |
|
11
|
|
|
class EE_Message extends EE_Base_Class implements EEI_Admin_Links { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @deprecated 4.9.0 Added for backward compat with add-on's |
|
15
|
|
|
* @type null |
|
16
|
|
|
*/ |
|
17
|
|
|
public $template_pack; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @deprecated 4.9.0 Added for backward compat with add-on's |
|
21
|
|
|
* @type null |
|
22
|
|
|
*/ |
|
23
|
|
|
public $template_variation; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @deprecated 4.9.0 Added for backward compat with add-on's |
|
27
|
|
|
* @type string |
|
28
|
|
|
*/ |
|
29
|
|
|
public $content = ''; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @type EE_messenger $_messenger |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $_messenger = null; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @type EE_message_type $_message_type |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $_message_type = null; |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $props_n_values |
|
47
|
|
|
* @param string $timezone |
|
48
|
|
|
* @param array $date_formats incoming date formats in an array. First value is the date_format, second is time format. |
|
49
|
|
|
* @return EE_Message |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
52
|
|
|
$has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
|
|
|
|
|
53
|
|
|
//if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
54
|
|
|
if ( ! $has_object ) { |
|
55
|
|
|
EE_Registry::instance()->load_helper( 'URL' ); |
|
56
|
|
|
$props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
57
|
|
|
} |
|
58
|
|
|
return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* |
|
65
|
|
|
* @param array $props_n_values |
|
66
|
|
|
* @param string $timezone |
|
67
|
|
|
* @return EE_Message |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
70
|
|
|
return new self( $props_n_values, true, $timezone ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Gets MSG_token |
|
77
|
|
|
* |
|
78
|
|
|
* @return int |
|
79
|
|
|
*/ |
|
80
|
|
|
public function MSG_token() { |
|
81
|
|
|
return $this->get( 'MSG_token' ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Sets MSG_token |
|
88
|
|
|
* |
|
89
|
|
|
* @param int $MSG_token |
|
90
|
|
|
*/ |
|
91
|
|
|
public function set_MSG_token( $MSG_token) { |
|
92
|
|
|
$this->set( 'MSG_token', $MSG_token ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Gets GRP_ID |
|
100
|
|
|
* |
|
101
|
|
|
* @return int |
|
102
|
|
|
*/ |
|
103
|
|
|
public function GRP_ID() { |
|
104
|
|
|
return $this->get( 'GRP_ID' ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Sets GRP_ID |
|
111
|
|
|
* |
|
112
|
|
|
* @param int $GRP_ID |
|
113
|
|
|
*/ |
|
114
|
|
|
public function set_GRP_ID( $GRP_ID ) { |
|
115
|
|
|
$this->set( 'GRP_ID', $GRP_ID ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Gets TXN_ID |
|
123
|
|
|
* |
|
124
|
|
|
* @return int |
|
125
|
|
|
*/ |
|
126
|
|
|
public function TXN_ID() { |
|
127
|
|
|
return $this->get( 'TXN_ID' ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Sets TXN_ID |
|
134
|
|
|
* |
|
135
|
|
|
* @param int $TXN_ID |
|
136
|
|
|
*/ |
|
137
|
|
|
public function set_TXN_ID( $TXN_ID) { |
|
138
|
|
|
$this->set( 'TXN_ID', $TXN_ID ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Gets messenger |
|
146
|
|
|
* |
|
147
|
|
|
* @return string |
|
148
|
|
|
*/ |
|
149
|
|
|
public function messenger() { |
|
150
|
|
|
return $this->get( 'MSG_messenger' ); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Sets messenger |
|
157
|
|
|
* |
|
158
|
|
|
* @param string $messenger |
|
159
|
|
|
*/ |
|
160
|
|
|
public function set_messenger( $messenger ) { |
|
161
|
|
|
$this->set( 'MSG_messenger', $messenger ); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Returns corresponding messenger object for the set messenger on this message |
|
168
|
|
|
* |
|
169
|
|
|
* @return EE_messenger | null |
|
170
|
|
|
*/ |
|
171
|
|
|
public function messenger_object() { |
|
172
|
|
|
return $this->_messenger; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Sets messenger |
|
179
|
|
|
* |
|
180
|
|
|
* @param EE_messenger $messenger |
|
181
|
|
|
*/ |
|
182
|
|
|
public function set_messenger_object( EE_messenger $messenger ) { |
|
183
|
|
|
$this->_messenger = $messenger; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* validates messenger |
|
190
|
|
|
* |
|
191
|
|
|
* @param bool $throw_exceptions |
|
192
|
|
|
* @return bool |
|
193
|
|
|
* @throws \EE_Error |
|
194
|
|
|
*/ |
|
195
|
|
|
public function valid_messenger( $throw_exceptions = false ) { |
|
196
|
|
|
if ( $this->_messenger instanceof EE_messenger ) { |
|
197
|
|
|
return true; |
|
198
|
|
|
} |
|
199
|
|
|
if ( $throw_exceptions ) { |
|
200
|
|
|
throw new EE_Error( |
|
201
|
|
|
sprintf( |
|
202
|
|
|
__( |
|
203
|
|
|
'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
204
|
|
|
'event_espresso' |
|
205
|
|
|
), |
|
206
|
|
|
$this->messenger() |
|
207
|
|
|
) |
|
208
|
|
|
); |
|
209
|
|
|
} |
|
210
|
|
|
return false; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* This returns the set localized label for the messenger on this message. |
|
217
|
|
|
* Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
218
|
|
|
* with this message. |
|
219
|
|
|
* |
|
220
|
|
|
* @param bool $plural whether to return the plural label or not. |
|
221
|
|
|
* @return string |
|
222
|
|
|
*/ |
|
223
|
|
|
public function messenger_label( $plural = false ) { |
|
224
|
|
|
$label_type = $plural ? 'plural' : 'singular'; |
|
225
|
|
|
$messenger = $this->messenger_object(); |
|
226
|
|
|
return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger(); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Gets message_type |
|
233
|
|
|
* |
|
234
|
|
|
* @return string |
|
235
|
|
|
*/ |
|
236
|
|
|
public function message_type() { |
|
237
|
|
|
return $this->get( 'MSG_message_type' ); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Sets message_type |
|
244
|
|
|
* |
|
245
|
|
|
* @param string $message_type |
|
246
|
|
|
*/ |
|
247
|
|
|
public function set_message_type( $message_type ) { |
|
248
|
|
|
$this->set( 'MSG_message_type', $message_type ); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Returns the message type object for the set message type on this message |
|
255
|
|
|
* |
|
256
|
|
|
* @return EE_message_type | null |
|
257
|
|
|
*/ |
|
258
|
|
|
public function message_type_object() { |
|
259
|
|
|
return $this->_message_type; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
|
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Sets message_type |
|
266
|
|
|
* |
|
267
|
|
|
* @param EE_message_type $message_type |
|
268
|
|
|
* @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
269
|
|
|
* the message type or not. |
|
270
|
|
|
*/ |
|
271
|
|
|
public function set_message_type_object( EE_message_type $message_type, $set_priority = false ) { |
|
272
|
|
|
$this->_message_type = $message_type; |
|
273
|
|
|
if ( $set_priority ) { |
|
274
|
|
|
$this->set_priority( $this->_message_type->get_priority() ); |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* validates message_type |
|
282
|
|
|
* |
|
283
|
|
|
* @param bool $throw_exceptions |
|
284
|
|
|
* @return bool |
|
285
|
|
|
* @throws \EE_Error |
|
286
|
|
|
*/ |
|
287
|
|
|
public function valid_message_type( $throw_exceptions = false ) { |
|
288
|
|
|
if ( $this->_message_type instanceof EE_message_type ) { |
|
289
|
|
|
return true; |
|
290
|
|
|
} |
|
291
|
|
|
if ( $throw_exceptions ) { |
|
292
|
|
|
throw new EE_Error( |
|
293
|
|
|
sprintf( |
|
294
|
|
|
__( |
|
295
|
|
|
'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
296
|
|
|
'event_espresso' |
|
297
|
|
|
), |
|
298
|
|
|
$this->message_type() |
|
299
|
|
|
) |
|
300
|
|
|
); |
|
301
|
|
|
} |
|
302
|
|
|
return false; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
309
|
|
|
* |
|
310
|
|
|
* @param bool $throw_exceptions |
|
311
|
|
|
* @return bool |
|
312
|
|
|
* @throws \EE_Error |
|
313
|
|
|
*/ |
|
314
|
|
|
public function is_valid( $throw_exceptions = false ) { |
|
315
|
|
|
if ( $this->valid_messenger( $throw_exceptions ) && $this->valid_message_type( $throw_exceptions ) ) { |
|
316
|
|
|
return true; |
|
317
|
|
|
} |
|
318
|
|
|
return false; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* This validates whether the internal messenger and message type objects are valid for sending. |
|
324
|
|
|
* |
|
325
|
|
|
* Three checks are done: |
|
326
|
|
|
* |
|
327
|
|
|
* 1. There is a valid messenger object. |
|
328
|
|
|
* 2. There is a valid message type object. |
|
329
|
|
|
* 3. The message type object is active for the messenger. |
|
330
|
|
|
* |
|
331
|
|
|
* @throws EE_Error But only if $throw_exceptions is set to true. |
|
332
|
|
|
* |
|
333
|
|
|
* @param bool $throw_exceptions |
|
334
|
|
|
* @return bool |
|
335
|
|
|
*/ |
|
336
|
|
|
public function is_valid_for_sending_or_generation( $throw_exceptions = false ) { |
|
337
|
|
|
$valid = false; |
|
338
|
|
|
if ( $this->is_valid( $throw_exceptions ) ) { |
|
339
|
|
|
/** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
340
|
|
|
$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
341
|
|
|
$valid = $message_resource_manager->is_message_type_active_for_messenger( $this->messenger(), $this->message_type() ); |
|
342
|
|
|
if ( ! $valid && $throw_exceptions ) { |
|
343
|
|
|
throw new EE_Error( |
|
344
|
|
|
sprintf( |
|
345
|
|
|
__( 'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', 'event_espresso' ), |
|
346
|
|
|
$this->message_type(), |
|
347
|
|
|
$this->messenger() |
|
348
|
|
|
) |
|
349
|
|
|
); |
|
350
|
|
|
} |
|
351
|
|
|
} |
|
352
|
|
|
return $valid; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
|
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* This returns the set localized label for the message type on this message. |
|
359
|
|
|
* Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
360
|
|
|
* with this message. |
|
361
|
|
|
* |
|
362
|
|
|
* @param bool $plural whether to return the plural label or not. |
|
363
|
|
|
* @return string |
|
364
|
|
|
*/ |
|
365
|
|
|
public function message_type_label( $plural = false ) { |
|
366
|
|
|
$label_type = $plural ? 'plural' : 'singular'; |
|
367
|
|
|
$message_type = $this->message_type_object(); |
|
368
|
|
|
return $message_type instanceof EE_message_type ? $message_type->label[ $label_type ] : $this->message_type(); |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
|
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* Gets context |
|
375
|
|
|
* |
|
376
|
|
|
* @return string |
|
377
|
|
|
*/ |
|
378
|
|
|
public function context() { |
|
379
|
|
|
return $this->get( 'MSG_context' ); |
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
|
|
383
|
|
|
|
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* This returns the corresponding localized label for the given context slug, if possible from installed message types. |
|
387
|
|
|
* Otherwise, this will just return the set context slug on this object. |
|
388
|
|
|
* |
|
389
|
|
|
* @return string |
|
390
|
|
|
*/ |
|
391
|
|
|
public function context_label() { |
|
392
|
|
|
/** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
393
|
|
|
$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
394
|
|
|
$contexts = $message_resource_manager->get_all_contexts(); |
|
395
|
|
|
return isset( $contexts[ $this->context() ] ) ? $contexts[ $this->context() ] : $this->context(); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Sets context |
|
402
|
|
|
* |
|
403
|
|
|
* @param string $context |
|
404
|
|
|
*/ |
|
405
|
|
|
public function set_context( $context ) { |
|
406
|
|
|
$this->set( 'MSG_context', $context ); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* Gets recipient_ID |
|
413
|
|
|
* |
|
414
|
|
|
* @return int |
|
415
|
|
|
*/ |
|
416
|
|
|
public function recipient_ID() { |
|
417
|
|
|
return $this->get( 'MSG_recipient_ID' ); |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* Sets recipient_ID |
|
424
|
|
|
* |
|
425
|
|
|
* @param string $recipient_ID |
|
426
|
|
|
*/ |
|
427
|
|
|
public function set_recipient_ID( $recipient_ID ) { |
|
428
|
|
|
$this->set( 'MSG_recipient_ID', $recipient_ID ); |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
|
|
432
|
|
|
|
|
433
|
|
|
/** |
|
434
|
|
|
* Gets recipient_type |
|
435
|
|
|
* |
|
436
|
|
|
* @return string |
|
437
|
|
|
*/ |
|
438
|
|
|
public function recipient_type() { |
|
439
|
|
|
return $this->get( 'MSG_recipient_type' ); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
|
|
443
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* Return the related object matching the recipient type and ID. |
|
447
|
|
|
* |
|
448
|
|
|
* @return EE_Base_Class | null |
|
449
|
|
|
*/ |
|
450
|
|
|
public function recipient_object() { |
|
451
|
|
|
if ( ! $this->recipient_type() || ! $this->recipient_ID() ) { |
|
452
|
|
|
return null; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
return $this->get_first_related( $this->recipient_type() ); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
|
|
459
|
|
|
|
|
460
|
|
|
/** |
|
461
|
|
|
* Sets recipient_type |
|
462
|
|
|
* |
|
463
|
|
|
* @param string $recipient_type |
|
464
|
|
|
*/ |
|
465
|
|
|
public function set_recipient_type( $recipient_type ) { |
|
466
|
|
|
$this->set( 'MSG_recipient_type', $recipient_type ); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
|
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* Gets content |
|
473
|
|
|
* |
|
474
|
|
|
* @return string |
|
475
|
|
|
*/ |
|
476
|
|
|
public function content() { |
|
477
|
|
|
return $this->get( 'MSG_content' ); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* Sets content |
|
484
|
|
|
* |
|
485
|
|
|
* @param string $content |
|
486
|
|
|
*/ |
|
487
|
|
|
public function set_content( $content ) { |
|
488
|
|
|
$this->set( 'MSG_content', $content ); |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
|
|
492
|
|
|
|
|
493
|
|
|
/** |
|
494
|
|
|
* Gets subject |
|
495
|
|
|
* |
|
496
|
|
|
* @return string |
|
497
|
|
|
*/ |
|
498
|
|
|
public function subject() { |
|
499
|
|
|
return $this->get( 'MSG_subject' ); |
|
500
|
|
|
} |
|
501
|
|
|
|
|
502
|
|
|
|
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Sets subject |
|
506
|
|
|
* |
|
507
|
|
|
* @param string $subject |
|
508
|
|
|
*/ |
|
509
|
|
|
public function set_subject( $subject ) { |
|
510
|
|
|
$this->set( 'MSG_subject', $subject ); |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
|
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* Gets to |
|
517
|
|
|
* |
|
518
|
|
|
* @return string |
|
519
|
|
|
*/ |
|
520
|
|
|
public function to() { |
|
521
|
|
|
$to = $this->get( 'MSG_to' ); |
|
522
|
|
|
return empty( $to ) ? __( 'No recipient', 'event_espresso' ) : $to; |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
|
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* Sets to |
|
529
|
|
|
* |
|
530
|
|
|
* @param string $to |
|
531
|
|
|
*/ |
|
532
|
|
|
public function set_to( $to ) { |
|
533
|
|
|
$this->set( 'MSG_to', $to ); |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
|
|
537
|
|
|
|
|
538
|
|
|
/** |
|
539
|
|
|
* Gets from |
|
540
|
|
|
* |
|
541
|
|
|
* @return string |
|
542
|
|
|
*/ |
|
543
|
|
|
public function from() { |
|
544
|
|
|
return $this->get( 'MSG_from' ); |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
|
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* Sets from |
|
551
|
|
|
* |
|
552
|
|
|
* @param string $from |
|
553
|
|
|
*/ |
|
554
|
|
|
public function set_from( $from ) { |
|
555
|
|
|
$this->set( 'MSG_from', $from ); |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
|
|
559
|
|
|
|
|
560
|
|
|
|
|
561
|
|
|
|
|
562
|
|
|
/** |
|
563
|
|
|
* Gets priority |
|
564
|
|
|
* |
|
565
|
|
|
* @return int |
|
566
|
|
|
*/ |
|
567
|
|
|
public function priority() { |
|
568
|
|
|
return $this->get( 'MSG_priority' ); |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
|
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Sets priority |
|
575
|
|
|
* |
|
576
|
|
|
* Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
577
|
|
|
* this method calls the send_now method to verify that. |
|
578
|
|
|
* |
|
579
|
|
|
* @param int $priority |
|
580
|
|
|
*/ |
|
581
|
|
|
public function set_priority( $priority ) { |
|
582
|
|
|
$priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
583
|
|
|
parent::set( 'MSG_priority', $priority ); |
|
|
|
|
|
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* Overrides parent::set method so we can capture any sets for priority. |
|
589
|
|
|
* @see parent::set() for phpdocs |
|
590
|
|
|
* @param string $field_name |
|
591
|
|
|
* @param mixed $field_value |
|
592
|
|
|
* @param bool $use_default |
|
593
|
|
|
* @throws EE_Error |
|
594
|
|
|
*/ |
|
595
|
|
|
public function set( $field_name, $field_value, $use_default = false ) { |
|
596
|
|
|
if ( $field_name === 'MSG_priority' ) { |
|
597
|
|
|
$this->set_priority( $field_value ); |
|
598
|
|
|
} |
|
599
|
|
|
parent::set( $field_name, $field_value, $use_default ); |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
|
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* @return bool |
|
606
|
|
|
* @throws \EE_Error |
|
607
|
|
|
*/ |
|
608
|
|
|
public function send_now() { |
|
609
|
|
|
$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority(); |
|
610
|
|
|
return $send_now === EEM_Message::priority_high ? true : false; |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
|
|
614
|
|
|
|
|
615
|
|
|
/** |
|
616
|
|
|
* Gets STS_ID |
|
617
|
|
|
* |
|
618
|
|
|
* @return string |
|
619
|
|
|
*/ |
|
620
|
|
|
public function STS_ID() { |
|
621
|
|
|
return $this->get( 'STS_ID' ); |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
|
|
|
|
625
|
|
|
|
|
626
|
|
|
/** |
|
627
|
|
|
* Sets STS_ID |
|
628
|
|
|
* |
|
629
|
|
|
* @param string $STS_ID |
|
630
|
|
|
*/ |
|
631
|
|
|
public function set_STS_ID( $STS_ID ) { |
|
632
|
|
|
$this->set( 'STS_ID', $STS_ID ); |
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
|
|
636
|
|
|
|
|
637
|
|
|
/** |
|
638
|
|
|
* Gets created |
|
639
|
|
|
* |
|
640
|
|
|
* @return string |
|
641
|
|
|
*/ |
|
642
|
|
|
public function created() { |
|
643
|
|
|
return $this->get( 'MSG_created' ); |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
|
|
647
|
|
|
|
|
648
|
|
|
/** |
|
649
|
|
|
* Sets created |
|
650
|
|
|
* |
|
651
|
|
|
* @param string $created |
|
652
|
|
|
*/ |
|
653
|
|
|
public function set_created( $created ) { |
|
654
|
|
|
$this->set( 'MSG_created', $created ); |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
|
|
658
|
|
|
|
|
659
|
|
|
/** |
|
660
|
|
|
* Gets modified |
|
661
|
|
|
* |
|
662
|
|
|
* @return string |
|
663
|
|
|
*/ |
|
664
|
|
|
public function modified() { |
|
665
|
|
|
return $this->get( 'MSG_modified' ); |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
|
|
669
|
|
|
|
|
670
|
|
|
/** |
|
671
|
|
|
* Sets modified |
|
672
|
|
|
* |
|
673
|
|
|
* @param string $modified |
|
674
|
|
|
*/ |
|
675
|
|
|
public function set_modified( $modified ) { |
|
676
|
|
|
$this->set( 'MSG_modified', $modified ); |
|
677
|
|
|
} |
|
678
|
|
|
|
|
679
|
|
|
|
|
680
|
|
|
|
|
681
|
|
|
|
|
682
|
|
|
/** |
|
683
|
|
|
* Sets generation data for this message. |
|
684
|
|
|
* @param mixed $data |
|
685
|
|
|
*/ |
|
686
|
|
|
public function set_generation_data( $data ) { |
|
687
|
|
|
$this->set_field_or_extra_meta( 'MSG_generation_data', $data ); |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
|
|
691
|
|
|
|
|
692
|
|
|
|
|
693
|
|
|
|
|
694
|
|
|
/** |
|
695
|
|
|
* Returns any set generation data for this message. |
|
696
|
|
|
* @return mixed|null |
|
697
|
|
|
*/ |
|
698
|
|
|
public function get_generation_data() { |
|
699
|
|
|
return $this->get_field_or_extra_meta( 'MSG_generation_data' ); |
|
700
|
|
|
} |
|
701
|
|
|
|
|
702
|
|
|
|
|
703
|
|
|
|
|
704
|
|
|
|
|
705
|
|
|
/** |
|
706
|
|
|
* Gets any error message. |
|
707
|
|
|
* @return mixed|null |
|
708
|
|
|
*/ |
|
709
|
|
|
public function error_message() { |
|
710
|
|
|
return $this->get_field_or_extra_meta( 'MSG_error' ); |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
|
|
714
|
|
|
/** |
|
715
|
|
|
* Sets an error message. |
|
716
|
|
|
* @param $message |
|
717
|
|
|
* @return bool|int |
|
718
|
|
|
*/ |
|
719
|
|
|
public function set_error_message( $message ) { |
|
720
|
|
|
return $this->set_field_or_extra_meta( 'MSG_error', $message ); |
|
721
|
|
|
} |
|
722
|
|
|
|
|
723
|
|
|
|
|
724
|
|
|
|
|
725
|
|
|
|
|
726
|
|
|
/** |
|
727
|
|
|
* This retrieves the associated template pack with this message. |
|
728
|
|
|
* @return EE_Messages_Template_Pack | null |
|
729
|
|
|
*/ |
|
730
|
|
View Code Duplication |
public function get_template_pack() { |
|
|
|
|
|
|
731
|
|
|
/** |
|
732
|
|
|
* This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
733
|
|
|
*/ |
|
734
|
|
|
if ( ! empty( $this->template_pack ) ) { |
|
|
|
|
|
|
735
|
|
|
return $this->template_pack; |
|
|
|
|
|
|
736
|
|
|
} |
|
737
|
|
|
/** @type EE_Message_Template_Group $grp */ |
|
738
|
|
|
$grp = $this->get_first_related( 'Message_Template_Group' ); |
|
739
|
|
|
//if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
740
|
|
|
if ( ! $grp instanceof EE_Message_Template_Group ) { |
|
741
|
|
|
$grp = EEM_Message_Template_Group::instance()->get_one( |
|
742
|
|
|
array( |
|
743
|
|
|
array( |
|
744
|
|
|
'MTP_messenger' => $this->messenger(), |
|
745
|
|
|
'MTP_message_type' => $this->message_type(), |
|
746
|
|
|
'MTP_is_global' => true |
|
747
|
|
|
) |
|
748
|
|
|
) |
|
749
|
|
|
); |
|
750
|
|
|
} |
|
751
|
|
|
|
|
752
|
|
|
return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
|
|
756
|
|
|
|
|
757
|
|
|
|
|
758
|
|
|
/** |
|
759
|
|
|
* Retrieves the variation used for generating this message. |
|
760
|
|
|
* @return string |
|
761
|
|
|
*/ |
|
762
|
|
View Code Duplication |
public function get_template_pack_variation() { |
|
|
|
|
|
|
763
|
|
|
/** |
|
764
|
|
|
* This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
765
|
|
|
*/ |
|
766
|
|
|
if ( ! empty( $this->template_variation ) ) { |
|
|
|
|
|
|
767
|
|
|
return $this->template_variation; |
|
|
|
|
|
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
|
|
/** @type EE_Message_Template_Group $grp */ |
|
771
|
|
|
$grp = $this->get_first_related( 'Message_Template_Group' ); |
|
772
|
|
|
|
|
773
|
|
|
//if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
774
|
|
|
if ( ! $grp instanceof EE_Message_Template_Group ) { |
|
775
|
|
|
$grp = EEM_Message_Template_Group::instance()->get_one( |
|
776
|
|
|
array( |
|
777
|
|
|
array( |
|
778
|
|
|
'MTP_messenger' => $this->messenger(), |
|
779
|
|
|
'MTP_message_type' => $this->message_type(), |
|
780
|
|
|
'MTP_is_global' => true |
|
781
|
|
|
) |
|
782
|
|
|
) |
|
783
|
|
|
); |
|
784
|
|
|
} |
|
785
|
|
|
|
|
786
|
|
|
return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
787
|
|
|
} |
|
788
|
|
|
|
|
789
|
|
|
/** |
|
790
|
|
|
* Return the link to the admin details for the object. |
|
791
|
|
|
* @return string |
|
792
|
|
|
*/ |
|
793
|
|
|
public function get_admin_details_link() { |
|
794
|
|
|
EE_Registry::instance()->load_helper( 'URL' ); |
|
795
|
|
|
EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
796
|
|
|
switch ( $this->STS_ID() ) { |
|
797
|
|
|
case EEM_Message::status_failed : |
|
798
|
|
|
case EEM_Message::status_debug_only : |
|
799
|
|
|
return EEH_MSG_Template::generate_error_display_trigger( $this ); |
|
800
|
|
|
break; |
|
|
|
|
|
|
801
|
|
|
|
|
802
|
|
|
case EEM_Message::status_sent : |
|
803
|
|
|
return EEH_MSG_Template::generate_browser_trigger( $this ); |
|
804
|
|
|
break; |
|
|
|
|
|
|
805
|
|
|
|
|
806
|
|
|
default : |
|
807
|
|
|
return ''; |
|
808
|
|
|
} |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
/** |
|
812
|
|
|
* Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
813
|
|
|
* @return string |
|
814
|
|
|
*/ |
|
815
|
|
|
public function get_admin_edit_link() { |
|
816
|
|
|
return $this->get_admin_details_link(); |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
/** |
|
820
|
|
|
* Returns the link to a settings page for the object. |
|
821
|
|
|
* @return string |
|
822
|
|
|
*/ |
|
823
|
|
View Code Duplication |
public function get_admin_settings_link() { |
|
|
|
|
|
|
824
|
|
|
EE_Registry::instance()->load_helper( 'URL' ); |
|
825
|
|
|
return EEH_URL::add_query_args_and_nonce( |
|
826
|
|
|
array( |
|
827
|
|
|
'page' => 'espresso_messages', |
|
828
|
|
|
'action' => 'settings', |
|
829
|
|
|
), |
|
830
|
|
|
admin_url( 'admin.php' ) |
|
831
|
|
|
); |
|
832
|
|
|
} |
|
833
|
|
|
|
|
834
|
|
|
/** |
|
835
|
|
|
* Returns the link to the "overview" for the object (typically the "list table" view). |
|
836
|
|
|
* @return string |
|
837
|
|
|
*/ |
|
838
|
|
|
public function get_admin_overview_link() { |
|
839
|
|
|
EE_Registry::instance()->load_helper( 'URL' ); |
|
840
|
|
|
return EEH_URL::add_query_args_and_nonce( |
|
841
|
|
|
array( |
|
842
|
|
|
'page' => 'espresso_messages', |
|
843
|
|
|
'action' => 'default', |
|
844
|
|
|
), |
|
845
|
|
|
admin_url( 'admin.php' ) |
|
846
|
|
|
); |
|
847
|
|
|
} |
|
848
|
|
|
|
|
849
|
|
|
|
|
850
|
|
|
} |
|
851
|
|
|
/* End of file EE_Message.class.php */ |
|
852
|
|
|
/* Location: /core/db_classes/EE_Message.class.php */ |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.