Completed
Branch dev (5b2722)
by
unknown
05:49 queued 10s
created
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -46,40 +46,40 @@  discard block
 block discarded – undo
46 46
             ? (string) $input->html_id()
47 47
             : spl_object_hash($input);
48 48
         // and add a generic input type class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
49
+        $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv';
50 50
         if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
52 52
         } elseif ($input instanceof EE_Submit_Input) {
53 53
             $html .= EEH_HTML::div(
54 54
                 $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
55
+                $html_id.'-submit-dv',
56 56
                 "{$input->html_class()}-submit-dv {$html_class}"
57 57
             );
58 58
         } elseif ($input instanceof EE_Select_Input) {
59 59
             $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
60
+                EEH_HTML::nl(1).$input->get_html_for_label().
61
+                EEH_HTML::nl().$input->get_html_for_errors().
62
+                EEH_HTML::nl().$input->get_html_for_input().
63
+                EEH_HTML::nl().$input->get_html_for_help(),
64
+                $html_id.'-input-dv',
65 65
                 "{$input->html_class()}-input-dv {$html_class}"
66 66
             );
67 67
         } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
68 68
             $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
69
+                EEH_HTML::nl().$this->_display_label_for_option_type_question($input).
70
+                EEH_HTML::nl().$input->get_html_for_errors().
71
+                EEH_HTML::nl().$input->get_html_for_input().
72
+                EEH_HTML::nl().$input->get_html_for_help(),
73
+                $html_id.'-input-dv',
74 74
                 "{$input->html_class()}-input-dv {$html_class}"
75 75
             );
76 76
         } else {
77 77
             $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
78
+                EEH_HTML::nl(1).$input->get_html_for_label().
79
+                EEH_HTML::nl().$input->get_html_for_errors().
80
+                EEH_HTML::nl().$input->get_html_for_input().
81
+                EEH_HTML::nl().$input->get_html_for_help(),
82
+                $html_id.'-input-dv',
83 83
                 "{$input->html_class()}-input-dv {$html_class}"
84 84
             );
85 85
         }
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
             $html_label_text = $input->html_label_text();
104 104
             $label_html = EEH_HTML::div(
105 105
                 $input->required()
106
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
106
+                    ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk')
107 107
                     : $html_label_text,
108 108
                 $input->html_label_id(),
109 109
                 $input->required()
110
-                    ? 'ee-required-label ' . $input->html_label_class()
110
+                    ? 'ee-required-label '.$input->html_label_class()
111 111
                     : $input->html_label_class(),
112 112
                 $input->html_label_style(),
113 113
                 $input->other_html_attributes()
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function layout_subsection($form_section)
134 134
     {
135
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
135
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
136 136
     }
137 137
 
138 138
 
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -11,136 +11,136 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
13 13
 {
14
-    /**
15
-     * opening div tag for a form
16
-     *
17
-     * @return string
18
-     */
19
-    public function layout_form_begin()
20
-    {
21
-        return EEH_HTML::div(
22
-            '',
23
-            $this->_form_section->html_id(),
24
-            $this->_form_section->html_class(),
25
-            $this->_form_section->html_style()
26
-        );
27
-    }
14
+	/**
15
+	 * opening div tag for a form
16
+	 *
17
+	 * @return string
18
+	 */
19
+	public function layout_form_begin()
20
+	{
21
+		return EEH_HTML::div(
22
+			'',
23
+			$this->_form_section->html_id(),
24
+			$this->_form_section->html_class(),
25
+			$this->_form_section->html_style()
26
+		);
27
+	}
28 28
 
29 29
 
30 30
 
31
-    /**
32
-     * Lays out the row for the input, including label and errors
33
-     *
34
-     * @param EE_Form_Input_Base $input
35
-     * @return string
36
-     * @throws \EE_Error
37
-     */
38
-    public function layout_input($input)
39
-    {
40
-        $html = '';
41
-        // set something unique for the id
42
-        $html_id = (string) $input->html_id() !== ''
43
-            ? (string) $input->html_id()
44
-            : spl_object_hash($input);
45
-        // and add a generic input type class
46
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
47
-        if ($input instanceof EE_Hidden_Input) {
48
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
49
-        } elseif ($input instanceof EE_Submit_Input) {
50
-            $html .= EEH_HTML::div(
51
-                $input->get_html_for_input(),
52
-                $html_id . '-submit-dv',
53
-                "{$input->html_class()}-submit-dv {$html_class}"
54
-            );
55
-        } elseif ($input instanceof EE_Select_Input) {
56
-            $html .= EEH_HTML::div(
57
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
58
-                EEH_HTML::nl() . $input->get_html_for_errors() .
59
-                EEH_HTML::nl() . $input->get_html_for_input() .
60
-                EEH_HTML::nl() . $input->get_html_for_help(),
61
-                $html_id . '-input-dv',
62
-                "{$input->html_class()}-input-dv {$html_class}"
63
-            );
64
-        } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
65
-            $html .= EEH_HTML::div(
66
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
67
-                EEH_HTML::nl() . $input->get_html_for_errors() .
68
-                EEH_HTML::nl() . $input->get_html_for_input() .
69
-                EEH_HTML::nl() . $input->get_html_for_help(),
70
-                $html_id . '-input-dv',
71
-                "{$input->html_class()}-input-dv {$html_class}"
72
-            );
73
-        } else {
74
-            $html .= EEH_HTML::div(
75
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
76
-                EEH_HTML::nl() . $input->get_html_for_errors() .
77
-                EEH_HTML::nl() . $input->get_html_for_input() .
78
-                EEH_HTML::nl() . $input->get_html_for_help(),
79
-                $html_id . '-input-dv',
80
-                "{$input->html_class()}-input-dv {$html_class}"
81
-            );
82
-        }
83
-        return $html;
84
-    }
31
+	/**
32
+	 * Lays out the row for the input, including label and errors
33
+	 *
34
+	 * @param EE_Form_Input_Base $input
35
+	 * @return string
36
+	 * @throws \EE_Error
37
+	 */
38
+	public function layout_input($input)
39
+	{
40
+		$html = '';
41
+		// set something unique for the id
42
+		$html_id = (string) $input->html_id() !== ''
43
+			? (string) $input->html_id()
44
+			: spl_object_hash($input);
45
+		// and add a generic input type class
46
+		$html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
47
+		if ($input instanceof EE_Hidden_Input) {
48
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
49
+		} elseif ($input instanceof EE_Submit_Input) {
50
+			$html .= EEH_HTML::div(
51
+				$input->get_html_for_input(),
52
+				$html_id . '-submit-dv',
53
+				"{$input->html_class()}-submit-dv {$html_class}"
54
+			);
55
+		} elseif ($input instanceof EE_Select_Input) {
56
+			$html .= EEH_HTML::div(
57
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
58
+				EEH_HTML::nl() . $input->get_html_for_errors() .
59
+				EEH_HTML::nl() . $input->get_html_for_input() .
60
+				EEH_HTML::nl() . $input->get_html_for_help(),
61
+				$html_id . '-input-dv',
62
+				"{$input->html_class()}-input-dv {$html_class}"
63
+			);
64
+		} elseif ($input instanceof EE_Form_Input_With_Options_Base) {
65
+			$html .= EEH_HTML::div(
66
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
67
+				EEH_HTML::nl() . $input->get_html_for_errors() .
68
+				EEH_HTML::nl() . $input->get_html_for_input() .
69
+				EEH_HTML::nl() . $input->get_html_for_help(),
70
+				$html_id . '-input-dv',
71
+				"{$input->html_class()}-input-dv {$html_class}"
72
+			);
73
+		} else {
74
+			$html .= EEH_HTML::div(
75
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
76
+				EEH_HTML::nl() . $input->get_html_for_errors() .
77
+				EEH_HTML::nl() . $input->get_html_for_input() .
78
+				EEH_HTML::nl() . $input->get_html_for_help(),
79
+				$html_id . '-input-dv',
80
+				"{$input->html_class()}-input-dv {$html_class}"
81
+			);
82
+		}
83
+		return $html;
84
+	}
85 85
 
86 86
 
87 87
 
88
-    /**
89
-     *
90
-     * _display_label_for_option_type_question
91
-     * Gets the HTML for the 'label', which is just text for this (because labels
92
-     * should be for each input)
93
-     *
94
-     * @param EE_Form_Input_With_Options_Base $input
95
-     * @return string
96
-     */
97
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
98
-    {
99
-        if ($input->display_html_label_text()) {
100
-            $html_label_text = $input->html_label_text();
101
-            $label_html = EEH_HTML::div(
102
-                $input->required()
103
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
104
-                    : $html_label_text,
105
-                $input->html_label_id(),
106
-                $input->required()
107
-                    ? 'ee-required-label ' . $input->html_label_class()
108
-                    : $input->html_label_class(),
109
-                $input->html_label_style(),
110
-                $input->other_html_attributes()
111
-            );
112
-            // if no content was provided to EEH_HTML::div() above (ie: an empty label),
113
-            // then we need to close the div manually
114
-            if (empty($html_label_text)) {
115
-                $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
116
-            }
117
-            return $label_html;
118
-        }
119
-        return '';
120
-    }
88
+	/**
89
+	 *
90
+	 * _display_label_for_option_type_question
91
+	 * Gets the HTML for the 'label', which is just text for this (because labels
92
+	 * should be for each input)
93
+	 *
94
+	 * @param EE_Form_Input_With_Options_Base $input
95
+	 * @return string
96
+	 */
97
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
98
+	{
99
+		if ($input->display_html_label_text()) {
100
+			$html_label_text = $input->html_label_text();
101
+			$label_html = EEH_HTML::div(
102
+				$input->required()
103
+					? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
104
+					: $html_label_text,
105
+				$input->html_label_id(),
106
+				$input->required()
107
+					? 'ee-required-label ' . $input->html_label_class()
108
+					: $input->html_label_class(),
109
+				$input->html_label_style(),
110
+				$input->other_html_attributes()
111
+			);
112
+			// if no content was provided to EEH_HTML::div() above (ie: an empty label),
113
+			// then we need to close the div manually
114
+			if (empty($html_label_text)) {
115
+				$label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
116
+			}
117
+			return $label_html;
118
+		}
119
+		return '';
120
+	}
121 121
 
122 122
 
123 123
 
124
-    /**
125
-     * Lays out a row for the subsection
126
-     *
127
-     * @param EE_Form_Section_Proper $form_section
128
-     * @return string
129
-     */
130
-    public function layout_subsection($form_section)
131
-    {
132
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
133
-    }
124
+	/**
125
+	 * Lays out a row for the subsection
126
+	 *
127
+	 * @param EE_Form_Section_Proper $form_section
128
+	 * @return string
129
+	 */
130
+	public function layout_subsection($form_section)
131
+	{
132
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
133
+	}
134 134
 
135 135
 
136 136
 
137
-    /**
138
-     * closing div tag for a form
139
-     *
140
-     * @return string
141
-     */
142
-    public function layout_form_end()
143
-    {
144
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
145
-    }
137
+	/**
138
+	 * closing div tag for a form
139
+	 *
140
+	 * @return string
141
+	 */
142
+	public function layout_form_end()
143
+	{
144
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/domain/services/admin/registrations/list_table/QueryBuilder.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             'caps'                     => EEM_Registration::caps_read_admin,
83 83
             'default_where_conditions' => 'this_model_only',
84 84
         ];
85
-        if (! $count_query) {
85
+        if ( ! $count_query) {
86 86
             $query_params = array_merge(
87 87
                 $query_params,
88 88
                 $this->getOrderbyClause(),
@@ -228,12 +228,12 @@  discard block
 block discarded – undo
228 228
                 [
229 229
                     $this->registration_model->convert_datetime_for_query(
230 230
                         'REG_date',
231
-                        $now . ' 00:00:00',
231
+                        $now.' 00:00:00',
232 232
                         'Y-m-d H:i:s'
233 233
                     ),
234 234
                     $this->registration_model->convert_datetime_for_query(
235 235
                         'REG_date',
236
-                        $now . ' 23:59:59',
236
+                        $now.' 23:59:59',
237 237
                         'Y-m-d H:i:s'
238 238
                     ),
239 239
                 ],
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
                 [
249 249
                     $this->registration_model->convert_datetime_for_query(
250 250
                         'REG_date',
251
-                        $current_year_and_month . '-01 00:00:00',
251
+                        $current_year_and_month.'-01 00:00:00',
252 252
                         'Y-m-d H:i:s'
253 253
                     ),
254 254
                     $this->registration_model->convert_datetime_for_query(
255 255
                         'REG_date',
256
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
256
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
257 257
                         'Y-m-d H:i:s'
258 258
                     ),
259 259
                 ],
@@ -272,18 +272,18 @@  discard block
 block discarded – undo
272 272
                 : '';
273 273
             // if there is not a month or year then we can't go further
274 274
             if ($month_requested && $year_requested) {
275
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
275
+                $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
276 276
                 $this->where_params['REG_date'] = [
277 277
                     'BETWEEN',
278 278
                     [
279 279
                         $this->registration_model->convert_datetime_for_query(
280 280
                             'REG_date',
281
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
281
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
282 282
                             'Y-m-d H:i:s'
283 283
                         ),
284 284
                         $this->registration_model->convert_datetime_for_query(
285 285
                             'REG_date',
286
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
286
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
287 287
                             'Y-m-d H:i:s'
288 288
                         ),
289 289
                     ],
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     {
301 301
         $search = $this->request->getRequestParam('s');
302 302
         if ($search) {
303
-            $search_string = '%' . sanitize_text_field($search) . '%';
303
+            $search_string = '%'.sanitize_text_field($search).'%';
304 304
             $this->where_params['OR*search_conditions'] = [
305 305
                 'Event.EVT_name'                          => ['LIKE', $search_string],
306 306
                 'Event.EVT_desc'                          => ['LIKE', $search_string],
Please login to merge, or discard this patch.
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -20,382 +20,382 @@
 block discarded – undo
20 20
  */
21 21
 class QueryBuilder
22 22
 {
23
-    /**
24
-     * @var RequestInterface $request
25
-     */
26
-    protected $request;
27
-
28
-    /**
29
-     * @var EEM_Registration $registration_model
30
-     */
31
-    protected $registration_model;
32
-
33
-    /**
34
-     * @var string $view
35
-     */
36
-    protected $view;
37
-
38
-    /**
39
-     * @var array $where_params
40
-     */
41
-    protected $where_params;
42
-
43
-
44
-    /**
45
-     * QueryBuilder constructor.
46
-     *
47
-     * @param RequestInterface $request
48
-     * @param EEM_Registration $registration_model
49
-     * @param array            $extra_request_params
50
-     */
51
-    public function __construct(
52
-        RequestInterface $request,
53
-        EEM_Registration $registration_model,
54
-        array $extra_request_params = []
55
-    ) {
56
-        $this->request = $request;
57
-        $this->registration_model = $registration_model;
58
-        foreach ($extra_request_params as $key => $value) {
59
-            $this->request->setRequestParam($key, $value);
60
-        }
61
-        $this->view = $this->request->getRequestParam('status', '');
62
-        $this->where_params = [];
63
-    }
64
-
65
-
66
-    /**
67
-     * Sets up the where conditions for the registrations query.
68
-     *
69
-     * @param int  $per_page
70
-     * @param bool $count_query
71
-     * @return array
72
-     * @throws EE_Error
73
-     * @throws InvalidArgumentException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     */
77
-    public function getQueryParams($per_page = 10, $count_query = false)
78
-    {
79
-        $query_params = [
80
-            0                          => $this->getWhereClause(),
81
-            'caps'                     => EEM_Registration::caps_read_admin,
82
-            'default_where_conditions' => 'this_model_only',
83
-        ];
84
-        if (! $count_query) {
85
-            $query_params = array_merge(
86
-                $query_params,
87
-                $this->getOrderbyClause(),
88
-                $this->getLimitClause($per_page)
89
-            );
90
-        }
91
-
92
-        return $query_params;
93
-    }
94
-
95
-
96
-    /**
97
-     * Sets up the where conditions for the registrations query.
98
-     *
99
-     * @return array
100
-     * @throws EE_Error
101
-     * @throws InvalidArgumentException
102
-     * @throws InvalidDataTypeException
103
-     * @throws InvalidInterfaceException
104
-     */
105
-    protected function getWhereClause()
106
-    {
107
-        $this->addAttendeeIdToWhereConditions();
108
-        $this->addEventIdToWhereConditions();
109
-        $this->addCategoryIdToWhereConditions();
110
-        $this->addDatetimeIdToWhereConditions();
111
-        $this->addTicketIdToWhereConditions();
112
-        $this->addRegistrationStatusToWhereConditions();
113
-        $this->addDateToWhereConditions();
114
-        $this->addSearchToWhereConditions();
115
-        return apply_filters(
116
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
117
-            $this->where_params,
118
-            $this->request->requestParams()
119
-        );
120
-    }
121
-
122
-
123
-    /**
124
-     * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
125
-     */
126
-    protected function addAttendeeIdToWhereConditions()
127
-    {
128
-        $ATT_ID = $this->request->getRequestParam('attendee_id');
129
-        $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int');
130
-        if ($ATT_ID) {
131
-            $this->where_params['ATT_ID'] = $ATT_ID;
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
138
-     */
139
-    protected function addEventIdToWhereConditions()
140
-    {
141
-        $EVT_ID = $this->request->getRequestParam('event_id');
142
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int');
143
-        if ($EVT_ID) {
144
-            $this->where_params['EVT_ID'] = $EVT_ID;
145
-        }
146
-    }
147
-
148
-
149
-    /**
150
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
151
-     */
152
-    protected function addCategoryIdToWhereConditions()
153
-    {
154
-        $EVT_CAT = (int) $this->request->getRequestParam('EVT_CAT', 0, 'int');
155
-        if ($EVT_CAT > 0) {
156
-            $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT;
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
163
-     */
164
-    protected function addDatetimeIdToWhereConditions()
165
-    {
166
-        // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
167
-        $DTT_ID = $this->request->getRequestParam('datetime_id');
168
-        $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, 'int');
169
-        if ($DTT_ID) {
170
-            $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID;
171
-        }
172
-    }
173
-
174
-
175
-    /**
176
-     * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
177
-     */
178
-    protected function addTicketIdToWhereConditions()
179
-    {
180
-        // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
181
-        $TKT_ID = $this->request->getRequestParam('ticket_id');
182
-        $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, 'int');
183
-        if ($TKT_ID) {
184
-            $this->where_params['TKT_ID'] = $TKT_ID;
185
-        }
186
-    }
187
-
188
-
189
-    /**
190
-     * Adds the correct registration status to the where conditions for the registrations query.
191
-     * If filtering by registration status, then we show registrations matching that status.
192
-     * If not filtering by specified status, then we show all registrations excluding incomplete registrations
193
-     * UNLESS viewing trashed registrations.
194
-     */
195
-    protected function addRegistrationStatusToWhereConditions()
196
-    {
197
-        $registration_status = $this->request->getRequestParam('_reg_status');
198
-        if ($registration_status) {
199
-            $this->where_params['STS_ID'] = sanitize_text_field($registration_status);
200
-            return;
201
-        }
202
-        // make sure we exclude incomplete registrations, but only if not trashed.
203
-        if ($this->view === 'trash') {
204
-            $this->where_params['REG_deleted'] = true;
205
-            return;
206
-        }
207
-        $this->where_params['STS_ID'] = $this->view === 'incomplete'
208
-            ? EEM_Registration::status_id_incomplete
209
-            : ['!=', EEM_Registration::status_id_incomplete];
210
-    }
211
-
212
-
213
-    /**
214
-     * Adds any provided date restraints to the where conditions for the registrations query.
215
-     *
216
-     * @throws EE_Error
217
-     * @throws InvalidArgumentException
218
-     * @throws InvalidDataTypeException
219
-     * @throws InvalidInterfaceException
220
-     */
221
-    protected function addDateToWhereConditions()
222
-    {
223
-        if ($this->view === 'today') {
224
-            $now = date('Y-m-d', current_time('timestamp'));
225
-            $this->where_params['REG_date'] = [
226
-                'BETWEEN',
227
-                [
228
-                    $this->registration_model->convert_datetime_for_query(
229
-                        'REG_date',
230
-                        $now . ' 00:00:00',
231
-                        'Y-m-d H:i:s'
232
-                    ),
233
-                    $this->registration_model->convert_datetime_for_query(
234
-                        'REG_date',
235
-                        $now . ' 23:59:59',
236
-                        'Y-m-d H:i:s'
237
-                    ),
238
-                ],
239
-            ];
240
-            return;
241
-        }
242
-        if ($this->view === 'month') {
243
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
244
-            $days_this_month = date('t', current_time('timestamp'));
245
-            $this->where_params['REG_date'] = [
246
-                'BETWEEN',
247
-                [
248
-                    $this->registration_model->convert_datetime_for_query(
249
-                        'REG_date',
250
-                        $current_year_and_month . '-01 00:00:00',
251
-                        'Y-m-d H:i:s'
252
-                    ),
253
-                    $this->registration_model->convert_datetime_for_query(
254
-                        'REG_date',
255
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
256
-                        'Y-m-d H:i:s'
257
-                    ),
258
-                ],
259
-            ];
260
-            return;
261
-        }
262
-        $month_range = $this->request->getRequestParam('month_range');
263
-        if ($month_range) {
264
-            $month_range = sanitize_text_field($month_range);
265
-            $pieces = explode(' ', $month_range, 3);
266
-            $month_requested = ! empty($pieces[0])
267
-                ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
268
-                : '';
269
-            $year_requested = ! empty($pieces[1])
270
-                ? $pieces[1]
271
-                : '';
272
-            // if there is not a month or year then we can't go further
273
-            if ($month_requested && $year_requested) {
274
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
275
-                $this->where_params['REG_date'] = [
276
-                    'BETWEEN',
277
-                    [
278
-                        $this->registration_model->convert_datetime_for_query(
279
-                            'REG_date',
280
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
281
-                            'Y-m-d H:i:s'
282
-                        ),
283
-                        $this->registration_model->convert_datetime_for_query(
284
-                            'REG_date',
285
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
286
-                            'Y-m-d H:i:s'
287
-                        ),
288
-                    ],
289
-                ];
290
-            }
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     * Adds any provided search restraints to the where conditions for the registrations query
297
-     */
298
-    protected function addSearchToWhereConditions()
299
-    {
300
-        $search = $this->request->getRequestParam('s');
301
-        if ($search) {
302
-            $search_string = '%' . sanitize_text_field($search) . '%';
303
-            $this->where_params['OR*search_conditions'] = [
304
-                'Event.EVT_name'                          => ['LIKE', $search_string],
305
-                'Event.EVT_desc'                          => ['LIKE', $search_string],
306
-                'Event.EVT_short_desc'                    => ['LIKE', $search_string],
307
-                'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
308
-                'Attendee.ATT_fname'                      => ['LIKE', $search_string],
309
-                'Attendee.ATT_lname'                      => ['LIKE', $search_string],
310
-                'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
311
-                'Attendee.ATT_email'                      => ['LIKE', $search_string],
312
-                'Attendee.ATT_address'                    => ['LIKE', $search_string],
313
-                'Attendee.ATT_address2'                   => ['LIKE', $search_string],
314
-                'Attendee.ATT_city'                       => ['LIKE', $search_string],
315
-                'REG_final_price'                         => ['LIKE', $search_string],
316
-                'REG_code'                                => ['LIKE', $search_string],
317
-                'REG_count'                               => ['LIKE', $search_string],
318
-                'REG_group_size'                          => ['LIKE', $search_string],
319
-                'Ticket.TKT_name'                         => ['LIKE', $search_string],
320
-                'Ticket.TKT_description'                  => ['LIKE', $search_string],
321
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
322
-            ];
323
-        }
324
-    }
325
-
326
-
327
-    /**
328
-     * Sets up the orderby for the registrations query.
329
-     *
330
-     * @return array
331
-     */
332
-    protected function getOrderbyClause()
333
-    {
334
-        $orderby_field = $this->request->getRequestParam('orderby');
335
-        $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
336
-        switch ($orderby_field) {
337
-            case '_REG_ID':
338
-                $orderby = ['REG_ID'];
339
-                break;
340
-            case '_Reg_status':
341
-                $orderby = ['STS_ID'];
342
-                break;
343
-            case 'ATT_fname':
344
-                $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
345
-                break;
346
-            case 'ATT_lname':
347
-                $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
348
-                break;
349
-            case 'event_name':
350
-                $orderby = ['Event.EVT_name'];
351
-                break;
352
-            case 'DTT_EVT_start':
353
-                $orderby = ['Event.Datetime.DTT_EVT_start'];
354
-                break;
355
-            case '_REG_date':
356
-                $orderby = ['REG_date'];
357
-                break;
358
-            default:
359
-                $orderby = [$orderby_field];
360
-                break;
361
-        }
362
-        $order = $this->request->getRequestParam('order');
363
-        $order = $order ? sanitize_text_field($order) : 'DESC';
364
-
365
-        $orderby = array_combine(
366
-            $orderby,
367
-            array_fill(0, count($orderby), $order)
368
-        );
369
-        // because there are many registrations with the same date, define
370
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
371
-        if (empty($orderby['REG_ID'])) {
372
-            $orderby['REG_ID'] = $order;
373
-        }
374
-
375
-        $orderby = apply_filters(
376
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
377
-            $orderby,
378
-            $this->request->requestParams()
379
-        );
380
-        return ['order_by' => $orderby];
381
-    }
382
-
383
-
384
-    /**
385
-     * Sets up the limit for the registrations query.
386
-     *
387
-     * @param $per_page
388
-     * @return array
389
-     */
390
-    protected function getLimitClause($per_page)
391
-    {
392
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
393
-        $per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
394
-        // -1 means return all results so get out if that's set.
395
-        if ($per_page === -1) {
396
-            return [];
397
-        }
398
-        $offset = ($current_page - 1) * $per_page;
399
-        return ['limit' => [$offset, $per_page]];
400
-    }
23
+	/**
24
+	 * @var RequestInterface $request
25
+	 */
26
+	protected $request;
27
+
28
+	/**
29
+	 * @var EEM_Registration $registration_model
30
+	 */
31
+	protected $registration_model;
32
+
33
+	/**
34
+	 * @var string $view
35
+	 */
36
+	protected $view;
37
+
38
+	/**
39
+	 * @var array $where_params
40
+	 */
41
+	protected $where_params;
42
+
43
+
44
+	/**
45
+	 * QueryBuilder constructor.
46
+	 *
47
+	 * @param RequestInterface $request
48
+	 * @param EEM_Registration $registration_model
49
+	 * @param array            $extra_request_params
50
+	 */
51
+	public function __construct(
52
+		RequestInterface $request,
53
+		EEM_Registration $registration_model,
54
+		array $extra_request_params = []
55
+	) {
56
+		$this->request = $request;
57
+		$this->registration_model = $registration_model;
58
+		foreach ($extra_request_params as $key => $value) {
59
+			$this->request->setRequestParam($key, $value);
60
+		}
61
+		$this->view = $this->request->getRequestParam('status', '');
62
+		$this->where_params = [];
63
+	}
64
+
65
+
66
+	/**
67
+	 * Sets up the where conditions for the registrations query.
68
+	 *
69
+	 * @param int  $per_page
70
+	 * @param bool $count_query
71
+	 * @return array
72
+	 * @throws EE_Error
73
+	 * @throws InvalidArgumentException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 */
77
+	public function getQueryParams($per_page = 10, $count_query = false)
78
+	{
79
+		$query_params = [
80
+			0                          => $this->getWhereClause(),
81
+			'caps'                     => EEM_Registration::caps_read_admin,
82
+			'default_where_conditions' => 'this_model_only',
83
+		];
84
+		if (! $count_query) {
85
+			$query_params = array_merge(
86
+				$query_params,
87
+				$this->getOrderbyClause(),
88
+				$this->getLimitClause($per_page)
89
+			);
90
+		}
91
+
92
+		return $query_params;
93
+	}
94
+
95
+
96
+	/**
97
+	 * Sets up the where conditions for the registrations query.
98
+	 *
99
+	 * @return array
100
+	 * @throws EE_Error
101
+	 * @throws InvalidArgumentException
102
+	 * @throws InvalidDataTypeException
103
+	 * @throws InvalidInterfaceException
104
+	 */
105
+	protected function getWhereClause()
106
+	{
107
+		$this->addAttendeeIdToWhereConditions();
108
+		$this->addEventIdToWhereConditions();
109
+		$this->addCategoryIdToWhereConditions();
110
+		$this->addDatetimeIdToWhereConditions();
111
+		$this->addTicketIdToWhereConditions();
112
+		$this->addRegistrationStatusToWhereConditions();
113
+		$this->addDateToWhereConditions();
114
+		$this->addSearchToWhereConditions();
115
+		return apply_filters(
116
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
117
+			$this->where_params,
118
+			$this->request->requestParams()
119
+		);
120
+	}
121
+
122
+
123
+	/**
124
+	 * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
125
+	 */
126
+	protected function addAttendeeIdToWhereConditions()
127
+	{
128
+		$ATT_ID = $this->request->getRequestParam('attendee_id');
129
+		$ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int');
130
+		if ($ATT_ID) {
131
+			$this->where_params['ATT_ID'] = $ATT_ID;
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
138
+	 */
139
+	protected function addEventIdToWhereConditions()
140
+	{
141
+		$EVT_ID = $this->request->getRequestParam('event_id');
142
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int');
143
+		if ($EVT_ID) {
144
+			$this->where_params['EVT_ID'] = $EVT_ID;
145
+		}
146
+	}
147
+
148
+
149
+	/**
150
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
151
+	 */
152
+	protected function addCategoryIdToWhereConditions()
153
+	{
154
+		$EVT_CAT = (int) $this->request->getRequestParam('EVT_CAT', 0, 'int');
155
+		if ($EVT_CAT > 0) {
156
+			$this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT;
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
163
+	 */
164
+	protected function addDatetimeIdToWhereConditions()
165
+	{
166
+		// first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
167
+		$DTT_ID = $this->request->getRequestParam('datetime_id');
168
+		$DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, 'int');
169
+		if ($DTT_ID) {
170
+			$this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID;
171
+		}
172
+	}
173
+
174
+
175
+	/**
176
+	 * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
177
+	 */
178
+	protected function addTicketIdToWhereConditions()
179
+	{
180
+		// first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
181
+		$TKT_ID = $this->request->getRequestParam('ticket_id');
182
+		$TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, 'int');
183
+		if ($TKT_ID) {
184
+			$this->where_params['TKT_ID'] = $TKT_ID;
185
+		}
186
+	}
187
+
188
+
189
+	/**
190
+	 * Adds the correct registration status to the where conditions for the registrations query.
191
+	 * If filtering by registration status, then we show registrations matching that status.
192
+	 * If not filtering by specified status, then we show all registrations excluding incomplete registrations
193
+	 * UNLESS viewing trashed registrations.
194
+	 */
195
+	protected function addRegistrationStatusToWhereConditions()
196
+	{
197
+		$registration_status = $this->request->getRequestParam('_reg_status');
198
+		if ($registration_status) {
199
+			$this->where_params['STS_ID'] = sanitize_text_field($registration_status);
200
+			return;
201
+		}
202
+		// make sure we exclude incomplete registrations, but only if not trashed.
203
+		if ($this->view === 'trash') {
204
+			$this->where_params['REG_deleted'] = true;
205
+			return;
206
+		}
207
+		$this->where_params['STS_ID'] = $this->view === 'incomplete'
208
+			? EEM_Registration::status_id_incomplete
209
+			: ['!=', EEM_Registration::status_id_incomplete];
210
+	}
211
+
212
+
213
+	/**
214
+	 * Adds any provided date restraints to the where conditions for the registrations query.
215
+	 *
216
+	 * @throws EE_Error
217
+	 * @throws InvalidArgumentException
218
+	 * @throws InvalidDataTypeException
219
+	 * @throws InvalidInterfaceException
220
+	 */
221
+	protected function addDateToWhereConditions()
222
+	{
223
+		if ($this->view === 'today') {
224
+			$now = date('Y-m-d', current_time('timestamp'));
225
+			$this->where_params['REG_date'] = [
226
+				'BETWEEN',
227
+				[
228
+					$this->registration_model->convert_datetime_for_query(
229
+						'REG_date',
230
+						$now . ' 00:00:00',
231
+						'Y-m-d H:i:s'
232
+					),
233
+					$this->registration_model->convert_datetime_for_query(
234
+						'REG_date',
235
+						$now . ' 23:59:59',
236
+						'Y-m-d H:i:s'
237
+					),
238
+				],
239
+			];
240
+			return;
241
+		}
242
+		if ($this->view === 'month') {
243
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
244
+			$days_this_month = date('t', current_time('timestamp'));
245
+			$this->where_params['REG_date'] = [
246
+				'BETWEEN',
247
+				[
248
+					$this->registration_model->convert_datetime_for_query(
249
+						'REG_date',
250
+						$current_year_and_month . '-01 00:00:00',
251
+						'Y-m-d H:i:s'
252
+					),
253
+					$this->registration_model->convert_datetime_for_query(
254
+						'REG_date',
255
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
256
+						'Y-m-d H:i:s'
257
+					),
258
+				],
259
+			];
260
+			return;
261
+		}
262
+		$month_range = $this->request->getRequestParam('month_range');
263
+		if ($month_range) {
264
+			$month_range = sanitize_text_field($month_range);
265
+			$pieces = explode(' ', $month_range, 3);
266
+			$month_requested = ! empty($pieces[0])
267
+				? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
268
+				: '';
269
+			$year_requested = ! empty($pieces[1])
270
+				? $pieces[1]
271
+				: '';
272
+			// if there is not a month or year then we can't go further
273
+			if ($month_requested && $year_requested) {
274
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
275
+				$this->where_params['REG_date'] = [
276
+					'BETWEEN',
277
+					[
278
+						$this->registration_model->convert_datetime_for_query(
279
+							'REG_date',
280
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
281
+							'Y-m-d H:i:s'
282
+						),
283
+						$this->registration_model->convert_datetime_for_query(
284
+							'REG_date',
285
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
286
+							'Y-m-d H:i:s'
287
+						),
288
+					],
289
+				];
290
+			}
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 * Adds any provided search restraints to the where conditions for the registrations query
297
+	 */
298
+	protected function addSearchToWhereConditions()
299
+	{
300
+		$search = $this->request->getRequestParam('s');
301
+		if ($search) {
302
+			$search_string = '%' . sanitize_text_field($search) . '%';
303
+			$this->where_params['OR*search_conditions'] = [
304
+				'Event.EVT_name'                          => ['LIKE', $search_string],
305
+				'Event.EVT_desc'                          => ['LIKE', $search_string],
306
+				'Event.EVT_short_desc'                    => ['LIKE', $search_string],
307
+				'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
308
+				'Attendee.ATT_fname'                      => ['LIKE', $search_string],
309
+				'Attendee.ATT_lname'                      => ['LIKE', $search_string],
310
+				'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
311
+				'Attendee.ATT_email'                      => ['LIKE', $search_string],
312
+				'Attendee.ATT_address'                    => ['LIKE', $search_string],
313
+				'Attendee.ATT_address2'                   => ['LIKE', $search_string],
314
+				'Attendee.ATT_city'                       => ['LIKE', $search_string],
315
+				'REG_final_price'                         => ['LIKE', $search_string],
316
+				'REG_code'                                => ['LIKE', $search_string],
317
+				'REG_count'                               => ['LIKE', $search_string],
318
+				'REG_group_size'                          => ['LIKE', $search_string],
319
+				'Ticket.TKT_name'                         => ['LIKE', $search_string],
320
+				'Ticket.TKT_description'                  => ['LIKE', $search_string],
321
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
322
+			];
323
+		}
324
+	}
325
+
326
+
327
+	/**
328
+	 * Sets up the orderby for the registrations query.
329
+	 *
330
+	 * @return array
331
+	 */
332
+	protected function getOrderbyClause()
333
+	{
334
+		$orderby_field = $this->request->getRequestParam('orderby');
335
+		$orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
336
+		switch ($orderby_field) {
337
+			case '_REG_ID':
338
+				$orderby = ['REG_ID'];
339
+				break;
340
+			case '_Reg_status':
341
+				$orderby = ['STS_ID'];
342
+				break;
343
+			case 'ATT_fname':
344
+				$orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
345
+				break;
346
+			case 'ATT_lname':
347
+				$orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
348
+				break;
349
+			case 'event_name':
350
+				$orderby = ['Event.EVT_name'];
351
+				break;
352
+			case 'DTT_EVT_start':
353
+				$orderby = ['Event.Datetime.DTT_EVT_start'];
354
+				break;
355
+			case '_REG_date':
356
+				$orderby = ['REG_date'];
357
+				break;
358
+			default:
359
+				$orderby = [$orderby_field];
360
+				break;
361
+		}
362
+		$order = $this->request->getRequestParam('order');
363
+		$order = $order ? sanitize_text_field($order) : 'DESC';
364
+
365
+		$orderby = array_combine(
366
+			$orderby,
367
+			array_fill(0, count($orderby), $order)
368
+		);
369
+		// because there are many registrations with the same date, define
370
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
371
+		if (empty($orderby['REG_ID'])) {
372
+			$orderby['REG_ID'] = $order;
373
+		}
374
+
375
+		$orderby = apply_filters(
376
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
377
+			$orderby,
378
+			$this->request->requestParams()
379
+		);
380
+		return ['order_by' => $orderby];
381
+	}
382
+
383
+
384
+	/**
385
+	 * Sets up the limit for the registrations query.
386
+	 *
387
+	 * @param $per_page
388
+	 * @return array
389
+	 */
390
+	protected function getLimitClause($per_page)
391
+	{
392
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
393
+		$per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
394
+		// -1 means return all results so get out if that's set.
395
+		if ($per_page === -1) {
396
+			return [];
397
+		}
398
+		$offset = ($current_page - 1) * $per_page;
399
+		return ['limit' => [$offset, $per_page]];
400
+	}
401 401
 }
Please login to merge, or discard this patch.
core/domain/services/converters/json/DatetimeToJson.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         $jsonDates = [];
38 38
         foreach ($datetimes as $datetime) {
39 39
             if ($datetime instanceof EE_Datetime) {
40
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
40
+                $jsonDates[$datetime->ID()] = $this->convertAndEncode($datetime);
41 41
             }
42 42
         }
43 43
         return $jsonDates;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         $arrayOfDates = [];
76 76
         foreach ($datetimes as $datetime) {
77 77
             if ($datetime instanceof EE_Datetime) {
78
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
78
+                $arrayOfDates[$datetime->ID()] = $this->convert($datetime);
79 79
             }
80 80
         }
81 81
         return $arrayOfDates;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $jsonDates = [];
128 128
         foreach ($datetimes as $datetime) {
129 129
             if ($datetime instanceof EE_Datetime) {
130
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
130
+                $jsonDates[$datetime->ID()] = $this->encode($datetime);
131 131
             }
132 132
         }
133 133
         return $jsonDates;
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -21,125 +21,125 @@
 block discarded – undo
21 21
  */
22 22
 class DatetimeToJson implements ModelObjectToJsonConverterInterface
23 23
 {
24
-    /**
25
-     * @param EE_Datetime[] $datetimes
26
-     * @return array
27
-     * @throws EE_Error
28
-     * @throws InvalidArgumentException
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     * @throws ReflectionException
32
-     * @since $VID:$
33
-     */
34
-    public function convertAndEncodeArrayOf(array $datetimes)
35
-    {
36
-        $jsonDates = [];
37
-        foreach ($datetimes as $datetime) {
38
-            if ($datetime instanceof EE_Datetime) {
39
-                $jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
40
-            }
41
-        }
42
-        return $jsonDates;
43
-    }
24
+	/**
25
+	 * @param EE_Datetime[] $datetimes
26
+	 * @return array
27
+	 * @throws EE_Error
28
+	 * @throws InvalidArgumentException
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 * @throws ReflectionException
32
+	 * @since $VID:$
33
+	 */
34
+	public function convertAndEncodeArrayOf(array $datetimes)
35
+	{
36
+		$jsonDates = [];
37
+		foreach ($datetimes as $datetime) {
38
+			if ($datetime instanceof EE_Datetime) {
39
+				$jsonDates[ $datetime->ID() ] = $this->convertAndEncode($datetime);
40
+			}
41
+		}
42
+		return $jsonDates;
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * @param EE_Datetime $datetime
48
-     * @return false|string
49
-     * @throws EE_Error
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidDataTypeException
52
-     * @throws InvalidInterfaceException
53
-     * @throws ReflectionException
54
-     * @since $VID:$
55
-     */
56
-    public function convertAndEncode($datetime)
57
-    {
58
-        return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
59
-    }
46
+	/**
47
+	 * @param EE_Datetime $datetime
48
+	 * @return false|string
49
+	 * @throws EE_Error
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidDataTypeException
52
+	 * @throws InvalidInterfaceException
53
+	 * @throws ReflectionException
54
+	 * @since $VID:$
55
+	 */
56
+	public function convertAndEncode($datetime)
57
+	{
58
+		return $datetime instanceof EE_Datetime ? $this->encode($this->convert($datetime)) : false;
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * @param EE_Datetime[] $datetimes
64
-     * @return array
65
-     * @throws EE_Error
66
-     * @throws InvalidArgumentException
67
-     * @throws InvalidDataTypeException
68
-     * @throws InvalidInterfaceException
69
-     * @throws ReflectionException
70
-     * @since $VID:$
71
-     */
72
-    public function convertArrayOf(array $datetimes)
73
-    {
74
-        $arrayOfDates = [];
75
-        foreach ($datetimes as $datetime) {
76
-            if ($datetime instanceof EE_Datetime) {
77
-                $arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
78
-            }
79
-        }
80
-        return $arrayOfDates;
81
-    }
62
+	/**
63
+	 * @param EE_Datetime[] $datetimes
64
+	 * @return array
65
+	 * @throws EE_Error
66
+	 * @throws InvalidArgumentException
67
+	 * @throws InvalidDataTypeException
68
+	 * @throws InvalidInterfaceException
69
+	 * @throws ReflectionException
70
+	 * @since $VID:$
71
+	 */
72
+	public function convertArrayOf(array $datetimes)
73
+	{
74
+		$arrayOfDates = [];
75
+		foreach ($datetimes as $datetime) {
76
+			if ($datetime instanceof EE_Datetime) {
77
+				$arrayOfDates[ $datetime->ID() ] = $this->convert($datetime);
78
+			}
79
+		}
80
+		return $arrayOfDates;
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * @param EE_Datetime $datetime
86
-     * @return array
87
-     * @throws EE_Error
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidArgumentException
91
-     * @throws ReflectionException
92
-     * @since $VID:$
93
-     */
94
-    public function convert($datetime)
95
-    {
96
-        return $datetime instanceof EE_Datetime ? [
97
-            'DTT_ID'          => $datetime->ID(),
98
-            'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
99
-            'DTT_name'        => $datetime->name(),
100
-            'DTT_description' => $datetime->description(),
101
-            'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
102
-            'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
103
-            'DTT_sold'        => $datetime->sold(),
104
-            'DTT_reserved'    => $datetime->reserved(),
105
-            'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
106
-            'DTT_is_primary'  => $datetime->get_active_status(),
107
-            'DTT_order'       => $datetime->order(),
108
-            'DTT_parent'      => $datetime->parent(),
109
-            'DTT_deleted'     => $datetime->get('DTT_deleted'),
110
-        ] : [];
111
-    }
84
+	/**
85
+	 * @param EE_Datetime $datetime
86
+	 * @return array
87
+	 * @throws EE_Error
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidArgumentException
91
+	 * @throws ReflectionException
92
+	 * @since $VID:$
93
+	 */
94
+	public function convert($datetime)
95
+	{
96
+		return $datetime instanceof EE_Datetime ? [
97
+			'DTT_ID'          => $datetime->ID(),
98
+			'EVT_ID'          => $datetime->event() instanceof EE_Event ? $datetime->event()->ID() : 0,
99
+			'DTT_name'        => $datetime->name(),
100
+			'DTT_description' => $datetime->description(),
101
+			'DTT_EVT_start'   => $datetime->start_date(DATE_ATOM),
102
+			'DTT_EVT_end'     => $datetime->end_date(DATE_ATOM),
103
+			'DTT_sold'        => $datetime->sold(),
104
+			'DTT_reserved'    => $datetime->reserved(),
105
+			'DTT_reg_limit'   => $datetime->reg_limit() === INF ? -1 : $datetime->reg_limit(),
106
+			'DTT_is_primary'  => $datetime->get_active_status(),
107
+			'DTT_order'       => $datetime->order(),
108
+			'DTT_parent'      => $datetime->parent(),
109
+			'DTT_deleted'     => $datetime->get('DTT_deleted'),
110
+		] : [];
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * @param EE_Datetime[] $datetimes
116
-     * @return array
117
-     * @throws EE_Error
118
-     * @throws InvalidArgumentException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     * @throws ReflectionException
122
-     * @since $VID:$
123
-     */
124
-    public function encodeArrayOf(array $datetimes)
125
-    {
126
-        $jsonDates = [];
127
-        foreach ($datetimes as $datetime) {
128
-            if ($datetime instanceof EE_Datetime) {
129
-                $jsonDates[ $datetime->ID() ] = $this->encode($datetime);
130
-            }
131
-        }
132
-        return $jsonDates;
133
-    }
114
+	/**
115
+	 * @param EE_Datetime[] $datetimes
116
+	 * @return array
117
+	 * @throws EE_Error
118
+	 * @throws InvalidArgumentException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 * @throws ReflectionException
122
+	 * @since $VID:$
123
+	 */
124
+	public function encodeArrayOf(array $datetimes)
125
+	{
126
+		$jsonDates = [];
127
+		foreach ($datetimes as $datetime) {
128
+			if ($datetime instanceof EE_Datetime) {
129
+				$jsonDates[ $datetime->ID() ] = $this->encode($datetime);
130
+			}
131
+		}
132
+		return $jsonDates;
133
+	}
134 134
 
135 135
 
136
-    /**
137
-     * @param array $datetime_array
138
-     * @return false|string
139
-     * @since $VID:$
140
-     */
141
-    public function encode(array $datetime_array)
142
-    {
143
-        return wp_json_encode($datetime_array);
144
-    }
136
+	/**
137
+	 * @param array $datetime_array
138
+	 * @return false|string
139
+	 * @since $VID:$
140
+	 */
141
+	public function encode(array $datetime_array)
142
+	{
143
+		return wp_json_encode($datetime_array);
144
+	}
145 145
 }
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
         $version = ''
177 177
     ) {
178 178
         $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
179
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
180 180
         return $this->addJavascript(
181 181
             $handle,
182 182
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -23,332 +23,332 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection|Asset[] $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        $this->registry->addAssetCollection($assets);
55
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return AssetCollection
62
-     */
63
-    public function getAssets()
64
-    {
65
-        return $this->assets;
66
-    }
67
-
68
-
69
-    /**
70
-     * @since 4.9.71.p
71
-     * @return string
72
-     */
73
-    public function assetNamespace()
74
-    {
75
-        return $this->domain->assetNamespace();
76
-    }
77
-
78
-
79
-    /**
80
-     * @param string $handle
81
-     * @param string $source
82
-     * @param array  $dependencies
83
-     * @param bool   $load_in_footer
84
-     * @param string $version
85
-     * @return JavascriptAsset
86
-     * @throws DuplicateCollectionIdentifierException
87
-     * @throws InvalidDataTypeException
88
-     * @throws InvalidEntityException
89
-     * @throws DomainException
90
-     * @since 4.9.62.p
91
-     */
92
-    public function addJavascript(
93
-        $handle,
94
-        $source,
95
-        array $dependencies = array(),
96
-        $load_in_footer = true,
97
-        $version = ''
98
-    ) {
99
-        $asset = new JavascriptAsset(
100
-            $handle,
101
-            $source,
102
-            array_unique($dependencies),
103
-            $load_in_footer,
104
-            $this->domain,
105
-            $version
106
-        );
107
-        $this->assets->add($asset, $handle);
108
-        return $asset;
109
-    }
110
-
111
-
112
-    /**
113
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
-     *
115
-     * @param string       $handle
116
-     * @param string|array $extra_dependencies
117
-     * @return JavascriptAsset
118
-     * @throws DuplicateCollectionIdentifierException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     */
123
-    public function addJs($handle, $extra_dependencies = [])
124
-    {
125
-        $details = $this->getAssetDetails(
126
-            Asset::TYPE_JS,
127
-            $handle,
128
-            $extra_dependencies
129
-        );
130
-        $source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
-        return $this->addJavascript(
132
-            $handle,
133
-            $source,
134
-            $details['dependencies'],
135
-            true,
136
-            $details['version']
137
-        );
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string $handle
143
-     * @param array  $dependencies
144
-     * @param bool   $load_in_footer
145
-     * @param string $version
146
-     * @return JavascriptAsset
147
-     * @throws DomainException
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @since 4.9.71.p
152
-     */
153
-    public function addVendorJavascript(
154
-        $handle,
155
-        array $dependencies = array(),
156
-        $load_in_footer = true,
157
-        $version = ''
158
-    ) {
159
-        $dev_suffix = wp_scripts_get_suffix('dev');
160
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
-        return $this->addJavascript(
162
-            $handle,
163
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
164
-            $dependencies,
165
-            $load_in_footer,
166
-            $version
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @param string $handle
173
-     * @param string $source
174
-     * @param array  $dependencies
175
-     * @param string $media
176
-     * @param string $version
177
-     * @return StylesheetAsset
178
-     * @throws DomainException
179
-     * @throws DuplicateCollectionIdentifierException
180
-     * @throws InvalidDataTypeException
181
-     * @throws InvalidEntityException
182
-     * @since 4.9.62.p
183
-     */
184
-    public function addStylesheet(
185
-        $handle,
186
-        $source,
187
-        array $dependencies = array(),
188
-        $media = 'all',
189
-        $version = ''
190
-    ) {
191
-        $asset = new StylesheetAsset(
192
-            $handle,
193
-            $source,
194
-            array_unique($dependencies),
195
-            $this->domain,
196
-            $media,
197
-            $version
198
-        );
199
-        $this->assets->add($asset, $handle);
200
-        return $asset;
201
-    }
202
-
203
-
204
-    /**
205
-     * Used to register a css asset where everything is dynamically derived from the given handle.
206
-     *
207
-     * @param string       $handle
208
-     * @param string|array $extra_dependencies
209
-     * @return StylesheetAsset
210
-     * @throws DuplicateCollectionIdentifierException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidEntityException
213
-     * @throws DomainException
214
-     */
215
-    public function addCss($handle, $extra_dependencies = [])
216
-    {
217
-        $details = $this->getAssetDetails(
218
-            Asset::TYPE_CSS,
219
-            $handle,
220
-            $extra_dependencies
221
-        );
222
-        return $this->addStylesheet(
223
-            $handle,
224
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
-            $details['dependencies'],
226
-            'all',
227
-            $details['version']
228
-        );
229
-    }
230
-
231
-
232
-    /**
233
-     * @param string $handle
234
-     * @return bool
235
-     * @since 4.9.62.p
236
-     */
237
-    public function enqueueAsset($handle)
238
-    {
239
-        if ($this->assets->has($handle)) {
240
-            /** @var Asset $asset */
241
-            $asset = $this->assets->get($handle);
242
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
-                $asset->enqueueAsset();
244
-                return true;
245
-            }
246
-        }
247
-        return false;
248
-    }
249
-
250
-
251
-    /**
252
-     * @return  void
253
-     * @since   $VID:$
254
-     */
255
-    public function enqueueBrowserAssets()
256
-    {
257
-        foreach ($this->assets as $asset) {
258
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
-                $asset->enqueueAsset();
260
-            }
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $asset_type
267
-     * @param string $handle
268
-     * @param array  $extra_dependencies
269
-     * @return array
270
-     * @since 4.10.2.p
271
-     */
272
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
-    {
274
-        $getAssetDetails = '';
275
-        switch ($asset_type) {
276
-            case Asset::TYPE_JS :
277
-                $getAssetDetails = 'getJsAssetDetails';
278
-                break;
279
-            case Asset::TYPE_CSS :
280
-                $getAssetDetails = 'getCssAssetDetails';
281
-                break;
282
-        }
283
-        if ($getAssetDetails === '') {
284
-            return ['dependencies' => [], 'version' => ''];
285
-        }
286
-        $details = $this->registry->$getAssetDetails(
287
-            $this->domain->assetNamespace(),
288
-            $handle
289
-        );
290
-        $details['dependencies'] = isset($details['dependencies'])
291
-            ? $details['dependencies']
292
-            : [];
293
-        $details['version'] = isset($details['version'])
294
-            ? $details['version']
295
-            : '';
296
-        $details['dependencies'] = ! empty($extra_dependencies)
297
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
298
-            : $details['dependencies'];
299
-        return $details;
300
-
301
-    }
302
-
303
-
304
-    /**
305
-     * @param string $handle
306
-     * @return bool
307
-     * @throws DomainException
308
-     */
309
-    public function verifyAssetIsRegistered($handle)
310
-    {
311
-        if (wp_script_is($handle, 'registered')) {
312
-            return true;
313
-        }
314
-        if (WP_DEBUG) {
315
-            throw new DomainException(
316
-                sprintf(
317
-                    esc_html__(
318
-                        'The "%1$s" script is not registered when it should be!%2$s
26
+	/**
27
+	 * @var AssetCollection|Asset[] $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		$this->registry->addAssetCollection($assets);
55
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
56
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return AssetCollection
62
+	 */
63
+	public function getAssets()
64
+	{
65
+		return $this->assets;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @since 4.9.71.p
71
+	 * @return string
72
+	 */
73
+	public function assetNamespace()
74
+	{
75
+		return $this->domain->assetNamespace();
76
+	}
77
+
78
+
79
+	/**
80
+	 * @param string $handle
81
+	 * @param string $source
82
+	 * @param array  $dependencies
83
+	 * @param bool   $load_in_footer
84
+	 * @param string $version
85
+	 * @return JavascriptAsset
86
+	 * @throws DuplicateCollectionIdentifierException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws InvalidEntityException
89
+	 * @throws DomainException
90
+	 * @since 4.9.62.p
91
+	 */
92
+	public function addJavascript(
93
+		$handle,
94
+		$source,
95
+		array $dependencies = array(),
96
+		$load_in_footer = true,
97
+		$version = ''
98
+	) {
99
+		$asset = new JavascriptAsset(
100
+			$handle,
101
+			$source,
102
+			array_unique($dependencies),
103
+			$load_in_footer,
104
+			$this->domain,
105
+			$version
106
+		);
107
+		$this->assets->add($asset, $handle);
108
+		return $asset;
109
+	}
110
+
111
+
112
+	/**
113
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
114
+	 *
115
+	 * @param string       $handle
116
+	 * @param string|array $extra_dependencies
117
+	 * @return JavascriptAsset
118
+	 * @throws DuplicateCollectionIdentifierException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 */
123
+	public function addJs($handle, $extra_dependencies = [])
124
+	{
125
+		$details = $this->getAssetDetails(
126
+			Asset::TYPE_JS,
127
+			$handle,
128
+			$extra_dependencies
129
+		);
130
+		$source = $this->registry->getJsUrl($this->domain->assetNamespace(), $handle);
131
+		return $this->addJavascript(
132
+			$handle,
133
+			$source,
134
+			$details['dependencies'],
135
+			true,
136
+			$details['version']
137
+		);
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string $handle
143
+	 * @param array  $dependencies
144
+	 * @param bool   $load_in_footer
145
+	 * @param string $version
146
+	 * @return JavascriptAsset
147
+	 * @throws DomainException
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @since 4.9.71.p
152
+	 */
153
+	public function addVendorJavascript(
154
+		$handle,
155
+		array $dependencies = array(),
156
+		$load_in_footer = true,
157
+		$version = ''
158
+	) {
159
+		$dev_suffix = wp_scripts_get_suffix('dev');
160
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
161
+		return $this->addJavascript(
162
+			$handle,
163
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
164
+			$dependencies,
165
+			$load_in_footer,
166
+			$version
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param string $handle
173
+	 * @param string $source
174
+	 * @param array  $dependencies
175
+	 * @param string $media
176
+	 * @param string $version
177
+	 * @return StylesheetAsset
178
+	 * @throws DomainException
179
+	 * @throws DuplicateCollectionIdentifierException
180
+	 * @throws InvalidDataTypeException
181
+	 * @throws InvalidEntityException
182
+	 * @since 4.9.62.p
183
+	 */
184
+	public function addStylesheet(
185
+		$handle,
186
+		$source,
187
+		array $dependencies = array(),
188
+		$media = 'all',
189
+		$version = ''
190
+	) {
191
+		$asset = new StylesheetAsset(
192
+			$handle,
193
+			$source,
194
+			array_unique($dependencies),
195
+			$this->domain,
196
+			$media,
197
+			$version
198
+		);
199
+		$this->assets->add($asset, $handle);
200
+		return $asset;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
206
+	 *
207
+	 * @param string       $handle
208
+	 * @param string|array $extra_dependencies
209
+	 * @return StylesheetAsset
210
+	 * @throws DuplicateCollectionIdentifierException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidEntityException
213
+	 * @throws DomainException
214
+	 */
215
+	public function addCss($handle, $extra_dependencies = [])
216
+	{
217
+		$details = $this->getAssetDetails(
218
+			Asset::TYPE_CSS,
219
+			$handle,
220
+			$extra_dependencies
221
+		);
222
+		return $this->addStylesheet(
223
+			$handle,
224
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
225
+			$details['dependencies'],
226
+			'all',
227
+			$details['version']
228
+		);
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param string $handle
234
+	 * @return bool
235
+	 * @since 4.9.62.p
236
+	 */
237
+	public function enqueueAsset($handle)
238
+	{
239
+		if ($this->assets->has($handle)) {
240
+			/** @var Asset $asset */
241
+			$asset = $this->assets->get($handle);
242
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
243
+				$asset->enqueueAsset();
244
+				return true;
245
+			}
246
+		}
247
+		return false;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return  void
253
+	 * @since   $VID:$
254
+	 */
255
+	public function enqueueBrowserAssets()
256
+	{
257
+		foreach ($this->assets as $asset) {
258
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
259
+				$asset->enqueueAsset();
260
+			}
261
+		}
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $asset_type
267
+	 * @param string $handle
268
+	 * @param array  $extra_dependencies
269
+	 * @return array
270
+	 * @since 4.10.2.p
271
+	 */
272
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
273
+	{
274
+		$getAssetDetails = '';
275
+		switch ($asset_type) {
276
+			case Asset::TYPE_JS :
277
+				$getAssetDetails = 'getJsAssetDetails';
278
+				break;
279
+			case Asset::TYPE_CSS :
280
+				$getAssetDetails = 'getCssAssetDetails';
281
+				break;
282
+		}
283
+		if ($getAssetDetails === '') {
284
+			return ['dependencies' => [], 'version' => ''];
285
+		}
286
+		$details = $this->registry->$getAssetDetails(
287
+			$this->domain->assetNamespace(),
288
+			$handle
289
+		);
290
+		$details['dependencies'] = isset($details['dependencies'])
291
+			? $details['dependencies']
292
+			: [];
293
+		$details['version'] = isset($details['version'])
294
+			? $details['version']
295
+			: '';
296
+		$details['dependencies'] = ! empty($extra_dependencies)
297
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
298
+			: $details['dependencies'];
299
+		return $details;
300
+
301
+	}
302
+
303
+
304
+	/**
305
+	 * @param string $handle
306
+	 * @return bool
307
+	 * @throws DomainException
308
+	 */
309
+	public function verifyAssetIsRegistered($handle)
310
+	{
311
+		if (wp_script_is($handle, 'registered')) {
312
+			return true;
313
+		}
314
+		if (WP_DEBUG) {
315
+			throw new DomainException(
316
+				sprintf(
317
+					esc_html__(
318
+						'The "%1$s" script is not registered when it should be!%2$s
319 319
                         Are you running the Barista plugin for development purposes? 
320 320
                         If so, then you need to build the appropriate assets for this domain.%2$s
321 321
                         If you are seeing this error on a live website, then you should not have 
322 322
                         the WP_DEBUG constant in your wp-config.php file set to "true". 
323 323
                         Please contact Event Espresso support for more information.',
324
-                        'event_espresso'
325
-                    ),
326
-                    $handle,
327
-                    '<br />'
328
-                )
329
-            );
330
-        }
331
-        return false;
332
-    }
333
-
334
-
335
-    /**************** deprecated ****************/
336
-
337
-
338
-    /**
339
-     * @return void
340
-     * @deprecated $VID:$
341
-     */
342
-    public function addManifestFile()
343
-    {
344
-    }
345
-
346
-
347
-    /**
348
-     * @return void
349
-     * @deprecated $VID:$
350
-     */
351
-    public function getManifestFile()
352
-    {
353
-    }
324
+						'event_espresso'
325
+					),
326
+					$handle,
327
+					'<br />'
328
+				)
329
+			);
330
+		}
331
+		return false;
332
+	}
333
+
334
+
335
+	/**************** deprecated ****************/
336
+
337
+
338
+	/**
339
+	 * @return void
340
+	 * @deprecated $VID:$
341
+	 */
342
+	public function addManifestFile()
343
+	{
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return void
349
+	 * @deprecated $VID:$
350
+	 */
351
+	public function getManifestFile()
352
+	{
353
+	}
354 354
 }
Please login to merge, or discard this patch.
core/services/graphql/fields/GraphQLField.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function shouldResolve()
136 136
     {
137 137
         foreach ($this->caps as $cap) {
138
-            if (! current_user_can($cap)) {
138
+            if ( ! current_user_can($cap)) {
139 139
                 return false;
140 140
             }
141 141
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
168 168
     {
169
-        if (! $this->hasInternalResolver()) {
169
+        if ( ! $this->hasInternalResolver()) {
170 170
             throw new LogicException('GraphQLField has no internal resolver.');
171 171
         }
172 172
         // dynamic methods using $this don't play nice
Please login to merge, or discard this patch.
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -19,262 +19,262 @@
 block discarded – undo
19 19
  */
20 20
 class GraphQLField implements GraphQLFieldInterface
21 21
 {
22
-    /**
23
-     * @var string $name
24
-     */
25
-    protected $name;
26
-
27
-    /**
28
-     * @var string|string[] $type
29
-     */
30
-    protected $type;
31
-
32
-    /**
33
-     * @var string|null $key
34
-     */
35
-    protected $key;
36
-
37
-    /**
38
-     * @var string $description
39
-     */
40
-    protected $description;
41
-
42
-    /**
43
-     * @var callable $formatter
44
-     */
45
-    protected $formatter;
46
-
47
-    /**
48
-     * @var callable $resolve
49
-     */
50
-    protected $resolver;
51
-
52
-    /**
53
-     * @var array $caps
54
-     */
55
-    protected $caps;
56
-
57
-    /**
58
-     * @var array $args
59
-     */
60
-    protected $args;
61
-
62
-    /**
63
-     * @var bool $use_for_input
64
-     */
65
-    protected $use_for_input = true;
66
-
67
-    /**
68
-     * @var bool $use_for_output
69
-     */
70
-    protected $use_for_output = true;
71
-
72
-
73
-    /**
74
-     * @param string          $name
75
-     * @param string|string[] $type
76
-     * @param string|null     $key
77
-     * @param string          $description
78
-     * @param callable|null   $formatter
79
-     * @param callable|null   $resolver
80
-     * @param array           $args
81
-     * @param array           $caps
82
-     * @param array           $args
83
-     */
84
-    public function __construct(
85
-        $name,
86
-        $type,
87
-        $key = null,
88
-        $description = '',
89
-        callable $formatter = null,
90
-        callable $resolver = null,
91
-        array $caps = [],
92
-        array $args = []
93
-    ) {
94
-        $this->name = $name;
95
-        $this->type = $type;
96
-        $this->key = $key;
97
-        $this->description = $description;
98
-        $this->formatter = $formatter;
99
-        $this->resolver = $resolver;
100
-        $this->caps = $caps;
101
-        $this->args = $args;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return array
107
-     */
108
-    public function caps()
109
-    {
110
-        return $this->caps;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return string
116
-     */
117
-    public function description()
118
-    {
119
-        return $this->description;
120
-    }
121
-
122
-
123
-    /**
124
-     * @return string
125
-     */
126
-    public function key()
127
-    {
128
-        return $this->key;
129
-    }
130
-
131
-
132
-    /**
133
-     * @return string
134
-     */
135
-    public function name()
136
-    {
137
-        return $this->name;
138
-    }
139
-
140
-
141
-    /**
142
-     * @return string|string[]
143
-     */
144
-    public function type()
145
-    {
146
-        return $this->type;
147
-    }
148
-
149
-
150
-    /**
151
-     * Convert the field to array to be
152
-     * able to pass as config to WP GraphQL
153
-     *
154
-     * @return array
155
-     */
156
-    public function toArray()
157
-    {
158
-        return get_object_vars($this);
159
-    }
160
-
161
-
162
-    /**
163
-     * Sets the value for use_for_input.
164
-     *
165
-     * @param bool $use_for_input
166
-     */
167
-    protected function setUseForInput($use_for_input)
168
-    {
169
-        $this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
170
-    }
171
-
172
-
173
-    /**
174
-     * Whether the field should be used for
175
-     * mutation inputs.
176
-     *
177
-     * @return bool
178
-     */
179
-    public function useForInput()
180
-    {
181
-        return (bool) $this->use_for_input;
182
-    }
183
-
184
-
185
-    /**
186
-     * Whether the field should be used for
187
-     * query outputs.
188
-     *
189
-     * @return bool
190
-     */
191
-    public function useForOutput()
192
-    {
193
-        return (bool) $this->use_for_output;
194
-    }
195
-
196
-
197
-    /**
198
-     * Sets the value for use_for_output
199
-     *
200
-     * @param bool $use_for_output
201
-     */
202
-    protected function setUseForOutput($use_for_output)
203
-    {
204
-        $this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
205
-    }
206
-
207
-
208
-    /**
209
-     * Whether the field should resolve
210
-     * based on the user caps etc.
211
-     *
212
-     * @return boolean
213
-     */
214
-    public function shouldResolve()
215
-    {
216
-        foreach ($this->caps as $cap) {
217
-            if (! current_user_can($cap)) {
218
-                return false;
219
-            }
220
-        }
221
-        return true;
222
-    }
223
-
224
-
225
-    /**
226
-     * Whether the field has an explicit resolver set.
227
-     *
228
-     * @return boolean
229
-     */
230
-    public function hasInternalResolver()
231
-    {
232
-        return is_callable($this->resolver);
233
-    }
234
-
235
-
236
-    /**
237
-     * Whether the field has an explicit resolver set.
238
-     *
239
-     * @param mixed       $source  The source that's passed down the GraphQL queries
240
-     * @param array       $args    The inputArgs on the field
241
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
242
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
243
-     * @return mixed
244
-     * @throws LogicException
245
-     */
246
-    public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
247
-    {
248
-        if (! $this->hasInternalResolver()) {
249
-            throw new LogicException('GraphQLField has no internal resolver.');
250
-        }
251
-        // dynamic methods using $this don't play nice
252
-        // so capture resolver to a single var first
253
-        $resolver = $this->resolver;
254
-        return $resolver($source, $args, $context, $info);
255
-    }
256
-
257
-
258
-    /**
259
-     * Checks if the format callback is set.
260
-     * If yes, then uses it to format the value.
261
-     *
262
-     * @param mixed         $value
263
-     * @param EE_Base_Class $source
264
-     * @return mixed The formatted value.
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     * @throws InvalidArgumentException
268
-     * @throws ReflectionException
269
-     */
270
-    public function mayBeFormatValue($value, EE_Base_Class $source)
271
-    {
272
-        if (is_callable($this->formatter)) {
273
-            // dynamic methods using $this don't play nice
274
-            // so capture formatter to a single var first
275
-            $formatter = $this->formatter;
276
-            return $formatter($value, $source);
277
-        }
278
-        return $value;
279
-    }
22
+	/**
23
+	 * @var string $name
24
+	 */
25
+	protected $name;
26
+
27
+	/**
28
+	 * @var string|string[] $type
29
+	 */
30
+	protected $type;
31
+
32
+	/**
33
+	 * @var string|null $key
34
+	 */
35
+	protected $key;
36
+
37
+	/**
38
+	 * @var string $description
39
+	 */
40
+	protected $description;
41
+
42
+	/**
43
+	 * @var callable $formatter
44
+	 */
45
+	protected $formatter;
46
+
47
+	/**
48
+	 * @var callable $resolve
49
+	 */
50
+	protected $resolver;
51
+
52
+	/**
53
+	 * @var array $caps
54
+	 */
55
+	protected $caps;
56
+
57
+	/**
58
+	 * @var array $args
59
+	 */
60
+	protected $args;
61
+
62
+	/**
63
+	 * @var bool $use_for_input
64
+	 */
65
+	protected $use_for_input = true;
66
+
67
+	/**
68
+	 * @var bool $use_for_output
69
+	 */
70
+	protected $use_for_output = true;
71
+
72
+
73
+	/**
74
+	 * @param string          $name
75
+	 * @param string|string[] $type
76
+	 * @param string|null     $key
77
+	 * @param string          $description
78
+	 * @param callable|null   $formatter
79
+	 * @param callable|null   $resolver
80
+	 * @param array           $args
81
+	 * @param array           $caps
82
+	 * @param array           $args
83
+	 */
84
+	public function __construct(
85
+		$name,
86
+		$type,
87
+		$key = null,
88
+		$description = '',
89
+		callable $formatter = null,
90
+		callable $resolver = null,
91
+		array $caps = [],
92
+		array $args = []
93
+	) {
94
+		$this->name = $name;
95
+		$this->type = $type;
96
+		$this->key = $key;
97
+		$this->description = $description;
98
+		$this->formatter = $formatter;
99
+		$this->resolver = $resolver;
100
+		$this->caps = $caps;
101
+		$this->args = $args;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return array
107
+	 */
108
+	public function caps()
109
+	{
110
+		return $this->caps;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return string
116
+	 */
117
+	public function description()
118
+	{
119
+		return $this->description;
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return string
125
+	 */
126
+	public function key()
127
+	{
128
+		return $this->key;
129
+	}
130
+
131
+
132
+	/**
133
+	 * @return string
134
+	 */
135
+	public function name()
136
+	{
137
+		return $this->name;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @return string|string[]
143
+	 */
144
+	public function type()
145
+	{
146
+		return $this->type;
147
+	}
148
+
149
+
150
+	/**
151
+	 * Convert the field to array to be
152
+	 * able to pass as config to WP GraphQL
153
+	 *
154
+	 * @return array
155
+	 */
156
+	public function toArray()
157
+	{
158
+		return get_object_vars($this);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Sets the value for use_for_input.
164
+	 *
165
+	 * @param bool $use_for_input
166
+	 */
167
+	protected function setUseForInput($use_for_input)
168
+	{
169
+		$this->use_for_input = filter_var($use_for_input, FILTER_VALIDATE_BOOLEAN);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Whether the field should be used for
175
+	 * mutation inputs.
176
+	 *
177
+	 * @return bool
178
+	 */
179
+	public function useForInput()
180
+	{
181
+		return (bool) $this->use_for_input;
182
+	}
183
+
184
+
185
+	/**
186
+	 * Whether the field should be used for
187
+	 * query outputs.
188
+	 *
189
+	 * @return bool
190
+	 */
191
+	public function useForOutput()
192
+	{
193
+		return (bool) $this->use_for_output;
194
+	}
195
+
196
+
197
+	/**
198
+	 * Sets the value for use_for_output
199
+	 *
200
+	 * @param bool $use_for_output
201
+	 */
202
+	protected function setUseForOutput($use_for_output)
203
+	{
204
+		$this->use_for_output = filter_var($use_for_output, FILTER_VALIDATE_BOOLEAN);
205
+	}
206
+
207
+
208
+	/**
209
+	 * Whether the field should resolve
210
+	 * based on the user caps etc.
211
+	 *
212
+	 * @return boolean
213
+	 */
214
+	public function shouldResolve()
215
+	{
216
+		foreach ($this->caps as $cap) {
217
+			if (! current_user_can($cap)) {
218
+				return false;
219
+			}
220
+		}
221
+		return true;
222
+	}
223
+
224
+
225
+	/**
226
+	 * Whether the field has an explicit resolver set.
227
+	 *
228
+	 * @return boolean
229
+	 */
230
+	public function hasInternalResolver()
231
+	{
232
+		return is_callable($this->resolver);
233
+	}
234
+
235
+
236
+	/**
237
+	 * Whether the field has an explicit resolver set.
238
+	 *
239
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
240
+	 * @param array       $args    The inputArgs on the field
241
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
242
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
243
+	 * @return mixed
244
+	 * @throws LogicException
245
+	 */
246
+	public function resolve($source, array $args, AppContext $context, ResolveInfo $info)
247
+	{
248
+		if (! $this->hasInternalResolver()) {
249
+			throw new LogicException('GraphQLField has no internal resolver.');
250
+		}
251
+		// dynamic methods using $this don't play nice
252
+		// so capture resolver to a single var first
253
+		$resolver = $this->resolver;
254
+		return $resolver($source, $args, $context, $info);
255
+	}
256
+
257
+
258
+	/**
259
+	 * Checks if the format callback is set.
260
+	 * If yes, then uses it to format the value.
261
+	 *
262
+	 * @param mixed         $value
263
+	 * @param EE_Base_Class $source
264
+	 * @return mixed The formatted value.
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 * @throws InvalidArgumentException
268
+	 * @throws ReflectionException
269
+	 */
270
+	public function mayBeFormatValue($value, EE_Base_Class $source)
271
+	{
272
+		if (is_callable($this->formatter)) {
273
+			// dynamic methods using $this don't play nice
274
+			// so capture formatter to a single var first
275
+			$formatter = $this->formatter;
276
+			return $formatter($value, $source);
277
+		}
278
+		return $value;
279
+	}
280 280
 }
Please login to merge, or discard this patch.
core/domain/services/converters/RestApiSpoofer.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118 118
     {
119
-        if (! array_key_exists('limit', $query_params)) {
119
+        if ( ! array_key_exists('limit', $query_params)) {
120 120
             $query_params['limit'] = 1;
121 121
         }
122 122
         $result = $this->getApiResults($model, $query_params, $include);
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145 145
     {
146
-        if (! array_key_exists('caps', $query_params)) {
146
+        if ( ! array_key_exists('caps', $query_params)) {
147 147
             $query_params['caps'] = EEM_Base::caps_read_admin;
148 148
         }
149
-        if (! array_key_exists('default_where_conditions', $query_params)) {
149
+        if ( ! array_key_exists('default_where_conditions', $query_params)) {
150 150
             $query_params['default_where_conditions'] = 'none';
151 151
         }
152 152
         /** @type array $results */
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -49,137 +49,137 @@
 block discarded – undo
49 49
  */
50 50
 class RestApiSpoofer
51 51
 {
52
-    /**
53
-     * @var WP_REST_Server $wp_rest_server
54
-     */
55
-    protected $wp_rest_server;
52
+	/**
53
+	 * @var WP_REST_Server $wp_rest_server
54
+	 */
55
+	protected $wp_rest_server;
56 56
 
57
-    /**
58
-     * @var Read
59
-     */
60
-    protected $rest_controller;
57
+	/**
58
+	 * @var Read
59
+	 */
60
+	protected $rest_controller;
61 61
 
62
-    /**
63
-     * @var EED_Core_Rest_Api $rest_module
64
-     */
65
-    protected $rest_module;
62
+	/**
63
+	 * @var EED_Core_Rest_Api $rest_module
64
+	 */
65
+	protected $rest_module;
66 66
 
67 67
 
68
-    /**
69
-     * RestApiSpoofer constructor.
70
-     *
71
-     * @param WP_REST_Server        $wp_rest_server
72
-     * @param EED_Core_Rest_Api $rest_module
73
-     * @param Read                  $rest_api
74
-     * @param string                $api_version
75
-     */
76
-    public function __construct(
77
-        WP_REST_Server $wp_rest_server,
78
-        EED_Core_Rest_Api $rest_module,
79
-        Read $rest_api,
80
-        $api_version = '4.8.36'
81
-    ) {
82
-        $this->wp_rest_server = $wp_rest_server;
83
-        $this->rest_module = $rest_module;
84
-        $this->rest_controller = $rest_api;
85
-        $this->rest_controller->setRequestedVersion($api_version);
86
-        $this->setUpRestServer();
87
-    }
68
+	/**
69
+	 * RestApiSpoofer constructor.
70
+	 *
71
+	 * @param WP_REST_Server        $wp_rest_server
72
+	 * @param EED_Core_Rest_Api $rest_module
73
+	 * @param Read                  $rest_api
74
+	 * @param string                $api_version
75
+	 */
76
+	public function __construct(
77
+		WP_REST_Server $wp_rest_server,
78
+		EED_Core_Rest_Api $rest_module,
79
+		Read $rest_api,
80
+		$api_version = '4.8.36'
81
+	) {
82
+		$this->wp_rest_server = $wp_rest_server;
83
+		$this->rest_module = $rest_module;
84
+		$this->rest_controller = $rest_api;
85
+		$this->rest_controller->setRequestedVersion($api_version);
86
+		$this->setUpRestServer();
87
+	}
88 88
 
89 89
 
90
-    private function setUpRestServer()
91
-    {
92
-        /* @var WP_REST_Server $wp_rest_server */
93
-        global $wp_rest_server;
94
-        $wp_rest_server = $this->wp_rest_server;
95
-        EED_Core_Rest_Api::set_hooks_both();
96
-        do_action('rest_api_init', $this->wp_rest_server);
97
-    }
90
+	private function setUpRestServer()
91
+	{
92
+		/* @var WP_REST_Server $wp_rest_server */
93
+		global $wp_rest_server;
94
+		$wp_rest_server = $this->wp_rest_server;
95
+		EED_Core_Rest_Api::set_hooks_both();
96
+		do_action('rest_api_init', $this->wp_rest_server);
97
+	}
98 98
 
99
-    /**
100
-     * @param EEM_Base $model
101
-     * @param array    $query_params
102
-     * @param string   $include
103
-     * @return array
104
-     * @throws EE_Error
105
-     * @throws InvalidArgumentException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @throws ModelConfigurationException
109
-     * @throws ReflectionException
110
-     * @throws RestException
111
-     * @throws RestPasswordIncorrectException
112
-     * @throws RestPasswordRequiredException
113
-     * @throws UnexpectedEntityException
114
-     * @throws DomainException
115
-     * @since $VID:$
116
-     */
117
-    public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118
-    {
119
-        if (! array_key_exists('limit', $query_params)) {
120
-            $query_params['limit'] = 1;
121
-        }
122
-        $result = $this->getApiResults($model, $query_params, $include);
123
-        return is_array($result) && isset($result[0]) ? $result[0] : [];
124
-    }
99
+	/**
100
+	 * @param EEM_Base $model
101
+	 * @param array    $query_params
102
+	 * @param string   $include
103
+	 * @return array
104
+	 * @throws EE_Error
105
+	 * @throws InvalidArgumentException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @throws ModelConfigurationException
109
+	 * @throws ReflectionException
110
+	 * @throws RestException
111
+	 * @throws RestPasswordIncorrectException
112
+	 * @throws RestPasswordRequiredException
113
+	 * @throws UnexpectedEntityException
114
+	 * @throws DomainException
115
+	 * @since $VID:$
116
+	 */
117
+	public function getOneApiResult(EEM_Base $model, array $query_params, $include = '')
118
+	{
119
+		if (! array_key_exists('limit', $query_params)) {
120
+			$query_params['limit'] = 1;
121
+		}
122
+		$result = $this->getApiResults($model, $query_params, $include);
123
+		return is_array($result) && isset($result[0]) ? $result[0] : [];
124
+	}
125 125
 
126
-    /**
127
-     * @param EEM_Base $model
128
-     * @param array    $query_params
129
-     * @param string   $include
130
-     * @return array
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidInterfaceException
135
-     * @throws ModelConfigurationException
136
-     * @throws ReflectionException
137
-     * @throws RestException
138
-     * @throws RestPasswordIncorrectException
139
-     * @throws RestPasswordRequiredException
140
-     * @throws UnexpectedEntityException
141
-     * @throws DomainException
142
-     * @since $VID:$
143
-     */
144
-    public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145
-    {
146
-        if (! array_key_exists('caps', $query_params)) {
147
-            $query_params['caps'] = EEM_Base::caps_read_admin;
148
-        }
149
-        if (! array_key_exists('default_where_conditions', $query_params)) {
150
-            $query_params['default_where_conditions'] = 'none';
151
-        }
152
-        /** @type array $results */
153
-        $results = $model->get_all_wpdb_results($query_params);
154
-        $rest_request = new WP_REST_Request();
155
-        $rest_request->set_param('include', $include);
156
-        $rest_request->set_param('caps', 'edit');
157
-        $nice_results = array();
158
-        foreach ($results as $result) {
159
-            $nice_results[] = $this->rest_controller->createEntityFromWpdbResult(
160
-                $model,
161
-                $result,
162
-                $rest_request
163
-            );
164
-        }
165
-        return $nice_results;
166
-    }
126
+	/**
127
+	 * @param EEM_Base $model
128
+	 * @param array    $query_params
129
+	 * @param string   $include
130
+	 * @return array
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidInterfaceException
135
+	 * @throws ModelConfigurationException
136
+	 * @throws ReflectionException
137
+	 * @throws RestException
138
+	 * @throws RestPasswordIncorrectException
139
+	 * @throws RestPasswordRequiredException
140
+	 * @throws UnexpectedEntityException
141
+	 * @throws DomainException
142
+	 * @since $VID:$
143
+	 */
144
+	public function getApiResults(EEM_Base $model, array $query_params, $include = '')
145
+	{
146
+		if (! array_key_exists('caps', $query_params)) {
147
+			$query_params['caps'] = EEM_Base::caps_read_admin;
148
+		}
149
+		if (! array_key_exists('default_where_conditions', $query_params)) {
150
+			$query_params['default_where_conditions'] = 'none';
151
+		}
152
+		/** @type array $results */
153
+		$results = $model->get_all_wpdb_results($query_params);
154
+		$rest_request = new WP_REST_Request();
155
+		$rest_request->set_param('include', $include);
156
+		$rest_request->set_param('caps', 'edit');
157
+		$nice_results = array();
158
+		foreach ($results as $result) {
159
+			$nice_results[] = $this->rest_controller->createEntityFromWpdbResult(
160
+				$model,
161
+				$result,
162
+				$rest_request
163
+			);
164
+		}
165
+		return $nice_results;
166
+	}
167 167
 
168 168
 
169
-    /**
170
-     * @param string $endpoint
171
-     * @return array
172
-     * @throws EE_Error
173
-     * @since $VID:$
174
-     */
175
-    public function getModelSchema($endpoint)
176
-    {
177
-        $response = $this->wp_rest_server->dispatch(
178
-            new WP_REST_Request(
179
-                'OPTIONS',
180
-                "/ee/v4.8.36/{$endpoint}"
181
-            )
182
-        );
183
-        return $response->get_data();
184
-    }
169
+	/**
170
+	 * @param string $endpoint
171
+	 * @return array
172
+	 * @throws EE_Error
173
+	 * @since $VID:$
174
+	 */
175
+	public function getModelSchema($endpoint)
176
+	{
177
+		$response = $this->wp_rest_server->dispatch(
178
+			new WP_REST_Request(
179
+				'OPTIONS',
180
+				"/ee/v4.8.36/{$endpoint}"
181
+			)
182
+		);
183
+		return $response->get_data();
184
+	}
185 185
 }
Please login to merge, or discard this patch.
core/services/graphql/TypesManager.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             $config = $field->toArray();
76 76
             if ($field->useForInput()) {
77 77
                 // Register input fields for existing mutations.
78
-                register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
79
-                register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
78
+                register_graphql_field('Update'.$typeName.'Input', $fieldName, $config);
79
+                register_graphql_field('Create'.$typeName.'Input', $fieldName, $config);
80 80
             }
81 81
             if ($field->useForOutput()) {
82 82
                 $config['resolve'] = [$type, 'resolveField'];
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
             $fieldName = $field->name();
103 103
             $config = $field->toArray();
104 104
             if ($field->useForInput()) {
105
-                $inputFields[ $fieldName ] = $config;
105
+                $inputFields[$fieldName] = $config;
106 106
             }
107 107
             if ($field->useForOutput()) {
108 108
                 $config['resolve'] = [$type, 'resolveField'];
109
-                $outputFields[ $fieldName ] = $config;
109
+                $outputFields[$fieldName] = $config;
110 110
             }
111 111
         }
112 112
         $typeName = $type->name();
113
-        if (! empty($outputFields)) {
113
+        if ( ! empty($outputFields)) {
114 114
             // Register the object type.
115 115
             register_graphql_object_type(
116 116
                 $typeName,
Please login to merge, or discard this patch.
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -17,110 +17,110 @@
 block discarded – undo
17 17
  */
18 18
 class TypesManager implements GQLManagerInterface
19 19
 {
20
-    /**
21
-     * @var TypeCollection|TypeInterface[] $types
22
-     */
23
-    private $types;
20
+	/**
21
+	 * @var TypeCollection|TypeInterface[] $types
22
+	 */
23
+	private $types;
24 24
 
25 25
 
26
-    /**
27
-     * TypesManager constructor.
28
-     *
29
-     * @param TypeCollection|TypeInterface[] $types
30
-     */
31
-    public function __construct(TypeCollection $types)
32
-    {
33
-        $this->types = $types;
34
-    }
26
+	/**
27
+	 * TypesManager constructor.
28
+	 *
29
+	 * @param TypeCollection|TypeInterface[] $types
30
+	 */
31
+	public function __construct(TypeCollection $types)
32
+	{
33
+		$this->types = $types;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @throws CollectionDetailsException
39
-     * @throws CollectionLoaderException
40
-     * @since $VID:$
41
-     */
42
-    public function init()
43
-    {
44
-        $this->types->loadTypes();
45
-        add_action('graphql_register_types', [$this, 'configureTypes'], 10);
46
-    }
37
+	/**
38
+	 * @throws CollectionDetailsException
39
+	 * @throws CollectionLoaderException
40
+	 * @since $VID:$
41
+	 */
42
+	public function init()
43
+	{
44
+		$this->types->loadTypes();
45
+		add_action('graphql_register_types', [$this, 'configureTypes'], 10);
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * @since $VID:$
51
-     */
52
-    public function configureTypes()
53
-    {
54
-        // loop through the collection of types and register their fields
55
-        foreach ($this->types as $type) {
56
-            if ($type->isCustomPostType()) {
57
-                $this->extendCustomPostType($type);
58
-            } else {
59
-                $this->registerType($type);
60
-            }
61
-        }
62
-    }
49
+	/**
50
+	 * @since $VID:$
51
+	 */
52
+	public function configureTypes()
53
+	{
54
+		// loop through the collection of types and register their fields
55
+		foreach ($this->types as $type) {
56
+			if ($type->isCustomPostType()) {
57
+				$this->extendCustomPostType($type);
58
+			} else {
59
+				$this->registerType($type);
60
+			}
61
+		}
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * @param TypeInterface $type
67
-     * @since $VID:$
68
-     */
69
-    public function extendCustomPostType(TypeInterface $type)
70
-    {
71
-        $typeName = $type->name();
72
-        foreach ($type->fields() as $field) {
73
-            $fieldName = $field->name();
74
-            $config = $field->toArray();
75
-            if ($field->useForInput()) {
76
-                // Register input fields for existing mutations.
77
-                register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
78
-                register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
79
-            }
80
-            if ($field->useForOutput()) {
81
-                $config['resolve'] = [$type, 'resolveField'];
82
-                // Register fields for queries.
83
-                register_graphql_field($typeName, $fieldName, $config);
84
-            }
85
-        }
86
-        if (is_callable([$type, 'extendMutations'])) {
87
-            $type->extendMutations();
88
-        }
89
-    }
65
+	/**
66
+	 * @param TypeInterface $type
67
+	 * @since $VID:$
68
+	 */
69
+	public function extendCustomPostType(TypeInterface $type)
70
+	{
71
+		$typeName = $type->name();
72
+		foreach ($type->fields() as $field) {
73
+			$fieldName = $field->name();
74
+			$config = $field->toArray();
75
+			if ($field->useForInput()) {
76
+				// Register input fields for existing mutations.
77
+				register_graphql_field('Update' . $typeName . 'Input', $fieldName, $config);
78
+				register_graphql_field('Create' . $typeName . 'Input', $fieldName, $config);
79
+			}
80
+			if ($field->useForOutput()) {
81
+				$config['resolve'] = [$type, 'resolveField'];
82
+				// Register fields for queries.
83
+				register_graphql_field($typeName, $fieldName, $config);
84
+			}
85
+		}
86
+		if (is_callable([$type, 'extendMutations'])) {
87
+			$type->extendMutations();
88
+		}
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * @param TypeInterface $type
94
-     * @since $VID:$
95
-     */
96
-    public function registerType(TypeInterface $type)
97
-    {
98
-        $outputFields = [];
99
-        $inputFields = [];
100
-        foreach ($type->fields() as $field) {
101
-            $fieldName = $field->name();
102
-            $config = $field->toArray();
103
-            if ($field->useForInput()) {
104
-                $inputFields[ $fieldName ] = $config;
105
-            }
106
-            if ($field->useForOutput()) {
107
-                $config['resolve'] = [$type, 'resolveField'];
108
-                $outputFields[ $fieldName ] = $config;
109
-            }
110
-        }
111
-        $typeName = $type->name();
112
-        if (! empty($outputFields)) {
113
-            // Register the object type.
114
-            register_graphql_object_type(
115
-                $typeName,
116
-                [
117
-                    'description' => $type->description(),
118
-                    'fields'      => $outputFields,
119
-                ]
120
-            );
121
-        }
122
-        if (is_callable([$type, 'registerMutations'])) {
123
-            $type->registerMutations($inputFields);
124
-        }
125
-    }
92
+	/**
93
+	 * @param TypeInterface $type
94
+	 * @since $VID:$
95
+	 */
96
+	public function registerType(TypeInterface $type)
97
+	{
98
+		$outputFields = [];
99
+		$inputFields = [];
100
+		foreach ($type->fields() as $field) {
101
+			$fieldName = $field->name();
102
+			$config = $field->toArray();
103
+			if ($field->useForInput()) {
104
+				$inputFields[ $fieldName ] = $config;
105
+			}
106
+			if ($field->useForOutput()) {
107
+				$config['resolve'] = [$type, 'resolveField'];
108
+				$outputFields[ $fieldName ] = $config;
109
+			}
110
+		}
111
+		$typeName = $type->name();
112
+		if (! empty($outputFields)) {
113
+			// Register the object type.
114
+			register_graphql_object_type(
115
+				$typeName,
116
+				[
117
+					'description' => $type->description(),
118
+					'fields'      => $outputFields,
119
+				]
120
+			);
121
+		}
122
+		if (is_callable([$type, 'registerMutations'])) {
123
+			$type->registerMutations($inputFields);
124
+		}
125
+	}
126 126
 }
Please login to merge, or discard this patch.
core/services/graphql/types/TypeBase.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
         $fields = [];
156 156
         foreach ($this->fields() as $field) {
157 157
             if ($field->useForOutput()) {
158
-                $fields[ $field->name() ] = $field;
158
+                $fields[$field->name()] = $field;
159 159
             }
160 160
         }
161 161
         return $fields;
Please login to merge, or discard this patch.
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -34,270 +34,270 @@
 block discarded – undo
34 34
  */
35 35
 abstract class TypeBase implements TypeInterface
36 36
 {
37
-    /**
38
-     * @var string $namespace The graphql namespace/prefix.
39
-     */
40
-    protected $namespace = 'Espresso';
41
-
42
-    /**
43
-     * @var EEM_Base $model
44
-     */
45
-    protected $model;
46
-
47
-    /**
48
-     * @var string $name
49
-     */
50
-    protected $name = '';
51
-
52
-    /**
53
-     * @var string $description
54
-     */
55
-    protected $description = '';
56
-
57
-    /**
58
-     * @var GraphQLFieldInterface[] $fields
59
-     */
60
-    protected $fields = [];
61
-
62
-    /**
63
-     * @var array $graphql_to_model_map
64
-     */
65
-    protected $graphql_to_model_map = [];
66
-
67
-    /**
68
-     * @var FieldResolver $field_resolver
69
-     */
70
-    protected $field_resolver;
71
-
72
-    /**
73
-     * @var bool $is_custom_post_type
74
-     */
75
-    protected $is_custom_post_type = false;
76
-
77
-
78
-    /**
79
-     * TypeBase constructor.
80
-     *
81
-     * @param EEM_Base|null $model
82
-     */
83
-    public function __construct(EEM_Base $model = null)
84
-    {
85
-        $this->model = $model;
86
-        $this->setFields($this->getFields());
87
-        $this->field_resolver = new FieldResolver(
88
-            $this->model,
89
-            $this->getFieldsForResolver()
90
-        );
91
-    }
92
-
93
-
94
-    /**
95
-     * @return GraphQLFieldInterface[]
96
-     * @since $VID:$
97
-     */
98
-    abstract protected function getFields(): array;
99
-
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function name(): string
105
-    {
106
-        return $this->name;
107
-    }
108
-
109
-
110
-    /**
111
-     * @param string $name
112
-     */
113
-    protected function setName(string $name)
114
-    {
115
-        $this->name = $name;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function description(): string
123
-    {
124
-        return $this->description;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $description
130
-     */
131
-    protected function setDescription(string $description)
132
-    {
133
-        $this->description = $description;
134
-    }
135
-
136
-
137
-    /**
138
-     * @return GraphQLFieldInterface[]
139
-     * @since $VID:$
140
-     */
141
-    public function fields(): array
142
-    {
143
-        return (array) $this->fields;
144
-    }
145
-
146
-
147
-    /**
148
-     * @param GraphQLFieldInterface[] $fields
149
-     */
150
-    protected function setFields(array $fields)
151
-    {
152
-        foreach ($fields as $field) {
153
-            if ($field instanceof GraphQLField) {
154
-                $this->fields[] = $field;
155
-            }
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Creates a key map for internal resolver.
162
-     *
163
-     * @return array
164
-     * @since $VID:$
165
-     */
166
-    public function getFieldsForResolver(): array
167
-    {
168
-        $fields = [];
169
-        foreach ($this->fields() as $field) {
170
-            if ($field->useForOutput()) {
171
-                $fields[ $field->name() ] = $field;
172
-            }
173
-        }
174
-        return $fields;
175
-    }
176
-
177
-
178
-    /**
179
-     * @return bool
180
-     */
181
-    public function isCustomPostType(): bool
182
-    {
183
-        return $this->is_custom_post_type;
184
-    }
185
-
186
-
187
-    /**
188
-     * @param bool $is_custom_post_type
189
-     */
190
-    protected function setIsCustomPostType(bool $is_custom_post_type)
191
-    {
192
-        $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
193
-    }
194
-
195
-
196
-    /**
197
-     * @param int|float $value
198
-     * @return int
199
-     * @since $VID:$
200
-     */
201
-    public function parseInfiniteValue($value): int
202
-    {
203
-        $value = trim($value);
204
-        return $value === null
205
-               || $value === ''
206
-               || $value === '&infin;'
207
-               || $value === 'INF'
208
-               || $value === INF
209
-               || $value === EE_INF
210
-               || is_infinite((float) $value)
211
-            ? -1
212
-            : $value;
213
-    }
214
-
215
-
216
-    /**
217
-     * @param mixed $source
218
-     * @return EE_Base_Class|null
219
-     * @throws EE_Error
220
-     */
221
-    private function getModel($source): ?EE_Base_Class
222
-    {
223
-        // If it comes from a custom connection
224
-        // where the $source is already instantiated.
225
-        if ($source instanceof EE_Base_Class) {
226
-            return $source;
227
-        }
228
-        return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
229
-    }
230
-
231
-
232
-    /**
233
-     * @param mixed       $source  The source that's passed down the GraphQL queries
234
-     * @param array       $args    The inputArgs on the field
235
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
236
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
237
-     * @return EE_Base_Class|Deferred|string|null
238
-     * @throws EE_Error
239
-     * @throws InvalidDataTypeException
240
-     * @throws InvalidInterfaceException
241
-     * @throws UnexpectedEntityException
242
-     * @throws UserError
243
-     * @throws InvalidArgumentException
244
-     * @throws ReflectionException
245
-     * @since $VID:$
246
-     */
247
-    public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
248
-    {
249
-        $source = $source instanceof RootQuery ? $source : $this->getModel($source);
250
-
251
-        return $this->field_resolver->resolve($source, $args, $context, $info);
252
-    }
253
-
254
-
255
-    /**
256
-     * @param mixed      $payload The payload returned after mutation
257
-     * @param array      $args    The inputArgs on the field
258
-     * @param AppContext $context The AppContext passed down the GraphQL tree
259
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
260
-     * @throws EE_Error
261
-     */
262
-    public function resolveFromPayload($payload, array $args, AppContext $context)
263
-    {
264
-        if (empty($payload['id'])) {
265
-            return null;
266
-        }
267
-        return $this->model->get_one_by_ID($payload['id']);
268
-    }
269
-
270
-
271
-    /**
272
-     * Prepares a datetime value in ISO8601/RFC3339 format.
273
-     * It is assumed that the value of $datetime is in the format
274
-     * returned by EE_Base_Class::get_format().
275
-     *
276
-     * @param string        $datetime The datetime value.
277
-     * @param EE_Base_Class $source   The source object.
278
-     * @return string ISO8601/RFC3339 formatted datetime.
279
-     */
280
-    public function formatDatetime(string $datetime, EE_Base_Class $source): string
281
-    {
282
-        $format   = $source->get_format();
283
-        // create date object based on local timezone
284
-        $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
285
-        // change the timezone to UTC
286
-        $datetime->setTimezone(new DateTimeZone('UTC'));
287
-
288
-        return $datetime->format(DateTime::RFC3339);
289
-    }
290
-
291
-
292
-    /**
293
-     * Converts an object to JSON. The object must have a "toJson" method.
294
-     *
295
-     * @param string        $object   The object/value.
296
-     * @param EE_Base_Class $source   The source object.
297
-     * @return string JSON representation of the object.
298
-     */
299
-    public function toJson(JsonableInterface $object, EE_Base_Class $source): string
300
-    {
301
-        return $object->toJson();
302
-    }
37
+	/**
38
+	 * @var string $namespace The graphql namespace/prefix.
39
+	 */
40
+	protected $namespace = 'Espresso';
41
+
42
+	/**
43
+	 * @var EEM_Base $model
44
+	 */
45
+	protected $model;
46
+
47
+	/**
48
+	 * @var string $name
49
+	 */
50
+	protected $name = '';
51
+
52
+	/**
53
+	 * @var string $description
54
+	 */
55
+	protected $description = '';
56
+
57
+	/**
58
+	 * @var GraphQLFieldInterface[] $fields
59
+	 */
60
+	protected $fields = [];
61
+
62
+	/**
63
+	 * @var array $graphql_to_model_map
64
+	 */
65
+	protected $graphql_to_model_map = [];
66
+
67
+	/**
68
+	 * @var FieldResolver $field_resolver
69
+	 */
70
+	protected $field_resolver;
71
+
72
+	/**
73
+	 * @var bool $is_custom_post_type
74
+	 */
75
+	protected $is_custom_post_type = false;
76
+
77
+
78
+	/**
79
+	 * TypeBase constructor.
80
+	 *
81
+	 * @param EEM_Base|null $model
82
+	 */
83
+	public function __construct(EEM_Base $model = null)
84
+	{
85
+		$this->model = $model;
86
+		$this->setFields($this->getFields());
87
+		$this->field_resolver = new FieldResolver(
88
+			$this->model,
89
+			$this->getFieldsForResolver()
90
+		);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return GraphQLFieldInterface[]
96
+	 * @since $VID:$
97
+	 */
98
+	abstract protected function getFields(): array;
99
+
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function name(): string
105
+	{
106
+		return $this->name;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param string $name
112
+	 */
113
+	protected function setName(string $name)
114
+	{
115
+		$this->name = $name;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function description(): string
123
+	{
124
+		return $this->description;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $description
130
+	 */
131
+	protected function setDescription(string $description)
132
+	{
133
+		$this->description = $description;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return GraphQLFieldInterface[]
139
+	 * @since $VID:$
140
+	 */
141
+	public function fields(): array
142
+	{
143
+		return (array) $this->fields;
144
+	}
145
+
146
+
147
+	/**
148
+	 * @param GraphQLFieldInterface[] $fields
149
+	 */
150
+	protected function setFields(array $fields)
151
+	{
152
+		foreach ($fields as $field) {
153
+			if ($field instanceof GraphQLField) {
154
+				$this->fields[] = $field;
155
+			}
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Creates a key map for internal resolver.
162
+	 *
163
+	 * @return array
164
+	 * @since $VID:$
165
+	 */
166
+	public function getFieldsForResolver(): array
167
+	{
168
+		$fields = [];
169
+		foreach ($this->fields() as $field) {
170
+			if ($field->useForOutput()) {
171
+				$fields[ $field->name() ] = $field;
172
+			}
173
+		}
174
+		return $fields;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return bool
180
+	 */
181
+	public function isCustomPostType(): bool
182
+	{
183
+		return $this->is_custom_post_type;
184
+	}
185
+
186
+
187
+	/**
188
+	 * @param bool $is_custom_post_type
189
+	 */
190
+	protected function setIsCustomPostType(bool $is_custom_post_type)
191
+	{
192
+		$this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN);
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param int|float $value
198
+	 * @return int
199
+	 * @since $VID:$
200
+	 */
201
+	public function parseInfiniteValue($value): int
202
+	{
203
+		$value = trim($value);
204
+		return $value === null
205
+			   || $value === ''
206
+			   || $value === '&infin;'
207
+			   || $value === 'INF'
208
+			   || $value === INF
209
+			   || $value === EE_INF
210
+			   || is_infinite((float) $value)
211
+			? -1
212
+			: $value;
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param mixed $source
218
+	 * @return EE_Base_Class|null
219
+	 * @throws EE_Error
220
+	 */
221
+	private function getModel($source): ?EE_Base_Class
222
+	{
223
+		// If it comes from a custom connection
224
+		// where the $source is already instantiated.
225
+		if ($source instanceof EE_Base_Class) {
226
+			return $source;
227
+		}
228
+		return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
234
+	 * @param array       $args    The inputArgs on the field
235
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
236
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
237
+	 * @return EE_Base_Class|Deferred|string|null
238
+	 * @throws EE_Error
239
+	 * @throws InvalidDataTypeException
240
+	 * @throws InvalidInterfaceException
241
+	 * @throws UnexpectedEntityException
242
+	 * @throws UserError
243
+	 * @throws InvalidArgumentException
244
+	 * @throws ReflectionException
245
+	 * @since $VID:$
246
+	 */
247
+	public function resolveField($source, array $args, AppContext $context, ResolveInfo $info)
248
+	{
249
+		$source = $source instanceof RootQuery ? $source : $this->getModel($source);
250
+
251
+		return $this->field_resolver->resolve($source, $args, $context, $info);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param mixed      $payload The payload returned after mutation
257
+	 * @param array      $args    The inputArgs on the field
258
+	 * @param AppContext $context The AppContext passed down the GraphQL tree
259
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|null
260
+	 * @throws EE_Error
261
+	 */
262
+	public function resolveFromPayload($payload, array $args, AppContext $context)
263
+	{
264
+		if (empty($payload['id'])) {
265
+			return null;
266
+		}
267
+		return $this->model->get_one_by_ID($payload['id']);
268
+	}
269
+
270
+
271
+	/**
272
+	 * Prepares a datetime value in ISO8601/RFC3339 format.
273
+	 * It is assumed that the value of $datetime is in the format
274
+	 * returned by EE_Base_Class::get_format().
275
+	 *
276
+	 * @param string        $datetime The datetime value.
277
+	 * @param EE_Base_Class $source   The source object.
278
+	 * @return string ISO8601/RFC3339 formatted datetime.
279
+	 */
280
+	public function formatDatetime(string $datetime, EE_Base_Class $source): string
281
+	{
282
+		$format   = $source->get_format();
283
+		// create date object based on local timezone
284
+		$datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone()));
285
+		// change the timezone to UTC
286
+		$datetime->setTimezone(new DateTimeZone('UTC'));
287
+
288
+		return $datetime->format(DateTime::RFC3339);
289
+	}
290
+
291
+
292
+	/**
293
+	 * Converts an object to JSON. The object must have a "toJson" method.
294
+	 *
295
+	 * @param string        $object   The object/value.
296
+	 * @param EE_Base_Class $source   The source object.
297
+	 * @return string JSON representation of the object.
298
+	 */
299
+	public function toJson(JsonableInterface $object, EE_Base_Class $source): string
300
+	{
301
+		return $object->toJson();
302
+	}
303 303
 }
Please login to merge, or discard this patch.
core/services/graphql/resolvers/ResolverCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
      */
50 50
     private function loadCollection()
51 51
     {
52
-        if (! $this->loader instanceof CollectionLoader) {
52
+        if ( ! $this->loader instanceof CollectionLoader) {
53 53
             $this->loader = new CollectionLoader(
54 54
                 new CollectionDetails(
55 55
                     // collection name
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -20,86 +20,86 @@
 block discarded – undo
20 20
  */
21 21
 class ResolverCollection extends Collection
22 22
 {
23
-    const COLLECTION_NAME = 'espresso_graphql_resolvers';
23
+	const COLLECTION_NAME = 'espresso_graphql_resolvers';
24 24
 
25
-    /**
26
-     * @var CollectionLoader $loader
27
-     */
28
-    protected $loader;
25
+	/**
26
+	 * @var CollectionLoader $loader
27
+	 */
28
+	protected $loader;
29 29
 
30
-    /**
31
-     * ResolverCollection constructor
32
-     *
33
-     * @throws InvalidInterfaceException
34
-     */
35
-    public function __construct()
36
-    {
37
-        parent::__construct(
38
-            'EventEspresso\core\services\graphql\ResolverInterface',
39
-            ResolverCollection::COLLECTION_NAME
40
-        );
41
-    }
30
+	/**
31
+	 * ResolverCollection constructor
32
+	 *
33
+	 * @throws InvalidInterfaceException
34
+	 */
35
+	public function __construct()
36
+	{
37
+		parent::__construct(
38
+			'EventEspresso\core\services\graphql\ResolverInterface',
39
+			ResolverCollection::COLLECTION_NAME
40
+		);
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @throws CollectionDetailsException
46
-     * @throws CollectionLoaderException
47
-     * @since $VID:$
48
-     */
49
-    private function loadCollection()
50
-    {
51
-        if (! $this->loader instanceof CollectionLoader) {
52
-            $this->loader = new CollectionLoader(
53
-                new CollectionDetails(
54
-                    // collection name
55
-                    ResolverCollection::COLLECTION_NAME,
56
-                    // collection interface
57
-                    'EventEspresso\core\services\graphql\ResolverInterface',
58
-                    // FQCNs for classes to add (all classes within each namespace will be loaded)
59
-                    apply_filters(
60
-                        'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs',
61
-                        ['EventEspresso\core\domain\services\graphql\resolvers']
62
-                    ),
63
-                    // filepaths to classes to add
64
-                    array(),
65
-                    // file mask to use if parsing folder for files to add
66
-                    '',
67
-                    // what to use as identifier for collection entities
68
-                    // using CLASS NAME prevents duplicates (works like a singleton)
69
-                    CollectionDetails::ID_CLASS_NAME
70
-                ),
71
-                $this
72
-            );
73
-        }
74
-    }
44
+	/**
45
+	 * @throws CollectionDetailsException
46
+	 * @throws CollectionLoaderException
47
+	 * @since $VID:$
48
+	 */
49
+	private function loadCollection()
50
+	{
51
+		if (! $this->loader instanceof CollectionLoader) {
52
+			$this->loader = new CollectionLoader(
53
+				new CollectionDetails(
54
+					// collection name
55
+					ResolverCollection::COLLECTION_NAME,
56
+					// collection interface
57
+					'EventEspresso\core\services\graphql\ResolverInterface',
58
+					// FQCNs for classes to add (all classes within each namespace will be loaded)
59
+					apply_filters(
60
+						'FHEE__EventEspresso_core_services_graphql_ResolverCollection__loadCollection__collection_FQCNs',
61
+						['EventEspresso\core\domain\services\graphql\resolvers']
62
+					),
63
+					// filepaths to classes to add
64
+					array(),
65
+					// file mask to use if parsing folder for files to add
66
+					'',
67
+					// what to use as identifier for collection entities
68
+					// using CLASS NAME prevents duplicates (works like a singleton)
69
+					CollectionDetails::ID_CLASS_NAME
70
+				),
71
+				$this
72
+			);
73
+		}
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @return CollectionInterface
79
-     * @throws CollectionDetailsException
80
-     * @throws CollectionLoaderException
81
-     * @since $VID:$
82
-     */
83
-    public function loadResolvers()
84
-    {
85
-        $this->loadCollection();
86
-        return $this->loader->getCollection();
87
-    }
77
+	/**
78
+	 * @return CollectionInterface
79
+	 * @throws CollectionDetailsException
80
+	 * @throws CollectionLoaderException
81
+	 * @since $VID:$
82
+	 */
83
+	public function loadResolvers()
84
+	{
85
+		$this->loadCollection();
86
+		return $this->loader->getCollection();
87
+	}
88 88
 
89 89
 
90
-    /**
91
-     * getIdentifier
92
-     * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
93
-     * If no $identifier is supplied, then the  fully qualified class name is used
94
-     *
95
-     * @param        $object
96
-     * @param mixed  $identifier
97
-     * @return bool
98
-     */
99
-    public function getIdentifier($object, $identifier = null)
100
-    {
101
-        return ! empty($identifier)
102
-            ? $identifier
103
-            : get_class($object);
104
-    }
90
+	/**
91
+	 * getIdentifier
92
+	 * Overrides EventEspresso\core\services\collections\Collection::getIdentifier()
93
+	 * If no $identifier is supplied, then the  fully qualified class name is used
94
+	 *
95
+	 * @param        $object
96
+	 * @param mixed  $identifier
97
+	 * @return bool
98
+	 */
99
+	public function getIdentifier($object, $identifier = null)
100
+	{
101
+		return ! empty($identifier)
102
+			? $identifier
103
+			: get_class($object);
104
+	}
105 105
 }
Please login to merge, or discard this patch.