Conditions | 14 |
Paths | 7 |
Total Lines | 118 |
Code Lines | 80 |
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 |
||
54 | public function doSelectRows($confirm, $msg = '') |
||
55 | { |
||
56 | $data = $this->misc->getDatabaseAccessor(); |
||
57 | |||
58 | if ($confirm) { |
||
59 | $this->printTrail($this->keystring); |
||
1 ignored issue
–
show
|
|||
60 | $this->printTabs($this->keystring, 'select'); |
||
1 ignored issue
–
show
|
|||
61 | $this->printMsg($msg); |
||
1 ignored issue
–
show
|
|||
62 | |||
63 | $attrs = $data->getTableAttributes($_REQUEST[$this->keystring]); |
||
64 | |||
65 | echo '<form action="'.\SUBFOLDER.'/src/views/'.$this->script.'" method="post" id="selectform">'; |
||
66 | echo "\n"; |
||
67 | |||
68 | if ($attrs->recordCount() > 0) { |
||
69 | // JavaScript for select all feature |
||
70 | echo "<script type=\"text/javascript\">\n"; |
||
71 | echo "//<![CDATA[\n"; |
||
72 | echo " function selectAll() {\n"; |
||
73 | echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
||
74 | echo " var e = document.getElementById('selectform').elements[i];\n"; |
||
75 | echo " if (e.name.indexOf('show') == 0) { \n "; |
||
76 | echo " e.checked = document.getElementById('selectform').selectall.checked;\n"; |
||
77 | echo " }\n"; |
||
78 | echo " }\n"; |
||
79 | echo " }\n"; |
||
80 | echo "//]]>\n"; |
||
81 | echo "</script>\n"; |
||
82 | |||
83 | echo "<table>\n"; |
||
84 | |||
85 | // Output table header |
||
86 | echo "<tr><th class=\"data\">{$this->lang['strshow']}</th><th class=\"data\">{$this->lang['strcolumn']}</th>"; |
||
87 | echo "<th class=\"data\">{$this->lang['strtype']}</th><th class=\"data\">{$this->lang['stroperator']}</th>"; |
||
88 | echo "<th class=\"data\">{$this->lang['strvalue']}</th></tr>"; |
||
89 | |||
90 | $i = 0; |
||
91 | while (!$attrs->EOF) { |
||
92 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
93 | // Set up default value if there isn't one already |
||
94 | if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
||
95 | $_REQUEST['values'][$attrs->fields['attname']] = null; |
||
96 | } |
||
97 | |||
98 | if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
||
99 | $_REQUEST['ops'][$attrs->fields['attname']] = null; |
||
100 | } |
||
101 | |||
102 | // Continue drawing row |
||
103 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
104 | echo "<tr class=\"data{$id}\">\n"; |
||
105 | echo '<td style="white-space:nowrap;">'; |
||
106 | echo '<input type="checkbox" name="show[', htmlspecialchars($attrs->fields['attname']), ']"', |
||
107 | isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
||
108 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
109 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
||
110 | echo '<td style="white-space:nowrap;">'; |
||
111 | echo "<select name=\"ops[{$attrs->fields['attname']}]\">\n"; |
||
112 | foreach (array_keys($data->selectOps) as $v) { |
||
113 | echo '<option value="', htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] == $v) ? ' selected="selected"' : '', |
||
114 | '>', htmlspecialchars($v), "</option>\n"; |
||
115 | } |
||
116 | echo "</select></td>\n"; |
||
117 | echo '<td style="white-space:nowrap;">', $data->printField( |
||
118 | "values[{$attrs->fields['attname']}]", |
||
119 | $_REQUEST['values'][$attrs->fields['attname']], |
||
120 | $attrs->fields['type'] |
||
121 | ), '</td>'; |
||
122 | echo "</tr>\n"; |
||
123 | ++$i; |
||
124 | $attrs->moveNext(); |
||
125 | } |
||
126 | // Select all checkbox |
||
127 | echo "<tr><td colspan=\"5\"><input type=\"checkbox\" id=\"selectall\" name=\"selectall\" accesskey=\"a\" onclick=\"javascript:selectAll()\" /><label for=\"selectall\">{$this->lang['strselectallfields']}</label></td></tr>"; |
||
128 | echo "</table>\n"; |
||
129 | } else { |
||
130 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
131 | } |
||
132 | |||
133 | echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n"; |
||
134 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->keystring]), "\" />\n"; |
||
135 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
136 | echo $this->misc->form; |
||
137 | echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$this->lang['strselect']}\" />\n"; |
||
138 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
139 | echo "</form>\n"; |
||
140 | |||
141 | return; |
||
142 | } |
||
143 | $this->coalesceArr($_POST, 'show', []); |
||
1 ignored issue
–
show
|
|||
144 | |||
145 | $this->coalesceArr($_POST, 'values', []); |
||
146 | |||
147 | $this->coalesceArr($_POST, 'nulls', []); |
||
148 | |||
149 | // Verify that they haven't supplied a value for unary operators |
||
150 | foreach ($_POST['ops'] as $k => $v) { |
||
151 | if ('p' == $data->selectOps[$v] && $_POST['values'][$k] != '') { |
||
152 | $this->doSelectRows(true, $this->lang['strselectunary']); |
||
153 | |||
154 | return; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | if (0 == sizeof($_POST['show'])) { |
||
159 | return $this->doSelectRows(true, $this->lang['strselectneedscol']); |
||
160 | } |
||
161 | // Generate query SQL |
||
162 | $query = $data->getSelectSQL($_REQUEST[$this->keystring], array_keys($_POST['show']), $_POST['values'], $_POST['ops']); |
||
163 | |||
164 | $_REQUEST['query'] = $query; |
||
165 | $_REQUEST['return'] = 'schema'; |
||
166 | |||
167 | $this->setNoOutput(true); |
||
1 ignored issue
–
show
|
|||
168 | |||
169 | $display_controller = new DisplayController($this->getContainer()); |
||
1 ignored issue
–
show
|
|||
170 | |||
171 | return $display_controller->render(); |
||
172 | } |
||
354 |