Completed
Pull Request — master (#964)
by
unknown
08:43
created
registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -15,168 +15,168 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Registration_Custom_Questions_Form extends EE_Form_Section_Proper
17 17
 {
18
-    /**
19
-     *
20
-     * @var EE_Registration
21
-     */
22
-    protected $_registration = null;
18
+	/**
19
+	 *
20
+	 * @var EE_Registration
21
+	 */
22
+	protected $_registration = null;
23 23
 
24
-    /**
25
-     *
26
-     * @param EE_Registration $reg
27
-     * @param array $options
28
-     */
29
-    public function __construct(EE_Registration $reg, $options = array())
30
-    {
31
-        $this->_registration = $reg;
32
-        if (! isset($options['layout_strategy'])) {
33
-            $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34
-        }
35
-        if (! isset($options['html_id'])) {
36
-            $options['html_id'] = 'reg-admin-attendee-questions-frm';
37
-        }
38
-        $this->build_form_from_registration();
39
-        parent::__construct($options);
40
-    }
24
+	/**
25
+	 *
26
+	 * @param EE_Registration $reg
27
+	 * @param array $options
28
+	 */
29
+	public function __construct(EE_Registration $reg, $options = array())
30
+	{
31
+		$this->_registration = $reg;
32
+		if (! isset($options['layout_strategy'])) {
33
+			$options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34
+		}
35
+		if (! isset($options['html_id'])) {
36
+			$options['html_id'] = 'reg-admin-attendee-questions-frm';
37
+		}
38
+		$this->build_form_from_registration();
39
+		parent::__construct($options);
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Gets the registration object this form is about
45
-     * @return EE_Registration
46
-     */
47
-    public function get_registration()
48
-    {
49
-        return $this->_registration;
50
-    }
43
+	/**
44
+	 * Gets the registration object this form is about
45
+	 * @return EE_Registration
46
+	 */
47
+	public function get_registration()
48
+	{
49
+		return $this->_registration;
50
+	}
51 51
 
52
-    public function build_form_from_registration()
53
-    {
54
-        $reg = $this->get_registration();
55
-        if (! $reg instanceof EE_Registration) {
56
-            throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57
-        }
58
-        // we want to get all their question groups
59
-        $question_groups = EEM_Question_Group::instance()->get_all(
60
-            array(
61
-                array(
62
-                    'Event_Question_Group.EVT_ID' => $reg->event_ID(),
63
-                    'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64
-                    'OR' => array(
65
-                        'Question.QST_system*blank' =>  '',
66
-                        'Question.QST_system*null' => array( 'IS_NULL' )
67
-                    )
68
-                ),
69
-                'order_by' => array( 'QSG_order' => 'ASC' )
70
-            )
71
-        );
72
-        // get each question groups questions
73
-        foreach ($question_groups as $question_group) {
74
-            if ($question_group instanceof EE_Question_Group) {
75
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
76
-                    $question_group,
77
-                    $reg
78
-                );
79
-            }
80
-        }
81
-    }
52
+	public function build_form_from_registration()
53
+	{
54
+		$reg = $this->get_registration();
55
+		if (! $reg instanceof EE_Registration) {
56
+			throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57
+		}
58
+		// we want to get all their question groups
59
+		$question_groups = EEM_Question_Group::instance()->get_all(
60
+			array(
61
+				array(
62
+					'Event_Question_Group.EVT_ID' => $reg->event_ID(),
63
+					'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64
+					'OR' => array(
65
+						'Question.QST_system*blank' =>  '',
66
+						'Question.QST_system*null' => array( 'IS_NULL' )
67
+					)
68
+				),
69
+				'order_by' => array( 'QSG_order' => 'ASC' )
70
+			)
71
+		);
72
+		// get each question groups questions
73
+		foreach ($question_groups as $question_group) {
74
+			if ($question_group instanceof EE_Question_Group) {
75
+				$this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
76
+					$question_group,
77
+					$reg
78
+				);
79
+			}
80
+		}
81
+	}
82 82
 
83 83
 
84 84
 
85
-    /**
86
-     *
87
-     * @param EE_Question_Group $question_group
88
-     * @param EE_Registration   $registration
89
-     * @return \EE_Form_Section_Proper
90
-     * @throws \EE_Error
91
-     */
92
-    public function build_subform_from_question_group($question_group, $registration)
93
-    {
94
-        if (! $question_group instanceof EE_Question_Group ||
95
-            ! $registration instanceof EE_Registration) {
96
-            throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97
-        }
98
-        $parts_of_subsection = array(
99
-            'title' => new EE_Form_Section_HTML(
100
-                EEH_HTML::h5(
101
-                    $question_group->name(),
102
-                    $question_group->identifier(),
103
-                    'espresso-question-group-title-h5 section-title'
104
-                )
105
-            )
106
-        );
107
-        $questions = $question_group->questions(
108
-            array(
109
-                array(
110
-                    'OR' => array(
111
-                        'QST_system*blank' => '',
112
-                        'QST_system*null' => array( 'IS_NULL' )
113
-                    )
114
-                )
115
-            )
116
-        );
117
-        foreach ($questions as $question) {
118
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
119
-        }
120
-        if (EE_Registry::instance()->CAP->current_user_can(
121
-            'ee_edit_registration',
122
-            'edit-reg-questions-mbox',
123
-            $this->_registration->ID()
124
-        )) {
125
-            $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
-                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
85
+	/**
86
+	 *
87
+	 * @param EE_Question_Group $question_group
88
+	 * @param EE_Registration   $registration
89
+	 * @return \EE_Form_Section_Proper
90
+	 * @throws \EE_Error
91
+	 */
92
+	public function build_subform_from_question_group($question_group, $registration)
93
+	{
94
+		if (! $question_group instanceof EE_Question_Group ||
95
+			! $registration instanceof EE_Registration) {
96
+			throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97
+		}
98
+		$parts_of_subsection = array(
99
+			'title' => new EE_Form_Section_HTML(
100
+				EEH_HTML::h5(
101
+					$question_group->name(),
102
+					$question_group->identifier(),
103
+					'espresso-question-group-title-h5 section-title'
104
+				)
105
+			)
106
+		);
107
+		$questions = $question_group->questions(
108
+			array(
109
+				array(
110
+					'OR' => array(
111
+						'QST_system*blank' => '',
112
+						'QST_system*null' => array( 'IS_NULL' )
113
+					)
114
+				)
115
+			)
116
+		);
117
+		foreach ($questions as $question) {
118
+			$parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
119
+		}
120
+		if (EE_Registry::instance()->CAP->current_user_can(
121
+			'ee_edit_registration',
122
+			'edit-reg-questions-mbox',
123
+			$this->_registration->ID()
124
+		)) {
125
+			$parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
+				'<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
127 127
 		  			<span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso') . '</span>
128 128
 		  			<div class="dashicons dashicons-edit"></div>
129 129
 		  		</a></td></tr>'
130
-            );
131
-        }
132
-        return new EE_Form_Section_Proper(
133
-            array(
134
-                'subsections' => $parts_of_subsection,
135
-                'html_class' => 'question-group-questions',
136
-            )
137
-        );
138
-    }
130
+			);
131
+		}
132
+		return new EE_Form_Section_Proper(
133
+			array(
134
+				'subsections' => $parts_of_subsection,
135
+				'html_class' => 'question-group-questions',
136
+			)
137
+		);
138
+	}
139 139
 
140
-    /**
141
-     * Overrides parent so if inputs were disabled, we leave those with their defaults
142
-     * from the answers in the DB
143
-     * @param array $req_data like $_POST
144
-     * @return void
145
-     */
146
-    protected function _normalize($req_data)
147
-    {
148
-        $this->_received_submission = true;
149
-        $this->_validation_errors = array();
150
-        foreach ($this->get_validatable_subsections() as $subsection) {
151
-            if ($subsection->form_data_present_in($req_data)) {
152
-                try {
153
-                    $subsection->_normalize($req_data);
154
-                } catch (EE_Validation_Error $e) {
155
-                    $subsection->add_validation_error($e);
156
-                }
157
-            }
158
-        }
159
-    }
140
+	/**
141
+	 * Overrides parent so if inputs were disabled, we leave those with their defaults
142
+	 * from the answers in the DB
143
+	 * @param array $req_data like $_POST
144
+	 * @return void
145
+	 */
146
+	protected function _normalize($req_data)
147
+	{
148
+		$this->_received_submission = true;
149
+		$this->_validation_errors = array();
150
+		foreach ($this->get_validatable_subsections() as $subsection) {
151
+			if ($subsection->form_data_present_in($req_data)) {
152
+				try {
153
+					$subsection->_normalize($req_data);
154
+				} catch (EE_Validation_Error $e) {
155
+					$subsection->add_validation_error($e);
156
+				}
157
+			}
158
+		}
159
+	}
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * Performs validation on this form section and its subsections. For each subsection,
165
-     * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection.
166
-     * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method,
167
-     * calling parent::_validate() first.
168
-     */
169
-    protected function _validate()
170
-    {
171
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172
-            if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173
-                if (method_exists($this, '_validate_'.$subsection_name)) {
174
-                    call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
175
-                }
176
-                $subsection->_validate();
177
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
178
-                $subsection->_received_submission = true;
179
-            }
180
-        }
181
-    }
163
+	/**
164
+	 * Performs validation on this form section and its subsections. For each subsection,
165
+	 * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection.
166
+	 * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method,
167
+	 * calling parent::_validate() first.
168
+	 */
169
+	protected function _validate()
170
+	{
171
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172
+			if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173
+				if (method_exists($this, '_validate_'.$subsection_name)) {
174
+					call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
175
+				}
176
+				$subsection->_validate();
177
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
178
+				$subsection->_received_submission = true;
179
+			}
180
+		}
181
+	}
182 182
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function __construct(EE_Registration $reg, $options = array())
30 30
     {
31 31
         $this->_registration = $reg;
32
-        if (! isset($options['layout_strategy'])) {
32
+        if ( ! isset($options['layout_strategy'])) {
33 33
             $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34 34
         }
35
-        if (! isset($options['html_id'])) {
35
+        if ( ! isset($options['html_id'])) {
36 36
             $options['html_id'] = 'reg-admin-attendee-questions-frm';
37 37
         }
38 38
         $this->build_form_from_registration();
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     public function build_form_from_registration()
53 53
     {
54 54
         $reg = $this->get_registration();
55
-        if (! $reg instanceof EE_Registration) {
55
+        if ( ! $reg instanceof EE_Registration) {
56 56
             throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57 57
         }
58 58
         // we want to get all their question groups
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
                     'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64 64
                     'OR' => array(
65 65
                         'Question.QST_system*blank' =>  '',
66
-                        'Question.QST_system*null' => array( 'IS_NULL' )
66
+                        'Question.QST_system*null' => array('IS_NULL')
67 67
                     )
68 68
                 ),
69
-                'order_by' => array( 'QSG_order' => 'ASC' )
69
+                'order_by' => array('QSG_order' => 'ASC')
70 70
             )
71 71
         );
72 72
         // get each question groups questions
73 73
         foreach ($question_groups as $question_group) {
74 74
             if ($question_group instanceof EE_Question_Group) {
75
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
75
+                $this->_subsections[$question_group->ID()] = $this->build_subform_from_question_group(
76 76
                     $question_group,
77 77
                     $reg
78 78
                 );
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function build_subform_from_question_group($question_group, $registration)
93 93
     {
94
-        if (! $question_group instanceof EE_Question_Group ||
94
+        if ( ! $question_group instanceof EE_Question_Group ||
95 95
             ! $registration instanceof EE_Registration) {
96 96
             throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97 97
         }
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
                 array(
110 110
                     'OR' => array(
111 111
                         'QST_system*blank' => '',
112
-                        'QST_system*null' => array( 'IS_NULL' )
112
+                        'QST_system*null' => array('IS_NULL')
113 113
                     )
114 114
                 )
115 115
             )
116 116
         );
117 117
         foreach ($questions as $question) {
118
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
118
+            $parts_of_subsection[$question->ID()] = $question->generate_form_input($registration);
119 119
         }
120 120
         if (EE_Registry::instance()->CAP->current_user_can(
121 121
             'ee_edit_registration',
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
             $this->_registration->ID()
124 124
         )) {
125 125
             $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
-                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
127
-		  			<span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso') . '</span>
126
+                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="'.esc_attr__('click to edit question', 'event_espresso').'">
127
+		  			<span class="reg-admin-edit-question-group-spn">' . __('edit the above question group', 'event_espresso').'</span>
128 128
 		  			<div class="dashicons dashicons-edit"></div>
129 129
 		  		</a></td></tr>'
130 130
             );
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172 172
             if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173 173
                 if (method_exists($this, '_validate_'.$subsection_name)) {
174
-                    call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
174
+                    call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
175 175
                 }
176 176
                 $subsection->_validate();
177 177
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
Please login to merge, or discard this patch.