@@ -10,145 +10,145 @@ |
||
10 | 10 | class EEM_Answer extends EEM_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * private instance of the EEM_Answer object |
|
15 | - * @type EEM_Answer |
|
16 | - */ |
|
17 | - protected static $_instance = null; |
|
13 | + /** |
|
14 | + * private instance of the EEM_Answer object |
|
15 | + * @type EEM_Answer |
|
16 | + */ |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Mapping from system question ids to attendee field names |
|
21 | - * @type array |
|
22 | - * @deprecated since version 4.8.8 |
|
23 | - */ |
|
24 | - protected $_question_id_to_att_field_map = array( |
|
25 | - EEM_Attendee::fname_question_id => 'ATT_fname', |
|
26 | - EEM_Attendee::lname_question_id => 'ATT_lname', |
|
27 | - EEM_Attendee::email_question_id => 'ATT_email', |
|
28 | - EEM_Attendee::address_question_id => 'ATT_address', |
|
29 | - EEM_Attendee::address2_question_id => 'ATT_address2', |
|
30 | - EEM_Attendee::city_question_id => 'ATT_city', |
|
31 | - EEM_Attendee::state_question_id => 'STA_ID', |
|
32 | - EEM_Attendee::country_question_id => 'CNT_ISO', |
|
33 | - EEM_Attendee::zip_question_id => 'ATT_zip', |
|
34 | - EEM_Attendee::phone_question_id => 'ATT_phone' |
|
35 | - ); |
|
19 | + /** |
|
20 | + * Mapping from system question ids to attendee field names |
|
21 | + * @type array |
|
22 | + * @deprecated since version 4.8.8 |
|
23 | + */ |
|
24 | + protected $_question_id_to_att_field_map = array( |
|
25 | + EEM_Attendee::fname_question_id => 'ATT_fname', |
|
26 | + EEM_Attendee::lname_question_id => 'ATT_lname', |
|
27 | + EEM_Attendee::email_question_id => 'ATT_email', |
|
28 | + EEM_Attendee::address_question_id => 'ATT_address', |
|
29 | + EEM_Attendee::address2_question_id => 'ATT_address2', |
|
30 | + EEM_Attendee::city_question_id => 'ATT_city', |
|
31 | + EEM_Attendee::state_question_id => 'STA_ID', |
|
32 | + EEM_Attendee::country_question_id => 'CNT_ISO', |
|
33 | + EEM_Attendee::zip_question_id => 'ATT_zip', |
|
34 | + EEM_Attendee::phone_question_id => 'ATT_phone' |
|
35 | + ); |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * constructor |
|
41 | - */ |
|
42 | - protected function __construct($timezone = null) |
|
43 | - { |
|
44 | - $this->singular_item = __('Answer', 'event_espresso'); |
|
45 | - $this->plural_item = __('Answers', 'event_espresso'); |
|
46 | - $this->_tables = array( |
|
47 | - 'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
48 | - ); |
|
49 | - $this->_fields = array( |
|
50 | - 'Answer' => array( |
|
51 | - 'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
52 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
53 | - 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
54 | - 'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
55 | - )); |
|
56 | - $this->_model_relations = array( |
|
57 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
58 | - 'Question' => new EE_Belongs_To_Relation() |
|
59 | - ); |
|
60 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
61 | - $this->_caps_slug = 'registrations'; |
|
62 | - parent::__construct($timezone); |
|
63 | - } |
|
39 | + /** |
|
40 | + * constructor |
|
41 | + */ |
|
42 | + protected function __construct($timezone = null) |
|
43 | + { |
|
44 | + $this->singular_item = __('Answer', 'event_espresso'); |
|
45 | + $this->plural_item = __('Answers', 'event_espresso'); |
|
46 | + $this->_tables = array( |
|
47 | + 'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
48 | + ); |
|
49 | + $this->_fields = array( |
|
50 | + 'Answer' => array( |
|
51 | + 'ANS_ID' => new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
52 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
53 | + 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
54 | + 'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
55 | + )); |
|
56 | + $this->_model_relations = array( |
|
57 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
58 | + 'Question' => new EE_Belongs_To_Relation() |
|
59 | + ); |
|
60 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
61 | + $this->_caps_slug = 'registrations'; |
|
62 | + parent::__construct($timezone); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Gets the string answer to the question for this registration (it could either be stored |
|
69 | - * on the attendee or in the answer table. This function finds its value regardless) |
|
70 | - * @param EE_Registration $registration |
|
71 | - * @param int $question_id |
|
72 | - * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
76 | - { |
|
77 | - $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
78 | - if ($value === null) { |
|
79 | - $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
80 | - if ($answer_obj instanceof EE_Answer) { |
|
81 | - if ($pretty_answer) { |
|
82 | - $value = $answer_obj->pretty_value(); |
|
83 | - } else { |
|
84 | - $value = $answer_obj->value(); |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
88 | - return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
89 | - } |
|
67 | + /** |
|
68 | + * Gets the string answer to the question for this registration (it could either be stored |
|
69 | + * on the attendee or in the answer table. This function finds its value regardless) |
|
70 | + * @param EE_Registration $registration |
|
71 | + * @param int $question_id |
|
72 | + * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
76 | + { |
|
77 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
78 | + if ($value === null) { |
|
79 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
80 | + if ($answer_obj instanceof EE_Answer) { |
|
81 | + if ($pretty_answer) { |
|
82 | + $value = $answer_obj->pretty_value(); |
|
83 | + } else { |
|
84 | + $value = $answer_obj->value(); |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * Gets the EE_Answer object for the question for this registration (if it exists) |
|
95 | - * @param EE_Registration $registration |
|
96 | - * @param int $question_id |
|
97 | - * @return EE_Answer |
|
98 | - */ |
|
99 | - public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
100 | - { |
|
101 | - $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() ))); |
|
102 | - return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
103 | - } |
|
93 | + /** |
|
94 | + * Gets the EE_Answer object for the question for this registration (if it exists) |
|
95 | + * @param EE_Registration $registration |
|
96 | + * @param int $question_id |
|
97 | + * @return EE_Answer |
|
98 | + */ |
|
99 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
100 | + { |
|
101 | + $answer_obj = $this->get_one(array( array( 'QST_ID' => $question_id, 'REG_ID' => $registration->ID() ))); |
|
102 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Gets the string answer to the question for this registration's attendee |
|
108 | - * |
|
109 | - * @param EE_Registration $registration |
|
110 | - * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string |
|
111 | - * then it should be its QST_system value. Passing in the QST_system |
|
112 | - * value is more efficient |
|
113 | - * @param boolean $pretty_answer |
|
114 | - * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or |
|
115 | - * QST_system for a question corresponding to an attendee field, returns |
|
116 | - * null) |
|
117 | - * @throws EE_Error |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
121 | - { |
|
122 | - $value = null; |
|
123 | - // backward compat: we still want to find the question's ID |
|
124 | - if (is_numeric($question_system_id)) { |
|
125 | - // find this question's QST_system value |
|
126 | - $question_id = $question_system_id; |
|
127 | - $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
128 | - } else { |
|
129 | - $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
130 | - } |
|
131 | - // only bother checking if the registration has an attendee |
|
132 | - if ($registration->attendee() instanceof EE_Attendee) { |
|
133 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
134 | - if ($field_name) { |
|
135 | - if ($pretty_answer) { |
|
136 | - if ($field_name === 'STA_ID') { |
|
137 | - $state = $registration->attendee()->state_obj(); |
|
138 | - $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
139 | - } elseif ($field_name === 'CNT_ISO') { |
|
140 | - $country = $registration->attendee()->country_obj(); |
|
141 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
142 | - } else { |
|
143 | - $value = $registration->attendee()->get_pretty($field_name); |
|
144 | - } |
|
145 | - // if field name is blank, leave the value as null too |
|
146 | - } else { |
|
147 | - $value = $registration->attendee()->get($field_name); |
|
148 | - } |
|
149 | - } |
|
150 | - // if no field was found, leave value blank |
|
151 | - } |
|
152 | - return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
153 | - } |
|
106 | + /** |
|
107 | + * Gets the string answer to the question for this registration's attendee |
|
108 | + * |
|
109 | + * @param EE_Registration $registration |
|
110 | + * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string |
|
111 | + * then it should be its QST_system value. Passing in the QST_system |
|
112 | + * value is more efficient |
|
113 | + * @param boolean $pretty_answer |
|
114 | + * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or |
|
115 | + * QST_system for a question corresponding to an attendee field, returns |
|
116 | + * null) |
|
117 | + * @throws EE_Error |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
121 | + { |
|
122 | + $value = null; |
|
123 | + // backward compat: we still want to find the question's ID |
|
124 | + if (is_numeric($question_system_id)) { |
|
125 | + // find this question's QST_system value |
|
126 | + $question_id = $question_system_id; |
|
127 | + $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
128 | + } else { |
|
129 | + $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
130 | + } |
|
131 | + // only bother checking if the registration has an attendee |
|
132 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
133 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
134 | + if ($field_name) { |
|
135 | + if ($pretty_answer) { |
|
136 | + if ($field_name === 'STA_ID') { |
|
137 | + $state = $registration->attendee()->state_obj(); |
|
138 | + $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
139 | + } elseif ($field_name === 'CNT_ISO') { |
|
140 | + $country = $registration->attendee()->country_obj(); |
|
141 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
142 | + } else { |
|
143 | + $value = $registration->attendee()->get_pretty($field_name); |
|
144 | + } |
|
145 | + // if field name is blank, leave the value as null too |
|
146 | + } else { |
|
147 | + $value = $registration->attendee()->get($field_name); |
|
148 | + } |
|
149 | + } |
|
150 | + // if no field was found, leave value blank |
|
151 | + } |
|
152 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
153 | + } |
|
154 | 154 | } |
@@ -152,10 +152,10 @@ |
||
152 | 152 | ]; |
153 | 153 | // this model is generally available for reading |
154 | 154 | $restrictions = []; |
155 | - $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
156 | - $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | - $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | - $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
155 | + $restrictions[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
156 | + $restrictions[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | + $restrictions[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | + $restrictions[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
159 | 159 | $this->_cap_restriction_generators = $restrictions; |
160 | 160 | parent::__construct($timezone); |
161 | 161 | $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
@@ -21,244 +21,244 @@ |
||
21 | 21 | */ |
22 | 22 | class EEM_Form_Section extends EEM_Base |
23 | 23 | { |
24 | - public const APPLIES_TO_ALL = 'all'; |
|
24 | + public const APPLIES_TO_ALL = 'all'; |
|
25 | 25 | |
26 | - public const APPLIES_TO_PRIMARY = 'primary'; |
|
26 | + public const APPLIES_TO_PRIMARY = 'primary'; |
|
27 | 27 | |
28 | - public const APPLIES_TO_PURCHASER = 'purchaser'; |
|
28 | + public const APPLIES_TO_PURCHASER = 'purchaser'; |
|
29 | 29 | |
30 | - public const APPLIES_TO_REGISTRANTS = 'registrants'; |
|
30 | + public const APPLIES_TO_REGISTRANTS = 'registrants'; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var EEM_Form_Section |
|
34 | - */ |
|
35 | - protected static $_instance; |
|
32 | + /** |
|
33 | + * @var EEM_Form_Section |
|
34 | + */ |
|
35 | + protected static $_instance; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var RequestInterface |
|
39 | - */ |
|
40 | - private $request; |
|
37 | + /** |
|
38 | + * @var RequestInterface |
|
39 | + */ |
|
40 | + private $request; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private $valid_applies_to_options; |
|
42 | + /** |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private $valid_applies_to_options; |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * EEM_Form_Section constructor. |
|
50 | - * |
|
51 | - * @param FormStatus $form_status |
|
52 | - * @param string|null $timezone |
|
53 | - * @throws EE_Error |
|
54 | - */ |
|
55 | - protected function __construct(FormStatus $form_status, ?string $timezone) |
|
56 | - { |
|
57 | - $this->valid_applies_to_options = apply_filters( |
|
58 | - 'FHEE__EEM_Form_Section__valid_applies_to_options', |
|
59 | - [ |
|
60 | - EEM_Form_Section::APPLIES_TO_ALL => esc_html__('All Registrants', 'event_espresso'), |
|
61 | - EEM_Form_Section::APPLIES_TO_PRIMARY => esc_html__('Primary Registrant Only', 'event_espresso'), |
|
62 | - EEM_Form_Section::APPLIES_TO_PURCHASER => esc_html__('Purchasing Agent', 'event_espresso'), |
|
63 | - EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'), |
|
64 | - ] |
|
65 | - ); |
|
48 | + /** |
|
49 | + * EEM_Form_Section constructor. |
|
50 | + * |
|
51 | + * @param FormStatus $form_status |
|
52 | + * @param string|null $timezone |
|
53 | + * @throws EE_Error |
|
54 | + */ |
|
55 | + protected function __construct(FormStatus $form_status, ?string $timezone) |
|
56 | + { |
|
57 | + $this->valid_applies_to_options = apply_filters( |
|
58 | + 'FHEE__EEM_Form_Section__valid_applies_to_options', |
|
59 | + [ |
|
60 | + EEM_Form_Section::APPLIES_TO_ALL => esc_html__('All Registrants', 'event_espresso'), |
|
61 | + EEM_Form_Section::APPLIES_TO_PRIMARY => esc_html__('Primary Registrant Only', 'event_espresso'), |
|
62 | + EEM_Form_Section::APPLIES_TO_PURCHASER => esc_html__('Purchasing Agent', 'event_espresso'), |
|
63 | + EEM_Form_Section::APPLIES_TO_REGISTRANTS => esc_html__('Additional Registrants', 'event_espresso'), |
|
64 | + ] |
|
65 | + ); |
|
66 | 66 | |
67 | - $this->singular_item = esc_html__('Form Section', 'event_espresso'); |
|
68 | - $this->plural_item = esc_html__('Form Sections', 'event_espresso'); |
|
67 | + $this->singular_item = esc_html__('Form Section', 'event_espresso'); |
|
68 | + $this->plural_item = esc_html__('Form Sections', 'event_espresso'); |
|
69 | 69 | |
70 | - $this->_tables = [ |
|
71 | - 'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'), |
|
72 | - ]; |
|
73 | - $this->_fields = [ |
|
74 | - 'Form_Section' => [ |
|
75 | - 'FSC_UUID' => new EE_Primary_Key_String_Field( |
|
76 | - 'FSC_UUID', |
|
77 | - esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso') |
|
78 | - ), |
|
79 | - 'FSC_appliesTo' => new EE_Enum_Text_Field( |
|
80 | - 'FSC_appliesTo', |
|
81 | - esc_html( |
|
82 | - sprintf( |
|
83 | - /* translators: 1 class name */ |
|
84 | - __( |
|
85 | - 'Form user type that this form section should be presented to. Values correspond to the %s constants.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - 'EEM_Form_Section::APPLIES_TO_*' |
|
89 | - ) |
|
90 | - ), |
|
91 | - false, |
|
92 | - EEM_Form_Section::APPLIES_TO_ALL, |
|
93 | - $this->valid_applies_to_options |
|
94 | - ), |
|
95 | - 'FSC_attributes' => new EE_JSON_Field( |
|
96 | - 'FSC_attributes', |
|
97 | - esc_html__( |
|
98 | - 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
99 | - 'event_espresso' |
|
100 | - ), |
|
101 | - false, |
|
102 | - '{}' |
|
103 | - ), |
|
104 | - 'FSC_belongsTo' => new EE_Plain_Text_Field( |
|
105 | - 'FSC_belongsTo', |
|
106 | - esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'), |
|
107 | - false, |
|
108 | - '' |
|
109 | - ), |
|
110 | - 'FSC_label' => new EE_JSON_Field( |
|
111 | - 'FSC_label', |
|
112 | - esc_html__( |
|
113 | - 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - false, |
|
117 | - '{}' |
|
118 | - ), |
|
119 | - 'FSC_order' => new EE_Integer_Field( |
|
120 | - 'FSC_order', |
|
121 | - esc_html__('Order in which form section appears in a form.', 'event_espresso'), |
|
122 | - false, |
|
123 | - 0 |
|
124 | - ), |
|
125 | - 'FSC_status' => new EE_Enum_Text_Field( |
|
126 | - 'FSC_status', |
|
127 | - esc_html( |
|
128 | - sprintf( |
|
129 | - /* translators: 1 class name */ |
|
130 | - __( |
|
131 | - 'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.', |
|
132 | - 'event_espresso' |
|
133 | - ), |
|
134 | - 'EventEspresso\core\services\form\meta\FormStatus' |
|
135 | - ) |
|
136 | - ), |
|
137 | - false, |
|
138 | - FormStatus::ACTIVE, |
|
139 | - $form_status->validStatusOptions() |
|
140 | - ), |
|
141 | - 'FSC_wpUser' => new EE_WP_User_Field( |
|
142 | - 'FSC_wpUser', |
|
143 | - esc_html__('ID of the WP User that created this form section.', 'event_espresso'), |
|
144 | - false |
|
145 | - ), |
|
146 | - ], |
|
147 | - ]; |
|
148 | - $this->_model_relations = [ |
|
149 | - 'Form_Element' => new EE_Has_Many_Relation(), |
|
150 | - 'Form_Submission' => new EE_Has_Many_Relation(), |
|
151 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
152 | - ]; |
|
153 | - // this model is generally available for reading |
|
154 | - $restrictions = []; |
|
155 | - $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
156 | - $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | - $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | - $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
159 | - $this->_cap_restriction_generators = $restrictions; |
|
160 | - parent::__construct($timezone); |
|
161 | - $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
162 | - } |
|
70 | + $this->_tables = [ |
|
71 | + 'Form_Section' => new EE_Primary_Table('esp_form_section', 'FSC_UUID'), |
|
72 | + ]; |
|
73 | + $this->_fields = [ |
|
74 | + 'Form_Section' => [ |
|
75 | + 'FSC_UUID' => new EE_Primary_Key_String_Field( |
|
76 | + 'FSC_UUID', |
|
77 | + esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso') |
|
78 | + ), |
|
79 | + 'FSC_appliesTo' => new EE_Enum_Text_Field( |
|
80 | + 'FSC_appliesTo', |
|
81 | + esc_html( |
|
82 | + sprintf( |
|
83 | + /* translators: 1 class name */ |
|
84 | + __( |
|
85 | + 'Form user type that this form section should be presented to. Values correspond to the %s constants.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + 'EEM_Form_Section::APPLIES_TO_*' |
|
89 | + ) |
|
90 | + ), |
|
91 | + false, |
|
92 | + EEM_Form_Section::APPLIES_TO_ALL, |
|
93 | + $this->valid_applies_to_options |
|
94 | + ), |
|
95 | + 'FSC_attributes' => new EE_JSON_Field( |
|
96 | + 'FSC_attributes', |
|
97 | + esc_html__( |
|
98 | + 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
99 | + 'event_espresso' |
|
100 | + ), |
|
101 | + false, |
|
102 | + '{}' |
|
103 | + ), |
|
104 | + 'FSC_belongsTo' => new EE_Plain_Text_Field( |
|
105 | + 'FSC_belongsTo', |
|
106 | + esc_html__('UUID of parent form section that this one belongs to.', 'event_espresso'), |
|
107 | + false, |
|
108 | + '' |
|
109 | + ), |
|
110 | + 'FSC_label' => new EE_JSON_Field( |
|
111 | + 'FSC_label', |
|
112 | + esc_html__( |
|
113 | + 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + false, |
|
117 | + '{}' |
|
118 | + ), |
|
119 | + 'FSC_order' => new EE_Integer_Field( |
|
120 | + 'FSC_order', |
|
121 | + esc_html__('Order in which form section appears in a form.', 'event_espresso'), |
|
122 | + false, |
|
123 | + 0 |
|
124 | + ), |
|
125 | + 'FSC_status' => new EE_Enum_Text_Field( |
|
126 | + 'FSC_status', |
|
127 | + esc_html( |
|
128 | + sprintf( |
|
129 | + /* translators: 1 class name */ |
|
130 | + __( |
|
131 | + 'Whether form section is active, archived, shared, trashed, or used as a default on new forms. Values correspond to the %1$s class constants.', |
|
132 | + 'event_espresso' |
|
133 | + ), |
|
134 | + 'EventEspresso\core\services\form\meta\FormStatus' |
|
135 | + ) |
|
136 | + ), |
|
137 | + false, |
|
138 | + FormStatus::ACTIVE, |
|
139 | + $form_status->validStatusOptions() |
|
140 | + ), |
|
141 | + 'FSC_wpUser' => new EE_WP_User_Field( |
|
142 | + 'FSC_wpUser', |
|
143 | + esc_html__('ID of the WP User that created this form section.', 'event_espresso'), |
|
144 | + false |
|
145 | + ), |
|
146 | + ], |
|
147 | + ]; |
|
148 | + $this->_model_relations = [ |
|
149 | + 'Form_Element' => new EE_Has_Many_Relation(), |
|
150 | + 'Form_Submission' => new EE_Has_Many_Relation(), |
|
151 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
152 | + ]; |
|
153 | + // this model is generally available for reading |
|
154 | + $restrictions = []; |
|
155 | + $restrictions[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
156 | + $restrictions[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
157 | + $restrictions[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
158 | + $restrictions[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('FSC_applies_to'); |
|
159 | + $this->_cap_restriction_generators = $restrictions; |
|
160 | + parent::__construct($timezone); |
|
161 | + $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | - /** |
|
166 | - * @param array $query_params |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - private function addDefaultWhereConditions(array $query_params): array |
|
170 | - { |
|
171 | - // might need to add a way to identify GQL requests for admin domains |
|
172 | - $admin_request = $this->request->isAdmin() || $this->request->isAdminAjax(); |
|
173 | - $query_params['default_where_conditions'] = $admin_request |
|
174 | - ? EEM_Base::default_where_conditions_none |
|
175 | - : EEM_Base::default_where_conditions_all; |
|
176 | - return $query_params; |
|
177 | - } |
|
165 | + /** |
|
166 | + * @param array $query_params |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + private function addDefaultWhereConditions(array $query_params): array |
|
170 | + { |
|
171 | + // might need to add a way to identify GQL requests for admin domains |
|
172 | + $admin_request = $this->request->isAdmin() || $this->request->isAdminAjax(); |
|
173 | + $query_params['default_where_conditions'] = $admin_request |
|
174 | + ? EEM_Base::default_where_conditions_none |
|
175 | + : EEM_Base::default_where_conditions_all; |
|
176 | + return $query_params; |
|
177 | + } |
|
178 | 178 | |
179 | 179 | |
180 | - /** |
|
181 | - * form sections should always be sorted in ascending order via the FSC_order field |
|
182 | - * |
|
183 | - * @param array $query_params |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - private function addOrderByQueryParams(array $query_params): array |
|
187 | - { |
|
188 | - $query_params['order_by'] = ['FSC_order' => 'ASC']; |
|
189 | - return $query_params; |
|
190 | - } |
|
180 | + /** |
|
181 | + * form sections should always be sorted in ascending order via the FSC_order field |
|
182 | + * |
|
183 | + * @param array $query_params |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + private function addOrderByQueryParams(array $query_params): array |
|
187 | + { |
|
188 | + $query_params['order_by'] = ['FSC_order' => 'ASC']; |
|
189 | + return $query_params; |
|
190 | + } |
|
191 | 191 | |
192 | 192 | |
193 | - /** |
|
194 | - * returns an array of Form Sections that should be added by default to new Events |
|
195 | - * |
|
196 | - * @return EE_Form_Section[] |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - public function getDefaultFormSections(): array |
|
200 | - { |
|
201 | - return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]); |
|
202 | - } |
|
193 | + /** |
|
194 | + * returns an array of Form Sections that should be added by default to new Events |
|
195 | + * |
|
196 | + * @return EE_Form_Section[] |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + public function getDefaultFormSections(): array |
|
200 | + { |
|
201 | + return $this->getFormSections(['FSC_status' => FormStatus::DEFAULT]); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - /** |
|
206 | - * returns an array of Form Sections for the specified parent Form Section |
|
207 | - * |
|
208 | - * @param string $FSC_UUID |
|
209 | - * @return EE_Form_Section[] |
|
210 | - * @throws EE_Error |
|
211 | - */ |
|
212 | - public function getChildFormSections(string $FSC_UUID): array |
|
213 | - { |
|
214 | - return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]); |
|
215 | - } |
|
205 | + /** |
|
206 | + * returns an array of Form Sections for the specified parent Form Section |
|
207 | + * |
|
208 | + * @param string $FSC_UUID |
|
209 | + * @return EE_Form_Section[] |
|
210 | + * @throws EE_Error |
|
211 | + */ |
|
212 | + public function getChildFormSections(string $FSC_UUID): array |
|
213 | + { |
|
214 | + return $this->getFormSections(['FSC_belongsTo' => $FSC_UUID]); |
|
215 | + } |
|
216 | 216 | |
217 | 217 | |
218 | - /** |
|
219 | - * @return EE_Form_Section[] |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function getFormSections(array $where_params): array |
|
223 | - { |
|
224 | - $query_params = $this->addDefaultWhereConditions([$where_params]); |
|
225 | - $query_params = $this->addOrderByQueryParams($query_params); |
|
226 | - return $this->get_all($query_params); |
|
227 | - } |
|
218 | + /** |
|
219 | + * @return EE_Form_Section[] |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function getFormSections(array $where_params): array |
|
223 | + { |
|
224 | + $query_params = $this->addDefaultWhereConditions([$where_params]); |
|
225 | + $query_params = $this->addOrderByQueryParams($query_params); |
|
226 | + return $this->get_all($query_params); |
|
227 | + } |
|
228 | 228 | |
229 | 229 | |
230 | - /** |
|
231 | - * returns an array of Form Sections for the specified Event |
|
232 | - * |
|
233 | - * @param EE_Event $event |
|
234 | - * @return EE_Form_Section[] |
|
235 | - * @throws EE_Error |
|
236 | - * @throws ReflectionException |
|
237 | - */ |
|
238 | - public function getFormSectionsForEvent(EE_Event $event): array |
|
239 | - { |
|
240 | - $FSC_UUID = $event->registrationFormUuid(); |
|
241 | - return ! empty($FSC_UUID) |
|
242 | - ? $this->getFormSections( |
|
243 | - [ |
|
244 | - 'OR' => [ |
|
245 | - 'FSC_UUID' => $FSC_UUID, // top level form |
|
246 | - 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
247 | - ] |
|
248 | - ] |
|
249 | - ) |
|
250 | - : []; |
|
251 | - } |
|
230 | + /** |
|
231 | + * returns an array of Form Sections for the specified Event |
|
232 | + * |
|
233 | + * @param EE_Event $event |
|
234 | + * @return EE_Form_Section[] |
|
235 | + * @throws EE_Error |
|
236 | + * @throws ReflectionException |
|
237 | + */ |
|
238 | + public function getFormSectionsForEvent(EE_Event $event): array |
|
239 | + { |
|
240 | + $FSC_UUID = $event->registrationFormUuid(); |
|
241 | + return ! empty($FSC_UUID) |
|
242 | + ? $this->getFormSections( |
|
243 | + [ |
|
244 | + 'OR' => [ |
|
245 | + 'FSC_UUID' => $FSC_UUID, // top level form |
|
246 | + 'FSC_belongsTo' => $FSC_UUID, // child form sections |
|
247 | + ] |
|
248 | + ] |
|
249 | + ) |
|
250 | + : []; |
|
251 | + } |
|
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @param bool $constants_only |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function validAppliesToOptions(bool $constants_only = false): array |
|
259 | - { |
|
260 | - return $constants_only |
|
261 | - ? array_keys($this->valid_applies_to_options) |
|
262 | - : $this->valid_applies_to_options; |
|
263 | - } |
|
254 | + /** |
|
255 | + * @param bool $constants_only |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function validAppliesToOptions(bool $constants_only = false): array |
|
259 | + { |
|
260 | + return $constants_only |
|
261 | + ? array_keys($this->valid_applies_to_options) |
|
262 | + : $this->valid_applies_to_options; |
|
263 | + } |
|
264 | 264 | } |
@@ -14,122 +14,122 @@ |
||
14 | 14 | */ |
15 | 15 | class FormElementConnectionResolver extends AbstractConnectionResolver |
16 | 16 | { |
17 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | - public function get_loader_name(): string |
|
19 | - { |
|
20 | - return 'espresso_formElement'; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @return EEM_Form_Element |
|
25 | - * @throws EE_Error |
|
26 | - * @throws InvalidArgumentException |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | - public function get_query(): EEM_Form_Element |
|
33 | - { |
|
34 | - return EEM_Form_Element::instance(); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Return an array of item IDs from the query |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | - public function get_ids(): array |
|
45 | - { |
|
46 | - $results = $this->query->get_col($this->query_args); |
|
47 | - return ! empty($results) ? $results : []; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
53 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
54 | - * handle batch resolution of the posts. |
|
55 | - * |
|
56 | - * @return array |
|
57 | - * @throws InvalidArgumentException |
|
58 | - * @throws InvalidDataTypeException |
|
59 | - * @throws InvalidInterfaceException |
|
60 | - */ |
|
61 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | - public function get_query_args(): array |
|
63 | - { |
|
64 | - $where_params = []; |
|
65 | - $query_args = []; |
|
66 | - |
|
67 | - $query_args['limit'] = $this->getLimit(); |
|
68 | - |
|
69 | - // Avoid multiple entries by join. |
|
70 | - $query_args['group_by'] = 'FIN_UUID'; |
|
71 | - |
|
72 | - /** |
|
73 | - * Collect the input fields and sanitize them to prepare them for sending to the Query |
|
74 | - */ |
|
75 | - $input_fields = []; |
|
76 | - if (! empty($this->args['where'])) { |
|
77 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
78 | - |
|
79 | - // Use the proper operator. |
|
80 | - if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | - $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
|
82 | - } |
|
83 | - if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | - $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Merge the input_fields with the default query_args |
|
90 | - */ |
|
91 | - if (! empty($input_fields)) { |
|
92 | - $where_params = array_merge($where_params, $input_fields); |
|
93 | - } |
|
94 | - |
|
95 | - $where_params = apply_filters( |
|
96 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_where_params', |
|
97 | - $where_params, |
|
98 | - $this->source, |
|
99 | - $this->args |
|
100 | - ); |
|
101 | - |
|
102 | - if (! empty($where_params)) { |
|
103 | - $query_args[] = $where_params; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Return the $query_args |
|
109 | - */ |
|
110 | - return apply_filters( |
|
111 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_query_args', |
|
112 | - $query_args, |
|
113 | - $this->source, |
|
114 | - $this->args |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
120 | - * friendly keys. |
|
121 | - * |
|
122 | - * @param array $where_args |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function sanitizeInputFields(array $where_args): array |
|
126 | - { |
|
127 | - return $this->sanitizeWhereArgsForInputFields( |
|
128 | - $where_args, |
|
129 | - [ |
|
130 | - 'belongsTo' => 'FSC_UUID', |
|
131 | - 'status' => 'FIN_status', |
|
132 | - ] |
|
133 | - ); |
|
134 | - } |
|
17 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
18 | + public function get_loader_name(): string |
|
19 | + { |
|
20 | + return 'espresso_formElement'; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @return EEM_Form_Element |
|
25 | + * @throws EE_Error |
|
26 | + * @throws InvalidArgumentException |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | + public function get_query(): EEM_Form_Element |
|
33 | + { |
|
34 | + return EEM_Form_Element::instance(); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Return an array of item IDs from the query |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
44 | + public function get_ids(): array |
|
45 | + { |
|
46 | + $results = $this->query->get_col($this->query_args); |
|
47 | + return ! empty($results) ? $results : []; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
53 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
54 | + * handle batch resolution of the posts. |
|
55 | + * |
|
56 | + * @return array |
|
57 | + * @throws InvalidArgumentException |
|
58 | + * @throws InvalidDataTypeException |
|
59 | + * @throws InvalidInterfaceException |
|
60 | + */ |
|
61 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
62 | + public function get_query_args(): array |
|
63 | + { |
|
64 | + $where_params = []; |
|
65 | + $query_args = []; |
|
66 | + |
|
67 | + $query_args['limit'] = $this->getLimit(); |
|
68 | + |
|
69 | + // Avoid multiple entries by join. |
|
70 | + $query_args['group_by'] = 'FIN_UUID'; |
|
71 | + |
|
72 | + /** |
|
73 | + * Collect the input fields and sanitize them to prepare them for sending to the Query |
|
74 | + */ |
|
75 | + $input_fields = []; |
|
76 | + if (! empty($this->args['where'])) { |
|
77 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
78 | + |
|
79 | + // Use the proper operator. |
|
80 | + if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | + $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
|
82 | + } |
|
83 | + if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | + $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Merge the input_fields with the default query_args |
|
90 | + */ |
|
91 | + if (! empty($input_fields)) { |
|
92 | + $where_params = array_merge($where_params, $input_fields); |
|
93 | + } |
|
94 | + |
|
95 | + $where_params = apply_filters( |
|
96 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_where_params', |
|
97 | + $where_params, |
|
98 | + $this->source, |
|
99 | + $this->args |
|
100 | + ); |
|
101 | + |
|
102 | + if (! empty($where_params)) { |
|
103 | + $query_args[] = $where_params; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Return the $query_args |
|
109 | + */ |
|
110 | + return apply_filters( |
|
111 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__form_element_query_args', |
|
112 | + $query_args, |
|
113 | + $this->source, |
|
114 | + $this->args |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
120 | + * friendly keys. |
|
121 | + * |
|
122 | + * @param array $where_args |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function sanitizeInputFields(array $where_args): array |
|
126 | + { |
|
127 | + return $this->sanitizeWhereArgsForInputFields( |
|
128 | + $where_args, |
|
129 | + [ |
|
130 | + 'belongsTo' => 'FSC_UUID', |
|
131 | + 'status' => 'FIN_status', |
|
132 | + ] |
|
133 | + ); |
|
134 | + } |
|
135 | 135 | } |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | * Collect the input fields and sanitize them to prepare them for sending to the Query |
74 | 74 | */ |
75 | 75 | $input_fields = []; |
76 | - if (! empty($this->args['where'])) { |
|
76 | + if ( ! empty($this->args['where'])) { |
|
77 | 77 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
78 | 78 | |
79 | 79 | // Use the proper operator. |
80 | - if (! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
80 | + if ( ! empty($input_fields['FSC_UUID']) && is_array($input_fields['FSC_UUID'])) { |
|
81 | 81 | $input_fields['FSC_UUID'] = ['IN', $input_fields['FSC_UUID']]; |
82 | 82 | } |
83 | - if (! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
83 | + if ( ! empty($input_fields['FIN_status']) && is_array($input_fields['FIN_status'])) { |
|
84 | 84 | $input_fields['FIN_status'] = ['IN', $input_fields['FIN_status']]; |
85 | 85 | } |
86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | /** |
89 | 89 | * Merge the input_fields with the default query_args |
90 | 90 | */ |
91 | - if (! empty($input_fields)) { |
|
91 | + if ( ! empty($input_fields)) { |
|
92 | 92 | $where_params = array_merge($where_params, $input_fields); |
93 | 93 | } |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->args |
100 | 100 | ); |
101 | 101 | |
102 | - if (! empty($where_params)) { |
|
102 | + if ( ! empty($where_params)) { |
|
103 | 103 | $query_args[] = $where_params; |
104 | 104 | } |
105 | 105 |
@@ -11,48 +11,48 @@ |
||
11 | 11 | class FormElementDelete extends EntityMutator |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Defines the mutation data modification closure. |
|
16 | - * |
|
17 | - * @param EEM_Form_Element $model |
|
18 | - * @return callable |
|
19 | - */ |
|
20 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Deletes an entity. |
|
24 | - * |
|
25 | - * @param array $input The input for the mutation |
|
26 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | - try { |
|
32 | - /** @var EE_Form_Element $entity */ |
|
33 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
14 | + /** |
|
15 | + * Defines the mutation data modification closure. |
|
16 | + * |
|
17 | + * @param EEM_Form_Element $model |
|
18 | + * @return callable |
|
19 | + */ |
|
20 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Deletes an entity. |
|
24 | + * |
|
25 | + * @param array $input The input for the mutation |
|
26 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
27 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | + try { |
|
32 | + /** @var EE_Form_Element $entity */ |
|
33 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
34 | 34 | |
35 | - $result = $entity->delete(); |
|
36 | - EntityMutator::validateResults($result); |
|
35 | + $result = $entity->delete(); |
|
36 | + EntityMutator::validateResults($result); |
|
37 | 37 | |
38 | - do_action( |
|
39 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | - $entity, |
|
41 | - $input |
|
42 | - ); |
|
43 | - } catch (Exception $exception) { |
|
44 | - EntityMutator::handleExceptions( |
|
45 | - $exception, |
|
46 | - esc_html__( |
|
47 | - 'The form element could not be deleted because of the following error(s)', |
|
48 | - 'event_espresso' |
|
49 | - ) |
|
50 | - ); |
|
51 | - } |
|
38 | + do_action( |
|
39 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_delete', |
|
40 | + $entity, |
|
41 | + $input |
|
42 | + ); |
|
43 | + } catch (Exception $exception) { |
|
44 | + EntityMutator::handleExceptions( |
|
45 | + $exception, |
|
46 | + esc_html__( |
|
47 | + 'The form element could not be deleted because of the following error(s)', |
|
48 | + 'event_espresso' |
|
49 | + ) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - return [ |
|
54 | - 'deleted' => $entity, |
|
55 | - ]; |
|
56 | - }; |
|
57 | - } |
|
53 | + return [ |
|
54 | + 'deleted' => $entity, |
|
55 | + ]; |
|
56 | + }; |
|
57 | + } |
|
58 | 58 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
30 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
31 | 31 | try { |
32 | 32 | /** @var EE_Form_Element $entity */ |
33 | 33 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -12,51 +12,51 @@ |
||
12 | 12 | class FormElementCreate extends EntityMutator |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Defines the mutation data modification closure. |
|
17 | - * |
|
18 | - * @param EEM_Form_Element $model |
|
19 | - * @return callable |
|
20 | - */ |
|
21 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
22 | - { |
|
23 | - /** |
|
24 | - * Creates an entity. |
|
25 | - * |
|
26 | - * @param array $input The input for the mutation |
|
27 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
28 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | - $id = null; |
|
33 | - try { |
|
34 | - EntityMutator::checkPermissions($model); |
|
35 | - |
|
36 | - $args = FormElementMutation::prepareFields($input); |
|
37 | - |
|
38 | - $entity = EE_Form_Element::new_instance($args); |
|
39 | - $id = $entity->save(); |
|
40 | - EntityMutator::validateResults($id); |
|
41 | - |
|
42 | - do_action( |
|
43 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
44 | - $entity, |
|
45 | - $input |
|
46 | - ); |
|
47 | - } catch (Exception $exception) { |
|
48 | - EntityMutator::handleExceptions( |
|
49 | - $exception, |
|
50 | - esc_html__( |
|
51 | - 'The form element could not be created because of the following error(s)', |
|
52 | - 'event_espresso' |
|
53 | - ) |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - return [ |
|
58 | - 'id' => $id, |
|
59 | - ]; |
|
60 | - }; |
|
61 | - } |
|
15 | + /** |
|
16 | + * Defines the mutation data modification closure. |
|
17 | + * |
|
18 | + * @param EEM_Form_Element $model |
|
19 | + * @return callable |
|
20 | + */ |
|
21 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
22 | + { |
|
23 | + /** |
|
24 | + * Creates an entity. |
|
25 | + * |
|
26 | + * @param array $input The input for the mutation |
|
27 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
28 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + $id = null; |
|
33 | + try { |
|
34 | + EntityMutator::checkPermissions($model); |
|
35 | + |
|
36 | + $args = FormElementMutation::prepareFields($input); |
|
37 | + |
|
38 | + $entity = EE_Form_Element::new_instance($args); |
|
39 | + $id = $entity->save(); |
|
40 | + EntityMutator::validateResults($id); |
|
41 | + |
|
42 | + do_action( |
|
43 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_create', |
|
44 | + $entity, |
|
45 | + $input |
|
46 | + ); |
|
47 | + } catch (Exception $exception) { |
|
48 | + EntityMutator::handleExceptions( |
|
49 | + $exception, |
|
50 | + esc_html__( |
|
51 | + 'The form element could not be created because of the following error(s)', |
|
52 | + 'event_espresso' |
|
53 | + ) |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + return [ |
|
58 | + 'id' => $id, |
|
59 | + ]; |
|
60 | + }; |
|
61 | + } |
|
62 | 62 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
32 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
33 | 33 | $id = null; |
34 | 34 | try { |
35 | 35 | EntityMutator::checkPermissions($model); |
@@ -14,52 +14,52 @@ |
||
14 | 14 | class FormElementUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Form_Element $model |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Updates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - * @throws EE_Error |
|
33 | - * @throws ReflectionException |
|
34 | - */ |
|
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | - try { |
|
37 | - /** @var EE_Form_Element $entity */ |
|
38 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Form_Element $model |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Form_Element $model) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Updates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + * @throws EE_Error |
|
33 | + * @throws ReflectionException |
|
34 | + */ |
|
35 | + return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | + try { |
|
37 | + /** @var EE_Form_Element $entity */ |
|
38 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
39 | 39 | |
40 | - $args = FormElementMutation::prepareFields($input); |
|
40 | + $args = FormElementMutation::prepareFields($input); |
|
41 | 41 | |
42 | - // Update the entity |
|
43 | - $entity->save($args); |
|
42 | + // Update the entity |
|
43 | + $entity->save($args); |
|
44 | 44 | |
45 | - do_action( |
|
46 | - 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | - $entity, |
|
48 | - $input |
|
49 | - ); |
|
50 | - } catch (Exception $exception) { |
|
51 | - EntityMutator::handleExceptions( |
|
52 | - $exception, |
|
53 | - esc_html__( |
|
54 | - 'The form element could not be updated because of the following error(s)', |
|
55 | - 'event_espresso' |
|
56 | - ) |
|
57 | - ); |
|
58 | - } |
|
45 | + do_action( |
|
46 | + 'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_element_update', |
|
47 | + $entity, |
|
48 | + $input |
|
49 | + ); |
|
50 | + } catch (Exception $exception) { |
|
51 | + EntityMutator::handleExceptions( |
|
52 | + $exception, |
|
53 | + esc_html__( |
|
54 | + 'The form element could not be updated because of the following error(s)', |
|
55 | + 'event_espresso' |
|
56 | + ) |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - return [ |
|
61 | - 'id' => $entity->UUID(), |
|
62 | - ]; |
|
63 | - }; |
|
64 | - } |
|
60 | + return [ |
|
61 | + 'id' => $entity->UUID(), |
|
62 | + ]; |
|
63 | + }; |
|
64 | + } |
|
65 | 65 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @throws EE_Error |
33 | 33 | * @throws ReflectionException |
34 | 34 | */ |
35 | - return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
35 | + return static function(array $input, AppContext $context, ResolveInfo $info) use ($model): array { |
|
36 | 36 | try { |
37 | 37 | /** @var EE_Form_Element $entity */ |
38 | 38 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -49,7 +49,7 @@ |
||
49 | 49 | $args['FSC_status'] = sanitize_text_field($input['status']); |
50 | 50 | } |
51 | 51 | |
52 | - if (! empty($input['wpUser'])) { |
|
52 | + if ( ! empty($input['wpUser'])) { |
|
53 | 53 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
54 | 54 | $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
55 | 55 | } |
@@ -15,54 +15,54 @@ |
||
15 | 15 | class FormSectionMutation |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Maps the GraphQL input to a format that the model functions can use |
|
20 | - * |
|
21 | - * @param array $input Data coming from the GraphQL mutation query input |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public static function prepareFields(array $input): array |
|
25 | - { |
|
26 | - $args = []; |
|
18 | + /** |
|
19 | + * Maps the GraphQL input to a format that the model functions can use |
|
20 | + * |
|
21 | + * @param array $input Data coming from the GraphQL mutation query input |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public static function prepareFields(array $input): array |
|
25 | + { |
|
26 | + $args = []; |
|
27 | 27 | |
28 | - if (isset($input['id'])) { |
|
29 | - $args['FSC_UUID'] = sanitize_text_field($input['id']); |
|
30 | - } |
|
28 | + if (isset($input['id'])) { |
|
29 | + $args['FSC_UUID'] = sanitize_text_field($input['id']); |
|
30 | + } |
|
31 | 31 | |
32 | - if (isset($input['appliesTo'])) { |
|
33 | - $args['FSC_appliesTo'] = sanitize_text_field($input['appliesTo']); |
|
34 | - } |
|
32 | + if (isset($input['appliesTo'])) { |
|
33 | + $args['FSC_appliesTo'] = sanitize_text_field($input['appliesTo']); |
|
34 | + } |
|
35 | 35 | |
36 | - if (isset($input['attributes'])) { |
|
37 | - $args['FSC_attributes'] = Attributes::fromJson(sanitize_text_field($input['attributes']))->toJson(); |
|
38 | - } |
|
36 | + if (isset($input['attributes'])) { |
|
37 | + $args['FSC_attributes'] = Attributes::fromJson(sanitize_text_field($input['attributes']))->toJson(); |
|
38 | + } |
|
39 | 39 | |
40 | - if (isset($input['belongsTo'])) { |
|
41 | - $args['FSC_belongsTo'] = sanitize_text_field($input['belongsTo']); |
|
42 | - } |
|
40 | + if (isset($input['belongsTo'])) { |
|
41 | + $args['FSC_belongsTo'] = sanitize_text_field($input['belongsTo']); |
|
42 | + } |
|
43 | 43 | |
44 | - if (isset($input['label'])) { |
|
45 | - $args['FSC_label'] = FormLabel::fromJson(sanitize_text_field($input['label']))->toJson(); |
|
46 | - } |
|
44 | + if (isset($input['label'])) { |
|
45 | + $args['FSC_label'] = FormLabel::fromJson(sanitize_text_field($input['label']))->toJson(); |
|
46 | + } |
|
47 | 47 | |
48 | - // order can be 0 |
|
49 | - if (array_key_exists('order', $input)) { |
|
50 | - $args['FSC_order'] = absint($input['order']); |
|
51 | - } |
|
48 | + // order can be 0 |
|
49 | + if (array_key_exists('order', $input)) { |
|
50 | + $args['FSC_order'] = absint($input['order']); |
|
51 | + } |
|
52 | 52 | |
53 | - if (isset($input['status'])) { |
|
54 | - $args['FSC_status'] = sanitize_text_field($input['status']); |
|
55 | - } |
|
53 | + if (isset($input['status'])) { |
|
54 | + $args['FSC_status'] = sanitize_text_field($input['status']); |
|
55 | + } |
|
56 | 56 | |
57 | - if (! empty($input['wpUser'])) { |
|
58 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
59 | - $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
60 | - } |
|
57 | + if (! empty($input['wpUser'])) { |
|
58 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
59 | + $args['FSC_wpUser'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
60 | + } |
|
61 | 61 | |
62 | - return apply_filters( |
|
63 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__form_section_args', |
|
64 | - $args, |
|
65 | - $input |
|
66 | - ); |
|
67 | - } |
|
62 | + return apply_filters( |
|
63 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__form_section_args', |
|
64 | + $args, |
|
65 | + $input |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | } |
@@ -15,27 +15,27 @@ |
||
15 | 15 | */ |
16 | 16 | class FormElementLoader extends AbstractLoader |
17 | 17 | { |
18 | - /** |
|
19 | - * @return EEM_Base |
|
20 | - * @throws EE_Error |
|
21 | - * @throws InvalidArgumentException |
|
22 | - * @throws InvalidDataTypeException |
|
23 | - * @throws InvalidInterfaceException |
|
24 | - * @throws ReflectionException |
|
25 | - */ |
|
26 | - protected function getQuery(): EEM_Base |
|
27 | - { |
|
28 | - return EEM_Form_Element::instance(); |
|
29 | - } |
|
18 | + /** |
|
19 | + * @return EEM_Base |
|
20 | + * @throws EE_Error |
|
21 | + * @throws InvalidArgumentException |
|
22 | + * @throws InvalidDataTypeException |
|
23 | + * @throws InvalidInterfaceException |
|
24 | + * @throws ReflectionException |
|
25 | + */ |
|
26 | + protected function getQuery(): EEM_Base |
|
27 | + { |
|
28 | + return EEM_Form_Element::instance(); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param array $keys |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - protected function getWhereParams(array $keys): array |
|
36 | - { |
|
37 | - return [ |
|
38 | - 'FIN_UUID' => ['IN', $keys], |
|
39 | - ]; |
|
40 | - } |
|
31 | + /** |
|
32 | + * @param array $keys |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + protected function getWhereParams(array $keys): array |
|
36 | + { |
|
37 | + return [ |
|
38 | + 'FIN_UUID' => ['IN', $keys], |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | } |
@@ -19,28 +19,28 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param $entity |
|
24 | - * @param $args |
|
25 | - * @param $context |
|
26 | - * @param $info |
|
27 | - * @return AbstractConnectionResolver |
|
28 | - * @throws Exception |
|
29 | - */ |
|
30 | - abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
22 | + /** |
|
23 | + * @param $entity |
|
24 | + * @param $args |
|
25 | + * @param $context |
|
26 | + * @param $info |
|
27 | + * @return AbstractConnectionResolver |
|
28 | + * @throws Exception |
|
29 | + */ |
|
30 | + abstract public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @param $entity |
|
35 | - * @param $args |
|
36 | - * @param $context |
|
37 | - * @param $info |
|
38 | - * @return mixed|array|Deferred |
|
39 | - * @throws Exception |
|
40 | - */ |
|
41 | - public function resolveConnection($entity, $args, $context, $info) |
|
42 | - { |
|
43 | - $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
44 | - return $resolver->get_connection(); |
|
45 | - } |
|
33 | + /** |
|
34 | + * @param $entity |
|
35 | + * @param $args |
|
36 | + * @param $context |
|
37 | + * @param $info |
|
38 | + * @return mixed|array|Deferred |
|
39 | + * @throws Exception |
|
40 | + */ |
|
41 | + public function resolveConnection($entity, $args, $context, $info) |
|
42 | + { |
|
43 | + $resolver = $this->getConnectionResolver($entity, $args, $context, $info); |
|
44 | + return $resolver->get_connection(); |
|
45 | + } |
|
46 | 46 | } |