Total Complexity | 93 |
Total Lines | 842 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like SequencesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SequencesController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class SequencesController extends BaseController |
||
17 | { |
||
18 | public $controller_name = 'SequencesController'; |
||
19 | |||
20 | /** |
||
21 | * Default method to render the controller according to the action parameter. |
||
22 | */ |
||
23 | public function render() |
||
24 | { |
||
25 | if ('tree' == $this->action) { |
||
26 | return $this->doTree(); |
||
27 | } |
||
28 | |||
29 | // Print header |
||
30 | $this->printHeader($this->lang['strsequences']); |
||
31 | $this->printBody(); |
||
32 | |||
33 | switch ($this->action) { |
||
34 | case 'create': |
||
35 | $this->doCreateSequence(); |
||
36 | |||
37 | break; |
||
38 | case 'save_create_sequence': |
||
39 | if (isset($_POST['create'])) { |
||
40 | $this->doSaveCreateSequence(); |
||
41 | } else { |
||
42 | $this->doDefault(); |
||
43 | } |
||
44 | |||
45 | break; |
||
46 | case 'properties': |
||
47 | $this->doProperties(); |
||
48 | |||
49 | break; |
||
50 | case 'drop': |
||
51 | if (isset($_POST['drop'])) { |
||
52 | $this->doDrop(false); |
||
53 | } else { |
||
54 | $this->doDefault(); |
||
55 | } |
||
56 | |||
57 | break; |
||
58 | case 'confirm_drop': |
||
59 | $this->doDrop(true); |
||
60 | |||
61 | break; |
||
62 | case 'restart': |
||
63 | $this->doRestart(); |
||
64 | |||
65 | break; |
||
66 | case 'reset': |
||
67 | $this->doReset(); |
||
68 | |||
69 | break; |
||
70 | case 'nextval': |
||
71 | $this->doNextval(); |
||
72 | |||
73 | break; |
||
74 | case 'setval': |
||
75 | if (isset($_POST['setval'])) { |
||
76 | $this->doSaveSetval(); |
||
77 | } else { |
||
78 | $this->doDefault(); |
||
79 | } |
||
80 | |||
81 | break; |
||
82 | case 'confirm_setval': |
||
83 | $this->doSetval(); |
||
84 | |||
85 | break; |
||
86 | case 'alter': |
||
87 | if (isset($_POST['alter'])) { |
||
88 | $this->doSaveAlter(); |
||
89 | } else { |
||
90 | $this->doDefault(); |
||
91 | } |
||
92 | |||
93 | break; |
||
94 | case 'confirm_alter': |
||
95 | $this->doAlter(); |
||
96 | |||
97 | break; |
||
98 | default: |
||
99 | $this->doDefault(); |
||
100 | |||
101 | break; |
||
102 | } |
||
103 | |||
104 | // Print footer |
||
105 | return $this->printFooter(); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Display list of all sequences in the database/schema. |
||
110 | * |
||
111 | * @param mixed $msg |
||
112 | */ |
||
113 | public function doDefault($msg = '') |
||
114 | { |
||
115 | $data = $this->misc->getDatabaseAccessor(); |
||
116 | |||
117 | $this->printTrail('schema'); |
||
118 | $this->printTabs('schema', 'sequences'); |
||
119 | $this->printMsg($msg); |
||
120 | |||
121 | // Get all sequences |
||
122 | $sequences = $data->getSequences(); |
||
123 | |||
124 | $columns = [ |
||
125 | 'sequence' => [ |
||
126 | 'title' => $this->lang['strsequence'], |
||
127 | 'field' => Decorator::field('seqname'), |
||
128 | 'url' => "sequences?action=properties&{$this->misc->href}&", |
||
129 | 'vars' => ['sequence' => 'seqname'], |
||
130 | ], |
||
131 | 'owner' => [ |
||
132 | 'title' => $this->lang['strowner'], |
||
133 | 'field' => Decorator::field('seqowner'), |
||
134 | ], |
||
135 | 'actions' => [ |
||
136 | 'title' => $this->lang['stractions'], |
||
137 | ], |
||
138 | 'comment' => [ |
||
139 | 'title' => $this->lang['strcomment'], |
||
140 | 'field' => Decorator::field('seqcomment'), |
||
141 | ], |
||
142 | ]; |
||
143 | |||
144 | $actions = [ |
||
145 | 'multiactions' => [ |
||
146 | 'keycols' => ['sequence' => 'seqname'], |
||
147 | 'url' => 'sequences', |
||
148 | ], |
||
149 | 'alter' => [ |
||
150 | 'content' => $this->lang['stralter'], |
||
151 | 'attr' => [ |
||
152 | 'href' => [ |
||
153 | 'url' => 'sequences', |
||
154 | 'urlvars' => [ |
||
155 | 'action' => 'confirm_alter', |
||
156 | 'subject' => 'sequence', |
||
157 | 'sequence' => Decorator::field('seqname'), |
||
158 | ], |
||
159 | ], |
||
160 | ], |
||
161 | ], |
||
162 | 'drop' => [ |
||
163 | 'content' => $this->lang['strdrop'], |
||
164 | 'attr' => [ |
||
165 | 'href' => [ |
||
166 | 'url' => 'sequences', |
||
167 | 'urlvars' => [ |
||
168 | 'action' => 'confirm_drop', |
||
169 | 'sequence' => Decorator::field('seqname'), |
||
170 | ], |
||
171 | ], |
||
172 | ], |
||
173 | 'multiaction' => 'confirm_drop', |
||
174 | ], |
||
175 | 'privileges' => [ |
||
176 | 'content' => $this->lang['strprivileges'], |
||
177 | 'attr' => [ |
||
178 | 'href' => [ |
||
179 | 'url' => 'privileges', |
||
180 | 'urlvars' => [ |
||
181 | 'subject' => 'sequence', |
||
182 | 'sequence' => Decorator::field('seqname'), |
||
183 | ], |
||
184 | ], |
||
185 | ], |
||
186 | ], |
||
187 | ]; |
||
188 | |||
189 | echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $this->lang['strnosequences']); |
||
190 | |||
191 | $this->printNavLinks(['create' => [ |
||
1 ignored issue
–
show
|
|||
192 | 'attr' => [ |
||
193 | 'href' => [ |
||
194 | 'url' => 'sequences', |
||
195 | 'urlvars' => [ |
||
196 | 'action' => 'create', |
||
197 | 'server' => $_REQUEST['server'], |
||
198 | 'database' => $_REQUEST['database'], |
||
199 | 'schema' => $_REQUEST['schema'], |
||
200 | ], |
||
201 | ], |
||
202 | ], |
||
203 | 'content' => $this->lang['strcreatesequence'], |
||
204 | ]], 'sequences-sequences', get_defined_vars()); |
||
1 ignored issue
–
show
|
|||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Generate XML for the browser tree. |
||
209 | */ |
||
210 | public function doTree() |
||
211 | { |
||
212 | $data = $this->misc->getDatabaseAccessor(); |
||
213 | |||
214 | $sequences = $data->getSequences(); |
||
215 | |||
216 | $reqvars = $this->misc->getRequestVars('sequence'); |
||
217 | |||
218 | $attrs = [ |
||
219 | 'text' => Decorator::field('seqname'), |
||
220 | 'icon' => 'Sequence', |
||
221 | 'toolTip' => Decorator::field('seqcomment'), |
||
222 | 'action' => Decorator::actionurl( |
||
223 | 'sequences', |
||
224 | $reqvars, |
||
225 | [ |
||
226 | 'action' => 'properties', |
||
227 | 'sequence' => Decorator::field('seqname'), |
||
228 | ] |
||
229 | ), |
||
230 | ]; |
||
231 | |||
232 | return $this->printTree($sequences, $attrs, 'sequences'); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Display the properties of a sequence. |
||
237 | * |
||
238 | * @param mixed $msg |
||
239 | */ |
||
240 | public function doProperties($msg = '') |
||
241 | { |
||
242 | $data = $this->misc->getDatabaseAccessor(); |
||
243 | $this->printTrail('sequence'); |
||
244 | $this->printTitle($this->lang['strproperties'], 'pg.sequence'); |
||
245 | $this->printMsg($msg); |
||
246 | |||
247 | // Fetch the sequence information |
||
248 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
249 | |||
250 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
251 | $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); |
||
252 | $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']); |
||
253 | |||
254 | // Show comment if any |
||
255 | if (null !== $sequence->fields['seqcomment']) { |
||
256 | echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n"; |
||
257 | } |
||
258 | |||
259 | echo '<table border="0">'; |
||
260 | echo "<tr><th class=\"data\">{$this->lang['strname']}</th>"; |
||
261 | if ($data->hasAlterSequenceStart()) { |
||
262 | echo "<th class=\"data\">{$this->lang['strstartvalue']}</th>"; |
||
263 | } |
||
264 | echo "<th class=\"data\">{$this->lang['strlastvalue']}</th>"; |
||
265 | echo "<th class=\"data\">{$this->lang['strincrementby']}</th>"; |
||
266 | echo "<th class=\"data\">{$this->lang['strmaxvalue']}</th>"; |
||
267 | echo "<th class=\"data\">{$this->lang['strminvalue']}</th>"; |
||
268 | echo "<th class=\"data\">{$this->lang['strcachevalue']}</th>"; |
||
269 | echo "<th class=\"data\">{$this->lang['strlogcount']}</th>"; |
||
270 | echo "<th class=\"data\">{$this->lang['strcancycle']}</th>"; |
||
271 | echo "<th class=\"data\">{$this->lang['striscalled']}</th></tr>"; |
||
272 | echo '<tr>'; |
||
273 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>'; |
||
274 | if ($data->hasAlterSequenceStart()) { |
||
275 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>'; |
||
276 | } |
||
277 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>'; |
||
278 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>'; |
||
279 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>'; |
||
280 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>'; |
||
281 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>'; |
||
282 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>'; |
||
283 | echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $this->lang['stryes'] : $this->lang['strno']), '</td>'; |
||
284 | echo '<td class="data1">', ($sequence->fields['is_called'] ? $this->lang['stryes'] : $this->lang['strno']), '</td>'; |
||
285 | echo '</tr>'; |
||
286 | echo '</table>'; |
||
287 | |||
288 | $navlinks = [ |
||
289 | 'alter' => [ |
||
290 | 'attr' => [ |
||
291 | 'href' => [ |
||
292 | 'url' => 'sequences', |
||
293 | 'urlvars' => [ |
||
294 | 'action' => 'confirm_alter', |
||
295 | 'server' => $_REQUEST['server'], |
||
296 | 'database' => $_REQUEST['database'], |
||
297 | 'schema' => $_REQUEST['schema'], |
||
298 | 'sequence' => $sequence->fields['seqname'], |
||
299 | ], |
||
300 | ], |
||
301 | ], |
||
302 | 'content' => $this->lang['stralter'], |
||
303 | ], |
||
304 | 'setval' => [ |
||
305 | 'attr' => [ |
||
306 | 'href' => [ |
||
307 | 'url' => 'sequences', |
||
308 | 'urlvars' => [ |
||
309 | 'action' => 'confirm_setval', |
||
310 | 'server' => $_REQUEST['server'], |
||
311 | 'database' => $_REQUEST['database'], |
||
312 | 'schema' => $_REQUEST['schema'], |
||
313 | 'sequence' => $sequence->fields['seqname'], |
||
314 | ], |
||
315 | ], |
||
316 | ], |
||
317 | 'content' => $this->lang['strsetval'], |
||
318 | ], |
||
319 | 'nextval' => [ |
||
320 | 'attr' => [ |
||
321 | 'href' => [ |
||
322 | 'url' => 'sequences', |
||
323 | 'urlvars' => [ |
||
324 | 'action' => 'nextval', |
||
325 | 'server' => $_REQUEST['server'], |
||
326 | 'database' => $_REQUEST['database'], |
||
327 | 'schema' => $_REQUEST['schema'], |
||
328 | 'sequence' => $sequence->fields['seqname'], |
||
329 | ], |
||
330 | ], |
||
331 | ], |
||
332 | 'content' => $this->lang['strnextval'], |
||
333 | ], |
||
334 | 'restart' => [ |
||
335 | 'attr' => [ |
||
336 | 'href' => [ |
||
337 | 'url' => 'sequences', |
||
338 | 'urlvars' => [ |
||
339 | 'action' => 'restart', |
||
340 | 'server' => $_REQUEST['server'], |
||
341 | 'database' => $_REQUEST['database'], |
||
342 | 'schema' => $_REQUEST['schema'], |
||
343 | 'sequence' => $sequence->fields['seqname'], |
||
344 | ], |
||
345 | ], |
||
346 | ], |
||
347 | 'content' => $this->lang['strrestart'], |
||
348 | ], |
||
349 | 'reset' => [ |
||
350 | 'attr' => [ |
||
351 | 'href' => [ |
||
352 | 'url' => 'sequences', |
||
353 | 'urlvars' => [ |
||
354 | 'action' => 'reset', |
||
355 | 'server' => $_REQUEST['server'], |
||
356 | 'database' => $_REQUEST['database'], |
||
357 | 'schema' => $_REQUEST['schema'], |
||
358 | 'sequence' => $sequence->fields['seqname'], |
||
359 | ], |
||
360 | ], |
||
361 | ], |
||
362 | 'content' => $this->lang['strreset'], |
||
363 | ], |
||
364 | 'showall' => [ |
||
365 | 'attr' => [ |
||
366 | 'href' => [ |
||
367 | 'url' => 'sequences', |
||
368 | 'urlvars' => [ |
||
369 | 'server' => $_REQUEST['server'], |
||
370 | 'database' => $_REQUEST['database'], |
||
371 | 'schema' => $_REQUEST['schema'], |
||
372 | ], |
||
373 | ], |
||
374 | ], |
||
375 | 'content' => $this->lang['strshowallsequences'], |
||
376 | ], |
||
377 | ]; |
||
378 | |||
379 | if (!$data->hasAlterSequenceStart()) { |
||
380 | unset($navlinks['restart']); |
||
381 | } |
||
382 | |||
383 | $this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars()); |
||
384 | } else { |
||
385 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
386 | } |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * Drop a sequence. |
||
391 | * |
||
392 | * @param mixed $confirm |
||
393 | * @param mixed $msg |
||
394 | */ |
||
395 | public function doDrop($confirm, $msg = '') |
||
396 | { |
||
397 | $data = $this->misc->getDatabaseAccessor(); |
||
398 | |||
399 | if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) { |
||
400 | return $this->doDefault($this->lang['strspecifysequencetodrop']); |
||
401 | } |
||
402 | |||
403 | if ($confirm) { |
||
404 | $this->printTrail('sequence'); |
||
405 | $this->printTitle($this->lang['strdrop'], 'pg.sequence.drop'); |
||
406 | $this->printMsg($msg); |
||
407 | |||
408 | echo '<form action="'.\SUBFOLDER."/src/views/sequences\" method=\"post\">\n"; |
||
409 | |||
410 | //If multi drop |
||
411 | if (isset($_REQUEST['ma'])) { |
||
412 | foreach ($_REQUEST['ma'] as $v) { |
||
413 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
414 | echo '<p>', sprintf($this->lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n"; |
||
415 | printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence'])); |
||
416 | } |
||
417 | } else { |
||
418 | echo '<p>', sprintf($this->lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n"; |
||
419 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
420 | } |
||
421 | |||
422 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
||
423 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
424 | echo $this->misc->form; |
||
425 | echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
||
426 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
427 | echo "</form>\n"; |
||
428 | } else { |
||
429 | if (is_array($_POST['sequence'])) { |
||
430 | $msg = ''; |
||
431 | $status = $data->beginTransaction(); |
||
432 | if (0 == $status) { |
||
433 | foreach ($_POST['sequence'] as $s) { |
||
434 | $status = $data->dropSequence($s, isset($_POST['cascade'])); |
||
435 | if (0 == $status) { |
||
436 | $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $this->lang['strsequencedropped']); |
||
437 | } else { |
||
438 | $data->endTransaction(); |
||
439 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $this->lang['strsequencedroppedbad'])); |
||
440 | |||
441 | return; |
||
442 | } |
||
443 | } |
||
444 | } |
||
445 | if (0 == $data->endTransaction()) { |
||
446 | // Everything went fine, back to the Default page.... |
||
447 | $this->misc->setReloadBrowser(true); |
||
448 | $this->doDefault($msg); |
||
449 | } else { |
||
450 | $this->doDefault($this->lang['strsequencedroppedbad']); |
||
451 | } |
||
452 | } else { |
||
453 | $status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade'])); |
||
454 | if (0 == $status) { |
||
455 | $this->misc->setReloadBrowser(true); |
||
456 | $this->doDefault($this->lang['strsequencedropped']); |
||
457 | } else { |
||
458 | $this->doDrop(true, $this->lang['strsequencedroppedbad']); |
||
459 | } |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 | |||
464 | /** |
||
465 | * Displays a screen where they can enter a new sequence. |
||
466 | * |
||
467 | * @param mixed $msg |
||
468 | */ |
||
469 | public function doCreateSequence($msg = '') |
||
470 | { |
||
471 | $data = $this->misc->getDatabaseAccessor(); |
||
472 | |||
473 | if (!isset($_POST['formSequenceName'])) { |
||
474 | $_POST['formSequenceName'] = ''; |
||
475 | } |
||
476 | |||
477 | if (!isset($_POST['formIncrement'])) { |
||
478 | $_POST['formIncrement'] = ''; |
||
479 | } |
||
480 | |||
481 | if (!isset($_POST['formMinValue'])) { |
||
482 | $_POST['formMinValue'] = ''; |
||
483 | } |
||
484 | |||
485 | if (!isset($_POST['formMaxValue'])) { |
||
486 | $_POST['formMaxValue'] = ''; |
||
487 | } |
||
488 | |||
489 | if (!isset($_POST['formStartValue'])) { |
||
490 | $_POST['formStartValue'] = ''; |
||
491 | } |
||
492 | |||
493 | if (!isset($_POST['formCacheValue'])) { |
||
494 | $_POST['formCacheValue'] = ''; |
||
495 | } |
||
496 | |||
497 | $this->printTrail('schema'); |
||
498 | $this->printTitle($this->lang['strcreatesequence'], 'pg.sequence.create'); |
||
499 | $this->printMsg($msg); |
||
500 | |||
501 | echo '<form action="'.\SUBFOLDER."/src/views/sequences\" method=\"post\">\n"; |
||
502 | echo "<table>\n"; |
||
503 | |||
504 | echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
505 | echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
506 | htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n"; |
||
507 | |||
508 | echo "<tr><th class=\"data left\">{$this->lang['strincrementby']}</th>\n"; |
||
509 | echo '<td class="data1"><input name="formIncrement" size="5" value="', |
||
510 | htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n"; |
||
511 | |||
512 | echo "<tr><th class=\"data left\">{$this->lang['strminvalue']}</th>\n"; |
||
513 | echo '<td class="data1"><input name="formMinValue" size="5" value="', |
||
514 | htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n"; |
||
515 | |||
516 | echo "<tr><th class=\"data left\">{$this->lang['strmaxvalue']}</th>\n"; |
||
517 | echo '<td class="data1"><input name="formMaxValue" size="5" value="', |
||
518 | htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n"; |
||
519 | |||
520 | echo "<tr><th class=\"data left\">{$this->lang['strstartvalue']}</th>\n"; |
||
521 | echo '<td class="data1"><input name="formStartValue" size="5" value="', |
||
522 | htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n"; |
||
523 | |||
524 | echo "<tr><th class=\"data left\">{$this->lang['strcachevalue']}</th>\n"; |
||
525 | echo '<td class="data1"><input name="formCacheValue" size="5" value="', |
||
526 | htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n"; |
||
527 | |||
528 | echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$this->lang['strcancycle']}</label></th>\n"; |
||
529 | echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ', |
||
530 | (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
||
531 | |||
532 | echo "</table>\n"; |
||
533 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n"; |
||
534 | echo $this->misc->form; |
||
535 | echo "<input type=\"submit\" name=\"create\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
536 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
537 | echo "</form>\n"; |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * Actually creates the new sequence in the database. |
||
542 | */ |
||
543 | public function doSaveCreateSequence() |
||
544 | { |
||
545 | $data = $this->misc->getDatabaseAccessor(); |
||
546 | |||
547 | // Check that they've given a name and at least one column |
||
548 | if ('' == $_POST['formSequenceName']) { |
||
549 | $this->doCreateSequence($this->lang['strsequenceneedsname']); |
||
550 | } else { |
||
551 | $status = $data->createSequence( |
||
552 | $_POST['formSequenceName'], |
||
553 | $_POST['formIncrement'], |
||
554 | $_POST['formMinValue'], |
||
555 | $_POST['formMaxValue'], |
||
556 | $_POST['formStartValue'], |
||
557 | $_POST['formCacheValue'], |
||
558 | isset($_POST['formCycledValue']) |
||
559 | ); |
||
560 | if (0 == $status) { |
||
561 | $this->doDefault($this->lang['strsequencecreated']); |
||
562 | } else { |
||
563 | $this->doCreateSequence($this->lang['strsequencecreatedbad']); |
||
564 | } |
||
565 | } |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * Restarts a sequence. |
||
570 | */ |
||
571 | public function doRestart() |
||
572 | { |
||
573 | $data = $this->misc->getDatabaseAccessor(); |
||
574 | |||
575 | $status = $data->restartSequence($_REQUEST['sequence']); |
||
576 | if (0 == $status) { |
||
577 | $this->doProperties($this->lang['strsequencerestart']); |
||
578 | } else { |
||
579 | $this->doProperties($this->lang['strsequencerestartbad']); |
||
580 | } |
||
581 | } |
||
582 | |||
583 | /** |
||
584 | * Resets a sequence. |
||
585 | */ |
||
586 | public function doReset() |
||
587 | { |
||
588 | $data = $this->misc->getDatabaseAccessor(); |
||
589 | |||
590 | $status = $data->resetSequence($_REQUEST['sequence']); |
||
591 | if (0 == $status) { |
||
592 | $this->doProperties($this->lang['strsequencereset']); |
||
593 | } else { |
||
594 | $this->doProperties($this->lang['strsequenceresetbad']); |
||
595 | } |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * Set Nextval of a sequence. |
||
600 | */ |
||
601 | public function doNextval() |
||
602 | { |
||
603 | $data = $this->misc->getDatabaseAccessor(); |
||
604 | |||
605 | $status = $data->nextvalSequence($_REQUEST['sequence']); |
||
606 | if (0 == $status) { |
||
607 | $this->doProperties($this->lang['strsequencenextval']); |
||
608 | } else { |
||
609 | $this->doProperties($this->lang['strsequencenextvalbad']); |
||
610 | } |
||
611 | } |
||
612 | |||
613 | /** |
||
614 | * Function to save after 'setval'ing a sequence. |
||
615 | */ |
||
616 | public function doSaveSetval() |
||
617 | { |
||
618 | $data = $this->misc->getDatabaseAccessor(); |
||
619 | |||
620 | $status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']); |
||
621 | if (0 == $status) { |
||
622 | $this->doProperties($this->lang['strsequencesetval']); |
||
623 | } else { |
||
624 | $this->doProperties($this->lang['strsequencesetvalbad']); |
||
625 | } |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * Function to allow 'setval'ing of a sequence. |
||
630 | * |
||
631 | * @param mixed $msg |
||
632 | */ |
||
633 | public function doSetval($msg = '') |
||
634 | { |
||
635 | $data = $this->misc->getDatabaseAccessor(); |
||
636 | |||
637 | $this->printTrail('sequence'); |
||
638 | $this->printTitle($this->lang['strsetval'], 'pg.sequence'); |
||
639 | $this->printMsg($msg); |
||
640 | |||
641 | // Fetch the sequence information |
||
642 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
643 | |||
644 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
645 | echo '<form action="'.\SUBFOLDER."/src/views/sequences\" method=\"post\">\n"; |
||
646 | echo '<table border="0">'; |
||
647 | echo "<tr><th class=\"data left required\">{$this->lang['strlastvalue']}</th>\n"; |
||
648 | echo '<td class="data1">'; |
||
649 | echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
650 | $this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n"; |
||
651 | echo "</table>\n"; |
||
652 | echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n"; |
||
653 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
654 | echo $this->misc->form; |
||
655 | echo "<input type=\"submit\" name=\"setval\" value=\"{$this->lang['strsetval']}\" />\n"; |
||
656 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
657 | echo "</form>\n"; |
||
658 | } else { |
||
659 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
660 | } |
||
661 | } |
||
662 | |||
663 | /** |
||
664 | * Function to save after altering a sequence. |
||
665 | */ |
||
666 | public function doSaveAlter() |
||
736 | } |
||
737 | } |
||
738 | |||
739 | /** |
||
740 | * Function to allow altering of a sequence. |
||
741 | * |
||
742 | * @param mixed $msg |
||
743 | */ |
||
744 | public function doAlter($msg = '') |
||
858 | } |
||
859 | } |
||
860 | } |
||
861 |