diff --git a/browse_foreigners.php b/browse_foreigners.php index 6b31352799..8412321cc9 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -38,10 +38,15 @@ $header->setBodyId('body_browse_foreigners'); /** * Displays the frame */ - $foreigners = Relation::getForeigners($db, $table); -$foreign_limit = BrowseForeigners::getForeignLimit( +$browseForeigners = new BrowseForeigners( + $GLOBALS['cfg']['LimitChars'], $GLOBALS['cfg']['MaxRows'], + $GLOBALS['cfg']['RepeatCells'], + $GLOBALS['cfg']['ShowAll'], + $GLOBALS['pmaThemeImage'] +); +$foreign_limit = $browseForeigners->getForeignLimit( isset($_REQUEST['foreign_showAll']) ? $_REQUEST['foreign_showAll'] : null ); @@ -55,12 +60,7 @@ $foreignData = Relation::getForeignData( ); // HTML output -$html = BrowseForeigners::getHtmlForRelationalFieldSelection( - $GLOBALS['cfg']['RepeatCells'], - $GLOBALS['pmaThemeImage'], - $GLOBALS['cfg']['MaxRows'], - $GLOBALS['cfg']['ShowAll'], - $GLOBALS['cfg']['LimitChars'], +$html = $browseForeigners->getHtmlForRelationalFieldSelection( $db, $table, $_REQUEST['field'], diff --git a/libraries/classes/BrowseForeigners.php b/libraries/classes/BrowseForeigners.php index 2ca1746673..b41ed78f2a 100644 --- a/libraries/classes/BrowseForeigners.php +++ b/libraries/classes/BrowseForeigners.php @@ -18,6 +18,35 @@ use PhpMyAdmin\Util; */ class BrowseForeigners { + private $limitChars; + private $maxRows; + private $repeatCells; + private $showAll; + private $themeImage; + + /** + * Constructor + * + * @param int $limitChars Maximum number of characters to show + * @param int $maxRows Number of rows to display + * @param int $repeatCells Repeat the headers every X cells, or 0 to deactivate + * @param boolean $showAll Shows the 'Show all' button or not + * @param string $themeImage Theme image path + */ + public function __construct( + $limitChars, + $maxRows, + $repeatCells, + $showAll, + $themeImage + ) { + $this->limitChars = (int) $limitChars; + $this->maxRows = (int) $maxRows; + $this->repeatCells = (int) $repeatCells; + $this->showAll = (bool) $showAll; + $this->themeImage = $themeImage; + } + /** * Function to get html for one relational key * @@ -31,10 +60,7 @@ class BrowseForeigners * * @return string $html the generated html */ - public static function getHtmlForOneKey( - $repeatCells, - $pmaThemeImage, - $limitChars, + private function getHtmlForOneKey( $horizontal_count, $header, array $keys, @@ -50,7 +76,7 @@ class BrowseForeigners $rightKeynameIsSelected = false; $leftKeynameIsSelected = false; - if ($repeatCells > 0 && $horizontal_count > $repeatCells) { + if ($this->repeatCells > 0 && $horizontal_count > $this->repeatCells) { $output .= $header; $horizontal_count = 0; } @@ -61,10 +87,7 @@ class BrowseForeigners list( $leftDescription, $leftDescriptionTitle - ) = self::getDescriptionAndTitle( - $limitChars, - $descriptions[$indexByKeyname] - ); + ) = $this->getDescriptionAndTitle($descriptions[$indexByKeyname]); // key names and descriptions for the right section, // sorted by descriptions @@ -72,10 +95,7 @@ class BrowseForeigners list( $rightDescription, $rightDescriptionTitle - ) = self::getDescriptionAndTitle( - $limitChars, - $descriptions[$indexByDescription] - ); + ) = $this->getDescriptionAndTitle($descriptions[$indexByDescription]); $indexByDescription++; @@ -102,7 +122,7 @@ class BrowseForeigners ]); $output .= '