@@ -17,64 +17,64 @@ |
||
17 | 17 | class Context implements ContextInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $slug |
|
22 | - */ |
|
23 | - private $slug; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string $description |
|
27 | - */ |
|
28 | - private $description; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Context constructor. |
|
33 | - * |
|
34 | - * @param string $slug |
|
35 | - * @param string $description |
|
36 | - */ |
|
37 | - public function __construct($slug, $description) |
|
38 | - { |
|
39 | - $this->setSlug($slug); |
|
40 | - $this->setDescription($description); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function slug() |
|
48 | - { |
|
49 | - return $this->slug; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $slug |
|
55 | - */ |
|
56 | - private function setSlug($slug) |
|
57 | - { |
|
58 | - $this->slug = sanitize_key($slug); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function description() |
|
66 | - { |
|
67 | - return $this->description; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $description |
|
73 | - */ |
|
74 | - private function setDescription($description) |
|
75 | - { |
|
76 | - $this->description = sanitize_text_field($description); |
|
77 | - } |
|
20 | + /** |
|
21 | + * @var string $slug |
|
22 | + */ |
|
23 | + private $slug; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string $description |
|
27 | + */ |
|
28 | + private $description; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Context constructor. |
|
33 | + * |
|
34 | + * @param string $slug |
|
35 | + * @param string $description |
|
36 | + */ |
|
37 | + public function __construct($slug, $description) |
|
38 | + { |
|
39 | + $this->setSlug($slug); |
|
40 | + $this->setDescription($description); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function slug() |
|
48 | + { |
|
49 | + return $this->slug; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $slug |
|
55 | + */ |
|
56 | + private function setSlug($slug) |
|
57 | + { |
|
58 | + $this->slug = sanitize_key($slug); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function description() |
|
66 | + { |
|
67 | + return $this->description; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $description |
|
73 | + */ |
|
74 | + private function setDescription($description) |
|
75 | + { |
|
76 | + $this->description = sanitize_text_field($description); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | // Location: Context.php |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
365 | 365 | * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
366 | 366 | * @param $QST_system |
367 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
367 | + * @return string of QST_ID for the question that corresponds to that QST_system |
|
368 | 368 | */ |
369 | 369 | public function get_Question_ID_from_system_string($QST_system) |
370 | 370 | { |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | |
427 | 427 | /** |
428 | - * @return array |
|
428 | + * @return EEM_Question |
|
429 | 429 | */ |
430 | 430 | public function question_descriptions() |
431 | 431 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
5 | 5 | require_once(EE_CLASSES . 'EE_Question.class.php'); |
@@ -16,431 +16,431 @@ discard block |
||
16 | 16 | class EEM_Question extends EEM_Soft_Delete_Base |
17 | 17 | { |
18 | 18 | |
19 | - // constant used to indicate that the question type is COUNTRY |
|
20 | - const QST_type_country = 'COUNTRY'; |
|
21 | - |
|
22 | - // constant used to indicate that the question type is DATE |
|
23 | - const QST_type_date = 'DATE'; |
|
24 | - |
|
25 | - // constant used to indicate that the question type is DROPDOWN |
|
26 | - const QST_type_dropdown = 'DROPDOWN'; |
|
27 | - |
|
28 | - // constant used to indicate that the question type is CHECKBOX |
|
29 | - const QST_type_checkbox = 'CHECKBOX'; |
|
30 | - |
|
31 | - // constant used to indicate that the question type is RADIO_BTN |
|
32 | - const QST_type_radio = 'RADIO_BTN'; |
|
33 | - |
|
34 | - // constant used to indicate that the question type is STATE |
|
35 | - const QST_type_state = 'STATE'; |
|
36 | - |
|
37 | - // constant used to indicate that the question type is TEXT |
|
38 | - const QST_type_text = 'TEXT'; |
|
39 | - |
|
40 | - // constant used to indicate that the question type is TEXTAREA |
|
41 | - const QST_type_textarea = 'TEXTAREA'; |
|
42 | - |
|
43 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
44 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
45 | - |
|
46 | - // constant used to indicate that the question type is an email input |
|
47 | - const QST_type_email = 'EMAIL'; |
|
48 | - |
|
49 | - // constant used to indicate that the question type is a US-formatted phone number |
|
50 | - const QST_type_us_phone = 'US_PHONE'; |
|
51 | - |
|
52 | - // constant used to indicate that the question type is an integer (whole number) |
|
53 | - const QST_type_int = 'INTEGER'; |
|
54 | - |
|
55 | - // constant used to indicate that the question type is a decimal (float) |
|
56 | - const QST_type_decimal = 'DECIMAL'; |
|
57 | - |
|
58 | - // constant used to indicate that the question type is a valid URL |
|
59 | - const QST_type_url = 'URL'; |
|
60 | - |
|
61 | - // constant used to indicate that the question type is a YEAR |
|
62 | - const QST_type_year = 'YEAR'; |
|
63 | - |
|
64 | - // constant used to indicate that the question type is a multi-select |
|
65 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
69 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
70 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
71 | - * |
|
72 | - * @access protected |
|
73 | - * @var array $_question_type_categories { |
|
74 | - * @type string $text |
|
75 | - * @type string $single -answer-enum |
|
76 | - * @type string $multi -answer-enum |
|
77 | - * } |
|
78 | - */ |
|
79 | - protected $_question_type_categories = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
83 | - * |
|
84 | - * @access protected |
|
85 | - * @var array $_allowed_question_types |
|
86 | - */ |
|
87 | - protected $_allowed_question_types = array(); |
|
88 | - |
|
89 | - /** |
|
90 | - * brief descriptions for all the question types |
|
91 | - * |
|
92 | - * @access protected |
|
93 | - * @var EEM_Question $_instance |
|
94 | - */ |
|
95 | - protected $_question_descriptions; |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Question types that should have an admin-defined max input length |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - protected $question_types_with_max_lengh; |
|
103 | - |
|
104 | - |
|
105 | - // private instance of the Attendee object |
|
106 | - protected static $_instance = NULL; |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * EEM_Question constructor. |
|
111 | - * |
|
112 | - * @param null $timezone |
|
113 | - */ |
|
114 | - protected function __construct($timezone = NULL) |
|
115 | - { |
|
116 | - $this->singular_item = __('Question', 'event_espresso'); |
|
117 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
118 | - $this->_allowed_question_types = apply_filters( |
|
119 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
120 | - array( |
|
121 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
122 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
123 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
124 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
125 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
126 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
127 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
128 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
129 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
130 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
131 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
132 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
133 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
134 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
135 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
136 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
137 | - ) |
|
138 | - ); |
|
139 | - $this->_question_descriptions = apply_filters( |
|
140 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
141 | - array( |
|
142 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
143 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
144 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
145 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
146 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
147 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
148 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
149 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
150 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
151 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
152 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
153 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
154 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
155 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
156 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
157 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
158 | - ) |
|
159 | - ); |
|
160 | - $this->_question_type_categories = (array)apply_filters( |
|
161 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
162 | - array( |
|
163 | - 'text' => array( |
|
164 | - EEM_Question::QST_type_text, |
|
165 | - EEM_Question::QST_type_textarea, |
|
166 | - EEM_Question::QST_type_date, |
|
167 | - EEM_Question::QST_type_html_textarea, |
|
168 | - EEM_Question::QST_type_email, |
|
169 | - EEM_Question::QST_type_us_phone, |
|
170 | - EEM_Question::QST_type_decimal, |
|
171 | - EEM_Question::QST_type_int, |
|
172 | - EEM_Question::QST_type_url, |
|
173 | - EEM_Question::QST_type_year |
|
174 | - ), |
|
175 | - 'single-answer-enum' => array( |
|
176 | - EEM_Question::QST_type_radio, |
|
177 | - EEM_Question::QST_type_dropdown |
|
178 | - ), |
|
179 | - 'multi-answer-enum' => array( |
|
180 | - EEM_Question::QST_type_checkbox, |
|
181 | - EEM_Question::QST_type_multi_select |
|
182 | - ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - $this->question_types_with_max_lengh = apply_filters( |
|
186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | - array( |
|
188 | - EEM_Question::QST_type_text, |
|
189 | - EEM_Question::QST_type_textarea, |
|
190 | - EEM_Question::QST_type_html_textarea |
|
191 | - ) |
|
192 | - ); |
|
193 | - |
|
194 | - $this->_tables = array( |
|
195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | - ); |
|
197 | - $this->_fields = array( |
|
198 | - 'Question' => array( |
|
199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | - ) |
|
212 | - ); |
|
213 | - $this->_model_relations = array( |
|
214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | - //for QST_order column |
|
219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | - ); |
|
221 | - //this model is generally available for reading |
|
222 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
223 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | - parent::__construct($timezone); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | - * but they can be extended |
|
232 | - * @return string[] |
|
233 | - */ |
|
234 | - public function allowed_question_types() |
|
235 | - { |
|
236 | - return $this->_allowed_question_types; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the question types in the same category |
|
241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
243 | - */ |
|
244 | - public function question_types_in_same_category($question_type) |
|
245 | - { |
|
246 | - $question_types = array($question_type); |
|
247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | - if (in_array($question_type, $question_types_in_category)) { |
|
249 | - $question_types = $question_types_in_category; |
|
250 | - break; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Determines if the given question type is in the given question type category |
|
259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | - * @return boolean |
|
262 | - */ |
|
263 | - public function question_type_is_in_category($question_type, $category) |
|
264 | - { |
|
265 | - if (!isset($this->_question_type_categories[$category])) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - return in_array($question_type, $this->_question_type_categories[$category]); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns all the question types in the given category |
|
274 | - * @param string $category |
|
275 | - * @return array|mixed |
|
276 | - */ |
|
277 | - public function question_types_in_category($category) |
|
278 | - { |
|
279 | - if (isset($this->_question_type_categories[$category])) { |
|
280 | - return $this->_question_type_categories[$category]; |
|
281 | - } |
|
282 | - return array(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Returns all the question types that should have question options |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function question_types_with_options() |
|
291 | - { |
|
292 | - return array_merge( |
|
293 | - $this->question_types_in_category('single-answer-enum'), |
|
294 | - $this->question_types_in_category('multi-answer-enum') |
|
295 | - ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the question type categories 2d array |
|
300 | - * @return array see EEM_Question::_question_type_categories |
|
301 | - */ |
|
302 | - public function question_type_categories() |
|
303 | - { |
|
304 | - return $this->_question_type_categories; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | - * identified by $system_question_group_id |
|
310 | - * @param string $system_question_group_id QSG_system |
|
311 | - * @return array of system question names (QST_system) |
|
312 | - */ |
|
313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | - { |
|
315 | - $question_system_ids = array(); |
|
316 | - switch ($system_question_group_id) { |
|
317 | - case EEM_Question_Group::system_personal: |
|
318 | - $question_system_ids = array( |
|
319 | - EEM_Attendee::system_question_fname, |
|
320 | - EEM_Attendee::system_question_lname, |
|
321 | - EEM_Attendee::system_question_email, |
|
322 | - EEM_Attendee::system_question_phone |
|
323 | - ); |
|
324 | - break; |
|
325 | - case EEM_Question_Group::system_address: |
|
326 | - $question_system_ids = array( |
|
327 | - EEM_Attendee::system_question_address, |
|
328 | - EEM_Attendee::system_question_address2, |
|
329 | - EEM_Attendee::system_question_city, |
|
330 | - EEM_Attendee::system_question_state, |
|
331 | - EEM_Attendee::system_question_country, |
|
332 | - EEM_Attendee::system_question_zip, |
|
333 | - EEM_Attendee::system_question_phone |
|
334 | - ); |
|
335 | - break; |
|
336 | - } |
|
337 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Returns an array of all the QST_system values that are required in the system question group |
|
342 | - * identified by $system_question_group_id |
|
343 | - * @param string $system_question_group_id QSG_system |
|
344 | - * @return array of system question names (QST_system) |
|
345 | - */ |
|
346 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
347 | - { |
|
348 | - $question_system_ids = null; |
|
349 | - switch ($system_question_group_id) { |
|
350 | - case EEM_Question_Group::system_personal: |
|
351 | - $question_system_ids = array( |
|
352 | - EEM_Attendee::system_question_fname, |
|
353 | - EEM_Attendee::system_question_email, |
|
354 | - ); |
|
355 | - break; |
|
356 | - default: |
|
357 | - $question_system_ids = array(); |
|
358 | - } |
|
359 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
365 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
366 | - * @param $QST_system |
|
367 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
368 | - */ |
|
369 | - public function get_Question_ID_from_system_string($QST_system) |
|
370 | - { |
|
371 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * searches the db for the question with the latest question order and returns that value. |
|
377 | - * @access public |
|
378 | - * @return int |
|
379 | - */ |
|
380 | - public function get_latest_question_order() |
|
381 | - { |
|
382 | - $columns_to_select = array( |
|
383 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
384 | - ); |
|
385 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
386 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Returns an array where keys are system question QST_system values, |
|
391 | - * and values are the highest question max the admin can set on the question |
|
392 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
393 | - * of 5, but no larger than 12) |
|
394 | - * @return array |
|
395 | - */ |
|
396 | - public function system_question_maxes() |
|
397 | - { |
|
398 | - return array( |
|
399 | - 'fname' => 45, |
|
400 | - 'lname' => 45, |
|
401 | - 'address' => 255, |
|
402 | - 'address2' => 255, |
|
403 | - 'city' => 45, |
|
404 | - 'zip' => 12, |
|
405 | - 'email' => 255, |
|
406 | - 'phone' => 45, |
|
407 | - ); |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
412 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
413 | - * @param string $system_question_value |
|
414 | - * @return int|float |
|
415 | - */ |
|
416 | - public function absolute_max_for_system_question($system_question_value) |
|
417 | - { |
|
418 | - $maxes = $this->system_question_maxes(); |
|
419 | - if (isset($maxes[$system_question_value])) { |
|
420 | - return $maxes[$system_question_value]; |
|
421 | - } else { |
|
422 | - return EE_INF; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * @return array |
|
429 | - */ |
|
430 | - public function question_descriptions() |
|
431 | - { |
|
432 | - return $this->_question_descriptions; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Returns all the question types that should have an admin-defined max input length |
|
438 | - * @return array |
|
439 | - */ |
|
440 | - public function questionTypesWithMaxLength() |
|
441 | - { |
|
442 | - return (array)$this->question_types_with_max_lengh; |
|
443 | - } |
|
19 | + // constant used to indicate that the question type is COUNTRY |
|
20 | + const QST_type_country = 'COUNTRY'; |
|
21 | + |
|
22 | + // constant used to indicate that the question type is DATE |
|
23 | + const QST_type_date = 'DATE'; |
|
24 | + |
|
25 | + // constant used to indicate that the question type is DROPDOWN |
|
26 | + const QST_type_dropdown = 'DROPDOWN'; |
|
27 | + |
|
28 | + // constant used to indicate that the question type is CHECKBOX |
|
29 | + const QST_type_checkbox = 'CHECKBOX'; |
|
30 | + |
|
31 | + // constant used to indicate that the question type is RADIO_BTN |
|
32 | + const QST_type_radio = 'RADIO_BTN'; |
|
33 | + |
|
34 | + // constant used to indicate that the question type is STATE |
|
35 | + const QST_type_state = 'STATE'; |
|
36 | + |
|
37 | + // constant used to indicate that the question type is TEXT |
|
38 | + const QST_type_text = 'TEXT'; |
|
39 | + |
|
40 | + // constant used to indicate that the question type is TEXTAREA |
|
41 | + const QST_type_textarea = 'TEXTAREA'; |
|
42 | + |
|
43 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
44 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
45 | + |
|
46 | + // constant used to indicate that the question type is an email input |
|
47 | + const QST_type_email = 'EMAIL'; |
|
48 | + |
|
49 | + // constant used to indicate that the question type is a US-formatted phone number |
|
50 | + const QST_type_us_phone = 'US_PHONE'; |
|
51 | + |
|
52 | + // constant used to indicate that the question type is an integer (whole number) |
|
53 | + const QST_type_int = 'INTEGER'; |
|
54 | + |
|
55 | + // constant used to indicate that the question type is a decimal (float) |
|
56 | + const QST_type_decimal = 'DECIMAL'; |
|
57 | + |
|
58 | + // constant used to indicate that the question type is a valid URL |
|
59 | + const QST_type_url = 'URL'; |
|
60 | + |
|
61 | + // constant used to indicate that the question type is a YEAR |
|
62 | + const QST_type_year = 'YEAR'; |
|
63 | + |
|
64 | + // constant used to indicate that the question type is a multi-select |
|
65 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
69 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
70 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
71 | + * |
|
72 | + * @access protected |
|
73 | + * @var array $_question_type_categories { |
|
74 | + * @type string $text |
|
75 | + * @type string $single -answer-enum |
|
76 | + * @type string $multi -answer-enum |
|
77 | + * } |
|
78 | + */ |
|
79 | + protected $_question_type_categories = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
83 | + * |
|
84 | + * @access protected |
|
85 | + * @var array $_allowed_question_types |
|
86 | + */ |
|
87 | + protected $_allowed_question_types = array(); |
|
88 | + |
|
89 | + /** |
|
90 | + * brief descriptions for all the question types |
|
91 | + * |
|
92 | + * @access protected |
|
93 | + * @var EEM_Question $_instance |
|
94 | + */ |
|
95 | + protected $_question_descriptions; |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Question types that should have an admin-defined max input length |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + protected $question_types_with_max_lengh; |
|
103 | + |
|
104 | + |
|
105 | + // private instance of the Attendee object |
|
106 | + protected static $_instance = NULL; |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * EEM_Question constructor. |
|
111 | + * |
|
112 | + * @param null $timezone |
|
113 | + */ |
|
114 | + protected function __construct($timezone = NULL) |
|
115 | + { |
|
116 | + $this->singular_item = __('Question', 'event_espresso'); |
|
117 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
118 | + $this->_allowed_question_types = apply_filters( |
|
119 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
120 | + array( |
|
121 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
130 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
131 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
132 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
133 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
134 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
135 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
136 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
137 | + ) |
|
138 | + ); |
|
139 | + $this->_question_descriptions = apply_filters( |
|
140 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
141 | + array( |
|
142 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
143 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
144 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
145 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
146 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
147 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
148 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
149 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
150 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
151 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
152 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
153 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
154 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
155 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
156 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
157 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
158 | + ) |
|
159 | + ); |
|
160 | + $this->_question_type_categories = (array)apply_filters( |
|
161 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
162 | + array( |
|
163 | + 'text' => array( |
|
164 | + EEM_Question::QST_type_text, |
|
165 | + EEM_Question::QST_type_textarea, |
|
166 | + EEM_Question::QST_type_date, |
|
167 | + EEM_Question::QST_type_html_textarea, |
|
168 | + EEM_Question::QST_type_email, |
|
169 | + EEM_Question::QST_type_us_phone, |
|
170 | + EEM_Question::QST_type_decimal, |
|
171 | + EEM_Question::QST_type_int, |
|
172 | + EEM_Question::QST_type_url, |
|
173 | + EEM_Question::QST_type_year |
|
174 | + ), |
|
175 | + 'single-answer-enum' => array( |
|
176 | + EEM_Question::QST_type_radio, |
|
177 | + EEM_Question::QST_type_dropdown |
|
178 | + ), |
|
179 | + 'multi-answer-enum' => array( |
|
180 | + EEM_Question::QST_type_checkbox, |
|
181 | + EEM_Question::QST_type_multi_select |
|
182 | + ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + $this->question_types_with_max_lengh = apply_filters( |
|
186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | + array( |
|
188 | + EEM_Question::QST_type_text, |
|
189 | + EEM_Question::QST_type_textarea, |
|
190 | + EEM_Question::QST_type_html_textarea |
|
191 | + ) |
|
192 | + ); |
|
193 | + |
|
194 | + $this->_tables = array( |
|
195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | + ); |
|
197 | + $this->_fields = array( |
|
198 | + 'Question' => array( |
|
199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | + ) |
|
212 | + ); |
|
213 | + $this->_model_relations = array( |
|
214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | + //for QST_order column |
|
219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | + ); |
|
221 | + //this model is generally available for reading |
|
222 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
223 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | + parent::__construct($timezone); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | + * but they can be extended |
|
232 | + * @return string[] |
|
233 | + */ |
|
234 | + public function allowed_question_types() |
|
235 | + { |
|
236 | + return $this->_allowed_question_types; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the question types in the same category |
|
241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
243 | + */ |
|
244 | + public function question_types_in_same_category($question_type) |
|
245 | + { |
|
246 | + $question_types = array($question_type); |
|
247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | + if (in_array($question_type, $question_types_in_category)) { |
|
249 | + $question_types = $question_types_in_category; |
|
250 | + break; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Determines if the given question type is in the given question type category |
|
259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | + * @return boolean |
|
262 | + */ |
|
263 | + public function question_type_is_in_category($question_type, $category) |
|
264 | + { |
|
265 | + if (!isset($this->_question_type_categories[$category])) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns all the question types in the given category |
|
274 | + * @param string $category |
|
275 | + * @return array|mixed |
|
276 | + */ |
|
277 | + public function question_types_in_category($category) |
|
278 | + { |
|
279 | + if (isset($this->_question_type_categories[$category])) { |
|
280 | + return $this->_question_type_categories[$category]; |
|
281 | + } |
|
282 | + return array(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Returns all the question types that should have question options |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function question_types_with_options() |
|
291 | + { |
|
292 | + return array_merge( |
|
293 | + $this->question_types_in_category('single-answer-enum'), |
|
294 | + $this->question_types_in_category('multi-answer-enum') |
|
295 | + ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the question type categories 2d array |
|
300 | + * @return array see EEM_Question::_question_type_categories |
|
301 | + */ |
|
302 | + public function question_type_categories() |
|
303 | + { |
|
304 | + return $this->_question_type_categories; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | + * identified by $system_question_group_id |
|
310 | + * @param string $system_question_group_id QSG_system |
|
311 | + * @return array of system question names (QST_system) |
|
312 | + */ |
|
313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | + { |
|
315 | + $question_system_ids = array(); |
|
316 | + switch ($system_question_group_id) { |
|
317 | + case EEM_Question_Group::system_personal: |
|
318 | + $question_system_ids = array( |
|
319 | + EEM_Attendee::system_question_fname, |
|
320 | + EEM_Attendee::system_question_lname, |
|
321 | + EEM_Attendee::system_question_email, |
|
322 | + EEM_Attendee::system_question_phone |
|
323 | + ); |
|
324 | + break; |
|
325 | + case EEM_Question_Group::system_address: |
|
326 | + $question_system_ids = array( |
|
327 | + EEM_Attendee::system_question_address, |
|
328 | + EEM_Attendee::system_question_address2, |
|
329 | + EEM_Attendee::system_question_city, |
|
330 | + EEM_Attendee::system_question_state, |
|
331 | + EEM_Attendee::system_question_country, |
|
332 | + EEM_Attendee::system_question_zip, |
|
333 | + EEM_Attendee::system_question_phone |
|
334 | + ); |
|
335 | + break; |
|
336 | + } |
|
337 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Returns an array of all the QST_system values that are required in the system question group |
|
342 | + * identified by $system_question_group_id |
|
343 | + * @param string $system_question_group_id QSG_system |
|
344 | + * @return array of system question names (QST_system) |
|
345 | + */ |
|
346 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
347 | + { |
|
348 | + $question_system_ids = null; |
|
349 | + switch ($system_question_group_id) { |
|
350 | + case EEM_Question_Group::system_personal: |
|
351 | + $question_system_ids = array( |
|
352 | + EEM_Attendee::system_question_fname, |
|
353 | + EEM_Attendee::system_question_email, |
|
354 | + ); |
|
355 | + break; |
|
356 | + default: |
|
357 | + $question_system_ids = array(); |
|
358 | + } |
|
359 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
365 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
366 | + * @param $QST_system |
|
367 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
368 | + */ |
|
369 | + public function get_Question_ID_from_system_string($QST_system) |
|
370 | + { |
|
371 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * searches the db for the question with the latest question order and returns that value. |
|
377 | + * @access public |
|
378 | + * @return int |
|
379 | + */ |
|
380 | + public function get_latest_question_order() |
|
381 | + { |
|
382 | + $columns_to_select = array( |
|
383 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
384 | + ); |
|
385 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
386 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Returns an array where keys are system question QST_system values, |
|
391 | + * and values are the highest question max the admin can set on the question |
|
392 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
393 | + * of 5, but no larger than 12) |
|
394 | + * @return array |
|
395 | + */ |
|
396 | + public function system_question_maxes() |
|
397 | + { |
|
398 | + return array( |
|
399 | + 'fname' => 45, |
|
400 | + 'lname' => 45, |
|
401 | + 'address' => 255, |
|
402 | + 'address2' => 255, |
|
403 | + 'city' => 45, |
|
404 | + 'zip' => 12, |
|
405 | + 'email' => 255, |
|
406 | + 'phone' => 45, |
|
407 | + ); |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
412 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
413 | + * @param string $system_question_value |
|
414 | + * @return int|float |
|
415 | + */ |
|
416 | + public function absolute_max_for_system_question($system_question_value) |
|
417 | + { |
|
418 | + $maxes = $this->system_question_maxes(); |
|
419 | + if (isset($maxes[$system_question_value])) { |
|
420 | + return $maxes[$system_question_value]; |
|
421 | + } else { |
|
422 | + return EE_INF; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * @return array |
|
429 | + */ |
|
430 | + public function question_descriptions() |
|
431 | + { |
|
432 | + return $this->_question_descriptions; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Returns all the question types that should have an admin-defined max input length |
|
438 | + * @return array |
|
439 | + */ |
|
440 | + public function questionTypesWithMaxLength() |
|
441 | + { |
|
442 | + return (array)$this->question_types_with_max_lengh; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | |
446 | 446 | } |
@@ -1,8 +1,8 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
|
5 | -require_once(EE_CLASSES . 'EE_Question.class.php'); |
|
4 | +require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
5 | +require_once(EE_CLASSES.'EE_Question.class.php'); |
|
6 | 6 | |
7 | 7 | |
8 | 8 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
158 | 158 | ) |
159 | 159 | ); |
160 | - $this->_question_type_categories = (array)apply_filters( |
|
160 | + $this->_question_type_categories = (array) apply_filters( |
|
161 | 161 | 'FHEE__EEM_Question__construct__question_type_categories', |
162 | 162 | array( |
163 | 163 | 'text' => array( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function question_type_is_in_category($question_type, $category) |
264 | 264 | { |
265 | - if (!isset($this->_question_type_categories[$category])) { |
|
265 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | return in_array($question_type, $this->_question_type_categories[$category]); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | */ |
440 | 440 | public function questionTypesWithMaxLength() |
441 | 441 | { |
442 | - return (array)$this->question_types_with_max_lengh; |
|
442 | + return (array) $this->question_types_with_max_lengh; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
446 | 446 | $new_question->set_system_ID( null ); |
447 | 447 | $new_question->set_wp_user( get_current_user_id() ); |
448 | - //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | - $new_question->set_deleted( false ); |
|
448 | + //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | + $new_question->set_deleted( false ); |
|
450 | 450 | $success = $new_question->save(); |
451 | 451 | if( $success ) { |
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | 503 | if ( $answer instanceof EE_Answer |
504 | - && $answer->value() !== '' |
|
505 | - ) { |
|
504 | + && $answer->value() !== '' |
|
505 | + ) { |
|
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
@@ -516,10 +516,10 @@ discard block |
||
516 | 516 | } |
517 | 517 | $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
518 | 518 | if( in_array( |
519 | - $this->type(), |
|
520 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
521 | - true |
|
522 | - ) ) { |
|
519 | + $this->type(), |
|
520 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
521 | + true |
|
522 | + ) ) { |
|
523 | 523 | $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
524 | 524 | null, |
525 | 525 | min( $max_max_for_question, $this->max() ) |
@@ -632,17 +632,17 @@ discard block |
||
632 | 632 | |
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Returns whether or not this question type should have question option entries |
|
637 | - * @return bool |
|
638 | - */ |
|
635 | + /** |
|
636 | + * Returns whether or not this question type should have question option entries |
|
637 | + * @return bool |
|
638 | + */ |
|
639 | 639 | public function should_have_question_options() |
640 | - { |
|
641 | - return in_array( |
|
642 | - $this->type(), |
|
643 | - $this->_model->question_types_with_options(), |
|
644 | - true |
|
645 | - ); |
|
646 | - } |
|
640 | + { |
|
641 | + return in_array( |
|
642 | + $this->type(), |
|
643 | + $this->_model->question_types_with_options(), |
|
644 | + true |
|
645 | + ); |
|
646 | + } |
|
647 | 647 | |
648 | 648 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * date_format and the second value is the time format |
38 | 38 | * @return EE_Question |
39 | 39 | */ |
40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * the website will be used. |
51 | 51 | * @return EE_Question |
52 | 52 | */ |
53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
54 | + return new self($props_n_values, TRUE, $timezone); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @access public |
63 | 63 | * @param string $QST_display_text |
64 | 64 | */ |
65 | - public function set_display_text( $QST_display_text = '' ) { |
|
66 | - $this->set( 'QST_display_text', $QST_display_text ); |
|
65 | + public function set_display_text($QST_display_text = '') { |
|
66 | + $this->set('QST_display_text', $QST_display_text); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @access public |
75 | 75 | * @param string $QST_admin_label |
76 | 76 | */ |
77 | - public function set_admin_label( $QST_admin_label = '' ) { |
|
78 | - $this->set( 'QST_admin_label', $QST_admin_label ); |
|
77 | + public function set_admin_label($QST_admin_label = '') { |
|
78 | + $this->set('QST_admin_label', $QST_admin_label); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @param mixed $QST_system |
88 | 88 | */ |
89 | - public function set_system_ID( $QST_system = '' ) { |
|
90 | - $this->set( 'QST_system', $QST_system ); |
|
89 | + public function set_system_ID($QST_system = '') { |
|
90 | + $this->set('QST_system', $QST_system); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @access public |
99 | 99 | * @param string $QST_type |
100 | 100 | */ |
101 | - public function set_question_type( $QST_type = '' ) { |
|
102 | - $this->set( 'QST_type', $QST_type ); |
|
101 | + public function set_question_type($QST_type = '') { |
|
102 | + $this->set('QST_type', $QST_type); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @access public |
111 | 111 | * @param bool $QST_required |
112 | 112 | */ |
113 | - public function set_required( $QST_required = FALSE ) { |
|
114 | - $this->set( 'QST_required', $QST_required ); |
|
113 | + public function set_required($QST_required = FALSE) { |
|
114 | + $this->set('QST_required', $QST_required); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @access public |
123 | 123 | * @param string $QST_required_text |
124 | 124 | */ |
125 | - public function set_required_text( $QST_required_text = '' ) { |
|
126 | - $this->set( 'QST_required_text', $QST_required_text ); |
|
125 | + public function set_required_text($QST_required_text = '') { |
|
126 | + $this->set('QST_required_text', $QST_required_text); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @access public |
135 | 135 | * @param int $QST_order |
136 | 136 | */ |
137 | - public function set_order( $QST_order = 0 ) { |
|
138 | - $this->set( 'QST_order', $QST_order ); |
|
137 | + public function set_order($QST_order = 0) { |
|
138 | + $this->set('QST_order', $QST_order); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | * @param bool $QST_admin_only |
148 | 148 | */ |
149 | - public function set_admin_only( $QST_admin_only = FALSE ) { |
|
150 | - $this->set( 'QST_admin_only', $QST_admin_only ); |
|
149 | + public function set_admin_only($QST_admin_only = FALSE) { |
|
150 | + $this->set('QST_admin_only', $QST_admin_only); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @access public |
159 | 159 | * @param int $QST_wp_user |
160 | 160 | */ |
161 | - public function set_wp_user( $QST_wp_user = 1 ) { |
|
162 | - $this->set( 'QST_wp_user', $QST_wp_user ); |
|
161 | + public function set_wp_user($QST_wp_user = 1) { |
|
162 | + $this->set('QST_wp_user', $QST_wp_user); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @access public |
176 | 176 | * @param bool $QST_deleted |
177 | 177 | */ |
178 | - public function set_deleted( $QST_deleted = FALSE ) { |
|
179 | - $this->set( 'QST_deleted', $QST_deleted ); |
|
178 | + public function set_deleted($QST_deleted = FALSE) { |
|
179 | + $this->set('QST_deleted', $QST_deleted); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @return string |
188 | 188 | */ |
189 | 189 | public function display_text() { |
190 | - return $this->get( 'QST_display_text' ); |
|
190 | + return $this->get('QST_display_text'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return string |
199 | 199 | */ |
200 | 200 | public function admin_label() { |
201 | - return $this->get( 'QST_admin_label' ); |
|
201 | + return $this->get('QST_admin_label'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | public function system_ID() { |
212 | - return $this->get( 'QST_system' ); |
|
212 | + return $this->get('QST_system'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | 222 | public function required() { |
223 | - return $this->get( 'QST_required' ); |
|
223 | + return $this->get('QST_required'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | */ |
234 | 234 | public function required_text() { |
235 | - return $this->get( 'QST_required_text' ); |
|
235 | + return $this->get('QST_required_text'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string |
244 | 244 | */ |
245 | 245 | public function type() { |
246 | - return $this->get( 'QST_type' ); |
|
246 | + return $this->get('QST_type'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return int |
256 | 256 | */ |
257 | 257 | public function order() { |
258 | - return $this->get( 'QST_order' ); |
|
258 | + return $this->get('QST_order'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | 269 | public function admin_only() { |
270 | - return $this->get( 'QST_admin_only' ); |
|
270 | + return $this->get('QST_admin_only'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return int |
279 | 279 | */ |
280 | 280 | public function wp_user() { |
281 | - return $this->get( 'QST_wp_user' ); |
|
281 | + return $this->get('QST_wp_user'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | 291 | public function deleted() { |
292 | - return $this->get( 'QST_deleted' ); |
|
292 | + return $this->get('QST_deleted'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return EE_Answer[] |
300 | 300 | */ |
301 | 301 | public function answers() { |
302 | - return $this->get_many_related( 'Answer' ); |
|
302 | + return $this->get_many_related('Answer'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @return boolean true = has answers, false = no answers. |
310 | 310 | */ |
311 | 311 | public function has_answers() { |
312 | - return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE; |
|
312 | + return $this->count_related('Answer') > 0 ? TRUE : FALSE; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return EE_Question_Group[] |
320 | 320 | */ |
321 | 321 | public function question_groups() { |
322 | - return $this->get_many_related( 'Question_Group' ); |
|
322 | + return $this->get_many_related('Question_Group'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * whether it was trashed or not. |
334 | 334 | * @return EE_Question_Option[] |
335 | 335 | */ |
336 | - public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) { |
|
337 | - if ( ! $this->ID() ) { |
|
336 | + public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) { |
|
337 | + if ( ! $this->ID()) { |
|
338 | 338 | return array(); |
339 | 339 | } |
340 | 340 | $query_params = array(); |
341 | - if ( $selected_value_to_always_include ) { |
|
342 | - if ( is_array( $selected_value_to_always_include ) ) { |
|
343 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include ); |
|
341 | + if ($selected_value_to_always_include) { |
|
342 | + if (is_array($selected_value_to_always_include)) { |
|
343 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
344 | 344 | } else { |
345 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include; |
|
345 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if ( $notDeletedOptionsOnly ) { |
|
349 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE; |
|
348 | + if ($notDeletedOptionsOnly) { |
|
349 | + $query_params[0]['OR*options-query']['QSO_deleted'] = FALSE; |
|
350 | 350 | } |
351 | 351 | //order by QSO_order |
352 | - $query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' ); |
|
353 | - return $this->get_many_related( 'Question_Option', $query_params ); |
|
352 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
353 | + return $this->get_many_related('Question_Option', $query_params); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @return \EE_Question_Option[] |
361 | 361 | */ |
362 | 362 | public function temp_options() { |
363 | - return $this->_model_relations[ 'Question_Option' ]; |
|
363 | + return $this->_model_relations['Question_Option']; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param EE_Question_Option $option |
372 | 372 | * @return boolean success |
373 | 373 | */ |
374 | - public function add_option( EE_Question_Option $option ) { |
|
375 | - return $this->_add_relation_to( $option, 'Question_Option' ); |
|
374 | + public function add_option(EE_Question_Option $option) { |
|
375 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param EE_Question_Option $option |
383 | 383 | * @return boolean success |
384 | 384 | */ |
385 | - public function add_temp_option( EE_Question_Option $option ) { |
|
386 | - $this->_model_relations[ 'Question_Option' ][ ] = $option; |
|
385 | + public function add_temp_option(EE_Question_Option $option) { |
|
386 | + $this->_model_relations['Question_Option'][] = $option; |
|
387 | 387 | return TRUE; |
388 | 388 | } |
389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param EE_Question_Option $option |
395 | 395 | * @return boolean success |
396 | 396 | */ |
397 | - public function remove_option( EE_Question_Option $option ) { |
|
398 | - return $this->_remove_relation_to( $option, 'Question_Option' ); |
|
397 | + public function remove_option(EE_Question_Option $option) { |
|
398 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * @return bool |
405 | 405 | */ |
406 | 406 | public function is_system_question() { |
407 | - $system_ID = $this->get( 'QST_system' ); |
|
408 | - return ! empty( $system_ID ) ? TRUE : FALSE; |
|
407 | + $system_ID = $this->get('QST_system'); |
|
408 | + return ! empty($system_ID) ? TRUE : FALSE; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function set_order_to_latest() { |
420 | 420 | $latest_order = $this->get_model()->get_latest_question_order(); |
421 | - $latest_order ++; |
|
422 | - $this->set( 'QST_order', $latest_order ); |
|
421 | + $latest_order++; |
|
422 | + $this->set('QST_order', $latest_order); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -438,20 +438,20 @@ discard block |
||
438 | 438 | * Duplicates this question and its question options |
439 | 439 | * @return \EE_Question |
440 | 440 | */ |
441 | - public function duplicate( $options = array() ) { |
|
441 | + public function duplicate($options = array()) { |
|
442 | 442 | $new_question = clone $this; |
443 | - $new_question->set( 'QST_ID', null ); |
|
444 | - $new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) ); |
|
445 | - $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
|
446 | - $new_question->set_system_ID( null ); |
|
447 | - $new_question->set_wp_user( get_current_user_id() ); |
|
443 | + $new_question->set('QST_ID', null); |
|
444 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
445 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
446 | + $new_question->set_system_ID(null); |
|
447 | + $new_question->set_wp_user(get_current_user_id()); |
|
448 | 448 | //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
449 | - $new_question->set_deleted( false ); |
|
449 | + $new_question->set_deleted(false); |
|
450 | 450 | $success = $new_question->save(); |
451 | - if( $success ) { |
|
451 | + if ($success) { |
|
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
453 | - foreach( $this->options() as $question_option ) { |
|
454 | - $question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) ); |
|
453 | + foreach ($this->options() as $question_option) { |
|
454 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
455 | 455 | } |
456 | 456 | return $new_question; |
457 | 457 | } else { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @return int|float |
465 | 465 | */ |
466 | 466 | public function max() { |
467 | - return $this->get( 'QST_max' ); |
|
467 | + return $this->get('QST_max'); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int|float $new_max |
473 | 473 | * @return void |
474 | 474 | */ |
475 | - public function set_max( $new_max ) { |
|
476 | - $this->set( 'QST_max', $new_max ); |
|
475 | + public function set_max($new_max) { |
|
476 | + $this->set('QST_max', $new_max); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @param array $input_constructor_args |
486 | 486 | * @return EE_Form_Input_Base |
487 | 487 | */ |
488 | - public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) { |
|
488 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) { |
|
489 | 489 | $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
490 | 490 | |
491 | 491 | $input_constructor_args = array_merge( |
@@ -496,33 +496,33 @@ discard block |
||
496 | 496 | ), |
497 | 497 | $input_constructor_args |
498 | 498 | ); |
499 | - if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) { |
|
500 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() ); |
|
499 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
500 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | - if ( $answer instanceof EE_Answer |
|
503 | + if ($answer instanceof EE_Answer |
|
504 | 504 | && $answer->value() !== '' |
505 | 505 | ) { |
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
509 | 509 | $values_with_html_special_chars = $answer->value(); |
510 | - if( is_array( $values_with_html_special_chars ) ) { |
|
511 | - $default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars ); |
|
510 | + if (is_array($values_with_html_special_chars)) { |
|
511 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
512 | 512 | } else { |
513 | - $default_value = htmlspecialchars_decode( $values_with_html_special_chars ); |
|
513 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
514 | 514 | } |
515 | 515 | $input_constructor_args['default'] = $default_value; |
516 | 516 | } |
517 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
|
518 | - if( in_array( |
|
517 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
518 | + if (in_array( |
|
519 | 519 | $this->type(), |
520 | 520 | EEM_Question::instance()->questionTypesWithMaxLength(), |
521 | 521 | true |
522 | - ) ) { |
|
523 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
522 | + )) { |
|
523 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
524 | 524 | null, |
525 | - min( $max_max_for_question, $this->max() ) |
|
525 | + min($max_max_for_question, $this->max()) |
|
526 | 526 | ); |
527 | 527 | } |
528 | 528 | $input_constructor_args = apply_filters( |
@@ -534,22 +534,22 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $result = null; |
537 | - switch ( $this->type() ) { |
|
537 | + switch ($this->type()) { |
|
538 | 538 | // Text |
539 | 539 | case EEM_Question::QST_type_text : |
540 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
540 | + $result = new EE_Text_Input($input_constructor_args); |
|
541 | 541 | break; |
542 | 542 | // Textarea |
543 | 543 | case EEM_Question::QST_type_textarea : |
544 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
544 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
545 | 545 | break; |
546 | 546 | // Radio Buttons |
547 | 547 | case EEM_Question::QST_type_radio : |
548 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
548 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
549 | 549 | break; |
550 | 550 | // Dropdown |
551 | 551 | case EEM_Question::QST_type_dropdown : |
552 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
552 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
553 | 553 | break; |
554 | 554 | // State Dropdown |
555 | 555 | case EEM_Question::QST_type_state : |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $registration, |
561 | 561 | $answer |
562 | 562 | ); |
563 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
563 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
564 | 564 | break; |
565 | 565 | // Country Dropdown |
566 | 566 | case EEM_Question::QST_type_country : |
@@ -571,47 +571,47 @@ discard block |
||
571 | 571 | $registration, |
572 | 572 | $answer |
573 | 573 | ); |
574 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
574 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
575 | 575 | break; |
576 | 576 | // Checkboxes |
577 | 577 | case EEM_Question::QST_type_checkbox : |
578 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
578 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
579 | 579 | break; |
580 | 580 | // Date |
581 | 581 | case EEM_Question::QST_type_date : |
582 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
582 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
583 | 583 | break; |
584 | 584 | case EEM_Question::QST_type_html_textarea : |
585 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
586 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
587 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
585 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
586 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
587 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
588 | 588 | break; |
589 | 589 | case EEM_Question::QST_type_email : |
590 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
590 | + $result = new EE_Email_Input($input_constructor_args); |
|
591 | 591 | break; |
592 | 592 | case EEM_Question::QST_type_us_phone : |
593 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
593 | + $result = new EE_Phone_Input($input_constructor_args); |
|
594 | 594 | break; |
595 | 595 | case EEM_Question::QST_type_int : |
596 | - $result = new EE_Integer_Input( $input_constructor_args ); |
|
596 | + $result = new EE_Integer_Input($input_constructor_args); |
|
597 | 597 | break; |
598 | 598 | case EEM_Question::QST_type_decimal : |
599 | - $result = new EE_Float_Input( $input_constructor_args ); |
|
599 | + $result = new EE_Float_Input($input_constructor_args); |
|
600 | 600 | break; |
601 | 601 | case EEM_Question::QST_type_url : |
602 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
603 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
602 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
603 | + $result = new EE_Text_Input($input_constructor_args); |
|
604 | 604 | break; |
605 | 605 | case EEM_Question::QST_type_year : |
606 | 606 | $result = new EE_Year_Input( |
607 | 607 | $input_constructor_args, |
608 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
609 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
610 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
608 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
609 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
610 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
611 | 611 | ); |
612 | 612 | break; |
613 | 613 | case EEM_Question::QST_type_multi_select : |
614 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
614 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
615 | 615 | break; |
616 | 616 | // fallback |
617 | 617 | default : |
@@ -622,12 +622,12 @@ discard block |
||
622 | 622 | $this, |
623 | 623 | $input_constructor_args |
624 | 624 | ); |
625 | - if( ! $default_input ){ |
|
626 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
625 | + if ( ! $default_input) { |
|
626 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
627 | 627 | } |
628 | 628 | $result = $default_input; |
629 | 629 | } |
630 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
630 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -28,621 +28,621 @@ discard block |
||
28 | 28 | class Registration_Form_Admin_Page extends EE_Admin_Page |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * _question |
|
33 | - * holds the specific question object for the question details screen |
|
34 | - * |
|
35 | - * @var EE_Question $_question |
|
36 | - */ |
|
37 | - protected $_question; |
|
38 | - |
|
39 | - /** |
|
40 | - * _question_group |
|
41 | - * holds the specific question group object for the question group details screen |
|
42 | - * |
|
43 | - * @var EE_Question_Group $_question_group |
|
44 | - */ |
|
45 | - protected $_question_group; |
|
46 | - |
|
47 | - /** |
|
48 | - *_question_model EEM_Question model instance (for queries) |
|
49 | - * |
|
50 | - * @var EEM_Question $_question_model ; |
|
51 | - */ |
|
52 | - protected $_question_model; |
|
53 | - |
|
54 | - /** |
|
55 | - * _question_group_model EEM_Question_group instance (for queries) |
|
56 | - * |
|
57 | - * @var EEM_Question_Group $_question_group_model |
|
58 | - */ |
|
59 | - protected $_question_group_model; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @Constructor |
|
64 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - public function __construct($routing = true) |
|
68 | - { |
|
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | - $this->_question_model = EEM_Question::instance(); |
|
72 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | - parent::__construct($routing); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - protected function _init_page_props() |
|
78 | - { |
|
79 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - protected function _ajax_hooks() |
|
87 | - { |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - protected function _define_page_props() |
|
92 | - { |
|
93 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | - $this->_labels = array( |
|
95 | - 'buttons' => array( |
|
96 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | - ), |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - *_set_page_routes |
|
104 | - */ |
|
105 | - protected function _set_page_routes() |
|
106 | - { |
|
107 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | - $this->_page_routes = array( |
|
109 | - 'default' => array( |
|
110 | - 'func' => '_questions_overview_list_table', |
|
111 | - 'capability' => 'ee_read_questions', |
|
112 | - ), |
|
113 | - |
|
114 | - 'edit_question' => array( |
|
115 | - 'func' => '_edit_question', |
|
116 | - 'capability' => 'ee_edit_question', |
|
117 | - 'obj_id' => $qst_id, |
|
118 | - 'args' => array('edit'), |
|
119 | - ), |
|
120 | - |
|
121 | - 'question_groups' => array( |
|
122 | - 'func' => '_questions_groups_preview', |
|
123 | - 'capability' => 'ee_read_question_groups', |
|
124 | - ), |
|
125 | - |
|
126 | - 'update_question' => array( |
|
127 | - 'func' => '_insert_or_update_question', |
|
128 | - 'args' => array('new_question' => false), |
|
129 | - 'capability' => 'ee_edit_question', |
|
130 | - 'obj_id' => $qst_id, |
|
131 | - 'noheader' => true, |
|
132 | - ), |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - protected function _set_page_config() |
|
138 | - { |
|
139 | - $this->_page_config = array( |
|
140 | - 'default' => array( |
|
141 | - 'nav' => array( |
|
142 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | - 'order' => 10, |
|
144 | - ), |
|
145 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | - 'help_tabs' => array( |
|
148 | - 'registration_form_questions_overview_help_tab' => array( |
|
149 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | - 'filename' => 'registration_form_questions_overview', |
|
151 | - ), |
|
152 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | - ), |
|
156 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | - ), |
|
160 | - ), |
|
161 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | - 'require_nonce' => false, |
|
163 | - 'qtips' => array( |
|
164 | - 'EE_Registration_Form_Tips', |
|
165 | - )/**/ |
|
166 | - ), |
|
167 | - |
|
168 | - 'question_groups' => array( |
|
169 | - 'nav' => array( |
|
170 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | - 'order' => 20, |
|
172 | - ), |
|
173 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | - 'help_tabs' => array( |
|
175 | - 'registration_form_question_groups_help_tab' => array( |
|
176 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | - 'filename' => 'registration_form_question_groups', |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | - 'require_nonce' => false, |
|
182 | - ), |
|
183 | - |
|
184 | - 'edit_question' => array( |
|
185 | - 'nav' => array( |
|
186 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | - 'order' => 15, |
|
188 | - 'persistent' => false, |
|
189 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | - ), |
|
192 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | - 'help_tabs' => array( |
|
194 | - 'registration_form_edit_question_group_help_tab' => array( |
|
195 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | - 'filename' => 'registration_form_edit_question', |
|
197 | - ), |
|
198 | - ), |
|
199 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | - 'require_nonce' => false, |
|
201 | - ), |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - protected function _add_screen_options() |
|
207 | - { |
|
208 | - //todo |
|
209 | - } |
|
210 | - |
|
211 | - protected function _add_screen_options_default() |
|
212 | - { |
|
213 | - $page_title = $this->_admin_page_title; |
|
214 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | - $this->_per_page_screen_option(); |
|
216 | - $this->_admin_page_title = $page_title; |
|
217 | - } |
|
218 | - |
|
219 | - protected function _add_screen_options_question_groups() |
|
220 | - { |
|
221 | - $page_title = $this->_admin_page_title; |
|
222 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | - $this->_per_page_screen_option(); |
|
224 | - $this->_admin_page_title = $page_title; |
|
225 | - } |
|
226 | - |
|
227 | - //none of the below group are currently used for Event Categories |
|
228 | - protected function _add_feature_pointers() |
|
229 | - { |
|
230 | - } |
|
231 | - |
|
232 | - public function load_scripts_styles() |
|
233 | - { |
|
234 | - wp_register_style('espresso_registration', |
|
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | - wp_enqueue_style('espresso_registration'); |
|
237 | - } |
|
238 | - |
|
239 | - public function admin_init() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - public function admin_notices() |
|
244 | - { |
|
245 | - } |
|
246 | - |
|
247 | - public function admin_footer_scripts() |
|
248 | - { |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - public function load_scripts_styles_default() |
|
253 | - { |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - public function load_scripts_styles_add_question() |
|
258 | - { |
|
259 | - $this->load_scripts_styles_question_details(); |
|
260 | - } |
|
261 | - |
|
262 | - public function load_scripts_styles_edit_question() |
|
263 | - { |
|
264 | - $this->load_scripts_styles_question_details(); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Loads the JS required for adding or editing a question |
|
269 | - */ |
|
270 | - protected function load_scripts_styles_question_details() |
|
271 | - { |
|
272 | - $this->load_scripts_styles_forms(); |
|
273 | - wp_register_script('espresso_registration_form_single', |
|
274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | - EVENT_ESPRESSO_VERSION, true); |
|
276 | - wp_enqueue_script('espresso_registration_form_single'); |
|
277 | - wp_localize_script( |
|
278 | - 'espresso_registration_form_single', |
|
279 | - 'ee_question_data', |
|
280 | - array( |
|
281 | - 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
282 | - 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - public function recaptcha_info_help_tab() |
|
289 | - { |
|
290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
291 | - EEH_Template::display_template($template, array()); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - public function load_scripts_styles_forms() |
|
296 | - { |
|
297 | - //styles |
|
298 | - wp_enqueue_style('espresso-ui-theme'); |
|
299 | - //scripts |
|
300 | - wp_enqueue_script('ee_admin_js'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - protected function _set_list_table_views_default() |
|
305 | - { |
|
306 | - $this->_views = array( |
|
307 | - 'all' => array( |
|
308 | - 'slug' => 'all', |
|
309 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
310 | - 'count' => 0, |
|
31 | + /** |
|
32 | + * _question |
|
33 | + * holds the specific question object for the question details screen |
|
34 | + * |
|
35 | + * @var EE_Question $_question |
|
36 | + */ |
|
37 | + protected $_question; |
|
38 | + |
|
39 | + /** |
|
40 | + * _question_group |
|
41 | + * holds the specific question group object for the question group details screen |
|
42 | + * |
|
43 | + * @var EE_Question_Group $_question_group |
|
44 | + */ |
|
45 | + protected $_question_group; |
|
46 | + |
|
47 | + /** |
|
48 | + *_question_model EEM_Question model instance (for queries) |
|
49 | + * |
|
50 | + * @var EEM_Question $_question_model ; |
|
51 | + */ |
|
52 | + protected $_question_model; |
|
53 | + |
|
54 | + /** |
|
55 | + * _question_group_model EEM_Question_group instance (for queries) |
|
56 | + * |
|
57 | + * @var EEM_Question_Group $_question_group_model |
|
58 | + */ |
|
59 | + protected $_question_group_model; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @Constructor |
|
64 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + public function __construct($routing = true) |
|
68 | + { |
|
69 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | + $this->_question_model = EEM_Question::instance(); |
|
72 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | + parent::__construct($routing); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + protected function _init_page_props() |
|
78 | + { |
|
79 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + protected function _ajax_hooks() |
|
87 | + { |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + protected function _define_page_props() |
|
92 | + { |
|
93 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | + $this->_labels = array( |
|
95 | + 'buttons' => array( |
|
96 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | + ), |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + *_set_page_routes |
|
104 | + */ |
|
105 | + protected function _set_page_routes() |
|
106 | + { |
|
107 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | + $this->_page_routes = array( |
|
109 | + 'default' => array( |
|
110 | + 'func' => '_questions_overview_list_table', |
|
111 | + 'capability' => 'ee_read_questions', |
|
112 | + ), |
|
113 | + |
|
114 | + 'edit_question' => array( |
|
115 | + 'func' => '_edit_question', |
|
116 | + 'capability' => 'ee_edit_question', |
|
117 | + 'obj_id' => $qst_id, |
|
118 | + 'args' => array('edit'), |
|
119 | + ), |
|
120 | + |
|
121 | + 'question_groups' => array( |
|
122 | + 'func' => '_questions_groups_preview', |
|
123 | + 'capability' => 'ee_read_question_groups', |
|
124 | + ), |
|
125 | + |
|
126 | + 'update_question' => array( |
|
127 | + 'func' => '_insert_or_update_question', |
|
128 | + 'args' => array('new_question' => false), |
|
129 | + 'capability' => 'ee_edit_question', |
|
130 | + 'obj_id' => $qst_id, |
|
131 | + 'noheader' => true, |
|
132 | + ), |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + protected function _set_page_config() |
|
138 | + { |
|
139 | + $this->_page_config = array( |
|
140 | + 'default' => array( |
|
141 | + 'nav' => array( |
|
142 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | + 'order' => 10, |
|
144 | + ), |
|
145 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | + 'help_tabs' => array( |
|
148 | + 'registration_form_questions_overview_help_tab' => array( |
|
149 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | + 'filename' => 'registration_form_questions_overview', |
|
151 | + ), |
|
152 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | + ), |
|
156 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | + ), |
|
160 | + ), |
|
161 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | + 'require_nonce' => false, |
|
163 | + 'qtips' => array( |
|
164 | + 'EE_Registration_Form_Tips', |
|
165 | + )/**/ |
|
166 | + ), |
|
167 | + |
|
168 | + 'question_groups' => array( |
|
169 | + 'nav' => array( |
|
170 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | + 'order' => 20, |
|
172 | + ), |
|
173 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | + 'help_tabs' => array( |
|
175 | + 'registration_form_question_groups_help_tab' => array( |
|
176 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | + 'filename' => 'registration_form_question_groups', |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | + 'require_nonce' => false, |
|
182 | + ), |
|
183 | + |
|
184 | + 'edit_question' => array( |
|
185 | + 'nav' => array( |
|
186 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | + 'order' => 15, |
|
188 | + 'persistent' => false, |
|
189 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | + ), |
|
192 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | + 'help_tabs' => array( |
|
194 | + 'registration_form_edit_question_group_help_tab' => array( |
|
195 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | + 'filename' => 'registration_form_edit_question', |
|
197 | + ), |
|
198 | + ), |
|
199 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | + 'require_nonce' => false, |
|
201 | + ), |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + protected function _add_screen_options() |
|
207 | + { |
|
208 | + //todo |
|
209 | + } |
|
210 | + |
|
211 | + protected function _add_screen_options_default() |
|
212 | + { |
|
213 | + $page_title = $this->_admin_page_title; |
|
214 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | + $this->_per_page_screen_option(); |
|
216 | + $this->_admin_page_title = $page_title; |
|
217 | + } |
|
218 | + |
|
219 | + protected function _add_screen_options_question_groups() |
|
220 | + { |
|
221 | + $page_title = $this->_admin_page_title; |
|
222 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | + $this->_per_page_screen_option(); |
|
224 | + $this->_admin_page_title = $page_title; |
|
225 | + } |
|
226 | + |
|
227 | + //none of the below group are currently used for Event Categories |
|
228 | + protected function _add_feature_pointers() |
|
229 | + { |
|
230 | + } |
|
231 | + |
|
232 | + public function load_scripts_styles() |
|
233 | + { |
|
234 | + wp_register_style('espresso_registration', |
|
235 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | + wp_enqueue_style('espresso_registration'); |
|
237 | + } |
|
238 | + |
|
239 | + public function admin_init() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + public function admin_notices() |
|
244 | + { |
|
245 | + } |
|
246 | + |
|
247 | + public function admin_footer_scripts() |
|
248 | + { |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + public function load_scripts_styles_default() |
|
253 | + { |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + public function load_scripts_styles_add_question() |
|
258 | + { |
|
259 | + $this->load_scripts_styles_question_details(); |
|
260 | + } |
|
261 | + |
|
262 | + public function load_scripts_styles_edit_question() |
|
263 | + { |
|
264 | + $this->load_scripts_styles_question_details(); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Loads the JS required for adding or editing a question |
|
269 | + */ |
|
270 | + protected function load_scripts_styles_question_details() |
|
271 | + { |
|
272 | + $this->load_scripts_styles_forms(); |
|
273 | + wp_register_script('espresso_registration_form_single', |
|
274 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | + EVENT_ESPRESSO_VERSION, true); |
|
276 | + wp_enqueue_script('espresso_registration_form_single'); |
|
277 | + wp_localize_script( |
|
278 | + 'espresso_registration_form_single', |
|
279 | + 'ee_question_data', |
|
280 | + array( |
|
281 | + 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
282 | + 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + public function recaptcha_info_help_tab() |
|
289 | + { |
|
290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
291 | + EEH_Template::display_template($template, array()); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + public function load_scripts_styles_forms() |
|
296 | + { |
|
297 | + //styles |
|
298 | + wp_enqueue_style('espresso-ui-theme'); |
|
299 | + //scripts |
|
300 | + wp_enqueue_script('ee_admin_js'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + protected function _set_list_table_views_default() |
|
305 | + { |
|
306 | + $this->_views = array( |
|
307 | + 'all' => array( |
|
308 | + 'slug' => 'all', |
|
309 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
310 | + 'count' => 0, |
|
311 | 311 | // 'bulk_action' => array( |
312 | 312 | // 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
313 | 313 | // ) |
314 | - ), |
|
315 | - ); |
|
316 | - |
|
317 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
318 | - 'espresso_registration_form_trash_questions') |
|
319 | - ) { |
|
320 | - $this->_views['trash'] = array( |
|
321 | - 'slug' => 'trash', |
|
322 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
323 | - 'count' => 0, |
|
314 | + ), |
|
315 | + ); |
|
316 | + |
|
317 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
318 | + 'espresso_registration_form_trash_questions') |
|
319 | + ) { |
|
320 | + $this->_views['trash'] = array( |
|
321 | + 'slug' => 'trash', |
|
322 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
323 | + 'count' => 0, |
|
324 | 324 | // 'bulk_action' => array( |
325 | 325 | // 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
326 | 326 | // 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
327 | - ); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * This just previews the question groups tab that comes in caffeinated. |
|
333 | - * |
|
334 | - * @return string html |
|
335 | - */ |
|
336 | - protected function _questions_groups_preview() |
|
337 | - { |
|
338 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | - 'event_espresso') . '" />'; |
|
341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | - 'event_espresso') . '</strong>'; |
|
343 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Extracts the question field's values from the POST request to update or insert them |
|
349 | - * |
|
350 | - * @param \EEM_Base $model |
|
351 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
352 | - */ |
|
353 | - protected function _set_column_values_for(EEM_Base $model) |
|
354 | - { |
|
355 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
356 | - $set_column_values = array(); |
|
357 | - |
|
358 | - //some initial checks for proper values. |
|
359 | - //if QST_admin_only, then no matter what QST_required is we disable. |
|
360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
361 | - $this->_req_data['QST_required'] = 0; |
|
362 | - } |
|
363 | - //if the question shouldn't have a max length, don't let them set one |
|
364 | - if (! isset( |
|
365 | - $this->_req_data['QST_type'], |
|
366 | - $this->_req_data['QST_max'] |
|
367 | - ) |
|
368 | - || ! in_array( |
|
369 | - $this->_req_data['QST_type'], |
|
370 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
371 | - true) |
|
372 | - ) { |
|
373 | - //they're not allowed to set the max |
|
374 | - $this->_req_data['QST_max'] = null; |
|
375 | - } |
|
376 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | - // basically if QSG_identifier is empty or not set |
|
378 | - if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
379 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
327 | + ); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * This just previews the question groups tab that comes in caffeinated. |
|
333 | + * |
|
334 | + * @return string html |
|
335 | + */ |
|
336 | + protected function _questions_groups_preview() |
|
337 | + { |
|
338 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
339 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | + 'event_espresso') . '" />'; |
|
341 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | + 'event_espresso') . '</strong>'; |
|
343 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Extracts the question field's values from the POST request to update or insert them |
|
349 | + * |
|
350 | + * @param \EEM_Base $model |
|
351 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
352 | + */ |
|
353 | + protected function _set_column_values_for(EEM_Base $model) |
|
354 | + { |
|
355 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
356 | + $set_column_values = array(); |
|
357 | + |
|
358 | + //some initial checks for proper values. |
|
359 | + //if QST_admin_only, then no matter what QST_required is we disable. |
|
360 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
361 | + $this->_req_data['QST_required'] = 0; |
|
362 | + } |
|
363 | + //if the question shouldn't have a max length, don't let them set one |
|
364 | + if (! isset( |
|
365 | + $this->_req_data['QST_type'], |
|
366 | + $this->_req_data['QST_max'] |
|
367 | + ) |
|
368 | + || ! in_array( |
|
369 | + $this->_req_data['QST_type'], |
|
370 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
371 | + true) |
|
372 | + ) { |
|
373 | + //they're not allowed to set the max |
|
374 | + $this->_req_data['QST_max'] = null; |
|
375 | + } |
|
376 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | + // basically if QSG_identifier is empty or not set |
|
378 | + if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
379 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
381 | 381 | // dd($set_column_values); |
382 | - } //if the admin label is blank, use a slug version of the question text |
|
383 | - else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
384 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
385 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
387 | - $set_column_values[$fieldName] = 0; |
|
388 | - } else if ($fieldName === 'QST_max') { |
|
389 | - $qst_system = EEM_Question::instance()->get_var( |
|
390 | - array( |
|
391 | - array( |
|
392 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
393 | - ), |
|
394 | - ), |
|
395 | - 'QST_system'); |
|
396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | - if (empty($this->_req_data['QST_max']) || |
|
398 | - $this->_req_data['QST_max'] > $max_max |
|
399 | - ) { |
|
400 | - $set_column_values[$fieldName] = $max_max; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
406 | - if ( |
|
407 | - ! isset($set_column_values[$fieldName]) && |
|
408 | - isset($this->_req_data[$fieldName]) |
|
409 | - ) { |
|
410 | - $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
411 | - } |
|
412 | - |
|
413 | - } |
|
414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - *_questions_overview_list_table |
|
420 | - */ |
|
421 | - protected function _questions_overview_list_table() |
|
422 | - { |
|
423 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
424 | - $this->display_admin_list_table_page_with_sidebar(); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * _edit_question |
|
430 | - */ |
|
431 | - protected function _edit_question() |
|
432 | - { |
|
433 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
434 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
435 | - |
|
436 | - switch ($this->_req_action) { |
|
437 | - case 'add_question' : |
|
438 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
439 | - break; |
|
440 | - case 'edit_question' : |
|
441 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
442 | - break; |
|
443 | - default : |
|
444 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
445 | - } |
|
446 | - |
|
447 | - // add PRC_ID to title if editing |
|
448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
449 | - if ($ID) { |
|
450 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
451 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
452 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
453 | - } else { |
|
454 | - $question = EE_Question::new_instance(); |
|
455 | - $question->set_order_to_latest(); |
|
456 | - $this->_set_add_edit_form_tags('insert_question'); |
|
457 | - } |
|
458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
459 | - $question_types = array_intersect_key( |
|
460 | - EEM_Question::instance()->allowed_question_types(), |
|
461 | - array_flip( |
|
462 | - array( |
|
463 | - EEM_Question::QST_type_text, |
|
464 | - EEM_Question::QST_type_us_phone |
|
465 | - ) |
|
466 | - ) |
|
467 | - ); |
|
468 | - } else { |
|
469 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
470 | - } |
|
471 | - $this->_template_args['QST_ID'] = $ID; |
|
472 | - $this->_template_args['question'] = $question; |
|
473 | - $this->_template_args['question_types'] = $question_types; |
|
474 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
475 | - $question->system_ID() |
|
476 | - ); |
|
477 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
478 | - $this->_set_publish_post_box_vars('id', $ID); |
|
479 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
481 | - $this->_template_args, true |
|
482 | - ); |
|
483 | - |
|
484 | - // the details template wrapper |
|
485 | - $this->display_admin_page_with_sidebar(); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - protected function _get_question_type_descriptions() |
|
493 | - { |
|
494 | - EE_Registry::instance()->load_helper('HTML'); |
|
495 | - $descriptions = ''; |
|
496 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
497 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
498 | - if ($type == 'HTML_TEXTAREA') { |
|
499 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
500 | - $question_type_description .= sprintf( |
|
501 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
502 | - '<br/>', |
|
503 | - $html->get_list_of_allowed_tags() |
|
504 | - ); |
|
505 | - } |
|
506 | - $descriptions .= EEH_HTML::p( |
|
507 | - $question_type_description, |
|
508 | - 'question_type_description-' . $type, |
|
509 | - 'question_type_description description', |
|
510 | - 'display:none;' |
|
511 | - ); |
|
512 | - } |
|
513 | - return $descriptions; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * @param bool|true $new_question |
|
519 | - * @throws \EE_Error |
|
520 | - */ |
|
521 | - protected function _insert_or_update_question($new_question = true) |
|
522 | - { |
|
523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
525 | - if ($new_question) { |
|
526 | - $question = EE_Question::new_instance($set_column_values); |
|
527 | - $action_desc = 'added'; |
|
528 | - } else { |
|
529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | - foreach($set_column_values as $field => $new_value) { |
|
531 | - $question->set($field, $new_value); |
|
532 | - } |
|
533 | - $action_desc = 'updated'; |
|
534 | - } |
|
535 | - $success = $question->save(); |
|
536 | - $ID = $question->ID(); |
|
537 | - if ($ID && $question->should_have_question_options()) { |
|
538 | - //save the related options |
|
539 | - //trash removed options, save old ones |
|
540 | - //get list of all options |
|
541 | - $options = $question->options(); |
|
542 | - if (! empty($options)) { |
|
543 | - foreach ($options as $option_ID => $option) { |
|
544 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
545 | - if ($option_req_index !== false) { |
|
546 | - $option->save($this->_req_data['question_options'][$option_req_index]); |
|
547 | - } else { |
|
548 | - //not found, remove it |
|
549 | - $option->delete(); |
|
550 | - } |
|
551 | - } |
|
552 | - } |
|
553 | - //save new related options |
|
554 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
555 | - //skip $index that is from our sample |
|
556 | - if ( $index === 'xxcountxx' ) { |
|
557 | - continue; |
|
558 | - } |
|
559 | - //note we allow saving blank options. |
|
560 | - if (empty($option_req_data['QSO_ID']) |
|
561 | - ) {//no ID! save it! |
|
562 | - $new_option = EE_Question_Option::new_instance(array( |
|
563 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
564 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
565 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
566 | - 'QST_ID' => $question->ID(), |
|
567 | - )); |
|
568 | - $new_option->save(); |
|
569 | - } |
|
570 | - } |
|
571 | - } |
|
572 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
573 | - if ($success !== false) { |
|
574 | - $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
575 | - $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
576 | - $this->_question_model->item_name()); |
|
577 | - EE_Error::add_success($msg); |
|
578 | - } |
|
579 | - |
|
580 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
586 | - * by ID |
|
587 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
588 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
589 | - * |
|
590 | - * @param int $ID of the question option to find |
|
591 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
592 | - */ |
|
593 | - protected function _get_option_req_data_index($ID) |
|
594 | - { |
|
595 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
596 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
598 | - return $num; |
|
599 | - } |
|
600 | - } |
|
601 | - return false; |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /***********/ |
|
608 | - /* QUERIES */ |
|
609 | - /** |
|
610 | - * For internal use in getting all the query parameters |
|
611 | - * (because it's pretty well the same between question, question groups, |
|
612 | - * and for both when searching for trashed and untrashed ones) |
|
613 | - * |
|
614 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
615 | - * @param int $per_page |
|
616 | - * @param int $current_page |
|
617 | - * @return array lik EEM_Base::get_all's $query_params parameter |
|
618 | - */ |
|
619 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
620 | - { |
|
621 | - $query_params = array(); |
|
622 | - $offset = ($current_page - 1) * $per_page; |
|
623 | - $query_params['limit'] = array($offset, $per_page); |
|
624 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
625 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
626 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
627 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
628 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
629 | - if (! empty($search_string)) { |
|
630 | - if ($model instanceof EEM_Question_Group) { |
|
631 | - $query_params[0] = array( |
|
632 | - 'OR' => array( |
|
633 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
634 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
635 | - ), |
|
636 | - ); |
|
637 | - } else { |
|
638 | - $query_params[0] = array( |
|
639 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
640 | - ); |
|
641 | - } |
|
642 | - } |
|
643 | - |
|
644 | - //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
645 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
382 | + } //if the admin label is blank, use a slug version of the question text |
|
383 | + else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
384 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
385 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
386 | + } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
387 | + $set_column_values[$fieldName] = 0; |
|
388 | + } else if ($fieldName === 'QST_max') { |
|
389 | + $qst_system = EEM_Question::instance()->get_var( |
|
390 | + array( |
|
391 | + array( |
|
392 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
393 | + ), |
|
394 | + ), |
|
395 | + 'QST_system'); |
|
396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | + if (empty($this->_req_data['QST_max']) || |
|
398 | + $this->_req_data['QST_max'] > $max_max |
|
399 | + ) { |
|
400 | + $set_column_values[$fieldName] = $max_max; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
406 | + if ( |
|
407 | + ! isset($set_column_values[$fieldName]) && |
|
408 | + isset($this->_req_data[$fieldName]) |
|
409 | + ) { |
|
410 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
411 | + } |
|
412 | + |
|
413 | + } |
|
414 | + return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + *_questions_overview_list_table |
|
420 | + */ |
|
421 | + protected function _questions_overview_list_table() |
|
422 | + { |
|
423 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
424 | + $this->display_admin_list_table_page_with_sidebar(); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * _edit_question |
|
430 | + */ |
|
431 | + protected function _edit_question() |
|
432 | + { |
|
433 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
434 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
435 | + |
|
436 | + switch ($this->_req_action) { |
|
437 | + case 'add_question' : |
|
438 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
439 | + break; |
|
440 | + case 'edit_question' : |
|
441 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
442 | + break; |
|
443 | + default : |
|
444 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
445 | + } |
|
446 | + |
|
447 | + // add PRC_ID to title if editing |
|
448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
449 | + if ($ID) { |
|
450 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
451 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
452 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
453 | + } else { |
|
454 | + $question = EE_Question::new_instance(); |
|
455 | + $question->set_order_to_latest(); |
|
456 | + $this->_set_add_edit_form_tags('insert_question'); |
|
457 | + } |
|
458 | + if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
459 | + $question_types = array_intersect_key( |
|
460 | + EEM_Question::instance()->allowed_question_types(), |
|
461 | + array_flip( |
|
462 | + array( |
|
463 | + EEM_Question::QST_type_text, |
|
464 | + EEM_Question::QST_type_us_phone |
|
465 | + ) |
|
466 | + ) |
|
467 | + ); |
|
468 | + } else { |
|
469 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
470 | + } |
|
471 | + $this->_template_args['QST_ID'] = $ID; |
|
472 | + $this->_template_args['question'] = $question; |
|
473 | + $this->_template_args['question_types'] = $question_types; |
|
474 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
475 | + $question->system_ID() |
|
476 | + ); |
|
477 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
478 | + $this->_set_publish_post_box_vars('id', $ID); |
|
479 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
480 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
481 | + $this->_template_args, true |
|
482 | + ); |
|
483 | + |
|
484 | + // the details template wrapper |
|
485 | + $this->display_admin_page_with_sidebar(); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + protected function _get_question_type_descriptions() |
|
493 | + { |
|
494 | + EE_Registry::instance()->load_helper('HTML'); |
|
495 | + $descriptions = ''; |
|
496 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
497 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
498 | + if ($type == 'HTML_TEXTAREA') { |
|
499 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
500 | + $question_type_description .= sprintf( |
|
501 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
502 | + '<br/>', |
|
503 | + $html->get_list_of_allowed_tags() |
|
504 | + ); |
|
505 | + } |
|
506 | + $descriptions .= EEH_HTML::p( |
|
507 | + $question_type_description, |
|
508 | + 'question_type_description-' . $type, |
|
509 | + 'question_type_description description', |
|
510 | + 'display:none;' |
|
511 | + ); |
|
512 | + } |
|
513 | + return $descriptions; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * @param bool|true $new_question |
|
519 | + * @throws \EE_Error |
|
520 | + */ |
|
521 | + protected function _insert_or_update_question($new_question = true) |
|
522 | + { |
|
523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
525 | + if ($new_question) { |
|
526 | + $question = EE_Question::new_instance($set_column_values); |
|
527 | + $action_desc = 'added'; |
|
528 | + } else { |
|
529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | + foreach($set_column_values as $field => $new_value) { |
|
531 | + $question->set($field, $new_value); |
|
532 | + } |
|
533 | + $action_desc = 'updated'; |
|
534 | + } |
|
535 | + $success = $question->save(); |
|
536 | + $ID = $question->ID(); |
|
537 | + if ($ID && $question->should_have_question_options()) { |
|
538 | + //save the related options |
|
539 | + //trash removed options, save old ones |
|
540 | + //get list of all options |
|
541 | + $options = $question->options(); |
|
542 | + if (! empty($options)) { |
|
543 | + foreach ($options as $option_ID => $option) { |
|
544 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
545 | + if ($option_req_index !== false) { |
|
546 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
547 | + } else { |
|
548 | + //not found, remove it |
|
549 | + $option->delete(); |
|
550 | + } |
|
551 | + } |
|
552 | + } |
|
553 | + //save new related options |
|
554 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
555 | + //skip $index that is from our sample |
|
556 | + if ( $index === 'xxcountxx' ) { |
|
557 | + continue; |
|
558 | + } |
|
559 | + //note we allow saving blank options. |
|
560 | + if (empty($option_req_data['QSO_ID']) |
|
561 | + ) {//no ID! save it! |
|
562 | + $new_option = EE_Question_Option::new_instance(array( |
|
563 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
564 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
565 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
566 | + 'QST_ID' => $question->ID(), |
|
567 | + )); |
|
568 | + $new_option->save(); |
|
569 | + } |
|
570 | + } |
|
571 | + } |
|
572 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
573 | + if ($success !== false) { |
|
574 | + $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
575 | + $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
576 | + $this->_question_model->item_name()); |
|
577 | + EE_Error::add_success($msg); |
|
578 | + } |
|
579 | + |
|
580 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
586 | + * by ID |
|
587 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
588 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
589 | + * |
|
590 | + * @param int $ID of the question option to find |
|
591 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
592 | + */ |
|
593 | + protected function _get_option_req_data_index($ID) |
|
594 | + { |
|
595 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
596 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
597 | + if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
598 | + return $num; |
|
599 | + } |
|
600 | + } |
|
601 | + return false; |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /***********/ |
|
608 | + /* QUERIES */ |
|
609 | + /** |
|
610 | + * For internal use in getting all the query parameters |
|
611 | + * (because it's pretty well the same between question, question groups, |
|
612 | + * and for both when searching for trashed and untrashed ones) |
|
613 | + * |
|
614 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
615 | + * @param int $per_page |
|
616 | + * @param int $current_page |
|
617 | + * @return array lik EEM_Base::get_all's $query_params parameter |
|
618 | + */ |
|
619 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
620 | + { |
|
621 | + $query_params = array(); |
|
622 | + $offset = ($current_page - 1) * $per_page; |
|
623 | + $query_params['limit'] = array($offset, $per_page); |
|
624 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
625 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
626 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
627 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
628 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
629 | + if (! empty($search_string)) { |
|
630 | + if ($model instanceof EEM_Question_Group) { |
|
631 | + $query_params[0] = array( |
|
632 | + 'OR' => array( |
|
633 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
634 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
635 | + ), |
|
636 | + ); |
|
637 | + } else { |
|
638 | + $query_params[0] = array( |
|
639 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
640 | + ); |
|
641 | + } |
|
642 | + } |
|
643 | + |
|
644 | + //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
645 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
646 | 646 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
647 | 647 | $query_params[0] = array( |
648 | 648 | 'AND' => array( |
@@ -672,62 +672,62 @@ discard block |
||
672 | 672 | } |
673 | 673 | }/**/ |
674 | 674 | |
675 | - return $query_params; |
|
676 | - |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * @param int $per_page |
|
682 | - * @param int $current_page |
|
683 | - * @param bool|false $count |
|
684 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
685 | - */ |
|
686 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
687 | - { |
|
688 | - $QST = EEM_Question::instance(); |
|
689 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
690 | - if ($count) { |
|
691 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
692 | - $results = $QST->count($where); |
|
693 | - } else { |
|
694 | - $results = $QST->get_all($query_params); |
|
695 | - } |
|
696 | - return $results; |
|
697 | - |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * @param $per_page |
|
703 | - * @param int $current_page |
|
704 | - * @param bool|false $count |
|
705 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
706 | - */ |
|
707 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
708 | - { |
|
709 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
710 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
711 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
712 | - return $questions; |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @param $per_page |
|
718 | - * @param int $current_page |
|
719 | - * @param bool|false $count |
|
720 | - * @return \EE_Soft_Delete_Base_Class[] |
|
721 | - */ |
|
722 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
723 | - { |
|
724 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
725 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
726 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
727 | - return $questionGroupModel->get_all( |
|
728 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
729 | - ); |
|
730 | - } |
|
675 | + return $query_params; |
|
676 | + |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * @param int $per_page |
|
682 | + * @param int $current_page |
|
683 | + * @param bool|false $count |
|
684 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
685 | + */ |
|
686 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
687 | + { |
|
688 | + $QST = EEM_Question::instance(); |
|
689 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
690 | + if ($count) { |
|
691 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
692 | + $results = $QST->count($where); |
|
693 | + } else { |
|
694 | + $results = $QST->get_all($query_params); |
|
695 | + } |
|
696 | + return $results; |
|
697 | + |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * @param $per_page |
|
703 | + * @param int $current_page |
|
704 | + * @param bool|false $count |
|
705 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
706 | + */ |
|
707 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
708 | + { |
|
709 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
710 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
711 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
712 | + return $questions; |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @param $per_page |
|
718 | + * @param int $current_page |
|
719 | + * @param bool|false $count |
|
720 | + * @return \EE_Soft_Delete_Base_Class[] |
|
721 | + */ |
|
722 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
723 | + { |
|
724 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
725 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
726 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
727 | + return $questionGroupModel->get_all( |
|
728 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
729 | + ); |
|
730 | + } |
|
731 | 731 | |
732 | 732 | |
733 | 733 | } //ends Registration_Form_Admin_Page class |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct($routing = true) |
68 | 68 | { |
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
69 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
71 | 71 | $this->_question_model = EEM_Question::instance(); |
72 | 72 | $this->_question_group_model = EEM_Question_Group::instance(); |
73 | 73 | parent::__construct($routing); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | public function load_scripts_styles() |
233 | 233 | { |
234 | 234 | wp_register_style('espresso_registration', |
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
235 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | 236 | wp_enqueue_style('espresso_registration'); |
237 | 237 | } |
238 | 238 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | { |
272 | 272 | $this->load_scripts_styles_forms(); |
273 | 273 | wp_register_script('espresso_registration_form_single', |
274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
274 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | 275 | EVENT_ESPRESSO_VERSION, true); |
276 | 276 | wp_enqueue_script('espresso_registration_form_single'); |
277 | 277 | wp_localize_script( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | public function recaptcha_info_help_tab() |
289 | 289 | { |
290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
291 | 291 | EEH_Template::display_template($template, array()); |
292 | 292 | } |
293 | 293 | |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | protected function _questions_groups_preview() |
337 | 337 | { |
338 | 338 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | - 'event_espresso') . '" />'; |
|
341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | - 'event_espresso') . '</strong>'; |
|
339 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | + 'event_espresso').'" />'; |
|
341 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | + 'event_espresso').'</strong>'; |
|
343 | 343 | $this->display_admin_caf_preview_page('question_groups_tab'); |
344 | 344 | } |
345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | |
358 | 358 | //some initial checks for proper values. |
359 | 359 | //if QST_admin_only, then no matter what QST_required is we disable. |
360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
360 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
361 | 361 | $this->_req_data['QST_required'] = 0; |
362 | 362 | } |
363 | 363 | //if the question shouldn't have a max length, don't let them set one |
364 | - if (! isset( |
|
364 | + if ( ! isset( |
|
365 | 365 | $this->_req_data['QST_type'], |
366 | 366 | $this->_req_data['QST_max'] |
367 | 367 | ) |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | // basically if QSG_identifier is empty or not set |
378 | 378 | if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
379 | 379 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
381 | 381 | // dd($set_column_values); |
382 | 382 | } //if the admin label is blank, use a slug version of the question text |
383 | 383 | else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
384 | 384 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
385 | 385 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
386 | + } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
387 | 387 | $set_column_values[$fieldName] = 0; |
388 | 388 | } else if ($fieldName === 'QST_max') { |
389 | 389 | $qst_system = EEM_Question::instance()->get_var( |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | ), |
394 | 394 | ), |
395 | 395 | 'QST_system'); |
396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | 397 | if (empty($this->_req_data['QST_max']) || |
398 | 398 | $this->_req_data['QST_max'] > $max_max |
399 | 399 | ) { |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | } |
412 | 412 | |
413 | 413 | } |
414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
414 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | } |
446 | 446 | |
447 | 447 | // add PRC_ID to title if editing |
448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
449 | 449 | if ($ID) { |
450 | 450 | $question = $this->_question_model->get_one_by_ID($ID); |
451 | 451 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $question->set_order_to_latest(); |
456 | 456 | $this->_set_add_edit_form_tags('insert_question'); |
457 | 457 | } |
458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
458 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
459 | 459 | $question_types = array_intersect_key( |
460 | 460 | EEM_Question::instance()->allowed_question_types(), |
461 | 461 | array_flip( |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
478 | 478 | $this->_set_publish_post_box_vars('id', $ID); |
479 | 479 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
480 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
481 | 481 | $this->_template_args, true |
482 | 482 | ); |
483 | 483 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | } |
506 | 506 | $descriptions .= EEH_HTML::p( |
507 | 507 | $question_type_description, |
508 | - 'question_type_description-' . $type, |
|
508 | + 'question_type_description-'.$type, |
|
509 | 509 | 'question_type_description description', |
510 | 510 | 'display:none;' |
511 | 511 | ); |
@@ -526,8 +526,8 @@ discard block |
||
526 | 526 | $question = EE_Question::new_instance($set_column_values); |
527 | 527 | $action_desc = 'added'; |
528 | 528 | } else { |
529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | - foreach($set_column_values as $field => $new_value) { |
|
529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | + foreach ($set_column_values as $field => $new_value) { |
|
531 | 531 | $question->set($field, $new_value); |
532 | 532 | } |
533 | 533 | $action_desc = 'updated'; |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | //save the related options |
539 | 539 | //trash removed options, save old ones |
540 | 540 | //get list of all options |
541 | - $options = $question->options(); |
|
542 | - if (! empty($options)) { |
|
541 | + $options = $question->options(); |
|
542 | + if ( ! empty($options)) { |
|
543 | 543 | foreach ($options as $option_ID => $option) { |
544 | 544 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
545 | 545 | if ($option_req_index !== false) { |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | //save new related options |
554 | 554 | foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
555 | 555 | //skip $index that is from our sample |
556 | - if ( $index === 'xxcountxx' ) { |
|
556 | + if ($index === 'xxcountxx') { |
|
557 | 557 | continue; |
558 | 558 | } |
559 | 559 | //note we allow saving blank options. |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | { |
595 | 595 | $req_data_for_question_options = $this->_req_data['question_options']; |
596 | 596 | foreach ($req_data_for_question_options as $num => $option_data) { |
597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
597 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
598 | 598 | return $num; |
599 | 599 | } |
600 | 600 | } |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
627 | 627 | $query_params['order_by'] = array($field_to_order_by => $order); |
628 | 628 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
629 | - if (! empty($search_string)) { |
|
629 | + if ( ! empty($search_string)) { |
|
630 | 630 | if ($model instanceof EEM_Question_Group) { |
631 | 631 | $query_params[0] = array( |
632 | 632 | 'OR' => array( |
@@ -21,724 +21,724 @@ |
||
21 | 21 | abstract class EE_PMT_Base |
22 | 22 | { |
23 | 23 | |
24 | - const onsite = 'on-site'; |
|
25 | - const offsite = 'off-site'; |
|
26 | - const offline = 'off-line'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var EE_Payment_Method |
|
30 | - */ |
|
31 | - protected $_pm_instance = NULL; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var boolean |
|
35 | - */ |
|
36 | - protected $_requires_https = FALSE; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var boolean |
|
40 | - */ |
|
41 | - protected $_has_billing_form; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Gateway |
|
45 | - */ |
|
46 | - protected $_gateway = NULL; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EE_Payment_Method_Form |
|
50 | - */ |
|
51 | - protected $_settings_form = NULL; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EE_Form_Section_Proper |
|
55 | - */ |
|
56 | - protected $_billing_form = NULL; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var boolean |
|
60 | - */ |
|
61 | - protected $_cache_billing_form = TRUE; |
|
62 | - |
|
63 | - /** |
|
64 | - * String of the absolute path to the folder containing this file, with a trailing slash. |
|
65 | - * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $_file_folder = NULL; |
|
69 | - |
|
70 | - /** |
|
71 | - * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
72 | - * like images, js, or css) |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - protected $_file_url = NULL; |
|
76 | - |
|
77 | - /** |
|
78 | - * Pretty name for the payment method |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - protected $_pretty_name = NULL; |
|
82 | - |
|
83 | - /** |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - protected $_default_button_url = NULL; |
|
88 | - |
|
89 | - /** |
|
90 | - * |
|
91 | - * @var string |
|
92 | - */ |
|
93 | - protected $_default_description = NULL; |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * |
|
98 | - * @param EE_Payment_Method $pm_instance |
|
99 | - * @throws EE_Error |
|
100 | - * @return EE_PMT_Base |
|
101 | - */ |
|
102 | - function __construct($pm_instance = NULL) |
|
103 | - { |
|
104 | - if ($pm_instance instanceof EE_Payment_Method) { |
|
105 | - $this->set_instance($pm_instance); |
|
106 | - } |
|
107 | - if ($this->_gateway) { |
|
108 | - $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
109 | - $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
110 | - $this->_gateway->set_template_helper(new EEH_Template()); |
|
111 | - $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
112 | - $this->_gateway->set_money_helper(new EEH_Money()); |
|
113 | - $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
114 | - $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
115 | - do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
116 | - } |
|
117 | - if (!isset($this->_has_billing_form)) { |
|
118 | - // by default, On Site gateways have a billing form |
|
119 | - if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
120 | - $this->set_has_billing_form(true); |
|
121 | - } else { |
|
122 | - $this->set_has_billing_form(false); |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - if (!$this->_pretty_name) { |
|
127 | - throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
|
128 | - } |
|
129 | - //if the child didn't specify a default button, use the credit card one |
|
130 | - if ($this->_default_button_url === NULL) { |
|
131 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param boolean $has_billing_form |
|
138 | - */ |
|
139 | - public function set_has_billing_form($has_billing_form) |
|
140 | - { |
|
141 | - $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * sets the file_folder property |
|
147 | - */ |
|
148 | - protected function _set_file_folder() |
|
149 | - { |
|
150 | - $reflector = new ReflectionClass(get_class($this)); |
|
151 | - $fn = $reflector->getFileName(); |
|
152 | - $this->_file_folder = dirname($fn) . DS; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * sets the file URL with a trailing slash for this PMT |
|
158 | - */ |
|
159 | - protected function _set_file_url() |
|
160 | - { |
|
161 | - $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
162 | - $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
163 | - $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
164 | - $this->_file_url = $file_path; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Gets the default description on all payment methods of this type |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function default_description() |
|
172 | - { |
|
173 | - return $this->_default_description; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns the folder containing the PMT child class, with a trailing slash |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function file_folder() |
|
182 | - { |
|
183 | - if (!$this->_file_folder) { |
|
184 | - $this->_set_file_folder(); |
|
185 | - } |
|
186 | - return $this->_file_folder; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function file_url() |
|
194 | - { |
|
195 | - if (!$this->_file_url) { |
|
196 | - $this->_set_file_url(); |
|
197 | - } |
|
198 | - return $this->_file_url; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Sets the payment method instance this payment method type is for. |
|
204 | - * Its important teh payment method instance is set before |
|
205 | - * @param EE_Payment_Method $payment_method_instance |
|
206 | - */ |
|
207 | - function set_instance($payment_method_instance) |
|
208 | - { |
|
209 | - $this->_pm_instance = $payment_method_instance; |
|
210 | - //if they have already requested the settings form, make sure its |
|
211 | - //data matches this model object |
|
212 | - if ($this->_settings_form) { |
|
213 | - $this->settings_form()->populate_model_obj($payment_method_instance); |
|
214 | - } |
|
215 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
216 | - $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * Gets teh form for displaying to admins where they setup the payment method |
|
223 | - * @return EE_Payment_Method_Form |
|
224 | - */ |
|
225 | - function settings_form() |
|
226 | - { |
|
227 | - if (!$this->_settings_form) { |
|
228 | - $this->_settings_form = $this->generate_new_settings_form(); |
|
229 | - $this->_settings_form->set_payment_method_type($this); |
|
230 | - //if we have already assigned a model object to this pmt, make |
|
231 | - //sure its reflected in teh form we just generated |
|
232 | - if ($this->_pm_instance) { |
|
233 | - $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
234 | - } |
|
235 | - } |
|
236 | - return $this->_settings_form; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Gets the form for all the settings related to this payment method type |
|
242 | - * @return EE_Payment_Method_Form |
|
243 | - */ |
|
244 | - abstract function generate_new_settings_form(); |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the form for settings. This may be useful if we have already received |
|
249 | - * a form submission and have form data it in, and want to use it anytime we're showing |
|
250 | - * this payment method type's settings form later in the request |
|
251 | - * @param EE_Payment_Method_Form $form |
|
252 | - */ |
|
253 | - public function set_settings_form($form) |
|
254 | - { |
|
255 | - $this->_settings_form = $form; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @return boolean |
|
261 | - */ |
|
262 | - public function has_billing_form() |
|
263 | - { |
|
264 | - return $this->_has_billing_form; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Gets the form for displaying to attendees where they can enter their billing info |
|
270 | - * which will be sent to teh gateway (can be null) |
|
271 | - * |
|
272 | - * @param \EE_Transaction $transaction |
|
273 | - * @param array $extra_args |
|
274 | - * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
275 | - */ |
|
276 | - public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
|
277 | - { |
|
278 | - // has billing form already been regenerated ? or overwrite cache? |
|
279 | - if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
280 | - $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
281 | - } |
|
282 | - //if we know who the attendee is, and this is a billing form |
|
283 | - //that uses attendee info, populate it |
|
284 | - if ( |
|
285 | - apply_filters( |
|
286 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
287 | - ( |
|
288 | - $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
289 | - && $transaction instanceof EE_Transaction |
|
290 | - && $transaction->primary_registration() instanceof EE_Registration |
|
291 | - && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
292 | - ), |
|
293 | - $this->_billing_form, |
|
294 | - $transaction |
|
295 | - ) |
|
296 | - ) { |
|
297 | - $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
298 | - } |
|
299 | - return $this->_billing_form; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Creates the billing form for this payment method type |
|
305 | - * @param \EE_Transaction $transaction |
|
306 | - * @return \EE_Billing_Info_Form |
|
307 | - */ |
|
308 | - abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * apply_billing_form_debug_settings |
|
313 | - * applies debug data to the form |
|
314 | - * |
|
315 | - * @param \EE_Billing_Info_Form $billing_form |
|
316 | - * @return \EE_Billing_Info_Form |
|
317 | - */ |
|
318 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
319 | - { |
|
320 | - return $billing_form; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Sets the billing form for this payment method type. You may want to use this |
|
326 | - * if you have form |
|
327 | - * @param EE_Payment_Method $form |
|
328 | - */ |
|
329 | - public function set_billing_form($form) |
|
330 | - { |
|
331 | - $this->_billing_form = $form; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Returns whether or not this payment method requires HTTPS to be used |
|
337 | - * @return boolean |
|
338 | - */ |
|
339 | - function requires_https() |
|
340 | - { |
|
341 | - return $this->_requires_https; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * |
|
347 | - * @param EE_Transaction $transaction |
|
348 | - * @param float $amount |
|
349 | - * @param EE_Billing_Info_Form $billing_info |
|
350 | - * @param string $return_url |
|
351 | - * @param string $fail_url |
|
352 | - * @param string $method |
|
353 | - * @param bool $by_admin |
|
354 | - * @return EE_Payment |
|
355 | - * @throws EE_Error |
|
356 | - */ |
|
357 | - function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) |
|
358 | - { |
|
359 | - // @todo: add surcharge for the payment method, if any |
|
360 | - if ($this->_gateway) { |
|
361 | - //there is a gateway, so we're going to make a payment object |
|
362 | - //but wait! do they already have a payment in progress that we thought was failed? |
|
363 | - $duplicate_properties = array( |
|
364 | - 'STS_ID' => EEM_Payment::status_id_failed, |
|
365 | - 'TXN_ID' => $transaction->ID(), |
|
366 | - 'PMD_ID' => $this->_pm_instance->ID(), |
|
367 | - 'PAY_source' => $method, |
|
368 | - 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
369 | - 'PAY_gateway_response' => null, |
|
370 | - ); |
|
371 | - $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
372 | - //if we didn't already have a payment in progress for the same thing, |
|
373 | - //then we actually want to make a new payment |
|
374 | - if (!$payment instanceof EE_Payment) { |
|
375 | - $payment = EE_Payment::new_instance( |
|
376 | - array_merge( |
|
377 | - $duplicate_properties, |
|
378 | - array( |
|
379 | - 'PAY_timestamp' => time(), |
|
380 | - 'PAY_txn_id_chq_nmbr' => null, |
|
381 | - 'PAY_po_number' => null, |
|
382 | - 'PAY_extra_accntng' => null, |
|
383 | - 'PAY_details' => null, |
|
384 | - ) |
|
385 | - ) |
|
386 | - ); |
|
387 | - } |
|
388 | - //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
389 | - $payment->save(); |
|
390 | - $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
391 | - |
|
392 | - // Offsite Gateway |
|
393 | - if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
394 | - |
|
395 | - $payment = $this->_gateway->set_redirection_info( |
|
396 | - $payment, |
|
397 | - $billing_values, |
|
398 | - $return_url, |
|
399 | - EE_Config::instance()->core->txn_page_url( |
|
400 | - array( |
|
401 | - 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
402 | - 'ee_payment_method' => $this->_pm_instance->slug() |
|
403 | - ) |
|
404 | - ), |
|
405 | - $fail_url |
|
406 | - ); |
|
407 | - $payment->save(); |
|
408 | - // Onsite Gateway |
|
409 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
410 | - |
|
411 | - $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
412 | - $payment->save(); |
|
413 | - |
|
414 | - } else { |
|
415 | - throw new EE_Error( |
|
416 | - sprintf( |
|
417 | - __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
418 | - get_class($this), |
|
419 | - gettype($this->_gateway) |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - } else { |
|
425 | - // no gateway provided |
|
426 | - // there is no payment. Must be an offline gateway |
|
427 | - // create a payment object anyways, but dont save it |
|
428 | - $payment = EE_Payment::new_instance( |
|
429 | - array( |
|
430 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
431 | - 'TXN_ID' => $transaction->ID(), |
|
432 | - 'PMD_ID' => $transaction->payment_method_ID(), |
|
433 | - 'PAY_amount' => 0.00, |
|
434 | - 'PAY_timestamp' => time(), |
|
435 | - ) |
|
436 | - ); |
|
437 | - |
|
438 | - } |
|
439 | - |
|
440 | - // if there is billing info, clean it and save it now |
|
441 | - if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
442 | - $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
443 | - } |
|
444 | - |
|
445 | - return $payment; |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Gets the values we want to pass onto the gateway. Normally these |
|
450 | - * are just the 'pretty' values, but there may be times the data may need |
|
451 | - * a little massaging. Proper subsections will become arrays of inputs |
|
452 | - * @param EE_Billing_Info_Form $billing_form |
|
453 | - * @return array |
|
454 | - */ |
|
455 | - protected function _get_billing_values_from_form($billing_form) |
|
456 | - { |
|
457 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
458 | - return $billing_form->input_pretty_values(true); |
|
459 | - } else { |
|
460 | - return NULL; |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * Handles an instant payment notification when the transaction is known (by default). |
|
467 | - * @param array $req_data |
|
468 | - * @param EE_Transaction $transaction |
|
469 | - * @return EE_Payment |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - public function handle_ipn($req_data, $transaction) |
|
473 | - { |
|
474 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
475 | - if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
476 | - throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
477 | - |
|
478 | - } |
|
479 | - $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
480 | - return $payment; |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
486 | - * cleans it first. |
|
487 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
488 | - * @param EE_Transaction $transaction |
|
489 | - * @return boolean success |
|
490 | - */ |
|
491 | - protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
492 | - { |
|
493 | - if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
494 | - EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
495 | - return false; |
|
496 | - } |
|
497 | - $primary_reg = $transaction->primary_registration(); |
|
498 | - if (!$primary_reg) { |
|
499 | - EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
500 | - return false; |
|
501 | - } |
|
502 | - $attendee = $primary_reg->attendee(); |
|
503 | - if (!$attendee) { |
|
504 | - EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
505 | - return false; |
|
506 | - } |
|
507 | - return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
508 | - |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Gets the payment this IPN is for. Children may often want to |
|
514 | - * override this to inspect the request |
|
515 | - * @param EE_Transaction $transaction |
|
516 | - * @param array $req_data |
|
517 | - * @return EE_Payment |
|
518 | - */ |
|
519 | - protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
520 | - { |
|
521 | - return $transaction->last_payment(); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * In case generic code cannot provide the payment processor with a specific payment method |
|
527 | - * and transaction, it will try calling this method on each activate payment method. |
|
528 | - * If the payment method is able to identify the request as being for it, it should fetch |
|
529 | - * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
530 | - * handle the IPN |
|
531 | - * @param array $req_data |
|
532 | - * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
533 | - * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
534 | - * @throws EE_Error |
|
535 | - */ |
|
536 | - public function handle_unclaimed_ipn($req_data = array()) |
|
537 | - { |
|
538 | - throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Logic to be accomplished when the payment attempt is complete. |
|
544 | - * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
545 | - * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
546 | - * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
547 | - * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
548 | - * we're dealing with. Returns that last payment (if there is one) |
|
549 | - * |
|
550 | - * @param EE_Transaction $transaction |
|
551 | - * @return EE_Payment |
|
552 | - */ |
|
553 | - public function finalize_payment_for($transaction) |
|
554 | - { |
|
555 | - return $transaction->last_payment(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Whether or not this payment method's gateway supports sending refund requests |
|
561 | - * @return boolean |
|
562 | - */ |
|
563 | - public function supports_sending_refunds() |
|
564 | - { |
|
565 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
566 | - return $this->_gateway->supports_sending_refunds(); |
|
567 | - } else { |
|
568 | - return false; |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * |
|
575 | - * @param EE_Payment $payment |
|
576 | - * @param array $refund_info |
|
577 | - * @throws EE_Error |
|
578 | - * @return EE_Payment |
|
579 | - */ |
|
580 | - public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
581 | - { |
|
582 | - if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
583 | - return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
584 | - } else { |
|
585 | - throw new EE_Error( |
|
586 | - sprintf( |
|
587 | - __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
588 | - get_class($this) |
|
589 | - ) |
|
590 | - ); |
|
591 | - } |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
597 | - * payment method's gateway. |
|
598 | - * @return string |
|
599 | - * @throws EE_Error |
|
600 | - */ |
|
601 | - public function payment_occurs() |
|
602 | - { |
|
603 | - if (!$this->_gateway) { |
|
604 | - return EE_PMT_Base::offline; |
|
605 | - } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
606 | - return EE_PMT_Base::onsite; |
|
607 | - } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
608 | - return EE_PMT_Base::offsite; |
|
609 | - } else { |
|
610 | - throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
611 | - } |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * For adding any html output ab ove the payment overview. |
|
617 | - * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
618 | - * Other gateways may want to override this, such as offline gateways. |
|
619 | - * @param EE_Payment $payment |
|
620 | - * @return string |
|
621 | - */ |
|
622 | - public function payment_overview_content(EE_Payment $payment) |
|
623 | - { |
|
624 | - return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * @return array where keys are the help tab name, |
|
630 | - * values are: array { |
|
631 | - * @type string $title i18n name for the help tab |
|
632 | - * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
633 | - * @type array $template_args any arguments you want passed to the template file while rendering. |
|
634 | - * Keys will be variable names and values with be their values. |
|
635 | - */ |
|
636 | - public function help_tabs_config() |
|
637 | - { |
|
638 | - return array(); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
644 | - * the payment method's table's PMT_type column) |
|
645 | - * @return string |
|
646 | - */ |
|
647 | - public function system_name() |
|
648 | - { |
|
649 | - $classname = get_class($this); |
|
650 | - return str_replace("EE_PMT_", '', $classname); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * A pretty i18n version of the PMT name |
|
656 | - * @return string |
|
657 | - */ |
|
658 | - public function pretty_name() |
|
659 | - { |
|
660 | - return $this->_pretty_name; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Gets the default absolute URL to the payment method type's button |
|
666 | - * @return string |
|
667 | - */ |
|
668 | - public function default_button_url() |
|
669 | - { |
|
670 | - return $this->_default_button_url; |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Gets the gateway used by this payment method (if any) |
|
676 | - * @return EE_Gateway |
|
677 | - */ |
|
678 | - public function get_gateway() |
|
679 | - { |
|
680 | - return $this->_gateway; |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * @return string html for the link to a help tab |
|
686 | - */ |
|
687 | - public function get_help_tab_link() |
|
688 | - { |
|
689 | - return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Returns the name of the help tab for this PMT |
|
695 | - * @return string |
|
696 | - */ |
|
697 | - public function get_help_tab_name() |
|
698 | - { |
|
699 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
700 | - } |
|
701 | - |
|
702 | - /** |
|
703 | - * The name of the wp capability that should be associated with the usage of |
|
704 | - * this PMT by an admin |
|
705 | - * @return string |
|
706 | - */ |
|
707 | - public function cap_name() |
|
708 | - { |
|
709 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Called by client code to tell the gateway that if it wants to change |
|
714 | - * the transaction or line items or registrations related to teh payment it already |
|
715 | - * processed (we think, but possibly not) that now's the time to do it. |
|
716 | - * It is expected that gateways will store any info they need for this on the PAY_details, |
|
717 | - * or maybe an extra meta value |
|
718 | - * @param EE_Payment $payment |
|
719 | - * @return void |
|
720 | - */ |
|
721 | - public function update_txn_based_on_payment($payment) |
|
722 | - { |
|
723 | - if ($this->_gateway instanceof EE_Gateway) { |
|
724 | - $this->_gateway->update_txn_based_on_payment($payment); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - /** |
|
729 | - * Returns a string of HTML describing this payment method type for an admin, |
|
730 | - * primarily intended for them to read before activating it. |
|
731 | - * The easiest way to set this is to create a folder 'templates' alongside |
|
732 | - * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
733 | - * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
734 | - * then you'd create a file named "templates" in the same folder as it, and name the file |
|
735 | - * "foo_bar_intro.template.php", and its content will be returned by this method |
|
736 | - * @return string |
|
737 | - */ |
|
738 | - public function introductory_html() |
|
739 | - { |
|
740 | - return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
741 | - } |
|
24 | + const onsite = 'on-site'; |
|
25 | + const offsite = 'off-site'; |
|
26 | + const offline = 'off-line'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var EE_Payment_Method |
|
30 | + */ |
|
31 | + protected $_pm_instance = NULL; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var boolean |
|
35 | + */ |
|
36 | + protected $_requires_https = FALSE; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var boolean |
|
40 | + */ |
|
41 | + protected $_has_billing_form; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Gateway |
|
45 | + */ |
|
46 | + protected $_gateway = NULL; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EE_Payment_Method_Form |
|
50 | + */ |
|
51 | + protected $_settings_form = NULL; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EE_Form_Section_Proper |
|
55 | + */ |
|
56 | + protected $_billing_form = NULL; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var boolean |
|
60 | + */ |
|
61 | + protected $_cache_billing_form = TRUE; |
|
62 | + |
|
63 | + /** |
|
64 | + * String of the absolute path to the folder containing this file, with a trailing slash. |
|
65 | + * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/' |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $_file_folder = NULL; |
|
69 | + |
|
70 | + /** |
|
71 | + * String to the absolute URL to this file (useful for getting its web-accessible resources |
|
72 | + * like images, js, or css) |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + protected $_file_url = NULL; |
|
76 | + |
|
77 | + /** |
|
78 | + * Pretty name for the payment method |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + protected $_pretty_name = NULL; |
|
82 | + |
|
83 | + /** |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + protected $_default_button_url = NULL; |
|
88 | + |
|
89 | + /** |
|
90 | + * |
|
91 | + * @var string |
|
92 | + */ |
|
93 | + protected $_default_description = NULL; |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * |
|
98 | + * @param EE_Payment_Method $pm_instance |
|
99 | + * @throws EE_Error |
|
100 | + * @return EE_PMT_Base |
|
101 | + */ |
|
102 | + function __construct($pm_instance = NULL) |
|
103 | + { |
|
104 | + if ($pm_instance instanceof EE_Payment_Method) { |
|
105 | + $this->set_instance($pm_instance); |
|
106 | + } |
|
107 | + if ($this->_gateway) { |
|
108 | + $this->_gateway->set_payment_model(EEM_Payment::instance()); |
|
109 | + $this->_gateway->set_payment_log(EEM_Change_Log::instance()); |
|
110 | + $this->_gateway->set_template_helper(new EEH_Template()); |
|
111 | + $this->_gateway->set_line_item_helper(new EEH_Line_Item()); |
|
112 | + $this->_gateway->set_money_helper(new EEH_Money()); |
|
113 | + $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter()); |
|
114 | + $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
|
115 | + do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
|
116 | + } |
|
117 | + if (!isset($this->_has_billing_form)) { |
|
118 | + // by default, On Site gateways have a billing form |
|
119 | + if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
|
120 | + $this->set_has_billing_form(true); |
|
121 | + } else { |
|
122 | + $this->set_has_billing_form(false); |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + if (!$this->_pretty_name) { |
|
127 | + throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
|
128 | + } |
|
129 | + //if the child didn't specify a default button, use the credit card one |
|
130 | + if ($this->_default_button_url === NULL) { |
|
131 | + $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param boolean $has_billing_form |
|
138 | + */ |
|
139 | + public function set_has_billing_form($has_billing_form) |
|
140 | + { |
|
141 | + $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * sets the file_folder property |
|
147 | + */ |
|
148 | + protected function _set_file_folder() |
|
149 | + { |
|
150 | + $reflector = new ReflectionClass(get_class($this)); |
|
151 | + $fn = $reflector->getFileName(); |
|
152 | + $this->_file_folder = dirname($fn) . DS; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * sets the file URL with a trailing slash for this PMT |
|
158 | + */ |
|
159 | + protected function _set_file_url() |
|
160 | + { |
|
161 | + $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR); |
|
162 | + $file_folder_fixed = str_replace('\\', DS, $this->file_folder()); |
|
163 | + $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed); |
|
164 | + $this->_file_url = $file_path; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Gets the default description on all payment methods of this type |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function default_description() |
|
172 | + { |
|
173 | + return $this->_default_description; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns the folder containing the PMT child class, with a trailing slash |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function file_folder() |
|
182 | + { |
|
183 | + if (!$this->_file_folder) { |
|
184 | + $this->_set_file_folder(); |
|
185 | + } |
|
186 | + return $this->_file_folder; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function file_url() |
|
194 | + { |
|
195 | + if (!$this->_file_url) { |
|
196 | + $this->_set_file_url(); |
|
197 | + } |
|
198 | + return $this->_file_url; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Sets the payment method instance this payment method type is for. |
|
204 | + * Its important teh payment method instance is set before |
|
205 | + * @param EE_Payment_Method $payment_method_instance |
|
206 | + */ |
|
207 | + function set_instance($payment_method_instance) |
|
208 | + { |
|
209 | + $this->_pm_instance = $payment_method_instance; |
|
210 | + //if they have already requested the settings form, make sure its |
|
211 | + //data matches this model object |
|
212 | + if ($this->_settings_form) { |
|
213 | + $this->settings_form()->populate_model_obj($payment_method_instance); |
|
214 | + } |
|
215 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
216 | + $this->_gateway->set_settings($payment_method_instance->settings_array()); |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * Gets teh form for displaying to admins where they setup the payment method |
|
223 | + * @return EE_Payment_Method_Form |
|
224 | + */ |
|
225 | + function settings_form() |
|
226 | + { |
|
227 | + if (!$this->_settings_form) { |
|
228 | + $this->_settings_form = $this->generate_new_settings_form(); |
|
229 | + $this->_settings_form->set_payment_method_type($this); |
|
230 | + //if we have already assigned a model object to this pmt, make |
|
231 | + //sure its reflected in teh form we just generated |
|
232 | + if ($this->_pm_instance) { |
|
233 | + $this->_settings_form->populate_model_obj($this->_pm_instance); |
|
234 | + } |
|
235 | + } |
|
236 | + return $this->_settings_form; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Gets the form for all the settings related to this payment method type |
|
242 | + * @return EE_Payment_Method_Form |
|
243 | + */ |
|
244 | + abstract function generate_new_settings_form(); |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the form for settings. This may be useful if we have already received |
|
249 | + * a form submission and have form data it in, and want to use it anytime we're showing |
|
250 | + * this payment method type's settings form later in the request |
|
251 | + * @param EE_Payment_Method_Form $form |
|
252 | + */ |
|
253 | + public function set_settings_form($form) |
|
254 | + { |
|
255 | + $this->_settings_form = $form; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @return boolean |
|
261 | + */ |
|
262 | + public function has_billing_form() |
|
263 | + { |
|
264 | + return $this->_has_billing_form; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Gets the form for displaying to attendees where they can enter their billing info |
|
270 | + * which will be sent to teh gateway (can be null) |
|
271 | + * |
|
272 | + * @param \EE_Transaction $transaction |
|
273 | + * @param array $extra_args |
|
274 | + * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null |
|
275 | + */ |
|
276 | + public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
|
277 | + { |
|
278 | + // has billing form already been regenerated ? or overwrite cache? |
|
279 | + if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
280 | + $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
|
281 | + } |
|
282 | + //if we know who the attendee is, and this is a billing form |
|
283 | + //that uses attendee info, populate it |
|
284 | + if ( |
|
285 | + apply_filters( |
|
286 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
287 | + ( |
|
288 | + $this->_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
289 | + && $transaction instanceof EE_Transaction |
|
290 | + && $transaction->primary_registration() instanceof EE_Registration |
|
291 | + && $transaction->primary_registration()->attendee() instanceof EE_Attendee |
|
292 | + ), |
|
293 | + $this->_billing_form, |
|
294 | + $transaction |
|
295 | + ) |
|
296 | + ) { |
|
297 | + $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee()); |
|
298 | + } |
|
299 | + return $this->_billing_form; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Creates the billing form for this payment method type |
|
305 | + * @param \EE_Transaction $transaction |
|
306 | + * @return \EE_Billing_Info_Form |
|
307 | + */ |
|
308 | + abstract function generate_new_billing_form(EE_Transaction $transaction = NULL); |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * apply_billing_form_debug_settings |
|
313 | + * applies debug data to the form |
|
314 | + * |
|
315 | + * @param \EE_Billing_Info_Form $billing_form |
|
316 | + * @return \EE_Billing_Info_Form |
|
317 | + */ |
|
318 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
319 | + { |
|
320 | + return $billing_form; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Sets the billing form for this payment method type. You may want to use this |
|
326 | + * if you have form |
|
327 | + * @param EE_Payment_Method $form |
|
328 | + */ |
|
329 | + public function set_billing_form($form) |
|
330 | + { |
|
331 | + $this->_billing_form = $form; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Returns whether or not this payment method requires HTTPS to be used |
|
337 | + * @return boolean |
|
338 | + */ |
|
339 | + function requires_https() |
|
340 | + { |
|
341 | + return $this->_requires_https; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * |
|
347 | + * @param EE_Transaction $transaction |
|
348 | + * @param float $amount |
|
349 | + * @param EE_Billing_Info_Form $billing_info |
|
350 | + * @param string $return_url |
|
351 | + * @param string $fail_url |
|
352 | + * @param string $method |
|
353 | + * @param bool $by_admin |
|
354 | + * @return EE_Payment |
|
355 | + * @throws EE_Error |
|
356 | + */ |
|
357 | + function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false) |
|
358 | + { |
|
359 | + // @todo: add surcharge for the payment method, if any |
|
360 | + if ($this->_gateway) { |
|
361 | + //there is a gateway, so we're going to make a payment object |
|
362 | + //but wait! do they already have a payment in progress that we thought was failed? |
|
363 | + $duplicate_properties = array( |
|
364 | + 'STS_ID' => EEM_Payment::status_id_failed, |
|
365 | + 'TXN_ID' => $transaction->ID(), |
|
366 | + 'PMD_ID' => $this->_pm_instance->ID(), |
|
367 | + 'PAY_source' => $method, |
|
368 | + 'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(), |
|
369 | + 'PAY_gateway_response' => null, |
|
370 | + ); |
|
371 | + $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
|
372 | + //if we didn't already have a payment in progress for the same thing, |
|
373 | + //then we actually want to make a new payment |
|
374 | + if (!$payment instanceof EE_Payment) { |
|
375 | + $payment = EE_Payment::new_instance( |
|
376 | + array_merge( |
|
377 | + $duplicate_properties, |
|
378 | + array( |
|
379 | + 'PAY_timestamp' => time(), |
|
380 | + 'PAY_txn_id_chq_nmbr' => null, |
|
381 | + 'PAY_po_number' => null, |
|
382 | + 'PAY_extra_accntng' => null, |
|
383 | + 'PAY_details' => null, |
|
384 | + ) |
|
385 | + ) |
|
386 | + ); |
|
387 | + } |
|
388 | + //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it |
|
389 | + $payment->save(); |
|
390 | + $billing_values = $this->_get_billing_values_from_form($billing_info); |
|
391 | + |
|
392 | + // Offsite Gateway |
|
393 | + if ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
394 | + |
|
395 | + $payment = $this->_gateway->set_redirection_info( |
|
396 | + $payment, |
|
397 | + $billing_values, |
|
398 | + $return_url, |
|
399 | + EE_Config::instance()->core->txn_page_url( |
|
400 | + array( |
|
401 | + 'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(), |
|
402 | + 'ee_payment_method' => $this->_pm_instance->slug() |
|
403 | + ) |
|
404 | + ), |
|
405 | + $fail_url |
|
406 | + ); |
|
407 | + $payment->save(); |
|
408 | + // Onsite Gateway |
|
409 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
410 | + |
|
411 | + $payment = $this->_gateway->do_direct_payment($payment, $billing_values); |
|
412 | + $payment->save(); |
|
413 | + |
|
414 | + } else { |
|
415 | + throw new EE_Error( |
|
416 | + sprintf( |
|
417 | + __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'), |
|
418 | + get_class($this), |
|
419 | + gettype($this->_gateway) |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + } else { |
|
425 | + // no gateway provided |
|
426 | + // there is no payment. Must be an offline gateway |
|
427 | + // create a payment object anyways, but dont save it |
|
428 | + $payment = EE_Payment::new_instance( |
|
429 | + array( |
|
430 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
431 | + 'TXN_ID' => $transaction->ID(), |
|
432 | + 'PMD_ID' => $transaction->payment_method_ID(), |
|
433 | + 'PAY_amount' => 0.00, |
|
434 | + 'PAY_timestamp' => time(), |
|
435 | + ) |
|
436 | + ); |
|
437 | + |
|
438 | + } |
|
439 | + |
|
440 | + // if there is billing info, clean it and save it now |
|
441 | + if ($billing_info instanceof EE_Billing_Attendee_Info_Form) { |
|
442 | + $this->_save_billing_info_to_attendee($billing_info, $transaction); |
|
443 | + } |
|
444 | + |
|
445 | + return $payment; |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Gets the values we want to pass onto the gateway. Normally these |
|
450 | + * are just the 'pretty' values, but there may be times the data may need |
|
451 | + * a little massaging. Proper subsections will become arrays of inputs |
|
452 | + * @param EE_Billing_Info_Form $billing_form |
|
453 | + * @return array |
|
454 | + */ |
|
455 | + protected function _get_billing_values_from_form($billing_form) |
|
456 | + { |
|
457 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
458 | + return $billing_form->input_pretty_values(true); |
|
459 | + } else { |
|
460 | + return NULL; |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * Handles an instant payment notification when the transaction is known (by default). |
|
467 | + * @param array $req_data |
|
468 | + * @param EE_Transaction $transaction |
|
469 | + * @return EE_Payment |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + public function handle_ipn($req_data, $transaction) |
|
473 | + { |
|
474 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
475 | + if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
476 | + throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
|
477 | + |
|
478 | + } |
|
479 | + $payment = $this->_gateway->handle_payment_update($req_data, $transaction); |
|
480 | + return $payment; |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * Saves the billing info onto the attendee of the primary registrant on this transaction, and |
|
486 | + * cleans it first. |
|
487 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
488 | + * @param EE_Transaction $transaction |
|
489 | + * @return boolean success |
|
490 | + */ |
|
491 | + protected function _save_billing_info_to_attendee($billing_form, $transaction) |
|
492 | + { |
|
493 | + if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
494 | + EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
495 | + return false; |
|
496 | + } |
|
497 | + $primary_reg = $transaction->primary_registration(); |
|
498 | + if (!$primary_reg) { |
|
499 | + EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
500 | + return false; |
|
501 | + } |
|
502 | + $attendee = $primary_reg->attendee(); |
|
503 | + if (!$attendee) { |
|
504 | + EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
505 | + return false; |
|
506 | + } |
|
507 | + return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method()); |
|
508 | + |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Gets the payment this IPN is for. Children may often want to |
|
514 | + * override this to inspect the request |
|
515 | + * @param EE_Transaction $transaction |
|
516 | + * @param array $req_data |
|
517 | + * @return EE_Payment |
|
518 | + */ |
|
519 | + protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) |
|
520 | + { |
|
521 | + return $transaction->last_payment(); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * In case generic code cannot provide the payment processor with a specific payment method |
|
527 | + * and transaction, it will try calling this method on each activate payment method. |
|
528 | + * If the payment method is able to identify the request as being for it, it should fetch |
|
529 | + * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot |
|
530 | + * handle the IPN |
|
531 | + * @param array $req_data |
|
532 | + * @return EE_Payment only if this payment method can find the info its needs from $req_data |
|
533 | + * and identifies the IPN as being for this payment method (not just fo ra payment method of this type) |
|
534 | + * @throws EE_Error |
|
535 | + */ |
|
536 | + public function handle_unclaimed_ipn($req_data = array()) |
|
537 | + { |
|
538 | + throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this))); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Logic to be accomplished when the payment attempt is complete. |
|
544 | + * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
545 | + * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
546 | + * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
547 | + * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
548 | + * we're dealing with. Returns that last payment (if there is one) |
|
549 | + * |
|
550 | + * @param EE_Transaction $transaction |
|
551 | + * @return EE_Payment |
|
552 | + */ |
|
553 | + public function finalize_payment_for($transaction) |
|
554 | + { |
|
555 | + return $transaction->last_payment(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Whether or not this payment method's gateway supports sending refund requests |
|
561 | + * @return boolean |
|
562 | + */ |
|
563 | + public function supports_sending_refunds() |
|
564 | + { |
|
565 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
566 | + return $this->_gateway->supports_sending_refunds(); |
|
567 | + } else { |
|
568 | + return false; |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * |
|
575 | + * @param EE_Payment $payment |
|
576 | + * @param array $refund_info |
|
577 | + * @throws EE_Error |
|
578 | + * @return EE_Payment |
|
579 | + */ |
|
580 | + public function process_refund(EE_Payment $payment, $refund_info = array()) |
|
581 | + { |
|
582 | + if ($this->_gateway && $this->_gateway instanceof EE_Gateway) { |
|
583 | + return $this->_gateway->do_direct_refund($payment, $refund_info); |
|
584 | + } else { |
|
585 | + throw new EE_Error( |
|
586 | + sprintf( |
|
587 | + __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'), |
|
588 | + get_class($this) |
|
589 | + ) |
|
590 | + ); |
|
591 | + } |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * Returns one the class's constants onsite,offsite, or offline, depending on this |
|
597 | + * payment method's gateway. |
|
598 | + * @return string |
|
599 | + * @throws EE_Error |
|
600 | + */ |
|
601 | + public function payment_occurs() |
|
602 | + { |
|
603 | + if (!$this->_gateway) { |
|
604 | + return EE_PMT_Base::offline; |
|
605 | + } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
|
606 | + return EE_PMT_Base::onsite; |
|
607 | + } elseif ($this->_gateway instanceof EE_Offsite_Gateway) { |
|
608 | + return EE_PMT_Base::offsite; |
|
609 | + } else { |
|
610 | + throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this))); |
|
611 | + } |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * For adding any html output ab ove the payment overview. |
|
617 | + * Many gateways won't want ot display anything, so this function just returns an empty string. |
|
618 | + * Other gateways may want to override this, such as offline gateways. |
|
619 | + * @param EE_Payment $payment |
|
620 | + * @return string |
|
621 | + */ |
|
622 | + public function payment_overview_content(EE_Payment $payment) |
|
623 | + { |
|
624 | + return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * @return array where keys are the help tab name, |
|
630 | + * values are: array { |
|
631 | + * @type string $title i18n name for the help tab |
|
632 | + * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file) |
|
633 | + * @type array $template_args any arguments you want passed to the template file while rendering. |
|
634 | + * Keys will be variable names and values with be their values. |
|
635 | + */ |
|
636 | + public function help_tabs_config() |
|
637 | + { |
|
638 | + return array(); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into |
|
644 | + * the payment method's table's PMT_type column) |
|
645 | + * @return string |
|
646 | + */ |
|
647 | + public function system_name() |
|
648 | + { |
|
649 | + $classname = get_class($this); |
|
650 | + return str_replace("EE_PMT_", '', $classname); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * A pretty i18n version of the PMT name |
|
656 | + * @return string |
|
657 | + */ |
|
658 | + public function pretty_name() |
|
659 | + { |
|
660 | + return $this->_pretty_name; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Gets the default absolute URL to the payment method type's button |
|
666 | + * @return string |
|
667 | + */ |
|
668 | + public function default_button_url() |
|
669 | + { |
|
670 | + return $this->_default_button_url; |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Gets the gateway used by this payment method (if any) |
|
676 | + * @return EE_Gateway |
|
677 | + */ |
|
678 | + public function get_gateway() |
|
679 | + { |
|
680 | + return $this->_gateway; |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * @return string html for the link to a help tab |
|
686 | + */ |
|
687 | + public function get_help_tab_link() |
|
688 | + { |
|
689 | + return EEH_Template::get_help_tab_link($this->get_help_tab_name()); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Returns the name of the help tab for this PMT |
|
695 | + * @return string |
|
696 | + */ |
|
697 | + public function get_help_tab_name() |
|
698 | + { |
|
699 | + return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
700 | + } |
|
701 | + |
|
702 | + /** |
|
703 | + * The name of the wp capability that should be associated with the usage of |
|
704 | + * this PMT by an admin |
|
705 | + * @return string |
|
706 | + */ |
|
707 | + public function cap_name() |
|
708 | + { |
|
709 | + return 'ee_payment_method_' . strtolower($this->system_name()); |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Called by client code to tell the gateway that if it wants to change |
|
714 | + * the transaction or line items or registrations related to teh payment it already |
|
715 | + * processed (we think, but possibly not) that now's the time to do it. |
|
716 | + * It is expected that gateways will store any info they need for this on the PAY_details, |
|
717 | + * or maybe an extra meta value |
|
718 | + * @param EE_Payment $payment |
|
719 | + * @return void |
|
720 | + */ |
|
721 | + public function update_txn_based_on_payment($payment) |
|
722 | + { |
|
723 | + if ($this->_gateway instanceof EE_Gateway) { |
|
724 | + $this->_gateway->update_txn_based_on_payment($payment); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + /** |
|
729 | + * Returns a string of HTML describing this payment method type for an admin, |
|
730 | + * primarily intended for them to read before activating it. |
|
731 | + * The easiest way to set this is to create a folder 'templates' alongside |
|
732 | + * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php". |
|
733 | + * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php", |
|
734 | + * then you'd create a file named "templates" in the same folder as it, and name the file |
|
735 | + * "foo_bar_intro.template.php", and its content will be returned by this method |
|
736 | + * @return string |
|
737 | + */ |
|
738 | + public function introductory_html() |
|
739 | + { |
|
740 | + return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
741 | + } |
|
742 | 742 | |
743 | 743 | |
744 | 744 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $this->_gateway->set_unsupported_character_remover(new AsciiOnly()); |
115 | 115 | do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway); |
116 | 116 | } |
117 | - if (!isset($this->_has_billing_form)) { |
|
117 | + if ( ! isset($this->_has_billing_form)) { |
|
118 | 118 | // by default, On Site gateways have a billing form |
119 | 119 | if ($this->payment_occurs() == EE_PMT_Base::onsite) { |
120 | 120 | $this->set_has_billing_form(true); |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - if (!$this->_pretty_name) { |
|
126 | + if ( ! $this->_pretty_name) { |
|
127 | 127 | throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso"))); |
128 | 128 | } |
129 | 129 | //if the child didn't specify a default button, use the credit card one |
130 | 130 | if ($this->_default_button_url === NULL) { |
131 | - $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png'; |
|
131 | + $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png'; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | { |
150 | 150 | $reflector = new ReflectionClass(get_class($this)); |
151 | 151 | $fn = $reflector->getFileName(); |
152 | - $this->_file_folder = dirname($fn) . DS; |
|
152 | + $this->_file_folder = dirname($fn).DS; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function file_folder() |
182 | 182 | { |
183 | - if (!$this->_file_folder) { |
|
183 | + if ( ! $this->_file_folder) { |
|
184 | 184 | $this->_set_file_folder(); |
185 | 185 | } |
186 | 186 | return $this->_file_folder; |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function file_url() |
194 | 194 | { |
195 | - if (!$this->_file_url) { |
|
195 | + if ( ! $this->_file_url) { |
|
196 | 196 | $this->_set_file_url(); |
197 | 197 | } |
198 | 198 | return $this->_file_url; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | function settings_form() |
226 | 226 | { |
227 | - if (!$this->_settings_form) { |
|
227 | + if ( ! $this->_settings_form) { |
|
228 | 228 | $this->_settings_form = $this->generate_new_settings_form(); |
229 | 229 | $this->_settings_form->set_payment_method_type($this); |
230 | 230 | //if we have already assigned a model object to this pmt, make |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array()) |
277 | 277 | { |
278 | 278 | // has billing form already been regenerated ? or overwrite cache? |
279 | - if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) { |
|
279 | + if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) { |
|
280 | 280 | $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args); |
281 | 281 | } |
282 | 282 | //if we know who the attendee is, and this is a billing form |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $payment = EEM_Payment::instance()->get_one(array($duplicate_properties)); |
372 | 372 | //if we didn't already have a payment in progress for the same thing, |
373 | 373 | //then we actually want to make a new payment |
374 | - if (!$payment instanceof EE_Payment) { |
|
374 | + if ( ! $payment instanceof EE_Payment) { |
|
375 | 375 | $payment = EE_Payment::new_instance( |
376 | 376 | array_merge( |
377 | 377 | $duplicate_properties, |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | public function handle_ipn($req_data, $transaction) |
473 | 473 | { |
474 | 474 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
475 | - if (!$this->_gateway instanceof EE_Offsite_Gateway) { |
|
475 | + if ( ! $this->_gateway instanceof EE_Offsite_Gateway) { |
|
476 | 476 | throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE))); |
477 | 477 | |
478 | 478 | } |
@@ -490,17 +490,17 @@ discard block |
||
490 | 490 | */ |
491 | 491 | protected function _save_billing_info_to_attendee($billing_form, $transaction) |
492 | 492 | { |
493 | - if (!$transaction || !$transaction instanceof EE_Transaction) { |
|
493 | + if ( ! $transaction || ! $transaction instanceof EE_Transaction) { |
|
494 | 494 | EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
495 | 495 | return false; |
496 | 496 | } |
497 | 497 | $primary_reg = $transaction->primary_registration(); |
498 | - if (!$primary_reg) { |
|
498 | + if ( ! $primary_reg) { |
|
499 | 499 | EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
500 | 500 | return false; |
501 | 501 | } |
502 | 502 | $attendee = $primary_reg->attendee(); |
503 | - if (!$attendee) { |
|
503 | + if ( ! $attendee) { |
|
504 | 504 | EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
505 | 505 | return false; |
506 | 506 | } |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | */ |
601 | 601 | public function payment_occurs() |
602 | 602 | { |
603 | - if (!$this->_gateway) { |
|
603 | + if ( ! $this->_gateway) { |
|
604 | 604 | return EE_PMT_Base::offline; |
605 | 605 | } elseif ($this->_gateway instanceof EE_Onsite_Gateway) { |
606 | 606 | return EE_PMT_Base::onsite; |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | */ |
622 | 622 | public function payment_overview_content(EE_Payment $payment) |
623 | 623 | { |
624 | - return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
624 | + return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | */ |
697 | 697 | public function get_help_tab_name() |
698 | 698 | { |
699 | - return 'ee_' . strtolower($this->system_name()) . '_help_tab'; |
|
699 | + return 'ee_'.strtolower($this->system_name()).'_help_tab'; |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | */ |
707 | 707 | public function cap_name() |
708 | 708 | { |
709 | - return 'ee_payment_method_' . strtolower($this->system_name()); |
|
709 | + return 'ee_payment_method_'.strtolower($this->system_name()); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | /** |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | */ |
738 | 738 | public function introductory_html() |
739 | 739 | { |
740 | - return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
740 | + return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance)); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
16 | 16 | $I->ensurePluginActive( |
17 | - 'event-espresso-mer-multi-event-registration', |
|
18 | - 'activated' |
|
17 | + 'event-espresso-mer-multi-event-registration', |
|
18 | + 'activated' |
|
19 | 19 | ); |
20 | 20 | |
21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -73,38 +73,38 @@ discard block |
||
73 | 73 | $I->loginAsAdmin(); |
74 | 74 | $I->amOnMessagesActivityListTablePage(); |
75 | 75 | $I->see( |
76 | - '[email protected]', |
|
77 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
78 | - 'to', |
|
79 | - 'Registration Multi-status Summary', |
|
80 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
81 | - '', |
|
82 | - 'Primary Registrant' |
|
83 | - ) |
|
76 | + '[email protected]', |
|
77 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
78 | + 'to', |
|
79 | + 'Registration Multi-status Summary', |
|
80 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
81 | + '', |
|
82 | + 'Primary Registrant' |
|
83 | + ) |
|
84 | 84 | ); |
85 | 85 | $I->see( |
86 | - '[email protected]', |
|
87 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
88 | - 'to', |
|
89 | - 'Registration Multi-status Summary', |
|
90 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
91 | - ) |
|
86 | + '[email protected]', |
|
87 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
88 | + 'to', |
|
89 | + 'Registration Multi-status Summary', |
|
90 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
91 | + ) |
|
92 | 92 | ); |
93 | 93 | //verify count |
94 | 94 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
95 | - 1, |
|
96 | - '[email protected]', |
|
97 | - 'to', |
|
98 | - 'Registration Multi-status Summary', |
|
99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | - 'Email', |
|
101 | - 'Primary Registrant' |
|
95 | + 1, |
|
96 | + '[email protected]', |
|
97 | + 'to', |
|
98 | + 'Registration Multi-status Summary', |
|
99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | + 'Email', |
|
101 | + 'Primary Registrant' |
|
102 | 102 | ); |
103 | 103 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
104 | - 1, |
|
105 | - '[email protected]', |
|
106 | - 'to', |
|
107 | - 'Registration Multi-status Summary' |
|
104 | + 1, |
|
105 | + '[email protected]', |
|
106 | + 'to', |
|
107 | + 'Registration Multi-status Summary' |
|
108 | 108 | ); |
109 | 109 | |
110 | 110 | //okay now let's do some registrations for just the first event and verify that registration multi-status summary is NOT |
@@ -134,25 +134,25 @@ discard block |
||
134 | 134 | $I->loginAsAdmin(); |
135 | 135 | $I->amOnMessagesActivityListTablePage(); |
136 | 136 | $I->dontSee( |
137 | - '[email protected]', |
|
138 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
139 | - 'to', |
|
140 | - 'Registration Multi-status Summary', |
|
141 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
142 | - '', |
|
143 | - 'Primary Registrant' |
|
144 | - ) |
|
137 | + '[email protected]', |
|
138 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
139 | + 'to', |
|
140 | + 'Registration Multi-status Summary', |
|
141 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
142 | + '', |
|
143 | + 'Primary Registrant' |
|
144 | + ) |
|
145 | 145 | ); |
146 | 146 | //there should still only be one admin multi-status summary thing. |
147 | 147 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
148 | - 1, |
|
149 | - '[email protected]', |
|
150 | - 'to', |
|
151 | - 'Registration Multi-status Summary' |
|
148 | + 1, |
|
149 | + '[email protected]', |
|
150 | + 'to', |
|
151 | + 'Registration Multi-status Summary' |
|
152 | 152 | ); |
153 | 153 | |
154 | 154 | //deactivate MER plugin so its not active for future tests |
155 | 155 | $I->ensurePluginDeactivated( |
156 | - 'event-espresso-mer-multi-event-registration', |
|
157 | - 'plugins deactivated' |
|
156 | + 'event-espresso-mer-multi-event-registration', |
|
157 | + 'plugins deactivated' |
|
158 | 158 | ); |
159 | 159 | \ No newline at end of file |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | $event_one_link = $event_two_link = $event_three_link = ''; |
19 | 19 | |
20 | 20 | $I->wantTo( |
21 | - 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | - . 'template, that that custom template will be used.' |
|
21 | + 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | + . 'template, that that custom template will be used.' |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | //need the MER plugin active for this test (we'll deactivate it after). |
26 | 26 | $I->ensurePluginActive( |
27 | - 'event-espresso-mer-multi-event-registration', |
|
28 | - 'activated' |
|
27 | + 'event-espresso-mer-multi-event-registration', |
|
28 | + 'activated' |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | $I->loginAsAdmin(); |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | |
81 | 81 | |
82 | 82 | $test_registration_details = array( |
83 | - 'fname' => 'CTGuy', |
|
84 | - 'lname' => 'Dude', |
|
85 | - 'email' => '[email protected]' |
|
83 | + 'fname' => 'CTGuy', |
|
84 | + 'lname' => 'Dude', |
|
85 | + 'email' => '[email protected]' |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.'); |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | $I->loginAsAdmin(); |
109 | 109 | $I->amOnMessagesActivityListTablePage(); |
110 | 110 | $I->viewMessageInMessagesListTableFor( |
111 | - 'Registration Approved', |
|
112 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
113 | - 'Email', |
|
114 | - 'Registrant' |
|
111 | + 'Registration Approved', |
|
112 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
113 | + 'Email', |
|
114 | + 'Registrant' |
|
115 | 115 | ); |
116 | 116 | $I->seeTextInViewMessageModal($custom_template_a_label); |
117 | 117 | $I->dismissMessageModal(); |
118 | 118 | $I->deleteMessageInMessagesListTableFor( |
119 | - 'Registration Approved', |
|
120 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
121 | - 'Email', |
|
122 | - 'Registrant' |
|
119 | + 'Registration Approved', |
|
120 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
121 | + 'Email', |
|
122 | + 'Registrant' |
|
123 | 123 | ); |
124 | 124 | |
125 | 125 | //verify admin context |
126 | 126 | $I->viewMessageInMessagesListTableFor( |
127 | - 'Registration Approved' |
|
127 | + 'Registration Approved' |
|
128 | 128 | ); |
129 | 129 | $I->seeTextInViewMessageModal($custom_template_a_label); |
130 | 130 | $I->dismissMessageModal(); |
@@ -153,25 +153,25 @@ discard block |
||
153 | 153 | $I->loginAsAdmin(); |
154 | 154 | $I->amOnMessagesActivityListTablePage(); |
155 | 155 | $I->viewMessageInMessagesListTableFor( |
156 | - 'Registration Approved', |
|
157 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
158 | - 'Email', |
|
159 | - 'Registrant' |
|
156 | + 'Registration Approved', |
|
157 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
158 | + 'Email', |
|
159 | + 'Registrant' |
|
160 | 160 | ); |
161 | 161 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
162 | 162 | $I->dontSeeTextInViewMessageModal($custom_template_a_label); |
163 | 163 | $I->dontSeeTextInViewMessageModal($custom_template_b_label); |
164 | 164 | $I->dismissMessageModal(); |
165 | 165 | $I->deleteMessageInMessagesListTableFor( |
166 | - 'Registration Approved', |
|
167 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
168 | - 'Email', |
|
169 | - 'Registrant' |
|
166 | + 'Registration Approved', |
|
167 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
168 | + 'Email', |
|
169 | + 'Registrant' |
|
170 | 170 | ); |
171 | 171 | |
172 | 172 | //verify admin context |
173 | 173 | $I->viewMessageInMessagesListTableFor( |
174 | - 'Registration Approved' |
|
174 | + 'Registration Approved' |
|
175 | 175 | ); |
176 | 176 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
177 | 177 | $I->dontSee($custom_template_a_label); |
@@ -183,6 +183,6 @@ discard block |
||
183 | 183 | |
184 | 184 | //deactivate MER plugin so its not active for future tests |
185 | 185 | $I->ensurePluginDeactivated( |
186 | - 'event-espresso-mer-multi-event-registration', |
|
187 | - 'plugins deactivated' |
|
186 | + 'event-espresso-mer-multi-event-registration', |
|
187 | + 'plugins deactivated' |
|
188 | 188 | ); |
189 | 189 | \ No newline at end of file |
@@ -6,59 +6,59 @@ |
||
6 | 6 | |
7 | 7 | trait CountrySettingsAdmin |
8 | 8 | { |
9 | - /** |
|
10 | - * Instructs the actor to browse to the country settings page. |
|
11 | - * Assumes the actor is already logged in. |
|
12 | - * @param string $additional_params |
|
13 | - */ |
|
14 | - public function amOnCountrySettingsAdminPage($additional_params = '') |
|
15 | - { |
|
16 | - $this->actor()->amOnAdminPage(CountrySettings::url($additional_params)); |
|
17 | - } |
|
9 | + /** |
|
10 | + * Instructs the actor to browse to the country settings page. |
|
11 | + * Assumes the actor is already logged in. |
|
12 | + * @param string $additional_params |
|
13 | + */ |
|
14 | + public function amOnCountrySettingsAdminPage($additional_params = '') |
|
15 | + { |
|
16 | + $this->actor()->amOnAdminPage(CountrySettings::url($additional_params)); |
|
17 | + } |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Instructs the actor to select the given decimal places radio option. |
|
22 | - * Assumes the actor is already on the country settings page. |
|
23 | - * @param string $decimal_places |
|
24 | - * @param string $country_code |
|
25 | - */ |
|
26 | - public function setCurrencyDecimalPlacesTo($decimal_places = '2', $country_code = 'US') |
|
27 | - { |
|
28 | - $this->actor()->click(CountrySettings::currencyDecimalPlacesRadioField($decimal_places, $country_code)); |
|
29 | - } |
|
20 | + /** |
|
21 | + * Instructs the actor to select the given decimal places radio option. |
|
22 | + * Assumes the actor is already on the country settings page. |
|
23 | + * @param string $decimal_places |
|
24 | + * @param string $country_code |
|
25 | + */ |
|
26 | + public function setCurrencyDecimalPlacesTo($decimal_places = '2', $country_code = 'US') |
|
27 | + { |
|
28 | + $this->actor()->click(CountrySettings::currencyDecimalPlacesRadioField($decimal_places, $country_code)); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Instructs the actor to select the given decimal mark radio option. |
|
34 | - * Assumes the actor is already on the country settings page. |
|
35 | - * @param string $decimal_mark |
|
36 | - */ |
|
37 | - public function setCurrencyDecimalMarkTo($decimal_mark = '.') |
|
38 | - { |
|
39 | - $this->actor()->click(CountrySettings::currencyDecimalMarkRadioField($decimal_mark)); |
|
40 | - } |
|
32 | + /** |
|
33 | + * Instructs the actor to select the given decimal mark radio option. |
|
34 | + * Assumes the actor is already on the country settings page. |
|
35 | + * @param string $decimal_mark |
|
36 | + */ |
|
37 | + public function setCurrencyDecimalMarkTo($decimal_mark = '.') |
|
38 | + { |
|
39 | + $this->actor()->click(CountrySettings::currencyDecimalMarkRadioField($decimal_mark)); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Instructs the actor to select the given thousands separator radio option. |
|
45 | - * Assumes the actor is already on the country settings page. |
|
46 | - * @param string $thousands_seperator |
|
47 | - */ |
|
48 | - public function setCurrencyThousandsSeparatorTo($thousands_seperator = ',') |
|
49 | - { |
|
50 | - $this->actor()->click(CountrySettings::currencyThousandsSeparatorField($thousands_seperator)); |
|
51 | - } |
|
43 | + /** |
|
44 | + * Instructs the actor to select the given thousands separator radio option. |
|
45 | + * Assumes the actor is already on the country settings page. |
|
46 | + * @param string $thousands_seperator |
|
47 | + */ |
|
48 | + public function setCurrencyThousandsSeparatorTo($thousands_seperator = ',') |
|
49 | + { |
|
50 | + $this->actor()->click(CountrySettings::currencyThousandsSeparatorField($thousands_seperator)); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * Clicks the country settings submit button. |
|
56 | - * Assumes the actor is on the country settings admin page. |
|
57 | - */ |
|
58 | - public function saveCountrySettings() |
|
59 | - { |
|
60 | - $this->actor()->click(CountrySettings::COUNTRY_SETTINGS_SAVE_BUTTON); |
|
61 | - //no indicator on the page when stuff has been updated so just give a bit of time for it to finish. |
|
62 | - $this->actor()->wait(10); |
|
63 | - } |
|
54 | + /** |
|
55 | + * Clicks the country settings submit button. |
|
56 | + * Assumes the actor is on the country settings admin page. |
|
57 | + */ |
|
58 | + public function saveCountrySettings() |
|
59 | + { |
|
60 | + $this->actor()->click(CountrySettings::COUNTRY_SETTINGS_SAVE_BUTTON); |
|
61 | + //no indicator on the page when stuff has been updated so just give a bit of time for it to finish. |
|
62 | + $this->actor()->wait(10); |
|
63 | + } |
|
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_SPCO_JSON_Response |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_SPCO_JSON_Response |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_SPCO_JSON_Response { |
15 | 15 | |
16 | 16 | /** |