Completed
Branch FET-10816-display-form-wide-er... (b27d66)
by
unknown
153:47 queued 140:47
created
core/libraries/rest_api/controllers/rpc/Checkin.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use EventEspresso\core\libraries\rest_api\controllers\Base as Base;
14 14
 use EventEspresso\core\libraries\rest_api\controllers\model\Read;
15 15
 
16
-if (! defined('EVENT_ESPRESSO_VERSION')) {
16
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
17 17
     exit('No direct script access allowed');
18 18
 }
19 19
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
             $force = false;
64 64
         }
65 65
         $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
66
-        if (! $reg instanceof EE_Registration) {
66
+        if ( ! $reg instanceof EE_Registration) {
67 67
             return $this->sendResponse(
68 68
                 new WP_Error(
69 69
                     'rest_registration_toggle_checkin_invalid_id',
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 )
77 77
             );
78 78
         }
79
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
79
+        if ( ! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
80 80
             return $this->sendResponse(
81 81
                 new WP_Error(
82 82
                     'rest_user_cannot_toggle_checkin',
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         $success = $reg->toggle_checkin_status($dtt_id, ! $force);
92 92
         if ($success === false) {
93 93
             //check if we know they can't check in because they're not approved and we aren't forcing
94
-            if (! $reg->is_approved() && ! $force) {
94
+            if ( ! $reg->is_approved() && ! $force) {
95 95
                 //rely on EE_Error::add_error messages to have been added to give more data about why it failed
96 96
                 return $this->sendResponse(
97 97
                     new WP_Error(
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                 ),
120 120
             )
121 121
         );
122
-        if (! $checkin instanceof EE_Checkin) {
122
+        if ( ! $checkin instanceof EE_Checkin) {
123 123
             return $this->sendResponse(
124 124
                 new WP_Error(
125 125
                     'rest_toggle_checkin_error',
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         }
135 135
         $get_request = new WP_REST_Request(
136 136
             'GET',
137
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
137
+            '/'.EED_Core_Rest_Api::ee_api_namespace.'v'.$version.'/checkins/'.$checkin->ID()
138 138
         );
139 139
         $get_request->set_url_params(
140 140
             array(
Please login to merge, or discard this patch.
Indentation   +119 added lines, -120 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use EventEspresso\core\libraries\rest_api\controllers\model\Read;
15 15
 
16 16
 if (! defined('EVENT_ESPRESSO_VERSION')) {
17
-    exit('No direct script access allowed');
17
+	exit('No direct script access allowed');
18 18
 }
19 19
 
20 20
 
@@ -31,126 +31,125 @@  discard block
 block discarded – undo
31 31
 class Checkin extends Base
32 32
 {
33 33
 
34
-    /**
35
-     * @param WP_REST_Request $request
36
-     * @param string           $version
37
-     * @return WP_Error|WP_REST_Response
38
-     */
39
-    public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
40
-    {
41
-        $controller = new Checkin();
42
-        return $controller->createCheckinCheckoutObject($request, $version);
43
-    }
34
+	/**
35
+	 * @param WP_REST_Request $request
36
+	 * @param string           $version
37
+	 * @return WP_Error|WP_REST_Response
38
+	 */
39
+	public static function handleRequestToggleCheckin(WP_REST_Request $request, $version)
40
+	{
41
+		$controller = new Checkin();
42
+		return $controller->createCheckinCheckoutObject($request, $version);
43
+	}
44 44
 
45 45
 
46 46
 
47
-    /**
48
-     * Toggles whether the user is checked in or not.
49
-
50
-     *
51
-     * @param WP_REST_Request $request
52
-     * @param string           $version
53
-     * @return WP_Error|WP_REST_Response
54
-     */
55
-    protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
56
-    {
57
-        $reg_id = $request->get_param('REG_ID');
58
-        $dtt_id = $request->get_param('DTT_ID');
59
-        $force = $request->get_param('force');
60
-        if ($force == 'true') {
61
-            $force = true;
62
-        } else {
63
-            $force = false;
64
-        }
65
-        $reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
66
-        if (! $reg instanceof EE_Registration) {
67
-            return $this->sendResponse(
68
-                new WP_Error(
69
-                    'rest_registration_toggle_checkin_invalid_id',
70
-                    sprintf(
71
-                        __(
72
-                            'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
73
-                            'event_espresso'
74
-                        ),
75
-                        $reg_id
76
-                    ),
77
-                    array('status' => 422)
78
-                )
79
-            );
80
-        }
81
-        if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
82
-            return $this->sendResponse(
83
-                new WP_Error(
84
-                    'rest_user_cannot_toggle_checkin',
85
-                    sprintf(
86
-                        __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
87
-                        $reg_id
88
-                    ),
89
-                    array('status' => 403)
90
-                )
91
-            );
92
-        }
93
-        $success = $reg->toggle_checkin_status($dtt_id, ! $force);
94
-        if ($success === false) {
95
-            //check if we know they can't check in because they're not approved and we aren't forcing
96
-            if (! $reg->is_approved() && ! $force) {
97
-                //rely on EE_Error::add_error messages to have been added to give more data about why it failed
98
-                return $this->sendResponse(
99
-                    new WP_Error(
100
-                        'rest_toggle_checkin_failed',
101
-                        __(
102
-                            // @codingStandardsIgnoreStart
103
-                            'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
104
-                            // @codingStandardsIgnoreEnd
105
-                            'event_espresso'
106
-                        )
107
-                    )
108
-                );
109
-            }
110
-            return $this->sendResponse(
111
-                new WP_Error(
112
-                    'rest_toggle_checkin_failed_not_forceable',
113
-                    __('Registration checkin failed. Please see additional error data.', 'event_espresso')
114
-                )
115
-            );
116
-        }
117
-        $checkin = EEM_Checkin::instance()->get_one(
118
-            array(
119
-                array(
120
-                    'REG_ID' => $reg_id,
121
-                    'DTT_ID' => $dtt_id,
122
-                ),
123
-                'order_by' => array(
124
-                    'CHK_timestamp' => 'DESC',
125
-                ),
126
-            )
127
-        );
128
-        if (! $checkin instanceof EE_Checkin) {
129
-            return $this->sendResponse(
130
-                new WP_Error(
131
-                    'rest_toggle_checkin_error',
132
-                    sprintf(
133
-                        __(
134
-                            // @codingStandardsIgnoreStart
135
-                            'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
136
-                            // @codingStandardsIgnoreEnd
137
-                            'event_espresso'
138
-                        ),
139
-                        $reg_id,
140
-                        $dtt_id
141
-                    )
142
-                )
143
-            );
144
-        }
145
-        $get_request = new WP_REST_Request(
146
-            'GET',
147
-            '/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
148
-        );
149
-        $get_request->set_url_params(
150
-            array(
151
-                'id' => $checkin->ID(),
152
-            )
153
-        );
154
-        return Read::handleRequestGetOne($get_request, $version, 'Checkin');
155
-    }
47
+	/**
48
+	 * Toggles whether the user is checked in or not.
49
+	 *
50
+	 * @param WP_REST_Request $request
51
+	 * @param string           $version
52
+	 * @return WP_Error|WP_REST_Response
53
+	 */
54
+	protected function createCheckinCheckoutObject(WP_REST_Request $request, $version)
55
+	{
56
+		$reg_id = $request->get_param('REG_ID');
57
+		$dtt_id = $request->get_param('DTT_ID');
58
+		$force = $request->get_param('force');
59
+		if ($force == 'true') {
60
+			$force = true;
61
+		} else {
62
+			$force = false;
63
+		}
64
+		$reg = EEM_Registration::instance()->get_one_by_ID($reg_id);
65
+		if (! $reg instanceof EE_Registration) {
66
+			return $this->sendResponse(
67
+				new WP_Error(
68
+					'rest_registration_toggle_checkin_invalid_id',
69
+					sprintf(
70
+						__(
71
+							'You cannot checkin registration with ID %1$s because it doesn\'t exist.',
72
+							'event_espresso'
73
+						),
74
+						$reg_id
75
+					),
76
+					array('status' => 422)
77
+				)
78
+			);
79
+		}
80
+		if (! EE_Capabilities::instance()->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id)) {
81
+			return $this->sendResponse(
82
+				new WP_Error(
83
+					'rest_user_cannot_toggle_checkin',
84
+					sprintf(
85
+						__('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'),
86
+						$reg_id
87
+					),
88
+					array('status' => 403)
89
+				)
90
+			);
91
+		}
92
+		$success = $reg->toggle_checkin_status($dtt_id, ! $force);
93
+		if ($success === false) {
94
+			//check if we know they can't check in because they're not approved and we aren't forcing
95
+			if (! $reg->is_approved() && ! $force) {
96
+				//rely on EE_Error::add_error messages to have been added to give more data about why it failed
97
+				return $this->sendResponse(
98
+					new WP_Error(
99
+						'rest_toggle_checkin_failed',
100
+						__(
101
+							// @codingStandardsIgnoreStart
102
+							'Registration check-in failed because the registration is not approved. You may attempt to force checking in though.',
103
+							// @codingStandardsIgnoreEnd
104
+							'event_espresso'
105
+						)
106
+					)
107
+				);
108
+			}
109
+			return $this->sendResponse(
110
+				new WP_Error(
111
+					'rest_toggle_checkin_failed_not_forceable',
112
+					__('Registration checkin failed. Please see additional error data.', 'event_espresso')
113
+				)
114
+			);
115
+		}
116
+		$checkin = EEM_Checkin::instance()->get_one(
117
+			array(
118
+				array(
119
+					'REG_ID' => $reg_id,
120
+					'DTT_ID' => $dtt_id,
121
+				),
122
+				'order_by' => array(
123
+					'CHK_timestamp' => 'DESC',
124
+				),
125
+			)
126
+		);
127
+		if (! $checkin instanceof EE_Checkin) {
128
+			return $this->sendResponse(
129
+				new WP_Error(
130
+					'rest_toggle_checkin_error',
131
+					sprintf(
132
+						__(
133
+							// @codingStandardsIgnoreStart
134
+							'Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.',
135
+							// @codingStandardsIgnoreEnd
136
+							'event_espresso'
137
+						),
138
+						$reg_id,
139
+						$dtt_id
140
+					)
141
+				)
142
+			);
143
+		}
144
+		$get_request = new WP_REST_Request(
145
+			'GET',
146
+			'/' . EED_Core_Rest_Api::ee_api_namespace . 'v' . $version . '/checkins/' . $checkin->ID()
147
+		);
148
+		$get_request->set_url_params(
149
+			array(
150
+				'id' => $checkin->ID(),
151
+			)
152
+		);
153
+		return Read::handleRequestGetOne($get_request, $version, 'Checkin');
154
+	}
156 155
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         // used by display strategies
100 100
         // assign incoming values to properties
101 101
         foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
102
+            $key = '_'.$key;
103 103
             if (property_exists($this, $key) && empty($this->{$key})) {
104 104
                 $this->{$key} = $value;
105 105
             }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function ensure_construct_finalized_called()
138 138
     {
139
-        if (! $this->_construction_finalized) {
139
+        if ( ! $this->_construction_finalized) {
140 140
             $this->_construct_finalize($this->_parent_section, $this->_name);
141 141
         }
142 142
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function _set_default_html_id_if_empty()
201 201
     {
202
-        if (! $this->_html_id) {
202
+        if ( ! $this->_html_id) {
203 203
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204 204
                 $this->_html_id = $this->_parent_section->html_id()
205 205
                                   . '-'
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     public function html_id($add_pound_sign = false)
259 259
     {
260 260
         $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
262 262
     }
263 263
 
264 264
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function name()
343 343
     {
344
-        if (! $this->_construction_finalized) {
344
+        if ( ! $this->_construction_finalized) {
345 345
             throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346 346
                 'event_espresso'), get_class($this)));
347 347
         }
@@ -372,17 +372,17 @@  discard block
 block discarded – undo
372 372
      */
373 373
     public function form_open($action = '', $method = '', $other_attributes = '')
374 374
     {
375
-        if (! empty($action)) {
375
+        if ( ! empty($action)) {
376 376
             $this->set_action($action);
377 377
         }
378
-        if (! empty($method)) {
378
+        if ( ! empty($method)) {
379 379
             $this->set_method($method);
380 380
         }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
381
+        $html = EEH_HTML::nl(1, 'form').'<form';
382
+        $html .= $this->html_id() !== '' ? ' id="'.$this->get_html_id_for_form($this->html_id()).'"' : '';
383
+        $html .= ' action="'.$this->action().'"';
384
+        $html .= ' method="'.$this->method().'"';
385
+        $html .= $other_attributes.'>';
386 386
         return $html;
387 387
     }
388 388
 
@@ -398,9 +398,9 @@  discard block
 block discarded – undo
398 398
     protected function get_html_id_for_form($html_id)
399 399
     {
400 400
         $strlen = strlen($html_id);
401
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
401
+        $html_id = strpos($html_id, '-form') === $strlen - 5 || strpos($html_id, '-frm') === $strlen - 4
402 402
             ? $html_id
403
-            : $html_id . '-frm';
403
+            : $html_id.'-frm';
404 404
         return $html_id;
405 405
     }
406 406
 
Please login to merge, or discard this patch.
Indentation   +464 added lines, -464 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,480 +19,480 @@  discard block
 block discarded – undo
19 19
 abstract class EE_Form_Section_Base
20 20
 {
21 21
 
22
-    /**
23
-     * the URL the form is submitted to
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_action;
28
-
29
-    /**
30
-     * POST (default) or GET
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_method;
35
-
36
-    /**
37
-     * html_id and html_name are derived from this by default
38
-     *
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-    /**
44
-     * $_html_id
45
-     * @var string
46
-     */
47
-    protected $_html_id;
48
-
49
-    /**
50
-     * $_html_class
51
-     * @var string
52
-     */
53
-    protected $_html_class;
54
-
55
-    /**
56
-     * $_html_style
57
-     * @var string
58
-     */
59
-    protected $_html_style;
60
-
61
-    /**
62
-     * $_other_html_attributes
63
-     * @var string
64
-     */
65
-    protected $_other_html_attributes;
66
-
67
-    /**
68
-     * The form section of which this form section is a part
69
-     *
70
-     * @var EE_Form_Section_Proper
71
-     */
72
-    protected $_parent_section;
73
-
74
-    /**
75
-     * flag indicating that _construct_finalize has been called.
76
-     * If it has not been called and we try to use functions which require it, we call it
77
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
-     *
79
-     * @var boolean
80
-     */
81
-    protected $_construction_finalized;
82
-
83
-    /**
84
-     * Strategy for parsing the form HTML upon display
85
-     *
86
-     * @var FormHtmlFilter
87
-     */
88
-    protected $_form_html_filter;
89
-
90
-
91
-
92
-    /**
93
-     * @param array $options_array {
94
-     * @type        $name          string the name for this form section, if you want to explicitly define it
95
-     *                             }
96
-     */
97
-    public function __construct($options_array = array())
98
-    {
99
-        // used by display strategies
100
-        // assign incoming values to properties
101
-        foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
103
-            if (property_exists($this, $key) && empty($this->{$key})) {
104
-                $this->{$key} = $value;
105
-            }
106
-        }
107
-        // set parser which allows the form section's rendered HTML to be filtered
108
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
-            $this->_form_html_filter = $options_array['form_html_filter'];
110
-        }
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param $parent_form_section
117
-     * @param $name
118
-     * @throws \EE_Error
119
-     */
120
-    protected function _construct_finalize($parent_form_section, $name)
121
-    {
122
-        $this->_construction_finalized = true;
123
-        $this->_parent_section = $parent_form_section;
124
-        if ($name !== null) {
125
-            $this->_name = $name;
126
-        }
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * make sure construction finalized was called, otherwise children might not be ready
133
-     *
134
-     * @return void
135
-     * @throws \EE_Error
136
-     */
137
-    public function ensure_construct_finalized_called()
138
-    {
139
-        if (! $this->_construction_finalized) {
140
-            $this->_construct_finalize($this->_parent_section, $this->_name);
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function action()
150
-    {
151
-        return $this->_action;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param string $action
158
-     */
159
-    public function set_action($action)
160
-    {
161
-        $this->_action = $action;
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @return string
168
-     */
169
-    public function method()
170
-    {
171
-        return ! empty($this->_method) ? $this->_method : 'POST';
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * @param string $method
178
-     */
179
-    public function set_method($method)
180
-    {
181
-        switch ($method) {
182
-            case 'get' :
183
-            case 'GET' :
184
-                $this->_method = 'GET';
185
-                break;
186
-            default :
187
-                $this->_method = 'POST';
188
-        }
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Sets the html_id to its default value, if none was specified in the constructor.
195
-     * Calculation involves using the name and the parent's html id
196
-     * return void
197
-     *
198
-     * @throws \EE_Error
199
-     */
200
-    protected function _set_default_html_id_if_empty()
201
-    {
202
-        if (! $this->_html_id) {
203
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
-                $this->_html_id = $this->_parent_section->html_id()
205
-                                  . '-'
206
-                                  . $this->_prep_name_for_html_id($this->name());
207
-            } else {
208
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
209
-            }
210
-        }
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _prep_name_for_html_id
217
-     *
218
-     * @param $name
219
-     * @return string
220
-     */
221
-    private function _prep_name_for_html_id($name)
222
-    {
223
-        return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
-    }
22
+	/**
23
+	 * the URL the form is submitted to
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_action;
28
+
29
+	/**
30
+	 * POST (default) or GET
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_method;
35
+
36
+	/**
37
+	 * html_id and html_name are derived from this by default
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+	/**
44
+	 * $_html_id
45
+	 * @var string
46
+	 */
47
+	protected $_html_id;
48
+
49
+	/**
50
+	 * $_html_class
51
+	 * @var string
52
+	 */
53
+	protected $_html_class;
54
+
55
+	/**
56
+	 * $_html_style
57
+	 * @var string
58
+	 */
59
+	protected $_html_style;
60
+
61
+	/**
62
+	 * $_other_html_attributes
63
+	 * @var string
64
+	 */
65
+	protected $_other_html_attributes;
66
+
67
+	/**
68
+	 * The form section of which this form section is a part
69
+	 *
70
+	 * @var EE_Form_Section_Proper
71
+	 */
72
+	protected $_parent_section;
73
+
74
+	/**
75
+	 * flag indicating that _construct_finalize has been called.
76
+	 * If it has not been called and we try to use functions which require it, we call it
77
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
+	 *
79
+	 * @var boolean
80
+	 */
81
+	protected $_construction_finalized;
82
+
83
+	/**
84
+	 * Strategy for parsing the form HTML upon display
85
+	 *
86
+	 * @var FormHtmlFilter
87
+	 */
88
+	protected $_form_html_filter;
89
+
90
+
91
+
92
+	/**
93
+	 * @param array $options_array {
94
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
95
+	 *                             }
96
+	 */
97
+	public function __construct($options_array = array())
98
+	{
99
+		// used by display strategies
100
+		// assign incoming values to properties
101
+		foreach ($options_array as $key => $value) {
102
+			$key = '_' . $key;
103
+			if (property_exists($this, $key) && empty($this->{$key})) {
104
+				$this->{$key} = $value;
105
+			}
106
+		}
107
+		// set parser which allows the form section's rendered HTML to be filtered
108
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
+			$this->_form_html_filter = $options_array['form_html_filter'];
110
+		}
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param $parent_form_section
117
+	 * @param $name
118
+	 * @throws \EE_Error
119
+	 */
120
+	protected function _construct_finalize($parent_form_section, $name)
121
+	{
122
+		$this->_construction_finalized = true;
123
+		$this->_parent_section = $parent_form_section;
124
+		if ($name !== null) {
125
+			$this->_name = $name;
126
+		}
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * make sure construction finalized was called, otherwise children might not be ready
133
+	 *
134
+	 * @return void
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function ensure_construct_finalized_called()
138
+	{
139
+		if (! $this->_construction_finalized) {
140
+			$this->_construct_finalize($this->_parent_section, $this->_name);
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function action()
150
+	{
151
+		return $this->_action;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param string $action
158
+	 */
159
+	public function set_action($action)
160
+	{
161
+		$this->_action = $action;
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @return string
168
+	 */
169
+	public function method()
170
+	{
171
+		return ! empty($this->_method) ? $this->_method : 'POST';
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * @param string $method
178
+	 */
179
+	public function set_method($method)
180
+	{
181
+		switch ($method) {
182
+			case 'get' :
183
+			case 'GET' :
184
+				$this->_method = 'GET';
185
+				break;
186
+			default :
187
+				$this->_method = 'POST';
188
+		}
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Sets the html_id to its default value, if none was specified in the constructor.
195
+	 * Calculation involves using the name and the parent's html id
196
+	 * return void
197
+	 *
198
+	 * @throws \EE_Error
199
+	 */
200
+	protected function _set_default_html_id_if_empty()
201
+	{
202
+		if (! $this->_html_id) {
203
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
+				$this->_html_id = $this->_parent_section->html_id()
205
+								  . '-'
206
+								  . $this->_prep_name_for_html_id($this->name());
207
+			} else {
208
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
209
+			}
210
+		}
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _prep_name_for_html_id
217
+	 *
218
+	 * @param $name
219
+	 * @return string
220
+	 */
221
+	private function _prep_name_for_html_id($name)
222
+	{
223
+		return sanitize_key(str_replace(array('&nbsp;', ' ', '_'), '-', $name));
224
+	}
225 225
 
226 226
 
227 227
 
228
-    /**
229
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
-     * and call get_html when you want to output the html. Calling get_html_and_js after
232
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
-     * and so might stop working anytime.
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_and_js()
239
-    {
240
-        return $this->get_html();
241
-    }
228
+	/**
229
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
232
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
+	 * and so might stop working anytime.
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_and_js()
239
+	{
240
+		return $this->get_html();
241
+	}
242 242
 
243 243
 
244 244
 
245
-    /**
246
-     * Gets the HTML for displaying this form section
247
-     *
248
-     * @return string
249
-     */
250
-    public abstract function get_html();
245
+	/**
246
+	 * Gets the HTML for displaying this form section
247
+	 *
248
+	 * @return string
249
+	 */
250
+	public abstract function get_html();
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @param bool $add_pound_sign
256
-     * @return string
257
-     */
258
-    public function html_id($add_pound_sign = false)
259
-    {
260
-        $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
-    }
254
+	/**
255
+	 * @param bool $add_pound_sign
256
+	 * @return string
257
+	 */
258
+	public function html_id($add_pound_sign = false)
259
+	{
260
+		$this->_set_default_html_id_if_empty();
261
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
+	}
263 263
 
264 264
 
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function html_class()
270
-    {
271
-        return $this->_html_class;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @return string
278
-     */
279
-    public function html_style()
280
-    {
281
-        return $this->_html_style;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed $html_class
288
-     */
289
-    public function set_html_class($html_class)
290
-    {
291
-        $this->_html_class = $html_class;
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param mixed $html_id
298
-     */
299
-    public function set_html_id($html_id)
300
-    {
301
-        $this->_html_id = $html_id;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param mixed $html_style
308
-     */
309
-    public function set_html_style($html_style)
310
-    {
311
-        $this->_html_style = $html_style;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * @param string $other_html_attributes
318
-     */
319
-    public function set_other_html_attributes($other_html_attributes)
320
-    {
321
-        $this->_other_html_attributes = $other_html_attributes;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function other_html_attributes()
330
-    {
331
-        return $this->_other_html_attributes;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Gets the name of the form section. This is not the same as the HTML name.
338
-     *
339
-     * @throws EE_Error
340
-     * @return string
341
-     */
342
-    public function name()
343
-    {
344
-        if (! $this->_construction_finalized) {
345
-            throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'), get_class($this)));
347
-        }
348
-        return $this->_name;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * Gets the parent section
355
-     *
356
-     * @return EE_Form_Section_Proper
357
-     */
358
-    public function parent_section()
359
-    {
360
-        return $this->_parent_section;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     */
373
-    public function form_open($action = '', $method = '', $other_attributes = '')
374
-    {
375
-        if (! empty($action)) {
376
-            $this->set_action($action);
377
-        }
378
-        if (! empty($method)) {
379
-            $this->set_method($method);
380
-        }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
386
-        return $html;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * ensures that html id for form either ends in "-form" or "-frm"
393
-     * so that id doesn't conflict/collide with other elements
394
-     *
395
-     * @param string $html_id
396
-     * @return string
397
-     */
398
-    protected function get_html_id_for_form($html_id)
399
-    {
400
-        $strlen = strlen($html_id);
401
-        $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
-            ? $html_id
403
-            : $html_id . '-frm';
404
-        return $html_id;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * returns HTML for generating the closing form HTML tag (</form>)
411
-     *
412
-     * @return string
413
-     */
414
-    public function form_close()
415
-    {
416
-        return EEH_HTML::nl(-1, 'form')
417
-               . '</form>'
418
-               . EEH_HTML::nl()
419
-               . '<!-- end of ee-'
420
-               . $this->html_id()
421
-               . '-form -->'
422
-               . EEH_HTML::nl();
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
-     * Default does nothing, but child classes can override
431
-     *
432
-     * @return void
433
-     */
434
-    public function enqueue_js()
435
-    {
436
-        //defaults to enqueue NO js or css
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
-     * with it, and it will be on each form section's 'other_data' property.
444
-     * By default nothing is added, but child classes can extend this method to add something.
445
-     * Eg, if you have an input that will cause a modal dialog to appear,
446
-     * here you could add an entry like 'modal_dialog_inputs' to this array
447
-     * to map between the input's html ID and the modal dialogue's ID, so that
448
-     * your JS code will know where to find the modal dialog when the input is pressed.
449
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
-     *
451
-     * @param array $form_other_js_data
452
-     * @return array
453
-     */
454
-    public function get_other_js_data($form_other_js_data = array())
455
-    {
456
-        return $form_other_js_data;
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * This isn't just the name of an input, it's a path pointing to an input. The
463
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
464
-     * dot-dot-slash (../) means to ascend into the parent section.
465
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
-     * which will be returned.
467
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
-     * Etc
472
-     *
473
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
-     * @return EE_Form_Section_Base
475
-     */
476
-    public function find_section_from_path($form_section_path)
477
-    {
478
-        if (strpos($form_section_path, '/') === 0) {
479
-            $form_section_path = substr($form_section_path, strlen('/'));
480
-        }
481
-        if (empty($form_section_path)) {
482
-            return $this;
483
-        }
484
-        if (strpos($form_section_path, '../') === 0) {
485
-            $parent = $this->parent_section();
486
-            $form_section_path = substr($form_section_path, strlen('../'));
487
-            if ($parent instanceof EE_Form_Section_Base) {
488
-                return $parent->find_section_from_path($form_section_path);
489
-            } elseif (empty($form_section_path)) {
490
-                return $this;
491
-            }
492
-        }
493
-        //couldn't find it using simple parent following
494
-        return null;
495
-    }
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function html_class()
270
+	{
271
+		return $this->_html_class;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @return string
278
+	 */
279
+	public function html_style()
280
+	{
281
+		return $this->_html_style;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed $html_class
288
+	 */
289
+	public function set_html_class($html_class)
290
+	{
291
+		$this->_html_class = $html_class;
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param mixed $html_id
298
+	 */
299
+	public function set_html_id($html_id)
300
+	{
301
+		$this->_html_id = $html_id;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param mixed $html_style
308
+	 */
309
+	public function set_html_style($html_style)
310
+	{
311
+		$this->_html_style = $html_style;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param string $other_html_attributes
318
+	 */
319
+	public function set_other_html_attributes($other_html_attributes)
320
+	{
321
+		$this->_other_html_attributes = $other_html_attributes;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function other_html_attributes()
330
+	{
331
+		return $this->_other_html_attributes;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Gets the name of the form section. This is not the same as the HTML name.
338
+	 *
339
+	 * @throws EE_Error
340
+	 * @return string
341
+	 */
342
+	public function name()
343
+	{
344
+		if (! $this->_construction_finalized) {
345
+			throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'), get_class($this)));
347
+		}
348
+		return $this->_name;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * Gets the parent section
355
+	 *
356
+	 * @return EE_Form_Section_Proper
357
+	 */
358
+	public function parent_section()
359
+	{
360
+		return $this->_parent_section;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 */
373
+	public function form_open($action = '', $method = '', $other_attributes = '')
374
+	{
375
+		if (! empty($action)) {
376
+			$this->set_action($action);
377
+		}
378
+		if (! empty($method)) {
379
+			$this->set_method($method);
380
+		}
381
+		$html = EEH_HTML::nl(1, 'form') . '<form';
382
+		$html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : '';
383
+		$html .= ' action="' . $this->action() . '"';
384
+		$html .= ' method="' . $this->method() . '"';
385
+		$html .= $other_attributes . '>';
386
+		return $html;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * ensures that html id for form either ends in "-form" or "-frm"
393
+	 * so that id doesn't conflict/collide with other elements
394
+	 *
395
+	 * @param string $html_id
396
+	 * @return string
397
+	 */
398
+	protected function get_html_id_for_form($html_id)
399
+	{
400
+		$strlen = strlen($html_id);
401
+		$html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4
402
+			? $html_id
403
+			: $html_id . '-frm';
404
+		return $html_id;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * returns HTML for generating the closing form HTML tag (</form>)
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public function form_close()
415
+	{
416
+		return EEH_HTML::nl(-1, 'form')
417
+			   . '</form>'
418
+			   . EEH_HTML::nl()
419
+			   . '<!-- end of ee-'
420
+			   . $this->html_id()
421
+			   . '-form -->'
422
+			   . EEH_HTML::nl();
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
429
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
430
+	 * Default does nothing, but child classes can override
431
+	 *
432
+	 * @return void
433
+	 */
434
+	public function enqueue_js()
435
+	{
436
+		//defaults to enqueue NO js or css
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
443
+	 * with it, and it will be on each form section's 'other_data' property.
444
+	 * By default nothing is added, but child classes can extend this method to add something.
445
+	 * Eg, if you have an input that will cause a modal dialog to appear,
446
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
447
+	 * to map between the input's html ID and the modal dialogue's ID, so that
448
+	 * your JS code will know where to find the modal dialog when the input is pressed.
449
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
450
+	 *
451
+	 * @param array $form_other_js_data
452
+	 * @return array
453
+	 */
454
+	public function get_other_js_data($form_other_js_data = array())
455
+	{
456
+		return $form_other_js_data;
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * This isn't just the name of an input, it's a path pointing to an input. The
463
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
464
+	 * dot-dot-slash (../) means to ascend into the parent section.
465
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
466
+	 * which will be returned.
467
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
468
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
469
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
470
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
471
+	 * Etc
472
+	 *
473
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
474
+	 * @return EE_Form_Section_Base
475
+	 */
476
+	public function find_section_from_path($form_section_path)
477
+	{
478
+		if (strpos($form_section_path, '/') === 0) {
479
+			$form_section_path = substr($form_section_path, strlen('/'));
480
+		}
481
+		if (empty($form_section_path)) {
482
+			return $this;
483
+		}
484
+		if (strpos($form_section_path, '../') === 0) {
485
+			$parent = $this->parent_section();
486
+			$form_section_path = substr($form_section_path, strlen('../'));
487
+			if ($parent instanceof EE_Form_Section_Base) {
488
+				return $parent->find_section_from_path($form_section_path);
489
+			} elseif (empty($form_section_path)) {
490
+				return $this;
491
+			}
492
+		}
493
+		//couldn't find it using simple parent following
494
+		return null;
495
+	}
496 496
 
497 497
 
498 498
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40833.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -7,59 +7,59 @@
 block discarded – undo
7 7
 class ChangesIn40833 extends ChangesInBase
8 8
 {
9 9
 
10
-    /**
11
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
12
-     */
13
-    public function setHooks()
14
-    {
15
-        //set a hook to remove the checkout/checkout endpoints if the request
16
-        //is for lower than 4.8.33
17
-        add_filter(
18
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
19
-            array($this, 'removeCheckinRoutesEarlierThan4833'),
20
-            10,
21
-            2
22
-        );
23
-        add_filter(
24
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
25
-            array($this, 'dontAddHeadersFromEeNotices'),
26
-            10,
27
-            2
28
-        );
29
-    }
10
+	/**
11
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
12
+	 */
13
+	public function setHooks()
14
+	{
15
+		//set a hook to remove the checkout/checkout endpoints if the request
16
+		//is for lower than 4.8.33
17
+		add_filter(
18
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
19
+			array($this, 'removeCheckinRoutesEarlierThan4833'),
20
+			10,
21
+			2
22
+		);
23
+		add_filter(
24
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return',
25
+			array($this, 'dontAddHeadersFromEeNotices'),
26
+			10,
27
+			2
28
+		);
29
+	}
30 30
 
31 31
 
32 32
 
33
-    /**
34
-     * Removes the checkin and checkout endpoints from the index for requests
35
-     * to api versions lowers than 4.8.33
36
-     *
37
-     * @param array  $routes_on_this_version
38
-     * @param string $version
39
-     * @return array like $routes_on_this_version
40
-     */
41
-    public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version)
42
-    {
43
-        if ($this->appliesToVersion($version)) {
44
-            unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']);
45
-        }
46
-        return $routes_on_this_version;
47
-    }
33
+	/**
34
+	 * Removes the checkin and checkout endpoints from the index for requests
35
+	 * to api versions lowers than 4.8.33
36
+	 *
37
+	 * @param array  $routes_on_this_version
38
+	 * @param string $version
39
+	 * @return array like $routes_on_this_version
40
+	 */
41
+	public function removeCheckinRoutesEarlierThan4833($routes_on_this_version, $version)
42
+	{
43
+		if ($this->appliesToVersion($version)) {
44
+			unset($routes_on_this_version['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)']);
45
+		}
46
+		return $routes_on_this_version;
47
+	}
48 48
 
49 49
 
50 50
 
51
-    /**
52
-     * We just added headers for notices in this version
53
-     *
54
-     * @param array  $headers_from_ee_notices
55
-     * @param string $requested_version
56
-     * @return array
57
-     */
58
-    public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version)
59
-    {
60
-        if ($this->appliesToVersion($requested_version)) {
61
-            return array();
62
-        }
63
-        return $headers_from_ee_notices;
64
-    }
51
+	/**
52
+	 * We just added headers for notices in this version
53
+	 *
54
+	 * @param array  $headers_from_ee_notices
55
+	 * @param string $requested_version
56
+	 * @return array
57
+	 */
58
+	public function dontAddHeadersFromEeNotices($headers_from_ee_notices, $requested_version)
59
+	{
60
+		if ($this->appliesToVersion($requested_version)) {
61
+			return array();
62
+		}
63
+		return $headers_from_ee_notices;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40834.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
 class ChangesIn40834 extends ChangesInBase
13 13
 {
14 14
 
15
-    /**
16
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
-     */
18
-    public function setHooks()
19
-    {
20
-        //set a hook to remove the checkout/checkout endpoints if the request
21
-        //is for lower than 4.8.33
22
-        add_filter(
23
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
-            array($this, 'removeResponseHeaders'),
25
-            10,
26
-            3
27
-        );
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * Removes the checkin and checkout endpoints from the index for requests
34
-     * to api versions lowers than 4.8.33
35
-     *
36
-     * @param array  $response_headers
37
-     * @param Base   $controller
38
-     * @param string $requested_version
39
-     * @return array like $routes_on_this_version
40
-     */
41
-    public function removeResponseHeaders($response_headers, $controller, $requested_version)
42
-    {
43
-        if ($controller instanceof Base
44
-            && $this->appliesToVersion($requested_version)
45
-        ) {
46
-            return array();
47
-        }
48
-        return $response_headers;
49
-    }
15
+	/**
16
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
17
+	 */
18
+	public function setHooks()
19
+	{
20
+		//set a hook to remove the checkout/checkout endpoints if the request
21
+		//is for lower than 4.8.33
22
+		add_filter(
23
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
24
+			array($this, 'removeResponseHeaders'),
25
+			10,
26
+			3
27
+		);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * Removes the checkin and checkout endpoints from the index for requests
34
+	 * to api versions lowers than 4.8.33
35
+	 *
36
+	 * @param array  $response_headers
37
+	 * @param Base   $controller
38
+	 * @param string $requested_version
39
+	 * @return array like $routes_on_this_version
40
+	 */
41
+	public function removeResponseHeaders($response_headers, $controller, $requested_version)
42
+	{
43
+		if ($controller instanceof Base
44
+			&& $this->appliesToVersion($requested_version)
45
+		) {
46
+			return array();
47
+		}
48
+		return $response_headers;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/changes/ChangesIn40836.php 2 patches
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -16,179 +16,179 @@
 block discarded – undo
16 16
 class ChangesIn40836 extends ChangesInBase
17 17
 {
18 18
 
19
-    /**
20
-     * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
21
-     */
22
-    public function setHooks()
23
-    {
24
-        //set a hook to remove the "calculate" query param
25
-        add_filter(
26
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
27
-            array($this, 'removeCalculateQueryParam'),
28
-            10,
29
-            3
30
-        );
31
-        //don't add the _calculated_fields either
32
-        add_filter(
33
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
34
-            array($this, 'removeCalculatedFieldsFromResponse'),
35
-            10,
36
-            5
37
-        );
38
-        //and also don't add the count headers
39
-        add_filter(
40
-            'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
41
-            array($this, 'removeHeadersNewInThisVersion'),
42
-            10,
43
-            3
44
-        );
45
-        //remove the old featured_image part of the response...
46
-        add_filter(
47
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
48
-            array($this, 'addOldFeaturedImagePartOfCptEntities'),
49
-            10,
50
-            5
51
-        );
52
-        //assuming ticket 9425's change gets pushed with 9406, we don't need to
53
-        //remove it from the calculated fields on older requests (because this will
54
-        //be the first version with calculated fields)
55
-        //before this, infinity was -1, now it's null
56
-        add_filter(
57
-            'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
58
-            array($this, 'useNegativeOneForInfinityBeforeThisVersion'),
59
-            10,
60
-            4
61
-        );
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * Don't show "calculate" as an query param option in the index
68
-     *
69
-     * @param array     $query_params
70
-     * @param EEM_Base $model
71
-     * @param string    $version
72
-     * @return array
73
-     */
74
-    public function removeCalculateQueryParam($query_params, EEM_Base $model, $version)
75
-    {
76
-        if ($this->appliesToVersion($version)) {
77
-            unset($query_params['calculate']);
78
-        }
79
-        return $query_params;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Removes the "_calculate_fields" part of entity responses before 4.8.36
86
-     *
87
-     * @param array            $entity_response_array
88
-     * @param EEM_Base        $model
89
-     * @param string           $request_context
90
-     * @param WP_REST_Request $request
91
-     * @param Read             $controller
92
-     * @return array
93
-     */
94
-    public function removeCalculatedFieldsFromResponse(
95
-        $entity_response_array,
96
-        EEM_Base $model,
97
-        $request_context,
98
-        WP_REST_Request $request,
99
-        Read $controller
100
-    ) {
101
-        if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())) {
102
-            unset($entity_response_array['_calculated_fields']);
103
-        }
104
-        return $entity_response_array;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Removes the new headers for requests before 4.8.36
111
-     *
112
-     * @param array           $headers
113
-     * @param Controller_Base $controller
114
-     * @param string          $version
115
-     * @return array
116
-     */
117
-    public function removeHeadersNewInThisVersion(
118
-        $headers,
119
-        Controller_Base $controller,
120
-        $version
121
-    ) {
122
-        if ($this->appliesToVersion($version)) {
123
-            $headers = array_diff_key(
124
-                $headers,
125
-                array_flip(
126
-                    array(
127
-                        Base::HEADER_PREFIX_FOR_WP . 'Total',
128
-                        Base::HEADER_PREFIX_FOR_WP . 'TotalPages',
129
-                        Base::HEADER_PREFIX_FOR_WP . 'PageSize',
130
-                    )
131
-                )
132
-            );
133
-        }
134
-        return $headers;
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * Puts the 'featured_image_url' back in for responses before 4.8.36.
141
-     *
142
-     * @param array            $entity_response_array
143
-     * @param EEM_Base        $model
144
-     * @param string           $request_context
145
-     * @param WP_REST_Request $request
146
-     * @param Read             $controller
147
-     * @return array
148
-     */
149
-    public function addOldFeaturedImagePartOfCptEntities(
150
-        $entity_response_array,
151
-        EEM_Base $model,
152
-        $request_context,
153
-        WP_REST_Request $request,
154
-        Read $controller
155
-    ) {
156
-        if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())
157
-            && $model instanceof \EEM_CPT_Base
158
-        ) {
159
-            $attachment = wp_get_attachment_image_src(
160
-                get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]),
161
-                'full'
162
-            );
163
-            $entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
164
-        }
165
-        return $entity_response_array;
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * If the value was infinity, we now use null in our JSON responses,
172
-     * but before this version we used -1.
173
-     *
174
-     * @param mixed                $new_value
175
-     * @param \EE_Model_Field_Base $field_obj
176
-     * @param mixed                $original_value
177
-     * @param string               $requested_value
178
-     * @return mixed
179
-     */
180
-    public function useNegativeOneForInfinityBeforeThisVersion(
181
-        $new_value,
182
-        $field_obj,
183
-        $original_value,
184
-        $requested_value
185
-    ) {
186
-        if ($this->appliesToVersion($requested_value)
187
-            && $original_value === EE_INF
188
-        ) {
189
-            //return the old representation of infinity in the JSON
190
-            return -1;
191
-        }
192
-        return $new_value;
193
-    }
19
+	/**
20
+	 * Adds hooks so requests to 4.8.29 don't have the checkin endpoints
21
+	 */
22
+	public function setHooks()
23
+	{
24
+		//set a hook to remove the "calculate" query param
25
+		add_filter(
26
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
27
+			array($this, 'removeCalculateQueryParam'),
28
+			10,
29
+			3
30
+		);
31
+		//don't add the _calculated_fields either
32
+		add_filter(
33
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
34
+			array($this, 'removeCalculatedFieldsFromResponse'),
35
+			10,
36
+			5
37
+		);
38
+		//and also don't add the count headers
39
+		add_filter(
40
+			'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers',
41
+			array($this, 'removeHeadersNewInThisVersion'),
42
+			10,
43
+			3
44
+		);
45
+		//remove the old featured_image part of the response...
46
+		add_filter(
47
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
48
+			array($this, 'addOldFeaturedImagePartOfCptEntities'),
49
+			10,
50
+			5
51
+		);
52
+		//assuming ticket 9425's change gets pushed with 9406, we don't need to
53
+		//remove it from the calculated fields on older requests (because this will
54
+		//be the first version with calculated fields)
55
+		//before this, infinity was -1, now it's null
56
+		add_filter(
57
+			'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api',
58
+			array($this, 'useNegativeOneForInfinityBeforeThisVersion'),
59
+			10,
60
+			4
61
+		);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * Don't show "calculate" as an query param option in the index
68
+	 *
69
+	 * @param array     $query_params
70
+	 * @param EEM_Base $model
71
+	 * @param string    $version
72
+	 * @return array
73
+	 */
74
+	public function removeCalculateQueryParam($query_params, EEM_Base $model, $version)
75
+	{
76
+		if ($this->appliesToVersion($version)) {
77
+			unset($query_params['calculate']);
78
+		}
79
+		return $query_params;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Removes the "_calculate_fields" part of entity responses before 4.8.36
86
+	 *
87
+	 * @param array            $entity_response_array
88
+	 * @param EEM_Base        $model
89
+	 * @param string           $request_context
90
+	 * @param WP_REST_Request $request
91
+	 * @param Read             $controller
92
+	 * @return array
93
+	 */
94
+	public function removeCalculatedFieldsFromResponse(
95
+		$entity_response_array,
96
+		EEM_Base $model,
97
+		$request_context,
98
+		WP_REST_Request $request,
99
+		Read $controller
100
+	) {
101
+		if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())) {
102
+			unset($entity_response_array['_calculated_fields']);
103
+		}
104
+		return $entity_response_array;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Removes the new headers for requests before 4.8.36
111
+	 *
112
+	 * @param array           $headers
113
+	 * @param Controller_Base $controller
114
+	 * @param string          $version
115
+	 * @return array
116
+	 */
117
+	public function removeHeadersNewInThisVersion(
118
+		$headers,
119
+		Controller_Base $controller,
120
+		$version
121
+	) {
122
+		if ($this->appliesToVersion($version)) {
123
+			$headers = array_diff_key(
124
+				$headers,
125
+				array_flip(
126
+					array(
127
+						Base::HEADER_PREFIX_FOR_WP . 'Total',
128
+						Base::HEADER_PREFIX_FOR_WP . 'TotalPages',
129
+						Base::HEADER_PREFIX_FOR_WP . 'PageSize',
130
+					)
131
+				)
132
+			);
133
+		}
134
+		return $headers;
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * Puts the 'featured_image_url' back in for responses before 4.8.36.
141
+	 *
142
+	 * @param array            $entity_response_array
143
+	 * @param EEM_Base        $model
144
+	 * @param string           $request_context
145
+	 * @param WP_REST_Request $request
146
+	 * @param Read             $controller
147
+	 * @return array
148
+	 */
149
+	public function addOldFeaturedImagePartOfCptEntities(
150
+		$entity_response_array,
151
+		EEM_Base $model,
152
+		$request_context,
153
+		WP_REST_Request $request,
154
+		Read $controller
155
+	) {
156
+		if ($this->appliesToVersion($controller->getModelVersionInfo()->requestedVersion())
157
+			&& $model instanceof \EEM_CPT_Base
158
+		) {
159
+			$attachment = wp_get_attachment_image_src(
160
+				get_post_thumbnail_id($entity_response_array[$model->primary_key_name()]),
161
+				'full'
162
+			);
163
+			$entity_response_array['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null;
164
+		}
165
+		return $entity_response_array;
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * If the value was infinity, we now use null in our JSON responses,
172
+	 * but before this version we used -1.
173
+	 *
174
+	 * @param mixed                $new_value
175
+	 * @param \EE_Model_Field_Base $field_obj
176
+	 * @param mixed                $original_value
177
+	 * @param string               $requested_value
178
+	 * @return mixed
179
+	 */
180
+	public function useNegativeOneForInfinityBeforeThisVersion(
181
+		$new_value,
182
+		$field_obj,
183
+		$original_value,
184
+		$requested_value
185
+	) {
186
+		if ($this->appliesToVersion($requested_value)
187
+			&& $original_value === EE_INF
188
+		) {
189
+			//return the old representation of infinity in the JSON
190
+			return -1;
191
+		}
192
+		return $new_value;
193
+	}
194 194
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -124,9 +124,9 @@
 block discarded – undo
124 124
                 $headers,
125 125
                 array_flip(
126 126
                     array(
127
-                        Base::HEADER_PREFIX_FOR_WP . 'Total',
128
-                        Base::HEADER_PREFIX_FOR_WP . 'TotalPages',
129
-                        Base::HEADER_PREFIX_FOR_WP . 'PageSize',
127
+                        Base::HEADER_PREFIX_FOR_WP.'Total',
128
+                        Base::HEADER_PREFIX_FOR_WP.'TotalPages',
129
+                        Base::HEADER_PREFIX_FOR_WP.'PageSize',
130 130
                     )
131 131
                 )
132 132
             );
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @since                 $VID:$
18 18
  */
19 19
 if (! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -25,144 +25,144 @@  discard block
 block discarded – undo
25 25
 class Datetime extends Calculations_Base
26 26
 {
27 27
 
28
-    /**
29
-     * Calculates the total spaces available on the datetime, taking into account
30
-     * ticket limits too.
31
-     *
32
-     * @see EE_Datetime::spaces_remaining( true )
33
-     * @param array            $wpdb_row
34
-     * @param \WP_REST_Request $request
35
-     * @param Controller_Base  $controller
36
-     * @return int
37
-     * @throws \EE_Error
38
-     */
39
-    public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
40
-    {
41
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
42
-            $dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
43
-        } else {
44
-            $dtt_obj = null;
45
-        }
46
-        if ($dtt_obj instanceof EE_Datetime) {
47
-            return $dtt_obj->spaces_remaining(true);
48
-        } else {
49
-            throw new \EE_Error(
50
-                sprintf(
51
-                    __(
52
-                        // @codingStandardsIgnoreStart
53
-                        'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
54
-                        // @codingStandardsIgnoreEnd
55
-                        'event_espresso'
56
-                    ),
57
-                    $wpdb_row['Datetime.DTT_ID'],
58
-                    print_r($wpdb_row, true)
59
-                )
60
-            );
61
-        }
62
-    }
28
+	/**
29
+	 * Calculates the total spaces available on the datetime, taking into account
30
+	 * ticket limits too.
31
+	 *
32
+	 * @see EE_Datetime::spaces_remaining( true )
33
+	 * @param array            $wpdb_row
34
+	 * @param \WP_REST_Request $request
35
+	 * @param Controller_Base  $controller
36
+	 * @return int
37
+	 * @throws \EE_Error
38
+	 */
39
+	public static function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
40
+	{
41
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
42
+			$dtt_obj = EEM_Datetime::instance()->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
43
+		} else {
44
+			$dtt_obj = null;
45
+		}
46
+		if ($dtt_obj instanceof EE_Datetime) {
47
+			return $dtt_obj->spaces_remaining(true);
48
+		} else {
49
+			throw new \EE_Error(
50
+				sprintf(
51
+					__(
52
+						// @codingStandardsIgnoreStart
53
+						'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
54
+						// @codingStandardsIgnoreEnd
55
+						'event_espresso'
56
+					),
57
+					$wpdb_row['Datetime.DTT_ID'],
58
+					print_r($wpdb_row, true)
59
+				)
60
+			);
61
+		}
62
+	}
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * Counts registrations who have checked into this datetime
68
-     *
69
-     * @param array            $wpdb_row
70
-     * @param \WP_REST_Request $request
71
-     * @param Controller_Base  $controller
72
-     * @return int
73
-     * @throws \EE_Error
74
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
75
-     */
76
-    public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
77
-    {
78
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
79
-            throw new \EE_Error(
80
-                sprintf(
81
-                    __(
82
-                        // @codingStandardsIgnoreStart
83
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
84
-                        // @codingStandardsIgnoreEnd
85
-                        'event_espresso'
86
-                    ),
87
-                    print_r($wpdb_row, true)
88
-                )
89
-            );
90
-        }
91
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
92
-        return EEM_Registration::instance()
93
-                                ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
94
-    }
66
+	/**
67
+	 * Counts registrations who have checked into this datetime
68
+	 *
69
+	 * @param array            $wpdb_row
70
+	 * @param \WP_REST_Request $request
71
+	 * @param Controller_Base  $controller
72
+	 * @return int
73
+	 * @throws \EE_Error
74
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
75
+	 */
76
+	public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
77
+	{
78
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
79
+			throw new \EE_Error(
80
+				sprintf(
81
+					__(
82
+						// @codingStandardsIgnoreStart
83
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
84
+						// @codingStandardsIgnoreEnd
85
+						'event_espresso'
86
+					),
87
+					print_r($wpdb_row, true)
88
+				)
89
+			);
90
+		}
91
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
92
+		return EEM_Registration::instance()
93
+								->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
94
+	}
95 95
 
96 96
 
97 97
 
98
-    /**
99
-     * Counts registrations who have checked out of this datetime
100
-     *
101
-     * @param array            $wpdb_row
102
-     * @param \WP_REST_Request $request
103
-     * @param Controller_Base  $controller
104
-     * @return int
105
-     * @throws \EE_Error
106
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
107
-     */
108
-    public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
109
-    {
110
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
111
-            throw new \EE_Error(
112
-                sprintf(
113
-                    __(
114
-                        // @codingStandardsIgnoreStart
115
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
116
-                        // @codingStandardsIgnoreEnd
117
-                        'event_espresso'
118
-                    ),
119
-                    print_r($wpdb_row, true)
120
-                )
121
-            );
122
-        }
123
-        self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
124
-        return EEM_Registration::instance()
125
-                                ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
126
-    }
98
+	/**
99
+	 * Counts registrations who have checked out of this datetime
100
+	 *
101
+	 * @param array            $wpdb_row
102
+	 * @param \WP_REST_Request $request
103
+	 * @param Controller_Base  $controller
104
+	 * @return int
105
+	 * @throws \EE_Error
106
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
107
+	 */
108
+	public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
109
+	{
110
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
111
+			throw new \EE_Error(
112
+				sprintf(
113
+					__(
114
+						// @codingStandardsIgnoreStart
115
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
116
+						// @codingStandardsIgnoreEnd
117
+						'event_espresso'
118
+					),
119
+					print_r($wpdb_row, true)
120
+				)
121
+			);
122
+		}
123
+		self::verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
124
+		return EEM_Registration::instance()
125
+								->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
126
+	}
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * Counts the number of pending-payment registrations for this event (regardless
132
-     * of how many datetimes each registrations' ticket purchase is for)
133
-     *
134
-     * @param array            $wpdb_row
135
-     * @param \WP_REST_Request $request
136
-     * @param Controller_Base  $controller
137
-     * @return int
138
-     * @throws \EE_Error
139
-     * @throws \EventEspresso\core\libraries\rest_api\RestException
140
-     */
141
-    public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
142
-    {
143
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
144
-            throw new \EE_Error(
145
-                sprintf(
146
-                    __(
147
-                        // @codingStandardsIgnoreStart
148
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
149
-                        // @codingStandardsIgnoreEnd
150
-                        'event_espresso'
151
-                    ),
152
-                    print_r($wpdb_row, true)
153
-                )
154
-            );
155
-        }
156
-        self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
157
-        return EEM_Registration::instance()->count(
158
-            array(
159
-                array(
160
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
161
-                    'STS_ID'                 => EEM_Registration::status_id_pending_payment,
162
-                ),
163
-            ),
164
-            'REG_ID',
165
-            true
166
-        );
167
-    }
130
+	/**
131
+	 * Counts the number of pending-payment registrations for this event (regardless
132
+	 * of how many datetimes each registrations' ticket purchase is for)
133
+	 *
134
+	 * @param array            $wpdb_row
135
+	 * @param \WP_REST_Request $request
136
+	 * @param Controller_Base  $controller
137
+	 * @return int
138
+	 * @throws \EE_Error
139
+	 * @throws \EventEspresso\core\libraries\rest_api\RestException
140
+	 */
141
+	public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
142
+	{
143
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
144
+			throw new \EE_Error(
145
+				sprintf(
146
+					__(
147
+						// @codingStandardsIgnoreStart
148
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
149
+						// @codingStandardsIgnoreEnd
150
+						'event_espresso'
151
+					),
152
+					print_r($wpdb_row, true)
153
+				)
154
+			);
155
+		}
156
+		self::verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
157
+		return EEM_Registration::instance()->count(
158
+			array(
159
+				array(
160
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
161
+					'STS_ID'                 => EEM_Registration::status_id_pending_payment,
162
+				),
163
+			),
164
+			'REG_ID',
165
+			true
166
+		);
167
+	}
168 168
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @author                Mike Nelson
17 17
  * @since                 $VID:$
18 18
  */
19
-if (! defined('EVENT_ESPRESSO_VERSION')) {
19
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20 20
     exit('No direct script access allowed');
21 21
 }
22 22
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public static function registrationsCheckedInCount($wpdb_row, $request, $controller)
77 77
     {
78
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
78
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
79 79
             throw new \EE_Error(
80 80
                 sprintf(
81 81
                     __(
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public static function registrationsCheckedOutCount($wpdb_row, $request, $controller)
109 109
     {
110
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
110
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
111 111
             throw new \EE_Error(
112 112
                 sprintf(
113 113
                     __(
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public static function spotsTakenPendingPayment($wpdb_row, $request, $controller)
142 142
     {
143
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
143
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
144 144
             throw new \EE_Error(
145 145
                 sprintf(
146 146
                     __(
Please login to merge, or discard this patch.
core/libraries/rest_api/RestException.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @since                 $VID:$
13 13
  */
14 14
 if (! defined('EVENT_ESPRESSO_VERSION')) {
15
-    exit('No direct script access allowed');
15
+	exit('No direct script access allowed');
16 16
 }
17 17
 
18 18
 
@@ -20,54 +20,54 @@  discard block
 block discarded – undo
20 20
 class RestException extends \EE_Error
21 21
 {
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $wp_error_data = array();
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $wp_error_data = array();
27 27
 
28
-    protected $wp_error_code = '';
28
+	protected $wp_error_code = '';
29 29
 
30 30
 
31 31
 
32
-    public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
33
-    {
34
-        if (is_array($wp_error_data)
35
-            && isset($wp_error_data['status'])
36
-        ) {
37
-            $http_status_number = $wp_error_data['status'];
38
-        } else {
39
-            $http_status_number = 500;
40
-        }
41
-        parent::__construct(
42
-            $message,
43
-            $http_status_number,
44
-            $previous
45
-        );
46
-        $this->wp_error_data = $wp_error_data;
47
-        $this->wp_error_code = $string_code;
48
-    }
32
+	public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
33
+	{
34
+		if (is_array($wp_error_data)
35
+			&& isset($wp_error_data['status'])
36
+		) {
37
+			$http_status_number = $wp_error_data['status'];
38
+		} else {
39
+			$http_status_number = 500;
40
+		}
41
+		parent::__construct(
42
+			$message,
43
+			$http_status_number,
44
+			$previous
45
+		);
46
+		$this->wp_error_data = $wp_error_data;
47
+		$this->wp_error_code = $string_code;
48
+	}
49 49
 
50 50
 
51 51
 
52
-    /**
53
-     * Array of data that may have been set during the constructor, intended for WP_Error's data
54
-     *
55
-     * @return array
56
-     */
57
-    public function getData()
58
-    {
59
-        return $this->wp_error_data;
60
-    }
52
+	/**
53
+	 * Array of data that may have been set during the constructor, intended for WP_Error's data
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public function getData()
58
+	{
59
+		return $this->wp_error_data;
60
+	}
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * Gets the error string
66
-     *
67
-     * @return string
68
-     */
69
-    public function getStringCode()
70
-    {
71
-        return $this->wp_error_code;
72
-    }
64
+	/**
65
+	 * Gets the error string
66
+	 *
67
+	 * @return string
68
+	 */
69
+	public function getStringCode()
70
+	{
71
+		return $this->wp_error_code;
72
+	}
73 73
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/Capabilities.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EEH_Inflector;
6 6
 
7 7
 if (! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,158 +20,158 @@  discard block
 block discarded – undo
20 20
 class Capabilities
21 21
 {
22 22
 
23
-    /**
24
-     * The current user can see at least SOME of these entities.
25
-     *
26
-     * @param EEM_Base $model
27
-     * @param string    $model_context one of the return values from EEM_Base::valid_cap_contexts()
28
-     * @return boolean
29
-     */
30
-    public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
31
-    {
32
-        if (apply_filters(
33
-            'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
34
-            false,
35
-            $model,
36
-            $model
37
-        )) {
38
-            return true;
39
-        }
40
-        foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
41
-            if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
42
-                return false;
43
-            }
44
-        }
45
-        if (apply_filters(
46
-            'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
47
-            false,
48
-            $model,
49
-            $model
50
-        )) {
51
-            return false;
52
-        }
53
-        return true;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * Gets an array of all the capabilities the current user is missing that affected
60
-     * the query
61
-     *
62
-     * @param EEM_Base $model
63
-     * @param string    $request_type one of the constants on WP_JSON_Server
64
-     * @return array
65
-     */
66
-    public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
67
-    {
68
-        return $model->caps_missing($request_type);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * Gets a string of all the capabilities the current user is missing that affected
75
-     * the query
76
-     *
77
-     * @param EEM_Base $model
78
-     * @param string    $model_context one of the return values from EEM_Base::valid_cap_contexts()
79
-     * @return string
80
-     */
81
-    public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
82
-    {
83
-        return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
84
-    }
85
-
86
-
87
-
88
-    /**
89
-     * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
90
-     *
91
-     * @param array            $entity
92
-     * @param EEM_Base        $model
93
-     * @param string           $request_type         one of the return values from EEM_Base::valid_cap_contexts()
94
-     * @param ModelVersionInfo $model_version_info
95
-     * @param string           $primary_key_string   result of EEM_Base::get_index_primary_key_string(), so that we can
96
-     *                                               use this with models that have no primary key
97
-     * @return array ready for converting into json
98
-     */
99
-    public static function filterOutInaccessibleEntityFields(
100
-        $entity,
101
-        $model,
102
-        $request_type,
103
-        $model_version_info,
104
-        $primary_key_string = null
105
-    ) {
106
-        //if they didn't provide the primary key string, we'll just hope we can figure it out
107
-        //from the entity (although it's preferred client code does it, because the entity might be missing
108
-        //necessary fields for creating the primary key string, or they could be named differently)
109
-        if ($primary_key_string === null) {
110
-            $primary_key_string = $model->get_index_primary_key_string(
111
-                $model->deduce_fields_n_values_from_cols_n_values($entity)
112
-            );
113
-        }
114
-        //we only care to do this for frontend reads and when the user can't edit the item
115
-        if ($request_type !== EEM_Base::caps_read
116
-            || $model->exists(
117
-                $model->alter_query_params_to_restrict_by_ID(
118
-                    $primary_key_string,
119
-                    array(
120
-                        'default_where_conditions' => 'none',
121
-                        'caps'                     => EEM_Base::caps_edit,
122
-                    )
123
-                )
124
-            )
125
-        ) {
126
-            return $entity;
127
-        }
128
-        foreach ($model->field_settings() as $field_name => $field_obj) {
129
-            if ($model_version_info->fieldHasRenderedFormat($field_obj)
130
-                && isset($entity[$field_name])
131
-                && is_array($entity[$field_name])
132
-                && isset($entity[$field_name]['raw'])
133
-            ) {
134
-                unset($entity[$field_name]['raw']);
135
-            }
136
-        }
137
-        //theoretically we may want to filter out specific fields for specific models
138
-        return apply_filters(
139
-            'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
140
-            $entity,
141
-            $model,
142
-            $request_type
143
-        );
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * Verifies the current user has at least partial access to do this action on this model.
150
-     * If not, throws an exception (so we can define the code that sets up this error object
151
-     * once)
152
-     *
153
-     * @param EEM_Base $model
154
-     * @param string   $model_action_context
155
-     * @param string   $action_name
156
-     * @return void
157
-     * @throws RestException
158
-     */
159
-    public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
160
-    {
161
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
162
-            $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
163
-            throw new RestException(
164
-                sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
165
-                sprintf(
166
-                    __('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
167
-                    $action_name,
168
-                    $model_name_plural,
169
-                    Capabilities::getMissingPermissionsString($model, $model_action_context)
170
-                ),
171
-                array('status' => 403)
172
-            );
173
-        }
174
-    }
23
+	/**
24
+	 * The current user can see at least SOME of these entities.
25
+	 *
26
+	 * @param EEM_Base $model
27
+	 * @param string    $model_context one of the return values from EEM_Base::valid_cap_contexts()
28
+	 * @return boolean
29
+	 */
30
+	public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
31
+	{
32
+		if (apply_filters(
33
+			'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
34
+			false,
35
+			$model,
36
+			$model
37
+		)) {
38
+			return true;
39
+		}
40
+		foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
41
+			if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
42
+				return false;
43
+			}
44
+		}
45
+		if (apply_filters(
46
+			'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
47
+			false,
48
+			$model,
49
+			$model
50
+		)) {
51
+			return false;
52
+		}
53
+		return true;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * Gets an array of all the capabilities the current user is missing that affected
60
+	 * the query
61
+	 *
62
+	 * @param EEM_Base $model
63
+	 * @param string    $request_type one of the constants on WP_JSON_Server
64
+	 * @return array
65
+	 */
66
+	public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
67
+	{
68
+		return $model->caps_missing($request_type);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * Gets a string of all the capabilities the current user is missing that affected
75
+	 * the query
76
+	 *
77
+	 * @param EEM_Base $model
78
+	 * @param string    $model_context one of the return values from EEM_Base::valid_cap_contexts()
79
+	 * @return string
80
+	 */
81
+	public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
82
+	{
83
+		return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
84
+	}
85
+
86
+
87
+
88
+	/**
89
+	 * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
90
+	 *
91
+	 * @param array            $entity
92
+	 * @param EEM_Base        $model
93
+	 * @param string           $request_type         one of the return values from EEM_Base::valid_cap_contexts()
94
+	 * @param ModelVersionInfo $model_version_info
95
+	 * @param string           $primary_key_string   result of EEM_Base::get_index_primary_key_string(), so that we can
96
+	 *                                               use this with models that have no primary key
97
+	 * @return array ready for converting into json
98
+	 */
99
+	public static function filterOutInaccessibleEntityFields(
100
+		$entity,
101
+		$model,
102
+		$request_type,
103
+		$model_version_info,
104
+		$primary_key_string = null
105
+	) {
106
+		//if they didn't provide the primary key string, we'll just hope we can figure it out
107
+		//from the entity (although it's preferred client code does it, because the entity might be missing
108
+		//necessary fields for creating the primary key string, or they could be named differently)
109
+		if ($primary_key_string === null) {
110
+			$primary_key_string = $model->get_index_primary_key_string(
111
+				$model->deduce_fields_n_values_from_cols_n_values($entity)
112
+			);
113
+		}
114
+		//we only care to do this for frontend reads and when the user can't edit the item
115
+		if ($request_type !== EEM_Base::caps_read
116
+			|| $model->exists(
117
+				$model->alter_query_params_to_restrict_by_ID(
118
+					$primary_key_string,
119
+					array(
120
+						'default_where_conditions' => 'none',
121
+						'caps'                     => EEM_Base::caps_edit,
122
+					)
123
+				)
124
+			)
125
+		) {
126
+			return $entity;
127
+		}
128
+		foreach ($model->field_settings() as $field_name => $field_obj) {
129
+			if ($model_version_info->fieldHasRenderedFormat($field_obj)
130
+				&& isset($entity[$field_name])
131
+				&& is_array($entity[$field_name])
132
+				&& isset($entity[$field_name]['raw'])
133
+			) {
134
+				unset($entity[$field_name]['raw']);
135
+			}
136
+		}
137
+		//theoretically we may want to filter out specific fields for specific models
138
+		return apply_filters(
139
+			'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
140
+			$entity,
141
+			$model,
142
+			$request_type
143
+		);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * Verifies the current user has at least partial access to do this action on this model.
150
+	 * If not, throws an exception (so we can define the code that sets up this error object
151
+	 * once)
152
+	 *
153
+	 * @param EEM_Base $model
154
+	 * @param string   $model_action_context
155
+	 * @param string   $action_name
156
+	 * @return void
157
+	 * @throws RestException
158
+	 */
159
+	public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
160
+	{
161
+		if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
162
+			$model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
163
+			throw new RestException(
164
+				sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
165
+				sprintf(
166
+					__('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
167
+					$action_name,
168
+					$model_name_plural,
169
+					Capabilities::getMissingPermissionsString($model, $model_action_context)
170
+				),
171
+				array('status' => 403)
172
+			);
173
+		}
174
+	}
175 175
 }
176 176
 
177 177
 // End of file Capabilities.php
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EEM_Base;
5 5
 use EEH_Inflector;
6 6
 
7
-if (! defined('EVENT_ESPRESSO_VERSION')) {
7
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8 8
     exit('No direct script access allowed');
9 9
 }
10 10
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
160 160
     {
161
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
161
+        if ( ! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
162 162
             $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
163 163
             throw new RestException(
164 164
                 sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Meta.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 use EEM_System_Status;
12 12
 use EventEspresso\core\libraries\rest_api\ModelDataTranslator;
13 13
 
14
-if (! defined('EVENT_ESPRESSO_VERSION')) {
14
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
15 15
     exit('No direct script access allowed');
16 16
 }
17 17
 
Please login to merge, or discard this patch.
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use EventEspresso\core\libraries\rest_api\ModelDataTranslator;
12 12
 
13 13
 if (! defined('EVENT_ESPRESSO_VERSION')) {
14
-    exit('No direct script access allowed');
14
+	exit('No direct script access allowed');
15 15
 }
16 16
 
17 17
 
@@ -28,124 +28,124 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * @param \WP_REST_Request $request
33
-     * @param string           $version
34
-     * @return array|\WP_REST_Response
35
-     */
36
-    public static function handleRequestModelsMeta(\WP_REST_Request $request, $version)
37
-    {
38
-        $controller = new Meta();
39
-        try {
40
-            $controller->setRequestedVersion($version);
41
-            return $controller->sendResponse($controller->getModelsMetadataEntity());
42
-        } catch (Exception $e) {
43
-            return $controller->sendResponse($e);
44
-        }
45
-    }
31
+	/**
32
+	 * @param \WP_REST_Request $request
33
+	 * @param string           $version
34
+	 * @return array|\WP_REST_Response
35
+	 */
36
+	public static function handleRequestModelsMeta(\WP_REST_Request $request, $version)
37
+	{
38
+		$controller = new Meta();
39
+		try {
40
+			$controller->setRequestedVersion($version);
41
+			return $controller->sendResponse($controller->getModelsMetadataEntity());
42
+		} catch (Exception $e) {
43
+			return $controller->sendResponse($e);
44
+		}
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /*
49
+	/*
50 50
      * Gets the model metadata resource entity
51 51
      * @return array for JSON response, describing all the models available in teh requested version
52 52
      */
53
-    protected function getModelsMetadataEntity()
54
-    {
55
-        $response = array();
56
-        foreach ($this->getModelVersionInfo()->modelsForRequestedVersion() as $model_name => $model_classname) {
57
-            $model = $this->getModelVersionInfo()->loadModel($model_name);
58
-            $fields_json = array();
59
-            foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field_obj) {
60
-                if ($this->getModelVersionInfo()->fieldIsIgnored($field_obj)) {
61
-                    continue;
62
-                }
63
-                if ($field_obj instanceof EE_Boolean_Field) {
64
-                    $datatype = 'Boolean';
65
-                } elseif ($field_obj->get_wpdb_data_type() == '%d') {
66
-                    $datatype = 'Number';
67
-                } elseif ($field_name instanceof EE_Serialized_Text_Field) {
68
-                    $datatype = 'Object';
69
-                } else {
70
-                    $datatype = 'String';
71
-                }
72
-                $default_value = ModelDataTranslator::prepareFieldValueForJson(
73
-                    $field_obj,
74
-                    $field_obj->get_default_value(),
75
-                    $this->getModelVersionInfo()->requestedVersion()
76
-                );
77
-                $field_json = array(
78
-                    'name'                => $field_name,
79
-                    'nicename'            => wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES),
80
-                    'has_rendered_format' => $this->getModelVersionInfo()->fieldHasRenderedFormat($field_obj),
81
-                    'has_pretty_format'   => $this->getModelVersionInfo()->fieldHasPrettyFormat($field_obj),
82
-                    'type'                => str_replace('EE_', '', get_class($field_obj)),
83
-                    'datatype'            => $datatype,
84
-                    'nullable'            => $field_obj->is_nullable(),
85
-                    'default'             => $default_value,
86
-                    'table_alias'         => $field_obj->get_table_alias(),
87
-                    'table_column'        => $field_obj->get_table_column(),
88
-                );
89
-                $fields_json[$field_json['name']] = $field_json;
90
-            }
91
-            $fields_json = array_merge(
92
-                $fields_json,
93
-                $this->getModelVersionInfo()->extraResourcePropertiesForModel($model)
94
-            );
95
-            $response[$model_name]['fields'] = apply_filters(
96
-                'FHEE__Meta__handle_request_models_meta__fields',
97
-                $fields_json,
98
-                $model
99
-            );
100
-            $relations_json = array();
101
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
102
-                $relation_json = array(
103
-                    'name'   => $relation_name,
104
-                    'type'   => str_replace('EE_', '', get_class($relation_obj)),
105
-                    'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false,
106
-                );
107
-                $relations_json[$relation_name] = $relation_json;
108
-            }
109
-            $response[$model_name]['relations'] = apply_filters(
110
-                'FHEE__Meta__handle_request_models_meta__relations',
111
-                $relations_json,
112
-                $model
113
-            );
114
-        }
115
-        return $response;
116
-    }
53
+	protected function getModelsMetadataEntity()
54
+	{
55
+		$response = array();
56
+		foreach ($this->getModelVersionInfo()->modelsForRequestedVersion() as $model_name => $model_classname) {
57
+			$model = $this->getModelVersionInfo()->loadModel($model_name);
58
+			$fields_json = array();
59
+			foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field_obj) {
60
+				if ($this->getModelVersionInfo()->fieldIsIgnored($field_obj)) {
61
+					continue;
62
+				}
63
+				if ($field_obj instanceof EE_Boolean_Field) {
64
+					$datatype = 'Boolean';
65
+				} elseif ($field_obj->get_wpdb_data_type() == '%d') {
66
+					$datatype = 'Number';
67
+				} elseif ($field_name instanceof EE_Serialized_Text_Field) {
68
+					$datatype = 'Object';
69
+				} else {
70
+					$datatype = 'String';
71
+				}
72
+				$default_value = ModelDataTranslator::prepareFieldValueForJson(
73
+					$field_obj,
74
+					$field_obj->get_default_value(),
75
+					$this->getModelVersionInfo()->requestedVersion()
76
+				);
77
+				$field_json = array(
78
+					'name'                => $field_name,
79
+					'nicename'            => wp_specialchars_decode($field_obj->get_nicename(), ENT_QUOTES),
80
+					'has_rendered_format' => $this->getModelVersionInfo()->fieldHasRenderedFormat($field_obj),
81
+					'has_pretty_format'   => $this->getModelVersionInfo()->fieldHasPrettyFormat($field_obj),
82
+					'type'                => str_replace('EE_', '', get_class($field_obj)),
83
+					'datatype'            => $datatype,
84
+					'nullable'            => $field_obj->is_nullable(),
85
+					'default'             => $default_value,
86
+					'table_alias'         => $field_obj->get_table_alias(),
87
+					'table_column'        => $field_obj->get_table_column(),
88
+				);
89
+				$fields_json[$field_json['name']] = $field_json;
90
+			}
91
+			$fields_json = array_merge(
92
+				$fields_json,
93
+				$this->getModelVersionInfo()->extraResourcePropertiesForModel($model)
94
+			);
95
+			$response[$model_name]['fields'] = apply_filters(
96
+				'FHEE__Meta__handle_request_models_meta__fields',
97
+				$fields_json,
98
+				$model
99
+			);
100
+			$relations_json = array();
101
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
102
+				$relation_json = array(
103
+					'name'   => $relation_name,
104
+					'type'   => str_replace('EE_', '', get_class($relation_obj)),
105
+					'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false,
106
+				);
107
+				$relations_json[$relation_name] = $relation_json;
108
+			}
109
+			$response[$model_name]['relations'] = apply_filters(
110
+				'FHEE__Meta__handle_request_models_meta__relations',
111
+				$relations_json,
112
+				$model
113
+			);
114
+		}
115
+		return $response;
116
+	}
117 117
 
118 118
 
119 119
 
120
-    /**
121
-     * Adds EE metadata to the index
122
-     *
123
-     * @param \WP_REST_Response $rest_response_obj
124
-     * @return \WP_REST_Response
125
-     */
126
-    public static function filterEeMetadataIntoIndex(\WP_REST_Response $rest_response_obj)
127
-    {
128
-        $response_data = $rest_response_obj->get_data();
129
-        $addons = array();
130
-        foreach (EE_Registry::instance()->addons as $addon) {
131
-            $addon_json = array(
132
-                'name'    => $addon->name(),
133
-                'version' => $addon->version(),
134
-            );
135
-            $addons[$addon_json['name']] = $addon_json;
136
-        }
137
-        $response_data['ee'] = array(
138
-            'version'              => EEM_System_Status::instance()->get_ee_version(),
139
-            // @codingStandardsIgnoreStart
140
-            'documentation_url'    => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API',
141
-            // @codingStandardsIgnoreEnd
142
-            'addons'               => $addons,
143
-            'maintenance_mode'     => EE_Maintenance_Mode::instance()->real_level(),
144
-            'served_core_versions' => array_keys(EED_Core_Rest_Api::versions_served()),
145
-        );
146
-        $rest_response_obj->set_data($response_data);
147
-        return $rest_response_obj;
148
-    }
120
+	/**
121
+	 * Adds EE metadata to the index
122
+	 *
123
+	 * @param \WP_REST_Response $rest_response_obj
124
+	 * @return \WP_REST_Response
125
+	 */
126
+	public static function filterEeMetadataIntoIndex(\WP_REST_Response $rest_response_obj)
127
+	{
128
+		$response_data = $rest_response_obj->get_data();
129
+		$addons = array();
130
+		foreach (EE_Registry::instance()->addons as $addon) {
131
+			$addon_json = array(
132
+				'name'    => $addon->name(),
133
+				'version' => $addon->version(),
134
+			);
135
+			$addons[$addon_json['name']] = $addon_json;
136
+		}
137
+		$response_data['ee'] = array(
138
+			'version'              => EEM_System_Status::instance()->get_ee_version(),
139
+			// @codingStandardsIgnoreStart
140
+			'documentation_url'    => 'https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API',
141
+			// @codingStandardsIgnoreEnd
142
+			'addons'               => $addons,
143
+			'maintenance_mode'     => EE_Maintenance_Mode::instance()->real_level(),
144
+			'served_core_versions' => array_keys(EED_Core_Rest_Api::versions_served()),
145
+		);
146
+		$rest_response_obj->set_data($response_data);
147
+		return $rest_response_obj;
148
+	}
149 149
 }
150 150
 
151 151
 
Please login to merge, or discard this patch.