| Conditions | 16 |
| Paths | 3241 |
| Total Lines | 138 |
| Code Lines | 90 |
| 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 |
||
| 345 | public function doSetParamsCreate($msg = '') |
||
| 346 | { |
||
| 347 | $data = $this->misc->getDatabaseAccessor(); |
||
| 348 | |||
| 349 | // Check that they've chosen tables for the view definition |
||
| 350 | if (!isset($_POST['formTables'])) { |
||
| 351 | $this->doWizardCreate($this->lang['strviewneedsdef']); |
||
| 352 | } else { |
||
| 353 | // Initialise variables |
||
| 354 | $this->coalesceArr($_REQUEST, 'formView', ''); |
||
| 355 | |||
| 356 | $this->coalesceArr($_REQUEST, 'formComment', ''); |
||
| 357 | |||
| 358 | $this->printTrail('schema'); |
||
| 359 | $this->printTitle($this->lang['strcreatematviewwiz'], 'pg.matview.create'); |
||
| 360 | $this->printMsg($msg); |
||
| 361 | |||
| 362 | $tblCount = sizeof($_POST['formTables']); |
||
| 363 | //unserialize our schema/table information and store in arrSelTables |
||
| 364 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 365 | $arrSelTables[] = unserialize($_POST['formTables'][$i]); |
||
| 366 | } |
||
| 367 | |||
| 368 | //get linking keys |
||
| 369 | $rsLinkKeys = $data->getLinkingKeys($arrSelTables); |
||
|
|
|||
| 370 | $linkCount = $rsLinkKeys->recordCount() > $tblCount ? $rsLinkKeys->recordCount() : $tblCount; |
||
| 371 | |||
| 372 | $arrFields = []; //array that will hold all our table/field names |
||
| 373 | |||
| 374 | //if we have schemas we need to specify the correct schema for each table we're retrieiving |
||
| 375 | //with getTableAttributes |
||
| 376 | $curSchema = $data->_schema; |
||
| 377 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 378 | if ($arrSelTables[$i]['schemaname'] != $data->_schema) { |
||
| 379 | $data->setSchema($arrSelTables[$i]['schemaname']); |
||
| 380 | } |
||
| 381 | |||
| 382 | $attrs = $data->getTableAttributes($arrSelTables[$i]['tablename']); |
||
| 383 | while (!$attrs->EOF) { |
||
| 384 | $arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->fields['attname']}"] = serialize( |
||
| 385 | [ |
||
| 386 | 'schemaname' => $arrSelTables[$i]['schemaname'], |
||
| 387 | 'tablename' => $arrSelTables[$i]['tablename'], |
||
| 388 | 'fieldname' => $attrs->fields['attname'], ] |
||
| 389 | ); |
||
| 390 | $attrs->moveNext(); |
||
| 391 | } |
||
| 392 | |||
| 393 | $data->setSchema($curSchema); |
||
| 394 | } |
||
| 395 | asort($arrFields); |
||
| 396 | |||
| 397 | echo '<form action="'.\SUBFOLDER."/src/views/materializedviews\" method=\"post\">\n"; |
||
| 398 | echo "<table>\n"; |
||
| 399 | echo "<tr><th class=\"data\">{$this->lang['strviewname']}</th></tr>"; |
||
| 400 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 401 | // View name |
||
| 402 | echo '<input name="formView" value="', htmlspecialchars($_REQUEST['formView']), "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
||
| 403 | echo "</td>\n</tr>\n"; |
||
| 404 | echo "<tr><th class=\"data\">{$this->lang['strcomment']}</th></tr>"; |
||
| 405 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 406 | // View comments |
||
| 407 | echo '<textarea name="formComment" rows="3" cols="32">', |
||
| 408 | htmlspecialchars($_REQUEST['formComment']), "</textarea>\n"; |
||
| 409 | echo "</td>\n</tr>\n"; |
||
| 410 | echo "</table>\n"; |
||
| 411 | |||
| 412 | // Output selector for fields to be retrieved from view |
||
| 413 | echo "<table>\n"; |
||
| 414 | echo "<tr><th class=\"data\">{$this->lang['strcolumns']}</th></tr>"; |
||
| 415 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 416 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, 'formFields[]', false, '', true); |
||
| 417 | echo "</td>\n</tr>"; |
||
| 418 | echo "<tr><td><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth1\" value=\"rename\" /><label for=\"dblFldMeth1\">{$this->lang['strrenamedupfields']}</label>"; |
||
| 419 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth2\" value=\"drop\" /><label for=\"dblFldMeth2\">{$this->lang['strdropdupfields']}</label>"; |
||
| 420 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth3\" value=\"\" checked=\"checked\" /><label for=\"dblFldMeth3\">{$this->lang['strerrordupfields']}</label></td></tr></table><br />"; |
||
| 421 | |||
| 422 | // Output the Linking keys combo boxes |
||
| 423 | echo "<table>\n"; |
||
| 424 | echo "<tr><th class=\"data\">{$this->lang['strviewlink']}</th></tr>"; |
||
| 425 | $rowClass = 'data1'; |
||
| 426 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 427 | // Initialise variables |
||
| 428 | if (!isset($formLink[$i]['operator'])) { |
||
| 429 | $formLink[$i]['operator'] = 'INNER JOIN'; |
||
| 430 | } |
||
| 431 | |||
| 432 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
| 433 | |||
| 434 | if (!$rsLinkKeys->EOF) { |
||
| 435 | $curLeftLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['p_schema'], 'tablename' => $rsLinkKeys->fields['p_table'], 'fieldname' => $rsLinkKeys->fields['p_field']])); |
||
| 436 | $curRightLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['f_schema'], 'tablename' => $rsLinkKeys->fields['f_table'], 'fieldname' => $rsLinkKeys->fields['f_field']])); |
||
| 437 | $rsLinkKeys->moveNext(); |
||
| 438 | } else { |
||
| 439 | $curLeftLink = ''; |
||
| 440 | $curRightLink = ''; |
||
| 441 | } |
||
| 442 | |||
| 443 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][leftlink]", true, $curLeftLink, false); |
||
| 444 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($data->joinOps, "formLink[${i}][operator]", true, $formLink[$i]['operator']); |
||
| 445 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][rightlink]", true, $curRightLink, false); |
||
| 446 | echo "</td>\n</tr>\n"; |
||
| 447 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
| 448 | } |
||
| 449 | echo "</table>\n<br />\n"; |
||
| 450 | |||
| 451 | // Build list of available operators (infix only) |
||
| 452 | $arrOperators = []; |
||
| 453 | foreach ($data->selectOps as $k => $v) { |
||
| 454 | if ('i' == $v) { |
||
| 455 | $arrOperators[$k] = $k; |
||
| 456 | } |
||
| 457 | } |
||
| 458 | |||
| 459 | // Output additional conditions, note that this portion of the wizard treats the right hand side as literal values |
||
| 460 | //(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins |
||
| 461 | echo "<table>\n"; |
||
| 462 | echo "<tr><th class=\"data\">{$this->lang['strviewconditions']}</th></tr>"; |
||
| 463 | $rowClass = 'data1'; |
||
| 464 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 465 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
| 466 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formCondition[${i}][field]"); |
||
| 467 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrOperators, "formCondition[${i}][operator]", false, '', false); |
||
| 468 | echo "<input type=\"text\" name=\"formCondition[${i}][txt]\" />\n"; |
||
| 469 | echo "</td>\n</tr>\n"; |
||
| 470 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
| 471 | } |
||
| 472 | echo "</table>\n"; |
||
| 473 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_wiz\" />\n"; |
||
| 474 | |||
| 475 | foreach ($arrSelTables as $curTable) { |
||
| 476 | echo '<input type="hidden" name="formTables[]" value="'.htmlspecialchars(serialize($curTable))."\" />\n"; |
||
| 477 | } |
||
| 478 | |||
| 479 | echo $this->misc->form; |
||
| 480 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 481 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 482 | echo "</form>\n"; |
||
| 483 | } |
||
| 566 |