Completed
Branch FET/allow-prices-to-be-more-pr... (276f1f)
by
unknown
17:42 queued 14:30
created
core/libraries/rest_api/changes/ChangesInBase.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -37,74 +37,74 @@
 block discarded – undo
37 37
 abstract class ChangesInBase
38 38
 {
39 39
 
40
-    /**
41
-     * The version that these changes happened
42
-     *
43
-     * @var string
44
-     */
45
-    protected $version = null;
40
+	/**
41
+	 * The version that these changes happened
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $version = null;
46 46
 
47 47
 
48
-    /**
49
-     * Called when an EE4 REST API request is made to an earlier version than
50
-     * what is indicated in this class' name.
51
-     * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
52
-     * so that regardless of what version of EE4 core is running, API clients
53
-     * will have a consistent response
54
-     *
55
-     * @return void
56
-     */
57
-    abstract public function setHooks();
48
+	/**
49
+	 * Called when an EE4 REST API request is made to an earlier version than
50
+	 * what is indicated in this class' name.
51
+	 * Uses WordPress' add_filter and add_action to modify the EE4 REST API's response
52
+	 * so that regardless of what version of EE4 core is running, API clients
53
+	 * will have a consistent response
54
+	 *
55
+	 * @return void
56
+	 */
57
+	abstract public function setHooks();
58 58
 
59 59
 
60
-    /**
61
-     * Returns whether or not this class' name indicates its hooks should
62
-     * apply when a request comes in for $requested_version. A class can use
63
-     * other conditions when determining whether to perform their callbacks or not,
64
-     * but this will typically be enough
65
-     *
66
-     * @param string $requested_version eg "4.8.33"
67
-     * @return boolean true: this class' name indicates its filters and actions
68
-     *                                  should take effect. False: this class' name indicates it shouldn't do anything
69
-     */
70
-    public function appliesToVersion($requested_version)
71
-    {
72
-        if ($this->version() > $requested_version) {
73
-            return true;
74
-        }
75
-        return false;
76
-    }
60
+	/**
61
+	 * Returns whether or not this class' name indicates its hooks should
62
+	 * apply when a request comes in for $requested_version. A class can use
63
+	 * other conditions when determining whether to perform their callbacks or not,
64
+	 * but this will typically be enough
65
+	 *
66
+	 * @param string $requested_version eg "4.8.33"
67
+	 * @return boolean true: this class' name indicates its filters and actions
68
+	 *                                  should take effect. False: this class' name indicates it shouldn't do anything
69
+	 */
70
+	public function appliesToVersion($requested_version)
71
+	{
72
+		if ($this->version() > $requested_version) {
73
+			return true;
74
+		}
75
+		return false;
76
+	}
77 77
 
78 78
 
79
-    /**
80
-     * Gets the EE core version when this changes were made to the rest api.
81
-     * Any requests to earlier versions should have modifications made to them
82
-     * by the callbacks of this class.
83
-     *
84
-     * @return string eg "4.8.33"
85
-     * @throws EE_Error
86
-     */
87
-    public function version()
88
-    {
89
-        if ($this->version === null) {
90
-            $matches = array();
91
-            $regex = '~ChangesIn(\d)(\d\d)(\d\d)$~';
92
-            $success = preg_match(
93
-                $regex,
94
-                get_class($this),
95
-                $matches
96
-            );
97
-            if (! $success) {
98
-                throw new EE_Error(
99
-                    sprintf(
100
-                        esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
101
-                        get_class($this),
102
-                        $regex
103
-                    )
104
-                );
105
-            }
106
-            $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
107
-        }
108
-        return $this->version;
109
-    }
79
+	/**
80
+	 * Gets the EE core version when this changes were made to the rest api.
81
+	 * Any requests to earlier versions should have modifications made to them
82
+	 * by the callbacks of this class.
83
+	 *
84
+	 * @return string eg "4.8.33"
85
+	 * @throws EE_Error
86
+	 */
87
+	public function version()
88
+	{
89
+		if ($this->version === null) {
90
+			$matches = array();
91
+			$regex = '~ChangesIn(\d)(\d\d)(\d\d)$~';
92
+			$success = preg_match(
93
+				$regex,
94
+				get_class($this),
95
+				$matches
96
+			);
97
+			if (! $success) {
98
+				throw new EE_Error(
99
+					sprintf(
100
+						esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
101
+						get_class($this),
102
+						$regex
103
+					)
104
+				);
105
+			}
106
+			$this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
107
+		}
108
+		return $this->version;
109
+	}
110 110
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 get_class($this),
95 95
                 $matches
96 96
             );
97
-            if (! $success) {
97
+            if ( ! $success) {
98 98
                 throw new EE_Error(
99 99
                     sprintf(
100 100
                         esc_html__('The class %1$s was misnamed. It name should match the regex "%2$s"', 'event_espresso'),
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
                     )
104 104
                 );
105 105
             }
106
-            $this->version = (int) $matches[1] . '.' . (int) $matches[2] . '.' . (int) $matches[3];
106
+            $this->version = (int) $matches[1].'.'.(int) $matches[2].'.'.(int) $matches[3];
107 107
         }
108 108
         return $this->version;
109 109
     }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Datetime.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -17,214 +17,214 @@
 block discarded – undo
17 17
 
18 18
 class Datetime extends DatetimeCalculationBase
19 19
 {
20
-    /**
21
-     * @var EEM_Datetime
22
-     */
23
-    protected $datetime_model;
20
+	/**
21
+	 * @var EEM_Datetime
22
+	 */
23
+	protected $datetime_model;
24 24
 
25
-    /**
26
-     * @var EEM_Registration
27
-     */
28
-    protected $registration_model;
29
-    public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
30
-    {
31
-        $this->datetime_model = $datetime_model;
32
-        $this->registration_model = $registration_model;
33
-    }
25
+	/**
26
+	 * @var EEM_Registration
27
+	 */
28
+	protected $registration_model;
29
+	public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model)
30
+	{
31
+		$this->datetime_model = $datetime_model;
32
+		$this->registration_model = $registration_model;
33
+	}
34 34
 
35
-    /**
36
-     * Calculates the total spaces available on the datetime, taking into account
37
-     * ticket limits too.
38
-     *
39
-     * @see EE_Datetime::spaces_remaining( true )
40
-     * @param array            $wpdb_row
41
-     * @param WP_REST_Request $request
42
-     * @param DatetimeControllerBase  $controller
43
-     * @return int
44
-     * @throws EE_Error
45
-     * @throws InvalidDataTypeException
46
-     * @throws InvalidInterfaceException
47
-     * @throws InvalidArgumentException
48
-     * @throws ReflectionException
49
-     */
50
-    public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
51
-    {
52
-        if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
53
-            $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
54
-        } else {
55
-            $dtt_obj = null;
56
-        }
57
-        if ($dtt_obj instanceof EE_Datetime) {
58
-            return $dtt_obj->spaces_remaining(true);
59
-        }
60
-        throw new EE_Error(
61
-            sprintf(
62
-                esc_html__(
63
-                // @codingStandardsIgnoreStart
64
-                    'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
65
-                    // @codingStandardsIgnoreEnd
66
-                    'event_espresso'
67
-                ),
68
-                $wpdb_row['Datetime.DTT_ID'],
69
-                print_r($wpdb_row, true)
70
-            )
71
-        );
72
-    }
35
+	/**
36
+	 * Calculates the total spaces available on the datetime, taking into account
37
+	 * ticket limits too.
38
+	 *
39
+	 * @see EE_Datetime::spaces_remaining( true )
40
+	 * @param array            $wpdb_row
41
+	 * @param WP_REST_Request $request
42
+	 * @param DatetimeControllerBase  $controller
43
+	 * @return int
44
+	 * @throws EE_Error
45
+	 * @throws InvalidDataTypeException
46
+	 * @throws InvalidInterfaceException
47
+	 * @throws InvalidArgumentException
48
+	 * @throws ReflectionException
49
+	 */
50
+	public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller)
51
+	{
52
+		if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) {
53
+			$dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']);
54
+		} else {
55
+			$dtt_obj = null;
56
+		}
57
+		if ($dtt_obj instanceof EE_Datetime) {
58
+			return $dtt_obj->spaces_remaining(true);
59
+		}
60
+		throw new EE_Error(
61
+			sprintf(
62
+				esc_html__(
63
+				// @codingStandardsIgnoreStart
64
+					'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found',
65
+					// @codingStandardsIgnoreEnd
66
+					'event_espresso'
67
+				),
68
+				$wpdb_row['Datetime.DTT_ID'],
69
+				print_r($wpdb_row, true)
70
+			)
71
+		);
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * Counts registrations who have checked into this datetime
77
-     *
78
-     * @param array           $wpdb_row
79
-     * @param WP_REST_Request $request
80
-     * @param DatetimeControllerBase $controller
81
-     * @return int
82
-     * @throws EE_Error
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @throws RestException
87
-     */
88
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89
-    {
90
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91
-            throw new EE_Error(
92
-                sprintf(
93
-                    esc_html__(
94
-                    // @codingStandardsIgnoreStart
95
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
96
-                        // @codingStandardsIgnoreEnd
97
-                        'event_espresso'
98
-                    ),
99
-                    print_r($wpdb_row, true)
100
-                )
101
-            );
102
-        }
103
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
104
-        return $this->registration_model
105
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
106
-    }
75
+	/**
76
+	 * Counts registrations who have checked into this datetime
77
+	 *
78
+	 * @param array           $wpdb_row
79
+	 * @param WP_REST_Request $request
80
+	 * @param DatetimeControllerBase $controller
81
+	 * @return int
82
+	 * @throws EE_Error
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @throws RestException
87
+	 */
88
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89
+	{
90
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91
+			throw new EE_Error(
92
+				sprintf(
93
+					esc_html__(
94
+					// @codingStandardsIgnoreStart
95
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
96
+						// @codingStandardsIgnoreEnd
97
+						'event_espresso'
98
+					),
99
+					print_r($wpdb_row, true)
100
+				)
101
+			);
102
+		}
103
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
104
+		return $this->registration_model
105
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true);
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * Counts registrations who have checked out of this datetime
111
-     *
112
-     * @param array           $wpdb_row
113
-     * @param WP_REST_Request $request
114
-     * @param DatetimeControllerBase $controller
115
-     * @return int
116
-     * @throws EE_Error
117
-     * @throws InvalidArgumentException
118
-     * @throws InvalidDataTypeException
119
-     * @throws InvalidInterfaceException
120
-     * @throws RestException
121
-     */
122
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123
-    {
124
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125
-            throw new EE_Error(
126
-                sprintf(
127
-                    esc_html__(
128
-                    // @codingStandardsIgnoreStart
129
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
130
-                        // @codingStandardsIgnoreEnd
131
-                        'event_espresso'
132
-                    ),
133
-                    print_r($wpdb_row, true)
134
-                )
135
-            );
136
-        }
137
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
138
-        return $this->registration_model
139
-                               ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
140
-    }
109
+	/**
110
+	 * Counts registrations who have checked out of this datetime
111
+	 *
112
+	 * @param array           $wpdb_row
113
+	 * @param WP_REST_Request $request
114
+	 * @param DatetimeControllerBase $controller
115
+	 * @return int
116
+	 * @throws EE_Error
117
+	 * @throws InvalidArgumentException
118
+	 * @throws InvalidDataTypeException
119
+	 * @throws InvalidInterfaceException
120
+	 * @throws RestException
121
+	 */
122
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123
+	{
124
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125
+			throw new EE_Error(
126
+				sprintf(
127
+					esc_html__(
128
+					// @codingStandardsIgnoreStart
129
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
130
+						// @codingStandardsIgnoreEnd
131
+						'event_espresso'
132
+					),
133
+					print_r($wpdb_row, true)
134
+				)
135
+			);
136
+		}
137
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
138
+		return $this->registration_model
139
+							   ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false);
140
+	}
141 141
 
142 142
 
143
-    /**
144
-     * Counts the number of pending-payment registrations for this event (regardless
145
-     * of how many datetimes each registrations' ticket purchase is for)
146
-     *
147
-     * @param array           $wpdb_row
148
-     * @param WP_REST_Request $request
149
-     * @param DatetimeControllerBase $controller
150
-     * @return int
151
-     * @throws EE_Error
152
-     * @throws InvalidArgumentException
153
-     * @throws InvalidDataTypeException
154
-     * @throws InvalidInterfaceException
155
-     * @throws RestException
156
-     */
157
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158
-    {
159
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160
-            throw new EE_Error(
161
-                sprintf(
162
-                    esc_html__(
163
-                    // @codingStandardsIgnoreStart
164
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
165
-                        // @codingStandardsIgnoreEnd
166
-                        'event_espresso'
167
-                    ),
168
-                    print_r($wpdb_row, true)
169
-                )
170
-            );
171
-        }
172
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
173
-        return $this->registration_model->count(
174
-            array(
175
-                array(
176
-                    'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
177
-                    'STS_ID'                 => EEM_Registration::status_id_pending_payment,
178
-                ),
179
-            ),
180
-            'REG_ID',
181
-            true
182
-        );
183
-    }
143
+	/**
144
+	 * Counts the number of pending-payment registrations for this event (regardless
145
+	 * of how many datetimes each registrations' ticket purchase is for)
146
+	 *
147
+	 * @param array           $wpdb_row
148
+	 * @param WP_REST_Request $request
149
+	 * @param DatetimeControllerBase $controller
150
+	 * @return int
151
+	 * @throws EE_Error
152
+	 * @throws InvalidArgumentException
153
+	 * @throws InvalidDataTypeException
154
+	 * @throws InvalidInterfaceException
155
+	 * @throws RestException
156
+	 */
157
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158
+	{
159
+		if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160
+			throw new EE_Error(
161
+				sprintf(
162
+					esc_html__(
163
+					// @codingStandardsIgnoreStart
164
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"',
165
+						// @codingStandardsIgnoreEnd
166
+						'event_espresso'
167
+					),
168
+					print_r($wpdb_row, true)
169
+				)
170
+			);
171
+		}
172
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
173
+		return $this->registration_model->count(
174
+			array(
175
+				array(
176
+					'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'],
177
+					'STS_ID'                 => EEM_Registration::status_id_pending_payment,
178
+				),
179
+			),
180
+			'REG_ID',
181
+			true
182
+		);
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
188
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
189
-     *
190
-     * @since 4.9.68.p
191
-     * @return array
192
-     */
193
-    public function schemaForCalculations()
194
-    {
195
-        return array(
196
-            'spaces_remaining_considering_tickets' => array(
197
-                'description' => esc_html__(
198
-                    'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
199
-                    'event_espresso'
200
-                ),
201
-                'type' => 'number',
202
-                'protected' => true,
203
-            ),
204
-            'registrations_checked_in_count' => array(
205
-                'description' => esc_html__(
206
-                    'Counts registrations who have checked into this datetime.',
207
-                    'event_espresso'
208
-                ),
209
-                'type' => 'number',
210
-                'protected' => true,
211
-            ),
212
-            'registrations_checked_out_count' => array(
213
-                'description' => esc_html__(
214
-                    'Counts registrations who have checked out of this datetime.',
215
-                    'event_espresso'
216
-                ),
217
-                'type' => 'number',
218
-                'protected' => true,
219
-            ),
220
-            'spots_taken_pending_payment' => array(
221
-                'description' => esc_html__(
222
-                    'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
223
-                    'event_espresso'
224
-                ),
225
-                'type' => 'number',
226
-                'protected' => true,
227
-            ),
228
-        );
229
-    }
186
+	/**
187
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
188
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
189
+	 *
190
+	 * @since 4.9.68.p
191
+	 * @return array
192
+	 */
193
+	public function schemaForCalculations()
194
+	{
195
+		return array(
196
+			'spaces_remaining_considering_tickets' => array(
197
+				'description' => esc_html__(
198
+					'Calculates the total spaces available on the datetime, taking into account ticket limits too.',
199
+					'event_espresso'
200
+				),
201
+				'type' => 'number',
202
+				'protected' => true,
203
+			),
204
+			'registrations_checked_in_count' => array(
205
+				'description' => esc_html__(
206
+					'Counts registrations who have checked into this datetime.',
207
+					'event_espresso'
208
+				),
209
+				'type' => 'number',
210
+				'protected' => true,
211
+			),
212
+			'registrations_checked_out_count' => array(
213
+				'description' => esc_html__(
214
+					'Counts registrations who have checked out of this datetime.',
215
+					'event_espresso'
216
+				),
217
+				'type' => 'number',
218
+				'protected' => true,
219
+			),
220
+			'spots_taken_pending_payment' => array(
221
+				'description' => esc_html__(
222
+					'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for',
223
+					'event_espresso'
224
+				),
225
+				'type' => 'number',
226
+				'protected' => true,
227
+			),
228
+		);
229
+	}
230 230
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
89 89
     {
90
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
90
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
91 91
             throw new EE_Error(
92 92
                 sprintf(
93 93
                     esc_html__(
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
123 123
     {
124
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
124
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
125 125
             throw new EE_Error(
126 126
                 sprintf(
127 127
                     esc_html__(
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
158 158
     {
159
-        if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
159
+        if ( ! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) {
160 160
             throw new EE_Error(
161 161
                 sprintf(
162 162
                     esc_html__(
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Event.php 2 patches
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -26,571 +26,571 @@
 block discarded – undo
26 26
  */
27 27
 class Event extends EventCalculationBase
28 28
 {
29
-    /**
30
-     * @var EEM_Event
31
-     */
32
-    protected $event_model;
33
-
34
-    /**
35
-     * @var EEM_Registration
36
-     */
37
-    protected $registration_model;
38
-    public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
39
-    {
40
-        $this->event_model = $event_model;
41
-        $this->registration_model = $registration_model;
42
-    }
43
-
44
-    /**
45
-     * Calculates the total spaces on the event (not subtracting sales, but taking
46
-     * sales into account; so this is the optimum sales that CAN still be achieved)
47
-     * See EE_Event::total_available_spaces( true );
48
-     *
49
-     * @param array               $wpdb_row
50
-     * @param WP_REST_Request     $request
51
-     * @param EventControllerBase $controller
52
-     * @return int
53
-     * @throws EE_Error
54
-     * @throws DomainException
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     * @throws UnexpectedEntityException
58
-     * @throws InvalidArgumentException
59
-     */
60
-    public function optimumSalesAtStart($wpdb_row, $request, $controller)
61
-    {
62
-        $event_obj = null;
63
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
64
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
65
-        }
66
-        if ($event_obj instanceof EE_Event) {
67
-            return $event_obj->total_available_spaces();
68
-        }
69
-        throw new EE_Error(
70
-            sprintf(
71
-                esc_html__(
72
-                // @codingStandardsIgnoreStart
73
-                    'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
74
-                    // @codingStandardsIgnoreEnd
75
-                    'event_espresso'
76
-                ),
77
-                $wpdb_row['Event_CPT.ID'],
78
-                print_r($wpdb_row, true)
79
-            )
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
86
-     * sales that COULD have been achieved)
87
-     * See EE_Event::total_available_spaces( true );
88
-     *
89
-     * @param array               $wpdb_row
90
-     * @param WP_REST_Request     $request
91
-     * @param EventControllerBase $controller
92
-     * @return int
93
-     * @throws DomainException
94
-     * @throws EE_Error
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     * @throws UnexpectedEntityException
99
-     */
100
-    public function optimumSalesNow($wpdb_row, $request, $controller)
101
-    {
102
-        $event_obj = null;
103
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
104
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
105
-        }
106
-        if ($event_obj instanceof EE_Event) {
107
-            return $event_obj->total_available_spaces(true);
108
-        }
109
-        throw new EE_Error(
110
-            sprintf(
111
-                esc_html__(
112
-                // @codingStandardsIgnoreStart
113
-                    'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
114
-                    // @codingStandardsIgnoreEnd
115
-                    'event_espresso'
116
-                ),
117
-                $wpdb_row['Event_CPT.ID'],
118
-                print_r($wpdb_row, true)
119
-            )
120
-        );
121
-    }
122
-
123
-
124
-    /**
125
-     * Like optimum_sales_now, but minus total sales so far.
126
-     * See EE_Event::spaces_remaining_for_sale( true );
127
-     *
128
-     * @param array               $wpdb_row
129
-     * @param WP_REST_Request     $request
130
-     * @param EventControllerBase $controller
131
-     * @return int
132
-     * @throws DomainException
133
-     * @throws EE_Error
134
-     * @throws InvalidArgumentException
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidInterfaceException
137
-     * @throws UnexpectedEntityException
138
-     */
139
-    public function spacesRemaining($wpdb_row, $request, $controller)
140
-    {
141
-        $event_obj = null;
142
-        if (Event::wpdbRowHasEventId($wpdb_row)) {
143
-            $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
144
-        }
145
-        if ($event_obj instanceof EE_Event) {
146
-            return $event_obj->spaces_remaining_for_sale();
147
-        }
148
-        throw new EE_Error(
149
-            sprintf(
150
-                esc_html__(
151
-                // @codingStandardsIgnoreStart
152
-                    'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
153
-                    // @codingStandardsIgnoreEnd
154
-                    'event_espresso'
155
-                ),
156
-                $wpdb_row['Event_CPT.ID'],
157
-                print_r($wpdb_row, true)
158
-            )
159
-        );
160
-    }
161
-
162
-
163
-    /**
164
-     * Counts the number of approved registrations for this event (regardless
165
-     * of how many datetimes each registrations' ticket purchase is for)
166
-     *
167
-     * @param array               $wpdb_row
168
-     * @param WP_REST_Request     $request
169
-     * @param EventControllerBase $controller
170
-     * @return int
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function spotsTaken($wpdb_row, $request, $controller)
177
-    {
178
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
179
-            throw new EE_Error(
180
-                sprintf(
181
-                    esc_html__(
182
-                    // @codingStandardsIgnoreStart
183
-                        'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
184
-                        // @codingStandardsIgnoreEnd
185
-                        'event_espresso'
186
-                    ),
187
-                    print_r($wpdb_row, true)
188
-                )
189
-            );
190
-        }
191
-        return $this->registration_model->count(
192
-            array(
193
-                array(
194
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
195
-                    'STS_ID' => EEM_Registration::status_id_approved,
196
-                ),
197
-            ),
198
-            'REG_ID',
199
-            true
200
-        );
201
-    }
202
-
203
-
204
-    /**
205
-     * Counts the number of pending-payment registrations for this event (regardless
206
-     * of how many datetimes each registrations' ticket purchase is for)
207
-     *
208
-     * @param array               $wpdb_row
209
-     * @param WP_REST_Request     $request
210
-     * @param EventControllerBase $controller
211
-     * @return int
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws RestException
217
-     */
218
-    public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219
-    {
220
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
221
-            throw new EE_Error(
222
-                sprintf(
223
-                    esc_html__(
224
-                    // @codingStandardsIgnoreStart
225
-                        'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
226
-                        // @codingStandardsIgnoreEnd
227
-                        'event_espresso'
228
-                    ),
229
-                    print_r($wpdb_row, true)
230
-                )
231
-            );
232
-        }
233
-        $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
234
-        return $this->registration_model->count(
235
-            array(
236
-                array(
237
-                    'EVT_ID' => $wpdb_row['Event_CPT.ID'],
238
-                    'STS_ID' => EEM_Registration::status_id_pending_payment,
239
-                ),
240
-            ),
241
-            'REG_ID',
242
-            true
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * Counts all the registrations who have checked into one of this events' datetimes
249
-     * See EE_Event::total_available_spaces( false );
250
-     *
251
-     * @param array               $wpdb_row
252
-     * @param WP_REST_Request     $request
253
-     * @param EventControllerBase $controller
254
-     * @return int|null if permission denied
255
-     * @throws EE_Error
256
-     * @throws InvalidArgumentException
257
-     * @throws InvalidDataTypeException
258
-     * @throws InvalidInterfaceException
259
-     * @throws RestException
260
-     */
261
-    public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262
-    {
263
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
264
-            throw new EE_Error(
265
-                sprintf(
266
-                    esc_html__(
267
-                    // @codingStandardsIgnoreStart
268
-                        'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
269
-                        // @codingStandardsIgnoreEnd
270
-                        'event_espresso'
271
-                    ),
272
-                    print_r($wpdb_row, true)
273
-                )
274
-            );
275
-        }
276
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
277
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
278
-    }
279
-
280
-
281
-    /**
282
-     * Counts all the registrations who have checked out of one of this events' datetimes
283
-     * See EE_Event::total_available_spaces( false );
284
-     *
285
-     * @param array               $wpdb_row
286
-     * @param WP_REST_Request     $request
287
-     * @param EventControllerBase $controller
288
-     * @return int
289
-     * @throws EE_Error
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     * @throws RestException
294
-     */
295
-    public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296
-    {
297
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
298
-            throw new EE_Error(
299
-                sprintf(
300
-                    esc_html__(
301
-                    // @codingStandardsIgnoreStart
302
-                        'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
303
-                        // @codingStandardsIgnoreEnd
304
-                        'event_espresso'
305
-                    ),
306
-                    print_r($wpdb_row, true)
307
-                )
308
-            );
309
-        }
310
-        $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
311
-        return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
312
-    }
313
-
314
-
315
-    /**
316
-     * Gets the thumbnail image
317
-     *
318
-     * @param array               $wpdb_row
319
-     * @param WP_REST_Request     $request
320
-     * @param EventControllerBase $controller
321
-     * @return array
322
-     * @throws EE_Error
323
-     */
324
-    public function imageThumbnail($wpdb_row, $request, $controller)
325
-    {
326
-        return self::calculateImageData($wpdb_row, 'thumbnail');
327
-    }
328
-
329
-
330
-    /**
331
-     * Gets the medium image
332
-     *
333
-     * @param array               $wpdb_row
334
-     * @param WP_REST_Request     $request
335
-     * @param EventControllerBase $controller
336
-     * @return array
337
-     * @throws EE_Error
338
-     */
339
-    public function imageMedium($wpdb_row, $request, $controller)
340
-    {
341
-        return self::calculateImageData($wpdb_row, 'medium');
342
-    }
343
-
344
-
345
-    /**
346
-     * Gets the medium-large image
347
-     *
348
-     * @param array               $wpdb_row
349
-     * @param WP_REST_Request     $request
350
-     * @param EventControllerBase $controller
351
-     * @return array
352
-     * @throws EE_Error
353
-     */
354
-    public function imageMediumLarge($wpdb_row, $request, $controller)
355
-    {
356
-        return self::calculateImageData($wpdb_row, 'medium_large');
357
-    }
358
-
359
-
360
-    /**
361
-     * Gets the large image
362
-     *
363
-     * @param array               $wpdb_row
364
-     * @param WP_REST_Request     $request
365
-     * @param EventControllerBase $controller
366
-     * @return array
367
-     * @throws EE_Error
368
-     */
369
-    public function imageLarge($wpdb_row, $request, $controller)
370
-    {
371
-        return self::calculateImageData($wpdb_row, 'large');
372
-    }
373
-
374
-
375
-    /**
376
-     * Gets the post-thumbnail image
377
-     *
378
-     * @param array               $wpdb_row
379
-     * @param WP_REST_Request     $request
380
-     * @param EventControllerBase $controller
381
-     * @return array
382
-     * @throws EE_Error
383
-     */
384
-    public function imagePostThumbnail($wpdb_row, $request, $controller)
385
-    {
386
-        return self::calculateImageData($wpdb_row, 'post-thumbnail');
387
-    }
388
-
389
-
390
-    /**
391
-     * Gets the full size image
392
-     *
393
-     * @param array               $wpdb_row
394
-     * @param WP_REST_Request     $request
395
-     * @param EventControllerBase $controller
396
-     * @return array
397
-     * @throws EE_Error
398
-     */
399
-    public function imageFull($wpdb_row, $request, $controller)
400
-    {
401
-        return self::calculateImageData($wpdb_row, 'full');
402
-    }
403
-
404
-
405
-    /**
406
-     * Gets image specs and formats them for the display in the API,
407
-     * according to the image size requested
408
-     *
409
-     * @param array  $wpdb_row
410
-     * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
411
-     * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
412
-     * @throws EE_Error
413
-     */
414
-    protected function calculateImageData($wpdb_row, $image_size)
415
-    {
416
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
417
-            throw new EE_Error(
418
-                sprintf(
419
-                    esc_html__(
420
-                    // @codingStandardsIgnoreStart
421
-                        'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
422
-                        // @codingStandardsIgnoreEnd
423
-                        'event_espresso'
424
-                    ),
425
-                    print_r($wpdb_row, true)
426
-                )
427
-            );
428
-        }
429
-        $EVT_ID = $wpdb_row['Event_CPT.ID'];
430
-        $attachment_id = get_post_thumbnail_id($EVT_ID);
431
-        $data = wp_get_attachment_image_src($attachment_id, $image_size);
432
-        if (! $data) {
433
-            return null;
434
-        }
435
-        $generated = true;
436
-        if (isset($data[3])) {
437
-            $generated = $data[3];
438
-        }
439
-        return array(
440
-            'url'       => $data[0],
441
-            'width'     => $data[1],
442
-            'height'    => $data[2],
443
-            'generated' => $generated,
444
-        );
445
-    }
446
-
447
-
448
-    /**
449
-     * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
450
-     *
451
-     * @param array $wpdb_row
452
-     * @return bool
453
-     */
454
-    protected function wpdbRowHasEventId($wpdb_row)
455
-    {
456
-        return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
457
-    }
458
-
459
-
460
-    /**
461
-     * Provides an array for all the calculations possible that outlines a json schema for those calculations.
462
-     * Array is indexed by calculation (snake case) and value is the schema for that calculation.
463
-     *
464
-     * @since 4.9.68.p
465
-     * @return array
466
-     */
467
-    public function schemaForCalculations()
468
-    {
469
-        $image_object_properties = array(
470
-            'url'       => array(
471
-                'type' => 'string',
472
-            ),
473
-            'width'     => array(
474
-                'type' => 'number',
475
-            ),
476
-            'height'    => array(
477
-                'type' => 'number',
478
-            ),
479
-            'generated' => array(
480
-                'type' => 'boolean',
481
-            ),
482
-        );
483
-        return array(
484
-            'optimum_sales_at_start'          => array(
485
-                'description' => esc_html__(
486
-                    'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
487
-                    'event_espresso'
488
-                ),
489
-                'type'        => 'number',
490
-                'protected' => true,
491
-            ),
492
-            'optimum_sales_now'               => array(
493
-                'description' => esc_html__(
494
-                    'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
495
-                    'event_espresso'
496
-                ),
497
-                'type'        => 'number',
498
-                'protected' => true,
499
-            ),
500
-            'spaces_remaining'                => array(
501
-                'description' => esc_html__(
502
-                    'The optimum_sales_number result, minus total sales so far.',
503
-                    'event_espresso'
504
-                ),
505
-                'type'        => 'number',
506
-                'protected' => true,
507
-            ),
508
-            'spots_taken'                     => array(
509
-                'description' => esc_html__(
510
-                    'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
511
-                    'event_espresso'
512
-                ),
513
-                'type'        => 'number',
514
-                'protected' => true,
515
-            ),
516
-            'spots_taken_pending_payment'     => array(
517
-                'description' => esc_html__(
518
-                    'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
519
-                    'event_espresso'
520
-                ),
521
-                'type'        => 'number',
522
-                'protected' => true,
523
-            ),
524
-            'registrations_checked_in_count'  => array(
525
-                'description' => esc_html__(
526
-                    'The count of all the registrations who have checked into one of this event\'s datetimes.',
527
-                    'event_espresso'
528
-                ),
529
-                'type'        => 'number',
530
-                'protected' => true,
531
-            ),
532
-            'registrations_checked_out_count' => array(
533
-                'description' => esc_html__(
534
-                    'The count of all registrations who have checked out of one of this event\'s datetimes.',
535
-                    'event_espresso'
536
-                ),
537
-                'type'        => 'number',
538
-                'protected' => true,
539
-            ),
540
-            'image_thumbnail'                 => array(
541
-                'description'          => esc_html__(
542
-                    'The thumbnail image data.',
543
-                    'event_espresso'
544
-                ),
545
-                'type'                 => 'object',
546
-                'properties'           => $image_object_properties,
547
-                'additionalProperties' => false,
548
-            ),
549
-            'image_medium'                    => array(
550
-                'description'          => esc_html__(
551
-                    'The medium image data.',
552
-                    'event_espresso'
553
-                ),
554
-                'type'                 => 'object',
555
-                'properties'           => $image_object_properties,
556
-                'additionalProperties' => false,
557
-            ),
558
-            'image_medium_large'              => array(
559
-                'description'          => esc_html__(
560
-                    'The medium-large image data.',
561
-                    'event_espresso'
562
-                ),
563
-                'type'                 => 'object',
564
-                'properties'           => $image_object_properties,
565
-                'additionalProperties' => false,
566
-            ),
567
-            'image_large'                     => array(
568
-                'description'          => esc_html__(
569
-                    'The large image data.',
570
-                    'event_espresso'
571
-                ),
572
-                'type'                 => 'object',
573
-                'properties'           => $image_object_properties,
574
-                'additionalProperties' => false,
575
-            ),
576
-            'image_post_thumbnail'            => array(
577
-                'description'          => esc_html__(
578
-                    'The post-thumbnail image data.',
579
-                    'event_espresso'
580
-                ),
581
-                'type'                 => 'object',
582
-                'properties'           => $image_object_properties,
583
-                'additionalProperties' => false,
584
-            ),
585
-            'image_full'                      => array(
586
-                'description'          => esc_html__(
587
-                    'The full size image data',
588
-                    'event_espresso'
589
-                ),
590
-                'type'                 => 'object',
591
-                'properties'           => $image_object_properties,
592
-                'additionalProperties' => false,
593
-            ),
594
-        );
595
-    }
29
+	/**
30
+	 * @var EEM_Event
31
+	 */
32
+	protected $event_model;
33
+
34
+	/**
35
+	 * @var EEM_Registration
36
+	 */
37
+	protected $registration_model;
38
+	public function __construct(EEM_Event $event_model, EEM_Registration $registration_model)
39
+	{
40
+		$this->event_model = $event_model;
41
+		$this->registration_model = $registration_model;
42
+	}
43
+
44
+	/**
45
+	 * Calculates the total spaces on the event (not subtracting sales, but taking
46
+	 * sales into account; so this is the optimum sales that CAN still be achieved)
47
+	 * See EE_Event::total_available_spaces( true );
48
+	 *
49
+	 * @param array               $wpdb_row
50
+	 * @param WP_REST_Request     $request
51
+	 * @param EventControllerBase $controller
52
+	 * @return int
53
+	 * @throws EE_Error
54
+	 * @throws DomainException
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 * @throws UnexpectedEntityException
58
+	 * @throws InvalidArgumentException
59
+	 */
60
+	public function optimumSalesAtStart($wpdb_row, $request, $controller)
61
+	{
62
+		$event_obj = null;
63
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
64
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
65
+		}
66
+		if ($event_obj instanceof EE_Event) {
67
+			return $event_obj->total_available_spaces();
68
+		}
69
+		throw new EE_Error(
70
+			sprintf(
71
+				esc_html__(
72
+				// @codingStandardsIgnoreStart
73
+					'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found',
74
+					// @codingStandardsIgnoreEnd
75
+					'event_espresso'
76
+				),
77
+				$wpdb_row['Event_CPT.ID'],
78
+				print_r($wpdb_row, true)
79
+			)
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * Calculates the total spaces on the event (ignoring all sales; so this is the optimum
86
+	 * sales that COULD have been achieved)
87
+	 * See EE_Event::total_available_spaces( true );
88
+	 *
89
+	 * @param array               $wpdb_row
90
+	 * @param WP_REST_Request     $request
91
+	 * @param EventControllerBase $controller
92
+	 * @return int
93
+	 * @throws DomainException
94
+	 * @throws EE_Error
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 * @throws UnexpectedEntityException
99
+	 */
100
+	public function optimumSalesNow($wpdb_row, $request, $controller)
101
+	{
102
+		$event_obj = null;
103
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
104
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
105
+		}
106
+		if ($event_obj instanceof EE_Event) {
107
+			return $event_obj->total_available_spaces(true);
108
+		}
109
+		throw new EE_Error(
110
+			sprintf(
111
+				esc_html__(
112
+				// @codingStandardsIgnoreStart
113
+					'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found',
114
+					// @codingStandardsIgnoreEnd
115
+					'event_espresso'
116
+				),
117
+				$wpdb_row['Event_CPT.ID'],
118
+				print_r($wpdb_row, true)
119
+			)
120
+		);
121
+	}
122
+
123
+
124
+	/**
125
+	 * Like optimum_sales_now, but minus total sales so far.
126
+	 * See EE_Event::spaces_remaining_for_sale( true );
127
+	 *
128
+	 * @param array               $wpdb_row
129
+	 * @param WP_REST_Request     $request
130
+	 * @param EventControllerBase $controller
131
+	 * @return int
132
+	 * @throws DomainException
133
+	 * @throws EE_Error
134
+	 * @throws InvalidArgumentException
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidInterfaceException
137
+	 * @throws UnexpectedEntityException
138
+	 */
139
+	public function spacesRemaining($wpdb_row, $request, $controller)
140
+	{
141
+		$event_obj = null;
142
+		if (Event::wpdbRowHasEventId($wpdb_row)) {
143
+			$event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']);
144
+		}
145
+		if ($event_obj instanceof EE_Event) {
146
+			return $event_obj->spaces_remaining_for_sale();
147
+		}
148
+		throw new EE_Error(
149
+			sprintf(
150
+				esc_html__(
151
+				// @codingStandardsIgnoreStart
152
+					'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found',
153
+					// @codingStandardsIgnoreEnd
154
+					'event_espresso'
155
+				),
156
+				$wpdb_row['Event_CPT.ID'],
157
+				print_r($wpdb_row, true)
158
+			)
159
+		);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Counts the number of approved registrations for this event (regardless
165
+	 * of how many datetimes each registrations' ticket purchase is for)
166
+	 *
167
+	 * @param array               $wpdb_row
168
+	 * @param WP_REST_Request     $request
169
+	 * @param EventControllerBase $controller
170
+	 * @return int
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function spotsTaken($wpdb_row, $request, $controller)
177
+	{
178
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
179
+			throw new EE_Error(
180
+				sprintf(
181
+					esc_html__(
182
+					// @codingStandardsIgnoreStart
183
+						'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"',
184
+						// @codingStandardsIgnoreEnd
185
+						'event_espresso'
186
+					),
187
+					print_r($wpdb_row, true)
188
+				)
189
+			);
190
+		}
191
+		return $this->registration_model->count(
192
+			array(
193
+				array(
194
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
195
+					'STS_ID' => EEM_Registration::status_id_approved,
196
+				),
197
+			),
198
+			'REG_ID',
199
+			true
200
+		);
201
+	}
202
+
203
+
204
+	/**
205
+	 * Counts the number of pending-payment registrations for this event (regardless
206
+	 * of how many datetimes each registrations' ticket purchase is for)
207
+	 *
208
+	 * @param array               $wpdb_row
209
+	 * @param WP_REST_Request     $request
210
+	 * @param EventControllerBase $controller
211
+	 * @return int
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws RestException
217
+	 */
218
+	public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219
+	{
220
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
221
+			throw new EE_Error(
222
+				sprintf(
223
+					esc_html__(
224
+					// @codingStandardsIgnoreStart
225
+						'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"',
226
+						// @codingStandardsIgnoreEnd
227
+						'event_espresso'
228
+					),
229
+					print_r($wpdb_row, true)
230
+				)
231
+			);
232
+		}
233
+		$this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment');
234
+		return $this->registration_model->count(
235
+			array(
236
+				array(
237
+					'EVT_ID' => $wpdb_row['Event_CPT.ID'],
238
+					'STS_ID' => EEM_Registration::status_id_pending_payment,
239
+				),
240
+			),
241
+			'REG_ID',
242
+			true
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * Counts all the registrations who have checked into one of this events' datetimes
249
+	 * See EE_Event::total_available_spaces( false );
250
+	 *
251
+	 * @param array               $wpdb_row
252
+	 * @param WP_REST_Request     $request
253
+	 * @param EventControllerBase $controller
254
+	 * @return int|null if permission denied
255
+	 * @throws EE_Error
256
+	 * @throws InvalidArgumentException
257
+	 * @throws InvalidDataTypeException
258
+	 * @throws InvalidInterfaceException
259
+	 * @throws RestException
260
+	 */
261
+	public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262
+	{
263
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
264
+			throw new EE_Error(
265
+				sprintf(
266
+					esc_html__(
267
+					// @codingStandardsIgnoreStart
268
+						'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
269
+						// @codingStandardsIgnoreEnd
270
+						'event_espresso'
271
+					),
272
+					print_r($wpdb_row, true)
273
+				)
274
+			);
275
+		}
276
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count');
277
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true);
278
+	}
279
+
280
+
281
+	/**
282
+	 * Counts all the registrations who have checked out of one of this events' datetimes
283
+	 * See EE_Event::total_available_spaces( false );
284
+	 *
285
+	 * @param array               $wpdb_row
286
+	 * @param WP_REST_Request     $request
287
+	 * @param EventControllerBase $controller
288
+	 * @return int
289
+	 * @throws EE_Error
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 * @throws RestException
294
+	 */
295
+	public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296
+	{
297
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
298
+			throw new EE_Error(
299
+				sprintf(
300
+					esc_html__(
301
+					// @codingStandardsIgnoreStart
302
+						'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"',
303
+						// @codingStandardsIgnoreEnd
304
+						'event_espresso'
305
+					),
306
+					print_r($wpdb_row, true)
307
+				)
308
+			);
309
+		}
310
+		$this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count');
311
+		return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false);
312
+	}
313
+
314
+
315
+	/**
316
+	 * Gets the thumbnail image
317
+	 *
318
+	 * @param array               $wpdb_row
319
+	 * @param WP_REST_Request     $request
320
+	 * @param EventControllerBase $controller
321
+	 * @return array
322
+	 * @throws EE_Error
323
+	 */
324
+	public function imageThumbnail($wpdb_row, $request, $controller)
325
+	{
326
+		return self::calculateImageData($wpdb_row, 'thumbnail');
327
+	}
328
+
329
+
330
+	/**
331
+	 * Gets the medium image
332
+	 *
333
+	 * @param array               $wpdb_row
334
+	 * @param WP_REST_Request     $request
335
+	 * @param EventControllerBase $controller
336
+	 * @return array
337
+	 * @throws EE_Error
338
+	 */
339
+	public function imageMedium($wpdb_row, $request, $controller)
340
+	{
341
+		return self::calculateImageData($wpdb_row, 'medium');
342
+	}
343
+
344
+
345
+	/**
346
+	 * Gets the medium-large image
347
+	 *
348
+	 * @param array               $wpdb_row
349
+	 * @param WP_REST_Request     $request
350
+	 * @param EventControllerBase $controller
351
+	 * @return array
352
+	 * @throws EE_Error
353
+	 */
354
+	public function imageMediumLarge($wpdb_row, $request, $controller)
355
+	{
356
+		return self::calculateImageData($wpdb_row, 'medium_large');
357
+	}
358
+
359
+
360
+	/**
361
+	 * Gets the large image
362
+	 *
363
+	 * @param array               $wpdb_row
364
+	 * @param WP_REST_Request     $request
365
+	 * @param EventControllerBase $controller
366
+	 * @return array
367
+	 * @throws EE_Error
368
+	 */
369
+	public function imageLarge($wpdb_row, $request, $controller)
370
+	{
371
+		return self::calculateImageData($wpdb_row, 'large');
372
+	}
373
+
374
+
375
+	/**
376
+	 * Gets the post-thumbnail image
377
+	 *
378
+	 * @param array               $wpdb_row
379
+	 * @param WP_REST_Request     $request
380
+	 * @param EventControllerBase $controller
381
+	 * @return array
382
+	 * @throws EE_Error
383
+	 */
384
+	public function imagePostThumbnail($wpdb_row, $request, $controller)
385
+	{
386
+		return self::calculateImageData($wpdb_row, 'post-thumbnail');
387
+	}
388
+
389
+
390
+	/**
391
+	 * Gets the full size image
392
+	 *
393
+	 * @param array               $wpdb_row
394
+	 * @param WP_REST_Request     $request
395
+	 * @param EventControllerBase $controller
396
+	 * @return array
397
+	 * @throws EE_Error
398
+	 */
399
+	public function imageFull($wpdb_row, $request, $controller)
400
+	{
401
+		return self::calculateImageData($wpdb_row, 'full');
402
+	}
403
+
404
+
405
+	/**
406
+	 * Gets image specs and formats them for the display in the API,
407
+	 * according to the image size requested
408
+	 *
409
+	 * @param array  $wpdb_row
410
+	 * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full
411
+	 * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original'
412
+	 * @throws EE_Error
413
+	 */
414
+	protected function calculateImageData($wpdb_row, $image_size)
415
+	{
416
+		if (! Event::wpdbRowHasEventId($wpdb_row)) {
417
+			throw new EE_Error(
418
+				sprintf(
419
+					esc_html__(
420
+					// @codingStandardsIgnoreStart
421
+						'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"',
422
+						// @codingStandardsIgnoreEnd
423
+						'event_espresso'
424
+					),
425
+					print_r($wpdb_row, true)
426
+				)
427
+			);
428
+		}
429
+		$EVT_ID = $wpdb_row['Event_CPT.ID'];
430
+		$attachment_id = get_post_thumbnail_id($EVT_ID);
431
+		$data = wp_get_attachment_image_src($attachment_id, $image_size);
432
+		if (! $data) {
433
+			return null;
434
+		}
435
+		$generated = true;
436
+		if (isset($data[3])) {
437
+			$generated = $data[3];
438
+		}
439
+		return array(
440
+			'url'       => $data[0],
441
+			'width'     => $data[1],
442
+			'height'    => $data[2],
443
+			'generated' => $generated,
444
+		);
445
+	}
446
+
447
+
448
+	/**
449
+	 * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise
450
+	 *
451
+	 * @param array $wpdb_row
452
+	 * @return bool
453
+	 */
454
+	protected function wpdbRowHasEventId($wpdb_row)
455
+	{
456
+		return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID']));
457
+	}
458
+
459
+
460
+	/**
461
+	 * Provides an array for all the calculations possible that outlines a json schema for those calculations.
462
+	 * Array is indexed by calculation (snake case) and value is the schema for that calculation.
463
+	 *
464
+	 * @since 4.9.68.p
465
+	 * @return array
466
+	 */
467
+	public function schemaForCalculations()
468
+	{
469
+		$image_object_properties = array(
470
+			'url'       => array(
471
+				'type' => 'string',
472
+			),
473
+			'width'     => array(
474
+				'type' => 'number',
475
+			),
476
+			'height'    => array(
477
+				'type' => 'number',
478
+			),
479
+			'generated' => array(
480
+				'type' => 'boolean',
481
+			),
482
+		);
483
+		return array(
484
+			'optimum_sales_at_start'          => array(
485
+				'description' => esc_html__(
486
+					'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.',
487
+					'event_espresso'
488
+				),
489
+				'type'        => 'number',
490
+				'protected' => true,
491
+			),
492
+			'optimum_sales_now'               => array(
493
+				'description' => esc_html__(
494
+					'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.',
495
+					'event_espresso'
496
+				),
497
+				'type'        => 'number',
498
+				'protected' => true,
499
+			),
500
+			'spaces_remaining'                => array(
501
+				'description' => esc_html__(
502
+					'The optimum_sales_number result, minus total sales so far.',
503
+					'event_espresso'
504
+				),
505
+				'type'        => 'number',
506
+				'protected' => true,
507
+			),
508
+			'spots_taken'                     => array(
509
+				'description' => esc_html__(
510
+					'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
511
+					'event_espresso'
512
+				),
513
+				'type'        => 'number',
514
+				'protected' => true,
515
+			),
516
+			'spots_taken_pending_payment'     => array(
517
+				'description' => esc_html__(
518
+					'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)',
519
+					'event_espresso'
520
+				),
521
+				'type'        => 'number',
522
+				'protected' => true,
523
+			),
524
+			'registrations_checked_in_count'  => array(
525
+				'description' => esc_html__(
526
+					'The count of all the registrations who have checked into one of this event\'s datetimes.',
527
+					'event_espresso'
528
+				),
529
+				'type'        => 'number',
530
+				'protected' => true,
531
+			),
532
+			'registrations_checked_out_count' => array(
533
+				'description' => esc_html__(
534
+					'The count of all registrations who have checked out of one of this event\'s datetimes.',
535
+					'event_espresso'
536
+				),
537
+				'type'        => 'number',
538
+				'protected' => true,
539
+			),
540
+			'image_thumbnail'                 => array(
541
+				'description'          => esc_html__(
542
+					'The thumbnail image data.',
543
+					'event_espresso'
544
+				),
545
+				'type'                 => 'object',
546
+				'properties'           => $image_object_properties,
547
+				'additionalProperties' => false,
548
+			),
549
+			'image_medium'                    => array(
550
+				'description'          => esc_html__(
551
+					'The medium image data.',
552
+					'event_espresso'
553
+				),
554
+				'type'                 => 'object',
555
+				'properties'           => $image_object_properties,
556
+				'additionalProperties' => false,
557
+			),
558
+			'image_medium_large'              => array(
559
+				'description'          => esc_html__(
560
+					'The medium-large image data.',
561
+					'event_espresso'
562
+				),
563
+				'type'                 => 'object',
564
+				'properties'           => $image_object_properties,
565
+				'additionalProperties' => false,
566
+			),
567
+			'image_large'                     => array(
568
+				'description'          => esc_html__(
569
+					'The large image data.',
570
+					'event_espresso'
571
+				),
572
+				'type'                 => 'object',
573
+				'properties'           => $image_object_properties,
574
+				'additionalProperties' => false,
575
+			),
576
+			'image_post_thumbnail'            => array(
577
+				'description'          => esc_html__(
578
+					'The post-thumbnail image data.',
579
+					'event_espresso'
580
+				),
581
+				'type'                 => 'object',
582
+				'properties'           => $image_object_properties,
583
+				'additionalProperties' => false,
584
+			),
585
+			'image_full'                      => array(
586
+				'description'          => esc_html__(
587
+					'The full size image data',
588
+					'event_espresso'
589
+				),
590
+				'type'                 => 'object',
591
+				'properties'           => $image_object_properties,
592
+				'additionalProperties' => false,
593
+			),
594
+		);
595
+	}
596 596
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      */
176 176
     public function spotsTaken($wpdb_row, $request, $controller)
177 177
     {
178
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
178
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
179 179
             throw new EE_Error(
180 180
                 sprintf(
181 181
                     esc_html__(
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function spotsTakenPendingPayment($wpdb_row, $request, $controller)
219 219
     {
220
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
220
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
221 221
             throw new EE_Error(
222 222
                 sprintf(
223 223
                     esc_html__(
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function registrationsCheckedInCount($wpdb_row, $request, $controller)
262 262
     {
263
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
263
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
264 264
             throw new EE_Error(
265 265
                 sprintf(
266 266
                     esc_html__(
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      */
295 295
     public function registrationsCheckedOutCount($wpdb_row, $request, $controller)
296 296
     {
297
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
297
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
298 298
             throw new EE_Error(
299 299
                 sprintf(
300 300
                     esc_html__(
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     protected function calculateImageData($wpdb_row, $image_size)
415 415
     {
416
-        if (! Event::wpdbRowHasEventId($wpdb_row)) {
416
+        if ( ! Event::wpdbRowHasEventId($wpdb_row)) {
417 417
             throw new EE_Error(
418 418
                 sprintf(
419 419
                     esc_html__(
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $EVT_ID = $wpdb_row['Event_CPT.ID'];
430 430
         $attachment_id = get_post_thumbnail_id($EVT_ID);
431 431
         $data = wp_get_attachment_image_src($attachment_id, $image_size);
432
-        if (! $data) {
432
+        if ( ! $data) {
433 433
             return null;
434 434
         }
435 435
         $generated = true;
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Model_Form_Section.form.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
39 39
             $this->_model = $options_array['model'];
40 40
         }
41
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
41
+        if ( ! $this->_model || ! $this->_model instanceof EEM_Base) {
42 42
             throw new EE_Error(sprintf(esc_html__(
43 43
                 "Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
44 44
                 "event_espresso"
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
             switch (get_class($relation_obj)) {
104 104
                 case 'EE_HABTM_Relation':
105 105
                     if (
106
-                        isset($subsection_args[ $relation_name ])
107
-                        && isset($subsection_args[ $relation_name ]['model_objects'])
106
+                        isset($subsection_args[$relation_name])
107
+                        && isset($subsection_args[$relation_name]['model_objects'])
108 108
                     ) {
109
-                        $model_objects = $subsection_args[ $relation_name ]['model_objects'];
109
+                        $model_objects = $subsection_args[$relation_name]['model_objects'];
110 110
                     } else {
111 111
                         $model_objects = $relation_obj->get_other_model()->get_all();
112 112
                     }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 default:
116 116
             }
117 117
             if ($input) {
118
-                $inputs[ $relation_name ] = $input;
118
+                $inputs[$relation_name] = $input;
119 119
             }
120 120
         }
121 121
         return $inputs;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                 }
266 266
                 $reflection = new ReflectionClass($input_class);
267 267
                 $input = $reflection->newInstanceArgs($input_constructor_args);
268
-                $inputs[ $field_name ] = $input;
268
+                $inputs[$field_name] = $input;
269 269
             }
270 270
         }
271 271
         return $inputs;
@@ -291,14 +291,14 @@  discard block
 block discarded – undo
291 291
                 if ($relation_obj instanceof EE_Belongs_To_Relation) {
292 292
                     // then we only expect there to be one
293 293
                     $related_item = $this->_model_object->get_first_related($relation_name);
294
-                    $defaults[ $relation_name ] = $related_item->ID();
294
+                    $defaults[$relation_name] = $related_item->ID();
295 295
                 } else {
296 296
                     $related_items = $this->_model_object->get_many_related($relation_name);
297 297
                     $ids = array();
298 298
                     foreach ($related_items as $related_item) {
299 299
                         $ids[] = $related_item->ID();
300 300
                     }
301
-                    $defaults[ $relation_name ] = $ids;
301
+                    $defaults[$relation_name] = $ids;
302 302
                 }
303 303
             }
304 304
         }
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     {
337 337
         parent::_normalize($req_data);
338 338
         // create or set the model object, if it isn't already
339
-        if (! $this->_model_object) {
339
+        if ( ! $this->_model_object) {
340 340
             // check to see if the form indicates a PK, in which case we want to only retrieve it and update it
341 341
             $pk_name = $this->_model->primary_key_name();
342 342
             $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
      */
362 362
     public function save()
363 363
     {
364
-        if (! $this->_model_object) {
364
+        if ( ! $this->_model_object) {
365 365
             throw new EE_Error(sprintf(esc_html__(
366 366
                 "Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
367 367
                 "event_espresso"
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         }
377 377
         $success = $this->_model_object->save();
378 378
         foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
379
-            if (isset($this->_subsections[ $relation_name ])) {
379
+            if (isset($this->_subsections[$relation_name])) {
380 380
                 $success = $this->_save_related_info($relation_name);
381 381
             }
382 382
         }
@@ -463,8 +463,8 @@  discard block
 block discarded – undo
463 463
      */
464 464
     protected function _set_default_name_if_empty()
465 465
     {
466
-        if (! $this->_name) {
467
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
466
+        if ( ! $this->_name) {
467
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
468 468
             $this->_name = $default_name;
469 469
         }
470 470
     }
Please login to merge, or discard this patch.
Indentation   +456 added lines, -456 removed lines patch added patch discarded remove patch
@@ -11,460 +11,460 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Model_Form_Section extends EE_Form_Section_Proper
13 13
 {
14
-    /**
15
-     * @var EEM_Base
16
-     */
17
-    protected $_model = null;
18
-
19
-    /**
20
-     * @var EE_Base_Class
21
-     */
22
-    protected $_model_object = null;
23
-
24
-
25
-
26
-    /**
27
-     * @param array        $options_array   keys: {
28
-     * @type EEM_Base      $model
29
-     * @type EE_Base_Class $model_object
30
-     * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
31
-     *       values are the arrays as you would pass them to that subsection
32
-     *                                      }
33
-     * @throws EE_Error
34
-     */
35
-    public function __construct($options_array = array())
36
-    {
37
-        if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
38
-            $this->_model = $options_array['model'];
39
-        }
40
-        if (! $this->_model || ! $this->_model instanceof EEM_Base) {
41
-            throw new EE_Error(sprintf(esc_html__(
42
-                "Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
43
-                "event_espresso"
44
-            )));
45
-        }
46
-        if (isset($options_array['subsection_args'])) {
47
-            $subsection_args = $options_array['subsection_args'];
48
-        } else {
49
-            $subsection_args = array();
50
-        }
51
-        // gather fields and relations to convert to inputs
52
-        // but if they're just going to exclude a field anyways, don't bother converting it to an input
53
-        $exclude = $this->_subsections;
54
-        if (isset($options_array['exclude'])) {
55
-            $exclude = array_merge($exclude, array_flip($options_array['exclude']));
56
-        }
57
-        $model_fields = array_diff_key($this->_model->field_settings(), $exclude);
58
-        $model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
59
-        // convert fields and relations to inputs
60
-        $this->_subsections = array_merge(
61
-            $this->_convert_model_fields_to_inputs($model_fields),
62
-            $this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
63
-            $this->_subsections
64
-        );
65
-        parent::__construct($options_array);
66
-        if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
67
-            $this->populate_model_obj($options_array['model_object']);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * For now, just makes inputs for only HABTM relations
75
-     *
76
-     * @param EE_Model_Relation_Base[] $relations
77
-     * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
78
-     *                                                  their values are {
79
-     * @type array {
80
-     * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
81
-     *                                                  }
82
-     *                                                  }
83
-     * @return array
84
-     */
85
-    protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
86
-    {
87
-        $inputs = array();
88
-        foreach ($relations as $relation_name => $relation_obj) {
89
-            $input_constructor_args = array(
90
-                array_merge(
91
-                    array(
92
-                        'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
93
-                        'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
94
-                            ? $relation_obj->get_other_model()->item_name(1)
95
-                            : $relation_obj->get_other_model()
96
-                                           ->item_name(2),
97
-                    ),
98
-                    $subsection_args
99
-                ),
100
-            );
101
-            $input = null;
102
-            switch (get_class($relation_obj)) {
103
-                case 'EE_HABTM_Relation':
104
-                    if (
105
-                        isset($subsection_args[ $relation_name ])
106
-                        && isset($subsection_args[ $relation_name ]['model_objects'])
107
-                    ) {
108
-                        $model_objects = $subsection_args[ $relation_name ]['model_objects'];
109
-                    } else {
110
-                        $model_objects = $relation_obj->get_other_model()->get_all();
111
-                    }
112
-                    $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
113
-                    break;
114
-                default:
115
-            }
116
-            if ($input) {
117
-                $inputs[ $relation_name ] = $input;
118
-            }
119
-        }
120
-        return $inputs;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Changes model fields into form section inputs
127
-     *
128
-     * @param EE_Model_Field_Base[] $model_fields keys are the model's name
129
-     * @throws EE_Error
130
-     * @return EE_Form_Input_Base[]
131
-     */
132
-    protected function _convert_model_fields_to_inputs($model_fields = array())
133
-    {
134
-        $inputs = array();
135
-        foreach ($model_fields as $field_name => $model_field) {
136
-            if ($model_field instanceof EE_Model_Field_Base) {
137
-                $input_constructor_args = array(
138
-                    array(
139
-                        'required'        => ! $model_field->is_nullable()
140
-                                             && $model_field->get_default_value()
141
-                                                === null,
142
-                        'html_label_text' => $model_field->get_nicename(),
143
-                        'default'         => $model_field->get_default_value(),
144
-                    ),
145
-                );
146
-                switch (get_class($model_field)) {
147
-                    case 'EE_All_Caps_Text_Field':
148
-                    case 'EE_Any_Foreign_Model_Name_Field':
149
-                        $input_class = 'EE_Text_Input';
150
-                        break;
151
-                    case 'EE_Boolean_Field':
152
-                        $input_class = 'EE_Yes_No_Input';
153
-                        break;
154
-                    case 'EE_Datetime_Field':
155
-                        throw new EE_Error(sprintf(esc_html__(
156
-                            "Model field '%s' does not yet have a known conversion to form input",
157
-                            "event_espresso"
158
-                        ), get_class($model_field)));
159
-                        break;
160
-                    case 'EE_Email_Field':
161
-                        $input_class = 'EE_Email_Input';
162
-                        break;
163
-                    case 'EE_Enum_Integer_Field':
164
-                        throw new EE_Error(sprintf(esc_html__(
165
-                            "Model field '%s' does not yet have a known conversion to form input",
166
-                            "event_espresso"
167
-                        ), get_class($model_field)));
168
-                        break;
169
-                    case 'EE_Enum_Text_Field':
170
-                        throw new EE_Error(sprintf(esc_html__(
171
-                            "Model field '%s' does not yet have a known conversion to form input",
172
-                            "event_espresso"
173
-                        ), get_class($model_field)));
174
-                        break;
175
-                    case 'EE_Float_Field':
176
-                        $input_class = 'EE_Float_Input';
177
-                        break;
178
-                    case 'EE_Foreign_Key_Int_Field':
179
-                    case 'EE_Foreign_Key_String_Field':
180
-                    case 'EE_WP_User_Field':
181
-                        $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
182
-                            ? $model_field->get_model_class_names_pointed_to() : array();
183
-                        if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
184
-                            $input_class = 'EE_Text_Input';
185
-                        } else {
186
-                            // so its just one model
187
-                            $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
188
-                            $model = EE_Registry::instance()->load_model($model_name);
189
-                            $model_names = $model->get_all_names(array('limit' => 10));
190
-                            if ($model_field->is_nullable()) {
191
-                                array_unshift($model_names, esc_html__("Please Select", 'event_espresso'));
192
-                            }
193
-                            $input_constructor_args[1] = $input_constructor_args[0];
194
-                            $input_constructor_args[0] = $model_names;
195
-                            $input_class = 'EE_Select_Input';
196
-                        }
197
-                        break;
198
-                    case 'EE_Full_HTML_Field':
199
-                        $input_class = 'EE_Text_Area_Input';
200
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
201
-                        break;
202
-                    case 'EE_Infinite_Integer':
203
-                        throw new EE_Error(sprintf(esc_html__(
204
-                            "Model field '%s' does not yet have a known conversion to form input",
205
-                            "event_espresso"
206
-                        ), get_class($model_field)));
207
-                        break;
208
-                    case 'EE_Integer_Field':
209
-                        $input_class = 'EE_Text_Input';
210
-                        break;
211
-                    case 'EE_Maybe_Serialized_Text_Field':
212
-                        $input_class = 'EE_Text_Area_Input';
213
-                        break;
214
-                    case 'EE_Money_Field':
215
-                        throw new EE_Error(sprintf(esc_html__(
216
-                            "Model field '%s' does not yet have a known conversion to form input",
217
-                            "event_espresso"
218
-                        ), get_class($model_field)));
219
-                        break;
220
-                    case 'EE_Post_Content_Field':
221
-                        $input_class = 'EE_Text_Area_Input';
222
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
223
-                        break;
224
-                    case 'EE_Plain_Text_Field':
225
-                        $input_class = 'EE_Text_Input';
226
-                        break;
227
-                    case 'EE_Primary_Key_Int_Field':
228
-                        $input_class = 'EE_Hidden_Input';
229
-                        $input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization();
230
-                        break;
231
-                    case 'EE_Primary_Key_String_Field':
232
-                        $input_class = 'EE_Hidden_Input';
233
-                        break;
234
-                    case 'EE_Serialized_Text_Field':
235
-                        $input_class = 'EE_Text_Area_Input';
236
-                        break;
237
-                    case 'EE_Simple_HTML_Field':
238
-                        $input_class = 'EE_Text_Area_Input';
239
-                        $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
240
-                        break;
241
-                    case 'EE_Slug_Field':
242
-                        $input_class = 'EE_Text_Input';
243
-                        break;
244
-                    case 'EE_Trashed_Flag_Field':
245
-                        $input_class = 'EE_Yes_No_Input';
246
-                        break;
247
-                    case 'EE_WP_Post_Status_Field':
248
-                        throw new EE_Error(sprintf(esc_html__(
249
-                            "Model field '%s' does not yet have a known conversion to form input",
250
-                            "event_espresso"
251
-                        ), get_class($model_field)));
252
-                        break;
253
-                    case 'EE_WP_Post_Type_Field':
254
-                        throw new EE_Error(sprintf(esc_html__(
255
-                            "Model field '%s' does not yet have a known conversion to form input",
256
-                            "event_espresso"
257
-                        ), get_class($model_field)));
258
-                        break;
259
-                    default:
260
-                        throw new EE_Error(sprintf(esc_html__(
261
-                            "Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
262
-                            "event_espresso"
263
-                        ), get_class($model_field)));
264
-                }
265
-                $reflection = new ReflectionClass($input_class);
266
-                $input = $reflection->newInstanceArgs($input_constructor_args);
267
-                $inputs[ $field_name ] = $input;
268
-            }
269
-        }
270
-        return $inputs;
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * Mostly the same as populate_defaults , except takes a model object as input, not an array,
277
-     * and also sets the form's _model_object
278
-     *
279
-     * @param EE_Base_Class $model_obj
280
-     * @return void
281
-     */
282
-    public function populate_model_obj($model_obj)
283
-    {
284
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
285
-        $this->_model_object = $model_obj;
286
-        $defaults = $model_obj->model_field_array();
287
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
288
-            $subsection = $this->get_subsection($relation_name, false);
289
-            if ($subsection instanceof EE_Form_Input_Base) {
290
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
291
-                    // then we only expect there to be one
292
-                    $related_item = $this->_model_object->get_first_related($relation_name);
293
-                    $defaults[ $relation_name ] = $related_item->ID();
294
-                } else {
295
-                    $related_items = $this->_model_object->get_many_related($relation_name);
296
-                    $ids = array();
297
-                    foreach ($related_items as $related_item) {
298
-                        $ids[] = $related_item->ID();
299
-                    }
300
-                    $defaults[ $relation_name ] = $ids;
301
-                }
302
-            }
303
-        }
304
-        $defaults = apply_filters(
305
-            'FHEE__EE_Model_Form_Section__populate_model_obj',
306
-            $defaults,
307
-            $this
308
-        );
309
-        $this->populate_defaults($defaults);
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * Gets all the input values that correspond to model fields. Keys are the input/field names,
316
-     * values are their normalized values
317
-     *
318
-     * @return array
319
-     */
320
-    public function inputs_values_corresponding_to_model_fields()
321
-    {
322
-        return array_intersect_key($this->input_values(), $this->_model->field_settings());
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * After we've normalized the data as normal, set the corresponding model object
329
-     * on the form.
330
-     *
331
-     * @param array $req_data should usually be the form post/request data (the default).
332
-     * @return void
333
-     */
334
-    public function _normalize($req_data)
335
-    {
336
-        parent::_normalize($req_data);
337
-        // create or set the model object, if it isn't already
338
-        if (! $this->_model_object) {
339
-            // check to see if the form indicates a PK, in which case we want to only retrieve it and update it
340
-            $pk_name = $this->_model->primary_key_name();
341
-            $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
342
-            if ($model_obj) {
343
-                $this->_model_object = $model_obj;
344
-            } else {
345
-                $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
346
-            }
347
-        }
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * After this form has been initialized and is verified to be valid,
354
-     * either creates a model object from its data and saves it, or updates
355
-     * the model object its data represents
356
-     *
357
-     * @throws EE_Error
358
-     * @return int, 1 on a successful update, the ID of
359
-     *                    the new entry on insert; 0 on failure
360
-     */
361
-    public function save()
362
-    {
363
-        if (! $this->_model_object) {
364
-            throw new EE_Error(sprintf(esc_html__(
365
-                "Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
366
-                "event_espresso"
367
-            ), get_class($this->_model)));
368
-        }
369
-        // ok so the model object is set. Just set it with the submitted form data
370
-        foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
371
-            // only set the non-primary key
372
-            if ($field_name != $this->_model->primary_key_name()) {
373
-                $this->_model_object->set($field_name, $field_value);
374
-            }
375
-        }
376
-        $success = $this->_model_object->save();
377
-        foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
378
-            if (isset($this->_subsections[ $relation_name ])) {
379
-                $success = $this->_save_related_info($relation_name);
380
-            }
381
-        }
382
-        do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
383
-        return $success;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * Automatically finds the related model info from the form, if present, and
390
-     * save the relations indicated
391
-     *
392
-     * @type string $relation_name
393
-     * @return bool
394
-     * @throws EE_Error
395
-     */
396
-    protected function _save_related_info($relation_name)
397
-    {
398
-        $relation_obj = $this->_model->related_settings_for($relation_name);
399
-        if ($relation_obj instanceof EE_Belongs_To_Relation) {
400
-            // there is just a foreign key on this model pointing to that one
401
-            $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
402
-        } elseif ($relation_obj instanceof EE_Has_Many_Relation) {
403
-            // then we want to consider all of its currently-related things.
404
-            // if they're in this list, keep them
405
-            // if they're not in this list, remove them
406
-            // and lastly add all the new items
407
-            throw new EE_Error(sprintf(esc_html__(
408
-                'Automatic saving of related info across a "has many" relation is not yet supported',
409
-                "event_espresso"
410
-            )));
411
-        } elseif ($relation_obj instanceof EE_HABTM_Relation) {
412
-            // delete everything NOT in this list
413
-            $normalized_input_value = $this->get_input_value($relation_name);
414
-            if ($normalized_input_value && is_array($normalized_input_value)) {
415
-                $where_query_params = array(
416
-                    $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
417
-                );
418
-            } else {
419
-                $where_query_params = array();
420
-            }
421
-            $this->_model_object->_remove_relations($relation_name, $where_query_params);
422
-            foreach ($normalized_input_value as $id) {
423
-                $this->_model_object->_add_relation_to($id, $relation_name);
424
-            }
425
-        }
426
-        return true;
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * Gets the model of this model form
433
-     *
434
-     * @return EEM_Base
435
-     */
436
-    public function get_model()
437
-    {
438
-        return $this->_model;
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Gets the model object for this model form, which was either set
445
-     * upon construction (using the $options_array arg 'model_object'), by using
446
-     * set_model_object($model_obj), or implicitly
447
-     * when receive_form_submission($req_data) was called.
448
-     *
449
-     * @return EE_Base_Class
450
-     */
451
-    public function get_model_object()
452
-    {
453
-        return $this->_model_object;
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * gets teh default name of this form section if none is specified
460
-     *
461
-     * @return string
462
-     */
463
-    protected function _set_default_name_if_empty()
464
-    {
465
-        if (! $this->_name) {
466
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
467
-            $this->_name = $default_name;
468
-        }
469
-    }
14
+	/**
15
+	 * @var EEM_Base
16
+	 */
17
+	protected $_model = null;
18
+
19
+	/**
20
+	 * @var EE_Base_Class
21
+	 */
22
+	protected $_model_object = null;
23
+
24
+
25
+
26
+	/**
27
+	 * @param array        $options_array   keys: {
28
+	 * @type EEM_Base      $model
29
+	 * @type EE_Base_Class $model_object
30
+	 * @type array         $subsection_args array keys should be subsection names (that either do or will exist), and
31
+	 *       values are the arrays as you would pass them to that subsection
32
+	 *                                      }
33
+	 * @throws EE_Error
34
+	 */
35
+	public function __construct($options_array = array())
36
+	{
37
+		if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) {
38
+			$this->_model = $options_array['model'];
39
+		}
40
+		if (! $this->_model || ! $this->_model instanceof EEM_Base) {
41
+			throw new EE_Error(sprintf(esc_html__(
42
+				"Model Form Sections must first specify the _model property to be a subclass of EEM_Base",
43
+				"event_espresso"
44
+			)));
45
+		}
46
+		if (isset($options_array['subsection_args'])) {
47
+			$subsection_args = $options_array['subsection_args'];
48
+		} else {
49
+			$subsection_args = array();
50
+		}
51
+		// gather fields and relations to convert to inputs
52
+		// but if they're just going to exclude a field anyways, don't bother converting it to an input
53
+		$exclude = $this->_subsections;
54
+		if (isset($options_array['exclude'])) {
55
+			$exclude = array_merge($exclude, array_flip($options_array['exclude']));
56
+		}
57
+		$model_fields = array_diff_key($this->_model->field_settings(), $exclude);
58
+		$model_relations = array_diff_key($this->_model->relation_settings(), $exclude);
59
+		// convert fields and relations to inputs
60
+		$this->_subsections = array_merge(
61
+			$this->_convert_model_fields_to_inputs($model_fields),
62
+			$this->_convert_model_relations_to_inputs($model_relations, $subsection_args),
63
+			$this->_subsections
64
+		);
65
+		parent::__construct($options_array);
66
+		if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) {
67
+			$this->populate_model_obj($options_array['model_object']);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * For now, just makes inputs for only HABTM relations
75
+	 *
76
+	 * @param EE_Model_Relation_Base[] $relations
77
+	 * @param array                    $subsection_args keys should be existing or soon-to-be-existing input names, and
78
+	 *                                                  their values are {
79
+	 * @type array {
80
+	 * @type EE_Base_Class[]           $model_objects   if the subsection is an EE_Select_Multi_Model_Input
81
+	 *                                                  }
82
+	 *                                                  }
83
+	 * @return array
84
+	 */
85
+	protected function _convert_model_relations_to_inputs($relations, $subsection_args = array())
86
+	{
87
+		$inputs = array();
88
+		foreach ($relations as $relation_name => $relation_obj) {
89
+			$input_constructor_args = array(
90
+				array_merge(
91
+					array(
92
+						'required'        => $relation_obj instanceof EE_Belongs_To_Relation,
93
+						'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation
94
+							? $relation_obj->get_other_model()->item_name(1)
95
+							: $relation_obj->get_other_model()
96
+										   ->item_name(2),
97
+					),
98
+					$subsection_args
99
+				),
100
+			);
101
+			$input = null;
102
+			switch (get_class($relation_obj)) {
103
+				case 'EE_HABTM_Relation':
104
+					if (
105
+						isset($subsection_args[ $relation_name ])
106
+						&& isset($subsection_args[ $relation_name ]['model_objects'])
107
+					) {
108
+						$model_objects = $subsection_args[ $relation_name ]['model_objects'];
109
+					} else {
110
+						$model_objects = $relation_obj->get_other_model()->get_all();
111
+					}
112
+					$input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args);
113
+					break;
114
+				default:
115
+			}
116
+			if ($input) {
117
+				$inputs[ $relation_name ] = $input;
118
+			}
119
+		}
120
+		return $inputs;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Changes model fields into form section inputs
127
+	 *
128
+	 * @param EE_Model_Field_Base[] $model_fields keys are the model's name
129
+	 * @throws EE_Error
130
+	 * @return EE_Form_Input_Base[]
131
+	 */
132
+	protected function _convert_model_fields_to_inputs($model_fields = array())
133
+	{
134
+		$inputs = array();
135
+		foreach ($model_fields as $field_name => $model_field) {
136
+			if ($model_field instanceof EE_Model_Field_Base) {
137
+				$input_constructor_args = array(
138
+					array(
139
+						'required'        => ! $model_field->is_nullable()
140
+											 && $model_field->get_default_value()
141
+												=== null,
142
+						'html_label_text' => $model_field->get_nicename(),
143
+						'default'         => $model_field->get_default_value(),
144
+					),
145
+				);
146
+				switch (get_class($model_field)) {
147
+					case 'EE_All_Caps_Text_Field':
148
+					case 'EE_Any_Foreign_Model_Name_Field':
149
+						$input_class = 'EE_Text_Input';
150
+						break;
151
+					case 'EE_Boolean_Field':
152
+						$input_class = 'EE_Yes_No_Input';
153
+						break;
154
+					case 'EE_Datetime_Field':
155
+						throw new EE_Error(sprintf(esc_html__(
156
+							"Model field '%s' does not yet have a known conversion to form input",
157
+							"event_espresso"
158
+						), get_class($model_field)));
159
+						break;
160
+					case 'EE_Email_Field':
161
+						$input_class = 'EE_Email_Input';
162
+						break;
163
+					case 'EE_Enum_Integer_Field':
164
+						throw new EE_Error(sprintf(esc_html__(
165
+							"Model field '%s' does not yet have a known conversion to form input",
166
+							"event_espresso"
167
+						), get_class($model_field)));
168
+						break;
169
+					case 'EE_Enum_Text_Field':
170
+						throw new EE_Error(sprintf(esc_html__(
171
+							"Model field '%s' does not yet have a known conversion to form input",
172
+							"event_espresso"
173
+						), get_class($model_field)));
174
+						break;
175
+					case 'EE_Float_Field':
176
+						$input_class = 'EE_Float_Input';
177
+						break;
178
+					case 'EE_Foreign_Key_Int_Field':
179
+					case 'EE_Foreign_Key_String_Field':
180
+					case 'EE_WP_User_Field':
181
+						$models_pointed_to = $model_field instanceof EE_Field_With_Model_Name
182
+							? $model_field->get_model_class_names_pointed_to() : array();
183
+						if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) {
184
+							$input_class = 'EE_Text_Input';
185
+						} else {
186
+							// so its just one model
187
+							$model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to;
188
+							$model = EE_Registry::instance()->load_model($model_name);
189
+							$model_names = $model->get_all_names(array('limit' => 10));
190
+							if ($model_field->is_nullable()) {
191
+								array_unshift($model_names, esc_html__("Please Select", 'event_espresso'));
192
+							}
193
+							$input_constructor_args[1] = $input_constructor_args[0];
194
+							$input_constructor_args[0] = $model_names;
195
+							$input_class = 'EE_Select_Input';
196
+						}
197
+						break;
198
+					case 'EE_Full_HTML_Field':
199
+						$input_class = 'EE_Text_Area_Input';
200
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
201
+						break;
202
+					case 'EE_Infinite_Integer':
203
+						throw new EE_Error(sprintf(esc_html__(
204
+							"Model field '%s' does not yet have a known conversion to form input",
205
+							"event_espresso"
206
+						), get_class($model_field)));
207
+						break;
208
+					case 'EE_Integer_Field':
209
+						$input_class = 'EE_Text_Input';
210
+						break;
211
+					case 'EE_Maybe_Serialized_Text_Field':
212
+						$input_class = 'EE_Text_Area_Input';
213
+						break;
214
+					case 'EE_Money_Field':
215
+						throw new EE_Error(sprintf(esc_html__(
216
+							"Model field '%s' does not yet have a known conversion to form input",
217
+							"event_espresso"
218
+						), get_class($model_field)));
219
+						break;
220
+					case 'EE_Post_Content_Field':
221
+						$input_class = 'EE_Text_Area_Input';
222
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy());
223
+						break;
224
+					case 'EE_Plain_Text_Field':
225
+						$input_class = 'EE_Text_Input';
226
+						break;
227
+					case 'EE_Primary_Key_Int_Field':
228
+						$input_class = 'EE_Hidden_Input';
229
+						$input_constructor_args[0]['normalization_strategy'] = new EE_Int_Normalization();
230
+						break;
231
+					case 'EE_Primary_Key_String_Field':
232
+						$input_class = 'EE_Hidden_Input';
233
+						break;
234
+					case 'EE_Serialized_Text_Field':
235
+						$input_class = 'EE_Text_Area_Input';
236
+						break;
237
+					case 'EE_Simple_HTML_Field':
238
+						$input_class = 'EE_Text_Area_Input';
239
+						$input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy());
240
+						break;
241
+					case 'EE_Slug_Field':
242
+						$input_class = 'EE_Text_Input';
243
+						break;
244
+					case 'EE_Trashed_Flag_Field':
245
+						$input_class = 'EE_Yes_No_Input';
246
+						break;
247
+					case 'EE_WP_Post_Status_Field':
248
+						throw new EE_Error(sprintf(esc_html__(
249
+							"Model field '%s' does not yet have a known conversion to form input",
250
+							"event_espresso"
251
+						), get_class($model_field)));
252
+						break;
253
+					case 'EE_WP_Post_Type_Field':
254
+						throw new EE_Error(sprintf(esc_html__(
255
+							"Model field '%s' does not yet have a known conversion to form input",
256
+							"event_espresso"
257
+						), get_class($model_field)));
258
+						break;
259
+					default:
260
+						throw new EE_Error(sprintf(esc_html__(
261
+							"Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement",
262
+							"event_espresso"
263
+						), get_class($model_field)));
264
+				}
265
+				$reflection = new ReflectionClass($input_class);
266
+				$input = $reflection->newInstanceArgs($input_constructor_args);
267
+				$inputs[ $field_name ] = $input;
268
+			}
269
+		}
270
+		return $inputs;
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * Mostly the same as populate_defaults , except takes a model object as input, not an array,
277
+	 * and also sets the form's _model_object
278
+	 *
279
+	 * @param EE_Base_Class $model_obj
280
+	 * @return void
281
+	 */
282
+	public function populate_model_obj($model_obj)
283
+	{
284
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
285
+		$this->_model_object = $model_obj;
286
+		$defaults = $model_obj->model_field_array();
287
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
288
+			$subsection = $this->get_subsection($relation_name, false);
289
+			if ($subsection instanceof EE_Form_Input_Base) {
290
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
291
+					// then we only expect there to be one
292
+					$related_item = $this->_model_object->get_first_related($relation_name);
293
+					$defaults[ $relation_name ] = $related_item->ID();
294
+				} else {
295
+					$related_items = $this->_model_object->get_many_related($relation_name);
296
+					$ids = array();
297
+					foreach ($related_items as $related_item) {
298
+						$ids[] = $related_item->ID();
299
+					}
300
+					$defaults[ $relation_name ] = $ids;
301
+				}
302
+			}
303
+		}
304
+		$defaults = apply_filters(
305
+			'FHEE__EE_Model_Form_Section__populate_model_obj',
306
+			$defaults,
307
+			$this
308
+		);
309
+		$this->populate_defaults($defaults);
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * Gets all the input values that correspond to model fields. Keys are the input/field names,
316
+	 * values are their normalized values
317
+	 *
318
+	 * @return array
319
+	 */
320
+	public function inputs_values_corresponding_to_model_fields()
321
+	{
322
+		return array_intersect_key($this->input_values(), $this->_model->field_settings());
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * After we've normalized the data as normal, set the corresponding model object
329
+	 * on the form.
330
+	 *
331
+	 * @param array $req_data should usually be the form post/request data (the default).
332
+	 * @return void
333
+	 */
334
+	public function _normalize($req_data)
335
+	{
336
+		parent::_normalize($req_data);
337
+		// create or set the model object, if it isn't already
338
+		if (! $this->_model_object) {
339
+			// check to see if the form indicates a PK, in which case we want to only retrieve it and update it
340
+			$pk_name = $this->_model->primary_key_name();
341
+			$model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name));
342
+			if ($model_obj) {
343
+				$this->_model_object = $model_obj;
344
+			} else {
345
+				$this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name());
346
+			}
347
+		}
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * After this form has been initialized and is verified to be valid,
354
+	 * either creates a model object from its data and saves it, or updates
355
+	 * the model object its data represents
356
+	 *
357
+	 * @throws EE_Error
358
+	 * @return int, 1 on a successful update, the ID of
359
+	 *                    the new entry on insert; 0 on failure
360
+	 */
361
+	public function save()
362
+	{
363
+		if (! $this->_model_object) {
364
+			throw new EE_Error(sprintf(esc_html__(
365
+				"Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically",
366
+				"event_espresso"
367
+			), get_class($this->_model)));
368
+		}
369
+		// ok so the model object is set. Just set it with the submitted form data
370
+		foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) {
371
+			// only set the non-primary key
372
+			if ($field_name != $this->_model->primary_key_name()) {
373
+				$this->_model_object->set($field_name, $field_value);
374
+			}
375
+		}
376
+		$success = $this->_model_object->save();
377
+		foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
378
+			if (isset($this->_subsections[ $relation_name ])) {
379
+				$success = $this->_save_related_info($relation_name);
380
+			}
381
+		}
382
+		do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success);
383
+		return $success;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * Automatically finds the related model info from the form, if present, and
390
+	 * save the relations indicated
391
+	 *
392
+	 * @type string $relation_name
393
+	 * @return bool
394
+	 * @throws EE_Error
395
+	 */
396
+	protected function _save_related_info($relation_name)
397
+	{
398
+		$relation_obj = $this->_model->related_settings_for($relation_name);
399
+		if ($relation_obj instanceof EE_Belongs_To_Relation) {
400
+			// there is just a foreign key on this model pointing to that one
401
+			$this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name);
402
+		} elseif ($relation_obj instanceof EE_Has_Many_Relation) {
403
+			// then we want to consider all of its currently-related things.
404
+			// if they're in this list, keep them
405
+			// if they're not in this list, remove them
406
+			// and lastly add all the new items
407
+			throw new EE_Error(sprintf(esc_html__(
408
+				'Automatic saving of related info across a "has many" relation is not yet supported',
409
+				"event_espresso"
410
+			)));
411
+		} elseif ($relation_obj instanceof EE_HABTM_Relation) {
412
+			// delete everything NOT in this list
413
+			$normalized_input_value = $this->get_input_value($relation_name);
414
+			if ($normalized_input_value && is_array($normalized_input_value)) {
415
+				$where_query_params = array(
416
+					$relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value),
417
+				);
418
+			} else {
419
+				$where_query_params = array();
420
+			}
421
+			$this->_model_object->_remove_relations($relation_name, $where_query_params);
422
+			foreach ($normalized_input_value as $id) {
423
+				$this->_model_object->_add_relation_to($id, $relation_name);
424
+			}
425
+		}
426
+		return true;
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * Gets the model of this model form
433
+	 *
434
+	 * @return EEM_Base
435
+	 */
436
+	public function get_model()
437
+	{
438
+		return $this->_model;
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Gets the model object for this model form, which was either set
445
+	 * upon construction (using the $options_array arg 'model_object'), by using
446
+	 * set_model_object($model_obj), or implicitly
447
+	 * when receive_form_submission($req_data) was called.
448
+	 *
449
+	 * @return EE_Base_Class
450
+	 */
451
+	public function get_model_object()
452
+	{
453
+		return $this->_model_object;
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * gets teh default name of this form section if none is specified
460
+	 *
461
+	 * @return string
462
+	 */
463
+	protected function _set_default_name_if_empty()
464
+	{
465
+		if (! $this->_name) {
466
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
467
+			$this->_name = $default_name;
468
+		}
469
+	}
470 470
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/EE_Sample_Form.form.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -2,62 +2,62 @@
 block discarded – undo
2 2
 
3 3
 class EE_Sample_Form extends EE_Form_Section_Proper
4 4
 {
5
-    public function __construct()
6
-    {
7
-        $this->_subsections = array(
8
-            'h1' => new EE_Form_Section_HTML('hello wordl'),
9
-            'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
10
-            'email' => new EE_Email_Input(array('required' => false)),
11
-            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
12
-            'month_normal' => new EE_Month_Input(),
13
-            'month_leading_zero' => new EE_Month_Input(true),
14
-            'year_2' => new EE_Year_Input(false, 1, 1),
15
-            'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')),
16
-            'yes_no' => new EE_Yes_No_Input(array('html_label_text' =>  esc_html__("Yes or No", "event_espresso"))),
17
-            'credit_card' => new EE_Credit_Card_Input(),
18
-            'image_1' => new EE_Admin_File_Uploader_Input(),
19
-            'image_2' => new EE_Admin_File_Uploader_Input(),
20
-            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
21
-            'float' => new EE_Float_Input(),
22
-            'essay' => new EE_Text_Area_Input(),
23
-            'amenities' => new EE_Select_Multiple_Input(
24
-                array(
25
-                    'hottub' => 'Hot Tub',
26
-                    'balcony' => "Balcony",
27
-                    'skylight' => 'SkyLight',
28
-                    'no_axe' => 'No Axe Murderers'
29
-                ),
30
-                array(
31
-                    'default' => array(
32
-                        'hottub',
33
-                        'no_axe' ),
34
-                )
35
-            ),
36
-            'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()),
37
-            );
38
-        $this->_layout_strategy = new EE_Div_Per_Section_Layout();
39
-        parent::__construct();
40
-    }
5
+	public function __construct()
6
+	{
7
+		$this->_subsections = array(
8
+			'h1' => new EE_Form_Section_HTML('hello wordl'),
9
+			'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
10
+			'email' => new EE_Email_Input(array('required' => false)),
11
+			'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
12
+			'month_normal' => new EE_Month_Input(),
13
+			'month_leading_zero' => new EE_Month_Input(true),
14
+			'year_2' => new EE_Year_Input(false, 1, 1),
15
+			'year_4' => new EE_Year_Input(true, 0, 10, array('default' => '2017')),
16
+			'yes_no' => new EE_Yes_No_Input(array('html_label_text' =>  esc_html__("Yes or No", "event_espresso"))),
17
+			'credit_card' => new EE_Credit_Card_Input(),
18
+			'image_1' => new EE_Admin_File_Uploader_Input(),
19
+			'image_2' => new EE_Admin_File_Uploader_Input(),
20
+			'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
21
+			'float' => new EE_Float_Input(),
22
+			'essay' => new EE_Text_Area_Input(),
23
+			'amenities' => new EE_Select_Multiple_Input(
24
+				array(
25
+					'hottub' => 'Hot Tub',
26
+					'balcony' => "Balcony",
27
+					'skylight' => 'SkyLight',
28
+					'no_axe' => 'No Axe Murderers'
29
+				),
30
+				array(
31
+					'default' => array(
32
+						'hottub',
33
+						'no_axe' ),
34
+				)
35
+			),
36
+			'payment_methods' => new EE_Select_Multi_Model_Input(EEM_Payment_Method::instance()->get_all()),
37
+			);
38
+		$this->_layout_strategy = new EE_Div_Per_Section_Layout();
39
+		parent::__construct();
40
+	}
41 41
 
42
-    /**
43
-     * Extra validation for the 'name' input.
44
-     * @param EE_Text_Input $form_input
45
-     */
46
-    public function _validate_name($form_input)
47
-    {
48
-        if ($form_input->raw_value() != 'Mike') {
49
-            $form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike');
50
-        }
51
-    }
42
+	/**
43
+	 * Extra validation for the 'name' input.
44
+	 * @param EE_Text_Input $form_input
45
+	 */
46
+	public function _validate_name($form_input)
47
+	{
48
+		if ($form_input->raw_value() != 'Mike') {
49
+			$form_input->add_validation_error(esc_html__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike');
50
+		}
51
+	}
52 52
 
53
-    public function _validate()
54
-    {
55
-        parent::_validate();
56
-        if (
57
-            $this->_subsections['shirt_size']->normalized_value() == 's'
58
-                && $this->_subsections['year_4']->normalized_value() < 2010
59
-        ) {
60
-            $this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old');
61
-        }
62
-    }
53
+	public function _validate()
54
+	{
55
+		parent::_validate();
56
+		if (
57
+			$this->_subsections['shirt_size']->normalized_value() == 's'
58
+				&& $this->_subsections['year_4']->normalized_value() < 2010
59
+		) {
60
+			$this->add_validation_error(esc_html__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old');
61
+		}
62
+	}
63 63
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@  discard block
 block discarded – undo
6 6
     {
7 7
         $this->_subsections = array(
8 8
             'h1' => new EE_Form_Section_HTML('hello wordl'),
9
-            'name' => new EE_Text_Input(array('required' => true,'default' => 'your name here')),
9
+            'name' => new EE_Text_Input(array('required' => true, 'default' => 'your name here')),
10 10
             'email' => new EE_Email_Input(array('required' => false)),
11
-            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"),'m' =>  esc_html__("Medium", "event_espresso"),'l' =>  esc_html__("Large", "event_espresso")), array('required' => true,'default' => 's')),
11
+            'shirt_size' => new EE_Select_Input(array('' => 'Please select...', 's' =>  esc_html__("Small", "event_espresso"), 'm' =>  esc_html__("Medium", "event_espresso"), 'l' =>  esc_html__("Large", "event_espresso")), array('required' => true, 'default' => 's')),
12 12
             'month_normal' => new EE_Month_Input(),
13 13
             'month_leading_zero' => new EE_Month_Input(true),
14 14
             'year_2' => new EE_Year_Input(false, 1, 1),
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
             'credit_card' => new EE_Credit_Card_Input(),
18 18
             'image_1' => new EE_Admin_File_Uploader_Input(),
19 19
             'image_2' => new EE_Admin_File_Uploader_Input(),
20
-            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP','mysql' => 'MYSQL'), array('default' => array('php'))),
20
+            'skillz' => new EE_Checkbox_Multi_Input(array('php' => 'PHP', 'mysql' => 'MYSQL'), array('default' => array('php'))),
21 21
             'float' => new EE_Float_Input(),
22 22
             'essay' => new EE_Text_Area_Input(),
23 23
             'amenities' => new EE_Select_Multiple_Input(
Please login to merge, or discard this patch.
form_sections/payment_methods/EE_Billing_Attendee_Info_Form.form.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
     {
24 24
         $options_array['subsections'] = array_merge(
25 25
             array(
26
-                'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
27
-                'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
28
-                'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
29
-                'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
30
-                'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
31
-                'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
32
-                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
33
-                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
34
-                'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
35
-                'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
26
+                'first_name'    => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso'))),
27
+                'last_name'     => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso'))),
28
+                'email'             => new EE_Email_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso'))),
29
+                'address'           => new EE_Text_Input(array('html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address')),
30
+                'address2'      => new EE_Text_Input(array('html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2')),
31
+                'city'                  => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso'))),
32
+                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso')))),
33
+                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso')))),
34
+                'zip'                   => new EE_Text_Input(array('required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso'))),
35
+                'phone'         => new EE_Text_Input(array('html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso'))),
36 36
             ),
37 37
             isset($options_array['subsections']) ? $options_array['subsections'] : array()
38 38
         );
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
     protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
81 81
     {
82 82
         // If the state input was removed, just return a blank string.
83
-        if (! $this->has_subsection('state')) {
83
+        if ( ! $this->has_subsection('state')) {
84 84
             return '';
85 85
         }
86
-        $state_input =  $this->get_input('state', false);
86
+        $state_input = $this->get_input('state', false);
87 87
         if ($state_input instanceof EE_State_Select_Input) {
88
-            $state_field_to_use =  $state_input->valueFieldName();
88
+            $state_field_to_use = $state_input->valueFieldName();
89 89
         } else {
90 90
             $state_field_to_use = 'STA_ID';
91 91
         }
@@ -115,43 +115,43 @@  discard block
 block discarded – undo
115 115
         // grab billing form data
116 116
         $data = $this->valid_data();
117 117
         // copy first_name
118
-        if (! empty($data['first_name'])) {
118
+        if ( ! empty($data['first_name'])) {
119 119
             $attendee->set_fname($data['first_name']);
120 120
         }
121 121
         // copy last_name
122
-        if (! empty($data['last_name'])) {
122
+        if ( ! empty($data['last_name'])) {
123 123
             $attendee->set_lname($data['last_name']);
124 124
         }
125 125
         // copy email
126
-        if (! empty($data['email'])) {
126
+        if ( ! empty($data['email'])) {
127 127
             $attendee->set_email($data['email']);
128 128
         }
129 129
         // copy address
130
-        if (! empty($data['address'])) {
130
+        if ( ! empty($data['address'])) {
131 131
             $attendee->set_address($data['address']);
132 132
         }
133 133
         // copy address2
134
-        if (! empty($data['address2'])) {
134
+        if ( ! empty($data['address2'])) {
135 135
             $attendee->set_address2($data['address2']);
136 136
         }
137 137
         // copy city
138
-        if (! empty($data['city'])) {
138
+        if ( ! empty($data['city'])) {
139 139
             $attendee->set_city($data['city']);
140 140
         }
141 141
         // copy state
142
-        if (! empty($data['state'])) {
142
+        if ( ! empty($data['state'])) {
143 143
             $attendee->set_state($data['state']);
144 144
         }
145 145
         // copy country
146
-        if (! empty($data['country'])) {
146
+        if ( ! empty($data['country'])) {
147 147
             $attendee->set_country($data['country']);
148 148
         }
149 149
         // copy zip
150
-        if (! empty($data['zip'])) {
150
+        if ( ! empty($data['zip'])) {
151 151
             $attendee->set_zip($data['zip']);
152 152
         }
153 153
         // copy phone
154
-        if (! empty($data['phone'])) {
154
+        if ( ! empty($data['phone'])) {
155 155
             $attendee->set_phone($data['phone']);
156 156
         }
157 157
         return $attendee;
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -13,172 +13,172 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Billing_Attendee_Info_Form extends EE_Billing_Info_Form
15 15
 {
16
-    /**
17
-     *
18
-     * @param EE_Payment_Method $payment_method
19
-     * @param array $options_array @see EE_Form_Section_Proper::__construct()
20
-     */
21
-    public function __construct(EE_Payment_Method $payment_method, $options_array = array())
22
-    {
23
-        $options_array['subsections'] = array_merge(
24
-            array(
25
-                'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
26
-                'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
27
-                'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
28
-                'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
29
-                'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
30
-                'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
31
-                'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
32
-                'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
33
-                'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
34
-                'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
35
-            ),
36
-            isset($options_array['subsections']) ? $options_array['subsections'] : array()
37
-        );
16
+	/**
17
+	 *
18
+	 * @param EE_Payment_Method $payment_method
19
+	 * @param array $options_array @see EE_Form_Section_Proper::__construct()
20
+	 */
21
+	public function __construct(EE_Payment_Method $payment_method, $options_array = array())
22
+	{
23
+		$options_array['subsections'] = array_merge(
24
+			array(
25
+				'first_name'    => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => esc_html__('First Name', 'event_espresso') )),
26
+				'last_name'     => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => esc_html__('Last Name', 'event_espresso') )),
27
+				'email'             => new EE_Email_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => esc_html__('Email', 'event_espresso') )),
28
+				'address'           => new EE_Text_Input(array( 'html_label_text' =>  esc_html__('Address', 'event_espresso'), 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )),
29
+				'address2'      => new EE_Text_Input(array( 'html_label_text' => esc_html__('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )),
30
+				'city'                  => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => esc_html__('City', 'event_espresso') )),
31
+				'state'                 => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => esc_html__('State', 'event_espresso') ))),
32
+				'country'           => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => esc_html__('Country', 'event_espresso') ))),
33
+				'zip'                   => new EE_Text_Input(array( 'required' => true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => esc_html__('Zip', 'event_espresso') )),
34
+				'phone'         => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => esc_html__('Phone', 'event_espresso') )),
35
+			),
36
+			isset($options_array['subsections']) ? $options_array['subsections'] : array()
37
+		);
38 38
 
39
-        parent::__construct($payment_method, $options_array);
40
-    }
39
+		parent::__construct($payment_method, $options_array);
40
+	}
41 41
 
42
-    /**
43
-     * Sets the defaults for the billing form according to the attendee's details
44
-     * @param EE_Attendee $attendee
45
-     */
46
-    public function populate_from_attendee($attendee)
47
-    {
48
-        $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee);
42
+	/**
43
+	 * Sets the defaults for the billing form according to the attendee's details
44
+	 * @param EE_Attendee $attendee
45
+	 */
46
+	public function populate_from_attendee($attendee)
47
+	{
48
+		$attendee = EEM_Attendee::instance()->ensure_is_obj($attendee);
49 49
 
50
-        /** @var $attendee EE_Attendee */
51
-        $this->populate_defaults(
52
-            apply_filters(
53
-                'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee',
54
-                array(
55
-                    'first_name' => $attendee->fname(),
56
-                    'last_name' => $attendee->lname(),
57
-                    'email' => $attendee->email(),
58
-                    'address' => $attendee->address(),
59
-                    'address2' => $attendee->address2(),
60
-                    'city' => $attendee->city(),
61
-                    'state' => $this->getAttendeeStateValueForForm($attendee),
62
-                    'country' => $attendee->country_ID(),
63
-                    'zip' => $attendee->zip(),
64
-                    'phone' => $attendee->phone(),
65
-                ),
66
-                $attendee,
67
-                $this
68
-            )
69
-        );
70
-    }
50
+		/** @var $attendee EE_Attendee */
51
+		$this->populate_defaults(
52
+			apply_filters(
53
+				'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee',
54
+				array(
55
+					'first_name' => $attendee->fname(),
56
+					'last_name' => $attendee->lname(),
57
+					'email' => $attendee->email(),
58
+					'address' => $attendee->address(),
59
+					'address2' => $attendee->address2(),
60
+					'city' => $attendee->city(),
61
+					'state' => $this->getAttendeeStateValueForForm($attendee),
62
+					'country' => $attendee->country_ID(),
63
+					'zip' => $attendee->zip(),
64
+					'phone' => $attendee->phone(),
65
+				),
66
+				$attendee,
67
+				$this
68
+			)
69
+		);
70
+	}
71 71
 
72
-    /**
73
-     * Gets the default value to use for the billing form's state value.
74
-     * @since 4.10.0.p
75
-     * @param EE_Attendee $attendee
76
-     * @return string
77
-     * @throws EE_Error2
78
-     */
79
-    protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
80
-    {
81
-        // If the state input was removed, just return a blank string.
82
-        if (! $this->has_subsection('state')) {
83
-            return '';
84
-        }
85
-        $state_input =  $this->get_input('state', false);
86
-        if ($state_input instanceof EE_State_Select_Input) {
87
-            $state_field_to_use =  $state_input->valueFieldName();
88
-        } else {
89
-            $state_field_to_use = 'STA_ID';
90
-        }
91
-        switch ($state_field_to_use) {
92
-            case 'STA_abbrev':
93
-                $state_value = $attendee->state_abbrev();
94
-                break;
95
-            case 'STA_name':
96
-                $state_value = $attendee->state_name();
97
-                break;
98
-            default:
99
-                $state_value = $attendee->state_ID();
100
-        }
101
-        return $state_value;
102
-    }
72
+	/**
73
+	 * Gets the default value to use for the billing form's state value.
74
+	 * @since 4.10.0.p
75
+	 * @param EE_Attendee $attendee
76
+	 * @return string
77
+	 * @throws EE_Error2
78
+	 */
79
+	protected function getAttendeeStateValueForForm(EE_Attendee $attendee)
80
+	{
81
+		// If the state input was removed, just return a blank string.
82
+		if (! $this->has_subsection('state')) {
83
+			return '';
84
+		}
85
+		$state_input =  $this->get_input('state', false);
86
+		if ($state_input instanceof EE_State_Select_Input) {
87
+			$state_field_to_use =  $state_input->valueFieldName();
88
+		} else {
89
+			$state_field_to_use = 'STA_ID';
90
+		}
91
+		switch ($state_field_to_use) {
92
+			case 'STA_abbrev':
93
+				$state_value = $attendee->state_abbrev();
94
+				break;
95
+			case 'STA_name':
96
+				$state_value = $attendee->state_name();
97
+				break;
98
+			default:
99
+				$state_value = $attendee->state_ID();
100
+		}
101
+		return $state_value;
102
+	}
103 103
 
104 104
 
105 105
 
106
-    /**
107
-     * copy_billing_form_data_to_attendee
108
-     * copies info from the billing form to the attendee's details
109
-     * @param \EE_Attendee $attendee - the attendee object to copy details to
110
-     * @return \EE_Attendee
111
-     */
112
-    public function copy_billing_form_data_to_attendee(EE_Attendee $attendee)
113
-    {
114
-        // grab billing form data
115
-        $data = $this->valid_data();
116
-        // copy first_name
117
-        if (! empty($data['first_name'])) {
118
-            $attendee->set_fname($data['first_name']);
119
-        }
120
-        // copy last_name
121
-        if (! empty($data['last_name'])) {
122
-            $attendee->set_lname($data['last_name']);
123
-        }
124
-        // copy email
125
-        if (! empty($data['email'])) {
126
-            $attendee->set_email($data['email']);
127
-        }
128
-        // copy address
129
-        if (! empty($data['address'])) {
130
-            $attendee->set_address($data['address']);
131
-        }
132
-        // copy address2
133
-        if (! empty($data['address2'])) {
134
-            $attendee->set_address2($data['address2']);
135
-        }
136
-        // copy city
137
-        if (! empty($data['city'])) {
138
-            $attendee->set_city($data['city']);
139
-        }
140
-        // copy state
141
-        if (! empty($data['state'])) {
142
-            $attendee->set_state($data['state']);
143
-        }
144
-        // copy country
145
-        if (! empty($data['country'])) {
146
-            $attendee->set_country($data['country']);
147
-        }
148
-        // copy zip
149
-        if (! empty($data['zip'])) {
150
-            $attendee->set_zip($data['zip']);
151
-        }
152
-        // copy phone
153
-        if (! empty($data['phone'])) {
154
-            $attendee->set_phone($data['phone']);
155
-        }
156
-        return $attendee;
157
-    }
106
+	/**
107
+	 * copy_billing_form_data_to_attendee
108
+	 * copies info from the billing form to the attendee's details
109
+	 * @param \EE_Attendee $attendee - the attendee object to copy details to
110
+	 * @return \EE_Attendee
111
+	 */
112
+	public function copy_billing_form_data_to_attendee(EE_Attendee $attendee)
113
+	{
114
+		// grab billing form data
115
+		$data = $this->valid_data();
116
+		// copy first_name
117
+		if (! empty($data['first_name'])) {
118
+			$attendee->set_fname($data['first_name']);
119
+		}
120
+		// copy last_name
121
+		if (! empty($data['last_name'])) {
122
+			$attendee->set_lname($data['last_name']);
123
+		}
124
+		// copy email
125
+		if (! empty($data['email'])) {
126
+			$attendee->set_email($data['email']);
127
+		}
128
+		// copy address
129
+		if (! empty($data['address'])) {
130
+			$attendee->set_address($data['address']);
131
+		}
132
+		// copy address2
133
+		if (! empty($data['address2'])) {
134
+			$attendee->set_address2($data['address2']);
135
+		}
136
+		// copy city
137
+		if (! empty($data['city'])) {
138
+			$attendee->set_city($data['city']);
139
+		}
140
+		// copy state
141
+		if (! empty($data['state'])) {
142
+			$attendee->set_state($data['state']);
143
+		}
144
+		// copy country
145
+		if (! empty($data['country'])) {
146
+			$attendee->set_country($data['country']);
147
+		}
148
+		// copy zip
149
+		if (! empty($data['zip'])) {
150
+			$attendee->set_zip($data['zip']);
151
+		}
152
+		// copy phone
153
+		if (! empty($data['phone'])) {
154
+			$attendee->set_phone($data['phone']);
155
+		}
156
+		return $attendee;
157
+	}
158 158
 
159 159
 
160
-    /**
161
-     * create_attendee_from_billing_form_data
162
-     * uses info from the billing form to create a new attendee
163
-     * @return \EE_Attendee
164
-     */
165
-    public function create_attendee_from_billing_form_data()
166
-    {
167
-        // grab billing form data
168
-        $data = $this->valid_data();
169
-        return EE_Attendee::new_instance(array(
170
-            'ATT_fname'         => ! empty($data['first_name']) ? $data['first_name'] : '',
171
-            'ATT_lname'         => ! empty($data['last_name']) ? $data['last_name'] : '',
172
-            'ATT_email'         => ! empty($data['email']) ? $data['email'] : '',
173
-            'ATT_address'       => ! empty($data['address']) ? $data['address'] : '',
174
-            'ATT_address2'  => ! empty($data['address2']) ? $data['address2'] : '',
175
-            'ATT_city'          => ! empty($data['city']) ? $data['city'] : '',
176
-            'STA_ID'                => ! empty($data['state']) ? $data['state'] : '',
177
-            'CNT_ISO'           => ! empty($data['country']) ? $data['country'] : '',
178
-            'ATT_zip'               => ! empty($data['zip']) ? $data['zip'] : '',
179
-            'ATT_phone'         => ! empty($data['phone']) ? $data['phone'] : '',
180
-        ));
181
-    }
160
+	/**
161
+	 * create_attendee_from_billing_form_data
162
+	 * uses info from the billing form to create a new attendee
163
+	 * @return \EE_Attendee
164
+	 */
165
+	public function create_attendee_from_billing_form_data()
166
+	{
167
+		// grab billing form data
168
+		$data = $this->valid_data();
169
+		return EE_Attendee::new_instance(array(
170
+			'ATT_fname'         => ! empty($data['first_name']) ? $data['first_name'] : '',
171
+			'ATT_lname'         => ! empty($data['last_name']) ? $data['last_name'] : '',
172
+			'ATT_email'         => ! empty($data['email']) ? $data['email'] : '',
173
+			'ATT_address'       => ! empty($data['address']) ? $data['address'] : '',
174
+			'ATT_address2'  => ! empty($data['address2']) ? $data['address2'] : '',
175
+			'ATT_city'          => ! empty($data['city']) ? $data['city'] : '',
176
+			'STA_ID'                => ! empty($data['state']) ? $data['state'] : '',
177
+			'CNT_ISO'           => ! empty($data['country']) ? $data['country'] : '',
178
+			'ATT_zip'               => ! empty($data['zip']) ? $data['zip'] : '',
179
+			'ATT_phone'         => ! empty($data['phone']) ? $data['phone'] : '',
180
+		));
181
+	}
182 182
 }
183 183
 
184 184
 // End of file EE_Billing_Attendee_Info_Form.form.php
Please login to merge, or discard this patch.
libraries/form_sections/payment_methods/EE_Payment_Method_Form.form.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -104,14 +104,14 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function _construct_finalize($parent_form_section, $name)
106 106
     {
107
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
107
+        if ( ! $this->_payment_method_type instanceof EE_PMT_Base) {
108 108
             throw new EE_Error(sprintf(esc_html__(
109 109
                 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
110 110
                 'event_espresso'
111 111
             )));
112 112
         }
113 113
         // set the name of this form based on the payment method type
114
-        if (! $this->_name && ! $name) {
114
+        if ( ! $this->_name && ! $name) {
115 115
             $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
116 116
                     . "_Settings_Form";
117 117
         }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function set_payment_method_type($payment_method_type)
128 128
     {
129
-        if (! $payment_method_type instanceof EE_PMT_Base) {
129
+        if ( ! $payment_method_type instanceof EE_PMT_Base) {
130 130
             throw new EE_Error(sprintf(esc_html__(
131 131
                 "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
132 132
                 "event_espresso"
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
         parent::populate_model_obj($model_obj);
167 167
         $extra_meta = $model_obj->all_extra_meta_array();
168 168
         foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
169
-            if (isset($extra_meta[ $input_name ])) {
170
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
169
+            if (isset($extra_meta[$input_name])) {
170
+                $extra_meta_input->set_default($extra_meta[$input_name]);
171 171
             }
172 172
         }
173 173
     }
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
      */
182 182
     protected function _set_default_name_if_empty()
183 183
     {
184
-        if (! $this->_name) {
185
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
184
+        if ( ! $this->_name) {
185
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
186 186
             $this->_name = $default_name;
187 187
         }
188 188
     }
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -6,195 +6,195 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Payment_Method_Form extends EE_Model_Form_Section
8 8
 {
9
-    /**
10
-     * All the subsection inputs that correspond ot extra meta rows
11
-     * for this payment method
12
-     *
13
-     * @var EE_Form_Input_Base[]
14
-     */
15
-    protected $_extra_meta_inputs = array();
16
-
17
-    /**
18
-     * Because payment method form might DELAY part of construction, we want to remember
19
-     * what options were passed in
20
-     *
21
-     * @var array
22
-     */
23
-    protected $_options_array = array();
24
-
25
-    /**
26
-     * The payment method type for this form
27
-     *
28
-     * @var EE_PMT_Base
29
-     */
30
-    protected $_payment_method_type;
31
-
32
-
33
-
34
-    /**
35
-     * @param array      $options_array       {
36
-     * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
37
-     *                                        will be _subsections and will be saved as extra meta on the payment
38
-     *                                        method object;
39
-     * @type EE_PMT_Base $payment_method_type the payment method type this form is for
40
-     * @see EE_Model_Form_Section::__construct() for more
41
-     *                                        }
42
-     */
43
-    public function __construct($options_array = array())
44
-    {
45
-        $this->_model = EEM_Payment_Method::instance();
46
-        $this->_options_array = $options_array;
47
-        if (isset($options_array['payment_method_type'])) {
48
-            $this->_payment_method_type = $options_array['payment_method_type'];
49
-        }
50
-        $options_array = $this->_options_array;
51
-        if (isset($options_array['extra_meta_inputs'])) {
52
-            $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
53
-        }
54
-        if ($this->_extra_meta_inputs) {
55
-            $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
56
-        }
57
-        $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
58
-            array('html_label_text' => esc_html__('Button URL', 'event_espresso'))
59
-        );
60
-        $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
61
-            EEM_Payment_Method::instance()->scopes(),
62
-            array(
63
-                'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
64
-                                     . EEH_Template::get_help_tab_link('payment_methods_overview'),
65
-            )
66
-        );
67
-        // setup the currency options
68
-        $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
69
-            EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
70
-            array(
71
-                'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
72
-                'required'        => true,
73
-            )
74
-        );
75
-        $this->_subsections['PMD_order'] = new EE_Text_Input(array(
76
-            'html_label_text'        => esc_html__('Order', 'event_espresso'),
77
-            'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
78
-            'normalization_strategy' => new EE_Int_Normalization(),
79
-            'validation_strategies'  => array(
80
-                new EE_Int_Validation_Strategy(),
81
-            ),
82
-            'default'                => 0,
83
-        ));
84
-        $this->_layout_strategy = new EE_Admin_Two_Column_Layout();
85
-        parent::__construct($options_array);
86
-        $debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
87
-        if ($debug_mode instanceof EE_Form_Input_Base) {
88
-            $debug_mode->set_html_help_text(esc_html__(
89
-                'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
90
-                'event_espresso'
91
-            ));
92
-        }
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Finishes construction given the parent form section and this form section's name
99
-     *
100
-     * @param EE_Form_Section_Proper $parent_form_section
101
-     * @param string                 $name
102
-     * @throws EE_Error
103
-     */
104
-    public function _construct_finalize($parent_form_section, $name)
105
-    {
106
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
107
-            throw new EE_Error(sprintf(esc_html__(
108
-                'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
109
-                'event_espresso'
110
-            )));
111
-        }
112
-        // set the name of this form based on the payment method type
113
-        if (! $this->_name && ! $name) {
114
-            $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
115
-                    . "_Settings_Form";
116
-        }
117
-        parent::_construct_finalize($parent_form_section, $name);
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @param $payment_method_type
124
-     * @throws EE_Error
125
-     */
126
-    public function set_payment_method_type($payment_method_type)
127
-    {
128
-        if (! $payment_method_type instanceof EE_PMT_Base) {
129
-            throw new EE_Error(sprintf(esc_html__(
130
-                "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
131
-                "event_espresso"
132
-            )));
133
-        }
134
-        $this->_payment_method_type = $payment_method_type;
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * extends the model form section's save method to also save the extra meta field values
141
-     *
142
-     * @return int ID of the payment method inserted, or true on update
143
-     */
144
-    public function save()
145
-    {
146
-        $parent_save_val = parent::save();
147
-        if ($this->_model_object && $this->_model_object->ID()) {
148
-            foreach ($this->_extra_meta_inputs as $input_name => $input) {
149
-                $this->_model_object->update_extra_meta($input_name, $input->normalized_value());
150
-            }
151
-        }
152
-        return $parent_save_val;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Overrides parent's populate_model_obj to also populate the extra meta fields
159
-     *
160
-     * @param EE_Base_Class $model_obj
161
-     */
162
-    public function populate_model_obj($model_obj)
163
-    {
164
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
165
-        parent::populate_model_obj($model_obj);
166
-        $extra_meta = $model_obj->all_extra_meta_array();
167
-        foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
168
-            if (isset($extra_meta[ $input_name ])) {
169
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
170
-            }
171
-        }
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * gets the default name of this form section if none is specified
178
-     *
179
-     * @return string
180
-     */
181
-    protected function _set_default_name_if_empty()
182
-    {
183
-        if (! $this->_name) {
184
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
185
-            $this->_name = $default_name;
186
-        }
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Gets all the extra meta inputs in this form
193
-     *
194
-     * @return EE_Form_Input_Base[]
195
-     */
196
-    public function extra_meta_inputs()
197
-    {
198
-        return $this->_extra_meta_inputs;
199
-    }
9
+	/**
10
+	 * All the subsection inputs that correspond ot extra meta rows
11
+	 * for this payment method
12
+	 *
13
+	 * @var EE_Form_Input_Base[]
14
+	 */
15
+	protected $_extra_meta_inputs = array();
16
+
17
+	/**
18
+	 * Because payment method form might DELAY part of construction, we want to remember
19
+	 * what options were passed in
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected $_options_array = array();
24
+
25
+	/**
26
+	 * The payment method type for this form
27
+	 *
28
+	 * @var EE_PMT_Base
29
+	 */
30
+	protected $_payment_method_type;
31
+
32
+
33
+
34
+	/**
35
+	 * @param array      $options_array       {
36
+	 * @type string      $extra_meta_inputs   should be EE_Form_Section_Validatable[] which
37
+	 *                                        will be _subsections and will be saved as extra meta on the payment
38
+	 *                                        method object;
39
+	 * @type EE_PMT_Base $payment_method_type the payment method type this form is for
40
+	 * @see EE_Model_Form_Section::__construct() for more
41
+	 *                                        }
42
+	 */
43
+	public function __construct($options_array = array())
44
+	{
45
+		$this->_model = EEM_Payment_Method::instance();
46
+		$this->_options_array = $options_array;
47
+		if (isset($options_array['payment_method_type'])) {
48
+			$this->_payment_method_type = $options_array['payment_method_type'];
49
+		}
50
+		$options_array = $this->_options_array;
51
+		if (isset($options_array['extra_meta_inputs'])) {
52
+			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
53
+		}
54
+		if ($this->_extra_meta_inputs) {
55
+			$this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
56
+		}
57
+		$this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
58
+			array('html_label_text' => esc_html__('Button URL', 'event_espresso'))
59
+		);
60
+		$this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
61
+			EEM_Payment_Method::instance()->scopes(),
62
+			array(
63
+				'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
64
+									 . EEH_Template::get_help_tab_link('payment_methods_overview'),
65
+			)
66
+		);
67
+		// setup the currency options
68
+		$this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
69
+			EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
70
+			array(
71
+				'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
72
+				'required'        => true,
73
+			)
74
+		);
75
+		$this->_subsections['PMD_order'] = new EE_Text_Input(array(
76
+			'html_label_text'        => esc_html__('Order', 'event_espresso'),
77
+			'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
78
+			'normalization_strategy' => new EE_Int_Normalization(),
79
+			'validation_strategies'  => array(
80
+				new EE_Int_Validation_Strategy(),
81
+			),
82
+			'default'                => 0,
83
+		));
84
+		$this->_layout_strategy = new EE_Admin_Two_Column_Layout();
85
+		parent::__construct($options_array);
86
+		$debug_mode = isset($this->_subsections['PMD_debug_mode']) ? $this->_subsections['PMD_debug_mode'] : null;
87
+		if ($debug_mode instanceof EE_Form_Input_Base) {
88
+			$debug_mode->set_html_help_text(esc_html__(
89
+				'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in debug mode and using this sandbox server, real payments will not be processed.',
90
+				'event_espresso'
91
+			));
92
+		}
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Finishes construction given the parent form section and this form section's name
99
+	 *
100
+	 * @param EE_Form_Section_Proper $parent_form_section
101
+	 * @param string                 $name
102
+	 * @throws EE_Error
103
+	 */
104
+	public function _construct_finalize($parent_form_section, $name)
105
+	{
106
+		if (! $this->_payment_method_type instanceof EE_PMT_Base) {
107
+			throw new EE_Error(sprintf(esc_html__(
108
+				'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
109
+				'event_espresso'
110
+			)));
111
+		}
112
+		// set the name of this form based on the payment method type
113
+		if (! $this->_name && ! $name) {
114
+			$name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
115
+					. "_Settings_Form";
116
+		}
117
+		parent::_construct_finalize($parent_form_section, $name);
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @param $payment_method_type
124
+	 * @throws EE_Error
125
+	 */
126
+	public function set_payment_method_type($payment_method_type)
127
+	{
128
+		if (! $payment_method_type instanceof EE_PMT_Base) {
129
+			throw new EE_Error(sprintf(esc_html__(
130
+				"Payment Method forms MUST set a payment method type by using _set_payment_method_type",
131
+				"event_espresso"
132
+			)));
133
+		}
134
+		$this->_payment_method_type = $payment_method_type;
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * extends the model form section's save method to also save the extra meta field values
141
+	 *
142
+	 * @return int ID of the payment method inserted, or true on update
143
+	 */
144
+	public function save()
145
+	{
146
+		$parent_save_val = parent::save();
147
+		if ($this->_model_object && $this->_model_object->ID()) {
148
+			foreach ($this->_extra_meta_inputs as $input_name => $input) {
149
+				$this->_model_object->update_extra_meta($input_name, $input->normalized_value());
150
+			}
151
+		}
152
+		return $parent_save_val;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Overrides parent's populate_model_obj to also populate the extra meta fields
159
+	 *
160
+	 * @param EE_Base_Class $model_obj
161
+	 */
162
+	public function populate_model_obj($model_obj)
163
+	{
164
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
165
+		parent::populate_model_obj($model_obj);
166
+		$extra_meta = $model_obj->all_extra_meta_array();
167
+		foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
168
+			if (isset($extra_meta[ $input_name ])) {
169
+				$extra_meta_input->set_default($extra_meta[ $input_name ]);
170
+			}
171
+		}
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * gets the default name of this form section if none is specified
178
+	 *
179
+	 * @return string
180
+	 */
181
+	protected function _set_default_name_if_empty()
182
+	{
183
+		if (! $this->_name) {
184
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
185
+			$this->_name = $default_name;
186
+		}
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Gets all the extra meta inputs in this form
193
+	 *
194
+	 * @return EE_Form_Input_Base[]
195
+	 */
196
+	public function extra_meta_inputs()
197
+	{
198
+		return $this->_extra_meta_inputs;
199
+	}
200 200
 }
Please login to merge, or discard this patch.
strategies/display/EE_Select_Multiple_Display_Strategy.strategy.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
     public function display()
21 21
     {
22 22
 
23
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
24 24
             throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
25 25
         }
26 26
 
27 27
         $html = EEH_HTML::nl(0, 'select');
28 28
         $html .= '<select multiple';
29
-        $html .= ' id="' . $this->_input->html_id() . '"';
30
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
31
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
32
-        $html .= ' class="' . $class . '"';
29
+        $html .= ' id="'.$this->_input->html_id().'"';
30
+        $html .= ' name="'.$this->_input->html_name().'[]"';
31
+        $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
32
+        $html .= ' class="'.$class.'"';
33 33
         // add html5 required
34 34
         $html .= $this->_input->required() ? ' required' : '';
35
-        $html .= ' style="' . $this->_input->html_style() . '"';
36
-        $html .= ' ' . $this->_input->other_html_attributes();
35
+        $html .= ' style="'.$this->_input->html_style().'"';
36
+        $html .= ' '.$this->_input->other_html_attributes();
37 37
         $html .= '>';
38 38
 
39 39
         EEH_HTML::indent(1, 'select');
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
             $html .= $this->_display_options($this->_input->options());
44 44
         }
45 45
 
46
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
46
+        $html .= EEH_HTML::nl(-1, 'select')."</select>";
47 47
         return $html;
48 48
     }
49 49
 
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -11,54 +11,54 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Select_Multiple_Display_Strategy extends EE_Select_Display_Strategy
13 13
 {
14
-    /**
15
-     *
16
-     * @throws EE_Error
17
-     * @return string of html to display the field
18
-     */
19
-    public function display()
20
-    {
14
+	/**
15
+	 *
16
+	 * @throws EE_Error
17
+	 * @return string of html to display the field
18
+	 */
19
+	public function display()
20
+	{
21 21
 
22
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
-            throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
24
-        }
22
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+			throw new EE_Error(sprintf(esc_html__('Cannot use Select Multiple Display Strategy with an input that doesn\'t have options', "event_espresso")));
24
+		}
25 25
 
26
-        $html = EEH_HTML::nl(0, 'select');
27
-        $html .= '<select multiple';
28
-        $html .= ' id="' . $this->_input->html_id() . '"';
29
-        $html .= ' name="' . $this->_input->html_name() . '[]"';
30
-        $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
-        $html .= ' class="' . $class . '"';
32
-        // add html5 required
33
-        $html .= $this->_input->required() ? ' required' : '';
34
-        $html .= ' style="' . $this->_input->html_style() . '"';
35
-        $html .= ' ' . $this->_input->other_html_attributes();
36
-        $html .= '>';
26
+		$html = EEH_HTML::nl(0, 'select');
27
+		$html .= '<select multiple';
28
+		$html .= ' id="' . $this->_input->html_id() . '"';
29
+		$html .= ' name="' . $this->_input->html_name() . '[]"';
30
+		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
+		$html .= ' class="' . $class . '"';
32
+		// add html5 required
33
+		$html .= $this->_input->required() ? ' required' : '';
34
+		$html .= ' style="' . $this->_input->html_style() . '"';
35
+		$html .= ' ' . $this->_input->other_html_attributes();
36
+		$html .= '>';
37 37
 
38
-        EEH_HTML::indent(1, 'select');
39
-        if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
40
-            throw new EE_Error(sprintf(esc_html__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso")));
41
-        } else {
42
-            $html .= $this->_display_options($this->_input->options());
43
-        }
38
+		EEH_HTML::indent(1, 'select');
39
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
40
+			throw new EE_Error(sprintf(esc_html__("Select multiple display strategy does not allow for nested arrays of options.", "event_espresso")));
41
+		} else {
42
+			$html .= $this->_display_options($this->_input->options());
43
+		}
44 44
 
45
-        $html .= EEH_HTML::nl(-1, 'select') . "</select>";
46
-        return $html;
47
-    }
45
+		$html .= EEH_HTML::nl(-1, 'select') . "</select>";
46
+		return $html;
47
+	}
48 48
 
49 49
 
50 50
 
51
-    /**
52
-     * Checks if that $value is one of the selected ones
53
-     * @param string|int $value unnormalized value option (string)
54
-     * @return boolean
55
-     */
56
-    protected function optionIsSelected($value)
57
-    {
58
-        $selected_options = $this->_input->raw_value();
59
-        if (empty($selected_options)) {
60
-            return false;
61
-        }
62
-        return in_array($value, $selected_options) ? true : false;
63
-    }
51
+	/**
52
+	 * Checks if that $value is one of the selected ones
53
+	 * @param string|int $value unnormalized value option (string)
54
+	 * @return boolean
55
+	 */
56
+	protected function optionIsSelected($value)
57
+	{
58
+		$selected_options = $this->_input->raw_value();
59
+		if (empty($selected_options)) {
60
+			return false;
61
+		}
62
+		return in_array($value, $selected_options) ? true : false;
63
+	}
64 64
 }
Please login to merge, or discard this patch.
strategies/display/EE_Compound_Input_Display_Strategy.strategy.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function get_sub_input_id($option_value, $add_pound_sign = false)
27 27
     {
28
-        return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value);
28
+        return $this->_append_chars($this->_input->html_id($add_pound_sign), '-').sanitize_key($option_value);
29 29
     }
30 30
 
31 31
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function get_input()
59 59
     {
60
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
60
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
61 61
             throw new EE_Error(
62 62
                 sprintf(
63 63
                     esc_html__(
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -15,57 +15,57 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Compound_Input_Display_Strategy extends EE_Display_Strategy_Base
17 17
 {
18
-    /**
19
-     * Gets the html ID for the sub-input for the specified option html value (not display text)
20
-     *
21
-     * @param string $option_value
22
-     * @param bool   $add_pound_sign
23
-     * @return string
24
-     */
25
-    public function get_sub_input_id($option_value, $add_pound_sign = false)
26
-    {
27
-        return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value);
28
-    }
18
+	/**
19
+	 * Gets the html ID for the sub-input for the specified option html value (not display text)
20
+	 *
21
+	 * @param string $option_value
22
+	 * @param bool   $add_pound_sign
23
+	 * @return string
24
+	 */
25
+	public function get_sub_input_id($option_value, $add_pound_sign = false)
26
+	{
27
+		return $this->_append_chars($this->_input->html_id($add_pound_sign), '-') . sanitize_key($option_value);
28
+	}
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Gets the HTML IDs of all the inputs
34
-     *
35
-     * @param boolean $add_pound_sign
36
-     * @return array
37
-     * @throws \EE_Error
38
-     */
39
-    public function get_html_input_ids($add_pound_sign = false)
40
-    {
41
-        $html_input_ids = array();
42
-        foreach ($this->get_input()->options() as $value => $display) {
43
-            $html_input_ids[] = $this->get_sub_input_id($value, $add_pound_sign);
44
-        }
45
-        return $html_input_ids;
46
-    }
32
+	/**
33
+	 * Gets the HTML IDs of all the inputs
34
+	 *
35
+	 * @param boolean $add_pound_sign
36
+	 * @return array
37
+	 * @throws \EE_Error
38
+	 */
39
+	public function get_html_input_ids($add_pound_sign = false)
40
+	{
41
+		$html_input_ids = array();
42
+		foreach ($this->get_input()->options() as $value => $display) {
43
+			$html_input_ids[] = $this->get_sub_input_id($value, $add_pound_sign);
44
+		}
45
+		return $html_input_ids;
46
+	}
47 47
 
48 48
 
49 49
 
50
-    /**
51
-     * Overrides parent to make sure this display strategy is only used with the
52
-     * appropriate input type
53
-     *
54
-     * @return \EE_Form_Input_With_Options_Base
55
-     * @throws \EE_Error
56
-     */
57
-    public function get_input()
58
-    {
59
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
60
-            throw new EE_Error(
61
-                sprintf(
62
-                    esc_html__(
63
-                        'Can not use a Compound Input Display Strategy (eg checkbox or radio) with an input that doesn\'t have options',
64
-                        'event_espresso'
65
-                    )
66
-                )
67
-            );
68
-        }
69
-        return parent::get_input();
70
-    }
50
+	/**
51
+	 * Overrides parent to make sure this display strategy is only used with the
52
+	 * appropriate input type
53
+	 *
54
+	 * @return \EE_Form_Input_With_Options_Base
55
+	 * @throws \EE_Error
56
+	 */
57
+	public function get_input()
58
+	{
59
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
60
+			throw new EE_Error(
61
+				sprintf(
62
+					esc_html__(
63
+						'Can not use a Compound Input Display Strategy (eg checkbox or radio) with an input that doesn\'t have options',
64
+						'event_espresso'
65
+					)
66
+				)
67
+			);
68
+		}
69
+		return parent::get_input();
70
+	}
71 71
 }
Please login to merge, or discard this patch.