@@ -14,17 +14,17 @@ |
||
14 | 14 | */ |
15 | 15 | class WordPressPageEditorAddNew extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since 4.9.71.p |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - global $pagenow; |
|
26 | - return $pagenow |
|
27 | - && $pagenow === 'post-new.php' |
|
28 | - && $this->request->getRequestParam('post_type', 'post') === 'page'; |
|
29 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since 4.9.71.p |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + global $pagenow; |
|
26 | + return $pagenow |
|
27 | + && $pagenow === 'post-new.php' |
|
28 | + && $this->request->getRequestParam('post_type', 'post') === 'page'; |
|
29 | + } |
|
30 | 30 | } |
@@ -14,18 +14,18 @@ |
||
14 | 14 | */ |
15 | 15 | class EspressoAttendeePostTypeEditor extends RouteMatchSpecification |
16 | 16 | { |
17 | - /** |
|
18 | - * returns true if current request matches specification |
|
19 | - * |
|
20 | - * @since 4.9.71.p |
|
21 | - * @return boolean |
|
22 | - */ |
|
23 | - public function isMatchingRoute() |
|
24 | - { |
|
25 | - global $pagenow; |
|
26 | - return $pagenow |
|
27 | - && $pagenow === 'admin.php' |
|
28 | - && $this->request->getRequestParam('page') === 'espresso_registrations' |
|
29 | - && $this->request->getRequestParam('action') === 'edit_attendee'; |
|
30 | - } |
|
17 | + /** |
|
18 | + * returns true if current request matches specification |
|
19 | + * |
|
20 | + * @since 4.9.71.p |
|
21 | + * @return boolean |
|
22 | + */ |
|
23 | + public function isMatchingRoute() |
|
24 | + { |
|
25 | + global $pagenow; |
|
26 | + return $pagenow |
|
27 | + && $pagenow === 'admin.php' |
|
28 | + && $this->request->getRequestParam('page') === 'espresso_registrations' |
|
29 | + && $this->request->getRequestParam('action') === 'edit_attendee'; |
|
30 | + } |
|
31 | 31 | } |
@@ -15,17 +15,17 @@ |
||
15 | 15 | */ |
16 | 16 | class WordPressPostsEditorAddNew extends RouteMatchSpecification |
17 | 17 | { |
18 | - /** |
|
19 | - * returns true if current request matches specification |
|
20 | - * |
|
21 | - * @since 4.9.71.p |
|
22 | - * @return boolean |
|
23 | - */ |
|
24 | - public function isMatchingRoute() |
|
25 | - { |
|
26 | - global $pagenow; |
|
27 | - return $pagenow |
|
28 | - && $pagenow === 'post-new.php' |
|
29 | - && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
30 | - } |
|
18 | + /** |
|
19 | + * returns true if current request matches specification |
|
20 | + * |
|
21 | + * @since 4.9.71.p |
|
22 | + * @return boolean |
|
23 | + */ |
|
24 | + public function isMatchingRoute() |
|
25 | + { |
|
26 | + global $pagenow; |
|
27 | + return $pagenow |
|
28 | + && $pagenow === 'post-new.php' |
|
29 | + && $this->request->getRequestParam('post_type', 'post') === 'post'; |
|
30 | + } |
|
31 | 31 | } |
@@ -16,18 +16,18 @@ |
||
16 | 16 | */ |
17 | 17 | class WordPressPageEditorEdit extends RouteMatchSpecification |
18 | 18 | { |
19 | - /** |
|
20 | - * returns true if current request matches specification |
|
21 | - * |
|
22 | - * @since 4.9.71.p |
|
23 | - * @return boolean |
|
24 | - */ |
|
25 | - public function isMatchingRoute() |
|
26 | - { |
|
27 | - global $pagenow; |
|
28 | - return $pagenow |
|
29 | - && $pagenow === 'plugins.php' |
|
30 | - && $this->request->getRequestParam('post_type', 'post') === 'page' |
|
31 | - && $this->request->getRequestParam('action') === 'edit'; |
|
32 | - } |
|
19 | + /** |
|
20 | + * returns true if current request matches specification |
|
21 | + * |
|
22 | + * @since 4.9.71.p |
|
23 | + * @return boolean |
|
24 | + */ |
|
25 | + public function isMatchingRoute() |
|
26 | + { |
|
27 | + global $pagenow; |
|
28 | + return $pagenow |
|
29 | + && $pagenow === 'plugins.php' |
|
30 | + && $this->request->getRequestParam('post_type', 'post') === 'page' |
|
31 | + && $this->request->getRequestParam('action') === 'edit'; |
|
32 | + } |
|
33 | 33 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | // @link http://josscrowcroft.github.io/accounting.js/ |
84 | 84 | $this->addJavascript( |
85 | 85 | LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
86 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
86 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
87 | 87 | [LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
88 | 88 | true, |
89 | 89 | '0.3.2' |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | |
92 | 92 | $this->addJavascript( |
93 | 93 | LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
94 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
94 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
95 | 95 | [LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
96 | 96 | ) |
97 | 97 | ->setInlineDataCallback( |
98 | - function () { |
|
98 | + function() { |
|
99 | 99 | wp_localize_script( |
100 | 100 | LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
101 | 101 | 'EE_ACCOUNTING_CFG', |
@@ -24,125 +24,125 @@ |
||
24 | 24 | class LegacyAccountingAssetManager extends AssetManager |
25 | 25 | { |
26 | 26 | |
27 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | - |
|
29 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
30 | - |
|
31 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @var EE_Currency_Config $currency_config |
|
36 | - */ |
|
37 | - protected $currency_config; |
|
38 | - |
|
39 | - /** |
|
40 | - * CoreAssetRegister constructor. |
|
41 | - * |
|
42 | - * @param AssetCollection $assets |
|
43 | - * @param DomainInterface $domain |
|
44 | - * @param Registry $registry |
|
45 | - * @param EE_Currency_Config $currency_config |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - AssetCollection $assets, |
|
49 | - DomainInterface $domain, |
|
50 | - Registry $registry, |
|
51 | - EE_Currency_Config $currency_config |
|
52 | - ) { |
|
53 | - $this->currency_config = $currency_config; |
|
54 | - parent::__construct($domain, $assets, $registry); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - * @throws InvalidEntityException |
|
62 | - * @throws DuplicateCollectionIdentifierException |
|
63 | - * @throws DomainException |
|
64 | - */ |
|
65 | - public function addAssets() |
|
66 | - { |
|
67 | - $this->loadAccountingJs(); |
|
68 | - add_action('admin_enqueue_scripts', [$this, 'enqueueLegacyAccountingAssets'], 100); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * accounting.js for performing client-side calculations |
|
74 | - * |
|
75 | - * @throws DomainException |
|
76 | - * @throws DuplicateCollectionIdentifierException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidEntityException |
|
79 | - * @since 5.0.0.p |
|
80 | - */ |
|
81 | - private function loadAccountingJs() |
|
82 | - { |
|
83 | - //accounting.js library |
|
84 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
85 | - $this->addJavascript( |
|
86 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
87 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
88 | - [LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
|
89 | - true, |
|
90 | - '0.3.2' |
|
91 | - ); |
|
92 | - |
|
93 | - $this->addJavascript( |
|
94 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
95 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
96 | - [LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
97 | - ) |
|
98 | - ->setInlineDataCallback( |
|
99 | - function () { |
|
100 | - wp_localize_script( |
|
101 | - LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
102 | - 'EE_ACCOUNTING_CFG', |
|
103 | - $this->getAccountingSettings() |
|
104 | - ); |
|
105 | - } |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Returns configuration data for the accounting-js library. |
|
112 | - * |
|
113 | - * @return array |
|
114 | - * @since 5.0.0.p |
|
115 | - */ |
|
116 | - private function getAccountingSettings() |
|
117 | - { |
|
118 | - return [ |
|
119 | - 'currency' => [ |
|
120 | - 'symbol' => $this->currency_config->sign, |
|
121 | - 'format' => [ |
|
122 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
123 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
124 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
125 | - ], |
|
126 | - 'decimal' => $this->currency_config->dec_mrk, |
|
127 | - 'thousand' => $this->currency_config->thsnds, |
|
128 | - 'precision' => $this->currency_config->dec_plc, |
|
129 | - ], |
|
130 | - 'number' => [ |
|
131 | - 'precision' => $this->currency_config->dec_plc, |
|
132 | - 'thousand' => $this->currency_config->thsnds, |
|
133 | - 'decimal' => $this->currency_config->dec_mrk, |
|
134 | - ], |
|
135 | - ]; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * enqueue_scripts - Load the scripts and css |
|
141 | - * |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function enqueueLegacyAccountingAssets() |
|
145 | - { |
|
146 | - $this->enqueueAsset(LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING); |
|
147 | - } |
|
27 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
28 | + |
|
29 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
30 | + |
|
31 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @var EE_Currency_Config $currency_config |
|
36 | + */ |
|
37 | + protected $currency_config; |
|
38 | + |
|
39 | + /** |
|
40 | + * CoreAssetRegister constructor. |
|
41 | + * |
|
42 | + * @param AssetCollection $assets |
|
43 | + * @param DomainInterface $domain |
|
44 | + * @param Registry $registry |
|
45 | + * @param EE_Currency_Config $currency_config |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + AssetCollection $assets, |
|
49 | + DomainInterface $domain, |
|
50 | + Registry $registry, |
|
51 | + EE_Currency_Config $currency_config |
|
52 | + ) { |
|
53 | + $this->currency_config = $currency_config; |
|
54 | + parent::__construct($domain, $assets, $registry); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + * @throws InvalidEntityException |
|
62 | + * @throws DuplicateCollectionIdentifierException |
|
63 | + * @throws DomainException |
|
64 | + */ |
|
65 | + public function addAssets() |
|
66 | + { |
|
67 | + $this->loadAccountingJs(); |
|
68 | + add_action('admin_enqueue_scripts', [$this, 'enqueueLegacyAccountingAssets'], 100); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * accounting.js for performing client-side calculations |
|
74 | + * |
|
75 | + * @throws DomainException |
|
76 | + * @throws DuplicateCollectionIdentifierException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidEntityException |
|
79 | + * @since 5.0.0.p |
|
80 | + */ |
|
81 | + private function loadAccountingJs() |
|
82 | + { |
|
83 | + //accounting.js library |
|
84 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
85 | + $this->addJavascript( |
|
86 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
87 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
88 | + [LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
|
89 | + true, |
|
90 | + '0.3.2' |
|
91 | + ); |
|
92 | + |
|
93 | + $this->addJavascript( |
|
94 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
95 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
96 | + [LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
|
97 | + ) |
|
98 | + ->setInlineDataCallback( |
|
99 | + function () { |
|
100 | + wp_localize_script( |
|
101 | + LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
|
102 | + 'EE_ACCOUNTING_CFG', |
|
103 | + $this->getAccountingSettings() |
|
104 | + ); |
|
105 | + } |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Returns configuration data for the accounting-js library. |
|
112 | + * |
|
113 | + * @return array |
|
114 | + * @since 5.0.0.p |
|
115 | + */ |
|
116 | + private function getAccountingSettings() |
|
117 | + { |
|
118 | + return [ |
|
119 | + 'currency' => [ |
|
120 | + 'symbol' => $this->currency_config->sign, |
|
121 | + 'format' => [ |
|
122 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
123 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
124 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
125 | + ], |
|
126 | + 'decimal' => $this->currency_config->dec_mrk, |
|
127 | + 'thousand' => $this->currency_config->thsnds, |
|
128 | + 'precision' => $this->currency_config->dec_plc, |
|
129 | + ], |
|
130 | + 'number' => [ |
|
131 | + 'precision' => $this->currency_config->dec_plc, |
|
132 | + 'thousand' => $this->currency_config->thsnds, |
|
133 | + 'decimal' => $this->currency_config->dec_mrk, |
|
134 | + ], |
|
135 | + ]; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * enqueue_scripts - Load the scripts and css |
|
141 | + * |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function enqueueLegacyAccountingAssets() |
|
145 | + { |
|
146 | + $this->enqueueAsset(LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING); |
|
147 | + } |
|
148 | 148 | } |
@@ -112,10 +112,10 @@ |
||
112 | 112 | ]; |
113 | 113 | $this->_wp_core_model = true; |
114 | 114 | $this->_caps_slug = 'users'; |
115 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
116 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
115 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
116 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
117 | 117 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
118 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
118 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
119 | 119 | } |
120 | 120 | // @todo: account for create_users controls whether they can create users at all |
121 | 121 | parent::__construct($timezone); |
@@ -12,132 +12,132 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_WP_User extends EEM_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * private instance of the EEM_WP_User object |
|
17 | - * |
|
18 | - * @type EEM_WP_User |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
15 | + /** |
|
16 | + * private instance of the EEM_WP_User object |
|
17 | + * |
|
18 | + * @type EEM_WP_User |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * constructor |
|
25 | - * |
|
26 | - * @param null $timezone |
|
27 | - * @param ModelFieldFactory $model_field_factory |
|
28 | - * @throws EE_Error |
|
29 | - * @throws InvalidArgumentException |
|
30 | - */ |
|
31 | - protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
32 | - { |
|
33 | - $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
34 | - $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
35 | - global $wpdb; |
|
36 | - $this->_tables = array( |
|
37 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
38 | - ); |
|
39 | - $this->_fields = array( |
|
40 | - 'WP_User' => array( |
|
41 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
42 | - 'ID', |
|
43 | - esc_html__('WP_User ID', 'event_espresso') |
|
44 | - ), |
|
45 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
46 | - 'user_login', |
|
47 | - esc_html__('User Login', 'event_espresso'), |
|
48 | - false |
|
49 | - ), |
|
50 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
51 | - 'user_pass', |
|
52 | - esc_html__('User Password', 'event_espresso'), |
|
53 | - false |
|
54 | - ), |
|
55 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
56 | - 'user_nicename', |
|
57 | - esc_html__(' User Nice Name', 'event_espresso'), |
|
58 | - false |
|
59 | - ), |
|
60 | - 'user_email' => $model_field_factory->createEmailField( |
|
61 | - 'user_email', |
|
62 | - esc_html__('User Email', 'event_espresso'), |
|
63 | - false |
|
64 | - ), |
|
65 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
66 | - 'user_registered', |
|
67 | - esc_html__('Date User Registered', 'event_espresso'), |
|
68 | - $timezone |
|
69 | - ), |
|
70 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
71 | - 'user_activation_key', |
|
72 | - esc_html__('User Activation Key', 'event_espresso'), |
|
73 | - false |
|
74 | - ), |
|
75 | - 'user_status' => $model_field_factory->createIntegerField( |
|
76 | - 'user_status', |
|
77 | - esc_html__('User Status', 'event_espresso') |
|
78 | - ), |
|
79 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
80 | - 'display_name', |
|
81 | - esc_html__('Display Name', 'event_espresso'), |
|
82 | - false |
|
83 | - ), |
|
84 | - ), |
|
85 | - ); |
|
86 | - $this->_model_relations = array( |
|
87 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
88 | - // all models are related to the change log |
|
89 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
90 | - 'Event' => new EE_Has_Many_Relation(), |
|
91 | - 'Message' => new EE_Has_Many_Relation(), |
|
92 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
93 | - 'Price' => new EE_Has_Many_Relation(), |
|
94 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
95 | - 'Question' => new EE_Has_Many_Relation(), |
|
96 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
97 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
98 | - 'Venue' => new EE_Has_Many_Relation(), |
|
99 | - ); |
|
100 | - $this->foreign_key_aliases = [ |
|
101 | - 'Event.EVT_wp_user' => 'WP_User.ID', |
|
102 | - 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
103 | - 'Price.PRC_wp_user' => 'WP_User.ID', |
|
104 | - 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
105 | - 'Question.QST_wp_user' => 'WP_User.ID', |
|
106 | - 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
107 | - 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
108 | - 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
109 | - ]; |
|
110 | - $this->_wp_core_model = true; |
|
111 | - $this->_caps_slug = 'users'; |
|
112 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
113 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
114 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
115 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
116 | - } |
|
117 | - // @todo: account for create_users controls whether they can create users at all |
|
118 | - parent::__construct($timezone); |
|
119 | - } |
|
23 | + /** |
|
24 | + * constructor |
|
25 | + * |
|
26 | + * @param null $timezone |
|
27 | + * @param ModelFieldFactory $model_field_factory |
|
28 | + * @throws EE_Error |
|
29 | + * @throws InvalidArgumentException |
|
30 | + */ |
|
31 | + protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
32 | + { |
|
33 | + $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
34 | + $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
35 | + global $wpdb; |
|
36 | + $this->_tables = array( |
|
37 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
38 | + ); |
|
39 | + $this->_fields = array( |
|
40 | + 'WP_User' => array( |
|
41 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
42 | + 'ID', |
|
43 | + esc_html__('WP_User ID', 'event_espresso') |
|
44 | + ), |
|
45 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
46 | + 'user_login', |
|
47 | + esc_html__('User Login', 'event_espresso'), |
|
48 | + false |
|
49 | + ), |
|
50 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
51 | + 'user_pass', |
|
52 | + esc_html__('User Password', 'event_espresso'), |
|
53 | + false |
|
54 | + ), |
|
55 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
56 | + 'user_nicename', |
|
57 | + esc_html__(' User Nice Name', 'event_espresso'), |
|
58 | + false |
|
59 | + ), |
|
60 | + 'user_email' => $model_field_factory->createEmailField( |
|
61 | + 'user_email', |
|
62 | + esc_html__('User Email', 'event_espresso'), |
|
63 | + false |
|
64 | + ), |
|
65 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
66 | + 'user_registered', |
|
67 | + esc_html__('Date User Registered', 'event_espresso'), |
|
68 | + $timezone |
|
69 | + ), |
|
70 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
71 | + 'user_activation_key', |
|
72 | + esc_html__('User Activation Key', 'event_espresso'), |
|
73 | + false |
|
74 | + ), |
|
75 | + 'user_status' => $model_field_factory->createIntegerField( |
|
76 | + 'user_status', |
|
77 | + esc_html__('User Status', 'event_espresso') |
|
78 | + ), |
|
79 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
80 | + 'display_name', |
|
81 | + esc_html__('Display Name', 'event_espresso'), |
|
82 | + false |
|
83 | + ), |
|
84 | + ), |
|
85 | + ); |
|
86 | + $this->_model_relations = array( |
|
87 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
88 | + // all models are related to the change log |
|
89 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
90 | + 'Event' => new EE_Has_Many_Relation(), |
|
91 | + 'Message' => new EE_Has_Many_Relation(), |
|
92 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
93 | + 'Price' => new EE_Has_Many_Relation(), |
|
94 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
95 | + 'Question' => new EE_Has_Many_Relation(), |
|
96 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
97 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
98 | + 'Venue' => new EE_Has_Many_Relation(), |
|
99 | + ); |
|
100 | + $this->foreign_key_aliases = [ |
|
101 | + 'Event.EVT_wp_user' => 'WP_User.ID', |
|
102 | + 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
103 | + 'Price.PRC_wp_user' => 'WP_User.ID', |
|
104 | + 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
105 | + 'Question.QST_wp_user' => 'WP_User.ID', |
|
106 | + 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
107 | + 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
108 | + 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
109 | + ]; |
|
110 | + $this->_wp_core_model = true; |
|
111 | + $this->_caps_slug = 'users'; |
|
112 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
113 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
114 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
115 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
116 | + } |
|
117 | + // @todo: account for create_users controls whether they can create users at all |
|
118 | + parent::__construct($timezone); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
124 | - * |
|
125 | - * @return string |
|
126 | - * @throws EE_Error |
|
127 | - */ |
|
128 | - public function wp_user_field_name() |
|
129 | - { |
|
130 | - return $this->primary_key_name(); |
|
131 | - } |
|
122 | + /** |
|
123 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
124 | + * |
|
125 | + * @return string |
|
126 | + * @throws EE_Error |
|
127 | + */ |
|
128 | + public function wp_user_field_name() |
|
129 | + { |
|
130 | + return $this->primary_key_name(); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
136 | - * |
|
137 | - * @return boolean |
|
138 | - */ |
|
139 | - public function is_owned() |
|
140 | - { |
|
141 | - return true; |
|
142 | - } |
|
134 | + /** |
|
135 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
136 | + * |
|
137 | + * @return boolean |
|
138 | + */ |
|
139 | + public function is_owned() |
|
140 | + { |
|
141 | + return true; |
|
142 | + } |
|
143 | 143 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function is_valid_scope($scope) |
171 | 171 | { |
172 | 172 | $scopes = $this->scopes(); |
173 | - if (isset($scopes[ $scope ])) { |
|
173 | + if (isset($scopes[$scope])) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | return false; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function get_all_active($scope = null, $query_params = []) |
189 | 189 | { |
190 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
191 | 191 | $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
192 | 192 | } |
193 | 193 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $count = 0; |
236 | 236 | foreach ($this->scopes() as $scope_name => $desc) { |
237 | 237 | $count++; |
238 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + $acceptable_scopes['PMD_scope*'.$count] = ['LIKE', '%'.$scope_name.'%']; |
|
239 | 239 | } |
240 | 240 | return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
241 | 241 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $usable_payment_methods = []; |
392 | 392 | foreach ($payment_methods as $key => $payment_method) { |
393 | 393 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
394 | + $usable_payment_methods[$key] = $payment_method; |
|
395 | 395 | // some payment methods enqueue their scripts in EE_PMT_*::__construct |
396 | 396 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
397 | 397 | // its scripts). but for backwards-compat we should continue to do that |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $payment_method |
406 | 406 | ); |
407 | 407 | new PersistentAdminNotice( |
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
408 | + 'auto-deactivated-'.$payment_method->type(), |
|
409 | 409 | sprintf( |
410 | 410 | esc_html__( |
411 | 411 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | ), |
414 | 414 | $payment_method->admin_name(), |
415 | 415 | '<br />', |
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
416 | + '<a href="'.admin_url('plugins.php').'">', |
|
417 | 417 | '</a>' |
418 | 418 | ), |
419 | 419 | true |
@@ -16,456 +16,456 @@ |
||
16 | 16 | */ |
17 | 17 | class EEM_Payment_Method extends EEM_Base |
18 | 18 | { |
19 | - const scope_cart = 'CART'; |
|
20 | - |
|
21 | - const scope_admin = 'ADMIN'; |
|
22 | - |
|
23 | - const scope_api = 'API'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @type EEM_Payment_Method |
|
27 | - */ |
|
28 | - protected static $_instance = null; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * private constructor to prevent direct creation |
|
33 | - * |
|
34 | - * @param null $timezone |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - protected function __construct($timezone = null) |
|
38 | - { |
|
39 | - $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | - $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | - $this->_tables = [ |
|
42 | - 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | - ]; |
|
44 | - $this->_fields = [ |
|
45 | - 'Payment_Method' => [ |
|
46 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | - 'PMD_ID', |
|
48 | - esc_html__('ID', 'event_espresso') |
|
49 | - ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | - 'PMD_type', |
|
52 | - esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | - false, |
|
54 | - 'Admin_Only' |
|
55 | - ), |
|
56 | - 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | - 'PMD_name', |
|
58 | - esc_html__('Name', 'event_espresso'), |
|
59 | - false |
|
60 | - ), |
|
61 | - 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | - 'PMD_desc', |
|
63 | - esc_html__('Description', 'event_espresso'), |
|
64 | - false, |
|
65 | - '' |
|
66 | - ), |
|
67 | - 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | - 'PMD_admin_name', |
|
69 | - esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | - true |
|
71 | - ), |
|
72 | - 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | - 'PMD_admin_desc', |
|
74 | - esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | - true |
|
76 | - ), |
|
77 | - 'PMD_slug' => new EE_Slug_Field( |
|
78 | - 'PMD_slug', |
|
79 | - esc_html__('Slug', 'event_espresso'), |
|
80 | - false |
|
81 | - ), |
|
82 | - 'PMD_order' => new EE_Integer_Field( |
|
83 | - 'PMD_order', |
|
84 | - esc_html__('Order', 'event_espresso'), |
|
85 | - false, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | - 'PMD_debug_mode', |
|
90 | - esc_html__('Sandbox Mode On? (AKA: debug mode)', 'event_espresso'), |
|
91 | - false, |
|
92 | - false |
|
93 | - ), |
|
94 | - 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | - 'PMD_wp_user', |
|
96 | - esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | - false |
|
98 | - ), |
|
99 | - 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | - 'PMD_open_by_default', |
|
101 | - esc_html__('Open by Default?', 'event_espresso'), |
|
102 | - false, |
|
103 | - false |
|
104 | - ), |
|
105 | - 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | - 'PMD_button_url', |
|
107 | - esc_html__('Button URL', 'event_espresso'), |
|
108 | - true, |
|
109 | - '' |
|
110 | - ), |
|
111 | - 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | - 'PMD_scope', |
|
113 | - esc_html__('Usable From?', 'event_espresso'), |
|
114 | - false, |
|
115 | - []// possible values currently are 'CART','ADMIN','API' |
|
116 | - ), |
|
117 | - ], |
|
118 | - ]; |
|
119 | - $this->_model_relations = [ |
|
120 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
121 | - 'Payment' => new EE_Has_Many_Relation(), |
|
122 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | - ]; |
|
125 | - parent::__construct($timezone); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets one by the slug provided |
|
131 | - * |
|
132 | - * @param string $slug |
|
133 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | - * @throws EE_Error |
|
135 | - */ |
|
136 | - public function get_one_by_slug($slug) |
|
137 | - { |
|
138 | - return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Gets all the acceptable scopes for payment methods. |
|
144 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | - * |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function scopes() |
|
149 | - { |
|
150 | - return apply_filters( |
|
151 | - 'FHEE__EEM_Payment_Method__scopes', |
|
152 | - [ |
|
153 | - EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | - EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | - 'Admin Registration Page (no online processing)', |
|
156 | - 'event_espresso' |
|
157 | - ), |
|
158 | - ] |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Determines if this is an valid scope |
|
165 | - * |
|
166 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | - * @return boolean |
|
168 | - */ |
|
169 | - public function is_valid_scope($scope) |
|
170 | - { |
|
171 | - $scopes = $this->scopes(); |
|
172 | - if (isset($scopes[ $scope ])) { |
|
173 | - return true; |
|
174 | - } |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Gets all active payment methods |
|
181 | - * |
|
182 | - * @param string $scope one of |
|
183 | - * @param array $query_params |
|
184 | - * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public function get_all_active($scope = null, $query_params = []) |
|
188 | - { |
|
189 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | - $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | - } |
|
192 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Counts all active gateways in the specified scope |
|
198 | - * |
|
199 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | - * @param array $query_params |
|
201 | - * @return int |
|
202 | - * @throws EE_Error |
|
203 | - */ |
|
204 | - public function count_active($scope = null, $query_params = []) |
|
205 | - { |
|
206 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | - * argument to get all active for a given scope |
|
213 | - * |
|
214 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | - * @param array $query_params |
|
216 | - * @return array |
|
217 | - * @throws EE_Error |
|
218 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | - */ |
|
220 | - protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | - { |
|
222 | - if ($scope) { |
|
223 | - if ($this->is_valid_scope($scope)) { |
|
224 | - return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | - } |
|
226 | - throw new EE_Error( |
|
227 | - sprintf( |
|
228 | - esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | - $scope |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $acceptable_scopes = []; |
|
234 | - $count = 0; |
|
235 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | - $count++; |
|
237 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | - } |
|
239 | - return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | - * argument to get all active for a given scope |
|
246 | - * |
|
247 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | - * @param array $query_params |
|
249 | - * @return array |
|
250 | - * @throws EE_Error |
|
251 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | - */ |
|
253 | - public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | - { |
|
255 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Gets one active payment method. see @get_all_active for documentation |
|
261 | - * |
|
262 | - * @param string $scope |
|
263 | - * @param array $query_params |
|
264 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | - * @throws EE_Error |
|
266 | - */ |
|
267 | - public function get_one_active($scope = null, $query_params = []) |
|
268 | - { |
|
269 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets one payment method of that type, regardless of whether its active or not |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function get_one_of_type($type) |
|
281 | - { |
|
282 | - return $this->get_one([['PMD_type' => $type]]); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Overrides parent ot also check by the slug |
|
288 | - * |
|
289 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | - * @param boolean $ensure_is_in_db |
|
291 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | - * @throws EE_Error |
|
293 | - * @see EEM_Base::ensure_is_obj() |
|
294 | - */ |
|
295 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | - { |
|
297 | - // first: check if it's a slug |
|
298 | - if (is_string($base_class_obj_or_id)) { |
|
299 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | - if ($obj) { |
|
301 | - return $obj; |
|
302 | - } |
|
303 | - } |
|
304 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | - try { |
|
306 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | - } catch (EE_Error $e) { |
|
308 | - // handle it outside the catch |
|
309 | - } |
|
310 | - throw new EE_Error( |
|
311 | - sprintf( |
|
312 | - esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | - $base_class_obj_or_id |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Gets the ID of this object, or if its a string finds the object's id |
|
321 | - * associated with that slug |
|
322 | - * |
|
323 | - * @param mixed $base_obj_or_id_or_slug |
|
324 | - * @return int |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | - { |
|
329 | - if (is_string($base_obj_or_id_or_slug)) { |
|
330 | - // assume it's a slug |
|
331 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | - } |
|
333 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | - * If not, resets them to their default. |
|
340 | - * |
|
341 | - * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | - * @throws EE_Error |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public function verify_button_urls($payment_methods = null) |
|
346 | - { |
|
347 | - $payment_methods = is_array($payment_methods) |
|
348 | - ? $payment_methods |
|
349 | - : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | - foreach ($payment_methods as $payment_method) { |
|
351 | - try { |
|
352 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | - // though this is a caffeinated install, reset it to the default. |
|
354 | - $current_button_url = $payment_method->button_url(); |
|
355 | - if ( |
|
356 | - empty($current_button_url) |
|
357 | - || ( |
|
358 | - strpos($current_button_url, 'decaf') !== false |
|
359 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | - ) |
|
361 | - ) { |
|
362 | - $payment_method->save( |
|
363 | - [ |
|
364 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | - ] |
|
366 | - ); |
|
367 | - } |
|
368 | - } catch (EE_Error $e) { |
|
369 | - $payment_method->deactivate(); |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | - * but also verifies the payment method type of each is a usable object. If not, |
|
378 | - * deactivate it, sets a notification, and deactivates it |
|
379 | - * |
|
380 | - * @param array $rows |
|
381 | - * @return EE_Payment_Method[] |
|
382 | - * @throws EE_Error |
|
383 | - * @throws InvalidDataTypeException |
|
384 | - * @throws ReflectionException |
|
385 | - */ |
|
386 | - protected function _create_objects($rows = []) |
|
387 | - { |
|
388 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | - $payment_methods = parent::_create_objects($rows); |
|
390 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | - $usable_payment_methods = []; |
|
392 | - foreach ($payment_methods as $key => $payment_method) { |
|
393 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
395 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | - // its scripts). but for backwards-compat we should continue to do that |
|
398 | - $payment_method->type_obj(); |
|
399 | - } elseif ($payment_method->active()) { |
|
400 | - // only deactivate and notify the admin if the payment is active somewhere |
|
401 | - $payment_method->deactivate(); |
|
402 | - $payment_method->save(); |
|
403 | - do_action( |
|
404 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | - $payment_method |
|
406 | - ); |
|
407 | - new PersistentAdminNotice( |
|
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
409 | - sprintf( |
|
410 | - esc_html__( |
|
411 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | - 'event_espresso' |
|
413 | - ), |
|
414 | - $payment_method->admin_name(), |
|
415 | - '<br />', |
|
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
417 | - '</a>' |
|
418 | - ), |
|
419 | - true |
|
420 | - ); |
|
421 | - } |
|
422 | - } |
|
423 | - return $usable_payment_methods; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Gets all the payment methods which can be used for transaction |
|
429 | - * (according to the relations between payment methods and events, and |
|
430 | - * the currencies used for the transaction and their relation to payment methods) |
|
431 | - * |
|
432 | - * @param EE_Transaction $transaction |
|
433 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | - * @return EE_Payment_Method[] |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - public function get_all_for_transaction($transaction, $scope) |
|
438 | - { |
|
439 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | - return apply_filters( |
|
441 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | - $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | - $transaction, |
|
444 | - $scope |
|
445 | - ); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns the payment method used for the last payment made for a registration. |
|
451 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | - * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | - * |
|
454 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | - * registration. |
|
456 | - * @return EE_Payment|null |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | - { |
|
461 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | - |
|
463 | - $query_params = [ |
|
464 | - 0 => [ |
|
465 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | - ], |
|
467 | - 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | - ]; |
|
469 | - return $this->get_one($query_params); |
|
470 | - } |
|
19 | + const scope_cart = 'CART'; |
|
20 | + |
|
21 | + const scope_admin = 'ADMIN'; |
|
22 | + |
|
23 | + const scope_api = 'API'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @type EEM_Payment_Method |
|
27 | + */ |
|
28 | + protected static $_instance = null; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * private constructor to prevent direct creation |
|
33 | + * |
|
34 | + * @param null $timezone |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + protected function __construct($timezone = null) |
|
38 | + { |
|
39 | + $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | + $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | + $this->_tables = [ |
|
42 | + 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | + ]; |
|
44 | + $this->_fields = [ |
|
45 | + 'Payment_Method' => [ |
|
46 | + 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | + 'PMD_ID', |
|
48 | + esc_html__('ID', 'event_espresso') |
|
49 | + ), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | + 'PMD_type', |
|
52 | + esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | + false, |
|
54 | + 'Admin_Only' |
|
55 | + ), |
|
56 | + 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | + 'PMD_name', |
|
58 | + esc_html__('Name', 'event_espresso'), |
|
59 | + false |
|
60 | + ), |
|
61 | + 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | + 'PMD_desc', |
|
63 | + esc_html__('Description', 'event_espresso'), |
|
64 | + false, |
|
65 | + '' |
|
66 | + ), |
|
67 | + 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | + 'PMD_admin_name', |
|
69 | + esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | + true |
|
71 | + ), |
|
72 | + 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | + 'PMD_admin_desc', |
|
74 | + esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | + true |
|
76 | + ), |
|
77 | + 'PMD_slug' => new EE_Slug_Field( |
|
78 | + 'PMD_slug', |
|
79 | + esc_html__('Slug', 'event_espresso'), |
|
80 | + false |
|
81 | + ), |
|
82 | + 'PMD_order' => new EE_Integer_Field( |
|
83 | + 'PMD_order', |
|
84 | + esc_html__('Order', 'event_espresso'), |
|
85 | + false, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | + 'PMD_debug_mode', |
|
90 | + esc_html__('Sandbox Mode On? (AKA: debug mode)', 'event_espresso'), |
|
91 | + false, |
|
92 | + false |
|
93 | + ), |
|
94 | + 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | + 'PMD_wp_user', |
|
96 | + esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | + false |
|
98 | + ), |
|
99 | + 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | + 'PMD_open_by_default', |
|
101 | + esc_html__('Open by Default?', 'event_espresso'), |
|
102 | + false, |
|
103 | + false |
|
104 | + ), |
|
105 | + 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | + 'PMD_button_url', |
|
107 | + esc_html__('Button URL', 'event_espresso'), |
|
108 | + true, |
|
109 | + '' |
|
110 | + ), |
|
111 | + 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | + 'PMD_scope', |
|
113 | + esc_html__('Usable From?', 'event_espresso'), |
|
114 | + false, |
|
115 | + []// possible values currently are 'CART','ADMIN','API' |
|
116 | + ), |
|
117 | + ], |
|
118 | + ]; |
|
119 | + $this->_model_relations = [ |
|
120 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
121 | + 'Payment' => new EE_Has_Many_Relation(), |
|
122 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | + ]; |
|
125 | + parent::__construct($timezone); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets one by the slug provided |
|
131 | + * |
|
132 | + * @param string $slug |
|
133 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | + * @throws EE_Error |
|
135 | + */ |
|
136 | + public function get_one_by_slug($slug) |
|
137 | + { |
|
138 | + return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Gets all the acceptable scopes for payment methods. |
|
144 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | + * |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function scopes() |
|
149 | + { |
|
150 | + return apply_filters( |
|
151 | + 'FHEE__EEM_Payment_Method__scopes', |
|
152 | + [ |
|
153 | + EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | + EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | + 'Admin Registration Page (no online processing)', |
|
156 | + 'event_espresso' |
|
157 | + ), |
|
158 | + ] |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Determines if this is an valid scope |
|
165 | + * |
|
166 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | + * @return boolean |
|
168 | + */ |
|
169 | + public function is_valid_scope($scope) |
|
170 | + { |
|
171 | + $scopes = $this->scopes(); |
|
172 | + if (isset($scopes[ $scope ])) { |
|
173 | + return true; |
|
174 | + } |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Gets all active payment methods |
|
181 | + * |
|
182 | + * @param string $scope one of |
|
183 | + * @param array $query_params |
|
184 | + * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public function get_all_active($scope = null, $query_params = []) |
|
188 | + { |
|
189 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | + } |
|
192 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Counts all active gateways in the specified scope |
|
198 | + * |
|
199 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | + * @param array $query_params |
|
201 | + * @return int |
|
202 | + * @throws EE_Error |
|
203 | + */ |
|
204 | + public function count_active($scope = null, $query_params = []) |
|
205 | + { |
|
206 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | + * argument to get all active for a given scope |
|
213 | + * |
|
214 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | + * @param array $query_params |
|
216 | + * @return array |
|
217 | + * @throws EE_Error |
|
218 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | + */ |
|
220 | + protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | + { |
|
222 | + if ($scope) { |
|
223 | + if ($this->is_valid_scope($scope)) { |
|
224 | + return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | + } |
|
226 | + throw new EE_Error( |
|
227 | + sprintf( |
|
228 | + esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | + $scope |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $acceptable_scopes = []; |
|
234 | + $count = 0; |
|
235 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | + $count++; |
|
237 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + } |
|
239 | + return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | + * argument to get all active for a given scope |
|
246 | + * |
|
247 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | + * @param array $query_params |
|
249 | + * @return array |
|
250 | + * @throws EE_Error |
|
251 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | + */ |
|
253 | + public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | + { |
|
255 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Gets one active payment method. see @get_all_active for documentation |
|
261 | + * |
|
262 | + * @param string $scope |
|
263 | + * @param array $query_params |
|
264 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | + * @throws EE_Error |
|
266 | + */ |
|
267 | + public function get_one_active($scope = null, $query_params = []) |
|
268 | + { |
|
269 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets one payment method of that type, regardless of whether its active or not |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function get_one_of_type($type) |
|
281 | + { |
|
282 | + return $this->get_one([['PMD_type' => $type]]); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Overrides parent ot also check by the slug |
|
288 | + * |
|
289 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | + * @param boolean $ensure_is_in_db |
|
291 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | + * @throws EE_Error |
|
293 | + * @see EEM_Base::ensure_is_obj() |
|
294 | + */ |
|
295 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | + { |
|
297 | + // first: check if it's a slug |
|
298 | + if (is_string($base_class_obj_or_id)) { |
|
299 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | + if ($obj) { |
|
301 | + return $obj; |
|
302 | + } |
|
303 | + } |
|
304 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | + try { |
|
306 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | + } catch (EE_Error $e) { |
|
308 | + // handle it outside the catch |
|
309 | + } |
|
310 | + throw new EE_Error( |
|
311 | + sprintf( |
|
312 | + esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | + $base_class_obj_or_id |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Gets the ID of this object, or if its a string finds the object's id |
|
321 | + * associated with that slug |
|
322 | + * |
|
323 | + * @param mixed $base_obj_or_id_or_slug |
|
324 | + * @return int |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | + { |
|
329 | + if (is_string($base_obj_or_id_or_slug)) { |
|
330 | + // assume it's a slug |
|
331 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | + } |
|
333 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | + * If not, resets them to their default. |
|
340 | + * |
|
341 | + * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | + * @throws EE_Error |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public function verify_button_urls($payment_methods = null) |
|
346 | + { |
|
347 | + $payment_methods = is_array($payment_methods) |
|
348 | + ? $payment_methods |
|
349 | + : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | + foreach ($payment_methods as $payment_method) { |
|
351 | + try { |
|
352 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | + // though this is a caffeinated install, reset it to the default. |
|
354 | + $current_button_url = $payment_method->button_url(); |
|
355 | + if ( |
|
356 | + empty($current_button_url) |
|
357 | + || ( |
|
358 | + strpos($current_button_url, 'decaf') !== false |
|
359 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | + ) |
|
361 | + ) { |
|
362 | + $payment_method->save( |
|
363 | + [ |
|
364 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | + ] |
|
366 | + ); |
|
367 | + } |
|
368 | + } catch (EE_Error $e) { |
|
369 | + $payment_method->deactivate(); |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | + * but also verifies the payment method type of each is a usable object. If not, |
|
378 | + * deactivate it, sets a notification, and deactivates it |
|
379 | + * |
|
380 | + * @param array $rows |
|
381 | + * @return EE_Payment_Method[] |
|
382 | + * @throws EE_Error |
|
383 | + * @throws InvalidDataTypeException |
|
384 | + * @throws ReflectionException |
|
385 | + */ |
|
386 | + protected function _create_objects($rows = []) |
|
387 | + { |
|
388 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | + $payment_methods = parent::_create_objects($rows); |
|
390 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | + $usable_payment_methods = []; |
|
392 | + foreach ($payment_methods as $key => $payment_method) { |
|
393 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | + $usable_payment_methods[ $key ] = $payment_method; |
|
395 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | + // its scripts). but for backwards-compat we should continue to do that |
|
398 | + $payment_method->type_obj(); |
|
399 | + } elseif ($payment_method->active()) { |
|
400 | + // only deactivate and notify the admin if the payment is active somewhere |
|
401 | + $payment_method->deactivate(); |
|
402 | + $payment_method->save(); |
|
403 | + do_action( |
|
404 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | + $payment_method |
|
406 | + ); |
|
407 | + new PersistentAdminNotice( |
|
408 | + 'auto-deactivated-' . $payment_method->type(), |
|
409 | + sprintf( |
|
410 | + esc_html__( |
|
411 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | + 'event_espresso' |
|
413 | + ), |
|
414 | + $payment_method->admin_name(), |
|
415 | + '<br />', |
|
416 | + '<a href="' . admin_url('plugins.php') . '">', |
|
417 | + '</a>' |
|
418 | + ), |
|
419 | + true |
|
420 | + ); |
|
421 | + } |
|
422 | + } |
|
423 | + return $usable_payment_methods; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Gets all the payment methods which can be used for transaction |
|
429 | + * (according to the relations between payment methods and events, and |
|
430 | + * the currencies used for the transaction and their relation to payment methods) |
|
431 | + * |
|
432 | + * @param EE_Transaction $transaction |
|
433 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | + * @return EE_Payment_Method[] |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + public function get_all_for_transaction($transaction, $scope) |
|
438 | + { |
|
439 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | + return apply_filters( |
|
441 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | + $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | + $transaction, |
|
444 | + $scope |
|
445 | + ); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns the payment method used for the last payment made for a registration. |
|
451 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | + * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | + * |
|
454 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | + * registration. |
|
456 | + * @return EE_Payment|null |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | + { |
|
461 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | + |
|
463 | + $query_params = [ |
|
464 | + 0 => [ |
|
465 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | + ], |
|
467 | + 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | + ]; |
|
469 | + return $this->get_one($query_params); |
|
470 | + } |
|
471 | 471 | } |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
58 | 58 | ]; |
59 | 59 | $path_to_event = 'Event'; |
60 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
61 | 61 | $path_to_event |
62 | 62 | ); |
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
64 | 64 | $path_to_event |
65 | 65 | ); |
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
67 | 67 | $path_to_event |
68 | 68 | ); |
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
70 | 70 | $path_to_event, |
71 | 71 | EEM_Base::caps_edit |
72 | 72 | ); |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | $where = []; |
118 | - if (! empty($GRP_IDs)) { |
|
118 | + if ( ! empty($GRP_IDs)) { |
|
119 | 119 | $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
120 | 120 | } |
121 | - if (! empty($EVT_IDs)) { |
|
121 | + if ( ! empty($EVT_IDs)) { |
|
122 | 122 | $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
123 | 123 | } |
124 | 124 |
@@ -11,134 +11,134 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Event_Message_Template extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Event_Message_Template object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Event_Message_Template object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * protected constructor to prevent direct creation |
|
20 | - * |
|
21 | - * @param null $timezone |
|
22 | - * @throws EE_Error |
|
23 | - */ |
|
24 | - protected function __construct($timezone = null) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
18 | + /** |
|
19 | + * protected constructor to prevent direct creation |
|
20 | + * |
|
21 | + * @param null $timezone |
|
22 | + * @throws EE_Error |
|
23 | + */ |
|
24 | + protected function __construct($timezone = null) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = [ |
|
30 | - 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
31 | - ]; |
|
32 | - $this->_fields = [ |
|
33 | - 'Event_Message_Template' => [ |
|
34 | - 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
35 | - 'EMT_ID', |
|
36 | - esc_html__('Event Message Template ID', 'event_espresso') |
|
37 | - ), |
|
38 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
39 | - 'EVT_ID', |
|
40 | - esc_html__('The ID to the Event', 'event_espresso'), |
|
41 | - false, |
|
42 | - 0, |
|
43 | - 'Event' |
|
44 | - ), |
|
45 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'GRP_ID', |
|
47 | - esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
48 | - false, |
|
49 | - 0, |
|
50 | - 'Message_Template_Group' |
|
51 | - ), |
|
52 | - ], |
|
53 | - ]; |
|
54 | - $this->_model_relations = [ |
|
55 | - 'Event' => new EE_Belongs_To_Relation(), |
|
56 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
57 | - ]; |
|
58 | - $path_to_event = 'Event'; |
|
59 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | - $path_to_event |
|
61 | - ); |
|
62 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | - $path_to_event |
|
64 | - ); |
|
65 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | - $path_to_event |
|
67 | - ); |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | - $path_to_event, |
|
70 | - EEM_Base::caps_edit |
|
71 | - ); |
|
72 | - parent::__construct($timezone); |
|
73 | - } |
|
29 | + $this->_tables = [ |
|
30 | + 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
31 | + ]; |
|
32 | + $this->_fields = [ |
|
33 | + 'Event_Message_Template' => [ |
|
34 | + 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
35 | + 'EMT_ID', |
|
36 | + esc_html__('Event Message Template ID', 'event_espresso') |
|
37 | + ), |
|
38 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
39 | + 'EVT_ID', |
|
40 | + esc_html__('The ID to the Event', 'event_espresso'), |
|
41 | + false, |
|
42 | + 0, |
|
43 | + 'Event' |
|
44 | + ), |
|
45 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'GRP_ID', |
|
47 | + esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
48 | + false, |
|
49 | + 0, |
|
50 | + 'Message_Template_Group' |
|
51 | + ), |
|
52 | + ], |
|
53 | + ]; |
|
54 | + $this->_model_relations = [ |
|
55 | + 'Event' => new EE_Belongs_To_Relation(), |
|
56 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
57 | + ]; |
|
58 | + $path_to_event = 'Event'; |
|
59 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | + $path_to_event |
|
61 | + ); |
|
62 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | + $path_to_event |
|
64 | + ); |
|
65 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | + $path_to_event |
|
67 | + ); |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | + $path_to_event, |
|
70 | + EEM_Base::caps_edit |
|
71 | + ); |
|
72 | + parent::__construct($timezone); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * helper method to simply return an array of event ids for events attached to the given |
|
78 | - * message template group. |
|
79 | - * |
|
80 | - * @param int $GRP_ID The MTP group we want attached events for. |
|
81 | - * @return array An array of event ids. |
|
82 | - * @throws EE_Error |
|
83 | - * @since 4.3.0 |
|
84 | - */ |
|
85 | - public function get_attached_event_ids($GRP_ID) |
|
86 | - { |
|
87 | - $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
88 | - $event_ids = call_user_func_array('array_merge', $event_ids); |
|
89 | - return $event_ids; |
|
90 | - } |
|
76 | + /** |
|
77 | + * helper method to simply return an array of event ids for events attached to the given |
|
78 | + * message template group. |
|
79 | + * |
|
80 | + * @param int $GRP_ID The MTP group we want attached events for. |
|
81 | + * @return array An array of event ids. |
|
82 | + * @throws EE_Error |
|
83 | + * @since 4.3.0 |
|
84 | + */ |
|
85 | + public function get_attached_event_ids($GRP_ID) |
|
86 | + { |
|
87 | + $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
88 | + $event_ids = call_user_func_array('array_merge', $event_ids); |
|
89 | + return $event_ids; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * helper method for clearing event/group relations for the given event ids and grp ids. |
|
95 | - * |
|
96 | - * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
97 | - * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
98 | - * @return int How many rows were deleted. |
|
99 | - * @throws EE_Error |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
103 | - { |
|
104 | - if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
105 | - throw new EE_Error( |
|
106 | - sprintf( |
|
107 | - esc_html__( |
|
108 | - '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - __METHOD__ |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
93 | + /** |
|
94 | + * helper method for clearing event/group relations for the given event ids and grp ids. |
|
95 | + * |
|
96 | + * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
97 | + * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
98 | + * @return int How many rows were deleted. |
|
99 | + * @throws EE_Error |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
103 | + { |
|
104 | + if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
105 | + throw new EE_Error( |
|
106 | + sprintf( |
|
107 | + esc_html__( |
|
108 | + '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + __METHOD__ |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | 115 | |
116 | - $where = []; |
|
117 | - if (! empty($GRP_IDs)) { |
|
118 | - $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
119 | - } |
|
120 | - if (! empty($EVT_IDs)) { |
|
121 | - $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
122 | - } |
|
116 | + $where = []; |
|
117 | + if (! empty($GRP_IDs)) { |
|
118 | + $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
119 | + } |
|
120 | + if (! empty($EVT_IDs)) { |
|
121 | + $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
122 | + } |
|
123 | 123 | |
124 | - return $this->delete([$where], false); |
|
125 | - } |
|
124 | + return $this->delete([$where], false); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * returns a numerically indexed array |
|
130 | - * with values that correspond to the 'GRP_ID' column |
|
131 | - * where the 'EVT_ID' column matches that of the supplied event |
|
132 | - * |
|
133 | - * @param EE_Event $event |
|
134 | - * @return array |
|
135 | - * @throws EE_Error |
|
136 | - * @throws ReflectionException |
|
137 | - * @since 5.0.0.p |
|
138 | - */ |
|
139 | - public function messageTemplateGroupIDsForEvent(EE_Event $event): array |
|
140 | - { |
|
141 | - $results = $this->get_col([['EVT_ID' => $event->ID()]], 'GRP_ID'); |
|
142 | - return $results !== false ? $results : []; |
|
143 | - } |
|
128 | + /** |
|
129 | + * returns a numerically indexed array |
|
130 | + * with values that correspond to the 'GRP_ID' column |
|
131 | + * where the 'EVT_ID' column matches that of the supplied event |
|
132 | + * |
|
133 | + * @param EE_Event $event |
|
134 | + * @return array |
|
135 | + * @throws EE_Error |
|
136 | + * @throws ReflectionException |
|
137 | + * @since 5.0.0.p |
|
138 | + */ |
|
139 | + public function messageTemplateGroupIDsForEvent(EE_Event $event): array |
|
140 | + { |
|
141 | + $results = $this->get_col([['EVT_ID' => $event->ID()]], 'GRP_ID'); |
|
142 | + return $results !== false ? $results : []; |
|
143 | + } |
|
144 | 144 | } |
@@ -16,39 +16,39 @@ |
||
16 | 16 | */ |
17 | 17 | class JsonWpOptionManager |
18 | 18 | { |
19 | - /** |
|
20 | - * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
21 | - * the object alone and returns false. |
|
22 | - * @since 4.9.80.p |
|
23 | - * @param JsonWpOptionSerializableInterface $obj |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
27 | - { |
|
28 | - $option = get_option($obj->getWpOptionName()); |
|
29 | - if ($option) { |
|
30 | - $json = json_decode($option, false); |
|
31 | - if ($json instanceof stdClass) { |
|
32 | - return $obj->fromJsonSerializedData($json); |
|
33 | - } |
|
34 | - } |
|
35 | - return false; |
|
36 | - } |
|
19 | + /** |
|
20 | + * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
21 | + * the object alone and returns false. |
|
22 | + * @since 4.9.80.p |
|
23 | + * @param JsonWpOptionSerializableInterface $obj |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
27 | + { |
|
28 | + $option = get_option($obj->getWpOptionName()); |
|
29 | + if ($option) { |
|
30 | + $json = json_decode($option, false); |
|
31 | + if ($json instanceof stdClass) { |
|
32 | + return $obj->fromJsonSerializedData($json); |
|
33 | + } |
|
34 | + } |
|
35 | + return false; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Saves the object's data to the wp_options table for later use. |
|
40 | - * @since 4.9.80.p |
|
41 | - * @param JsonWpOptionSerializableInterface $obj |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
45 | - { |
|
46 | - return update_option( |
|
47 | - $obj->getWpOptionName(), |
|
48 | - wp_json_encode($obj->toJsonSerializableData()), |
|
49 | - false |
|
50 | - ); |
|
51 | - } |
|
38 | + /** |
|
39 | + * Saves the object's data to the wp_options table for later use. |
|
40 | + * @since 4.9.80.p |
|
41 | + * @param JsonWpOptionSerializableInterface $obj |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
45 | + { |
|
46 | + return update_option( |
|
47 | + $obj->getWpOptionName(), |
|
48 | + wp_json_encode($obj->toJsonSerializableData()), |
|
49 | + false |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | // End of file JsonWpOptionManager.php |
54 | 54 | // Location: EventEspresso\core\services\options/JsonWpOptionManager.php |