Completed
Branch dependabot/composer/tijsverkoy... (491ea6)
by
unknown
32:00 queued 25:42
created
EE_Admin_Table_Registration_Line_Item_Display_Strategy.strategy.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -72,22 +72,22 @@  discard block
 block discarded – undo
72 72
 
73 73
         $name_html = $line_item_related_object instanceof EEI_Line_Item_Object
74 74
             ? $line_item_related_object->name() : $line_item->name();
75
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>'
75
+        $name_html = $name_link ? '<a href="'.$name_link.'">'.$name_html.'</a>'
76 76
             : $name_html;
77 77
         $name_html .= $line_item->is_taxable() ? ' *' : '';
78 78
         // maybe preface with icon?
79 79
         $name_html = $line_item_related_object instanceof EEI_Has_Icon
80
-            ? $line_item_related_object->get_icon() . $name_html
80
+            ? $line_item_related_object->get_icon().$name_html
81 81
             : $name_html;
82
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
83
-        $name_html .=  sprintf(
82
+        $name_html = '<span class="ee-line-item-name linked">'.$name_html.'</span><br>';
83
+        $name_html .= sprintf(
84 84
             _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
85 85
             '<span class="ee-line-item-related-parent-object">',
86 86
             $line_item->parent() instanceof EE_Line_Item
87 87
                 ? $line_item->parent()->OBJ_type_i18n()
88 88
                 : esc_html__('Item:', 'event_espresso'),
89 89
             $parent_related_object_link
90
-                ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>'
90
+                ? '<a href="'.$parent_related_object_link.'">'.$parent_related_object_name.'</a>'
91 91
                 : $parent_related_object_name,
92 92
             '</span>'
93 93
         );
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
         $type_html .= $this->_get_cancellations($line_item);
106 106
         $type_html .= $line_item->OBJ_type() ? '<br />' : '';
107 107
         $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
108
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
108
+        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">'.sprintf(esc_html__('Code: %s', 'event_espresso'), $code).'</span>' : '';
109 109
         $html .= EEH_HTML::td($type_html, '', 'jst-left');
110 110
 
111 111
         // Date column
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             $datetimes = $line_item_related_object->datetimes();
115 115
             foreach ($datetimes as $datetime) {
116 116
                 if ($datetime instanceof EE_Datetime) {
117
-                    $datetime_content .= $datetime->get_dtt_display_name() . '<br>';
117
+                    $datetime_content .= $datetime->get_dtt_display_name().'<br>';
118 118
                 }
119 119
             }
120 120
         }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 
123 123
         // Amount Column
124 124
         if ($line_item->is_percent()) {
125
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
125
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'jst-rght');
126 126
         } else {
127 127
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
128 128
         }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         // start of row
148 148
         $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
149 149
         // name th
150
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"');
150
+        $html .= EEH_HTML::th($line_item->name().'('.$line_item->get_pretty('LIN_percent').'%)', '', 'jst-rght', '', ' colspan="3"');
151 151
         // total th
152 152
         $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
153 153
         // end of row
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
         $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
181 181
         // Total th label
182 182
         if ($total_match) {
183
-            $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
183
+            $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')');
184 184
         } else {
185
-            $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
185
+            $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')');
186 186
             $total_label .= '<br>';
187 187
             $total_label .= '<p class="ee-footnote-text">'
188 188
                             . sprintf(
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -14,190 +14,190 @@
 block discarded – undo
14 14
 class EE_Admin_Table_Registration_Line_Item_Display_Strategy extends EE_Admin_Table_Line_Item_Display_Strategy
15 15
 {
16 16
 
17
-    /**
18
-     * Table header for display.
19
-     * @since   4.8
20
-     * @param array $options
21
-     * @return string
22
-     */
23
-    protected function _table_header($options)
24
-    {
25
-        $html = EEH_HTML::table('', '', $options['table_css_class']);
26
-        $html .= EEH_HTML::thead();
27
-        $html .= EEH_HTML::tr();
28
-        $html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left');
29
-        $html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left');
30
-        $html .= EEH_HTML::th(esc_html__('Date(s)', 'event_espresso'), '', 'jst-left');
31
-        $html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr');
32
-        $html .= EEH_HTML::tbody();
33
-        return $html;
34
-    }
35
-
36
-
37
-
38
-
39
-
40
-    /**
41
-     *    _item_row
42
-     *
43
-     * @param EE_Line_Item $line_item
44
-     * @param array        $options
45
-     * @return mixed
46
-     */
47
-    protected function _item_row(EE_Line_Item $line_item, $options = array())
48
-    {
49
-        $line_item_related_object = $line_item->get_object();
50
-        $parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item
51
-            ? $line_item->parent()->get_object()
52
-            : null;
53
-        // start of row
54
-        $html = EEH_HTML::tr('', '', 'item');
55
-
56
-
57
-        // Name Column
58
-        $name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
59
-
60
-        // related object scope.
61
-        $parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object
62
-            ? $parent_line_item_related_object->name()
63
-            : '';
64
-        $parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item
65
-            ? $line_item->parent()->name()
66
-            : $parent_related_object_name;
67
-        $parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links
68
-            ? $parent_line_item_related_object->get_admin_details_link()
69
-            : '';
70
-
71
-
72
-        $name_html = $line_item_related_object instanceof EEI_Line_Item_Object
73
-            ? $line_item_related_object->name() : $line_item->name();
74
-        $name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>'
75
-            : $name_html;
76
-        $name_html .= $line_item->is_taxable() ? ' *' : '';
77
-        // maybe preface with icon?
78
-        $name_html = $line_item_related_object instanceof EEI_Has_Icon
79
-            ? $line_item_related_object->get_icon() . $name_html
80
-            : $name_html;
81
-        $name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
82
-        $name_html .=  sprintf(
83
-            _x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
84
-            '<span class="ee-line-item-related-parent-object">',
85
-            $line_item->parent() instanceof EE_Line_Item
86
-                ? $line_item->parent()->OBJ_type_i18n()
87
-                : esc_html__('Item:', 'event_espresso'),
88
-            $parent_related_object_link
89
-                ? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>'
90
-                : $parent_related_object_name,
91
-            '</span>'
92
-        );
93
-
94
-        $name_html = apply_filters(
95
-            'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html',
96
-            $name_html,
97
-            $line_item,
98
-            $options
99
-        );
100
-
101
-        $html .= EEH_HTML::td($name_html, '', 'jst-left');
102
-        // Type Column
103
-        $type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
104
-        $type_html .= $this->_get_cancellations($line_item);
105
-        $type_html .= $line_item->OBJ_type() ? '<br />' : '';
106
-        $code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
107
-        $type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
108
-        $html .= EEH_HTML::td($type_html, '', 'jst-left');
109
-
110
-        // Date column
111
-        $datetime_content = '';
112
-        if ($line_item_related_object instanceof EE_Ticket) {
113
-            $datetimes = $line_item_related_object->datetimes();
114
-            foreach ($datetimes as $datetime) {
115
-                if ($datetime instanceof EE_Datetime) {
116
-                    $datetime_content .= $datetime->get_dtt_display_name() . '<br>';
117
-                }
118
-            }
119
-        }
120
-        $html .= EEH_HTML::td($datetime_content, '', 'jst-left');
121
-
122
-        // Amount Column
123
-        if ($line_item->is_percent()) {
124
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
125
-        } else {
126
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
127
-        }
128
-
129
-
130
-        // finish things off and return
131
-        $html .= EEH_HTML::trx();
132
-        return $html;
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     *  _tax_row
139
-     *
140
-     * @param EE_Line_Item $line_item
141
-     * @param array        $options
142
-     * @return mixed
143
-     */
144
-    protected function _tax_row(EE_Line_Item $line_item, $options = array())
145
-    {
146
-        // start of row
147
-        $html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
148
-        // name th
149
-        $html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"');
150
-        // total th
151
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
152
-        // end of row
153
-        $html .= EEH_HTML::trx();
154
-        return $html;
155
-    }
156
-
157
-
158
-
159
-
160
-
161
-    /**
162
-     *  _total_row
163
-     *
164
-     * @param EE_Line_Item $line_item
165
-     * @param array        $options
166
-     * @return mixed
167
-     */
168
-    protected function _total_row(EE_Line_Item $line_item, $options = array())
169
-    {
170
-
171
-        $registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null;
172
-        $registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0;
173
-        // if no valid registration object then we're not going to show the approximate text.
174
-        $total_match = $registration instanceof EE_Registration
175
-            ? $registration->final_price() === $line_item->total()
176
-            : true;
177
-
178
-        // start of row
179
-        $html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
180
-        // Total th label
181
-        if ($total_match) {
182
-            $total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
183
-        } else {
184
-            $total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
185
-            $total_label .= '<br>';
186
-            $total_label .= '<p class="ee-footnote-text">'
187
-                            . sprintf(
188
-                                esc_html__('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others.  This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'),
189
-                                '<strong>',
190
-                                $registration_total,
191
-                                '</strong>'
192
-                            )
193
-                            . '</p>';
194
-        }
195
-        $html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"');
196
-        // total th
197
-
198
-        $html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
199
-        // end of row
200
-        $html .= EEH_HTML::trx();
201
-        return $html;
202
-    }
17
+	/**
18
+	 * Table header for display.
19
+	 * @since   4.8
20
+	 * @param array $options
21
+	 * @return string
22
+	 */
23
+	protected function _table_header($options)
24
+	{
25
+		$html = EEH_HTML::table('', '', $options['table_css_class']);
26
+		$html .= EEH_HTML::thead();
27
+		$html .= EEH_HTML::tr();
28
+		$html .= EEH_HTML::th(esc_html__('Name', 'event_espresso'), '', 'jst-left');
29
+		$html .= EEH_HTML::th(esc_html__('Type', 'event_espresso'), '', 'jst-left');
30
+		$html .= EEH_HTML::th(esc_html__('Date(s)', 'event_espresso'), '', 'jst-left');
31
+		$html .= EEH_HTML::th(esc_html__('Amount', 'event_espresso'), '', 'jst-cntr');
32
+		$html .= EEH_HTML::tbody();
33
+		return $html;
34
+	}
35
+
36
+
37
+
38
+
39
+
40
+	/**
41
+	 *    _item_row
42
+	 *
43
+	 * @param EE_Line_Item $line_item
44
+	 * @param array        $options
45
+	 * @return mixed
46
+	 */
47
+	protected function _item_row(EE_Line_Item $line_item, $options = array())
48
+	{
49
+		$line_item_related_object = $line_item->get_object();
50
+		$parent_line_item_related_object = $line_item->parent() instanceof EE_Line_Item
51
+			? $line_item->parent()->get_object()
52
+			: null;
53
+		// start of row
54
+		$html = EEH_HTML::tr('', '', 'item');
55
+
56
+
57
+		// Name Column
58
+		$name_link = $line_item_related_object instanceof EEI_Admin_Links ? $line_item_related_object->get_admin_details_link() : '';
59
+
60
+		// related object scope.
61
+		$parent_related_object_name = $parent_line_item_related_object instanceof EEI_Line_Item_Object
62
+			? $parent_line_item_related_object->name()
63
+			: '';
64
+		$parent_related_object_name = empty($parent_related_object_name) && $line_item->parent() instanceof EE_Line_Item
65
+			? $line_item->parent()->name()
66
+			: $parent_related_object_name;
67
+		$parent_related_object_link = $parent_line_item_related_object instanceof EEI_Admin_Links
68
+			? $parent_line_item_related_object->get_admin_details_link()
69
+			: '';
70
+
71
+
72
+		$name_html = $line_item_related_object instanceof EEI_Line_Item_Object
73
+			? $line_item_related_object->name() : $line_item->name();
74
+		$name_html = $name_link ? '<a href="' . $name_link . '">' . $name_html . '</a>'
75
+			: $name_html;
76
+		$name_html .= $line_item->is_taxable() ? ' *' : '';
77
+		// maybe preface with icon?
78
+		$name_html = $line_item_related_object instanceof EEI_Has_Icon
79
+			? $line_item_related_object->get_icon() . $name_html
80
+			: $name_html;
81
+		$name_html = '<span class="ee-line-item-name linked">' . $name_html . '</span><br>';
82
+		$name_html .=  sprintf(
83
+			_x('%1$sfor the %2$s: %3$s%4$s', 'eg. "for the Event: My Cool Event"', 'event_espresso'),
84
+			'<span class="ee-line-item-related-parent-object">',
85
+			$line_item->parent() instanceof EE_Line_Item
86
+				? $line_item->parent()->OBJ_type_i18n()
87
+				: esc_html__('Item:', 'event_espresso'),
88
+			$parent_related_object_link
89
+				? '<a href="' . $parent_related_object_link . '">' . $parent_related_object_name . '</a>'
90
+				: $parent_related_object_name,
91
+			'</span>'
92
+		);
93
+
94
+		$name_html = apply_filters(
95
+			'FHEE__EE_Admin_Table_Registration_Line_Item_Display_Strategy___item_row__name_html',
96
+			$name_html,
97
+			$line_item,
98
+			$options
99
+		);
100
+
101
+		$html .= EEH_HTML::td($name_html, '', 'jst-left');
102
+		// Type Column
103
+		$type_html = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() : '';
104
+		$type_html .= $this->_get_cancellations($line_item);
105
+		$type_html .= $line_item->OBJ_type() ? '<br />' : '';
106
+		$code = $line_item_related_object instanceof EEI_Has_Code ? $line_item_related_object->code() : '';
107
+		$type_html .= ! empty($code) ? '<span class="ee-line-item-id">' . sprintf(esc_html__('Code: %s', 'event_espresso'), $code) . '</span>' : '';
108
+		$html .= EEH_HTML::td($type_html, '', 'jst-left');
109
+
110
+		// Date column
111
+		$datetime_content = '';
112
+		if ($line_item_related_object instanceof EE_Ticket) {
113
+			$datetimes = $line_item_related_object->datetimes();
114
+			foreach ($datetimes as $datetime) {
115
+				if ($datetime instanceof EE_Datetime) {
116
+					$datetime_content .= $datetime->get_dtt_display_name() . '<br>';
117
+				}
118
+			}
119
+		}
120
+		$html .= EEH_HTML::td($datetime_content, '', 'jst-left');
121
+
122
+		// Amount Column
123
+		if ($line_item->is_percent()) {
124
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'jst-rght');
125
+		} else {
126
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'jst-rght');
127
+		}
128
+
129
+
130
+		// finish things off and return
131
+		$html .= EEH_HTML::trx();
132
+		return $html;
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 *  _tax_row
139
+	 *
140
+	 * @param EE_Line_Item $line_item
141
+	 * @param array        $options
142
+	 * @return mixed
143
+	 */
144
+	protected function _tax_row(EE_Line_Item $line_item, $options = array())
145
+	{
146
+		// start of row
147
+		$html = EEH_HTML::tr('', 'admin-primary-mbox-taxes-tr');
148
+		// name th
149
+		$html .= EEH_HTML::th($line_item->name() . '(' . $line_item->get_pretty('LIN_percent') . '%)', '', 'jst-rght', '', ' colspan="3"');
150
+		// total th
151
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
152
+		// end of row
153
+		$html .= EEH_HTML::trx();
154
+		return $html;
155
+	}
156
+
157
+
158
+
159
+
160
+
161
+	/**
162
+	 *  _total_row
163
+	 *
164
+	 * @param EE_Line_Item $line_item
165
+	 * @param array        $options
166
+	 * @return mixed
167
+	 */
168
+	protected function _total_row(EE_Line_Item $line_item, $options = array())
169
+	{
170
+
171
+		$registration = isset($options['EE_Registration']) ? $options['EE_Registration'] : null;
172
+		$registration_total = $registration instanceof EE_Registration ? $registration->pretty_final_price() : 0;
173
+		// if no valid registration object then we're not going to show the approximate text.
174
+		$total_match = $registration instanceof EE_Registration
175
+			? $registration->final_price() === $line_item->total()
176
+			: true;
177
+
178
+		// start of row
179
+		$html = EEH_HTML::tr('', '', 'admin-primary-mbox-total-tr');
180
+		// Total th label
181
+		if ($total_match) {
182
+			$total_label = sprintf(esc_html__('This registration\'s total %s:', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
183
+		} else {
184
+			$total_label = sprintf(esc_html__('This registration\'s approximate total %s', 'event_espresso'), '(' . EE_Registry::instance()->CFG->currency->code . ')');
185
+			$total_label .= '<br>';
186
+			$total_label .= '<p class="ee-footnote-text">'
187
+							. sprintf(
188
+								esc_html__('The registrations\' share of the transaction total is approximate because it might not be possible to evenly divide the transaction total among each registration, and so some registrations may need to pay a penny more than others.  This registration\'s final share is actually %1$s%2$s%3$s.', 'event_espresso'),
189
+								'<strong>',
190
+								$registration_total,
191
+								'</strong>'
192
+							)
193
+							. '</p>';
194
+		}
195
+		$html .= EEH_HTML::th($total_label, '', 'jst-rght', '', ' colspan="3"');
196
+		// total th
197
+
198
+		$html .= EEH_HTML::th(EEH_Template::format_currency($line_item->total(), false, false), '', 'jst-rght');
199
+		// end of row
200
+		$html .= EEH_HTML::trx();
201
+		return $html;
202
+	}
203 203
 }
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/strategies/validation/EE_Int_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
      */
16 16
     public function __construct($validation_error_message = null)
17 17
     {
18
-        if (! $validation_error_message) {
18
+        if ( ! $validation_error_message) {
19 19
             $validation_error_message = esc_html__("Only digits are allowed.", "event_espresso");
20 20
         }
21 21
         parent::__construct($validation_error_message);
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -9,41 +9,41 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base
11 11
 {
12
-    /**
13
-     * @param null $validation_error_message
14
-     */
15
-    public function __construct($validation_error_message = null)
16
-    {
17
-        if (! $validation_error_message) {
18
-            $validation_error_message = esc_html__("Only digits are allowed.", "event_espresso");
19
-        }
20
-        parent::__construct($validation_error_message);
21
-    }
12
+	/**
13
+	 * @param null $validation_error_message
14
+	 */
15
+	public function __construct($validation_error_message = null)
16
+	{
17
+		if (! $validation_error_message) {
18
+			$validation_error_message = esc_html__("Only digits are allowed.", "event_espresso");
19
+		}
20
+		parent::__construct($validation_error_message);
21
+	}
22 22
 
23 23
 
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        // this should have already been detected by the normalization strategy
31
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		// this should have already been detected by the normalization strategy
31
+	}
32 32
 
33 33
 
34 34
 
35
-    /**
36
-     * @return array
37
-     */
38
-    public function get_jquery_validation_rule_array()
39
-    {
40
-        return array(
41
-            'number' => true,
42
-            'step' => 1,
43
-            'messages' => array(
44
-                'number' => $this->get_validation_error_message(),
45
-                'step' => $this->get_validation_error_message()
46
-            )
47
-        );
48
-    }
35
+	/**
36
+	 * @return array
37
+	 */
38
+	public function get_jquery_validation_rule_array()
39
+	{
40
+		return array(
41
+			'number' => true,
42
+			'step' => 1,
43
+			'messages' => array(
44
+				'number' => $this->get_validation_error_message(),
45
+				'step' => $this->get_validation_error_message()
46
+			)
47
+		);
48
+	}
49 49
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Full_HTML_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     public function __construct($validation_error_message = null)
21 21
     {
22
-        if (! $validation_error_message) {
22
+        if ( ! $validation_error_message) {
23 23
             $validation_error_message = sprintf(
24 24
                 esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"),
25 25
                 '<br />',
Please login to merge, or discard this patch.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,62 +13,62 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base
15 15
 {
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $validation_error_message = sprintf(
23
-                esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"),
24
-                '<br />',
25
-                $this->get_list_of_allowed_tags()
26
-            );
27
-        }
28
-        parent::__construct($validation_error_message);
29
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$validation_error_message = sprintf(
23
+				esc_html__('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"),
24
+				'<br />',
25
+				$this->get_list_of_allowed_tags()
26
+			);
27
+		}
28
+		parent::__construct($validation_error_message);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * get_list_of_allowed_tags
34
-     *
35
-     * generates and returns a string that lists the top-level HTML tags that are allowable for this input
36
-     *
37
-     * @return string
38
-     */
39
-    public function get_list_of_allowed_tags(): string
40
-    {
41
-        $tags_we_allow = $this->getAllowedTags();
42
-        ksort($tags_we_allow);
43
-        return implode(', ', array_keys($tags_we_allow));
44
-    }
32
+	/**
33
+	 * get_list_of_allowed_tags
34
+	 *
35
+	 * generates and returns a string that lists the top-level HTML tags that are allowable for this input
36
+	 *
37
+	 * @return string
38
+	 */
39
+	public function get_list_of_allowed_tags(): string
40
+	{
41
+		$tags_we_allow = $this->getAllowedTags();
42
+		ksort($tags_we_allow);
43
+		return implode(', ', array_keys($tags_we_allow));
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * Returns an array whose keys are allowed tags and values are an array of allowed attributes
49
-     *
50
-     * @return array
51
-     */
52
-    protected function getAllowedTags(): array
53
-    {
54
-        global $allowedposttags;
55
-        return array_merge_recursive(
56
-            $allowedposttags,
57
-            EEH_HTML::get_simple_tags()
58
-        );
59
-    }
47
+	/**
48
+	 * Returns an array whose keys are allowed tags and values are an array of allowed attributes
49
+	 *
50
+	 * @return array
51
+	 */
52
+	protected function getAllowedTags(): array
53
+	{
54
+		global $allowedposttags;
55
+		return array_merge_recursive(
56
+			$allowedposttags,
57
+			EEH_HTML::get_simple_tags()
58
+		);
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * @param mixed $normalized_value
64
-     * @throws EE_Validation_Error
65
-     */
66
-    public function validate($normalized_value)
67
-    {
68
-        parent::validate($normalized_value);
69
-        $normalized_value_sans_tags = wp_kses((string) $normalized_value, $this->getAllowedTags());
70
-        if (strlen((string) $normalized_value) > strlen($normalized_value_sans_tags)) {
71
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags');
72
-        }
73
-    }
62
+	/**
63
+	 * @param mixed $normalized_value
64
+	 * @throws EE_Validation_Error
65
+	 */
66
+	public function validate($normalized_value)
67
+	{
68
+		parent::validate($normalized_value);
69
+		$normalized_value_sans_tags = wp_kses((string) $normalized_value, $this->getAllowedTags());
70
+		if (strlen((string) $normalized_value) > strlen($normalized_value_sans_tags)) {
71
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags');
72
+		}
73
+	}
74 74
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Credit_Card_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     public function __construct($validation_error_message = null)
21 21
     {
22
-        if (! $validation_error_message) {
22
+        if ( ! $validation_error_message) {
23 23
             $validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso");
24 24
         }
25 25
         parent::__construct(
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Credit_Card_Validation_Strategy extends EE_Text_Validation_Strategy
15 15
 {
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso");
23
-        }
24
-        parent::__construct(
25
-            $validation_error_message,
26
-            // @codingStandardsIgnoreStart
27
-            '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~'
28
-            // @codingStandardsIgnoreEnd
29
-        );
30
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$validation_error_message = esc_html__("Please enter a valid credit card number", "event_espresso");
23
+		}
24
+		parent::__construct(
25
+			$validation_error_message,
26
+			// @codingStandardsIgnoreStart
27
+			'~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~'
28
+			// @codingStandardsIgnoreEnd
29
+		);
30
+	}
31 31
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Required_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     public function __construct($validation_error_message = null)
21 21
     {
22
-        if (! $validation_error_message) {
22
+        if ( ! $validation_error_message) {
23 23
             $validation_error_message = esc_html__("This field is required.", "event_espresso");
24 24
         }
25 25
         parent::__construct($validation_error_message);
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,51 +11,51 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Required_Validation_Strategy extends EE_Validation_Strategy_Base
13 13
 {
14
-    /**
15
-     * @param string $validation_error_message
16
-     */
17
-    public function __construct($validation_error_message = null)
18
-    {
19
-        if (! $validation_error_message) {
20
-            $validation_error_message = esc_html__("This field is required.", "event_espresso");
21
-        }
22
-        parent::__construct($validation_error_message);
23
-    }
14
+	/**
15
+	 * @param string $validation_error_message
16
+	 */
17
+	public function __construct($validation_error_message = null)
18
+	{
19
+		if (! $validation_error_message) {
20
+			$validation_error_message = esc_html__("This field is required.", "event_espresso");
21
+		}
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * just checks the field isn't blank, provided the requirement conditions
29
-     * indicate this input is still required
30
-     *
31
-     * @param $normalized_value
32
-     * @return bool
33
-     * @throws EE_Validation_Error
34
-     */
35
-    public function validate($normalized_value)
36
-    {
37
-        if (
38
-            $normalized_value === ''
39
-            || $normalized_value === null
40
-            || $normalized_value === array()
41
-        ) {
42
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
43
-        }
44
-        return true;
45
-    }
27
+	/**
28
+	 * just checks the field isn't blank, provided the requirement conditions
29
+	 * indicate this input is still required
30
+	 *
31
+	 * @param $normalized_value
32
+	 * @return bool
33
+	 * @throws EE_Validation_Error
34
+	 */
35
+	public function validate($normalized_value)
36
+	{
37
+		if (
38
+			$normalized_value === ''
39
+			|| $normalized_value === null
40
+			|| $normalized_value === array()
41
+		) {
42
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
43
+		}
44
+		return true;
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * @return array
51
-     */
52
-    public function get_jquery_validation_rule_array()
53
-    {
54
-        return array(
55
-            'required' => true,
56
-            'messages' => array(
57
-                'required' => $this->get_validation_error_message()
58
-            )
59
-        );
60
-    }
49
+	/**
50
+	 * @return array
51
+	 */
52
+	public function get_jquery_validation_rule_array()
53
+	{
54
+		return array(
55
+			'required' => true,
56
+			'messages' => array(
57
+				'required' => $this->get_validation_error_message()
58
+			)
59
+		);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
validation/EE_Model_Matching_Query_Validation_Strategy.strategy.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
35 35
     {
36
-        if (! EE_Registry::instance()->is_model_name($model_name)) {
36
+        if ( ! EE_Registry::instance()->is_model_name($model_name)) {
37 37
             throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name));
38 38
         }
39 39
         $this->_model = EE_Registry::instance()->load_model($model_name);
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
             return true;
60 60
         }
61 61
         $combined_query_params = $this->get_query_params();
62
-        $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
63
-        if (! $this->get_model()->exists($combined_query_params)) {
62
+        $combined_query_params[0][$this->treat_input_as_field()] = $normalized_value;
63
+        if ( ! $this->get_model()->exists($combined_query_params)) {
64 64
             throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
65 65
         }
66 66
     }
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -13,86 +13,86 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Model_Matching_Query_Validation_Strategy extends EE_Validation_Strategy_Base
15 15
 {
16
-    /**
17
-     *
18
-     * @var EEM_Base
19
-     */
20
-    protected $_model;
21
-    protected $_query_params;
22
-    protected $_input_field_name;
16
+	/**
17
+	 *
18
+	 * @var EEM_Base
19
+	 */
20
+	protected $_model;
21
+	protected $_query_params;
22
+	protected $_input_field_name;
23 23
 
24 24
 
25 25
 
26
-    /**
27
-     * @param string $validation_error_message
28
-     * @param string $model_name  name of an EEM_Base model
29
-     * @param array  $query_params     @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
30
-     * @param string $input_field_name the input will be treated as this field's value
31
-     * @throws \EE_Error
32
-     */
33
-    public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
34
-    {
35
-        if (! EE_Registry::instance()->is_model_name($model_name)) {
36
-            throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name));
37
-        }
38
-        $this->_model = EE_Registry::instance()->load_model($model_name);
39
-        $this->_query_params = $query_params;
40
-        if (empty($input_field_name)) {
41
-            $input_field_name = $this->_model->primary_key_name();
42
-        }
43
-        $this->_input_field_name = $input_field_name;
44
-        parent::__construct($validation_error_message);
45
-    }
26
+	/**
27
+	 * @param string $validation_error_message
28
+	 * @param string $model_name  name of an EEM_Base model
29
+	 * @param array  $query_params     @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
30
+	 * @param string $input_field_name the input will be treated as this field's value
31
+	 * @throws \EE_Error
32
+	 */
33
+	public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
34
+	{
35
+		if (! EE_Registry::instance()->is_model_name($model_name)) {
36
+			throw new EE_Error(sprintf(esc_html__('You must provide a valid model object ', 'event_espresso'), $model_name));
37
+		}
38
+		$this->_model = EE_Registry::instance()->load_model($model_name);
39
+		$this->_query_params = $query_params;
40
+		if (empty($input_field_name)) {
41
+			$input_field_name = $this->_model->primary_key_name();
42
+		}
43
+		$this->_input_field_name = $input_field_name;
44
+		parent::__construct($validation_error_message);
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * @param $normalized_value
51
-     * @return bool|void
52
-     * @throws \EE_Error
53
-     * @throws \EE_Validation_Error
54
-     */
55
-    public function validate($normalized_value)
56
-    {
57
-        if (empty($normalized_value)) {
58
-            return true;
59
-        }
60
-        $combined_query_params = $this->get_query_params();
61
-        $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
62
-        if (! $this->get_model()->exists($combined_query_params)) {
63
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
64
-        }
65
-    }
49
+	/**
50
+	 * @param $normalized_value
51
+	 * @return bool|void
52
+	 * @throws \EE_Error
53
+	 * @throws \EE_Validation_Error
54
+	 */
55
+	public function validate($normalized_value)
56
+	{
57
+		if (empty($normalized_value)) {
58
+			return true;
59
+		}
60
+		$combined_query_params = $this->get_query_params();
61
+		$combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
62
+		if (! $this->get_model()->exists($combined_query_params)) {
63
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
64
+		}
65
+	}
66 66
 
67
-    /**
68
-     * Gets the model used for querying
69
-     * @return EEM_Base
70
-     */
71
-    public function get_model()
72
-    {
73
-        return $this->_model;
74
-    }
67
+	/**
68
+	 * Gets the model used for querying
69
+	 * @return EEM_Base
70
+	 */
71
+	public function get_model()
72
+	{
73
+		return $this->_model;
74
+	}
75 75
 
76
-    /**
77
-     * Returns query params used for model query
78
-     * @return array
79
-     */
80
-    public function get_query_params()
81
-    {
82
-        return (array) $this->_query_params;
83
-    }
76
+	/**
77
+	 * Returns query params used for model query
78
+	 * @return array
79
+	 */
80
+	public function get_query_params()
81
+	{
82
+		return (array) $this->_query_params;
83
+	}
84 84
 
85
-    /**
86
-     * Gets the name of the field that will be used for lookup.
87
-     * eg it could be "EVT_name", meaning that if there is a model object in
88
-     * the database that has that event name, and matching the other query parameters
89
-     * on this strategy, the input will pass validation server-side
90
-     * @return string
91
-     */
92
-    public function treat_input_as_field()
93
-    {
94
-        return $this->_input_field_name;
95
-    }
85
+	/**
86
+	 * Gets the name of the field that will be used for lookup.
87
+	 * eg it could be "EVT_name", meaning that if there is a model object in
88
+	 * the database that has that event name, and matching the other query parameters
89
+	 * on this strategy, the input will pass validation server-side
90
+	 * @return string
91
+	 */
92
+	public function treat_input_as_field()
93
+	{
94
+		return $this->_input_field_name;
95
+	}
96 96
 }
97 97
 
98 98
 // End of file EE_FUll_HTML_Validation_Strategy.strategy.php
Please login to merge, or discard this patch.
strategies/validation/EE_Plaintext_Validation_Strategy.strategy.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     public function __construct($validation_error_message = null)
21 21
     {
22
-        if (! $validation_error_message) {
22
+        if ( ! $validation_error_message) {
23 23
             $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso");
24 24
         }
25 25
         parent::__construct($validation_error_message);
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,28 +13,28 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Plaintext_Validation_Strategy extends EE_Validation_Strategy_Base
15 15
 {
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso");
23
-        }
24
-        parent::__construct($validation_error_message);
25
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso");
23
+		}
24
+		parent::__construct($validation_error_message);
25
+	}
26 26
 
27
-    /**
28
-     * @param string|null $normalized_value
29
-     * @throws EE_Validation_Error
30
-     */
31
-    public function validate($normalized_value = '')
32
-    {
33
-        $normalized_value = (string) $normalized_value;
34
-        $no_tags = wp_strip_all_tags($normalized_value);
35
-        if (strlen($no_tags) < strlen(trim($normalized_value))) {
36
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags');
37
-        }
38
-        parent::validate($normalized_value);
39
-    }
27
+	/**
28
+	 * @param string|null $normalized_value
29
+	 * @throws EE_Validation_Error
30
+	 */
31
+	public function validate($normalized_value = '')
32
+	{
33
+		$normalized_value = (string) $normalized_value;
34
+		$no_tags = wp_strip_all_tags($normalized_value);
35
+		if (strlen($no_tags) < strlen(trim($normalized_value))) {
36
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags');
37
+		}
38
+		parent::validate($normalized_value);
39
+	}
40 40
 }
Please login to merge, or discard this patch.