Completed
Branch dev (02312e)
by
unknown
11:42 queued 04:50
created
core/libraries/shortcodes/EE_Recipient_List_Shortcodes.lib.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     {
80 80
         // first get registrations just for this attendee.
81 81
         $att = $data->att_obj;
82
-        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
82
+        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[$att->ID()]['reg_objs'] : array();
83 83
         $registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
84 84
             ? array($data->reg_obj) : $registrations_on_attendee;
85 85
         $tkts = array();
@@ -101,12 +101,12 @@  discard block
 block discarded – undo
101 101
             // tickets will be tickets for all registrations on this attendee.
102 102
             foreach ($registrations_on_attendee as $reg) {
103 103
                 if ($reg instanceof EE_Registration) {
104
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
105
-                        $data->registrations[ $reg->ID() ]
106
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
107
-                    ) ]['tkt_obj'] : null;
104
+                    $ticket = isset($data->registrations[$reg->ID()]) && is_array(
105
+                        $data->registrations[$reg->ID()]
106
+                    ) && isset($data->registrations[$reg->ID()]['tkt_obj']) ? $data->registrations[$reg->ID(
107
+                    )]['tkt_obj'] : null;
108 108
                     if ($ticket instanceof EE_Ticket) {
109
-                        $tkts[ $ticket->ID() ] = $ticket;
109
+                        $tkts[$ticket->ID()] = $ticket;
110 110
                     }
111 111
                 }
112 112
             }
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
             // data will be tickets for this event for this recipient.
124 124
             foreach ($registrations_on_attendee as $reg) {
125 125
                 if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
126
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
127
-                        $data->registrations[ $reg->ID() ]
128
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
129
-                    ) ]['tkt_obj'] : null;
126
+                    $ticket = isset($data->registrations[$reg->ID()]) && is_array(
127
+                        $data->registrations[$reg->ID()]
128
+                    ) && isset($data->registrations[$reg->ID()]['tkt_obj']) ? $data->registrations[$reg->ID(
129
+                    )]['tkt_obj'] : null;
130 130
                     if ($ticket instanceof EE_Ticket) {
131
-                        $tkts[ $ticket->ID() ] = $ticket;
131
+                        $tkts[$ticket->ID()] = $ticket;
132 132
                     }
133 133
                 }
134 134
             }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     {
171 171
         // first get registrations just for this attendee.
172 172
         $att = $data->att_obj;
173
-        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
173
+        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[$att->ID()]['reg_objs'] : array();
174 174
         $registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
175 175
             ? array($data->reg_obj)
176 176
             : $registrations_on_attendee;
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
             // dtts will be datetimes for all registrations on this attendee
186 186
             foreach ($registrations_on_attendee as $reg) {
187 187
                 if ($reg instanceof EE_Registration) {
188
-                    $dtt_objs = isset($data->registrations[ $reg->ID() ]) && is_array(
189
-                        $data->registrations[ $reg->ID() ]
190
-                    ) && isset($data->registrations[ $reg->ID() ]['dtt_objs']) ? $data->registrations[ $reg->ID(
191
-                    ) ]['dtt_objs'] : array();
188
+                    $dtt_objs = isset($data->registrations[$reg->ID()]) && is_array(
189
+                        $data->registrations[$reg->ID()]
190
+                    ) && isset($data->registrations[$reg->ID()]['dtt_objs']) ? $data->registrations[$reg->ID(
191
+                    )]['dtt_objs'] : array();
192 192
                     $dtt_objs = (array) $dtt_objs;
193 193
                     foreach ($dtt_objs as $dtt_obj) {
194 194
                         if ($dtt_obj instanceof EE_Datetime) {
195
-                            $dtts[ $dtt_obj->ID() ] = $dtt_obj;
195
+                            $dtts[$dtt_obj->ID()] = $dtt_obj;
196 196
                         }
197 197
                     }
198 198
                 }
@@ -208,19 +208,19 @@  discard block
 block discarded – undo
208 208
             // data will be datetimes for this event for this recipient
209 209
             foreach ($registrations_on_attendee as $reg) {
210 210
                 if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
211
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
212
-                        $data->registrations[ $reg->ID() ]
213
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
214
-                    ) ]['tkt_obj'] : null;
211
+                    $ticket = isset($data->registrations[$reg->ID()]) && is_array(
212
+                        $data->registrations[$reg->ID()]
213
+                    ) && isset($data->registrations[$reg->ID()]['tkt_obj']) ? $data->registrations[$reg->ID(
214
+                    )]['tkt_obj'] : null;
215 215
                     if ($ticket instanceof EE_Ticket) {
216
-                        $dtt_objs = isset($data->tickets[ $ticket->ID() ]) && is_array(
217
-                            $data->tickets[ $ticket->ID() ]
218
-                        ) && isset($data->tickets[ $ticket->ID() ]['dtt_objs']) ? $data->tickets[ $ticket->ID(
219
-                        ) ]['dtt_objs'] : array();
216
+                        $dtt_objs = isset($data->tickets[$ticket->ID()]) && is_array(
217
+                            $data->tickets[$ticket->ID()]
218
+                        ) && isset($data->tickets[$ticket->ID()]['dtt_objs']) ? $data->tickets[$ticket->ID(
219
+                        )]['dtt_objs'] : array();
220 220
                         $dtt_objs = (array) $dtt_objs;
221 221
                         foreach ($dtt_objs as $dtt_obj) {
222 222
                             if ($dtt_obj instanceof EE_Datetime) {
223
-                                $dtts[ $dtt_obj->ID() ] = $dtt_obj;
223
+                                $dtts[$dtt_obj->ID()] = $dtt_obj;
224 224
                             }
225 225
                         }
226 226
                     }
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -18,225 +18,225 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Recipient_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    public function __construct()
22
-    {
23
-        parent::__construct();
24
-    }
25
-
26
-
27
-    protected function _init_props()
28
-    {
29
-        $this->label = esc_html__('Recipient List Shortcodes', 'event_espresso');
30
-        $this->description = esc_html__('All shortcodes specific to registrant recipients list type data.', 'event_espresso');
31
-        $this->_shortcodes = array(
32
-            '[RECIPIENT_TICKET_LIST]' => esc_html__(
33
-                'Will output a list of tickets for the recipient of the email. Note, if the recipient is the Event Author, then this is blank.',
34
-                'event_espresso'
35
-            ),
36
-            '[RECIPIENT_DATETIME_LIST]' => esc_html__(
37
-                'Will output a list of datetimes that the person receiving this message has been registered for.',
38
-                'event_espresso'
39
-            ),
40
-        );
41
-    }
42
-
43
-
44
-    protected function _parser($shortcode)
45
-    {
46
-        switch ($shortcode) {
47
-            case '[RECIPIENT_TICKET_LIST]':
48
-                return $this->_get_recipient_ticket_list();
49
-                break;
50
-
51
-            case '[RECIPIENT_DATETIME_LIST]':
52
-                return $this->_get_recipient_datetime_list();
53
-                break;
54
-        }
55
-        return '';
56
-    }
57
-
58
-
59
-    /**
60
-     * figure out what the incoming data is and then return the appropriate parsed value
61
-     *
62
-     * @return string
63
-     */
64
-    private function _get_recipient_ticket_list()
65
-    {
66
-        $this->_validate_list_requirements();
67
-
68
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
69
-            return $this->_get_recipient_ticket_list_parsed($this->_data['data']);
70
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
71
-            return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data']);
72
-        } else {
73
-            return '';
74
-        }
75
-    }
76
-
77
-
78
-    private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data)
79
-    {
80
-        // first get registrations just for this attendee.
81
-        $att = $data->att_obj;
82
-        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
83
-        $registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
84
-            ? array($data->reg_obj) : $registrations_on_attendee;
85
-        $tkts = array();
86
-
87
-        // if we're coming in from the main content then $this->_data['data'] is instanceof EE_Messages_Addressee.
88
-        // which means we want to get tickets for all events this addressee is a part of.
89
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
90
-            $valid_shortcodes = array(
91
-                'ticket',
92
-                'event_list',
93
-                'attendee_list',
94
-                'datetime_list',
95
-                'registration_details',
96
-                'attendee',
97
-                'recipient_details',
98
-            );
99
-            $template = $this->_data['template'];
100
-
101
-            // tickets will be tickets for all registrations on this attendee.
102
-            foreach ($registrations_on_attendee as $reg) {
103
-                if ($reg instanceof EE_Registration) {
104
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
105
-                        $data->registrations[ $reg->ID() ]
106
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
107
-                    ) ]['tkt_obj'] : null;
108
-                    if ($ticket instanceof EE_Ticket) {
109
-                        $tkts[ $ticket->ID() ] = $ticket;
110
-                    }
111
-                }
112
-            }
113
-        }
114
-
115
-        // if coming from the context of the event list parser, then let's return just the tickets for that event.
116
-        $event = $this->_data['data'];
117
-        if ($event instanceof EE_Event) {
118
-            $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee', 'recipient_details');
119
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
120
-                ? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
121
-            // let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
122
-            $template = str_replace('[EVENT_LIST]', '', $template);
123
-            // data will be tickets for this event for this recipient.
124
-            foreach ($registrations_on_attendee as $reg) {
125
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
126
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
127
-                        $data->registrations[ $reg->ID() ]
128
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
129
-                    ) ]['tkt_obj'] : null;
130
-                    if ($ticket instanceof EE_Ticket) {
131
-                        $tkts[ $ticket->ID() ] = $ticket;
132
-                    }
133
-                }
134
-            }
135
-        }
136
-
137
-        $tkt_parsed = '';
138
-        foreach ($tkts as $ticket) {
139
-            $tkt_parsed .= $this->_shortcode_helper->parse_ticket_list_template(
140
-                $template,
141
-                $ticket,
142
-                $valid_shortcodes,
143
-                $this->_extra_data
144
-            );
145
-        }
146
-        return $tkt_parsed;
147
-    }
148
-
149
-
150
-    /**
151
-     * figure out what the incoming data is and then return the appropriate parsed value
152
-     *
153
-     * @return string
154
-     */
155
-    private function _get_recipient_datetime_list()
156
-    {
157
-        $this->_validate_list_requirements();
158
-
159
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
-            return $this->_get_recipient_datetime_list_parsed($this->_data['data']);
161
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
-            return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data']);
163
-        } else {
164
-            return '';
165
-        }
166
-    }
167
-
168
-
169
-    private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data)
170
-    {
171
-        // first get registrations just for this attendee.
172
-        $att = $data->att_obj;
173
-        $registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
174
-        $registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
175
-            ? array($data->reg_obj)
176
-            : $registrations_on_attendee;
177
-        $valid_shortcodes = array('datetime', 'attendee', 'recipient_details');
178
-        $template = '';
179
-        $dtts = array();
180
-
181
-        // setup valid shortcodes depending on what the status of the $this->_data property is
182
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
183
-            $template = $this->_data['template'];
184
-
185
-            // dtts will be datetimes for all registrations on this attendee
186
-            foreach ($registrations_on_attendee as $reg) {
187
-                if ($reg instanceof EE_Registration) {
188
-                    $dtt_objs = isset($data->registrations[ $reg->ID() ]) && is_array(
189
-                        $data->registrations[ $reg->ID() ]
190
-                    ) && isset($data->registrations[ $reg->ID() ]['dtt_objs']) ? $data->registrations[ $reg->ID(
191
-                    ) ]['dtt_objs'] : array();
192
-                    $dtt_objs = (array) $dtt_objs;
193
-                    foreach ($dtt_objs as $dtt_obj) {
194
-                        if ($dtt_obj instanceof EE_Datetime) {
195
-                            $dtts[ $dtt_obj->ID() ] = $dtt_obj;
196
-                        }
197
-                    }
198
-                }
199
-            }
200
-        }
201
-
202
-        // if coming from the context of the event list parser, then let's just return the datetimes for the specific event.
203
-        $event = $this->_data['data'];
204
-        if ($event instanceof EE_Event) {
205
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
206
-                ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
207
-
208
-            // data will be datetimes for this event for this recipient
209
-            foreach ($registrations_on_attendee as $reg) {
210
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
211
-                    $ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
212
-                        $data->registrations[ $reg->ID() ]
213
-                    ) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
214
-                    ) ]['tkt_obj'] : null;
215
-                    if ($ticket instanceof EE_Ticket) {
216
-                        $dtt_objs = isset($data->tickets[ $ticket->ID() ]) && is_array(
217
-                            $data->tickets[ $ticket->ID() ]
218
-                        ) && isset($data->tickets[ $ticket->ID() ]['dtt_objs']) ? $data->tickets[ $ticket->ID(
219
-                        ) ]['dtt_objs'] : array();
220
-                        $dtt_objs = (array) $dtt_objs;
221
-                        foreach ($dtt_objs as $dtt_obj) {
222
-                            if ($dtt_obj instanceof EE_Datetime) {
223
-                                $dtts[ $dtt_obj->ID() ] = $dtt_obj;
224
-                            }
225
-                        }
226
-                    }
227
-                }
228
-            }
229
-        }
230
-
231
-        $dtt_parsed = '';
232
-        foreach ($dtts as $datetime) {
233
-            $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
234
-                $template,
235
-                $datetime,
236
-                $valid_shortcodes,
237
-                $this->_extra_data
238
-            );
239
-        }
240
-        return $dtt_parsed;
241
-    }
21
+	public function __construct()
22
+	{
23
+		parent::__construct();
24
+	}
25
+
26
+
27
+	protected function _init_props()
28
+	{
29
+		$this->label = esc_html__('Recipient List Shortcodes', 'event_espresso');
30
+		$this->description = esc_html__('All shortcodes specific to registrant recipients list type data.', 'event_espresso');
31
+		$this->_shortcodes = array(
32
+			'[RECIPIENT_TICKET_LIST]' => esc_html__(
33
+				'Will output a list of tickets for the recipient of the email. Note, if the recipient is the Event Author, then this is blank.',
34
+				'event_espresso'
35
+			),
36
+			'[RECIPIENT_DATETIME_LIST]' => esc_html__(
37
+				'Will output a list of datetimes that the person receiving this message has been registered for.',
38
+				'event_espresso'
39
+			),
40
+		);
41
+	}
42
+
43
+
44
+	protected function _parser($shortcode)
45
+	{
46
+		switch ($shortcode) {
47
+			case '[RECIPIENT_TICKET_LIST]':
48
+				return $this->_get_recipient_ticket_list();
49
+				break;
50
+
51
+			case '[RECIPIENT_DATETIME_LIST]':
52
+				return $this->_get_recipient_datetime_list();
53
+				break;
54
+		}
55
+		return '';
56
+	}
57
+
58
+
59
+	/**
60
+	 * figure out what the incoming data is and then return the appropriate parsed value
61
+	 *
62
+	 * @return string
63
+	 */
64
+	private function _get_recipient_ticket_list()
65
+	{
66
+		$this->_validate_list_requirements();
67
+
68
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
69
+			return $this->_get_recipient_ticket_list_parsed($this->_data['data']);
70
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
71
+			return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data']);
72
+		} else {
73
+			return '';
74
+		}
75
+	}
76
+
77
+
78
+	private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data)
79
+	{
80
+		// first get registrations just for this attendee.
81
+		$att = $data->att_obj;
82
+		$registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
83
+		$registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
84
+			? array($data->reg_obj) : $registrations_on_attendee;
85
+		$tkts = array();
86
+
87
+		// if we're coming in from the main content then $this->_data['data'] is instanceof EE_Messages_Addressee.
88
+		// which means we want to get tickets for all events this addressee is a part of.
89
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
90
+			$valid_shortcodes = array(
91
+				'ticket',
92
+				'event_list',
93
+				'attendee_list',
94
+				'datetime_list',
95
+				'registration_details',
96
+				'attendee',
97
+				'recipient_details',
98
+			);
99
+			$template = $this->_data['template'];
100
+
101
+			// tickets will be tickets for all registrations on this attendee.
102
+			foreach ($registrations_on_attendee as $reg) {
103
+				if ($reg instanceof EE_Registration) {
104
+					$ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
105
+						$data->registrations[ $reg->ID() ]
106
+					) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
107
+					) ]['tkt_obj'] : null;
108
+					if ($ticket instanceof EE_Ticket) {
109
+						$tkts[ $ticket->ID() ] = $ticket;
110
+					}
111
+				}
112
+			}
113
+		}
114
+
115
+		// if coming from the context of the event list parser, then let's return just the tickets for that event.
116
+		$event = $this->_data['data'];
117
+		if ($event instanceof EE_Event) {
118
+			$valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee', 'recipient_details');
119
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
120
+				? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
121
+			// let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
122
+			$template = str_replace('[EVENT_LIST]', '', $template);
123
+			// data will be tickets for this event for this recipient.
124
+			foreach ($registrations_on_attendee as $reg) {
125
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
126
+					$ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
127
+						$data->registrations[ $reg->ID() ]
128
+					) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
129
+					) ]['tkt_obj'] : null;
130
+					if ($ticket instanceof EE_Ticket) {
131
+						$tkts[ $ticket->ID() ] = $ticket;
132
+					}
133
+				}
134
+			}
135
+		}
136
+
137
+		$tkt_parsed = '';
138
+		foreach ($tkts as $ticket) {
139
+			$tkt_parsed .= $this->_shortcode_helper->parse_ticket_list_template(
140
+				$template,
141
+				$ticket,
142
+				$valid_shortcodes,
143
+				$this->_extra_data
144
+			);
145
+		}
146
+		return $tkt_parsed;
147
+	}
148
+
149
+
150
+	/**
151
+	 * figure out what the incoming data is and then return the appropriate parsed value
152
+	 *
153
+	 * @return string
154
+	 */
155
+	private function _get_recipient_datetime_list()
156
+	{
157
+		$this->_validate_list_requirements();
158
+
159
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
+			return $this->_get_recipient_datetime_list_parsed($this->_data['data']);
161
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
+			return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data']);
163
+		} else {
164
+			return '';
165
+		}
166
+	}
167
+
168
+
169
+	private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data)
170
+	{
171
+		// first get registrations just for this attendee.
172
+		$att = $data->att_obj;
173
+		$registrations_on_attendee = $att instanceof EE_Attendee ? $data->attendees[ $att->ID() ]['reg_objs'] : array();
174
+		$registrations_on_attendee = empty($registrations_on_attendee) && $data->reg_obj instanceof EE_Registration
175
+			? array($data->reg_obj)
176
+			: $registrations_on_attendee;
177
+		$valid_shortcodes = array('datetime', 'attendee', 'recipient_details');
178
+		$template = '';
179
+		$dtts = array();
180
+
181
+		// setup valid shortcodes depending on what the status of the $this->_data property is
182
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
183
+			$template = $this->_data['template'];
184
+
185
+			// dtts will be datetimes for all registrations on this attendee
186
+			foreach ($registrations_on_attendee as $reg) {
187
+				if ($reg instanceof EE_Registration) {
188
+					$dtt_objs = isset($data->registrations[ $reg->ID() ]) && is_array(
189
+						$data->registrations[ $reg->ID() ]
190
+					) && isset($data->registrations[ $reg->ID() ]['dtt_objs']) ? $data->registrations[ $reg->ID(
191
+					) ]['dtt_objs'] : array();
192
+					$dtt_objs = (array) $dtt_objs;
193
+					foreach ($dtt_objs as $dtt_obj) {
194
+						if ($dtt_obj instanceof EE_Datetime) {
195
+							$dtts[ $dtt_obj->ID() ] = $dtt_obj;
196
+						}
197
+					}
198
+				}
199
+			}
200
+		}
201
+
202
+		// if coming from the context of the event list parser, then let's just return the datetimes for the specific event.
203
+		$event = $this->_data['data'];
204
+		if ($event instanceof EE_Event) {
205
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
206
+				? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
207
+
208
+			// data will be datetimes for this event for this recipient
209
+			foreach ($registrations_on_attendee as $reg) {
210
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
211
+					$ticket = isset($data->registrations[ $reg->ID() ]) && is_array(
212
+						$data->registrations[ $reg->ID() ]
213
+					) && isset($data->registrations[ $reg->ID() ]['tkt_obj']) ? $data->registrations[ $reg->ID(
214
+					) ]['tkt_obj'] : null;
215
+					if ($ticket instanceof EE_Ticket) {
216
+						$dtt_objs = isset($data->tickets[ $ticket->ID() ]) && is_array(
217
+							$data->tickets[ $ticket->ID() ]
218
+						) && isset($data->tickets[ $ticket->ID() ]['dtt_objs']) ? $data->tickets[ $ticket->ID(
219
+						) ]['dtt_objs'] : array();
220
+						$dtt_objs = (array) $dtt_objs;
221
+						foreach ($dtt_objs as $dtt_obj) {
222
+							if ($dtt_obj instanceof EE_Datetime) {
223
+								$dtts[ $dtt_obj->ID() ] = $dtt_obj;
224
+							}
225
+						}
226
+					}
227
+				}
228
+			}
229
+		}
230
+
231
+		$dtt_parsed = '';
232
+		foreach ($dtts as $datetime) {
233
+			$dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
234
+				$template,
235
+				$datetime,
236
+				$valid_shortcodes,
237
+				$this->_extra_data
238
+			);
239
+		}
240
+		return $dtt_parsed;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
services/admin/registrations/list_table/page_header/DateFilterHeader.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
                 $text .= '<span class="drk-grey-text">';
71 71
                 $text .= '<span class="dashicons dashicons-calendar"></span>';
72 72
                 $text .= $datetime->name();
73
-                $text .= ' ( ' . $datetime->start_date() . ' )';
73
+                $text .= ' ( '.$datetime->start_date().' )';
74 74
                 $text .= '</span></h3>';
75 75
             }
76 76
         }
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -22,57 +22,57 @@
 block discarded – undo
22 22
  */
23 23
 class DateFilterHeader extends AdminPageHeaderDecorator
24 24
 {
25
-    /**
26
-     * @var EEM_Datetime $datetime_model
27
-     */
28
-    private $datetime_model;
25
+	/**
26
+	 * @var EEM_Datetime $datetime_model
27
+	 */
28
+	private $datetime_model;
29 29
 
30 30
 
31
-    /**
32
-     * DateFilterHeader constructor.
33
-     *
34
-     * @param RequestInterface $request
35
-     * @param EEM_Datetime     $datetime_model
36
-     */
37
-    public function __construct(RequestInterface $request, EEM_Datetime $datetime_model)
38
-    {
39
-        parent::__construct($request);
40
-        $this->datetime_model = $datetime_model;
41
-    }
31
+	/**
32
+	 * DateFilterHeader constructor.
33
+	 *
34
+	 * @param RequestInterface $request
35
+	 * @param EEM_Datetime     $datetime_model
36
+	 */
37
+	public function __construct(RequestInterface $request, EEM_Datetime $datetime_model)
38
+	{
39
+		parent::__construct($request);
40
+		$this->datetime_model = $datetime_model;
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param string $text
46
-     * @return string
47
-     * @throws EE_Error
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @since 4.10.2.p
53
-     */
54
-    public function getHeaderText($text = '')
55
-    {
56
-        $DTT_ID = $this->request->getRequestParam('DTT_ID');
57
-        $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int');
58
-        if ($DTT_ID) {
59
-            $datetime = $this->datetime_model->get_one_by_ID($DTT_ID);
60
-            if ($datetime instanceof EE_Datetime && $text !== '') {
61
-                // remove the closing h3 heading tag if it exists
62
-                $text = str_replace(
63
-                    '</h3>',
64
-                    '',
65
-                    $text
66
-                );
67
-                $text .= '&nbsp; &nbsp; ';
68
-                $text .= '<span class="drk-grey-text">';
69
-                $text .= '<span class="dashicons dashicons-calendar"></span>';
70
-                $text .= $datetime->name();
71
-                $text .= ' ( ' . $datetime->start_date() . ' )';
72
-                $text .= '</span></h3>';
73
-            }
74
-        }
44
+	/**
45
+	 * @param string $text
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @since 4.10.2.p
53
+	 */
54
+	public function getHeaderText($text = '')
55
+	{
56
+		$DTT_ID = $this->request->getRequestParam('DTT_ID');
57
+		$DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID, 'int');
58
+		if ($DTT_ID) {
59
+			$datetime = $this->datetime_model->get_one_by_ID($DTT_ID);
60
+			if ($datetime instanceof EE_Datetime && $text !== '') {
61
+				// remove the closing h3 heading tag if it exists
62
+				$text = str_replace(
63
+					'</h3>',
64
+					'',
65
+					$text
66
+				);
67
+				$text .= '&nbsp; &nbsp; ';
68
+				$text .= '<span class="drk-grey-text">';
69
+				$text .= '<span class="dashicons dashicons-calendar"></span>';
70
+				$text .= $datetime->name();
71
+				$text .= ' ( ' . $datetime->start_date() . ' )';
72
+				$text .= '</span></h3>';
73
+			}
74
+		}
75 75
 
76
-        return $text;
77
-    }
76
+		return $text;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
admin/registrations/list_table/page_header/AttendeeFilterHeader.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,13 +59,13 @@
 block discarded – undo
59 59
                         'event_espresso'
60 60
                     ),
61 61
                     '<h3 style="line-height:1.5em;">',
62
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
62
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
63 63
                         array(
64 64
                             'action' => 'edit_attendee',
65 65
                             'post'   => $ATT_ID,
66 66
                         ),
67 67
                         REG_ADMIN_URL
68
-                    ) . '">' . $attendee->full_name() . '</a>',
68
+                    ).'">'.$attendee->full_name().'</a>',
69 69
                     '</h3>'
70 70
                 );
71 71
             }
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -19,55 +19,55 @@
 block discarded – undo
19 19
  */
20 20
 class AttendeeFilterHeader extends AdminPageHeaderDecorator
21 21
 {
22
-    /**
23
-     * @var EEM_Attendee $attendee_model
24
-     */
25
-    private $attendee_model;
22
+	/**
23
+	 * @var EEM_Attendee $attendee_model
24
+	 */
25
+	private $attendee_model;
26 26
 
27 27
 
28
-    /**
29
-     * AttendeeFilterHeader constructor.
30
-     *
31
-     * @param RequestInterface $request
32
-     * @param EEM_Attendee     $attendee_model
33
-     */
34
-    public function __construct(RequestInterface $request, EEM_Attendee $attendee_model)
35
-    {
36
-        parent::__construct($request);
37
-        $this->attendee_model = $attendee_model;
38
-    }
28
+	/**
29
+	 * AttendeeFilterHeader constructor.
30
+	 *
31
+	 * @param RequestInterface $request
32
+	 * @param EEM_Attendee     $attendee_model
33
+	 */
34
+	public function __construct(RequestInterface $request, EEM_Attendee $attendee_model)
35
+	{
36
+		parent::__construct($request);
37
+		$this->attendee_model = $attendee_model;
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * @param string $text
43
-     * @return string
44
-     * @throws EE_Error
45
-     * @since 4.10.2.p
46
-     */
47
-    public function getHeaderText($text = '')
48
-    {
49
-        $ATT_ID = $this->request->getRequestParam('ATT_ID');
50
-        $ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID, 'int');
51
-        if ($ATT_ID) {
52
-            $attendee = $this->attendee_model->get_one_by_ID($ATT_ID);
53
-            if ($attendee instanceof EE_Attendee) {
54
-                $text .= sprintf(
55
-                    esc_html__(
56
-                        '%1$s Viewing registrations for %2$s%3$s',
57
-                        'event_espresso'
58
-                    ),
59
-                    '<h3 style="line-height:1.5em;">',
60
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
61
-                        array(
62
-                            'action' => 'edit_attendee',
63
-                            'post'   => $ATT_ID,
64
-                        ),
65
-                        REG_ADMIN_URL
66
-                    ) . '">' . $attendee->full_name() . '</a>',
67
-                    '</h3>'
68
-                );
69
-            }
70
-        }
71
-        return $text;
72
-    }
41
+	/**
42
+	 * @param string $text
43
+	 * @return string
44
+	 * @throws EE_Error
45
+	 * @since 4.10.2.p
46
+	 */
47
+	public function getHeaderText($text = '')
48
+	{
49
+		$ATT_ID = $this->request->getRequestParam('ATT_ID');
50
+		$ATT_ID = $this->request->getRequestParam('attendee_id', $ATT_ID, 'int');
51
+		if ($ATT_ID) {
52
+			$attendee = $this->attendee_model->get_one_by_ID($ATT_ID);
53
+			if ($attendee instanceof EE_Attendee) {
54
+				$text .= sprintf(
55
+					esc_html__(
56
+						'%1$s Viewing registrations for %2$s%3$s',
57
+						'event_espresso'
58
+					),
59
+					'<h3 style="line-height:1.5em;">',
60
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
61
+						array(
62
+							'action' => 'edit_attendee',
63
+							'post'   => $ATT_ID,
64
+						),
65
+						REG_ADMIN_URL
66
+					) . '">' . $attendee->full_name() . '</a>',
67
+					'</h3>'
68
+				);
69
+			}
70
+		}
71
+		return $text;
72
+	}
73 73
 }
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/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.