Conditions | 2 |
Paths | 2 |
Total Lines | 131 |
Code Lines | 86 |
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 |
||
99 | public function doSaveEdit() |
||
100 | { |
||
101 | $data = $this->misc->getDatabaseAccessor(); |
||
102 | |||
103 | $status = $data->setView($_POST[$this->subject], $_POST['formDefinition'], $_POST['formComment']); |
||
104 | if (0 == $status) { |
||
105 | $this->doDefinition($this->lang['strviewupdated']); |
||
106 | } else { |
||
107 | $this->doEdit($this->lang['strviewupdatedbad']); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Function to allow editing of a view. |
||
113 | * |
||
114 | * @param mixed $msg |
||
115 | */ |
||
116 | public function doEdit($msg = '') |
||
117 | { |
||
118 | $data = $this->misc->getDatabaseAccessor(); |
||
119 | |||
120 | $this->printTrail($this->subject); |
||
121 | $this->printTitle($this->lang['stredit'], 'pg.view.alter'); |
||
122 | $this->printMsg($msg); |
||
123 | |||
124 | $viewdata = $data->getView($_REQUEST[$this->subject]); |
||
125 | |||
126 | if ($viewdata->recordCount() > 0) { |
||
127 | if (!isset($_POST['formDefinition'])) { |
||
128 | $_POST['formDefinition'] = $viewdata->fields['vwdefinition']; |
||
129 | $_POST['formComment'] = $viewdata->fields['relcomment']; |
||
130 | } |
||
131 | |||
132 | echo '<form action="'.\SUBFOLDER."/src/views/viewproperties\" method=\"post\">\n"; |
||
133 | echo "<table style=\"width: 100%\">\n"; |
||
134 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strdefinition']}</th>\n"; |
||
135 | echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">", |
||
136 | htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
||
137 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
138 | echo "\t\t<td class=\"data1\"><textarea rows=\"3\" cols=\"32\" name=\"formComment\">", |
||
139 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
140 | echo "</table>\n"; |
||
141 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n"; |
||
142 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->subject]), "\" />\n"; |
||
143 | echo $this->misc->form; |
||
144 | echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />\n"; |
||
145 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
146 | echo "</form>\n"; |
||
147 | } else { |
||
148 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Displays a screen where they can alter a column in a view. |
||
154 | * |
||
155 | * @param mixed $msg |
||
156 | */ |
||
157 | public function doProperties($msg = '') |
||
158 | { |
||
159 | $data = $this->misc->getDatabaseAccessor(); |
||
160 | |||
161 | $this->coalesceArr($_REQUEST, 'stage', 1); |
||
162 | |||
163 | switch ($_REQUEST['stage']) { |
||
164 | case 1: |
||
165 | |||
166 | $this->printTrail('column'); |
||
167 | $this->printTitle($this->lang['stralter'], 'pg.column.alter'); |
||
168 | $this->printMsg($msg); |
||
169 | |||
170 | echo '<form action="'.\SUBFOLDER."/src/views/viewproperties\" method=\"post\">\n"; |
||
171 | |||
172 | // Output view header |
||
173 | echo "<table>\n"; |
||
174 | echo "<tr><th class=\"data required\">{$this->lang['strname']}</th><th class=\"data required\">{$this->lang['strtype']}</th>"; |
||
175 | echo "<th class=\"data\">{$this->lang['strdefault']}</th><th class=\"data\">{$this->lang['strcomment']}</th></tr>"; |
||
176 | |||
177 | $column = $data->getTableAttributes($_REQUEST[$this->subject], $_REQUEST['column']); |
||
178 | |||
179 | if (!isset($_REQUEST['default'])) { |
||
180 | $_REQUEST['field'] = $column->fields['attname']; |
||
181 | $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc']; |
||
182 | $_REQUEST['comment'] = $column->fields['comment']; |
||
183 | } |
||
184 | |||
185 | echo '<tr><td><input name="field" size="32" value="', |
||
186 | htmlspecialchars($_REQUEST['field']), '" /></td>'; |
||
187 | |||
188 | echo '<td>', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '</td>'; |
||
189 | echo '<td><input name="default" size="20" value="', |
||
190 | htmlspecialchars($_REQUEST['default']), '" /></td>'; |
||
191 | echo '<td><input name="comment" size="32" value="', |
||
192 | htmlspecialchars($_REQUEST['comment']), '" /></td>'; |
||
193 | |||
194 | echo "</table>\n"; |
||
195 | echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n"; |
||
196 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
197 | echo $this->misc->form; |
||
198 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->subject]), "\" />\n"; |
||
199 | echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), "\" />\n"; |
||
200 | echo '<input type="hidden" name="olddefault" value="', htmlspecialchars($_REQUEST['olddefault']), "\" />\n"; |
||
201 | echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />\n"; |
||
202 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
203 | echo "</form>\n"; |
||
204 | |||
205 | break; |
||
206 | case 2: |
||
207 | |||
208 | // Check inputs |
||
209 | if ('' == trim($_REQUEST['field'])) { |
||
210 | $_REQUEST['stage'] = 1; |
||
211 | $this->doProperties($this->lang['strcolneedsname']); |
||
212 | |||
213 | return; |
||
214 | } |
||
215 | |||
216 | // Alter the view column |
||
217 | list($status, $sql) = $data->alterColumn( |
||
218 | $_REQUEST[$this->subject], |
||
219 | $_REQUEST['column'], |
||
220 | $_REQUEST['field'], |
||
221 | false, |
||
222 | false, |
||
223 | $_REQUEST['default'], |
||
224 | $_REQUEST['olddefault'], |
||
225 | '', |
||
226 | '', |
||
227 | '', |
||
228 | '', |
||
229 | $_REQUEST['comment'] |
||
230 | ); |
||
345 |