Conditions | 16 |
Paths | 6336 |
Total Lines | 89 |
Code Lines | 57 |
Lines | 9 |
Ratio | 10.11 % |
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 |
||
22 | public function createForm($surveyData, $formData) |
||
23 | { |
||
24 | $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||
25 | $questionId = isset($_GET['question_id']) ? intval($_GET['question_id']) : null; |
||
26 | $surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; |
||
27 | |||
28 | $toolName = Display::return_icon( |
||
29 | SurveyManager::icon_question(Security::remove_XSS($_GET['type'])), |
||
30 | get_lang(ucfirst(Security::remove_XSS($_GET['type']))), |
||
31 | array('align' => 'middle', 'height' => '22px') |
||
32 | ).' '; |
||
33 | |||
34 | if ($action == 'add') { |
||
35 | $toolName .= get_lang('AddQuestion'); |
||
36 | } |
||
37 | if ($action == 'edit') { |
||
38 | $toolName .= get_lang('EditQuestion'); |
||
39 | } |
||
40 | |||
41 | if ($_GET['type'] == 'yesno') { |
||
42 | $toolName .= ': '.get_lang('YesNo'); |
||
43 | } else if ($_GET['type'] == 'multiplechoice') { |
||
44 | $toolName .= ': '.get_lang('UniqueSelect'); |
||
45 | } else { |
||
46 | $toolName .= ': '.get_lang(api_ucfirst(Security::remove_XSS($_GET['type']))); |
||
47 | } |
||
48 | |||
49 | $sharedQuestionId = isset($formData['shared_question_id']) ? $formData['shared_question_id'] : null; |
||
50 | |||
51 | $url = api_get_self().'?action='.$action.'&type='.Security::remove_XSS($_GET['type']).'&survey_id='.$surveyId.'&question_id='.$questionId.'&'.api_get_cidreq(); |
||
52 | |||
53 | $form = new FormValidator('question_form', 'post', $url); |
||
54 | $form->addHeader($toolName); |
||
55 | $form->addHidden('survey_id', $surveyId); |
||
56 | $form->addHidden('question_id', $questionId); |
||
57 | $form->addHidden('shared_question_id', Security::remove_XSS($sharedQuestionId)); |
||
58 | $form->addHidden('type', Security::remove_XSS($_GET['type'])); |
||
59 | |||
60 | $config = array('ToolbarSet' => 'SurveyQuestion', 'Width' => '100%', 'Height' => '120'); |
||
61 | $form->addHtmlEditor('question', get_lang('Question'), true, false, $config); |
||
62 | |||
63 | // When survey type = 1?? |
||
64 | if ($surveyData['survey_type'] == 1) { |
||
65 | $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); |
||
66 | $sql = 'SELECT id,name FROM '.$table_survey_question_group.' |
||
67 | WHERE survey_id = '.(int)$_GET['survey_id'].' |
||
68 | ORDER BY name'; |
||
69 | $rs = Database::query($sql); |
||
70 | $glist = null; |
||
71 | while ($row = Database::fetch_array($rs, 'NUM')) { |
||
72 | $glist .= '<option value="'.$row[0].'" >'.$row[1].'</option>'; |
||
73 | } |
||
74 | |||
75 | $grouplist = $grouplist1 = $grouplist2 = $glist; |
||
76 | |||
77 | View Code Duplication | if (!empty($formData['assigned'])) { |
|
78 | $grouplist = str_replace('<option value="'.$formData['assigned'].'"','<option value="'.$formData['assigned'].'" selected',$glist); |
||
79 | } |
||
80 | |||
81 | View Code Duplication | if (!empty($formData['assigned1'])) { |
|
82 | $grouplist1 = str_replace('<option value="'.$formData['assigned1'].'"','<option value="'.$formData['assigned1'].'" selected',$glist); |
||
83 | } |
||
84 | |||
85 | View Code Duplication | if (!empty($formData['assigned2'])) { |
|
86 | $grouplist2 = str_replace('<option value="'.$formData['assigned2'].'"','<option value="'.$formData['assigned2'].'" selected',$glist); |
||
87 | } |
||
88 | |||
89 | $this->html .= ' <tr><td colspan=""> |
||
90 | <fieldset style="border:1px solid black"><legend>'.get_lang('Condition').'</legend> |
||
91 | |||
92 | <b>'.get_lang('Primary').'</b><br /> |
||
93 | '.'<input type="radio" name="choose" value="1" '.(($formData['choose'] == 1) ? 'checked' : ''). |
||
94 | '><select name="assigned">'.$grouplist.'</select><br />'; |
||
95 | |||
96 | $this->html .= ' |
||
97 | <b>'.get_lang('Secondary').'</b><br /> |
||
98 | '.'<input type="radio" name="choose" value="2" '.(($formData['choose']==2)?'checked':''). |
||
99 | '><select name="assigned1">'.$grouplist1.'</select> '. |
||
100 | '<select name="assigned2">'.$grouplist2.'</select>' |
||
101 | .'</fieldset><br />'; |
||
102 | |||
103 | //$form->addRadio('choose', get_lang('Primary')); |
||
104 | //$form->addRadio('choose', get_lang('Secondary')); |
||
105 | } |
||
106 | |||
107 | $this->setForm($form); |
||
108 | |||
109 | return $form; |
||
110 | } |
||
111 | |||
335 |