@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return $this->_message; |
94 | 94 | } |
95 | 95 | $message = EEM_Message::instance()->get_one_by_token($this->token); |
96 | - if (! $message instanceof EE_Message) { |
|
96 | + if ( ! $message instanceof EE_Message) { |
|
97 | 97 | throw new EE_Error( |
98 | 98 | sprintf( |
99 | 99 | esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | $message->set_STS_ID(EEM_Message::status_idle); |
105 | 105 | |
106 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
106 | + if ( ! $this->_sending_messenger instanceof EE_messenger) { |
|
107 | 107 | $message->set_STS_ID(EEM_Message::status_failed); |
108 | 108 | $message->set_error_message( |
109 | 109 | sprintf( |
@@ -11,111 +11,111 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Message_Generated_From_Token extends EE_Message_To_Generate implements EEI_Has_Sending_Messenger |
13 | 13 | { |
14 | - /** |
|
15 | - * Sending messenger |
|
16 | - * |
|
17 | - * @type EE_messenger | string |
|
18 | - */ |
|
19 | - protected $_sending_messenger = ''; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds the incoming token; |
|
24 | - * @type string |
|
25 | - */ |
|
26 | - public $token = ''; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Constructor |
|
31 | - * |
|
32 | - * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
33 | - * the EE_Message retrieved from the DB via the given token. |
|
34 | - * @param string $token This is a token for a Message that should already exist int the db. |
|
35 | - * This is then used to populate the properties in here. |
|
36 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
37 | - */ |
|
38 | - public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager) |
|
39 | - { |
|
40 | - $this->token = $token; |
|
41 | - $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
42 | - $this->_message = $this->_generate_message(); |
|
43 | - // set params for parent from the message object |
|
44 | - parent::__construct( |
|
45 | - $this->_message->messenger(), |
|
46 | - $this->_message->message_type(), |
|
47 | - array(), |
|
48 | - $this->_message->context(), |
|
49 | - false |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $sending_messenger_slug |
|
57 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
58 | - * @return \EE_messenger | string |
|
59 | - */ |
|
60 | - protected function _set_sending_messenger( |
|
61 | - $sending_messenger_slug, |
|
62 | - EE_Message_Resource_Manager $message_resource_manager |
|
63 | - ) { |
|
64 | - $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
65 | - return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return EE_messenger |
|
72 | - */ |
|
73 | - public function sending_messenger() |
|
74 | - { |
|
75 | - return $this->_sending_messenger; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * generates an EE_Message using the supplied arguments and some defaults |
|
82 | - * |
|
83 | - * @param array $properties |
|
84 | - * @return EE_Message |
|
85 | - * @throws \EE_Error |
|
86 | - */ |
|
87 | - protected function _generate_message($properties = array()) |
|
88 | - { |
|
89 | - // a message was generated immediately but the parent class will call this again |
|
90 | - if ($this->_message instanceof EE_Message) { |
|
91 | - return $this->_message; |
|
92 | - } |
|
93 | - $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
94 | - if (! $message instanceof EE_Message) { |
|
95 | - throw new EE_Error( |
|
96 | - sprintf( |
|
97 | - esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
98 | - $this->token |
|
99 | - ) |
|
100 | - ); |
|
101 | - } |
|
102 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
103 | - |
|
104 | - if (! $this->_sending_messenger instanceof EE_messenger) { |
|
105 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
106 | - $message->set_error_message( |
|
107 | - sprintf( |
|
108 | - esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
109 | - $this->_sending_messenger |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
113 | - |
|
114 | - // set properties |
|
115 | - $this->_valid = true; |
|
116 | - $this->_messenger = $message->messenger_object(); |
|
117 | - $this->_message_type = $message->message_type_object(); |
|
118 | - $this->_send_now = $message->send_now(); |
|
119 | - return $message; |
|
120 | - } |
|
14 | + /** |
|
15 | + * Sending messenger |
|
16 | + * |
|
17 | + * @type EE_messenger | string |
|
18 | + */ |
|
19 | + protected $_sending_messenger = ''; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds the incoming token; |
|
24 | + * @type string |
|
25 | + */ |
|
26 | + public $token = ''; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Constructor |
|
31 | + * |
|
32 | + * @param string $sending_messenger_slug This is used to set what messenger is used to "send" |
|
33 | + * the EE_Message retrieved from the DB via the given token. |
|
34 | + * @param string $token This is a token for a Message that should already exist int the db. |
|
35 | + * This is then used to populate the properties in here. |
|
36 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
37 | + */ |
|
38 | + public function __construct($token, $sending_messenger_slug, EE_Message_Resource_Manager $message_resource_manager) |
|
39 | + { |
|
40 | + $this->token = $token; |
|
41 | + $this->_sending_messenger = $this->_set_sending_messenger($sending_messenger_slug, $message_resource_manager); |
|
42 | + $this->_message = $this->_generate_message(); |
|
43 | + // set params for parent from the message object |
|
44 | + parent::__construct( |
|
45 | + $this->_message->messenger(), |
|
46 | + $this->_message->message_type(), |
|
47 | + array(), |
|
48 | + $this->_message->context(), |
|
49 | + false |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $sending_messenger_slug |
|
57 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
58 | + * @return \EE_messenger | string |
|
59 | + */ |
|
60 | + protected function _set_sending_messenger( |
|
61 | + $sending_messenger_slug, |
|
62 | + EE_Message_Resource_Manager $message_resource_manager |
|
63 | + ) { |
|
64 | + $sending_messenger = $message_resource_manager->get_active_messenger($sending_messenger_slug); |
|
65 | + return $sending_messenger instanceof EE_messenger ? $sending_messenger : $sending_messenger_slug; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return EE_messenger |
|
72 | + */ |
|
73 | + public function sending_messenger() |
|
74 | + { |
|
75 | + return $this->_sending_messenger; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * generates an EE_Message using the supplied arguments and some defaults |
|
82 | + * |
|
83 | + * @param array $properties |
|
84 | + * @return EE_Message |
|
85 | + * @throws \EE_Error |
|
86 | + */ |
|
87 | + protected function _generate_message($properties = array()) |
|
88 | + { |
|
89 | + // a message was generated immediately but the parent class will call this again |
|
90 | + if ($this->_message instanceof EE_Message) { |
|
91 | + return $this->_message; |
|
92 | + } |
|
93 | + $message = EEM_Message::instance()->get_one_by_token($this->token); |
|
94 | + if (! $message instanceof EE_Message) { |
|
95 | + throw new EE_Error( |
|
96 | + sprintf( |
|
97 | + esc_html__('Unable to retrieve generated message from DB using given token: "%1$s"', 'event_espresso'), |
|
98 | + $this->token |
|
99 | + ) |
|
100 | + ); |
|
101 | + } |
|
102 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
103 | + |
|
104 | + if (! $this->_sending_messenger instanceof EE_messenger) { |
|
105 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
106 | + $message->set_error_message( |
|
107 | + sprintf( |
|
108 | + esc_html__('Unable to send message because the "%1$s" messenger is not active or not installed', 'event_espresso'), |
|
109 | + $this->_sending_messenger |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | + |
|
114 | + // set properties |
|
115 | + $this->_valid = true; |
|
116 | + $this->_messenger = $message->messenger_object(); |
|
117 | + $this->_message_type = $message->message_type_object(); |
|
118 | + $this->_send_now = $message->send_now(); |
|
119 | + return $message; |
|
120 | + } |
|
121 | 121 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
37 | 37 | { |
38 | 38 | // this is just a test |
39 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
39 | + return $this->name.' Message Type for '.$messenger->name.' Messenger '; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
56 | 56 | $regs = $data_type; |
57 | 57 | } else { |
58 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
58 | + $regs = is_array($data_type[0]) ? $data_type[0] : array($maybe_reg); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | foreach ($regs as $reg) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $this->_regs_for_sending[] = $reg->ID(); |
64 | 64 | } |
65 | 65 | } |
66 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
66 | + $this->_data = isset($this->_data[1]) ? array($maybe_reg->transaction(), null, $this->_data[1]) : array($maybe_reg->transaction()); |
|
67 | 67 | $this->_data_handler = 'Gateways'; |
68 | 68 | } else { |
69 | 69 | $this->_data_handler = 'Gateways'; |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | |
83 | 83 | protected function _get_data_for_context($context, EE_Registration $registration, $id) |
84 | 84 | { |
85 | - if ($context == 'admin') { |
|
85 | + if ($context == 'admin') { |
|
86 | 86 | // use the registration to get the transaction. |
87 | 87 | $transaction = $registration->transaction(); |
88 | 88 | |
89 | 89 | // bail early if no transaction |
90 | - if (! $transaction instanceof EE_Transaction) { |
|
90 | + if ( ! $transaction instanceof EE_Transaction) { |
|
91 | 91 | throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
92 | 92 | } |
93 | 93 | |
94 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
95 | - return array( $transaction, $payment ); |
|
94 | + $payment = ! empty($id) ? EEM_Payment::instance()->get_one(array(array('PAY_ID' => $id, 'TXN_ID' => $transaction->ID()))) : 0; |
|
95 | + return array($transaction, $payment); |
|
96 | 96 | } else { |
97 | 97 | return $registration; |
98 | 98 | } |
@@ -12,126 +12,126 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class EE_Registration_Base_message_type extends EE_message_type |
14 | 14 | { |
15 | - /** |
|
16 | - * @see parent::get_priority() for documentation. |
|
17 | - * @return int |
|
18 | - */ |
|
19 | - public function get_priority() |
|
20 | - { |
|
21 | - return EEM_Message::priority_medium; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - protected function _set_admin_pages() |
|
27 | - { |
|
28 | - $this->admin_registered_pages = array( |
|
29 | - 'events_edit' => true |
|
30 | - ); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
35 | - { |
|
36 | - // this is just a test |
|
37 | - return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - protected function _set_data_handler() |
|
44 | - { |
|
45 | - if (is_array($this->_data)) { |
|
46 | - $data_type = reset($this->_data); |
|
47 | - |
|
48 | - if (is_array($data_type)) { |
|
49 | - // grab the first item and see if its a registration. |
|
50 | - $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
51 | - if ($maybe_reg instanceof EE_Registration) { |
|
52 | - // is $data_type itself just an array of registrations? |
|
53 | - if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
54 | - $regs = $data_type; |
|
55 | - } else { |
|
56 | - $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
57 | - } |
|
58 | - |
|
59 | - foreach ($regs as $reg) { |
|
60 | - if ($reg instanceof EE_Registration) { |
|
61 | - $this->_regs_for_sending[] = $reg->ID(); |
|
62 | - } |
|
63 | - } |
|
64 | - $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
65 | - $this->_data_handler = 'Gateways'; |
|
66 | - } else { |
|
67 | - $this->_data_handler = 'Gateways'; |
|
68 | - } |
|
69 | - } else { |
|
70 | - $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
71 | - } |
|
72 | - } else { |
|
73 | - $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
74 | - } |
|
75 | - |
|
76 | - $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
82 | - { |
|
83 | - if ($context == 'admin') { |
|
84 | - // use the registration to get the transaction. |
|
85 | - $transaction = $registration->transaction(); |
|
86 | - |
|
87 | - // bail early if no transaction |
|
88 | - if (! $transaction instanceof EE_Transaction) { |
|
89 | - throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
90 | - } |
|
91 | - |
|
92 | - $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
93 | - return array( $transaction, $payment ); |
|
94 | - } else { |
|
95 | - return $registration; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Setup admin settings for this message type. |
|
103 | - */ |
|
104 | - protected function _set_admin_settings_fields() |
|
105 | - { |
|
106 | - $this->_admin_settings_fields = array(); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * returns an array of addressee objects for event_admins |
|
115 | - * |
|
116 | - * @access protected |
|
117 | - * @return array array of EE_Messages_Addressee objects |
|
118 | - */ |
|
119 | - protected function _admin_addressees() |
|
120 | - { |
|
121 | - if ($this->_single_message) { |
|
122 | - return array(); |
|
123 | - } |
|
124 | - return parent::_admin_addressees(); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - protected function _primary_attendee_addressees() |
|
130 | - { |
|
131 | - if ($this->_single_message) { |
|
132 | - return array(); |
|
133 | - } |
|
134 | - |
|
135 | - return parent::_primary_attendee_addressees(); |
|
136 | - } |
|
15 | + /** |
|
16 | + * @see parent::get_priority() for documentation. |
|
17 | + * @return int |
|
18 | + */ |
|
19 | + public function get_priority() |
|
20 | + { |
|
21 | + return EEM_Message::priority_medium; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + protected function _set_admin_pages() |
|
27 | + { |
|
28 | + $this->admin_registered_pages = array( |
|
29 | + 'events_edit' => true |
|
30 | + ); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + protected function _get_admin_content_events_edit_for_messenger(EE_messenger $messenger) |
|
35 | + { |
|
36 | + // this is just a test |
|
37 | + return $this->name . ' Message Type for ' . $messenger->name . ' Messenger '; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + protected function _set_data_handler() |
|
44 | + { |
|
45 | + if (is_array($this->_data)) { |
|
46 | + $data_type = reset($this->_data); |
|
47 | + |
|
48 | + if (is_array($data_type)) { |
|
49 | + // grab the first item and see if its a registration. |
|
50 | + $maybe_reg = isset($data_type[0]) && is_array($data_type[0]) ? reset($data_type[0]) : reset($data_type); |
|
51 | + if ($maybe_reg instanceof EE_Registration) { |
|
52 | + // is $data_type itself just an array of registrations? |
|
53 | + if (isset($data_type[1]) && $data_type[1] instanceof EE_Registration) { |
|
54 | + $regs = $data_type; |
|
55 | + } else { |
|
56 | + $regs = is_array($data_type[0]) ? $data_type[0] : array( $maybe_reg ); |
|
57 | + } |
|
58 | + |
|
59 | + foreach ($regs as $reg) { |
|
60 | + if ($reg instanceof EE_Registration) { |
|
61 | + $this->_regs_for_sending[] = $reg->ID(); |
|
62 | + } |
|
63 | + } |
|
64 | + $this->_data = isset($this->_data[1]) ? array( $maybe_reg->transaction(), null, $this->_data[1] ) : array( $maybe_reg->transaction() ); |
|
65 | + $this->_data_handler = 'Gateways'; |
|
66 | + } else { |
|
67 | + $this->_data_handler = 'Gateways'; |
|
68 | + } |
|
69 | + } else { |
|
70 | + $this->_data_handler = $data_type instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
71 | + } |
|
72 | + } else { |
|
73 | + $this->_data_handler = $this->_data instanceof EE_Registration ? 'REG' : 'Gateways'; |
|
74 | + } |
|
75 | + |
|
76 | + $this->_single_message = $this->_data_handler == 'REG' ? true : false; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + protected function _get_data_for_context($context, EE_Registration $registration, $id) |
|
82 | + { |
|
83 | + if ($context == 'admin') { |
|
84 | + // use the registration to get the transaction. |
|
85 | + $transaction = $registration->transaction(); |
|
86 | + |
|
87 | + // bail early if no transaction |
|
88 | + if (! $transaction instanceof EE_Transaction) { |
|
89 | + throw new EE_Error(esc_html__('The given registration does not have an associated transaction. Something is wrong.', 'event_espresso')); |
|
90 | + } |
|
91 | + |
|
92 | + $payment = !empty($id) ? EEM_Payment::instance()->get_one(array( array( 'PAY_ID' => $id, 'TXN_ID' => $transaction->ID() ) )) : 0; |
|
93 | + return array( $transaction, $payment ); |
|
94 | + } else { |
|
95 | + return $registration; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Setup admin settings for this message type. |
|
103 | + */ |
|
104 | + protected function _set_admin_settings_fields() |
|
105 | + { |
|
106 | + $this->_admin_settings_fields = array(); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * returns an array of addressee objects for event_admins |
|
115 | + * |
|
116 | + * @access protected |
|
117 | + * @return array array of EE_Messages_Addressee objects |
|
118 | + */ |
|
119 | + protected function _admin_addressees() |
|
120 | + { |
|
121 | + if ($this->_single_message) { |
|
122 | + return array(); |
|
123 | + } |
|
124 | + return parent::_admin_addressees(); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + protected function _primary_attendee_addressees() |
|
130 | + { |
|
131 | + if ($this->_single_message) { |
|
132 | + return array(); |
|
133 | + } |
|
134 | + |
|
135 | + return parent::_primary_attendee_addressees(); |
|
136 | + } |
|
137 | 137 | } |
@@ -207,7 +207,7 @@ |
||
207 | 207 | { |
208 | 208 | foreach ($this->_qtipsa as $qt) { |
209 | 209 | // make sure we have what we need. |
210 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
210 | + if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
211 | 211 | throw new EE_Error( |
212 | 212 | sprintf( |
213 | 213 | esc_html__( |
@@ -14,235 +14,235 @@ discard block |
||
14 | 14 | */ |
15 | 15 | abstract class EE_Qtip_Config extends EE_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * This will hold the qtips setup array (setup by children) |
|
19 | - * |
|
20 | - * @access protected |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_qtipsa; |
|
17 | + /** |
|
18 | + * This will hold the qtips setup array (setup by children) |
|
19 | + * |
|
20 | + * @access protected |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_qtipsa; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * This holds the constructed EE_Qtip objects |
|
28 | - * |
|
29 | - * @access protected |
|
30 | - * @var EE_Qtip |
|
31 | - */ |
|
32 | - protected $_qtips; |
|
26 | + /** |
|
27 | + * This holds the constructed EE_Qtip objects |
|
28 | + * |
|
29 | + * @access protected |
|
30 | + * @var EE_Qtip |
|
31 | + */ |
|
32 | + protected $_qtips; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * an array of default options for instantiated qtip js objects |
|
37 | - * |
|
38 | - * @access protected |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $_default_options; |
|
35 | + /** |
|
36 | + * an array of default options for instantiated qtip js objects |
|
37 | + * |
|
38 | + * @access protected |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $_default_options; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * constructor |
|
46 | - * |
|
47 | - * @access public |
|
48 | - */ |
|
49 | - public function __construct() |
|
50 | - { |
|
51 | - $this->_qtipsa = $this->_qtips = array(); |
|
52 | - $this->_set_default_options(); |
|
53 | - $this->_set_tips_array(); |
|
54 | - $this->_construct_tips(); |
|
55 | - } |
|
44 | + /** |
|
45 | + * constructor |
|
46 | + * |
|
47 | + * @access public |
|
48 | + */ |
|
49 | + public function __construct() |
|
50 | + { |
|
51 | + $this->_qtipsa = $this->_qtips = array(); |
|
52 | + $this->_set_default_options(); |
|
53 | + $this->_set_tips_array(); |
|
54 | + $this->_construct_tips(); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
60 | - * |
|
61 | - * $qtipsa = array( |
|
62 | - * 0 => array( |
|
63 | - * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
64 | - * 'content' => 'html/text content for the qtip', |
|
65 | - * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
66 | - * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
67 | - * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
68 | - * ) |
|
69 | - * ); |
|
70 | - * |
|
71 | - * @abstract |
|
72 | - * @access protected |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - abstract protected function _set_tips_array(); |
|
58 | + /** |
|
59 | + * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
60 | + * |
|
61 | + * $qtipsa = array( |
|
62 | + * 0 => array( |
|
63 | + * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
64 | + * 'content' => 'html/text content for the qtip', |
|
65 | + * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
66 | + * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
67 | + * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
68 | + * ) |
|
69 | + * ); |
|
70 | + * |
|
71 | + * @abstract |
|
72 | + * @access protected |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + abstract protected function _set_tips_array(); |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
80 | - * qtips defined in their config OR just leave it and have the parent default options apply. |
|
81 | - * |
|
82 | - * commented out options are there for reference so you know which can be defined by the child. |
|
83 | - * |
|
84 | - * Note: children do NOT have to define all these options. Just define the ones to override. |
|
85 | - * |
|
86 | - * @link http://qtip2.com/options |
|
87 | - * |
|
88 | - * @access protected |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - protected function _set_default_options() |
|
92 | - { |
|
93 | - $this->_default_options = array( |
|
94 | - // 'id' => 'unique_id_referncing_qtip_instance', |
|
95 | - 'prerender' => false, |
|
96 | - // increases page load if true, |
|
97 | - 'suppress' => true, |
|
98 | - // whether default browser tooltips are suppressed. |
|
99 | - 'content' => array( |
|
100 | - 'button' => false, |
|
101 | - // what you want for the close button text/link. |
|
102 | - 'title' => true, |
|
103 | - // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
104 | - 'clone' => true, |
|
105 | - // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
106 | - ), |
|
107 | - 'show_only_once' => false, |
|
108 | - // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
109 | - 'position' => array( |
|
110 | - 'my' => 'top left', |
|
111 | - // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
112 | - 'at' => 'bottom right', |
|
113 | - // same options as above. |
|
114 | - 'target' => 'event', |
|
115 | - // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
116 | - 'container' => false, |
|
117 | - // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
118 | - 'viewport' => true, |
|
119 | - // @link http://qtip2.com/plugins#viewport |
|
120 | - 'adjust' => array( |
|
121 | - 'x' => 0, |
|
122 | - // adjust position on x axis by 0 pixels. |
|
123 | - 'y' => 0, |
|
124 | - // adjust position on y axis by 0 pixels. |
|
125 | - 'mouse' => true, |
|
126 | - // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
127 | - 'resize' => true, |
|
128 | - // adjust tooltip position when window is resized. |
|
129 | - 'scroll' => true, |
|
130 | - // position of tooltip adjusted when window (or position.container) is scrolled. |
|
131 | - 'method' => 'flipinvert', |
|
132 | - // @link http://qtip2.com/plugins#viewport |
|
133 | - ), |
|
134 | - ), |
|
135 | - 'show' => array( |
|
136 | - 'event' => 'mouseenter', |
|
137 | - // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
138 | - 'target' => false, |
|
139 | - // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
140 | - 'delay' => 90, |
|
141 | - // time in millisecons by which to delay showing of tooltip. |
|
142 | - 'solo' => false, |
|
143 | - // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
144 | - 'modal' => array( |
|
145 | - 'on' => false, // does tooltip trigger modal? |
|
146 | - 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
147 | - 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
148 | - 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
149 | - ), |
|
150 | - ), |
|
151 | - 'hide' => array( |
|
152 | - 'event' => 'mouseleave', |
|
153 | - // similar as what you do for show.event. |
|
154 | - 'target' => false, |
|
155 | - // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
156 | - 'delay' => 0, |
|
157 | - // set time in milliseconds for delaying the hide of the tooltip |
|
158 | - 'inactive' => false, |
|
159 | - // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
160 | - 'fixed' => false, |
|
161 | - // when set to true, the tooltip will not hide if moused over. |
|
162 | - 'leave' => 'window', |
|
163 | - // specify whether the tooltip will hide when leaving the window it's conained within. |
|
164 | - 'distance' => false, |
|
165 | - // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
166 | - ), |
|
167 | - 'style' => array( |
|
168 | - 'classes' => 'qtip-tipsy', |
|
169 | - // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
170 | - 'def' => true, |
|
171 | - // set to false and the default qtip class does not get applied |
|
172 | - 'widget' => false, |
|
173 | - // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
174 | - 'width' => false, |
|
175 | - // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
176 | - 'height' => false, |
|
177 | - // same as above except applies to height. |
|
178 | - 'tip' => array( |
|
179 | - 'corner' => true, |
|
180 | - // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
181 | - 'mimic' => false, |
|
182 | - // see documentation @link http://qtip2.com/plugins#tips |
|
183 | - 'border' => true, |
|
184 | - // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
185 | - 'width' => 6, |
|
186 | - // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
187 | - 'height' => 6, |
|
188 | - // works the same as tip.width |
|
189 | - 'offset' => 0, |
|
190 | - // use to set the offset of the tip in relation to its corner position. |
|
191 | - ), |
|
192 | - ), |
|
78 | + /** |
|
79 | + * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
80 | + * qtips defined in their config OR just leave it and have the parent default options apply. |
|
81 | + * |
|
82 | + * commented out options are there for reference so you know which can be defined by the child. |
|
83 | + * |
|
84 | + * Note: children do NOT have to define all these options. Just define the ones to override. |
|
85 | + * |
|
86 | + * @link http://qtip2.com/options |
|
87 | + * |
|
88 | + * @access protected |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + protected function _set_default_options() |
|
92 | + { |
|
93 | + $this->_default_options = array( |
|
94 | + // 'id' => 'unique_id_referncing_qtip_instance', |
|
95 | + 'prerender' => false, |
|
96 | + // increases page load if true, |
|
97 | + 'suppress' => true, |
|
98 | + // whether default browser tooltips are suppressed. |
|
99 | + 'content' => array( |
|
100 | + 'button' => false, |
|
101 | + // what you want for the close button text/link. |
|
102 | + 'title' => true, |
|
103 | + // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
104 | + 'clone' => true, |
|
105 | + // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
106 | + ), |
|
107 | + 'show_only_once' => false, |
|
108 | + // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
109 | + 'position' => array( |
|
110 | + 'my' => 'top left', |
|
111 | + // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
112 | + 'at' => 'bottom right', |
|
113 | + // same options as above. |
|
114 | + 'target' => 'event', |
|
115 | + // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
116 | + 'container' => false, |
|
117 | + // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
118 | + 'viewport' => true, |
|
119 | + // @link http://qtip2.com/plugins#viewport |
|
120 | + 'adjust' => array( |
|
121 | + 'x' => 0, |
|
122 | + // adjust position on x axis by 0 pixels. |
|
123 | + 'y' => 0, |
|
124 | + // adjust position on y axis by 0 pixels. |
|
125 | + 'mouse' => true, |
|
126 | + // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
127 | + 'resize' => true, |
|
128 | + // adjust tooltip position when window is resized. |
|
129 | + 'scroll' => true, |
|
130 | + // position of tooltip adjusted when window (or position.container) is scrolled. |
|
131 | + 'method' => 'flipinvert', |
|
132 | + // @link http://qtip2.com/plugins#viewport |
|
133 | + ), |
|
134 | + ), |
|
135 | + 'show' => array( |
|
136 | + 'event' => 'mouseenter', |
|
137 | + // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
138 | + 'target' => false, |
|
139 | + // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
140 | + 'delay' => 90, |
|
141 | + // time in millisecons by which to delay showing of tooltip. |
|
142 | + 'solo' => false, |
|
143 | + // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
144 | + 'modal' => array( |
|
145 | + 'on' => false, // does tooltip trigger modal? |
|
146 | + 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
147 | + 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
148 | + 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
149 | + ), |
|
150 | + ), |
|
151 | + 'hide' => array( |
|
152 | + 'event' => 'mouseleave', |
|
153 | + // similar as what you do for show.event. |
|
154 | + 'target' => false, |
|
155 | + // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
156 | + 'delay' => 0, |
|
157 | + // set time in milliseconds for delaying the hide of the tooltip |
|
158 | + 'inactive' => false, |
|
159 | + // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
160 | + 'fixed' => false, |
|
161 | + // when set to true, the tooltip will not hide if moused over. |
|
162 | + 'leave' => 'window', |
|
163 | + // specify whether the tooltip will hide when leaving the window it's conained within. |
|
164 | + 'distance' => false, |
|
165 | + // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
166 | + ), |
|
167 | + 'style' => array( |
|
168 | + 'classes' => 'qtip-tipsy', |
|
169 | + // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
170 | + 'def' => true, |
|
171 | + // set to false and the default qtip class does not get applied |
|
172 | + 'widget' => false, |
|
173 | + // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
174 | + 'width' => false, |
|
175 | + // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
176 | + 'height' => false, |
|
177 | + // same as above except applies to height. |
|
178 | + 'tip' => array( |
|
179 | + 'corner' => true, |
|
180 | + // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
181 | + 'mimic' => false, |
|
182 | + // see documentation @link http://qtip2.com/plugins#tips |
|
183 | + 'border' => true, |
|
184 | + // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
185 | + 'width' => 6, |
|
186 | + // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
187 | + 'height' => 6, |
|
188 | + // works the same as tip.width |
|
189 | + 'offset' => 0, |
|
190 | + // use to set the offset of the tip in relation to its corner position. |
|
191 | + ), |
|
192 | + ), |
|
193 | 193 | |
194 | - ); |
|
195 | - } |
|
194 | + ); |
|
195 | + } |
|
196 | 196 | |
197 | 197 | |
198 | - /** |
|
199 | - * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
200 | - * the $_qtips property |
|
201 | - * |
|
202 | - * @access protected |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - protected function _construct_tips() |
|
206 | - { |
|
207 | - foreach ($this->_qtipsa as $qt) { |
|
208 | - // make sure we have what we need. |
|
209 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
210 | - throw new EE_Error( |
|
211 | - sprintf( |
|
212 | - esc_html__( |
|
213 | - 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - get_class($this), |
|
217 | - var_export($qt, true) |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
198 | + /** |
|
199 | + * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
200 | + * the $_qtips property |
|
201 | + * |
|
202 | + * @access protected |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + protected function _construct_tips() |
|
206 | + { |
|
207 | + foreach ($this->_qtipsa as $qt) { |
|
208 | + // make sure we have what we need. |
|
209 | + if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
210 | + throw new EE_Error( |
|
211 | + sprintf( |
|
212 | + esc_html__( |
|
213 | + 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + get_class($this), |
|
217 | + var_export($qt, true) |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | 221 | |
222 | - // make sure the options include defaults and just override via set config. |
|
223 | - $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
224 | - $options = array_merge($this->_default_options, $options_override); |
|
225 | - $setup = array( |
|
226 | - 'content_id' => $qt['content_id'], |
|
227 | - 'options' => $options, |
|
228 | - 'target' => $qt['target'], |
|
229 | - 'content' => $qt['content'], |
|
230 | - ); |
|
231 | - $this->_qtips[] = new EE_Qtip($setup); |
|
232 | - } |
|
233 | - } |
|
222 | + // make sure the options include defaults and just override via set config. |
|
223 | + $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
224 | + $options = array_merge($this->_default_options, $options_override); |
|
225 | + $setup = array( |
|
226 | + 'content_id' => $qt['content_id'], |
|
227 | + 'options' => $options, |
|
228 | + 'target' => $qt['target'], |
|
229 | + 'content' => $qt['content'], |
|
230 | + ); |
|
231 | + $this->_qtips[] = new EE_Qtip($setup); |
|
232 | + } |
|
233 | + } |
|
234 | 234 | |
235 | 235 | |
236 | - /** |
|
237 | - * return the _qtips property contents |
|
238 | - * |
|
239 | - * @access public |
|
240 | - * @return EE_Qtip[] |
|
241 | - */ |
|
242 | - public function get_tips() |
|
243 | - { |
|
244 | - return $this->_qtips; |
|
245 | - } |
|
236 | + /** |
|
237 | + * return the _qtips property contents |
|
238 | + * |
|
239 | + * @access public |
|
240 | + * @return EE_Qtip[] |
|
241 | + */ |
|
242 | + public function get_tips() |
|
243 | + { |
|
244 | + return $this->_qtips; |
|
245 | + } |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // class names you can use for tooltip styles |
@@ -294,17 +294,17 @@ discard block |
||
294 | 294 | */ |
295 | 295 | class EE_Qtip extends EE_Base |
296 | 296 | { |
297 | - public $content_id; |
|
298 | - public $options; |
|
299 | - public $target; |
|
300 | - public $content; |
|
297 | + public $content_id; |
|
298 | + public $options; |
|
299 | + public $target; |
|
300 | + public $content; |
|
301 | 301 | |
302 | - public function __construct($setup_array) |
|
303 | - { |
|
304 | - foreach ($setup_array as $prop => $value) { |
|
305 | - if (EEH_Class_Tools::has_property($this, $prop)) { |
|
306 | - $this->{$prop} = $value; |
|
307 | - } |
|
308 | - } |
|
309 | - } |
|
302 | + public function __construct($setup_array) |
|
303 | + { |
|
304 | + foreach ($setup_array as $prop => $value) { |
|
305 | + if (EEH_Class_Tools::has_property($this, $prop)) { |
|
306 | + $this->{$prop} = $value; |
|
307 | + } |
|
308 | + } |
|
309 | + } |
|
310 | 310 | } |
@@ -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 | esc_html__( |
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 { |
@@ -43,211 +43,211 @@ |
||
43 | 43 | */ |
44 | 44 | abstract class EEME_Base |
45 | 45 | { |
46 | - const extending_method_prefix = 'ext_'; |
|
47 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
48 | - |
|
49 | - protected $_extra_tables = array(); |
|
50 | - protected $_extra_fields = array(); |
|
51 | - protected $_extra_relations = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * The model name that is extended (not classname) |
|
55 | - * |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $_model_name_extended = null; |
|
59 | - |
|
60 | - /** |
|
61 | - * The model this extends |
|
62 | - * |
|
63 | - * @var EEM_Base |
|
64 | - */ |
|
65 | - protected $_ = null; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @throws \EE_Error |
|
70 | - */ |
|
71 | - public function __construct() |
|
72 | - { |
|
73 | - if (! $this->_model_name_extended) { |
|
74 | - throw new EE_Error( |
|
75 | - esc_html__( |
|
76 | - "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
77 | - "event_espresso" |
|
78 | - ) |
|
79 | - ); |
|
80 | - } |
|
81 | - $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
82 | - if (did_action($construct_end_action)) { |
|
83 | - throw new EE_Error( |
|
84 | - sprintf( |
|
85 | - esc_html__( |
|
86 | - "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
87 | - "event_espresso" |
|
88 | - ), |
|
89 | - get_class($this), |
|
90 | - $this->_model_name_extended, |
|
91 | - $construct_end_action |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - add_filter( |
|
96 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
97 | - array($this, 'add_extra_tables_on_filter') |
|
98 | - ); |
|
99 | - add_filter( |
|
100 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
101 | - array($this, 'add_extra_fields_on_filter') |
|
102 | - ); |
|
103 | - add_filter( |
|
104 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
105 | - array($this, 'add_extra_relations_on_filter') |
|
106 | - ); |
|
107 | - $this->_register_extending_methods(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param array $existing_tables |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public function add_extra_tables_on_filter($existing_tables) |
|
116 | - { |
|
117 | - return array_merge((array) $existing_tables, $this->_extra_tables); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param array $existing_fields |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function add_extra_fields_on_filter($existing_fields) |
|
126 | - { |
|
127 | - if ($this->_extra_fields) { |
|
128 | - foreach ($this->_extra_fields as $table_alias => $fields) { |
|
129 | - if (! isset($existing_fields[ $table_alias ])) { |
|
130 | - $existing_fields[ $table_alias ] = array(); |
|
131 | - } |
|
132 | - $existing_fields[ $table_alias ] = array_merge( |
|
133 | - (array) $existing_fields[ $table_alias ], |
|
134 | - $this->_extra_fields[ $table_alias ] |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - return $existing_fields; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param array $existing_relations |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - public function add_extra_relations_on_filter($existing_relations) |
|
147 | - { |
|
148 | - return array_merge((array) $existing_relations, $this->_extra_relations); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
154 | - * model extended. (Internally uses filters, and the __call magic method) |
|
155 | - */ |
|
156 | - protected function _register_extending_methods() |
|
157 | - { |
|
158 | - $all_methods = get_class_methods(get_class($this)); |
|
159 | - foreach ($all_methods as $method_name) { |
|
160 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
161 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
162 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
163 | - add_filter( |
|
164 | - $callback_name, |
|
165 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
166 | - 10, |
|
167 | - 10 |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
175 | - * model extended. (Internally uses filters, and the __call magic method) |
|
176 | - */ |
|
177 | - public function deregister() |
|
178 | - { |
|
179 | - remove_filter( |
|
180 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
181 | - array($this, 'add_extra_tables_on_filter') |
|
182 | - ); |
|
183 | - remove_filter( |
|
184 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
185 | - array($this, 'add_extra_fields_on_filter') |
|
186 | - ); |
|
187 | - remove_filter( |
|
188 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
189 | - array($this, 'add_extra_relations_on_filter') |
|
190 | - ); |
|
191 | - $all_methods = get_class_methods(get_class($this)); |
|
192 | - foreach ($all_methods as $method_name) { |
|
193 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
194 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
195 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
196 | - remove_filter( |
|
197 | - $callback_name, |
|
198 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
199 | - 10 |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - /** @var EEM_Base $model_to_reset */ |
|
204 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
205 | - if (class_exists($model_to_reset)) { |
|
206 | - $model_to_reset::reset(); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param string $callback_method_name |
|
213 | - * @param array $args |
|
214 | - * @return mixed |
|
215 | - * @throws EE_Error |
|
216 | - */ |
|
217 | - public function __call($callback_method_name, $args) |
|
218 | - { |
|
219 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
220 | - // it's a dynamic callback for a method name |
|
221 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
222 | - list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
223 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
224 | - $this->_ = $model_called; |
|
225 | - // phpcs:enable |
|
226 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
227 | - if (method_exists($this, $extending_method)) { |
|
228 | - return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
229 | - } else { |
|
230 | - throw new EE_Error( |
|
231 | - sprintf( |
|
232 | - esc_html__( |
|
233 | - "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!)", |
|
234 | - "event_espresso" |
|
235 | - ), |
|
236 | - $this->_model_name_extended, |
|
237 | - get_class($this), |
|
238 | - $extending_method, |
|
239 | - $extending_method |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - } else { |
|
244 | - throw new EE_Error( |
|
245 | - sprintf( |
|
246 | - esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
247 | - $callback_method_name, |
|
248 | - get_class($this) |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - } |
|
46 | + const extending_method_prefix = 'ext_'; |
|
47 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
48 | + |
|
49 | + protected $_extra_tables = array(); |
|
50 | + protected $_extra_fields = array(); |
|
51 | + protected $_extra_relations = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * The model name that is extended (not classname) |
|
55 | + * |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $_model_name_extended = null; |
|
59 | + |
|
60 | + /** |
|
61 | + * The model this extends |
|
62 | + * |
|
63 | + * @var EEM_Base |
|
64 | + */ |
|
65 | + protected $_ = null; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @throws \EE_Error |
|
70 | + */ |
|
71 | + public function __construct() |
|
72 | + { |
|
73 | + if (! $this->_model_name_extended) { |
|
74 | + throw new EE_Error( |
|
75 | + esc_html__( |
|
76 | + "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
77 | + "event_espresso" |
|
78 | + ) |
|
79 | + ); |
|
80 | + } |
|
81 | + $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
82 | + if (did_action($construct_end_action)) { |
|
83 | + throw new EE_Error( |
|
84 | + sprintf( |
|
85 | + esc_html__( |
|
86 | + "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
87 | + "event_espresso" |
|
88 | + ), |
|
89 | + get_class($this), |
|
90 | + $this->_model_name_extended, |
|
91 | + $construct_end_action |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + add_filter( |
|
96 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
97 | + array($this, 'add_extra_tables_on_filter') |
|
98 | + ); |
|
99 | + add_filter( |
|
100 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
101 | + array($this, 'add_extra_fields_on_filter') |
|
102 | + ); |
|
103 | + add_filter( |
|
104 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
105 | + array($this, 'add_extra_relations_on_filter') |
|
106 | + ); |
|
107 | + $this->_register_extending_methods(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param array $existing_tables |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public function add_extra_tables_on_filter($existing_tables) |
|
116 | + { |
|
117 | + return array_merge((array) $existing_tables, $this->_extra_tables); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param array $existing_fields |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function add_extra_fields_on_filter($existing_fields) |
|
126 | + { |
|
127 | + if ($this->_extra_fields) { |
|
128 | + foreach ($this->_extra_fields as $table_alias => $fields) { |
|
129 | + if (! isset($existing_fields[ $table_alias ])) { |
|
130 | + $existing_fields[ $table_alias ] = array(); |
|
131 | + } |
|
132 | + $existing_fields[ $table_alias ] = array_merge( |
|
133 | + (array) $existing_fields[ $table_alias ], |
|
134 | + $this->_extra_fields[ $table_alias ] |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + return $existing_fields; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param array $existing_relations |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + public function add_extra_relations_on_filter($existing_relations) |
|
147 | + { |
|
148 | + return array_merge((array) $existing_relations, $this->_extra_relations); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
154 | + * model extended. (Internally uses filters, and the __call magic method) |
|
155 | + */ |
|
156 | + protected function _register_extending_methods() |
|
157 | + { |
|
158 | + $all_methods = get_class_methods(get_class($this)); |
|
159 | + foreach ($all_methods as $method_name) { |
|
160 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
161 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
162 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
163 | + add_filter( |
|
164 | + $callback_name, |
|
165 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
166 | + 10, |
|
167 | + 10 |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
175 | + * model extended. (Internally uses filters, and the __call magic method) |
|
176 | + */ |
|
177 | + public function deregister() |
|
178 | + { |
|
179 | + remove_filter( |
|
180 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
181 | + array($this, 'add_extra_tables_on_filter') |
|
182 | + ); |
|
183 | + remove_filter( |
|
184 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
185 | + array($this, 'add_extra_fields_on_filter') |
|
186 | + ); |
|
187 | + remove_filter( |
|
188 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
189 | + array($this, 'add_extra_relations_on_filter') |
|
190 | + ); |
|
191 | + $all_methods = get_class_methods(get_class($this)); |
|
192 | + foreach ($all_methods as $method_name) { |
|
193 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
194 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
195 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
196 | + remove_filter( |
|
197 | + $callback_name, |
|
198 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
199 | + 10 |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + /** @var EEM_Base $model_to_reset */ |
|
204 | + $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
205 | + if (class_exists($model_to_reset)) { |
|
206 | + $model_to_reset::reset(); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param string $callback_method_name |
|
213 | + * @param array $args |
|
214 | + * @return mixed |
|
215 | + * @throws EE_Error |
|
216 | + */ |
|
217 | + public function __call($callback_method_name, $args) |
|
218 | + { |
|
219 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
220 | + // it's a dynamic callback for a method name |
|
221 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
222 | + list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
223 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
224 | + $this->_ = $model_called; |
|
225 | + // phpcs:enable |
|
226 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
227 | + if (method_exists($this, $extending_method)) { |
|
228 | + return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
229 | + } else { |
|
230 | + throw new EE_Error( |
|
231 | + sprintf( |
|
232 | + esc_html__( |
|
233 | + "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!)", |
|
234 | + "event_espresso" |
|
235 | + ), |
|
236 | + $this->_model_name_extended, |
|
237 | + get_class($this), |
|
238 | + $extending_method, |
|
239 | + $extending_method |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + } else { |
|
244 | + throw new EE_Error( |
|
245 | + sprintf( |
|
246 | + esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
247 | + $callback_method_name, |
|
248 | + get_class($this) |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | } |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | '[TKT_USES_*]' => esc_html__( |
48 | 48 | 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
49 | 49 | 'event_espresso' |
50 | - ) . |
|
51 | - '<p><ul>' . |
|
52 | - '<li><strong>symbol</strong>:' . esc_html__( |
|
50 | + ). |
|
51 | + '<p><ul>'. |
|
52 | + '<li><strong>symbol</strong>:'.esc_html__( |
|
53 | 53 | 'This returns the ∞ symbol.', |
54 | 54 | 'event_espresso' |
55 | - ) . '</li>' . |
|
56 | - '<li><strong>text</strong>:' . esc_html__( |
|
55 | + ).'</li>'. |
|
56 | + '<li><strong>text</strong>:'.esc_html__( |
|
57 | 57 | 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
58 | 58 | 'event_espresso' |
59 | - ) . '</li>' . |
|
60 | - '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | + ).'</li>'. |
|
60 | + '<li><strong>{custom}</strong>:'.esc_html__( |
|
61 | 61 | 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
62 | 62 | 'event_espresso' |
63 | - ) . '</li>' . |
|
63 | + ).'</li>'. |
|
64 | 64 | '</ul></p>', |
65 | 65 | ); |
66 | 66 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | $this->_ticket = empty($this->_ticket) |
83 | 83 | && $this->_data instanceof EE_Line_Item |
84 | 84 | && $aee instanceof EE_Messages_Addressee |
85 | - && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
86 | - && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
87 | - ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
85 | + && ! empty($aee->line_items_with_children[$this->_data->ID()]['EE_Ticket']) |
|
86 | + && $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] instanceof EE_Ticket |
|
87 | + ? $aee->line_items_with_children[$this->_data->ID()]['EE_Ticket'] |
|
88 | 88 | : $this->_ticket; |
89 | 89 | |
90 | 90 | // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | |
97 | 97 | // If there is no event object by now then get out. |
98 | - if (! $this->_ticket instanceof EE_Ticket) { |
|
98 | + if ( ! $this->_ticket instanceof EE_Ticket) { |
|
99 | 99 | return ''; |
100 | 100 | } |
101 | 101 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | break; |
122 | 122 | |
123 | 123 | case '[TKT_QTY_PURCHASED]': |
124 | - return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
124 | + return $aee instanceof EE_Messages_Addressee ? $aee->tickets[$this->_ticket->ID()]['count'] : ''; |
|
125 | 125 | break; |
126 | 126 | } |
127 | 127 |
@@ -17,123 +17,123 @@ |
||
17 | 17 | */ |
18 | 18 | class EE_Ticket_Shortcodes extends EE_Shortcodes |
19 | 19 | { |
20 | - /** |
|
21 | - * Will hold the EE_Ticket if available |
|
22 | - * |
|
23 | - * @var EE_Ticket |
|
24 | - */ |
|
25 | - protected $_ticket; |
|
26 | - |
|
27 | - |
|
28 | - protected function _init_props() |
|
29 | - { |
|
30 | - $this->label = esc_html__('Ticket Shortcodes', 'event_espresso'); |
|
31 | - $this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso'); |
|
32 | - $this->_shortcodes = array( |
|
33 | - '[TICKET_ID]' => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'), |
|
34 | - '[TICKET_NAME]' => esc_html__('The name of the ticket', 'event_espresso'), |
|
35 | - '[TICKET_DESCRIPTION]' => esc_html__('The description of the ticket', 'event_espresso'), |
|
36 | - '[TICKET_PRICE]' => esc_html__('The price of the ticket', 'event_espresso'), |
|
37 | - '[TICKET_PRICE_WITH_TAXES]' => esc_html__( |
|
38 | - 'The price of the ticket including any taxes that might be on the ticket', |
|
39 | - 'event_espresso' |
|
40 | - ), |
|
41 | - '[TKT_QTY_PURCHASED]' => esc_html__( |
|
42 | - 'The total quantity of the current ticket in the list that has been purchased in this transaction', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - '[TKT_USES_*]' => esc_html__( |
|
46 | - 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
|
47 | - 'event_espresso' |
|
48 | - ) . |
|
49 | - '<p><ul>' . |
|
50 | - '<li><strong>symbol</strong>:' . esc_html__( |
|
51 | - 'This returns the ∞ symbol.', |
|
52 | - 'event_espresso' |
|
53 | - ) . '</li>' . |
|
54 | - '<li><strong>text</strong>:' . esc_html__( |
|
55 | - 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
|
56 | - 'event_espresso' |
|
57 | - ) . '</li>' . |
|
58 | - '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | - 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
|
60 | - 'event_espresso' |
|
61 | - ) . '</li>' . |
|
62 | - '</ul></p>', |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - protected function _parser($shortcode) |
|
68 | - { |
|
69 | - |
|
70 | - $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null; |
|
71 | - |
|
72 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
73 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
74 | - $this->_extra_data |
|
75 | - ) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
76 | - ? $this->_extra_data['data'] : $aee; |
|
77 | - |
|
78 | - |
|
79 | - // possible EE_Line_Item may be incoming data |
|
80 | - $this->_ticket = empty($this->_ticket) |
|
81 | - && $this->_data instanceof EE_Line_Item |
|
82 | - && $aee instanceof EE_Messages_Addressee |
|
83 | - && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
84 | - && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
85 | - ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
86 | - : $this->_ticket; |
|
87 | - |
|
88 | - // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
|
89 | - if (empty($this->_ticket)) { |
|
90 | - $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
91 | - ? $aee->reg_obj->ticket() : null; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - // If there is no event object by now then get out. |
|
96 | - if (! $this->_ticket instanceof EE_Ticket) { |
|
97 | - return ''; |
|
98 | - } |
|
99 | - |
|
100 | - switch ($shortcode) { |
|
101 | - case '[TICKET_ID]': |
|
102 | - return $this->_ticket->ID(); |
|
103 | - break; |
|
104 | - |
|
105 | - case '[TICKET_NAME]': |
|
106 | - return $this->_ticket->get('TKT_name'); |
|
107 | - break; |
|
108 | - |
|
109 | - case '[TICKET_DESCRIPTION]': |
|
110 | - return $this->_ticket->get('TKT_description'); |
|
111 | - break; |
|
112 | - |
|
113 | - case '[TICKET_PRICE]': |
|
114 | - return EEH_Template::format_currency($this->_ticket->get('TKT_price')); |
|
115 | - break; |
|
116 | - |
|
117 | - case '[TICKET_PRICE_WITH_TAXES]': |
|
118 | - return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes()); |
|
119 | - break; |
|
120 | - |
|
121 | - case '[TKT_QTY_PURCHASED]': |
|
122 | - return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
123 | - break; |
|
124 | - } |
|
125 | - |
|
126 | - if (strpos($shortcode, '[TKT_USES_*') !== false) { |
|
127 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
128 | - $schema = empty($attrs['schema']) ? null : $attrs['schema']; |
|
129 | - return $this->_ticket->get_pretty('TKT_uses', $schema); |
|
130 | - } |
|
131 | - return ''; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - public function get_ticket_set() |
|
136 | - { |
|
137 | - return $this->_ticket; |
|
138 | - } |
|
20 | + /** |
|
21 | + * Will hold the EE_Ticket if available |
|
22 | + * |
|
23 | + * @var EE_Ticket |
|
24 | + */ |
|
25 | + protected $_ticket; |
|
26 | + |
|
27 | + |
|
28 | + protected function _init_props() |
|
29 | + { |
|
30 | + $this->label = esc_html__('Ticket Shortcodes', 'event_espresso'); |
|
31 | + $this->description = esc_html__('All shortcodes specific to ticket related data', 'event_espresso'); |
|
32 | + $this->_shortcodes = array( |
|
33 | + '[TICKET_ID]' => esc_html__('Will be replaced by the ticket ID of a ticket', 'event_espresso'), |
|
34 | + '[TICKET_NAME]' => esc_html__('The name of the ticket', 'event_espresso'), |
|
35 | + '[TICKET_DESCRIPTION]' => esc_html__('The description of the ticket', 'event_espresso'), |
|
36 | + '[TICKET_PRICE]' => esc_html__('The price of the ticket', 'event_espresso'), |
|
37 | + '[TICKET_PRICE_WITH_TAXES]' => esc_html__( |
|
38 | + 'The price of the ticket including any taxes that might be on the ticket', |
|
39 | + 'event_espresso' |
|
40 | + ), |
|
41 | + '[TKT_QTY_PURCHASED]' => esc_html__( |
|
42 | + 'The total quantity of the current ticket in the list that has been purchased in this transaction', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + '[TKT_USES_*]' => esc_html__( |
|
46 | + 'This attribute based shortcode parses to show the number of uses the ticket has. The optional "schema" attribute can be used to indicate what schema is used when the uses is infinite. Options are:', |
|
47 | + 'event_espresso' |
|
48 | + ) . |
|
49 | + '<p><ul>' . |
|
50 | + '<li><strong>symbol</strong>:' . esc_html__( |
|
51 | + 'This returns the ∞ symbol.', |
|
52 | + 'event_espresso' |
|
53 | + ) . '</li>' . |
|
54 | + '<li><strong>text</strong>:' . esc_html__( |
|
55 | + 'This returns the word, "Unlimited". This is also the default if the "schema" attribute is not used.', |
|
56 | + 'event_espresso' |
|
57 | + ) . '</li>' . |
|
58 | + '<li><strong>{custom}</strong>:' . esc_html__( |
|
59 | + 'You can put anything you want as a string instead and that will be used. So you could have the world "any" and whenever uses for a ticket is infinity, this shortcode will parse to "any".', |
|
60 | + 'event_espresso' |
|
61 | + ) . '</li>' . |
|
62 | + '</ul></p>', |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + protected function _parser($shortcode) |
|
68 | + { |
|
69 | + |
|
70 | + $this->_ticket = $this->_data instanceof EE_Ticket ? $this->_data : null; |
|
71 | + |
|
72 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
73 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
74 | + $this->_extra_data |
|
75 | + ) && isset($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
76 | + ? $this->_extra_data['data'] : $aee; |
|
77 | + |
|
78 | + |
|
79 | + // possible EE_Line_Item may be incoming data |
|
80 | + $this->_ticket = empty($this->_ticket) |
|
81 | + && $this->_data instanceof EE_Line_Item |
|
82 | + && $aee instanceof EE_Messages_Addressee |
|
83 | + && ! empty($aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket']) |
|
84 | + && $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] instanceof EE_Ticket |
|
85 | + ? $aee->line_items_with_children[ $this->_data->ID() ]['EE_Ticket'] |
|
86 | + : $this->_ticket; |
|
87 | + |
|
88 | + // if still no ticket, then let's see if there is a reg_obj. If there IS, then we'll try and grab the ticket from the reg_obj instead. |
|
89 | + if (empty($this->_ticket)) { |
|
90 | + $this->_ticket = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
91 | + ? $aee->reg_obj->ticket() : null; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + // If there is no event object by now then get out. |
|
96 | + if (! $this->_ticket instanceof EE_Ticket) { |
|
97 | + return ''; |
|
98 | + } |
|
99 | + |
|
100 | + switch ($shortcode) { |
|
101 | + case '[TICKET_ID]': |
|
102 | + return $this->_ticket->ID(); |
|
103 | + break; |
|
104 | + |
|
105 | + case '[TICKET_NAME]': |
|
106 | + return $this->_ticket->get('TKT_name'); |
|
107 | + break; |
|
108 | + |
|
109 | + case '[TICKET_DESCRIPTION]': |
|
110 | + return $this->_ticket->get('TKT_description'); |
|
111 | + break; |
|
112 | + |
|
113 | + case '[TICKET_PRICE]': |
|
114 | + return EEH_Template::format_currency($this->_ticket->get('TKT_price')); |
|
115 | + break; |
|
116 | + |
|
117 | + case '[TICKET_PRICE_WITH_TAXES]': |
|
118 | + return EEH_Template::format_currency($this->_ticket->get_ticket_total_with_taxes()); |
|
119 | + break; |
|
120 | + |
|
121 | + case '[TKT_QTY_PURCHASED]': |
|
122 | + return $aee instanceof EE_Messages_Addressee ? $aee->tickets[ $this->_ticket->ID() ]['count'] : ''; |
|
123 | + break; |
|
124 | + } |
|
125 | + |
|
126 | + if (strpos($shortcode, '[TKT_USES_*') !== false) { |
|
127 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
128 | + $schema = empty($attrs['schema']) ? null : $attrs['schema']; |
|
129 | + return $this->_ticket->get_pretty('TKT_uses', $schema); |
|
130 | + } |
|
131 | + return ''; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + public function get_ticket_set() |
|
136 | + { |
|
137 | + return $this->_ticket; |
|
138 | + } |
|
139 | 139 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
30 | 30 | 'event_espresso' |
31 | 31 | ) |
32 | - . '<p><ul>' . |
|
33 | - '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | + . '<p><ul>'. |
|
33 | + '<li><strong>no_payments</strong>:'.sprintf( |
|
34 | 34 | esc_html__( |
35 | 35 | 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
36 | 36 | 'event_espresso' |
37 | 37 | ), |
38 | 38 | htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
39 | 39 | htmlspecialchars('</td>') |
40 | - ) . '</li>' . |
|
40 | + ).'</li>'. |
|
41 | 41 | '</ul></p>', |
42 | 42 | ); |
43 | 43 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $this->_validate_list_requirements(); |
68 | 68 | |
69 | 69 | |
70 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
71 | 71 | return ''; |
72 | 72 | } |
73 | 73 |
@@ -18,88 +18,88 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Payment_List_Shortcodes extends EE_Shortcodes |
20 | 20 | { |
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Payment List Shortcodes', 'event_espresso'); |
|
24 | - $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso'); |
|
25 | - $this->_shortcodes = array( |
|
26 | - '[PAYMENT_LIST_*]' => esc_html__( |
|
27 | - 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
|
28 | - 'event_espresso' |
|
29 | - ) |
|
30 | - . '<p><ul>' . |
|
31 | - '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | - esc_html__( |
|
33 | - 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
|
37 | - htmlspecialchars('</td>') |
|
38 | - ) . '</li>' . |
|
39 | - '</ul></p>', |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _parser($shortcode) |
|
45 | - { |
|
46 | - |
|
47 | - if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) { |
|
48 | - return $this->_get_payment_list($shortcode); |
|
49 | - } |
|
50 | - return ''; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * verify incoming data contains what is needed for retrieving and parsing each payment for transaction. |
|
56 | - * |
|
57 | - * @since 4.5.0 |
|
58 | - * |
|
59 | - * @param string $shortcode The incoming shortcode. |
|
60 | - * |
|
61 | - * @return string parsed ticket line item list. |
|
62 | - */ |
|
63 | - private function _get_payment_list($shortcode) |
|
64 | - { |
|
65 | - $this->_validate_list_requirements(); |
|
66 | - |
|
67 | - |
|
68 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
69 | - return ''; |
|
70 | - } |
|
71 | - |
|
72 | - $valid_shortcodes = array('payment'); |
|
73 | - |
|
74 | - $addressee_obj = $this->_data['data']; |
|
75 | - $templates = $this->_extra_data['template']; |
|
76 | - $payments = apply_filters( |
|
77 | - 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', |
|
78 | - $addressee_obj->payments |
|
79 | - ); |
|
80 | - |
|
81 | - // let's get any attributes that may be present and set the defaults. |
|
82 | - $atts = $this->_get_shortcode_attrs($shortcode); |
|
83 | - |
|
84 | - $no_payments_msg = empty($atts['no_payments']) ? esc_html__( |
|
85 | - 'No approved payments have been received.', |
|
86 | - 'event_espresso' |
|
87 | - ) : $atts['no_payments']; |
|
88 | - |
|
89 | - // made it here so we have an array of paymnets, so we should have what we need. |
|
90 | - $payment_content = empty($payments) ? $no_payments_msg : ''; |
|
91 | - |
|
92 | - $payments = (array) $payments; |
|
93 | - |
|
94 | - foreach ($payments as $payment) { |
|
95 | - $payment_content .= $this->_shortcode_helper->parse_payment_list_template( |
|
96 | - $templates['payment_list'], |
|
97 | - $payment, |
|
98 | - $valid_shortcodes, |
|
99 | - $this->_extra_data |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - return $payment_content; |
|
104 | - } |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Payment List Shortcodes', 'event_espresso'); |
|
24 | + $this->description = esc_html__('All shortcodes specific to payment lists', 'event_espresso'); |
|
25 | + $this->_shortcodes = array( |
|
26 | + '[PAYMENT_LIST_*]' => esc_html__( |
|
27 | + 'Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults. Attributes that are available are:', |
|
28 | + 'event_espresso' |
|
29 | + ) |
|
30 | + . '<p><ul>' . |
|
31 | + '<li><strong>no_payments</strong>:' . sprintf( |
|
32 | + esc_html__( |
|
33 | + 'Indicate with this attribute what will be used if there are no payments present. Default is: "%sNo approved payments have been received.%s"', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + htmlspecialchars('<td class="aln-cntr" colspan="6">'), |
|
37 | + htmlspecialchars('</td>') |
|
38 | + ) . '</li>' . |
|
39 | + '</ul></p>', |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _parser($shortcode) |
|
45 | + { |
|
46 | + |
|
47 | + if (strpos($shortcode, '[PAYMENT_LIST_*') !== false) { |
|
48 | + return $this->_get_payment_list($shortcode); |
|
49 | + } |
|
50 | + return ''; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * verify incoming data contains what is needed for retrieving and parsing each payment for transaction. |
|
56 | + * |
|
57 | + * @since 4.5.0 |
|
58 | + * |
|
59 | + * @param string $shortcode The incoming shortcode. |
|
60 | + * |
|
61 | + * @return string parsed ticket line item list. |
|
62 | + */ |
|
63 | + private function _get_payment_list($shortcode) |
|
64 | + { |
|
65 | + $this->_validate_list_requirements(); |
|
66 | + |
|
67 | + |
|
68 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
69 | + return ''; |
|
70 | + } |
|
71 | + |
|
72 | + $valid_shortcodes = array('payment'); |
|
73 | + |
|
74 | + $addressee_obj = $this->_data['data']; |
|
75 | + $templates = $this->_extra_data['template']; |
|
76 | + $payments = apply_filters( |
|
77 | + 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', |
|
78 | + $addressee_obj->payments |
|
79 | + ); |
|
80 | + |
|
81 | + // let's get any attributes that may be present and set the defaults. |
|
82 | + $atts = $this->_get_shortcode_attrs($shortcode); |
|
83 | + |
|
84 | + $no_payments_msg = empty($atts['no_payments']) ? esc_html__( |
|
85 | + 'No approved payments have been received.', |
|
86 | + 'event_espresso' |
|
87 | + ) : $atts['no_payments']; |
|
88 | + |
|
89 | + // made it here so we have an array of paymnets, so we should have what we need. |
|
90 | + $payment_content = empty($payments) ? $no_payments_msg : ''; |
|
91 | + |
|
92 | + $payments = (array) $payments; |
|
93 | + |
|
94 | + foreach ($payments as $payment) { |
|
95 | + $payment_content .= $this->_shortcode_helper->parse_payment_list_template( |
|
96 | + $templates['payment_list'], |
|
97 | + $payment, |
|
98 | + $valid_shortcodes, |
|
99 | + $this->_extra_data |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + return $payment_content; |
|
104 | + } |
|
105 | 105 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $action = $request->getRequestParam('action'); |
62 | 62 | // show error message about buttons/urls not working as expected if messenger deactivated. |
63 | 63 | if ($action === 'update_message_template' && is_admin()) { |
64 | - if (! isset($this->_active_messengers['pdf'])) { |
|
64 | + if ( ! isset($this->_active_messengers['pdf'])) { |
|
65 | 65 | EE_Error::add_attention( |
66 | 66 | esc_html__( |
67 | 67 | 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
73 | - if (! isset($this->_active_messengers['html'])) { |
|
73 | + if ( ! isset($this->_active_messengers['html'])) { |
|
74 | 74 | EE_Error::add_attention( |
75 | 75 | esc_html__( |
76 | 76 | 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
94 | 94 | ? $this->_extra_data['data'] : $recipient; |
95 | 95 | |
96 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
96 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
97 | 97 | return ''; |
98 | 98 | } |
99 | 99 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | 'event_espresso' |
133 | 133 | ); |
134 | 134 | $content = ' |
135 | -<form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" > |
|
136 | - <input class="print_button" type="submit" value="' . $download_text . '" /> |
|
135 | +<form method="post" action="' . $this->_get_url($recipient, $sending_messenger).'" > |
|
136 | + <input class="print_button" type="submit" value="' . $download_text.'" /> |
|
137 | 137 | </form> |
138 | 138 | '; |
139 | 139 | return $content; |
@@ -22,157 +22,157 @@ |
||
22 | 22 | */ |
23 | 23 | class EE_Messenger_Shortcodes extends EE_Shortcodes |
24 | 24 | { |
25 | - /** |
|
26 | - * Hold array of active messengers indexed by messenger name. |
|
27 | - * |
|
28 | - * @since 4.5.0 |
|
29 | - * |
|
30 | - * @var EE_messenger[] |
|
31 | - */ |
|
32 | - protected $_active_messengers = array(); |
|
33 | - |
|
34 | - |
|
35 | - protected function _init_props() |
|
36 | - { |
|
37 | - $this->label = esc_html__('Messenger Shortcodes', 'event_espresso'); |
|
38 | - $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso'); |
|
39 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
40 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
41 | - // add messages about what happens when the messenger is active. |
|
42 | - $this->_active_messengers = $message_resource_manager->active_messengers(); |
|
43 | - |
|
44 | - $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__( |
|
45 | - 'This will return a link to view the template in a browser if the html messenger is active.', |
|
46 | - 'event_espresso' |
|
47 | - ); |
|
48 | - $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__( |
|
49 | - 'This will return a link to generate a pdf for the template if the pdf messenger is active.', |
|
50 | - 'event_espresso' |
|
51 | - ); |
|
52 | - $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__( |
|
53 | - 'This will return html for a download pdf button trigger if the pdf messenger is active.', |
|
54 | - 'event_espresso' |
|
55 | - ); |
|
56 | - |
|
57 | - /** @var RequestInterface $request */ |
|
58 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
59 | - $action = $request->getRequestParam('action'); |
|
60 | - // show error message about buttons/urls not working as expected if messenger deactivated. |
|
61 | - if ($action === 'update_message_template' && is_admin()) { |
|
62 | - if (! isset($this->_active_messengers['pdf'])) { |
|
63 | - EE_Error::add_attention( |
|
64 | - esc_html__( |
|
65 | - 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
|
66 | - 'event_espresso' |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - if (! isset($this->_active_messengers['html'])) { |
|
72 | - EE_Error::add_attention( |
|
73 | - esc_html__( |
|
74 | - 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
|
75 | - 'event_espresso' |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - protected function _parser($shortcode) |
|
84 | - { |
|
85 | - // make sure we end up with a copy of the EE_Messages_Addressee object |
|
86 | - $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
87 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && is_array( |
|
88 | - $this->_data |
|
89 | - ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
90 | - : $recipient; |
|
91 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
92 | - ? $this->_extra_data['data'] : $recipient; |
|
93 | - |
|
94 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
95 | - return ''; |
|
96 | - } |
|
97 | - |
|
98 | - switch ($shortcode) { |
|
99 | - case '[DISPLAY_HTML_URL]': |
|
100 | - return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : ''; |
|
101 | - break; |
|
102 | - case '[DISPLAY_PDF_URL]': |
|
103 | - return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : ''; |
|
104 | - break; |
|
105 | - case '[DISPLAY_PDF_BUTTON]': |
|
106 | - return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : ''; |
|
107 | - break; |
|
108 | - } |
|
109 | - return ''; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses |
|
115 | - * that to generate the html for a button in the template. |
|
116 | - * |
|
117 | - * @since 4.5.0 |
|
118 | - * |
|
119 | - * @param EE_Messages_Addressee $recipient |
|
120 | - * @param string $sending_messenger 'html' or 'pdf' |
|
121 | - * |
|
122 | - * @return string Generated html |
|
123 | - */ |
|
124 | - private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger) |
|
125 | - { |
|
126 | - $download_text = $sending_messenger == 'pdf' |
|
127 | - ? esc_html__('Download PDF', 'event_espresso') |
|
128 | - : esc_html__( |
|
129 | - 'Show HTML', |
|
130 | - 'event_espresso' |
|
131 | - ); |
|
132 | - $content = ' |
|
25 | + /** |
|
26 | + * Hold array of active messengers indexed by messenger name. |
|
27 | + * |
|
28 | + * @since 4.5.0 |
|
29 | + * |
|
30 | + * @var EE_messenger[] |
|
31 | + */ |
|
32 | + protected $_active_messengers = array(); |
|
33 | + |
|
34 | + |
|
35 | + protected function _init_props() |
|
36 | + { |
|
37 | + $this->label = esc_html__('Messenger Shortcodes', 'event_espresso'); |
|
38 | + $this->description = esc_html__('All shortcodes that are messenger specific.', 'event_espresso'); |
|
39 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
40 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
41 | + // add messages about what happens when the messenger is active. |
|
42 | + $this->_active_messengers = $message_resource_manager->active_messengers(); |
|
43 | + |
|
44 | + $this->_shortcodes['[DISPLAY_HTML_URL]'] = esc_html__( |
|
45 | + 'This will return a link to view the template in a browser if the html messenger is active.', |
|
46 | + 'event_espresso' |
|
47 | + ); |
|
48 | + $this->_shortcodes['[DISPLAY_PDF_URL]'] = esc_html__( |
|
49 | + 'This will return a link to generate a pdf for the template if the pdf messenger is active.', |
|
50 | + 'event_espresso' |
|
51 | + ); |
|
52 | + $this->_shortcodes['[DISPLAY_PDF_BUTTON]'] = esc_html__( |
|
53 | + 'This will return html for a download pdf button trigger if the pdf messenger is active.', |
|
54 | + 'event_espresso' |
|
55 | + ); |
|
56 | + |
|
57 | + /** @var RequestInterface $request */ |
|
58 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
59 | + $action = $request->getRequestParam('action'); |
|
60 | + // show error message about buttons/urls not working as expected if messenger deactivated. |
|
61 | + if ($action === 'update_message_template' && is_admin()) { |
|
62 | + if (! isset($this->_active_messengers['pdf'])) { |
|
63 | + EE_Error::add_attention( |
|
64 | + esc_html__( |
|
65 | + 'Be aware that the pdf messenger is inactive. This means that any pdf related shortcodes will parse to an empty string.', |
|
66 | + 'event_espresso' |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + if (! isset($this->_active_messengers['html'])) { |
|
72 | + EE_Error::add_attention( |
|
73 | + esc_html__( |
|
74 | + 'Be aware that the html messenger is inactive. This means that any html related shortcodes will parse to an empty string.', |
|
75 | + 'event_espresso' |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + protected function _parser($shortcode) |
|
84 | + { |
|
85 | + // make sure we end up with a copy of the EE_Messages_Addressee object |
|
86 | + $recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
87 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && is_array( |
|
88 | + $this->_data |
|
89 | + ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
90 | + : $recipient; |
|
91 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
92 | + ? $this->_extra_data['data'] : $recipient; |
|
93 | + |
|
94 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
95 | + return ''; |
|
96 | + } |
|
97 | + |
|
98 | + switch ($shortcode) { |
|
99 | + case '[DISPLAY_HTML_URL]': |
|
100 | + return isset($this->_active_messengers['html']) ? $this->_get_url($recipient, 'html') : ''; |
|
101 | + break; |
|
102 | + case '[DISPLAY_PDF_URL]': |
|
103 | + return isset($this->_active_messengers['pdf']) ? $this->_get_url($recipient, 'pdf') : ''; |
|
104 | + break; |
|
105 | + case '[DISPLAY_PDF_BUTTON]': |
|
106 | + return isset($this->_active_messengers['pdf']) ? $this->_get_button($recipient, 'pdf') : ''; |
|
107 | + break; |
|
108 | + } |
|
109 | + return ''; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This method takes the incoming data and figures out from it what the message type is and evt_id/grp_id and uses |
|
115 | + * that to generate the html for a button in the template. |
|
116 | + * |
|
117 | + * @since 4.5.0 |
|
118 | + * |
|
119 | + * @param EE_Messages_Addressee $recipient |
|
120 | + * @param string $sending_messenger 'html' or 'pdf' |
|
121 | + * |
|
122 | + * @return string Generated html |
|
123 | + */ |
|
124 | + private function _get_button(EE_Messages_Addressee $recipient, $sending_messenger) |
|
125 | + { |
|
126 | + $download_text = $sending_messenger == 'pdf' |
|
127 | + ? esc_html__('Download PDF', 'event_espresso') |
|
128 | + : esc_html__( |
|
129 | + 'Show HTML', |
|
130 | + 'event_espresso' |
|
131 | + ); |
|
132 | + $content = ' |
|
133 | 133 | <form method="post" action="' . $this->_get_url($recipient, $sending_messenger) . '" > |
134 | 134 | <input class="print_button" type="submit" value="' . $download_text . '" /> |
135 | 135 | </form> |
136 | 136 | '; |
137 | - return $content; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * This method takes the incoming data and figures out from it what the message type is and |
|
143 | - * evt_id/grp_id and uses that to generate the url for displaying the template in a browser. |
|
144 | - * |
|
145 | - * @since 4.5.0 |
|
146 | - * |
|
147 | - * @param EE_Messages_Addressee $recipient |
|
148 | - * @param string $sending_messenger |
|
149 | - * |
|
150 | - * @return string The generated url for displaying the link. |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger) |
|
154 | - { |
|
155 | - |
|
156 | - $reg = $recipient->reg_obj; |
|
157 | - $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg; |
|
158 | - |
|
159 | - |
|
160 | - if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) { |
|
161 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
162 | - try { |
|
163 | - return EEH_MSG_Template::get_url_trigger( |
|
164 | - $this->_message_type, |
|
165 | - $this->_message, |
|
166 | - $reg, |
|
167 | - $sending_messenger |
|
168 | - ); |
|
169 | - } catch (EE_Error $e) { |
|
170 | - if (WP_DEBUG) { |
|
171 | - $e->get_error(); |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - return ''; |
|
177 | - } |
|
137 | + return $content; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * This method takes the incoming data and figures out from it what the message type is and |
|
143 | + * evt_id/grp_id and uses that to generate the url for displaying the template in a browser. |
|
144 | + * |
|
145 | + * @since 4.5.0 |
|
146 | + * |
|
147 | + * @param EE_Messages_Addressee $recipient |
|
148 | + * @param string $sending_messenger |
|
149 | + * |
|
150 | + * @return string The generated url for displaying the link. |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger) |
|
154 | + { |
|
155 | + |
|
156 | + $reg = $recipient->reg_obj; |
|
157 | + $reg = ! $reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg; |
|
158 | + |
|
159 | + |
|
160 | + if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) { |
|
161 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
162 | + try { |
|
163 | + return EEH_MSG_Template::get_url_trigger( |
|
164 | + $this->_message_type, |
|
165 | + $this->_message, |
|
166 | + $reg, |
|
167 | + $sending_messenger |
|
168 | + ); |
|
169 | + } catch (EE_Error $e) { |
|
170 | + if (WP_DEBUG) { |
|
171 | + $e->get_error(); |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + return ''; |
|
177 | + } |
|
178 | 178 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getModelVersionInfo() |
52 | 52 | { |
53 | - if (! $this->model_version_info) { |
|
53 | + if ( ! $this->model_version_info) { |
|
54 | 54 | throw new EE_Error( |
55 | 55 | sprintf( |
56 | 56 | esc_html__( |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | protected function validateModel($model_name) |
97 | 97 | { |
98 | - if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) { |
|
98 | + if ( ! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) { |
|
99 | 99 | throw new RestException( |
100 | 100 | 'endpoint_parsing_error', |
101 | 101 | sprintf( |
@@ -18,95 +18,95 @@ |
||
18 | 18 | */ |
19 | 19 | class Base extends Controller_Base |
20 | 20 | { |
21 | - /** |
|
22 | - * Holds reference to the model version info, which knows the requested version |
|
23 | - * |
|
24 | - * @var ModelVersionInfo |
|
25 | - */ |
|
26 | - protected $model_version_info; |
|
21 | + /** |
|
22 | + * Holds reference to the model version info, which knows the requested version |
|
23 | + * |
|
24 | + * @var ModelVersionInfo |
|
25 | + */ |
|
26 | + protected $model_version_info; |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Sets the version the user requested |
|
32 | - * |
|
33 | - * @param string $version eg '4.8' |
|
34 | - */ |
|
35 | - public function setRequestedVersion($version) |
|
36 | - { |
|
37 | - parent::setRequestedVersion($version); |
|
38 | - $this->model_version_info = new ModelVersionInfo($version); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Sets the version the user requested |
|
32 | + * |
|
33 | + * @param string $version eg '4.8' |
|
34 | + */ |
|
35 | + public function setRequestedVersion($version) |
|
36 | + { |
|
37 | + parent::setRequestedVersion($version); |
|
38 | + $this->model_version_info = new ModelVersionInfo($version); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Gets the object that should be used for getting any info from the models, |
|
45 | - * because it's takes the requested and current core version into account |
|
46 | - * |
|
47 | - * @return ModelVersionInfo |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - public function getModelVersionInfo() |
|
51 | - { |
|
52 | - if (! $this->model_version_info) { |
|
53 | - throw new EE_Error( |
|
54 | - sprintf( |
|
55 | - esc_html__( |
|
56 | - 'Cannot use model version info before setting the requested version in the controller', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
62 | - return $this->model_version_info; |
|
63 | - } |
|
43 | + /** |
|
44 | + * Gets the object that should be used for getting any info from the models, |
|
45 | + * because it's takes the requested and current core version into account |
|
46 | + * |
|
47 | + * @return ModelVersionInfo |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + public function getModelVersionInfo() |
|
51 | + { |
|
52 | + if (! $this->model_version_info) { |
|
53 | + throw new EE_Error( |
|
54 | + sprintf( |
|
55 | + esc_html__( |
|
56 | + 'Cannot use model version info before setting the requested version in the controller', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | + return $this->model_version_info; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Determines if $object is of one of the classes of $classes. Similar to |
|
69 | - * in_array(), except this checks if $object is a subclass of the classnames provided |
|
70 | - * in $classnames |
|
71 | - * |
|
72 | - * @param object $object |
|
73 | - * @param array $classnames |
|
74 | - * @return boolean |
|
75 | - */ |
|
76 | - public function isSubclassOfOne($object, $classnames) |
|
77 | - { |
|
78 | - foreach ($classnames as $classname) { |
|
79 | - if (is_a($object, $classname)) { |
|
80 | - return true; |
|
81 | - } |
|
82 | - } |
|
83 | - return false; |
|
84 | - } |
|
67 | + /** |
|
68 | + * Determines if $object is of one of the classes of $classes. Similar to |
|
69 | + * in_array(), except this checks if $object is a subclass of the classnames provided |
|
70 | + * in $classnames |
|
71 | + * |
|
72 | + * @param object $object |
|
73 | + * @param array $classnames |
|
74 | + * @return boolean |
|
75 | + */ |
|
76 | + public function isSubclassOfOne($object, $classnames) |
|
77 | + { |
|
78 | + foreach ($classnames as $classname) { |
|
79 | + if (is_a($object, $classname)) { |
|
80 | + return true; |
|
81 | + } |
|
82 | + } |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Verifies the model name provided was valid. If so, returns the model (as an object). Otherwise, throws an |
|
88 | - * exception. Must be called after `setRequestedVersion()`. |
|
89 | - * @since 4.9.76.p |
|
90 | - * @param $model_name |
|
91 | - * @return EEM_Base |
|
92 | - * @throws EE_Error |
|
93 | - * @throws RestException |
|
94 | - */ |
|
95 | - protected function validateModel($model_name) |
|
96 | - { |
|
97 | - if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) { |
|
98 | - throw new RestException( |
|
99 | - 'endpoint_parsing_error', |
|
100 | - sprintf( |
|
101 | - esc_html__( |
|
102 | - 'There is no model for endpoint %s. Please contact event espresso support', |
|
103 | - 'event_espresso' |
|
104 | - ), |
|
105 | - $model_name |
|
106 | - ) |
|
107 | - ); |
|
108 | - } |
|
109 | - return $this->getModelVersionInfo()->loadModel($model_name); |
|
110 | - } |
|
86 | + /** |
|
87 | + * Verifies the model name provided was valid. If so, returns the model (as an object). Otherwise, throws an |
|
88 | + * exception. Must be called after `setRequestedVersion()`. |
|
89 | + * @since 4.9.76.p |
|
90 | + * @param $model_name |
|
91 | + * @return EEM_Base |
|
92 | + * @throws EE_Error |
|
93 | + * @throws RestException |
|
94 | + */ |
|
95 | + protected function validateModel($model_name) |
|
96 | + { |
|
97 | + if (! $this->getModelVersionInfo()->isModelNameInThisVersion($model_name)) { |
|
98 | + throw new RestException( |
|
99 | + 'endpoint_parsing_error', |
|
100 | + sprintf( |
|
101 | + esc_html__( |
|
102 | + 'There is no model for endpoint %s. Please contact event espresso support', |
|
103 | + 'event_espresso' |
|
104 | + ), |
|
105 | + $model_name |
|
106 | + ) |
|
107 | + ); |
|
108 | + } |
|
109 | + return $this->getModelVersionInfo()->loadModel($model_name); |
|
110 | + } |
|
111 | 111 | } |
112 | 112 | // End of file Base.php |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
136 | 136 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
137 | - if (! current_user_can($default_cap_to_check_for)) { |
|
137 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
138 | 138 | throw new RestException( |
139 | - 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
139 | + 'rest_cannot_create_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
140 | 140 | sprintf( |
141 | 141 | esc_html__( |
142 | 142 | // @codingStandardsIgnoreStart |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | ); |
165 | 165 | $model_obj->save(); |
166 | 166 | $new_id = $model_obj->ID(); |
167 | - if (! $new_id) { |
|
167 | + if ( ! $new_id) { |
|
168 | 168 | throw new RestException( |
169 | 169 | 'rest_insertion_failed', |
170 | 170 | sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | { |
187 | 187 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
188 | 188 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
189 | - if (! current_user_can($default_cap_to_check_for)) { |
|
189 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
190 | 190 | throw new RestException( |
191 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
191 | + 'rest_cannot_edit_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
192 | 192 | sprintf( |
193 | 193 | esc_html__( |
194 | 194 | // @codingStandardsIgnoreStart |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | ); |
203 | 203 | } |
204 | 204 | $obj_id = $request->get_param('id'); |
205 | - if (! $obj_id) { |
|
205 | + if ( ! $obj_id) { |
|
206 | 206 | throw new RestException( |
207 | 207 | 'rest_edit_failed', |
208 | 208 | sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | true |
216 | 216 | ); |
217 | 217 | $model_obj = $model->get_one_by_ID($obj_id); |
218 | - if (! $model_obj instanceof EE_Base_Class) { |
|
218 | + if ( ! $model_obj instanceof EE_Base_Class) { |
|
219 | 219 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
220 | 220 | throw new RestException( |
221 | 221 | sprintf('rest_%s_invalid_id', $lowercase_model_name), |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | { |
241 | 241 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
242 | 242 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
243 | - if (! current_user_can($default_cap_to_check_for)) { |
|
243 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
244 | 244 | throw new RestException( |
245 | - 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
245 | + 'rest_cannot_delete_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
246 | 246 | sprintf( |
247 | 247 | esc_html__( |
248 | 248 | // @codingStandardsIgnoreStart |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $obj_id = $request->get_param('id'); |
259 | 259 | // this is where we would apply more fine-grained caps |
260 | 260 | $model_obj = $model->get_one_by_ID($obj_id); |
261 | - if (! $model_obj instanceof EE_Base_Class) { |
|
261 | + if ( ! $model_obj instanceof EE_Base_Class) { |
|
262 | 262 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
263 | 263 | throw new RestException( |
264 | 264 | sprintf('rest_%s_invalid_id', $lowercase_model_name), |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | } else { |
317 | 317 | $raw_value = $model_obj->get_raw($field_name); |
318 | 318 | } |
319 | - $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value); |
|
319 | + $simulated_db_row[$field_obj->get_qualified_column()] = $field_obj->prepare_for_use_in_db($raw_value); |
|
320 | 320 | } |
321 | 321 | $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read'); |
322 | 322 | $read_controller->setRequestedVersion($this->getRequestedVersion()); |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | ) |
448 | 448 | ) |
449 | 449 | ); |
450 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
450 | + $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
451 | 451 | } |
452 | 452 | return $response; |
453 | 453 | } |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | { |
496 | 496 | // This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know |
497 | 497 | // up-front that it doesn't.) |
498 | - if (!empty($request->get_body_params())) { |
|
498 | + if ( ! empty($request->get_body_params())) { |
|
499 | 499 | $body_params = $request->get_body_params(); |
500 | 500 | throw new RestException( |
501 | 501 | 'invalid_field', |
@@ -537,9 +537,9 @@ discard block |
||
537 | 537 | ) |
538 | 538 | ); |
539 | 539 | if ($join_model_obj instanceof EE_Base_Class) { |
540 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
540 | + $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
541 | 541 | } else { |
542 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null; |
|
542 | + $response['join'][strtolower($relation->get_join_model()->get_this_model_name())] = null; |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | return $response; |
@@ -564,9 +564,9 @@ discard block |
||
564 | 564 | // Check generic caps. For now, we're only allowing access to this endpoint to full admins. |
565 | 565 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
566 | 566 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
567 | - if (! current_user_can($default_cap_to_check_for)) { |
|
567 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
568 | 568 | throw new RestException( |
569 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
569 | + 'rest_cannot_edit_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
570 | 570 | sprintf( |
571 | 571 | esc_html__( |
572 | 572 | // @codingStandardsIgnoreStart |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $model_obj = $this->getOneOrThrowException($model, $request->get_param('id')); |
584 | 584 | // For now, we require the other model object to exist too. This might be relaxed later. |
585 | 585 | $other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id')); |
586 | - return array($model_obj,$other_obj); |
|
586 | + return array($model_obj, $other_obj); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -37,573 +37,573 @@ |
||
37 | 37 | */ |
38 | 38 | class Write extends Base |
39 | 39 | { |
40 | - public function __construct() |
|
41 | - { |
|
42 | - parent::__construct(); |
|
43 | - EE_Registry::instance()->load_helper('Inflector'); |
|
44 | - } |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + parent::__construct(); |
|
43 | + EE_Registry::instance()->load_helper('Inflector'); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
49 | - * |
|
50 | - * @param WP_REST_Request $request |
|
51 | - * @param string $version |
|
52 | - * @param string $model_name |
|
53 | - * @return WP_REST_Response|\WP_Error |
|
54 | - */ |
|
55 | - public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
56 | - { |
|
57 | - $controller = new Write(); |
|
58 | - try { |
|
59 | - $controller->setRequestedVersion($version); |
|
60 | - return $controller->sendResponse( |
|
61 | - $controller->insert( |
|
62 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
63 | - $request |
|
64 | - ) |
|
65 | - ); |
|
66 | - } catch (Exception $e) { |
|
67 | - return $controller->sendResponse($e); |
|
68 | - } |
|
69 | - } |
|
47 | + /** |
|
48 | + * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
49 | + * |
|
50 | + * @param WP_REST_Request $request |
|
51 | + * @param string $version |
|
52 | + * @param string $model_name |
|
53 | + * @return WP_REST_Response|\WP_Error |
|
54 | + */ |
|
55 | + public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
56 | + { |
|
57 | + $controller = new Write(); |
|
58 | + try { |
|
59 | + $controller->setRequestedVersion($version); |
|
60 | + return $controller->sendResponse( |
|
61 | + $controller->insert( |
|
62 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
63 | + $request |
|
64 | + ) |
|
65 | + ); |
|
66 | + } catch (Exception $e) { |
|
67 | + return $controller->sendResponse($e); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Handles a request from \WP_REST_Server to update an EE model |
|
74 | - * |
|
75 | - * @param WP_REST_Request $request |
|
76 | - * @param string $version |
|
77 | - * @param string $model_name |
|
78 | - * @return WP_REST_Response|\WP_Error |
|
79 | - */ |
|
80 | - public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
81 | - { |
|
82 | - $controller = new Write(); |
|
83 | - try { |
|
84 | - $controller->setRequestedVersion($version); |
|
85 | - return $controller->sendResponse( |
|
86 | - $controller->update( |
|
87 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
88 | - $request |
|
89 | - ) |
|
90 | - ); |
|
91 | - } catch (Exception $e) { |
|
92 | - return $controller->sendResponse($e); |
|
93 | - } |
|
94 | - } |
|
72 | + /** |
|
73 | + * Handles a request from \WP_REST_Server to update an EE model |
|
74 | + * |
|
75 | + * @param WP_REST_Request $request |
|
76 | + * @param string $version |
|
77 | + * @param string $model_name |
|
78 | + * @return WP_REST_Response|\WP_Error |
|
79 | + */ |
|
80 | + public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
81 | + { |
|
82 | + $controller = new Write(); |
|
83 | + try { |
|
84 | + $controller->setRequestedVersion($version); |
|
85 | + return $controller->sendResponse( |
|
86 | + $controller->update( |
|
87 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
88 | + $request |
|
89 | + ) |
|
90 | + ); |
|
91 | + } catch (Exception $e) { |
|
92 | + return $controller->sendResponse($e); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Deletes a single model object and returns it. Unless |
|
99 | - * |
|
100 | - * @param WP_REST_Request $request |
|
101 | - * @param string $version |
|
102 | - * @param string $model_name |
|
103 | - * @return WP_REST_Response|\WP_Error |
|
104 | - */ |
|
105 | - public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
106 | - { |
|
107 | - $controller = new Write(); |
|
108 | - try { |
|
109 | - $controller->setRequestedVersion($version); |
|
110 | - return $controller->sendResponse( |
|
111 | - $controller->delete( |
|
112 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
113 | - $request |
|
114 | - ) |
|
115 | - ); |
|
116 | - } catch (Exception $e) { |
|
117 | - return $controller->sendResponse($e); |
|
118 | - } |
|
119 | - } |
|
97 | + /** |
|
98 | + * Deletes a single model object and returns it. Unless |
|
99 | + * |
|
100 | + * @param WP_REST_Request $request |
|
101 | + * @param string $version |
|
102 | + * @param string $model_name |
|
103 | + * @return WP_REST_Response|\WP_Error |
|
104 | + */ |
|
105 | + public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
106 | + { |
|
107 | + $controller = new Write(); |
|
108 | + try { |
|
109 | + $controller->setRequestedVersion($version); |
|
110 | + return $controller->sendResponse( |
|
111 | + $controller->delete( |
|
112 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
113 | + $request |
|
114 | + ) |
|
115 | + ); |
|
116 | + } catch (Exception $e) { |
|
117 | + return $controller->sendResponse($e); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * Inserts a new model object according to the $request |
|
124 | - * |
|
125 | - * @param EEM_Base $model |
|
126 | - * @param WP_REST_Request $request |
|
127 | - * @return array |
|
128 | - * @throws EE_Error |
|
129 | - * @throws RestException |
|
130 | - */ |
|
131 | - public function insert(EEM_Base $model, WP_REST_Request $request) |
|
132 | - { |
|
133 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
134 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
135 | - if (! current_user_can($default_cap_to_check_for)) { |
|
136 | - throw new RestException( |
|
137 | - 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
138 | - sprintf( |
|
139 | - esc_html__( |
|
140 | - // @codingStandardsIgnoreStart |
|
141 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
142 | - // @codingStandardsIgnoreEnd |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - $default_cap_to_check_for |
|
146 | - ), |
|
147 | - array('status' => 403) |
|
148 | - ); |
|
149 | - } |
|
150 | - $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
151 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
152 | - $submitted_json_data, |
|
153 | - $model, |
|
154 | - $this->getModelVersionInfo()->requestedVersion(), |
|
155 | - true |
|
156 | - ); |
|
157 | - $model_obj = EE_Registry::instance()->load_class( |
|
158 | - $model->get_this_model_name(), |
|
159 | - array($model_data, $model->get_timezone()), |
|
160 | - false, |
|
161 | - false |
|
162 | - ); |
|
163 | - $model_obj->save(); |
|
164 | - $new_id = $model_obj->ID(); |
|
165 | - if (! $new_id) { |
|
166 | - throw new RestException( |
|
167 | - 'rest_insertion_failed', |
|
168 | - sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
169 | - ); |
|
170 | - } |
|
171 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
172 | - } |
|
122 | + /** |
|
123 | + * Inserts a new model object according to the $request |
|
124 | + * |
|
125 | + * @param EEM_Base $model |
|
126 | + * @param WP_REST_Request $request |
|
127 | + * @return array |
|
128 | + * @throws EE_Error |
|
129 | + * @throws RestException |
|
130 | + */ |
|
131 | + public function insert(EEM_Base $model, WP_REST_Request $request) |
|
132 | + { |
|
133 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
134 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
135 | + if (! current_user_can($default_cap_to_check_for)) { |
|
136 | + throw new RestException( |
|
137 | + 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
138 | + sprintf( |
|
139 | + esc_html__( |
|
140 | + // @codingStandardsIgnoreStart |
|
141 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
142 | + // @codingStandardsIgnoreEnd |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + $default_cap_to_check_for |
|
146 | + ), |
|
147 | + array('status' => 403) |
|
148 | + ); |
|
149 | + } |
|
150 | + $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
151 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
152 | + $submitted_json_data, |
|
153 | + $model, |
|
154 | + $this->getModelVersionInfo()->requestedVersion(), |
|
155 | + true |
|
156 | + ); |
|
157 | + $model_obj = EE_Registry::instance()->load_class( |
|
158 | + $model->get_this_model_name(), |
|
159 | + array($model_data, $model->get_timezone()), |
|
160 | + false, |
|
161 | + false |
|
162 | + ); |
|
163 | + $model_obj->save(); |
|
164 | + $new_id = $model_obj->ID(); |
|
165 | + if (! $new_id) { |
|
166 | + throw new RestException( |
|
167 | + 'rest_insertion_failed', |
|
168 | + sprintf(esc_html__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
169 | + ); |
|
170 | + } |
|
171 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * Updates an existing model object according to the $request |
|
177 | - * |
|
178 | - * @param EEM_Base $model |
|
179 | - * @param WP_REST_Request $request |
|
180 | - * @return array |
|
181 | - * @throws EE_Error |
|
182 | - */ |
|
183 | - public function update(EEM_Base $model, WP_REST_Request $request) |
|
184 | - { |
|
185 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
186 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
187 | - if (! current_user_can($default_cap_to_check_for)) { |
|
188 | - throw new RestException( |
|
189 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
190 | - sprintf( |
|
191 | - esc_html__( |
|
192 | - // @codingStandardsIgnoreStart |
|
193 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
194 | - // @codingStandardsIgnoreEnd |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $default_cap_to_check_for |
|
198 | - ), |
|
199 | - array('status' => 403) |
|
200 | - ); |
|
201 | - } |
|
202 | - $obj_id = $request->get_param('id'); |
|
203 | - if (! $obj_id) { |
|
204 | - throw new RestException( |
|
205 | - 'rest_edit_failed', |
|
206 | - sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
207 | - ); |
|
208 | - } |
|
209 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
210 | - $this->getBodyParams($request), |
|
211 | - $model, |
|
212 | - $this->getModelVersionInfo()->requestedVersion(), |
|
213 | - true |
|
214 | - ); |
|
215 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
216 | - if (! $model_obj instanceof EE_Base_Class) { |
|
217 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
218 | - throw new RestException( |
|
219 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
220 | - sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
221 | - array('status' => 404) |
|
222 | - ); |
|
223 | - } |
|
224 | - $model_obj->save($model_data); |
|
225 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
226 | - } |
|
175 | + /** |
|
176 | + * Updates an existing model object according to the $request |
|
177 | + * |
|
178 | + * @param EEM_Base $model |
|
179 | + * @param WP_REST_Request $request |
|
180 | + * @return array |
|
181 | + * @throws EE_Error |
|
182 | + */ |
|
183 | + public function update(EEM_Base $model, WP_REST_Request $request) |
|
184 | + { |
|
185 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
186 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
187 | + if (! current_user_can($default_cap_to_check_for)) { |
|
188 | + throw new RestException( |
|
189 | + 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
190 | + sprintf( |
|
191 | + esc_html__( |
|
192 | + // @codingStandardsIgnoreStart |
|
193 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
194 | + // @codingStandardsIgnoreEnd |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $default_cap_to_check_for |
|
198 | + ), |
|
199 | + array('status' => 403) |
|
200 | + ); |
|
201 | + } |
|
202 | + $obj_id = $request->get_param('id'); |
|
203 | + if (! $obj_id) { |
|
204 | + throw new RestException( |
|
205 | + 'rest_edit_failed', |
|
206 | + sprintf(esc_html__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
207 | + ); |
|
208 | + } |
|
209 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
210 | + $this->getBodyParams($request), |
|
211 | + $model, |
|
212 | + $this->getModelVersionInfo()->requestedVersion(), |
|
213 | + true |
|
214 | + ); |
|
215 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
216 | + if (! $model_obj instanceof EE_Base_Class) { |
|
217 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
218 | + throw new RestException( |
|
219 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
220 | + sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
221 | + array('status' => 404) |
|
222 | + ); |
|
223 | + } |
|
224 | + $model_obj->save($model_data); |
|
225 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | - /** |
|
230 | - * Updates an existing model object according to the $request |
|
231 | - * |
|
232 | - * @param EEM_Base $model |
|
233 | - * @param WP_REST_Request $request |
|
234 | - * @return array of either the soft-deleted item, or |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - public function delete(EEM_Base $model, WP_REST_Request $request) |
|
238 | - { |
|
239 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
240 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
241 | - if (! current_user_can($default_cap_to_check_for)) { |
|
242 | - throw new RestException( |
|
243 | - 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - // @codingStandardsIgnoreStart |
|
247 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
248 | - // @codingStandardsIgnoreEnd |
|
249 | - 'event_espresso' |
|
250 | - ), |
|
251 | - $default_cap_to_check_for |
|
252 | - ), |
|
253 | - array('status' => 403) |
|
254 | - ); |
|
255 | - } |
|
256 | - $obj_id = $request->get_param('id'); |
|
257 | - // this is where we would apply more fine-grained caps |
|
258 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
259 | - if (! $model_obj instanceof EE_Base_Class) { |
|
260 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
261 | - throw new RestException( |
|
262 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
263 | - sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
264 | - array('status' => 404) |
|
265 | - ); |
|
266 | - } |
|
267 | - $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
268 | - $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
269 | - if ($requested_permanent_delete) { |
|
270 | - $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
271 | - $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
272 | - return array( |
|
273 | - 'deleted' => $deleted, |
|
274 | - 'previous' => $previous, |
|
275 | - ); |
|
276 | - } else { |
|
277 | - if ($model instanceof EEM_Soft_Delete_Base) { |
|
278 | - $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
279 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
280 | - } else { |
|
281 | - throw new RestException( |
|
282 | - 'rest_trash_not_supported', |
|
283 | - 501, |
|
284 | - sprintf( |
|
285 | - esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
286 | - EEH_Inflector::pluralize($model->get_this_model_name()) |
|
287 | - ) |
|
288 | - ); |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
229 | + /** |
|
230 | + * Updates an existing model object according to the $request |
|
231 | + * |
|
232 | + * @param EEM_Base $model |
|
233 | + * @param WP_REST_Request $request |
|
234 | + * @return array of either the soft-deleted item, or |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + public function delete(EEM_Base $model, WP_REST_Request $request) |
|
238 | + { |
|
239 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
240 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
241 | + if (! current_user_can($default_cap_to_check_for)) { |
|
242 | + throw new RestException( |
|
243 | + 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + // @codingStandardsIgnoreStart |
|
247 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
248 | + // @codingStandardsIgnoreEnd |
|
249 | + 'event_espresso' |
|
250 | + ), |
|
251 | + $default_cap_to_check_for |
|
252 | + ), |
|
253 | + array('status' => 403) |
|
254 | + ); |
|
255 | + } |
|
256 | + $obj_id = $request->get_param('id'); |
|
257 | + // this is where we would apply more fine-grained caps |
|
258 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
259 | + if (! $model_obj instanceof EE_Base_Class) { |
|
260 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
261 | + throw new RestException( |
|
262 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
263 | + sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
264 | + array('status' => 404) |
|
265 | + ); |
|
266 | + } |
|
267 | + $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
268 | + $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
269 | + if ($requested_permanent_delete) { |
|
270 | + $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
271 | + $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
272 | + return array( |
|
273 | + 'deleted' => $deleted, |
|
274 | + 'previous' => $previous, |
|
275 | + ); |
|
276 | + } else { |
|
277 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
278 | + $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
279 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
280 | + } else { |
|
281 | + throw new RestException( |
|
282 | + 'rest_trash_not_supported', |
|
283 | + 501, |
|
284 | + sprintf( |
|
285 | + esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
286 | + EEH_Inflector::pluralize($model->get_this_model_name()) |
|
287 | + ) |
|
288 | + ); |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | 292 | |
293 | 293 | |
294 | - /** |
|
295 | - * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
296 | - * |
|
297 | - * @param EE_Base_Class $model_obj |
|
298 | - * @param WP_REST_Request $request |
|
299 | - * @return array ready for a response |
|
300 | - */ |
|
301 | - protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
302 | - { |
|
303 | - $model = $model_obj->get_model(); |
|
304 | - // create an array exactly like the wpdb results row, |
|
305 | - // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
306 | - $simulated_db_row = array(); |
|
307 | - foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
308 | - // we need to reconstruct the normal wpdb results, including the db-only fields |
|
309 | - // like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
310 | - if ($field_obj instanceof EE_DB_Only_Field_Base) { |
|
311 | - $raw_value = true; |
|
312 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
313 | - $raw_value = $model_obj->get_DateTime_object($field_name); |
|
314 | - } else { |
|
315 | - $raw_value = $model_obj->get_raw($field_name); |
|
316 | - } |
|
317 | - $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value); |
|
318 | - } |
|
319 | - $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read'); |
|
320 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
321 | - // the simulates request really doesn't need any info downstream |
|
322 | - $simulated_request = new WP_REST_Request('GET'); |
|
323 | - // set the caps context on the simulated according to the original request. |
|
324 | - switch ($request->get_method()) { |
|
325 | - case 'POST': |
|
326 | - case 'PUT': |
|
327 | - $caps_context = EEM_Base::caps_edit; |
|
328 | - break; |
|
329 | - case 'DELETE': |
|
330 | - $caps_context = EEM_Base::caps_delete; |
|
331 | - break; |
|
332 | - default: |
|
333 | - $caps_context = EEM_Base::caps_read_admin; |
|
334 | - } |
|
335 | - $simulated_request->set_param('caps', $caps_context); |
|
336 | - return $read_controller->createEntityFromWpdbResult( |
|
337 | - $model_obj->get_model(), |
|
338 | - $simulated_db_row, |
|
339 | - $simulated_request |
|
340 | - ); |
|
341 | - } |
|
294 | + /** |
|
295 | + * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
296 | + * |
|
297 | + * @param EE_Base_Class $model_obj |
|
298 | + * @param WP_REST_Request $request |
|
299 | + * @return array ready for a response |
|
300 | + */ |
|
301 | + protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
302 | + { |
|
303 | + $model = $model_obj->get_model(); |
|
304 | + // create an array exactly like the wpdb results row, |
|
305 | + // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
306 | + $simulated_db_row = array(); |
|
307 | + foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
308 | + // we need to reconstruct the normal wpdb results, including the db-only fields |
|
309 | + // like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
310 | + if ($field_obj instanceof EE_DB_Only_Field_Base) { |
|
311 | + $raw_value = true; |
|
312 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
313 | + $raw_value = $model_obj->get_DateTime_object($field_name); |
|
314 | + } else { |
|
315 | + $raw_value = $model_obj->get_raw($field_name); |
|
316 | + } |
|
317 | + $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value); |
|
318 | + } |
|
319 | + $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read'); |
|
320 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
321 | + // the simulates request really doesn't need any info downstream |
|
322 | + $simulated_request = new WP_REST_Request('GET'); |
|
323 | + // set the caps context on the simulated according to the original request. |
|
324 | + switch ($request->get_method()) { |
|
325 | + case 'POST': |
|
326 | + case 'PUT': |
|
327 | + $caps_context = EEM_Base::caps_edit; |
|
328 | + break; |
|
329 | + case 'DELETE': |
|
330 | + $caps_context = EEM_Base::caps_delete; |
|
331 | + break; |
|
332 | + default: |
|
333 | + $caps_context = EEM_Base::caps_read_admin; |
|
334 | + } |
|
335 | + $simulated_request->set_param('caps', $caps_context); |
|
336 | + return $read_controller->createEntityFromWpdbResult( |
|
337 | + $model_obj->get_model(), |
|
338 | + $simulated_db_row, |
|
339 | + $simulated_request |
|
340 | + ); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | |
344 | - /** |
|
345 | - * Gets the item affected by this request |
|
346 | - * |
|
347 | - * @param EEM_Base $model |
|
348 | - * @param WP_REST_Request $request |
|
349 | - * @param int|string $obj_id |
|
350 | - * @return \WP_Error|array |
|
351 | - */ |
|
352 | - protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
353 | - { |
|
354 | - $requested_version = $this->getRequestedVersion($request->get_route()); |
|
355 | - $get_request = new WP_REST_Request( |
|
356 | - 'GET', |
|
357 | - EED_Core_Rest_Api::ee_api_namespace |
|
358 | - . $requested_version |
|
359 | - . '/' |
|
360 | - . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
361 | - . '/' |
|
362 | - . $obj_id |
|
363 | - ); |
|
364 | - $get_request->set_url_params( |
|
365 | - array( |
|
366 | - 'id' => $obj_id, |
|
367 | - 'include' => $request->get_param('include'), |
|
368 | - ) |
|
369 | - ); |
|
370 | - $read_controller = new Read(); |
|
371 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
372 | - return $read_controller->getEntityFromModel($model, $get_request); |
|
373 | - } |
|
344 | + /** |
|
345 | + * Gets the item affected by this request |
|
346 | + * |
|
347 | + * @param EEM_Base $model |
|
348 | + * @param WP_REST_Request $request |
|
349 | + * @param int|string $obj_id |
|
350 | + * @return \WP_Error|array |
|
351 | + */ |
|
352 | + protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
353 | + { |
|
354 | + $requested_version = $this->getRequestedVersion($request->get_route()); |
|
355 | + $get_request = new WP_REST_Request( |
|
356 | + 'GET', |
|
357 | + EED_Core_Rest_Api::ee_api_namespace |
|
358 | + . $requested_version |
|
359 | + . '/' |
|
360 | + . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
361 | + . '/' |
|
362 | + . $obj_id |
|
363 | + ); |
|
364 | + $get_request->set_url_params( |
|
365 | + array( |
|
366 | + 'id' => $obj_id, |
|
367 | + 'include' => $request->get_param('include'), |
|
368 | + ) |
|
369 | + ); |
|
370 | + $read_controller = new Read(); |
|
371 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
372 | + return $read_controller->getEntityFromModel($model, $get_request); |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Adds a relation between the specified models (if it doesn't already exist.) |
|
377 | - * @since 4.9.76.p |
|
378 | - * @param WP_REST_Request $request |
|
379 | - * @return WP_REST_Response |
|
380 | - */ |
|
381 | - public static function handleRequestAddRelation(WP_REST_Request $request, $version, $model_name, $related_model_name) |
|
382 | - { |
|
383 | - $controller = new Write(); |
|
384 | - try { |
|
385 | - $controller->setRequestedVersion($version); |
|
386 | - $main_model = $controller->validateModel($model_name); |
|
387 | - $controller->validateModel($related_model_name); |
|
388 | - return $controller->sendResponse( |
|
389 | - $controller->addRelation( |
|
390 | - $main_model, |
|
391 | - $main_model->related_settings_for($related_model_name), |
|
392 | - $request |
|
393 | - ) |
|
394 | - ); |
|
395 | - } catch (Exception $e) { |
|
396 | - return $controller->sendResponse($e); |
|
397 | - } |
|
398 | - } |
|
375 | + /** |
|
376 | + * Adds a relation between the specified models (if it doesn't already exist.) |
|
377 | + * @since 4.9.76.p |
|
378 | + * @param WP_REST_Request $request |
|
379 | + * @return WP_REST_Response |
|
380 | + */ |
|
381 | + public static function handleRequestAddRelation(WP_REST_Request $request, $version, $model_name, $related_model_name) |
|
382 | + { |
|
383 | + $controller = new Write(); |
|
384 | + try { |
|
385 | + $controller->setRequestedVersion($version); |
|
386 | + $main_model = $controller->validateModel($model_name); |
|
387 | + $controller->validateModel($related_model_name); |
|
388 | + return $controller->sendResponse( |
|
389 | + $controller->addRelation( |
|
390 | + $main_model, |
|
391 | + $main_model->related_settings_for($related_model_name), |
|
392 | + $request |
|
393 | + ) |
|
394 | + ); |
|
395 | + } catch (Exception $e) { |
|
396 | + return $controller->sendResponse($e); |
|
397 | + } |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Adds a relation between the two model specified model objects. |
|
402 | - * @since 4.9.76.p |
|
403 | - * @param EEM_Base $model |
|
404 | - * @param EE_Model_Relation_Base $relation |
|
405 | - * @param WP_REST_Request $request |
|
406 | - * @return array |
|
407 | - * @throws EE_Error |
|
408 | - * @throws InvalidArgumentException |
|
409 | - * @throws InvalidDataTypeException |
|
410 | - * @throws InvalidInterfaceException |
|
411 | - * @throws RestException |
|
412 | - * @throws DomainException |
|
413 | - */ |
|
414 | - public function addRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
415 | - { |
|
416 | - list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
417 | - $extra_params = array(); |
|
418 | - if ($relation instanceof EE_HABTM_Relation) { |
|
419 | - $extra_params = array_intersect_key( |
|
420 | - ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
421 | - $request->get_body_params(), |
|
422 | - $relation->get_join_model(), |
|
423 | - $this->getModelVersionInfo()->requestedVersion(), |
|
424 | - true |
|
425 | - ), |
|
426 | - $relation->getNonKeyFields() |
|
427 | - ); |
|
428 | - } |
|
429 | - // Add a relation. |
|
430 | - $related_obj = $model_obj->_add_relation_to( |
|
431 | - $other_obj, |
|
432 | - $relation->get_other_model()->get_this_model_name(), |
|
433 | - $extra_params |
|
434 | - ); |
|
435 | - $response = array( |
|
436 | - strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request), |
|
437 | - strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request), |
|
438 | - ); |
|
439 | - if ($relation instanceof EE_HABTM_Relation) { |
|
440 | - $join_model_obj = $relation->get_join_model()->get_one( |
|
441 | - array( |
|
442 | - array( |
|
443 | - $relation->get_join_model()->get_foreign_key_to($model->get_this_model_name())->get_name() => $model_obj->ID(), |
|
444 | - $relation->get_join_model()->get_foreign_key_to($relation->get_other_model()->get_this_model_name())->get_name() => $related_obj->ID() |
|
445 | - ) |
|
446 | - ) |
|
447 | - ); |
|
448 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
449 | - } |
|
450 | - return $response; |
|
451 | - } |
|
400 | + /** |
|
401 | + * Adds a relation between the two model specified model objects. |
|
402 | + * @since 4.9.76.p |
|
403 | + * @param EEM_Base $model |
|
404 | + * @param EE_Model_Relation_Base $relation |
|
405 | + * @param WP_REST_Request $request |
|
406 | + * @return array |
|
407 | + * @throws EE_Error |
|
408 | + * @throws InvalidArgumentException |
|
409 | + * @throws InvalidDataTypeException |
|
410 | + * @throws InvalidInterfaceException |
|
411 | + * @throws RestException |
|
412 | + * @throws DomainException |
|
413 | + */ |
|
414 | + public function addRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
415 | + { |
|
416 | + list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
417 | + $extra_params = array(); |
|
418 | + if ($relation instanceof EE_HABTM_Relation) { |
|
419 | + $extra_params = array_intersect_key( |
|
420 | + ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
421 | + $request->get_body_params(), |
|
422 | + $relation->get_join_model(), |
|
423 | + $this->getModelVersionInfo()->requestedVersion(), |
|
424 | + true |
|
425 | + ), |
|
426 | + $relation->getNonKeyFields() |
|
427 | + ); |
|
428 | + } |
|
429 | + // Add a relation. |
|
430 | + $related_obj = $model_obj->_add_relation_to( |
|
431 | + $other_obj, |
|
432 | + $relation->get_other_model()->get_this_model_name(), |
|
433 | + $extra_params |
|
434 | + ); |
|
435 | + $response = array( |
|
436 | + strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request), |
|
437 | + strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request), |
|
438 | + ); |
|
439 | + if ($relation instanceof EE_HABTM_Relation) { |
|
440 | + $join_model_obj = $relation->get_join_model()->get_one( |
|
441 | + array( |
|
442 | + array( |
|
443 | + $relation->get_join_model()->get_foreign_key_to($model->get_this_model_name())->get_name() => $model_obj->ID(), |
|
444 | + $relation->get_join_model()->get_foreign_key_to($relation->get_other_model()->get_this_model_name())->get_name() => $related_obj->ID() |
|
445 | + ) |
|
446 | + ) |
|
447 | + ); |
|
448 | + $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
449 | + } |
|
450 | + return $response; |
|
451 | + } |
|
452 | 452 | |
453 | 453 | |
454 | - /** |
|
455 | - * Removes the relation between the specified models (if it exists). |
|
456 | - * @since 4.9.76.p |
|
457 | - * @param WP_REST_Request $request |
|
458 | - * @return WP_REST_Response |
|
459 | - */ |
|
460 | - public static function handleRequestRemoveRelation(WP_REST_Request $request, $version, $model_name, $related_model_name) |
|
461 | - { |
|
462 | - $controller = new Write(); |
|
463 | - try { |
|
464 | - $controller->setRequestedVersion($version); |
|
465 | - $main_model = $controller->getModelVersionInfo()->loadModel($model_name); |
|
466 | - return $controller->sendResponse( |
|
467 | - $controller->removeRelation( |
|
468 | - $main_model, |
|
469 | - $main_model->related_settings_for($related_model_name), |
|
470 | - $request |
|
471 | - ) |
|
472 | - ); |
|
473 | - } catch (Exception $e) { |
|
474 | - return $controller->sendResponse($e); |
|
475 | - } |
|
476 | - } |
|
454 | + /** |
|
455 | + * Removes the relation between the specified models (if it exists). |
|
456 | + * @since 4.9.76.p |
|
457 | + * @param WP_REST_Request $request |
|
458 | + * @return WP_REST_Response |
|
459 | + */ |
|
460 | + public static function handleRequestRemoveRelation(WP_REST_Request $request, $version, $model_name, $related_model_name) |
|
461 | + { |
|
462 | + $controller = new Write(); |
|
463 | + try { |
|
464 | + $controller->setRequestedVersion($version); |
|
465 | + $main_model = $controller->getModelVersionInfo()->loadModel($model_name); |
|
466 | + return $controller->sendResponse( |
|
467 | + $controller->removeRelation( |
|
468 | + $main_model, |
|
469 | + $main_model->related_settings_for($related_model_name), |
|
470 | + $request |
|
471 | + ) |
|
472 | + ); |
|
473 | + } catch (Exception $e) { |
|
474 | + return $controller->sendResponse($e); |
|
475 | + } |
|
476 | + } |
|
477 | 477 | |
478 | - /** |
|
479 | - * Adds a relation between the two model specified model objects. |
|
480 | - * @since 4.9.76.p |
|
481 | - * @param EEM_Base $model |
|
482 | - * @param EE_Model_Relation_Base $relation |
|
483 | - * @param WP_REST_Request $request |
|
484 | - * @return array |
|
485 | - * @throws DomainException |
|
486 | - * @throws EE_Error |
|
487 | - * @throws InvalidArgumentException |
|
488 | - * @throws InvalidDataTypeException |
|
489 | - * @throws InvalidInterfaceException |
|
490 | - * @throws RestException |
|
491 | - */ |
|
492 | - public function removeRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
493 | - { |
|
494 | - // This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know |
|
495 | - // up-front that it doesn't.) |
|
496 | - if (!empty($request->get_body_params())) { |
|
497 | - $body_params = $request->get_body_params(); |
|
498 | - throw new RestException( |
|
499 | - 'invalid_field', |
|
500 | - sprintf( |
|
501 | - esc_html__('This endpoint doesn\'t accept post body arguments, you sent in %1$s', 'event_espresso'), |
|
502 | - implode(array_keys($body_params)) |
|
503 | - ) |
|
504 | - ); |
|
505 | - } |
|
506 | - list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
507 | - // Remember the old relation, if it used a join entry. |
|
508 | - $join_model_obj = null; |
|
509 | - if ($relation instanceof EE_HABTM_Relation) { |
|
510 | - $join_model_obj = $relation->get_join_model()->get_one( |
|
511 | - array( |
|
512 | - array( |
|
513 | - $model->primary_key_name() => $model_obj->ID(), |
|
514 | - $relation->get_other_model()->primary_key_name() => $other_obj->ID() |
|
515 | - ) |
|
516 | - ) |
|
517 | - ); |
|
518 | - } |
|
519 | - // Remove the relation. |
|
520 | - $related_obj = $model_obj->_remove_relation_to( |
|
521 | - $other_obj, |
|
522 | - $relation->get_other_model()->get_this_model_name() |
|
523 | - ); |
|
524 | - $response = array( |
|
525 | - strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request), |
|
526 | - strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request), |
|
527 | - ); |
|
528 | - if ($relation instanceof EE_HABTM_Relation) { |
|
529 | - $join_model_obj_after_removal = $relation->get_join_model()->get_one( |
|
530 | - array( |
|
531 | - array( |
|
532 | - $model->primary_key_name() => $model_obj->ID(), |
|
533 | - $relation->get_other_model()->primary_key_name() => $other_obj->ID() |
|
534 | - ) |
|
535 | - ) |
|
536 | - ); |
|
537 | - if ($join_model_obj instanceof EE_Base_Class) { |
|
538 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
539 | - } else { |
|
540 | - $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null; |
|
541 | - } |
|
542 | - } |
|
543 | - return $response; |
|
544 | - } |
|
478 | + /** |
|
479 | + * Adds a relation between the two model specified model objects. |
|
480 | + * @since 4.9.76.p |
|
481 | + * @param EEM_Base $model |
|
482 | + * @param EE_Model_Relation_Base $relation |
|
483 | + * @param WP_REST_Request $request |
|
484 | + * @return array |
|
485 | + * @throws DomainException |
|
486 | + * @throws EE_Error |
|
487 | + * @throws InvalidArgumentException |
|
488 | + * @throws InvalidDataTypeException |
|
489 | + * @throws InvalidInterfaceException |
|
490 | + * @throws RestException |
|
491 | + */ |
|
492 | + public function removeRelation(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
493 | + { |
|
494 | + // This endpoint doesn't accept body parameters (it's understandable to think it might, so let developers know |
|
495 | + // up-front that it doesn't.) |
|
496 | + if (!empty($request->get_body_params())) { |
|
497 | + $body_params = $request->get_body_params(); |
|
498 | + throw new RestException( |
|
499 | + 'invalid_field', |
|
500 | + sprintf( |
|
501 | + esc_html__('This endpoint doesn\'t accept post body arguments, you sent in %1$s', 'event_espresso'), |
|
502 | + implode(array_keys($body_params)) |
|
503 | + ) |
|
504 | + ); |
|
505 | + } |
|
506 | + list($model_obj, $other_obj) = $this->getBothModelObjects($model, $relation, $request); |
|
507 | + // Remember the old relation, if it used a join entry. |
|
508 | + $join_model_obj = null; |
|
509 | + if ($relation instanceof EE_HABTM_Relation) { |
|
510 | + $join_model_obj = $relation->get_join_model()->get_one( |
|
511 | + array( |
|
512 | + array( |
|
513 | + $model->primary_key_name() => $model_obj->ID(), |
|
514 | + $relation->get_other_model()->primary_key_name() => $other_obj->ID() |
|
515 | + ) |
|
516 | + ) |
|
517 | + ); |
|
518 | + } |
|
519 | + // Remove the relation. |
|
520 | + $related_obj = $model_obj->_remove_relation_to( |
|
521 | + $other_obj, |
|
522 | + $relation->get_other_model()->get_this_model_name() |
|
523 | + ); |
|
524 | + $response = array( |
|
525 | + strtolower($model->get_this_model_name()) => $this->returnModelObjAsJsonResponse($model_obj, $request), |
|
526 | + strtolower($relation->get_other_model()->get_this_model_name()) => $this->returnModelObjAsJsonResponse($related_obj, $request), |
|
527 | + ); |
|
528 | + if ($relation instanceof EE_HABTM_Relation) { |
|
529 | + $join_model_obj_after_removal = $relation->get_join_model()->get_one( |
|
530 | + array( |
|
531 | + array( |
|
532 | + $model->primary_key_name() => $model_obj->ID(), |
|
533 | + $relation->get_other_model()->primary_key_name() => $other_obj->ID() |
|
534 | + ) |
|
535 | + ) |
|
536 | + ); |
|
537 | + if ($join_model_obj instanceof EE_Base_Class) { |
|
538 | + $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = $this->returnModelObjAsJsonResponse($join_model_obj, $request); |
|
539 | + } else { |
|
540 | + $response['join'][ strtolower($relation->get_join_model()->get_this_model_name()) ] = null; |
|
541 | + } |
|
542 | + } |
|
543 | + return $response; |
|
544 | + } |
|
545 | 545 | |
546 | - /** |
|
547 | - * Gets the model objects indicated by the model, relation object, and request. |
|
548 | - * Throws an exception if the first object doesn't exist, and currently if the related object also doesn't exist. |
|
549 | - * However, this behaviour may change, as we may add support for simultaneously creating and relating data. |
|
550 | - * @since 4.9.76.p |
|
551 | - * @param EEM_Base $model |
|
552 | - * @param EE_Model_Relation_Base $relation |
|
553 | - * @param WP_REST_Request $request |
|
554 | - * @return array { |
|
555 | - * @type EE_Base_Class $model_obj |
|
556 | - * @type EE_Base_Class|null $other_model_obj |
|
557 | - * } |
|
558 | - * @throws RestException |
|
559 | - */ |
|
560 | - protected function getBothModelObjects(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
561 | - { |
|
562 | - // Check generic caps. For now, we're only allowing access to this endpoint to full admins. |
|
563 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
564 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
565 | - if (! current_user_can($default_cap_to_check_for)) { |
|
566 | - throw new RestException( |
|
567 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
568 | - sprintf( |
|
569 | - esc_html__( |
|
570 | - // @codingStandardsIgnoreStart |
|
571 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to add relations in Event Espresso.', |
|
572 | - // @codingStandardsIgnoreEnd |
|
573 | - 'event_espresso' |
|
574 | - ), |
|
575 | - $default_cap_to_check_for |
|
576 | - ), |
|
577 | - array('status' => 403) |
|
578 | - ); |
|
579 | - } |
|
580 | - // Get the main model object. |
|
581 | - $model_obj = $this->getOneOrThrowException($model, $request->get_param('id')); |
|
582 | - // For now, we require the other model object to exist too. This might be relaxed later. |
|
583 | - $other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id')); |
|
584 | - return array($model_obj,$other_obj); |
|
585 | - } |
|
546 | + /** |
|
547 | + * Gets the model objects indicated by the model, relation object, and request. |
|
548 | + * Throws an exception if the first object doesn't exist, and currently if the related object also doesn't exist. |
|
549 | + * However, this behaviour may change, as we may add support for simultaneously creating and relating data. |
|
550 | + * @since 4.9.76.p |
|
551 | + * @param EEM_Base $model |
|
552 | + * @param EE_Model_Relation_Base $relation |
|
553 | + * @param WP_REST_Request $request |
|
554 | + * @return array { |
|
555 | + * @type EE_Base_Class $model_obj |
|
556 | + * @type EE_Base_Class|null $other_model_obj |
|
557 | + * } |
|
558 | + * @throws RestException |
|
559 | + */ |
|
560 | + protected function getBothModelObjects(EEM_Base $model, EE_Model_Relation_Base $relation, WP_REST_Request $request) |
|
561 | + { |
|
562 | + // Check generic caps. For now, we're only allowing access to this endpoint to full admins. |
|
563 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
564 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
565 | + if (! current_user_can($default_cap_to_check_for)) { |
|
566 | + throw new RestException( |
|
567 | + 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
568 | + sprintf( |
|
569 | + esc_html__( |
|
570 | + // @codingStandardsIgnoreStart |
|
571 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to add relations in Event Espresso.', |
|
572 | + // @codingStandardsIgnoreEnd |
|
573 | + 'event_espresso' |
|
574 | + ), |
|
575 | + $default_cap_to_check_for |
|
576 | + ), |
|
577 | + array('status' => 403) |
|
578 | + ); |
|
579 | + } |
|
580 | + // Get the main model object. |
|
581 | + $model_obj = $this->getOneOrThrowException($model, $request->get_param('id')); |
|
582 | + // For now, we require the other model object to exist too. This might be relaxed later. |
|
583 | + $other_obj = $this->getOneOrThrowException($relation->get_other_model(), $request->get_param('related_id')); |
|
584 | + return array($model_obj,$other_obj); |
|
585 | + } |
|
586 | 586 | |
587 | - /** |
|
588 | - * Gets the model with that ID or throws a REST exception. |
|
589 | - * @since 4.9.76.p |
|
590 | - * @param EEM_Base $model |
|
591 | - * @param $id |
|
592 | - * @return EE_Base_Class |
|
593 | - * @throws RestException |
|
594 | - */ |
|
595 | - protected function getOneOrThrowException(EEM_Base $model, $id) |
|
596 | - { |
|
597 | - $model_obj = $model->get_one_by_ID($id); |
|
598 | - // @todo: check they can permission for it. For now unnecessary because only full admins can use this endpoint. |
|
599 | - if ($model_obj instanceof EE_Base_Class) { |
|
600 | - return $model_obj; |
|
601 | - } |
|
602 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
603 | - throw new RestException( |
|
604 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
605 | - sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
606 | - array('status' => 404) |
|
607 | - ); |
|
608 | - } |
|
587 | + /** |
|
588 | + * Gets the model with that ID or throws a REST exception. |
|
589 | + * @since 4.9.76.p |
|
590 | + * @param EEM_Base $model |
|
591 | + * @param $id |
|
592 | + * @return EE_Base_Class |
|
593 | + * @throws RestException |
|
594 | + */ |
|
595 | + protected function getOneOrThrowException(EEM_Base $model, $id) |
|
596 | + { |
|
597 | + $model_obj = $model->get_one_by_ID($id); |
|
598 | + // @todo: check they can permission for it. For now unnecessary because only full admins can use this endpoint. |
|
599 | + if ($model_obj instanceof EE_Base_Class) { |
|
600 | + return $model_obj; |
|
601 | + } |
|
602 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
603 | + throw new RestException( |
|
604 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
605 | + sprintf(esc_html__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
606 | + array('status' => 404) |
|
607 | + ); |
|
608 | + } |
|
609 | 609 | } |