Skip to content

Commit

Permalink
Merge pull request #14531 from Piyush3079/PMA_14530
Browse files Browse the repository at this point in the history
Add method getHtmlForColumnDropdown in CentralColumns.php
  • Loading branch information
MauricioFauth committed Aug 1, 2018
2 parents 7209ef9 + 229deb9 commit 6416623
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
27 changes: 27 additions & 0 deletions libraries/classes/CentralColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,33 @@ public function getColumnsCount(string $db, int $from = 0, int $num = 25): int
return -1;
}

/**
* build dropdown select html to select column in selected table,
* include only columns which are not already in central list
*
* @param string $db current database to which selected table belongs
* @param string $selected_tbl selected table
*
* @return string html to select column
*/
public function getHtmlForColumnDropdown($db, $selected_tbl)
{
$existing_cols = $this->getFromTable($db, $selected_tbl);
$this->dbi->selectDb($db);
$columns = (array) $this->dbi->getColumnNames(
$db, $selected_tbl
);
$selectColHtml = "";
foreach ($columns as $column) {
if (!in_array($column, $existing_cols)) {
$selectColHtml .= '<option value="' . htmlspecialchars($column) . '">'
. htmlspecialchars($column)
. '</option>';
}
}
return $selectColHtml;
}

/**
* build html for adding a new user defined column to central list
*
Expand Down
20 changes: 20 additions & 0 deletions test/classes/CentralColumnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,24 @@ public function testGetTableFooter()
$result
);
}

/**
* Test for getHtmlForColumnDropdown
*
* @return void
*/
public function testGetHtmlForColumnDropdown()
{
$db = 'PMA_db';
$selected_tbl = 'PMA_table';
$result = $this->centralColumns->getHtmlForColumnDropdown(
$db,
$selected_tbl
);
$this->assertEquals(
'<option value="id">id</option><option value="col1">col1</option>'
. '<option value="col2">col2</option>',
$result
);
}
}

0 comments on commit 6416623

Please sign in to comment.