| Total Complexity | 156 |
| Total Lines | 1034 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like DisplayController 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 DisplayController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class DisplayController extends BaseController |
||
| 13 | { |
||
| 14 | public $controller_name = 'DisplayController'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Default method to render the controller according to the action parameter. |
||
| 18 | */ |
||
| 19 | public function render() |
||
| 20 | { |
||
| 21 | $conf = $this->conf; |
||
| 22 | $this->misc = $this->misc; |
||
| 23 | $lang = $this->lang; |
||
| 24 | $plugin_manager = $this->plugin_manager; |
||
|
1 ignored issue
–
show
|
|||
| 25 | $action = $this->action; |
||
| 26 | |||
| 27 | if ('dobrowsefk' == $action) { |
||
| 28 | return $this->doBrowseFK(); |
||
| 29 | } |
||
| 30 | |||
| 31 | set_time_limit(0); |
||
| 32 | |||
| 33 | $scripts = '<script src="' . \SUBFOLDER . '/js/display.js" type="text/javascript"></script>'; |
||
| 34 | |||
| 35 | $scripts .= '<script type="text/javascript">' . "\n"; |
||
| 36 | $scripts .= "var Display = {\n"; |
||
| 37 | $scripts .= "errmsg: '" . str_replace("'", "\\'", $lang['strconnectionfail']) . "'\n"; |
||
| 38 | $scripts .= "};\n"; |
||
| 39 | $scripts .= '</script>' . "\n"; |
||
| 40 | |||
| 41 | $footer_template = 'footer.twig'; |
||
| 42 | $header_template = 'header.twig'; |
||
| 43 | |||
| 44 | ob_start(); |
||
| 45 | switch ($action) { |
||
| 46 | case 'editrow': |
||
| 47 | $header_template = 'header_sqledit.twig'; |
||
| 48 | $footer_template = 'footer_sqledit.twig'; |
||
| 49 | if (isset($_POST['save'])) { |
||
| 50 | $this->doEditRow(false); |
||
| 51 | } else { |
||
| 52 | $this->doBrowse(); |
||
| 53 | } |
||
| 54 | |||
| 55 | break; |
||
| 56 | case 'confeditrow': |
||
| 57 | $this->doEditRow(true); |
||
| 58 | |||
| 59 | break; |
||
| 60 | case 'delrow': |
||
| 61 | $header_template = 'header_sqledit.twig'; |
||
| 62 | $footer_template = 'footer_sqledit.twig'; |
||
| 63 | if (isset($_POST['yes'])) { |
||
| 64 | $this->doDelRow(false); |
||
| 65 | } else { |
||
| 66 | $this->doBrowse(); |
||
| 67 | } |
||
| 68 | |||
| 69 | break; |
||
| 70 | case 'confdelrow': |
||
| 71 | $this->doDelRow(true); |
||
| 72 | |||
| 73 | break; |
||
| 74 | default: |
||
| 75 | $header_template = 'header_sqledit.twig'; |
||
| 76 | $footer_template = 'footer_sqledit.twig'; |
||
| 77 | $this->doBrowse(); |
||
| 78 | |||
| 79 | break; |
||
| 80 | } |
||
| 81 | $output = ob_get_clean(); |
||
| 82 | |||
| 83 | // Set the title based on the subject of the request |
||
| 84 | if (isset($_REQUEST['subject'], $_REQUEST[$_REQUEST['subject']])) { |
||
| 85 | if ('table' == $_REQUEST['subject']) { |
||
| 86 | $this->printHeader($lang['strtables'] . ': ' . $_REQUEST[$_REQUEST['subject']], $scripts, true, $header_template); |
||
| 87 | } elseif ('view' == $_REQUEST['subject']) { |
||
| 88 | $this->printHeader($lang['strviews'] . ': ' . $_REQUEST[$_REQUEST['subject']], $scripts, true, $header_template); |
||
| 89 | } elseif ('matview' == $_REQUEST['subject']) { |
||
| 90 | $this->printHeader('M' . $lang['strviews'] . ': ' . $_REQUEST[$_REQUEST['subject']], $scripts, true, $header_template); |
||
| 91 | } elseif ('column' == $_REQUEST['subject']) { |
||
| 92 | $this->printHeader($lang['strcolumn'] . ': ' . $_REQUEST[$_REQUEST['subject']], $scripts, true, $header_template); |
||
| 93 | } |
||
| 94 | } else { |
||
| 95 | $this->printHeader($lang['strqueryresults'], $scripts, true, $header_template); |
||
| 96 | } |
||
| 97 | |||
| 98 | $this->printBody(); |
||
| 99 | |||
| 100 | echo $output; |
||
| 101 | |||
| 102 | $this->printFooter(true, $footer_template); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Displays requested data. |
||
| 107 | * |
||
| 108 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 109 | */ |
||
| 110 | public function doBrowse($msg = '') |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Show confirmation of edit and perform actual update. |
||
| 577 | * |
||
| 578 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 579 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 580 | */ |
||
| 581 | public function doEditRow($confirm, $msg = '') |
||
| 582 | { |
||
| 583 | $lang = $this->lang; |
||
| 584 | $data = $this->misc->getDatabaseAccessor(); |
||
| 585 | |||
| 586 | if (is_array($_REQUEST['key'])) { |
||
| 587 | $key = $_REQUEST['key']; |
||
| 588 | } else { |
||
| 589 | $key = unserialize(urldecode($_REQUEST['key'])); |
||
| 590 | } |
||
| 591 | |||
| 592 | if ($confirm) { |
||
| 593 | $this->printTrail($_REQUEST['subject']); |
||
| 594 | $this->printTitle($lang['streditrow']); |
||
| 595 | $this->printMsg($msg); |
||
| 596 | |||
| 597 | $attrs = $data->getTableAttributes($_REQUEST['table']); |
||
| 598 | $resultset = $data->browseRow($_REQUEST['table'], $key); |
||
| 599 | |||
| 600 | if (('disable' != $this->conf['autocomplete'])) { |
||
| 601 | $fksprops = $this->misc->getAutocompleteFKProperties($_REQUEST['table']); |
||
| 602 | if (false !== $fksprops) { |
||
| 603 | echo $fksprops['code']; |
||
| 604 | } |
||
| 605 | } else { |
||
| 606 | $fksprops = false; |
||
| 607 | } |
||
| 608 | |||
| 609 | echo '<form action="' . \SUBFOLDER . '/src/views/display.php" method="post" id="ac_form">' . "\n"; |
||
| 610 | |||
| 611 | /*echo '<p>'; |
||
| 612 | if (!$error) { |
||
| 613 | echo "<input type=\"submit\" name=\"save\" accesskey=\"r\" value=\"{$lang['strsave']}\" />" . "\n"; |
||
| 614 | } |
||
| 615 | |||
| 616 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
||
| 617 | |||
| 618 | echo '</p>' . "\n";*/ |
||
| 619 | |||
| 620 | $elements = 0; |
||
| 621 | $error = true; |
||
| 622 | if (1 == $resultset->recordCount() && $attrs->recordCount() > 0) { |
||
| 623 | echo '<table>' . "\n"; |
||
| 624 | |||
| 625 | // Output table header |
||
| 626 | echo "<tr><th class=\"data\">{$lang['strcolumn']}</th><th class=\"data\">{$lang['strtype']}</th>"; |
||
| 627 | echo "<th class=\"data\">{$lang['strformat']}</th>" . "\n"; |
||
| 628 | echo "<th class=\"data\">{$lang['strnull']}</th><th class=\"data\">{$lang['strvalue']}</th></tr>"; |
||
| 629 | |||
| 630 | $i = 0; |
||
| 631 | while (!$attrs->EOF) { |
||
| 632 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
| 633 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 634 | |||
| 635 | // Initialise variables |
||
| 636 | if (!isset($_REQUEST['format'][$attrs->fields['attname']])) { |
||
| 637 | $_REQUEST['format'][$attrs->fields['attname']] = 'VALUE'; |
||
| 638 | } |
||
| 639 | |||
| 640 | echo "<tr class=\"data{$id}\">" . "\n"; |
||
| 641 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
| 642 | echo '<td style="white-space:nowrap;">' . "\n"; |
||
| 643 | echo $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])); |
||
| 644 | echo '<input type="hidden" name="types[', htmlspecialchars($attrs->fields['attname']), ']" value="', |
||
| 645 | htmlspecialchars($attrs->fields['type']), '" /></td>'; |
||
| 646 | ++$elements; |
||
| 647 | echo '<td style="white-space:nowrap;">' . "\n"; |
||
| 648 | echo '<select name="format[' . htmlspecialchars($attrs->fields['attname']), ']">' . "\n"; |
||
| 649 | echo '<option value="VALUE"', ($_REQUEST['format'][$attrs->fields['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>" . "\n"; |
||
| 650 | $selected = ($_REQUEST['format'][$attrs->fields['attname']] == 'EXPRESSION') ? ' selected="selected"' : ''; |
||
| 651 | echo '<option value="EXPRESSION"' . $selected . ">{$lang['strexpression']}</option>" . "\n"; |
||
| 652 | echo "</select>\n</td>" . "\n"; |
||
| 653 | ++$elements; |
||
| 654 | echo '<td style="white-space:nowrap;">'; |
||
| 655 | // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS) |
||
| 656 | if (!$attrs->fields['attnotnull']) { |
||
| 657 | // Set initial null values |
||
| 658 | if ('confeditrow' == $_REQUEST['action'] && null === $resultset->fields[$attrs->fields['attname']]) { |
||
| 659 | $_REQUEST['nulls'][$attrs->fields['attname']] = 'on'; |
||
| 660 | } |
||
| 661 | echo "<label><span><input type=\"checkbox\" name=\"nulls[{$attrs->fields['attname']}]\"", |
||
| 662 | isset($_REQUEST['nulls'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></span></label></td>' . "\n"; |
||
| 663 | ++$elements; |
||
| 664 | } else { |
||
| 665 | echo ' </td>'; |
||
| 666 | } |
||
| 667 | |||
| 668 | echo "<td id=\"row_att_{$attrs->fields['attnum']}\" style=\"white-space:nowrap;\">"; |
||
| 669 | |||
| 670 | $extras = []; |
||
| 671 | |||
| 672 | // If the column allows nulls, then we put a JavaScript action on the data field to unset the |
||
| 673 | // NULL checkbox as soon as anything is entered in the field. We use the $elements variable to |
||
| 674 | // keep track of which element offset we're up to. We can't refer to the null checkbox by name |
||
| 675 | // as it contains '[' and ']' characters. |
||
| 676 | if (!$attrs->fields['attnotnull']) { |
||
| 677 | $extras['onChange'] = 'elements[' . ($elements - 1) . '].checked = false;'; |
||
| 678 | } |
||
| 679 | |||
| 680 | if ((false !== $fksprops) && isset($fksprops['byfield'][$attrs->fields['attnum']])) { |
||
| 681 | $extras['id'] = "attr_{$attrs->fields['attnum']}"; |
||
| 682 | $extras['autocomplete'] = 'off'; |
||
| 683 | } |
||
| 684 | |||
| 685 | echo $data->printField("values[{$attrs->fields['attname']}]", $resultset->fields[$attrs->fields['attname']], $attrs->fields['type'], $extras); |
||
| 686 | |||
| 687 | echo '</td>'; |
||
| 688 | ++$elements; |
||
| 689 | echo '</tr>' . "\n"; |
||
| 690 | ++$i; |
||
| 691 | $attrs->moveNext(); |
||
| 692 | } |
||
| 693 | echo '</table>' . "\n"; |
||
| 694 | |||
| 695 | $error = false; |
||
| 696 | } elseif (1 != $resultset->recordCount()) { |
||
| 697 | echo "<p>{$lang['strrownotunique']}</p>" . "\n"; |
||
| 698 | } else { |
||
| 699 | echo "<p>{$lang['strinvalidparam']}</p>" . "\n"; |
||
| 700 | } |
||
| 701 | |||
| 702 | echo '<input type="hidden" name="action" value="editrow" />' . "\n"; |
||
| 703 | echo $this->misc->form; |
||
| 704 | if (isset($_REQUEST['table'])) { |
||
| 705 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />' . "\n"; |
||
| 706 | } |
||
| 707 | |||
| 708 | if (isset($_REQUEST['subject'])) { |
||
| 709 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), '" />' . "\n"; |
||
| 710 | } |
||
| 711 | |||
| 712 | if (isset($_REQUEST['query'])) { |
||
| 713 | echo '<input type="hidden" name="query" value="', htmlspecialchars($_REQUEST['query']), '" />' . "\n"; |
||
| 714 | } |
||
| 715 | |||
| 716 | if (isset($_REQUEST['count'])) { |
||
| 717 | echo '<input type="hidden" name="count" value="', htmlspecialchars($_REQUEST['count']), '" />' . "\n"; |
||
| 718 | } |
||
| 719 | |||
| 720 | if (isset($_REQUEST['return'])) { |
||
| 721 | echo '<input type="hidden" name="return" value="', htmlspecialchars($_REQUEST['return']), '" />' . "\n"; |
||
| 722 | } |
||
| 723 | |||
| 724 | echo '<input type="hidden" name="page" value="', htmlspecialchars($_REQUEST['page']), '" />' . "\n"; |
||
| 725 | echo '<input type="hidden" name="sortkey" value="', htmlspecialchars($_REQUEST['sortkey']), '" />' . "\n"; |
||
| 726 | echo '<input type="hidden" name="sortdir" value="', htmlspecialchars($_REQUEST['sortdir']), '" />' . "\n"; |
||
| 727 | echo '<input type="hidden" name="strings" value="', htmlspecialchars($_REQUEST['strings']), '" />' . "\n"; |
||
| 728 | echo '<input type="hidden" name="key" value="', htmlspecialchars(urlencode(serialize($key))), '" />' . "\n"; |
||
| 729 | echo '<p>'; |
||
| 730 | if (!$error) { |
||
| 731 | echo "<input type=\"submit\" name=\"save\" accesskey=\"r\" value=\"{$lang['strsave']}\" />" . "\n"; |
||
| 732 | } |
||
| 733 | |||
| 734 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
||
| 735 | |||
| 736 | if (false !== $fksprops) { |
||
| 737 | if ('default off' != $this->conf['autocomplete']) { |
||
| 738 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"1\" checked=\"checked\" /><label for=\"no_ac\">{$lang['strac']}</label>" . "\n"; |
||
| 739 | } else { |
||
| 740 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"0\" /><label for=\"no_ac\">{$lang['strac']}</label>" . "\n"; |
||
| 741 | } |
||
| 742 | } |
||
| 743 | |||
| 744 | echo '</p>' . "\n"; |
||
| 745 | echo '</form>' . "\n"; |
||
| 746 | } else { |
||
| 747 | if (!isset($_POST['values'])) { |
||
| 748 | $_POST['values'] = []; |
||
| 749 | } |
||
| 750 | |||
| 751 | if (!isset($_POST['nulls'])) { |
||
| 752 | $_POST['nulls'] = []; |
||
| 753 | } |
||
| 754 | |||
| 755 | $status = $data->editRow( |
||
| 756 | $_POST['table'], |
||
| 757 | $_POST['values'], |
||
| 758 | $_POST['nulls'], |
||
| 759 | $_POST['format'], |
||
| 760 | $_POST['types'], |
||
| 761 | $key |
||
| 762 | ); |
||
| 763 | if (0 == $status) { |
||
| 764 | $this->doBrowse($lang['strrowupdated']); |
||
| 765 | } elseif ($status == -2) { |
||
| 766 | $this->doEditRow(true, $lang['strrownotunique']); |
||
| 767 | } else { |
||
| 768 | $this->doEditRow(true, $lang['strrowupdatedbad']); |
||
| 769 | } |
||
| 770 | } |
||
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Show confirmation of drop and perform actual drop. |
||
| 775 | * |
||
| 776 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 777 | */ |
||
| 778 | public function doDelRow($confirm) |
||
| 779 | { |
||
| 780 | $lang = $this->lang; |
||
| 781 | $data = $this->misc->getDatabaseAccessor(); |
||
| 782 | |||
| 783 | if ($confirm) { |
||
| 784 | $this->printTrail($_REQUEST['subject']); |
||
| 785 | $this->printTitle($lang['strdeleterow']); |
||
| 786 | |||
| 787 | $resultset = $data->browseRow($_REQUEST['table'], $_REQUEST['key']); |
||
| 788 | |||
| 789 | echo '<form action="' . \SUBFOLDER . '/src/views/display.php" method="post">' . "\n"; |
||
| 790 | echo $this->misc->form; |
||
| 791 | |||
| 792 | if (1 == $resultset->recordCount()) { |
||
| 793 | echo "<p>{$lang['strconfdeleterow']}</p>" . "\n"; |
||
| 794 | |||
| 795 | $fkinfo = []; |
||
| 796 | echo '<table><tr>'; |
||
| 797 | $this->printTableHeaderCells($resultset, false, true); |
||
| 798 | echo '</tr>'; |
||
| 799 | echo '<tr class="data1">' . "\n"; |
||
| 800 | $this->printTableRowCells($resultset, $fkinfo, true); |
||
| 801 | echo '</tr>' . "\n"; |
||
| 802 | echo '</table>' . "\n"; |
||
| 803 | echo '<br />' . "\n"; |
||
| 804 | |||
| 805 | echo '<input type="hidden" name="action" value="delrow" />' . "\n"; |
||
| 806 | echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />" . "\n"; |
||
| 807 | echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />" . "\n"; |
||
| 808 | } elseif (1 != $resultset->recordCount()) { |
||
| 809 | echo "<p>{$lang['strrownotunique']}</p>" . "\n"; |
||
| 810 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
||
| 811 | } else { |
||
| 812 | echo "<p>{$lang['strinvalidparam']}</p>" . "\n"; |
||
| 813 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
||
| 814 | } |
||
| 815 | if (isset($_REQUEST['table'])) { |
||
| 816 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />' . "\n"; |
||
| 817 | } |
||
| 818 | |||
| 819 | if (isset($_REQUEST['subject'])) { |
||
| 820 | echo '<input type="hidden" name="subject" value="', htmlspecialchars($_REQUEST['subject']), '" />' . "\n"; |
||
| 821 | } |
||
| 822 | |||
| 823 | if (isset($_REQUEST['query'])) { |
||
| 824 | echo '<input type="hidden" name="query" value="', htmlspecialchars($_REQUEST['query']), '" />' . "\n"; |
||
| 825 | } |
||
| 826 | |||
| 827 | if (isset($_REQUEST['count'])) { |
||
| 828 | echo '<input type="hidden" name="count" value="', htmlspecialchars($_REQUEST['count']), '" />' . "\n"; |
||
| 829 | } |
||
| 830 | |||
| 831 | if (isset($_REQUEST['return'])) { |
||
| 832 | echo '<input type="hidden" name="return" value="', htmlspecialchars($_REQUEST['return']), '" />' . "\n"; |
||
| 833 | } |
||
| 834 | |||
| 835 | echo '<input type="hidden" name="page" value="', htmlspecialchars($_REQUEST['page']), '" />' . "\n"; |
||
| 836 | echo '<input type="hidden" name="sortkey" value="', htmlspecialchars($_REQUEST['sortkey']), '" />' . "\n"; |
||
| 837 | echo '<input type="hidden" name="sortdir" value="', htmlspecialchars($_REQUEST['sortdir']), '" />' . "\n"; |
||
| 838 | echo '<input type="hidden" name="strings" value="', htmlspecialchars($_REQUEST['strings']), '" />' . "\n"; |
||
| 839 | echo '<input type="hidden" name="key" value="', htmlspecialchars(urlencode(serialize($_REQUEST['key']))), '" />' . "\n"; |
||
| 840 | echo '</form>' . "\n"; |
||
| 841 | } else { |
||
| 842 | $status = $data->deleteRow($_POST['table'], unserialize(urldecode($_POST['key']))); |
||
| 843 | if (0 == $status) { |
||
| 844 | $this->doBrowse($lang['strrowdeleted']); |
||
| 845 | } elseif ($status == -2) { |
||
| 846 | $this->doBrowse($lang['strrownotunique']); |
||
| 847 | } else { |
||
| 848 | $this->doBrowse($lang['strrowdeletedbad']); |
||
| 849 | } |
||
| 850 | } |
||
| 851 | } |
||
| 852 | |||
| 853 | /** |
||
| 854 | * build & return the FK information data structure |
||
|
1 ignored issue
–
show
|
|||
| 855 | * used when deciding if a field should have a FK link or not. |
||
| 856 | * |
||
| 857 | * @return [type] [description] |
||
| 858 | */ |
||
| 859 | public function &getFKInfo() |
||
| 860 | { |
||
| 861 | $lang = $this->lang; |
||
| 862 | $data = $this->misc->getDatabaseAccessor(); |
||
| 863 | |||
| 864 | // Get the foreign key(s) information from the current table |
||
| 865 | $fkey_information = ['byconstr' => [], 'byfield' => []]; |
||
| 866 | |||
| 867 | if (isset($_REQUEST['table'])) { |
||
| 868 | $constraints = $data->getConstraintsWithFields($_REQUEST['table']); |
||
| 869 | if ($constraints->recordCount() > 0) { |
||
| 870 | $fkey_information['common_url'] = $this->misc->getHREF('schema') . '&subject=table'; |
||
| 871 | |||
| 872 | // build the FK constraints data structure |
||
| 873 | while (!$constraints->EOF) { |
||
| 874 | $constr = &$constraints->fields; |
||
| 875 | if ('f' == $constr['contype']) { |
||
| 876 | if (!isset($fkey_information['byconstr'][$constr['conid']])) { |
||
| 877 | $fkey_information['byconstr'][$constr['conid']] = [ |
||
| 878 | 'url_data' => 'table=' . urlencode($constr['f_table']) . '&schema=' . urlencode($constr['f_schema']), |
||
| 879 | 'fkeys' => [], |
||
| 880 | 'consrc' => $constr['consrc'], |
||
| 881 | ]; |
||
| 882 | } |
||
| 883 | |||
| 884 | $fkey_information['byconstr'][$constr['conid']]['fkeys'][$constr['p_field']] = $constr['f_field']; |
||
| 885 | |||
| 886 | if (!isset($fkey_information['byfield'][$constr['p_field']])) { |
||
| 887 | $fkey_information['byfield'][$constr['p_field']] = []; |
||
| 888 | } |
||
| 889 | |||
| 890 | $fkey_information['byfield'][$constr['p_field']][] = $constr['conid']; |
||
| 891 | } |
||
| 892 | $constraints->moveNext(); |
||
| 893 | } |
||
| 894 | } |
||
| 895 | } |
||
| 896 | |||
| 897 | return $fkey_information; |
||
| 898 | } |
||
| 899 | |||
| 900 | /** |
||
| 901 | * Print table header cells. |
||
| 902 | * |
||
| 903 | * @param $args - associative array for sort link parameters |
||
| 904 | * @param mixed $withOid |
||
|
1 ignored issue
–
show
|
|||
| 905 | */ |
||
| 906 | public function printTableHeaderCells(&$resultset, $args, $withOid) |
||
| 907 | { |
||
| 908 | $lang = $this->lang; |
||
| 909 | $data = $this->misc->getDatabaseAccessor(); |
||
| 910 | $j = 0; |
||
| 911 | |||
| 912 | foreach ($resultset->fields as $k => $v) { |
||
| 913 | if (($k === $data->id) && (!($withOid && $this->conf['show_oids']))) { |
||
| 914 | ++$j; |
||
| 915 | |||
| 916 | continue; |
||
| 917 | } |
||
| 918 | $finfo = $resultset->fetchField($j); |
||
| 919 | |||
| 920 | if (false === $args) { |
||
| 921 | echo '<th class="data">', $this->misc->printVal($finfo->name), '</th>' . "\n"; |
||
| 922 | } else { |
||
| 923 | $args['page'] = $_REQUEST['page']; |
||
| 924 | $args['sortkey'] = $j + 1; |
||
| 925 | // Sort direction opposite to current direction, unless it's currently '' |
||
| 926 | $args['sortdir'] = ( |
||
| 927 | 'asc' == $_REQUEST['sortdir'] |
||
| 928 | and $_REQUEST['sortkey'] == ($j + 1) |
||
| 929 | ) ? 'desc' : 'asc'; |
||
| 930 | |||
| 931 | $sortLink = http_build_query($args); |
||
| 932 | |||
| 933 | echo "<th class=\"data\"><a href=\"?{$sortLink}\">" |
||
| 934 | , $this->misc->printVal($finfo->name); |
||
| 935 | if ($_REQUEST['sortkey'] == ($j + 1)) { |
||
| 936 | if ('asc' == $_REQUEST['sortdir']) { |
||
| 937 | echo '<img src="' . $this->misc->icon('RaiseArgument') . '" alt="asc">'; |
||
| 938 | } else { |
||
| 939 | echo '<img src="' . $this->misc->icon('LowerArgument') . '" alt="desc">'; |
||
| 940 | } |
||
| 941 | } |
||
| 942 | echo '</a></th>' . "\n"; |
||
| 943 | } |
||
| 944 | ++$j; |
||
| 945 | } |
||
| 946 | |||
| 947 | reset($resultset->fields); |
||
| 948 | } |
||
| 949 | |||
| 950 | // Print data-row cells |
||
| 951 | public function printTableRowCells(&$resultset, &$fkey_information, $withOid) |
||
|
1 ignored issue
–
show
|
|||
| 952 | { |
||
| 953 | $lang = $this->lang; |
||
| 954 | $data = $this->misc->getDatabaseAccessor(); |
||
| 955 | $j = 0; |
||
| 956 | |||
| 957 | if (!isset($_REQUEST['strings'])) { |
||
| 958 | $_REQUEST['strings'] = 'collapsed'; |
||
| 959 | } |
||
| 960 | |||
| 961 | foreach ($resultset->fields as $k => $v) { |
||
| 962 | $finfo = $resultset->fetchField($j++); |
||
| 963 | |||
| 964 | if (($k === $data->id) && (!($withOid && $this->conf['show_oids']))) { |
||
| 965 | continue; |
||
| 966 | } |
||
| 967 | if (null !== $v && '' == $v) { |
||
| 968 | echo '<td> </td>'; |
||
| 969 | } else { |
||
| 970 | echo '<td style="white-space:nowrap;">'; |
||
| 971 | |||
| 972 | if ((null !== $v) && isset($fkey_information['byfield'][$k])) { |
||
| 973 | foreach ($fkey_information['byfield'][$k] as $conid) { |
||
| 974 | $query_params = $fkey_information['byconstr'][$conid]['url_data']; |
||
| 975 | |||
| 976 | foreach ($fkey_information['byconstr'][$conid]['fkeys'] as $p_field => $f_field) { |
||
| 977 | $query_params .= '&' . urlencode("fkey[{$f_field}]") . '=' . urlencode($resultset->fields[$p_field]); |
||
| 978 | } |
||
| 979 | |||
| 980 | // $fkey_information['common_url'] is already urlencoded |
||
| 981 | $query_params .= '&' . $fkey_information['common_url']; |
||
| 982 | echo '<div style="display:inline-block;">'; |
||
| 983 | echo '<a class="fk fk_' . htmlentities($conid, ENT_QUOTES, 'UTF-8') . "\" href=\"display.php?{$query_params}\">"; |
||
| 984 | echo '<img src="' . $this->misc->icon('ForeignKey') . '" style="vertical-align:middle;" alt="[fk]" title="' |
||
| 985 | . htmlentities($fkey_information['byconstr'][$conid]['consrc'], ENT_QUOTES, 'UTF-8') |
||
| 986 | . '" />'; |
||
| 987 | echo '</a>'; |
||
| 988 | echo '</div>'; |
||
| 989 | } |
||
| 990 | echo $this->misc->printVal($v, $finfo->type, ['null' => true, 'clip' => ('collapsed' == $_REQUEST['strings']), 'class' => 'fk_value']); |
||
| 991 | } else { |
||
| 992 | echo $this->misc->printVal($v, $finfo->type, ['null' => true, 'clip' => ('collapsed' == $_REQUEST['strings'])]); |
||
| 993 | } |
||
| 994 | echo '</td>'; |
||
| 995 | } |
||
| 996 | } |
||
| 997 | } |
||
| 998 | |||
| 999 | // Print the FK row, used in ajax requests |
||
| 1000 | public function doBrowseFK() |
||
| 1046 | } |
||
| 1047 | } |
||
| 1048 |