| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 126 |
| Code Lines | 93 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 105 | public function createForm($surveyData, $formData) |
||
| 106 | { |
||
| 107 | $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||
| 108 | $questionId = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null; |
||
| 109 | $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null; |
||
| 110 | $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null; |
||
| 111 | |||
| 112 | $actionHeader = get_lang('EditQuestion').': '; |
||
| 113 | if ($action === 'add') { |
||
| 114 | $actionHeader = get_lang('AddQuestion').': '; |
||
| 115 | } |
||
| 116 | |||
| 117 | $questionComment = ''; |
||
| 118 | switch ($type) { |
||
| 119 | case 'open': |
||
| 120 | $toolName = get_lang('Open'); |
||
| 121 | $questionComment = get_lang('QuestionTags'); |
||
| 122 | break; |
||
| 123 | case 'yesno': |
||
| 124 | $toolName = get_lang('YesNo'); |
||
| 125 | break; |
||
| 126 | case 'multiplechoice': |
||
| 127 | $toolName = get_lang('UniqueSelect'); |
||
| 128 | break; |
||
| 129 | case 'multipleresponse': |
||
| 130 | $toolName = get_lang('MultipleResponse'); |
||
| 131 | break; |
||
| 132 | case 'selectivedisplay': |
||
| 133 | $toolName = get_lang('SurveyQuestionSelectiveDisplay'); |
||
| 134 | $questionComment = get_lang('SurveyQuestionSelectiveDisplayComment'); |
||
| 135 | break; |
||
| 136 | default: |
||
| 137 | $toolName = get_lang(api_ucfirst($type)); |
||
| 138 | } |
||
| 139 | |||
| 140 | $icon = Display::return_icon( |
||
| 141 | SurveyManager::icon_question($type), |
||
| 142 | $toolName, |
||
| 143 | ['align' => 'middle', 'height' => '22px'] |
||
| 144 | ).' '; |
||
| 145 | |||
| 146 | $toolName = $icon.$actionHeader.$toolName; |
||
| 147 | $sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null; |
||
| 148 | |||
| 149 | $url = api_get_self().'?action='.$action.'&type='.$type.'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq(); |
||
| 150 | $form = new FormValidator('question_form', 'post', $url); |
||
| 151 | $form->addHeader($toolName); |
||
| 152 | if (!empty($questionComment)) { |
||
| 153 | $form->addHtml(Display::return_message($questionComment, 'info', false)); |
||
| 154 | } |
||
| 155 | $form->addHidden('survey_id', $surveyId); |
||
| 156 | $form->addHidden('question_id', $questionId); |
||
| 157 | $form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId)); |
||
| 158 | $form->addHidden('type', $type); |
||
| 159 | |||
| 160 | $config = [ |
||
| 161 | 'ToolbarSet' => 'SurveyQuestion', |
||
| 162 | 'Width' => '100%', |
||
| 163 | 'Height' => '120', |
||
| 164 | ]; |
||
| 165 | $form->addHtmlEditor( |
||
| 166 | 'question', |
||
| 167 | get_lang('Question'), |
||
| 168 | true, |
||
| 169 | false, |
||
| 170 | $config |
||
| 171 | ); |
||
| 172 | |||
| 173 | if (api_get_configuration_value('allow_required_survey_questions') && |
||
| 174 | in_array($_GET['type'], ['yesno', 'multiplechoice'])) { |
||
| 175 | $form->addCheckBox('is_required', get_lang('IsMandatory'), get_lang('Yes')); |
||
| 176 | } |
||
| 177 | |||
| 178 | if ($surveyData['survey_type'] == 1) { |
||
| 179 | $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); |
||
| 180 | $sql = 'SELECT id, name FROM '.$table_survey_question_group.' |
||
| 181 | WHERE survey_id = '.$surveyId.' |
||
| 182 | ORDER BY name'; |
||
| 183 | $rs = Database::query($sql); |
||
| 184 | $glist = null; |
||
| 185 | while ($row = Database::fetch_array($rs, 'NUM')) { |
||
| 186 | $glist .= '<option value="'.$row[0].'" >'.$row[1].'</option>'; |
||
| 187 | } |
||
| 188 | |||
| 189 | $grouplist = $grouplist1 = $grouplist2 = $glist; |
||
| 190 | if (!empty($formData['assigned'])) { |
||
| 191 | $grouplist = str_replace( |
||
| 192 | '<option value="'.$formData['assigned'].'"', |
||
| 193 | '<option value="'.$formData['assigned'].'" selected', |
||
| 194 | $glist |
||
| 195 | ); |
||
| 196 | } |
||
| 197 | |||
| 198 | if (!empty($formData['assigned1'])) { |
||
| 199 | $grouplist1 = str_replace( |
||
| 200 | '<option value="'.$formData['assigned1'].'"', |
||
| 201 | '<option value="'.$formData['assigned1'].'" selected', |
||
| 202 | $glist |
||
| 203 | ); |
||
| 204 | } |
||
| 205 | |||
| 206 | if (!empty($formData['assigned2'])) { |
||
| 207 | $grouplist2 = str_replace( |
||
| 208 | '<option value="'.$formData['assigned2'].'"', |
||
| 209 | '<option value="'.$formData['assigned2'].'" selected', |
||
| 210 | $glist |
||
| 211 | ); |
||
| 212 | } |
||
| 213 | |||
| 214 | $this->html .= '<tr><td colspan=""> |
||
|
|
|||
| 215 | <fieldset style="border:1px solid black"> |
||
| 216 | <legend>'.get_lang('Condition').'</legend> |
||
| 217 | <b>'.get_lang('Primary').'</b><br /> |
||
| 218 | <input type="radio" name="choose" value="1" '.(($formData['choose'] == 1) ? 'checked' : '').'> |
||
| 219 | <select name="assigned">'.$grouplist.'</select><br />'; |
||
| 220 | $this->html .= ' |
||
| 221 | <b>'.get_lang('Secondary').'</b><br /> |
||
| 222 | <input type="radio" name="choose" value="2" '.(($formData['choose'] == 2) ? 'checked' : '').'> |
||
| 223 | <select name="assigned1">'.$grouplist1.'</select> |
||
| 224 | <select name="assigned2">'.$grouplist2.'</select> |
||
| 225 | </fieldset><br />'; |
||
| 226 | } |
||
| 227 | |||
| 228 | $this->setForm($form); |
||
| 229 | |||
| 230 | return $form; |
||
| 231 | } |
||
| 478 |