From 763e161355df3bce18b2537e8ae5f4fc3eb6b170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 3 Feb 2018 22:11:39 -0200 Subject: [PATCH] Move MaxRows setting to constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- db_central_columns.php | 4 --- libraries/classes/CentralColumns.php | 41 ++++++++++++++-------------- test/classes/CentralColumnsTest.php | 5 ---- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/db_central_columns.php b/db_central_columns.php index 4da66d7d01..bc18cd1dad 100644 --- a/db_central_columns.php +++ b/db_central_columns.php @@ -88,7 +88,6 @@ if (isset($_REQUEST['edit_central_columns_page'])) { $selected_fld = $_REQUEST['selected_fld']; $selected_db = $_REQUEST['db']; $edit_central_column_page = $centralColumns->getHtmlForEditingPage( - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], $selected_fld, @@ -123,7 +122,6 @@ if (Core::isValid($_REQUEST['pos'], 'integer')) { $pos = 0; } $addNewColumn = $centralColumns->getHtmlForAddNewColumn( - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], $db, @@ -141,7 +139,6 @@ if ($total_rows <= 0) { exit; } $table_navigation_html = $centralColumns->getHtmlForTableNavigation( - $GLOBALS['cfg']['MaxRows'], $total_rows, $pos, $db @@ -170,7 +167,6 @@ $result = $centralColumns->getColumnsList($db, $pos, $max_rows); $row_num = 0; foreach ($result as $row) { $tableHtmlRow = $centralColumns->getHtmlForTableRow( - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], $row, diff --git a/libraries/classes/CentralColumns.php b/libraries/classes/CentralColumns.php index 182b9f50fa..ddded1f7ce 100644 --- a/libraries/classes/CentralColumns.php +++ b/libraries/classes/CentralColumns.php @@ -36,6 +36,13 @@ class CentralColumns */ private $user; + /** + * Number of rows displayed when browsing a result set + * + * @var int + */ + private $maxRows; + /** * Constructor * @@ -46,6 +53,7 @@ class CentralColumns $this->dbi = $dbi; $this->user = $GLOBALS['cfg']['Server']['user']; + $this->maxRows = (int) $GLOBALS['cfg']['MaxRows']; } /** @@ -141,6 +149,7 @@ class CentralColumns return 0; } + /** * return the existing columns in central list among the given list of columns * @@ -661,28 +670,27 @@ class CentralColumns /** * get the html for table navigation in Central columns page * - * @param string $max_rows number of rows displayed when browsing a result set * @param int $total_rows total number of rows in complete result set * @param int $pos offset of first result with complete result set * @param string $db current database * * @return string html for table navigation in Central columns page */ - public function getHtmlForTableNavigation($max_rows, $total_rows, $pos, $db) + public function getHtmlForTableNavigation($total_rows, $pos, $db) { - $pageNow = ($pos / $max_rows) + 1; - $nbTotalPage = ceil($total_rows / $max_rows); + $pageNow = ($pos / $this->maxRows) + 1; + $nbTotalPage = ceil($total_rows / $this->maxRows); $table_navigation_html = '' . '' . ''; - if ($pos - $max_rows >= 0) { + if ($pos - $this->maxRows >= 0) { $table_navigation_html .= ''; } - if ($pos + $max_rows < $total_rows) { + if ($pos + $this->maxRows < $total_rows) { $table_navigation_html .= ''; $tableHtml .= @@ -1069,7 +1075,6 @@ class CentralColumns /** * build html for editing a row in central columns table * - * @param string $maxRows number of rows displayed when browsing a result set * @param string $charEditing which editor should be used for CHAR/VARCHAR fields * @param boolean $disableIs Disable use of INFORMATION_SCHEMA * @param array $row array contains complete information of a @@ -1079,7 +1084,6 @@ class CentralColumns * @return string html of a particular row in the central columns table. */ private function getHtmlForEditTableRow( - $maxRows, $charEditing, $disableIs, array $row, @@ -1099,7 +1103,7 @@ class CentralColumns 'cfg_relation' => array( 'centralcolumnswork' => false ), - 'max_rows' => intval($maxRows), + 'max_rows' => $this->maxRows, )) . ''; $tableHtml .= @@ -1336,7 +1340,6 @@ class CentralColumns /** * build html for adding a new user defined column to central list * - * @param string $maxRows number of rows displayed when browsing a result set * @param string $charEditing which editor should be used for CHAR/VARCHAR fields * @param boolean $disableIs Disable use of INFORMATION_SCHEMA * @param string $db current database @@ -1346,7 +1349,6 @@ class CentralColumns * list */ public function getHtmlForAddNewColumn( - $maxRows, $charEditing, $disableIs, $db, @@ -1375,7 +1377,7 @@ class CentralColumns 'cfg_relation' => array( 'centralcolumnswork' => false ), - 'max_rows' => intval($maxRows), + 'max_rows' => $this->maxRows, )) . '' . '
' . '
' . Url::getHiddenInputs( $db ) - . '' + . '' . '' . ''; $table_navigation_html .= Util::pageselector( - 'pos', $max_rows, $pageNow, $nbTotalPage + 'pos', $this->maxRows, $pageNow, $nbTotalPage ); $table_navigation_html .= '
' . '
' . '
' . Url::getHiddenInputs( $db ) - . '' + . '' . '' . ' array( 'centralcolumnswork' => false ), - 'max_rows' => intval($maxRows), + 'max_rows' => $this->maxRows, )) . '
' @@ -1468,7 +1470,6 @@ class CentralColumns /** * Get HTML for editing page central columns * - * @param string $maxRows number of rows displayed when browsing a result set * @param string $charEditing which editor should be used for CHAR/VARCHAR fields * @param boolean $disableIs Disable use of INFORMATION_SCHEMA * @param array $selected_fld Array containing the selected fields @@ -1477,7 +1478,6 @@ class CentralColumns * @return string HTML for complete editing page for central columns */ public function getHtmlForEditingPage( - $maxRows, $charEditing, $disableIs, array $selected_fld, @@ -1499,7 +1499,6 @@ class CentralColumns $row_num = 0; foreach ($list_detail_cols as $row) { $tableHtmlRow = $this->getHtmlForEditTableRow( - $maxRows, $charEditing, $disableIs, $row, diff --git a/test/classes/CentralColumnsTest.php b/test/classes/CentralColumnsTest.php index af3eb0d09b..848a7c9b4c 100644 --- a/test/classes/CentralColumnsTest.php +++ b/test/classes/CentralColumnsTest.php @@ -435,7 +435,6 @@ class CentralColumnsTest extends TestCase $this->returnValue($this->columnData) ); $result = $this->centralColumns->getHtmlForEditingPage( - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], array("col1", "col2"), @@ -468,7 +467,6 @@ class CentralColumnsTest extends TestCase $this->callProtectedMethod( 'getHtmlForEditTableRow', [ - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], $list_detail_cols[0], @@ -492,7 +490,6 @@ class CentralColumnsTest extends TestCase public function testGetHtmlForTableNavigation() { $result = $this->centralColumns->getHtmlForTableNavigation( - $GLOBALS['cfg']['MaxRows'], 0, 0, 'phpmyadmin' @@ -506,7 +503,6 @@ class CentralColumnsTest extends TestCase $result ); $result_1 = $this->centralColumns->getHtmlForTableNavigation( - $GLOBALS['cfg']['MaxRows'], 25, 10, 'phpmyadmin' @@ -615,7 +611,6 @@ class CentralColumnsTest extends TestCase public function testGetHtmlForAddNewColumn() { $result = $this->centralColumns->getHtmlForAddNewColumn( - $GLOBALS['cfg']['MaxRows'], $GLOBALS['cfg']['CharEditing'], $GLOBALS['cfg']['Server']['DisableIS'], 'phpmyadmin',