Completed
Branch master (d65695)
by
unknown
04:25
created
domain/entities/routing/specifications/admin/EspressoVenueEditorEdit.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -14,18 +14,18 @@
 block discarded – undo
14 14
  */
15 15
 class EspressoVenueEditorEdit 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_venues'
29
-               && $this->request->getRequestParam('action') === 'edit';
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_venues'
29
+			   && $this->request->getRequestParam('action') === 'edit';
30
+	}
31 31
 }
Please login to merge, or discard this patch.
domain/entities/routing/specifications/admin/WordPressPostTypeEditor.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,15 +15,15 @@
 block discarded – undo
15 15
  */
16 16
 class WordPressPostTypeEditor 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 && ($pagenow === 'post.php' || $pagenow === 'post-new.php');
28
-    }
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 && ($pagenow === 'post.php' || $pagenow === 'post-new.php');
28
+	}
29 29
 }
Please login to merge, or discard this patch.
domain/entities/routing/specifications/admin/WordPressPageEditorAddNew.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
entities/routing/specifications/admin/EspressoAttendeePostTypeEditor.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -14,18 +14,18 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
domain/entities/routing/specifications/admin/WordPressPostsEditorAddNew.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
domain/entities/routing/specifications/admin/WordPressPageEditorEdit.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,18 +16,18 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/domain/services/assets/LegacyAccountingAssetManager.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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',
Please login to merge, or discard this patch.
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -24,125 +24,125 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/db_models/EEM_WP_User.model.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -112,10 +112,10 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -12,132 +12,132 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Payment_Method.model.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +451 added lines, -451 removed lines patch added patch discarded remove patch
@@ -16,455 +16,455 @@
 block discarded – undo
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
-            'Payment'     => new EE_Has_Many_Relation(),
121
-            'Transaction' => new EE_Has_Many_Relation(),
122
-            'WP_User'     => new EE_Belongs_To_Relation(),
123
-        ];
124
-        parent::__construct($timezone);
125
-    }
126
-
127
-
128
-    /**
129
-     * Gets one by the slug provided
130
-     *
131
-     * @param string $slug
132
-     * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
133
-     * @throws EE_Error
134
-     */
135
-    public function get_one_by_slug($slug)
136
-    {
137
-        return $this->get_one([['PMD_slug' => $slug]]);
138
-    }
139
-
140
-
141
-    /**
142
-     * Gets all the acceptable scopes for payment methods.
143
-     * Keys are their names as store din the DB, and values are nice names for displaying them
144
-     *
145
-     * @return array
146
-     */
147
-    public function scopes()
148
-    {
149
-        return apply_filters(
150
-            'FHEE__EEM_Payment_Method__scopes',
151
-            [
152
-                EEM_Payment_Method::scope_cart  => esc_html__('Front-end Registration Page', 'event_espresso'),
153
-                EEM_Payment_Method::scope_admin => esc_html__(
154
-                    'Admin Registration Page (no online processing)',
155
-                    'event_espresso'
156
-                ),
157
-            ]
158
-        );
159
-    }
160
-
161
-
162
-    /**
163
-     * Determines if this is an valid scope
164
-     *
165
-     * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
166
-     * @return boolean
167
-     */
168
-    public function is_valid_scope($scope)
169
-    {
170
-        $scopes = $this->scopes();
171
-        if (isset($scopes[ $scope ])) {
172
-            return true;
173
-        }
174
-        return false;
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets all active payment methods
180
-     *
181
-     * @param string $scope one of
182
-     * @param array  $query_params
183
-     * @return EE_Base_Class[]|EE_Payment_Method[]
184
-     * @throws EE_Error
185
-     */
186
-    public function get_all_active($scope = null, $query_params = [])
187
-    {
188
-        if (! isset($query_params['order_by']) && ! isset($query_params['order'])) {
189
-            $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC'];
190
-        }
191
-        return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
192
-    }
193
-
194
-
195
-    /**
196
-     * Counts all active gateways in the specified scope
197
-     *
198
-     * @param string $scope one of EEM_Payment_Method::scope_*
199
-     * @param array  $query_params
200
-     * @return int
201
-     * @throws EE_Error
202
-     */
203
-    public function count_active($scope = null, $query_params = [])
204
-    {
205
-        return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
206
-    }
207
-
208
-
209
-    /**
210
-     * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
211
-     * argument to get all active for a given scope
212
-     *
213
-     * @param string $scope one of the constants EEM_Payment_Method::scope_*
214
-     * @param array  $query_params
215
-     * @return array
216
-     * @throws EE_Error
217
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
-     */
219
-    protected function _get_query_params_for_all_active($scope = null, $query_params = [])
220
-    {
221
-        if ($scope) {
222
-            if ($this->is_valid_scope($scope)) {
223
-                return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params);
224
-            }
225
-            throw new EE_Error(
226
-                sprintf(
227
-                    esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'),
228
-                    $scope
229
-                )
230
-            );
231
-        }
232
-        $acceptable_scopes = [];
233
-        $count = 0;
234
-        foreach ($this->scopes() as $scope_name => $desc) {
235
-            $count++;
236
-            $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%'];
237
-        }
238
-        return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params);
239
-    }
240
-
241
-
242
-    /**
243
-     * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
244
-     * argument to get all active for a given scope
245
-     *
246
-     * @param string $scope one of the constants EEM_Payment_Method::scope_*
247
-     * @param array  $query_params
248
-     * @return array
249
-     * @throws EE_Error
250
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
251
-     */
252
-    public function get_query_params_for_all_active($scope = null, $query_params = [])
253
-    {
254
-        return $this->_get_query_params_for_all_active($scope, $query_params);
255
-    }
256
-
257
-
258
-    /**
259
-     * Gets one active payment method. see @get_all_active for documentation
260
-     *
261
-     * @param string $scope
262
-     * @param array  $query_params
263
-     * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
264
-     * @throws EE_Error
265
-     */
266
-    public function get_one_active($scope = null, $query_params = [])
267
-    {
268
-        return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
269
-    }
270
-
271
-
272
-    /**
273
-     * Gets one payment method of that type, regardless of whether its active or not
274
-     *
275
-     * @param string $type
276
-     * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
277
-     * @throws EE_Error
278
-     */
279
-    public function get_one_of_type($type)
280
-    {
281
-        return $this->get_one([['PMD_type' => $type]]);
282
-    }
283
-
284
-
285
-    /**
286
-     * Overrides parent ot also check by the slug
287
-     *
288
-     * @param string|int|EE_Payment_Method $base_class_obj_or_id
289
-     * @param boolean                      $ensure_is_in_db
290
-     * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string
291
-     * @throws EE_Error
292
-     * @see EEM_Base::ensure_is_obj()
293
-     */
294
-    public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)
295
-    {
296
-        // first: check if it's a slug
297
-        if (is_string($base_class_obj_or_id)) {
298
-            $obj = $this->get_one_by_slug($base_class_obj_or_id);
299
-            if ($obj) {
300
-                return $obj;
301
-            }
302
-        }
303
-        // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
304
-        try {
305
-            return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
306
-        } catch (EE_Error $e) {
307
-            // handle it outside the catch
308
-        }
309
-        throw new EE_Error(
310
-            sprintf(
311
-                esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'),
312
-                $base_class_obj_or_id
313
-            )
314
-        );
315
-    }
316
-
317
-
318
-    /**
319
-     * Gets the ID of this object, or if its a string finds the object's id
320
-     * associated with that slug
321
-     *
322
-     * @param mixed $base_obj_or_id_or_slug
323
-     * @return int
324
-     * @throws EE_Error
325
-     */
326
-    public function ensure_is_ID($base_obj_or_id_or_slug)
327
-    {
328
-        if (is_string($base_obj_or_id_or_slug)) {
329
-            // assume it's a slug
330
-            $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
331
-        }
332
-        return parent::ensure_is_ID($base_obj_or_id_or_slug);
333
-    }
334
-
335
-
336
-    /**
337
-     * Verifies the button urls on all the passed payment methods have a valid button url.
338
-     * If not, resets them to their default.
339
-     *
340
-     * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart
341
-     * @throws EE_Error
342
-     * @throws ReflectionException
343
-     */
344
-    public function verify_button_urls($payment_methods = null)
345
-    {
346
-        $payment_methods = is_array($payment_methods)
347
-            ? $payment_methods
348
-            : $this->get_all_active(EEM_Payment_Method::scope_cart);
349
-        foreach ($payment_methods as $payment_method) {
350
-            try {
351
-                // If there is really no button URL at all, or if the button URLs still point to decaf folder even
352
-                // though this is a caffeinated install, reset it to the default.
353
-                $current_button_url = $payment_method->button_url();
354
-                if (
355
-                    empty($current_button_url)
356
-                    || (
357
-                        strpos($current_button_url, 'decaf') !== false
358
-                        && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false
359
-                    )
360
-                ) {
361
-                    $payment_method->save(
362
-                        [
363
-                            'PMD_button_url' => $payment_method->type_obj()->default_button_url(),
364
-                        ]
365
-                    );
366
-                }
367
-            } catch (EE_Error $e) {
368
-                $payment_method->deactivate();
369
-            }
370
-        }
371
-    }
372
-
373
-
374
-    /**
375
-     * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
376
-     * but also verifies the payment method type of each is a usable object. If not,
377
-     * deactivate it, sets a notification, and deactivates it
378
-     *
379
-     * @param array $rows
380
-     * @return EE_Payment_Method[]
381
-     * @throws EE_Error
382
-     * @throws InvalidDataTypeException
383
-     * @throws ReflectionException
384
-     */
385
-    protected function _create_objects($rows = [])
386
-    {
387
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
388
-        $payment_methods = parent::_create_objects($rows);
389
-        /* @var $payment_methods EE_Payment_Method[] */
390
-        $usable_payment_methods = [];
391
-        foreach ($payment_methods as $key => $payment_method) {
392
-            if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
393
-                $usable_payment_methods[ $key ] = $payment_method;
394
-                // some payment methods enqueue their scripts in EE_PMT_*::__construct
395
-                // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
396
-                // its scripts). but for backwards-compat we should continue to do that
397
-                $payment_method->type_obj();
398
-            } elseif ($payment_method->active()) {
399
-                // only deactivate and notify the admin if the payment is active somewhere
400
-                $payment_method->deactivate();
401
-                $payment_method->save();
402
-                do_action(
403
-                    'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',
404
-                    $payment_method
405
-                );
406
-                new PersistentAdminNotice(
407
-                    'auto-deactivated-' . $payment_method->type(),
408
-                    sprintf(
409
-                        esc_html__(
410
-                            '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.',
411
-                            'event_espresso'
412
-                        ),
413
-                        $payment_method->admin_name(),
414
-                        '<br />',
415
-                        '<a href="' . admin_url('plugins.php') . '">',
416
-                        '</a>'
417
-                    ),
418
-                    true
419
-                );
420
-            }
421
-        }
422
-        return $usable_payment_methods;
423
-    }
424
-
425
-
426
-    /**
427
-     * Gets all the payment methods which can be used for transaction
428
-     * (according to the relations between payment methods and events, and
429
-     * the currencies used for the transaction and their relation to payment methods)
430
-     *
431
-     * @param EE_Transaction $transaction
432
-     * @param string         $scope @see EEM_Payment_Method::get_all_for_events
433
-     * @return EE_Payment_Method[]
434
-     * @throws EE_Error
435
-     */
436
-    public function get_all_for_transaction($transaction, $scope)
437
-    {
438
-        // give addons a chance to override what payment methods are chosen based on the transaction
439
-        return apply_filters(
440
-            'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
441
-            $this->get_all_active($scope, ['group_by' => 'PMD_type']),
442
-            $transaction,
443
-            $scope
444
-        );
445
-    }
446
-
447
-
448
-    /**
449
-     * Returns the payment method used for the last payment made for a registration.
450
-     * Note: if an offline payment method was selected on the related transaction then this will have no payment
451
-     * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration.
452
-     *
453
-     * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the
454
-     *                                                    registration.
455
-     * @return EE_Payment|null
456
-     * @throws EE_Error
457
-     */
458
-    public function get_last_used_for_registration($registration_or_reg_id)
459
-    {
460
-        $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
461
-
462
-        $query_params = [
463
-            0          => [
464
-                'Payment.Registration.REG_ID' => $registration_id,
465
-            ],
466
-            'order_by' => ['Payment.PAY_ID' => 'DESC'],
467
-        ];
468
-        return $this->get_one($query_params);
469
-    }
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
+			'Payment'     => new EE_Has_Many_Relation(),
121
+			'Transaction' => new EE_Has_Many_Relation(),
122
+			'WP_User'     => new EE_Belongs_To_Relation(),
123
+		];
124
+		parent::__construct($timezone);
125
+	}
126
+
127
+
128
+	/**
129
+	 * Gets one by the slug provided
130
+	 *
131
+	 * @param string $slug
132
+	 * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
133
+	 * @throws EE_Error
134
+	 */
135
+	public function get_one_by_slug($slug)
136
+	{
137
+		return $this->get_one([['PMD_slug' => $slug]]);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Gets all the acceptable scopes for payment methods.
143
+	 * Keys are their names as store din the DB, and values are nice names for displaying them
144
+	 *
145
+	 * @return array
146
+	 */
147
+	public function scopes()
148
+	{
149
+		return apply_filters(
150
+			'FHEE__EEM_Payment_Method__scopes',
151
+			[
152
+				EEM_Payment_Method::scope_cart  => esc_html__('Front-end Registration Page', 'event_espresso'),
153
+				EEM_Payment_Method::scope_admin => esc_html__(
154
+					'Admin Registration Page (no online processing)',
155
+					'event_espresso'
156
+				),
157
+			]
158
+		);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Determines if this is an valid scope
164
+	 *
165
+	 * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
166
+	 * @return boolean
167
+	 */
168
+	public function is_valid_scope($scope)
169
+	{
170
+		$scopes = $this->scopes();
171
+		if (isset($scopes[ $scope ])) {
172
+			return true;
173
+		}
174
+		return false;
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets all active payment methods
180
+	 *
181
+	 * @param string $scope one of
182
+	 * @param array  $query_params
183
+	 * @return EE_Base_Class[]|EE_Payment_Method[]
184
+	 * @throws EE_Error
185
+	 */
186
+	public function get_all_active($scope = null, $query_params = [])
187
+	{
188
+		if (! isset($query_params['order_by']) && ! isset($query_params['order'])) {
189
+			$query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC'];
190
+		}
191
+		return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
192
+	}
193
+
194
+
195
+	/**
196
+	 * Counts all active gateways in the specified scope
197
+	 *
198
+	 * @param string $scope one of EEM_Payment_Method::scope_*
199
+	 * @param array  $query_params
200
+	 * @return int
201
+	 * @throws EE_Error
202
+	 */
203
+	public function count_active($scope = null, $query_params = [])
204
+	{
205
+		return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
206
+	}
207
+
208
+
209
+	/**
210
+	 * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
211
+	 * argument to get all active for a given scope
212
+	 *
213
+	 * @param string $scope one of the constants EEM_Payment_Method::scope_*
214
+	 * @param array  $query_params
215
+	 * @return array
216
+	 * @throws EE_Error
217
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
+	 */
219
+	protected function _get_query_params_for_all_active($scope = null, $query_params = [])
220
+	{
221
+		if ($scope) {
222
+			if ($this->is_valid_scope($scope)) {
223
+				return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params);
224
+			}
225
+			throw new EE_Error(
226
+				sprintf(
227
+					esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'),
228
+					$scope
229
+				)
230
+			);
231
+		}
232
+		$acceptable_scopes = [];
233
+		$count = 0;
234
+		foreach ($this->scopes() as $scope_name => $desc) {
235
+			$count++;
236
+			$acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%'];
237
+		}
238
+		return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params);
239
+	}
240
+
241
+
242
+	/**
243
+	 * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params
244
+	 * argument to get all active for a given scope
245
+	 *
246
+	 * @param string $scope one of the constants EEM_Payment_Method::scope_*
247
+	 * @param array  $query_params
248
+	 * @return array
249
+	 * @throws EE_Error
250
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
251
+	 */
252
+	public function get_query_params_for_all_active($scope = null, $query_params = [])
253
+	{
254
+		return $this->_get_query_params_for_all_active($scope, $query_params);
255
+	}
256
+
257
+
258
+	/**
259
+	 * Gets one active payment method. see @get_all_active for documentation
260
+	 *
261
+	 * @param string $scope
262
+	 * @param array  $query_params
263
+	 * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
264
+	 * @throws EE_Error
265
+	 */
266
+	public function get_one_active($scope = null, $query_params = [])
267
+	{
268
+		return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
269
+	}
270
+
271
+
272
+	/**
273
+	 * Gets one payment method of that type, regardless of whether its active or not
274
+	 *
275
+	 * @param string $type
276
+	 * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL
277
+	 * @throws EE_Error
278
+	 */
279
+	public function get_one_of_type($type)
280
+	{
281
+		return $this->get_one([['PMD_type' => $type]]);
282
+	}
283
+
284
+
285
+	/**
286
+	 * Overrides parent ot also check by the slug
287
+	 *
288
+	 * @param string|int|EE_Payment_Method $base_class_obj_or_id
289
+	 * @param boolean                      $ensure_is_in_db
290
+	 * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string
291
+	 * @throws EE_Error
292
+	 * @see EEM_Base::ensure_is_obj()
293
+	 */
294
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false)
295
+	{
296
+		// first: check if it's a slug
297
+		if (is_string($base_class_obj_or_id)) {
298
+			$obj = $this->get_one_by_slug($base_class_obj_or_id);
299
+			if ($obj) {
300
+				return $obj;
301
+			}
302
+		}
303
+		// ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
304
+		try {
305
+			return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
306
+		} catch (EE_Error $e) {
307
+			// handle it outside the catch
308
+		}
309
+		throw new EE_Error(
310
+			sprintf(
311
+				esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'),
312
+				$base_class_obj_or_id
313
+			)
314
+		);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Gets the ID of this object, or if its a string finds the object's id
320
+	 * associated with that slug
321
+	 *
322
+	 * @param mixed $base_obj_or_id_or_slug
323
+	 * @return int
324
+	 * @throws EE_Error
325
+	 */
326
+	public function ensure_is_ID($base_obj_or_id_or_slug)
327
+	{
328
+		if (is_string($base_obj_or_id_or_slug)) {
329
+			// assume it's a slug
330
+			$base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
331
+		}
332
+		return parent::ensure_is_ID($base_obj_or_id_or_slug);
333
+	}
334
+
335
+
336
+	/**
337
+	 * Verifies the button urls on all the passed payment methods have a valid button url.
338
+	 * If not, resets them to their default.
339
+	 *
340
+	 * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart
341
+	 * @throws EE_Error
342
+	 * @throws ReflectionException
343
+	 */
344
+	public function verify_button_urls($payment_methods = null)
345
+	{
346
+		$payment_methods = is_array($payment_methods)
347
+			? $payment_methods
348
+			: $this->get_all_active(EEM_Payment_Method::scope_cart);
349
+		foreach ($payment_methods as $payment_method) {
350
+			try {
351
+				// If there is really no button URL at all, or if the button URLs still point to decaf folder even
352
+				// though this is a caffeinated install, reset it to the default.
353
+				$current_button_url = $payment_method->button_url();
354
+				if (
355
+					empty($current_button_url)
356
+					|| (
357
+						strpos($current_button_url, 'decaf') !== false
358
+						&& strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false
359
+					)
360
+				) {
361
+					$payment_method->save(
362
+						[
363
+							'PMD_button_url' => $payment_method->type_obj()->default_button_url(),
364
+						]
365
+					);
366
+				}
367
+			} catch (EE_Error $e) {
368
+				$payment_method->deactivate();
369
+			}
370
+		}
371
+	}
372
+
373
+
374
+	/**
375
+	 * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
376
+	 * but also verifies the payment method type of each is a usable object. If not,
377
+	 * deactivate it, sets a notification, and deactivates it
378
+	 *
379
+	 * @param array $rows
380
+	 * @return EE_Payment_Method[]
381
+	 * @throws EE_Error
382
+	 * @throws InvalidDataTypeException
383
+	 * @throws ReflectionException
384
+	 */
385
+	protected function _create_objects($rows = [])
386
+	{
387
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
388
+		$payment_methods = parent::_create_objects($rows);
389
+		/* @var $payment_methods EE_Payment_Method[] */
390
+		$usable_payment_methods = [];
391
+		foreach ($payment_methods as $key => $payment_method) {
392
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
393
+				$usable_payment_methods[ $key ] = $payment_method;
394
+				// some payment methods enqueue their scripts in EE_PMT_*::__construct
395
+				// which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
396
+				// its scripts). but for backwards-compat we should continue to do that
397
+				$payment_method->type_obj();
398
+			} elseif ($payment_method->active()) {
399
+				// only deactivate and notify the admin if the payment is active somewhere
400
+				$payment_method->deactivate();
401
+				$payment_method->save();
402
+				do_action(
403
+					'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method',
404
+					$payment_method
405
+				);
406
+				new PersistentAdminNotice(
407
+					'auto-deactivated-' . $payment_method->type(),
408
+					sprintf(
409
+						esc_html__(
410
+							'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.',
411
+							'event_espresso'
412
+						),
413
+						$payment_method->admin_name(),
414
+						'<br />',
415
+						'<a href="' . admin_url('plugins.php') . '">',
416
+						'</a>'
417
+					),
418
+					true
419
+				);
420
+			}
421
+		}
422
+		return $usable_payment_methods;
423
+	}
424
+
425
+
426
+	/**
427
+	 * Gets all the payment methods which can be used for transaction
428
+	 * (according to the relations between payment methods and events, and
429
+	 * the currencies used for the transaction and their relation to payment methods)
430
+	 *
431
+	 * @param EE_Transaction $transaction
432
+	 * @param string         $scope @see EEM_Payment_Method::get_all_for_events
433
+	 * @return EE_Payment_Method[]
434
+	 * @throws EE_Error
435
+	 */
436
+	public function get_all_for_transaction($transaction, $scope)
437
+	{
438
+		// give addons a chance to override what payment methods are chosen based on the transaction
439
+		return apply_filters(
440
+			'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
441
+			$this->get_all_active($scope, ['group_by' => 'PMD_type']),
442
+			$transaction,
443
+			$scope
444
+		);
445
+	}
446
+
447
+
448
+	/**
449
+	 * Returns the payment method used for the last payment made for a registration.
450
+	 * Note: if an offline payment method was selected on the related transaction then this will have no payment
451
+	 * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration.
452
+	 *
453
+	 * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the
454
+	 *                                                    registration.
455
+	 * @return EE_Payment|null
456
+	 * @throws EE_Error
457
+	 */
458
+	public function get_last_used_for_registration($registration_or_reg_id)
459
+	{
460
+		$registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
461
+
462
+		$query_params = [
463
+			0          => [
464
+				'Payment.Registration.REG_ID' => $registration_id,
465
+			],
466
+			'order_by' => ['Payment.PAY_ID' => 'DESC'],
467
+		];
468
+		return $this->get_one($query_params);
469
+	}
470 470
 }
Please login to merge, or discard this patch.