| Total Complexity | 66 |
| Total Lines | 505 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 0 |
Complex classes like ViewsMatviewsTrait 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 ViewsMatviewsTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | trait ViewsMatviewsTrait |
||
| 15 | { |
||
| 16 | public $href = ''; |
||
| 17 | |||
| 18 | public $misc; |
||
| 19 | |||
| 20 | public $view_name; |
||
| 21 | |||
| 22 | public function doSubTree() |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Ask for select parameters and perform select. |
||
| 52 | * |
||
| 53 | * @param mixed $confirm |
||
| 54 | * @param mixed $msg |
||
| 55 | */ |
||
| 56 | public function doSelectRows($confirm, $msg = '') |
||
| 57 | { |
||
| 58 | $data = $this->misc->getDatabaseAccessor(); |
||
| 59 | |||
| 60 | if ($confirm) { |
||
| 61 | $this->printTrail($this->keystring); |
||
| 62 | $this->printTabs($this->keystring, 'select'); |
||
| 63 | $this->printMsg($msg); |
||
| 64 | |||
| 65 | $attrs = $data->getTableAttributes($_REQUEST[$this->keystring]); |
||
| 66 | |||
| 67 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/' . $this->script . '" method="post" id="selectform">'; |
||
| 68 | echo \PHP_EOL; |
||
| 69 | |||
| 70 | if (0 < $attrs->recordCount()) { |
||
| 71 | // JavaScript for select all feature |
||
| 72 | echo '<script type="text/javascript">' . \PHP_EOL; |
||
| 73 | echo "//<![CDATA[\n"; |
||
| 74 | echo " function selectAll() {\n"; |
||
| 75 | echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
||
| 76 | echo " var e = document.getElementById('selectform').elements[i];\n"; |
||
| 77 | echo " if (e.name.indexOf('show') == 0) { \n "; |
||
| 78 | echo " e.checked = document.getElementById('selectform').selectall.checked;\n"; |
||
| 79 | echo " }\n"; |
||
| 80 | echo " }\n"; |
||
| 81 | echo " }\n"; |
||
| 82 | echo '//]]>' . \PHP_EOL; |
||
| 83 | echo '</script>' . \PHP_EOL; |
||
| 84 | |||
| 85 | echo '<table>' . \PHP_EOL; |
||
| 86 | |||
| 87 | // Output table header |
||
| 88 | echo "<tr><th class=\"data\">{$this->lang['strshow']}</th><th class=\"data\">{$this->lang['strcolumn']}</th>"; |
||
| 89 | echo "<th class=\"data\">{$this->lang['strtype']}</th><th class=\"data\">{$this->lang['stroperator']}</th>"; |
||
| 90 | echo "<th class=\"data\">{$this->lang['strvalue']}</th></tr>"; |
||
| 91 | |||
| 92 | $i = 0; |
||
| 93 | |||
| 94 | while (!$attrs->EOF) { |
||
| 95 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
| 96 | // Set up default value if there isn't one already |
||
| 97 | if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
||
| 98 | $_REQUEST['values'][$attrs->fields['attname']] = null; |
||
| 99 | } |
||
| 100 | |||
| 101 | if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
||
| 102 | $_REQUEST['ops'][$attrs->fields['attname']] = null; |
||
| 103 | } |
||
| 104 | |||
| 105 | // Continue drawing row |
||
| 106 | $id = (0 === ($i % 2) ? '1' : '2'); |
||
| 107 | echo "<tr class=\"data{$id}\">" . \PHP_EOL; |
||
| 108 | echo '<td style="white-space:nowrap;">'; |
||
| 109 | echo '<input type="checkbox" name="show[', \htmlspecialchars($attrs->fields['attname']), ']"', |
||
| 110 | isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
||
| 111 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
| 112 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
||
| 113 | echo '<td style="white-space:nowrap;">'; |
||
| 114 | echo "<select name=\"ops[{$attrs->fields['attname']}]\">" . \PHP_EOL; |
||
| 115 | |||
| 116 | foreach (\array_keys($data->selectOps) as $v) { |
||
| 117 | echo '<option value="', \htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] === $v) ? ' selected="selected"' : '', |
||
| 118 | '>', \htmlspecialchars($v), '</option>' . \PHP_EOL; |
||
| 119 | } |
||
| 120 | echo '</select></td>' . \PHP_EOL; |
||
| 121 | echo '<td style="white-space:nowrap;">'; |
||
| 122 | echo $data->printField( |
||
| 123 | "values[{$attrs->fields['attname']}]", |
||
| 124 | $_REQUEST['values'][$attrs->fields['attname']], |
||
| 125 | $attrs->fields['type'] |
||
| 126 | ); |
||
| 127 | echo '</td></tr>' . \PHP_EOL; |
||
| 128 | ++$i; |
||
| 129 | $attrs->moveNext(); |
||
| 130 | } |
||
| 131 | // Select all checkbox |
||
| 132 | 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>"; |
||
|
|
|||
| 133 | echo '</table>' . \PHP_EOL; |
||
| 134 | } else { |
||
| 135 | echo "<p>{$this->lang['strinvalidparam']}</p>" . \PHP_EOL; |
||
| 136 | } |
||
| 137 | |||
| 138 | echo '<p><input type="hidden" name="action" value="selectrows" />' . \PHP_EOL; |
||
| 139 | echo '<input type="hidden" name="view" value="', \htmlspecialchars($_REQUEST[$this->keystring]), '" />' . \PHP_EOL; |
||
| 140 | echo '<input type="hidden" name="subject" value="view" />' . \PHP_EOL; |
||
| 141 | echo $this->view->form; |
||
| 142 | echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$this->lang['strselect']}\" />" . \PHP_EOL; |
||
| 143 | echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
||
| 144 | echo '</form>' . \PHP_EOL; |
||
| 145 | |||
| 146 | return; |
||
| 147 | } |
||
| 148 | $this->coalesceArr($_POST, 'show', []); |
||
| 149 | |||
| 150 | $this->coalesceArr($_POST, 'values', []); |
||
| 151 | |||
| 152 | $this->coalesceArr($_POST, 'nulls', []); |
||
| 153 | |||
| 154 | // Verify that they haven't supplied a value for unary operators |
||
| 155 | foreach ($_POST['ops'] as $k => $v) { |
||
| 156 | if ('p' === $data->selectOps[$v] && '' !== $_POST['values'][$k]) { |
||
| 157 | $this->doSelectRows(true, $this->lang['strselectunary']); |
||
| 158 | |||
| 159 | return; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | if (0 === \count($_POST['show'])) { |
||
| 164 | return $this->doSelectRows(true, $this->lang['strselectneedscol']); |
||
| 165 | } |
||
| 166 | // Generate query SQL |
||
| 167 | $query = $data->getSelectSQL($_REQUEST[$this->keystring], \array_keys($_POST['show']), $_POST['values'], $_POST['ops']); |
||
| 168 | |||
| 169 | $_REQUEST['query'] = $query; |
||
| 170 | $_REQUEST['return'] = 'schema'; |
||
| 171 | |||
| 172 | $this->setNoOutput(true); |
||
| 173 | |||
| 174 | $display_controller = new \PHPPgAdmin\Controller\DisplayController($this->getContainer()); |
||
| 175 | |||
| 176 | return $display_controller->render(); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Prints the form wizard to create view or materialized view. |
||
| 181 | */ |
||
| 182 | public function printWizardCreateForm(): void |
||
| 183 | { |
||
| 184 | $data = $this->misc->getDatabaseAccessor(); |
||
| 185 | |||
| 186 | $tables = $data->getAllTables(); |
||
| 187 | |||
| 188 | echo '<form action="' . \containerInstance()->subFolder . "/src/views/{$this->script}\" method=\"post\">" . \PHP_EOL; |
||
| 189 | echo '<table>' . \PHP_EOL; |
||
| 190 | echo "<tr><th class=\"data\">{$this->lang['strtables']}</th></tr>"; |
||
| 191 | echo "<tr>\n<td class=\"data1\">" . \PHP_EOL; |
||
| 192 | |||
| 193 | $arrTables = []; |
||
| 194 | |||
| 195 | while (!$tables->EOF) { |
||
| 196 | $arrTmp = []; |
||
| 197 | $arrTmp['schemaname'] = $tables->fields['nspname']; |
||
| 198 | $arrTmp['tablename'] = $tables->fields['relname']; |
||
| 199 | $schema_and_name = $tables->fields['nspname'] . '.' . $tables->fields['relname']; |
||
| 200 | $arrTables[$schema_and_name] = \serialize($arrTmp); |
||
| 201 | $tables->moveNext(); |
||
| 202 | } |
||
| 203 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrTables, 'formTables[]', false, '', true); |
||
| 204 | |||
| 205 | echo "</td>\n</tr>" . \PHP_EOL; |
||
| 206 | echo '</table>' . \PHP_EOL; |
||
| 207 | echo '<p><input type="hidden" name="action" value="set_params_create" />' . \PHP_EOL; |
||
| 208 | echo $this->view->form; |
||
| 209 | echo "<input type=\"submit\" value=\"{$this->lang['strnext']}\" />" . \PHP_EOL; |
||
| 210 | echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
||
| 211 | echo '</form>' . \PHP_EOL; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Actually creates the new wizard view in the database. |
||
| 216 | * |
||
| 217 | * @param bool $is_materialized true if it's a materialized view, false by default |
||
| 218 | * |
||
| 219 | * @return mixed either a sucess message, a redirection, an error message and who knows |
||
| 220 | */ |
||
| 221 | public function doSaveCreateWiz($is_materialized = false) |
||
| 222 | { |
||
| 223 | $data = $this->misc->getDatabaseAccessor(); |
||
| 224 | |||
| 225 | // Check that they've given a name and fields they want to select |
||
| 226 | |||
| 227 | if (!\mb_strlen($_POST['formView'])) { |
||
| 228 | return $this->doSetParamsCreate($this->lang['strviewneedsname']); |
||
| 229 | } |
||
| 230 | |||
| 231 | if (!isset($_POST['formFields']) || !\count($_POST['formFields'])) { |
||
| 232 | return $this->doSetParamsCreate($this->lang['strviewneedsfields']); |
||
| 233 | } |
||
| 234 | $selFields = ''; |
||
| 235 | |||
| 236 | $tmpHsh = []; |
||
| 237 | |||
| 238 | foreach ($_POST['formFields'] as $curField) { |
||
| 239 | $arrTmp = \unserialize($curField); |
||
| 240 | $data->fieldArrayClean($arrTmp); |
||
| 241 | |||
| 242 | $this->_appendToSelFields($arrTmp, $selFields, $tmpHsh); |
||
| 243 | } |
||
| 244 | |||
| 245 | $selFields = \mb_substr($selFields, 0, -2); |
||
| 246 | unset($arrTmp, $tmpHsh); |
||
| 247 | $linkFields = ''; |
||
| 248 | $arrJoined = []; |
||
| 249 | $arrUsedTbls = []; |
||
| 250 | |||
| 251 | [$arrLinks, $count] = $this->_getArrLinks(); |
||
| 252 | |||
| 253 | // If we have at least one join condition, output it |
||
| 254 | |||
| 255 | $j = 0; |
||
| 256 | |||
| 257 | while ($j < $count) { |
||
| 258 | foreach ($arrLinks as $curLink) { |
||
| 259 | $arrLeftLink = \unserialize($curLink['leftlink']); |
||
| 260 | $arrRightLink = \unserialize($curLink['rightlink']); |
||
| 261 | $data->fieldArrayClean($arrLeftLink); |
||
| 262 | $data->fieldArrayClean($arrRightLink); |
||
| 263 | |||
| 264 | $tbl1 = "\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\""; |
||
| 265 | $tbl2 = "\"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\""; |
||
| 266 | |||
| 267 | if (!((!\in_array($curLink, $arrJoined, true) && \in_array($tbl1, $arrUsedTbls, true)) || !\count($arrJoined))) { |
||
| 268 | continue; |
||
| 269 | } |
||
| 270 | // Make sure for multi-column foreign keys that we use a table alias tables joined to more than once |
||
| 271 | // This can (and should be) more optimized for multi-column foreign keys |
||
| 272 | $adj_tbl2 = \in_array($tbl2, $arrUsedTbls, true) ? "{$tbl2} AS alias_ppa_" . \time() : $tbl2; |
||
| 273 | |||
| 274 | $clause1 = "{$curLink['operator']} {$adj_tbl2} ON ({$tbl1}.\"{$arrLeftLink['fieldname']}\" = {$tbl2}.\"{$arrRightLink['fieldname']}\") "; |
||
| 275 | $clause2 = "{$tbl1} {$curLink['operator']} {$adj_tbl2} ON ({$tbl1}.\"{$arrLeftLink['fieldname']}\" = {$tbl2}.\"{$arrRightLink['fieldname']}\") "; |
||
| 276 | |||
| 277 | $linkFields .= \mb_strlen($linkFields) ? $clause1 : $clause2; |
||
| 278 | |||
| 279 | $arrJoined[] = $curLink; |
||
| 280 | |||
| 281 | if (!\in_array($tbl1, $arrUsedTbls, true)) { |
||
| 282 | $arrUsedTbls[] = $tbl1; |
||
| 283 | } |
||
| 284 | |||
| 285 | if (!\in_array($tbl2, $arrUsedTbls, true)) { |
||
| 286 | $arrUsedTbls[] = $tbl2; |
||
| 287 | } |
||
| 288 | } |
||
| 289 | ++$j; |
||
| 290 | } |
||
| 291 | |||
| 292 | //if linkFields has no length then either _POST['formLink'] was not set, or there were no join conditions |
||
| 293 | //just select from all seleted tables - a cartesian join do a |
||
| 294 | if (!\mb_strlen($linkFields)) { |
||
| 295 | foreach ($_POST['formTables'] as $curTable) { |
||
| 296 | $arrTmp = \unserialize($curTable); |
||
| 297 | $data->fieldArrayClean($arrTmp); |
||
| 298 | $linkFields .= (\mb_strlen($linkFields) ? ', ' : ' ') . "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\""; |
||
| 299 | } |
||
| 300 | } |
||
| 301 | |||
| 302 | $addConditions = ''; |
||
| 303 | |||
| 304 | if (\is_array($_POST['formCondition'])) { |
||
| 305 | foreach ($_POST['formCondition'] as $curCondition) { |
||
| 306 | if (\mb_strlen($curCondition['field']) && \mb_strlen($curCondition['txt'])) { |
||
| 307 | $arrTmp = \unserialize($curCondition['field']); |
||
| 308 | $data->fieldArrayClean($arrTmp); |
||
| 309 | $condition = " \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' "; |
||
| 310 | $addConditions .= (\mb_strlen($addConditions) ? ' AND ' : ' ') . $condition; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | } |
||
| 314 | |||
| 315 | $viewQuery = "SELECT {$selFields} FROM {$linkFields} "; |
||
| 316 | |||
| 317 | //add where from additional conditions |
||
| 318 | if (\mb_strlen($addConditions)) { |
||
| 319 | $viewQuery .= ' WHERE ' . $addConditions; |
||
| 320 | } |
||
| 321 | |||
| 322 | try { |
||
| 323 | $status = $data->createView($_POST['formView'], $viewQuery, false, $_POST['formComment'], $is_materialized); |
||
| 324 | |||
| 325 | if (0 === $status) { |
||
| 326 | $this->view->setReloadBrowser(true); |
||
| 327 | |||
| 328 | return $this->doDefault($this->lang['strviewcreated']); |
||
| 329 | } |
||
| 330 | |||
| 331 | return $this->doSetParamsCreate($this->lang['strviewcreatedbad']); |
||
| 332 | } catch (\PHPPgAdmin\ADOdbException $e) { |
||
| 333 | return $this->halt($e->getMessage()); |
||
| 334 | } |
||
| 335 | } |
||
| 336 | |||
| 337 | public function printParamsCreateForm(): void |
||
| 338 | { |
||
| 339 | $data = $this->misc->getDatabaseAccessor(); |
||
| 340 | |||
| 341 | $tblCount = \count($_POST['formTables']); |
||
| 342 | $arrSelTables = []; |
||
| 343 | //unserialize our schema/table information and store in arrSelTables |
||
| 344 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 345 | $arrSelTables[] = \unserialize($_POST['formTables'][$i]); |
||
| 346 | } |
||
| 347 | |||
| 348 | //get linking keys |
||
| 349 | $rsLinkKeys = $data->getLinkingKeys($arrSelTables); |
||
| 350 | $linkCount = $rsLinkKeys->recordCount() > $tblCount ? $rsLinkKeys->recordCount() : $tblCount; |
||
| 351 | |||
| 352 | $arrFields = []; //array that will hold all our table/field names |
||
| 353 | |||
| 354 | //if we have schemas we need to specify the correct schema for each table we're retrieiving |
||
| 355 | //with getTableAttributes |
||
| 356 | $curSchema = $data->_schema; |
||
| 357 | |||
| 358 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 359 | if ($arrSelTables[$i]['schemaname'] !== $data->_schema) { |
||
| 360 | $data->setSchema($arrSelTables[$i]['schemaname']); |
||
| 361 | } |
||
| 362 | |||
| 363 | $attrs = $data->getTableAttributes($arrSelTables[$i]['tablename']); |
||
| 364 | |||
| 365 | while (!$attrs->EOF) { |
||
| 366 | $arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->fields['attname']}"] = \serialize( |
||
| 367 | [ |
||
| 368 | 'schemaname' => $arrSelTables[$i]['schemaname'], |
||
| 369 | 'tablename' => $arrSelTables[$i]['tablename'], |
||
| 370 | 'fieldname' => $attrs->fields['attname'], ] |
||
| 371 | ); |
||
| 372 | $attrs->moveNext(); |
||
| 373 | } |
||
| 374 | |||
| 375 | $data->setSchema($curSchema); |
||
| 376 | } |
||
| 377 | \asort($arrFields); |
||
| 378 | |||
| 379 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/materializedviews" method="post">' . \PHP_EOL; |
||
| 380 | echo '<table>' . \PHP_EOL; |
||
| 381 | echo "<tr><th class=\"data\">{$this->lang['strviewname']}</th></tr>"; |
||
| 382 | echo "<tr>\n<td class=\"data1\">" . \PHP_EOL; |
||
| 383 | // View name |
||
| 384 | echo '<input name="formView" value="' . \htmlspecialchars($_REQUEST['formView']) . "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />" . \PHP_EOL; |
||
| 385 | echo "</td>\n</tr>" . \PHP_EOL; |
||
| 386 | echo "<tr><th class=\"data\">{$this->lang['strcomment']}</th></tr>"; |
||
| 387 | echo "<tr>\n<td class=\"data1\">" . \PHP_EOL; |
||
| 388 | // View comments |
||
| 389 | echo '<textarea name="formComment" rows="3" cols="32">' . \htmlspecialchars($_REQUEST['formComment']) . '</textarea>' . \PHP_EOL; |
||
| 390 | echo "</td>\n</tr>" . \PHP_EOL; |
||
| 391 | echo '</table>' . \PHP_EOL; |
||
| 392 | |||
| 393 | // Output selector for fields to be retrieved from view |
||
| 394 | echo '<table>' . \PHP_EOL; |
||
| 395 | echo "<tr><th class=\"data\">{$this->lang['strcolumns']}</th></tr>"; |
||
| 396 | echo "<tr>\n<td class=\"data1\">" . \PHP_EOL; |
||
| 397 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, 'formFields[]', false, '', true); |
||
| 398 | echo "</td>\n</tr>"; |
||
| 399 | echo '<tr><td>'; |
||
| 400 | echo \sprintf('<input type="radio" name="dblFldMeth" id="dblFldMeth1" value="rename" /><label for="dblFldMeth1">%s</label><br>', $this->lang['strrenamedupfields']); |
||
| 401 | echo \sprintf('<input type="radio" name="dblFldMeth" id="dblFldMeth2" value="drop" /><label for="dblFldMeth2">%s</label><br>', $this->lang['strdropdupfields']); |
||
| 402 | echo \sprintf('<input type="radio" name="dblFldMeth" id="dblFldMeth3" value="" checked="checked" /><label for="dblFldMeth3">%s</label>', $this->lang['strerrordupfields']); |
||
| 403 | echo '</td></tr></table><br />'; |
||
| 404 | |||
| 405 | // Output the Linking keys combo boxes |
||
| 406 | echo '<table>' . \PHP_EOL; |
||
| 407 | echo "<tr><th class=\"data\">{$this->lang['strviewlink']}</th></tr>"; |
||
| 408 | $rowClass = 'data1'; |
||
| 409 | $formLink = []; |
||
| 410 | |||
| 411 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 412 | // Initialise variables |
||
| 413 | $formLink[$i] = $formLink[$i] ?? []; |
||
| 414 | $this->coalesceArr($formLink[$i], 'operator', 'INNER JOIN'); |
||
| 415 | |||
| 416 | echo "<tr>\n<td class=\"{$rowClass}\">" . \PHP_EOL; |
||
| 417 | |||
| 418 | if (!$rsLinkKeys->EOF) { |
||
| 419 | $curLeftLink = \htmlspecialchars(\serialize(['schemaname' => $rsLinkKeys->fields['p_schema'], 'tablename' => $rsLinkKeys->fields['p_table'], 'fieldname' => $rsLinkKeys->fields['p_field']])); |
||
| 420 | $curRightLink = \htmlspecialchars(\serialize(['schemaname' => $rsLinkKeys->fields['f_schema'], 'tablename' => $rsLinkKeys->fields['f_table'], 'fieldname' => $rsLinkKeys->fields['f_field']])); |
||
| 421 | $rsLinkKeys->moveNext(); |
||
| 422 | } else { |
||
| 423 | $curLeftLink = ''; |
||
| 424 | $curRightLink = ''; |
||
| 425 | } |
||
| 426 | |||
| 427 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[{$i}][leftlink]", true, $curLeftLink, false); |
||
| 428 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($data->joinOps, "formLink[{$i}][operator]", true, $formLink[$i]['operator']); |
||
| 429 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[{$i}][rightlink]", true, $curRightLink, false); |
||
| 430 | echo "</td>\n</tr>" . \PHP_EOL; |
||
| 431 | $rowClass = 'data1' === $rowClass ? 'data2' : 'data1'; |
||
| 432 | } |
||
| 433 | echo "</table>\n<br />" . \PHP_EOL; |
||
| 434 | |||
| 435 | // Build list of available operators (infix only) |
||
| 436 | $arrOperators = []; |
||
| 437 | |||
| 438 | foreach ($data->selectOps as $k => $v) { |
||
| 439 | if ('i' === $v) { |
||
| 440 | $arrOperators[$k] = $k; |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | // Output additional conditions, note that this portion of the wizard treats the right hand side as literal values |
||
| 445 | //(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins |
||
| 446 | echo '<table>' . \PHP_EOL; |
||
| 447 | echo "<tr><th class=\"data\">{$this->lang['strviewconditions']}</th></tr>"; |
||
| 448 | $rowClass = 'data1'; |
||
| 449 | |||
| 450 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 451 | echo "<tr>\n<td class=\"{$rowClass}\">" . \PHP_EOL; |
||
| 452 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formCondition[{$i}][field]"); |
||
| 453 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrOperators, "formCondition[{$i}][operator]", false, '', false); |
||
| 454 | echo "<input type=\"text\" name=\"formCondition[{$i}][txt]\" />" . \PHP_EOL; |
||
| 455 | echo "</td>\n</tr>" . \PHP_EOL; |
||
| 456 | $rowClass = 'data1' === $rowClass ? 'data2' : 'data1'; |
||
| 457 | } |
||
| 458 | echo '</table>' . \PHP_EOL; |
||
| 459 | echo '<p><input type="hidden" name="action" value="save_create_wiz" />' . \PHP_EOL; |
||
| 460 | |||
| 461 | foreach ($arrSelTables as $curTable) { |
||
| 462 | echo '<input type="hidden" name="formTables[]" value="' . \htmlspecialchars(\serialize($curTable)) . '" />' . \PHP_EOL; |
||
| 463 | } |
||
| 464 | |||
| 465 | echo $this->view->form; |
||
| 466 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />" . \PHP_EOL; |
||
| 467 | echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
||
| 468 | echo '</form>' . \PHP_EOL; |
||
| 469 | } |
||
| 470 | |||
| 471 | abstract public function doSetParamsCreate($msg = ''); |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Appends to selected fields. |
||
| 475 | * |
||
| 476 | * @param array $arrTmp The arr temporary |
||
| 477 | * @param string $selFields The selected fields |
||
| 478 | * @param array $tmpHsh The temporary hsh |
||
| 479 | */ |
||
| 480 | private function _appendToSelFields($arrTmp, &$selFields, &$tmpHsh): void |
||
| 481 | { |
||
| 482 | $field_arr = [$arrTmp['schemaname'], $arrTmp['tablename'], $arrTmp['fieldname']]; |
||
| 483 | |||
| 484 | $field_element = '"' . \implode('"."', $field_arr) . '"'; |
||
| 485 | |||
| 486 | if (empty($_POST['dblFldMeth'])) { |
||
| 487 | // no doublon control |
||
| 488 | $selFields .= $field_element . ', '; |
||
| 489 | } elseif (empty($tmpHsh[$arrTmp['fieldname']])) { |
||
| 490 | // field does not exist |
||
| 491 | $selFields .= $field_element . ', '; |
||
| 492 | $tmpHsh[$arrTmp['fieldname']] = 1; |
||
| 493 | } elseif ('rename' === $_POST['dblFldMeth']) { |
||
| 494 | // field exist and must be renamed |
||
| 495 | ++$tmpHsh[$arrTmp['fieldname']]; |
||
| 496 | $selFields .= $field_element . ' AS "' . \implode('_', $field_arr) . '_' . $tmpHsh[$arrTmp['fieldname']] . '", '; |
||
| 497 | } |
||
| 498 | // if field already exist, just ignore this one |
||
| 499 | } |
||
| 500 | |||
| 501 | private function _getArrLinks() |
||
| 519 | } |
||
| 520 | } |
||
| 521 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.