| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 116 |
| Code Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 106 | public function createForm($surveyData, $formData) |
||
| 107 | { |
||
| 108 | $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||
| 109 | $questionId = isset($_GET['question_id']) ? (int) $_GET['question_id'] : null; |
||
| 110 | $surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null; |
||
| 111 | $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null; |
||
| 112 | |||
| 113 | $toolName = Display::return_icon( |
||
| 114 | SurveyManager::icon_question($type), |
||
| 115 | get_lang(ucfirst($type)), |
||
| 116 | ['align' => 'middle', 'height' => '22px'] |
||
| 117 | ).' '; |
||
| 118 | |||
| 119 | if ($action == 'add') { |
||
| 120 | $toolName .= get_lang('AddQuestion').': '; |
||
| 121 | } elseif ($action == 'edit') { |
||
| 122 | $toolName .= get_lang('EditQuestion').': '; |
||
| 123 | } |
||
| 124 | |||
| 125 | switch ($_GET['type']) { |
||
| 126 | case 'yesno': |
||
| 127 | $toolName .= get_lang('YesNo'); |
||
| 128 | break; |
||
| 129 | case 'multiplechoice': |
||
| 130 | $toolName .= get_lang('UniqueSelect'); |
||
| 131 | break; |
||
| 132 | case 'multipleresponse': |
||
| 133 | $toolName .= get_lang('MultipleResponse'); |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | $toolName .= get_lang(api_ucfirst($type)); |
||
| 137 | } |
||
| 138 | |||
| 139 | $sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null; |
||
| 140 | |||
| 141 | $url = api_get_self().'?action='.$action.'&type='.$type.'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq(); |
||
| 142 | $form = new FormValidator('question_form', 'post', $url); |
||
| 143 | $form->addHeader($toolName); |
||
| 144 | $form->addHidden('survey_id', $surveyId); |
||
| 145 | $form->addHidden('question_id', $questionId); |
||
| 146 | $form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId)); |
||
| 147 | $form->addHidden('type', $type); |
||
| 148 | |||
| 149 | $config = [ |
||
| 150 | 'ToolbarSet' => 'SurveyQuestion', |
||
| 151 | 'Width' => '100%', |
||
| 152 | 'Height' => '120', |
||
| 153 | ]; |
||
| 154 | $form->addHtmlEditor( |
||
| 155 | 'question', |
||
| 156 | get_lang('Question'), |
||
| 157 | true, |
||
| 158 | false, |
||
| 159 | $config |
||
| 160 | ); |
||
| 161 | |||
| 162 | if (api_get_configuration_value('allow_required_survey_questions') && |
||
| 163 | in_array($_GET['type'], ['yesno', 'multiplechoice'])) { |
||
| 164 | $form->addCheckBox('is_required', get_lang('IsMandatory'), get_lang('Yes')); |
||
| 165 | } |
||
| 166 | |||
| 167 | // When survey type = 1?? |
||
| 168 | if ($surveyData['survey_type'] == 1) { |
||
| 169 | $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); |
||
| 170 | $sql = 'SELECT id,name FROM '.$table_survey_question_group.' |
||
| 171 | WHERE survey_id = '.(int) $_GET['survey_id'].' |
||
| 172 | ORDER BY name'; |
||
| 173 | $rs = Database::query($sql); |
||
| 174 | $glist = null; |
||
| 175 | while ($row = Database::fetch_array($rs, 'NUM')) { |
||
| 176 | $glist .= '<option value="'.$row[0].'" >'.$row[1].'</option>'; |
||
| 177 | } |
||
| 178 | |||
| 179 | $grouplist = $grouplist1 = $grouplist2 = $glist; |
||
| 180 | if (!empty($formData['assigned'])) { |
||
| 181 | $grouplist = str_replace( |
||
| 182 | '<option value="'.$formData['assigned'].'"', |
||
| 183 | '<option value="'.$formData['assigned'].'" selected', |
||
| 184 | $glist |
||
| 185 | ); |
||
| 186 | } |
||
| 187 | |||
| 188 | if (!empty($formData['assigned1'])) { |
||
| 189 | $grouplist1 = str_replace( |
||
| 190 | '<option value="'.$formData['assigned1'].'"', |
||
| 191 | '<option value="'.$formData['assigned1'].'" selected', |
||
| 192 | $glist |
||
| 193 | ); |
||
| 194 | } |
||
| 195 | |||
| 196 | if (!empty($formData['assigned2'])) { |
||
| 197 | $grouplist2 = str_replace( |
||
| 198 | '<option value="'.$formData['assigned2'].'"', |
||
| 199 | '<option value="'.$formData['assigned2'].'" selected', |
||
| 200 | $glist |
||
| 201 | ); |
||
| 202 | } |
||
| 203 | |||
| 204 | $this->html .= ' <tr><td colspan=""> |
||
|
|
|||
| 205 | <fieldset style="border:1px solid black"><legend>'.get_lang('Condition').'</legend> |
||
| 206 | |||
| 207 | <b>'.get_lang('Primary').'</b><br /> |
||
| 208 | '.'<input type="radio" name="choose" value="1" '.(($formData['choose'] == 1) ? 'checked' : ''). |
||
| 209 | '><select name="assigned">'.$grouplist.'</select><br />'; |
||
| 210 | |||
| 211 | $this->html .= ' |
||
| 212 | <b>'.get_lang('Secondary').'</b><br /> |
||
| 213 | '.'<input type="radio" name="choose" value="2" '.(($formData['choose'] == 2) ? 'checked' : ''). |
||
| 214 | '><select name="assigned1">'.$grouplist1.'</select> '. |
||
| 215 | '<select name="assigned2">'.$grouplist2.'</select>' |
||
| 216 | .'</fieldset><br />'; |
||
| 217 | } |
||
| 218 | |||
| 219 | $this->setForm($form); |
||
| 220 | |||
| 221 | return $form; |
||
| 222 | } |
||
| 448 |