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