<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Controllers\Table\SearchController
*
* @package PhpMyAdmin\Controllers
*/
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Table;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
/**
* Class SearchController
*
* @package PhpMyAdmin\Controllers
*/
class SearchController extends AbstractController
{
/**
* Normal search or Zoom search
*
* @access private
* @var string
*/
private $_searchType;
/**
* Names of columns
*
* @access private
* @var array
*/
private $_columnNames;
/**
* Types of columns
*
* @access private
* @var array
*/
private $_columnTypes;
/**
* Collations of columns
*
* @access private
* @var array
*/
private $_columnCollations;
/**
* Null Flags of columns
*
* @access private
* @var array
*/
private $_columnNullFlags;
/**
* Whether a geometry column is present
*
* @access private
* @var boolean
*/
private $_geomColumnFlag;
/**
* Foreign Keys
*
* @access private
* @var array
*/
private $_foreigners;
/**
* Connection charset
*
* @access private
* @var string
*/
private $_connectionCharSet;
protected $url_query;
/**
* @var Relation
*/
private $relation;
/**
* Constructor
*
* @param Response $response Response object
* @param DatabaseInterface $dbi DatabaseInterface object
* @param Template $template Template object
* @param string $db Database name
* @param string $table Table name
* @param string $searchType Search type
* @param string $url_query URL query
* @param Relation $relation Relation instance
*/
public function __construct(
$response,
$dbi,
Template $template,
$db,
$table,
$searchType,
$url_query,
Relation $relation
) {
parent::__construct($response, $dbi, $template, $db, $table);
$this->url_query = $url_query;
$this->_searchType = $searchType;
$this->_columnNames = [];
$this->_columnNullFlags = [];
$this->_columnTypes = [];
$this->_columnCollations = [];
$this->_geomColumnFlag = false;
$this->_foreigners = [];
$this->relation = $relation;
// Loads table's information
$this->_loadTableInfo();
$this->_connectionCharSet = $this->dbi->fetchValue(
"SELECT @@character_set_connection"
);
}
/**
* Gets all the columns of a table along with their types, collations
* and whether null or not.
*
* @return void
*/
private function _loadTableInfo()
{
// Gets the list and number of columns
$columns = $this->dbi->getColumns(
$this->db,
$this->table,
null,
true
);
// Get details about the geometry functions
$geom_types = Util::getGISDatatypes();
foreach ($columns as $row) {
// set column name
$this->_columnNames[] = $row['Field'];
$type = $row['Type'];
// check whether table contains geometric columns
if (in_array($type, $geom_types)) {
$this->_geomColumnFlag = true;
}
// reformat mysql query output
if (strncasecmp($type, 'set', 3) == 0
|| strncasecmp($type, 'enum', 4) == 0
) {
$type = str_replace(',', ', ', $type);
} else {
// strip the "BINARY" attribute, except if we find "BINARY(" because
// this would be a BINARY or VARBINARY column type
if (! preg_match('@BINARY[\(]@i', $type)) {
$type = str_ireplace("BINARY", '', $type);
}
$type = str_ireplace("ZEROFILL", '', $type);
$type = str_ireplace("UNSIGNED", '', $type);
$type = mb_strtolower($type);
}
if (empty($type)) {
$type = ' ';
}
|