mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 06:38:00 +02:00
Search filter was failing when $listQry contained a JOIN. Fixed. Old JOIN methods require cleanup/removal.
This commit is contained in:
@@ -2177,6 +2177,13 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
*/
|
*/
|
||||||
protected $joinAlias = array();
|
protected $joinAlias = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of fields detected from listQry which are JOINs
|
||||||
|
* @example returns array('user_name'=>'u.user_name'); from $listQry = "SELECT n.*,u.user_name FROM #news...."etc.
|
||||||
|
*/
|
||||||
|
protected $joinField = array();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main model table alias
|
* Main model table alias
|
||||||
* @var string
|
* @var string
|
||||||
@@ -2496,7 +2503,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return ($prefix ? '#' : '').$this->getModel()->getModelTable();
|
return ($prefix ? '#' : '').$this->getModel()->getModelTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIfTableAlias($prefix = false, $quote = false)
|
public function getIfTableAlias($prefix = false, $quote = false) //XXX May no longer by useful. see joinAlias()
|
||||||
{
|
{
|
||||||
$alias = $this->getTableName(true);
|
$alias = $this->getTableName(true);
|
||||||
if($alias)
|
if($alias)
|
||||||
@@ -2507,13 +2514,13 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get join table data
|
* Get join table data - XXX DEPRECATE?
|
||||||
* @param string $table if null all data will be returned
|
* @param string $table if null all data will be returned
|
||||||
* @param string $att_name search for specific attribute, default null (no search)
|
* @param string $att_name search for specific attribute, default null (no search)
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getJoinData($table = null, $att_name = null, $default_att = null)
|
public function getJoinData($table = null, $att_name = null, $default_att = null)
|
||||||
{
|
{
|
||||||
if(null === $table)
|
if(null === $table)
|
||||||
{
|
{
|
||||||
return $this->tableJoin;
|
return $this->tableJoin;
|
||||||
@@ -2525,7 +2532,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return (isset($this->tableJoin[$table][$att_name]) ? $this->tableJoin[$table][$att_name] : $default_att);
|
return (isset($this->tableJoin[$table][$att_name]) ? $this->tableJoin[$table][$att_name] : $default_att);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setJoinData($table, $data)
|
public function setJoinData($table, $data) //XXX - DEPRECATE?
|
||||||
{
|
{
|
||||||
if(null === $data)
|
if(null === $data)
|
||||||
{
|
{
|
||||||
@@ -2999,6 +3006,25 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an alias such as 'u' or 'n.news_datestamp' - will return the associated table such as 'user' or 'news'
|
||||||
|
*/
|
||||||
|
function getTableFromAlias($alias)
|
||||||
|
{
|
||||||
|
if(strpos($alias,".")!==false)
|
||||||
|
{
|
||||||
|
list($alias,$tmp) = explode(".",$alias,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = array_flip($this->joinAlias);
|
||||||
|
return vartrue($tmp[$alias]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getJoinField($field)
|
||||||
|
{
|
||||||
|
return vartrue($this->joinField[$field],false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses all available field data, adds internal attributes for handling join requests
|
* Parses all available field data, adds internal attributes for handling join requests
|
||||||
* @return e_admin_controller_ui
|
* @return e_admin_controller_ui
|
||||||
@@ -3008,7 +3034,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
if($this->_alias_parsed) return $this; // already parsed!!!
|
if($this->_alias_parsed) return $this; // already parsed!!!
|
||||||
|
|
||||||
|
|
||||||
|
/* OUTDATED.
|
||||||
if($this->getJoinData())
|
if($this->getJoinData())
|
||||||
{
|
{
|
||||||
foreach ($this->getJoinData() as $table => $att)
|
foreach ($this->getJoinData() as $table => $att)
|
||||||
@@ -3032,7 +3058,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
$this->setJoinData($table, $att);
|
$this->setJoinData($table, $att);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
$this->joinAlias(); // generate Table Aliases from listQry
|
$this->joinAlias(); // generate Table Aliases from listQry
|
||||||
@@ -3041,22 +3067,36 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
$fields = array(); // preserve order
|
$fields = array(); // preserve order
|
||||||
foreach ($this->fields as $field => $att)
|
foreach ($this->fields as $field => $att)
|
||||||
{
|
{
|
||||||
// tableAlias.fieldName.fieldAlias
|
// fieldAlias.fieldName // table name no longer required as it's included in listQry. (see joinAlias() )
|
||||||
if(strpos($field, '.') !== false) // manually entered alias.
|
if(strpos($field, '.') !== false) // manually entered alias.
|
||||||
{
|
{
|
||||||
$tmp = explode('.', $field, 3);
|
$tmp = explode('.', $field, 2);
|
||||||
$att['table'] = $tmp[0] ? $tmp[0] : $this->getIfTableAlias(false);
|
$table = $this->getTableFromAlias($tmp[0]);
|
||||||
$att['alias'] = vartrue($tmp[2]);
|
$att['table'] = $table;
|
||||||
|
$att['alias'] = $field;
|
||||||
$att['field'] = $tmp[1];
|
$att['field'] = $tmp[1];
|
||||||
$field = $att['alias'] ? $att['alias'] : $tmp[1];
|
$att['__tableField'] = $field;
|
||||||
|
$att['__tableFrom'] = "`#".$table."`.".$tmp[1]." AS ".$field;
|
||||||
|
$field = $att['alias'] ? $tmp[1] : $tmp[0];
|
||||||
|
|
||||||
$fields[$field] = $att;
|
$fields[$field] = $att;
|
||||||
|
|
||||||
unset($tmp);
|
unset($tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
$att['table'] = $this->getIfTableAlias(false);
|
$att['table'] = $this->getIfTableAlias(false);
|
||||||
if(isset($this->joinAlias[$this->table]) && $field !='checkboxes' && $field !='options')
|
|
||||||
|
if($newField = $this->getJoinField($field)) // Auto-Detect.
|
||||||
|
{
|
||||||
|
$table = $this->getTableFromAlias($newField); // Auto-Detect.
|
||||||
|
$att['table'] = $table;
|
||||||
|
$att['alias'] = $newField;
|
||||||
|
$att['__tableField'] = $newField;
|
||||||
|
$att['__tableFrom'] = "`#".$table."`.".$field." AS ".$newField;
|
||||||
|
}
|
||||||
|
elseif(isset($this->joinAlias[$this->table]) && $field !='checkboxes' && $field !='options')
|
||||||
{
|
{
|
||||||
$att['alias'] = $this->joinAlias[$this->table].".".$field;
|
$att['alias'] = $this->joinAlias[$this->table].".".$field;
|
||||||
}
|
}
|
||||||
@@ -3075,7 +3115,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
|
// $fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
|
||||||
}
|
}
|
||||||
/*if($fields[$field]['table'])
|
/*if($fields[$field]['table'])
|
||||||
{
|
{
|
||||||
@@ -3095,7 +3135,9 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->fields = $fields;
|
$this->fields = $fields;
|
||||||
|
|
||||||
$this->_alias_parsed = true;
|
$this->_alias_parsed = true;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -3112,16 +3154,29 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
if($this->listQry)
|
if($this->listQry)
|
||||||
{
|
{
|
||||||
preg_match_all("/`?#([\w-]+)`?\s*(as|AS)\s*([\w-])/im",$this->listQry,$matches);
|
preg_match_all("/`?#([\w-]+)`?\s*(as|AS)\s*([\w-])/im",$this->listQry,$matches);
|
||||||
|
$keys = array();
|
||||||
foreach($matches[1] AS $k=>$v)
|
foreach($matches[1] AS $k=>$v)
|
||||||
{
|
{
|
||||||
if(varset($matches[3][$k]))
|
if(varset($matches[3][$k]))
|
||||||
{
|
{
|
||||||
$this->joinAlias[$v] = $matches[3][$k]; // array. eg $this->joinAlias['core_media'] = 'm';
|
$this->joinAlias[$v] = $matches[3][$k]; // array. eg $this->joinAlias['core_media'] = 'm';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$keys[] = $matches[3][$k];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($keys as $alias)
|
||||||
|
{
|
||||||
|
preg_match_all("/".$alias."\.([\w]*)/i",$this->listQry,$match);
|
||||||
|
foreach($match[1] as $k=>$m)
|
||||||
|
{
|
||||||
|
$this->joinField[$m] = $match[0][$k];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3130,6 +3185,8 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
// TODO - abstract, array return type, move to parent?
|
// TODO - abstract, array return type, move to parent?
|
||||||
protected function _modifyListQry($raw = false, $isfilter = false, $forceFrom = false, $forceTo = false, $listQry = '')
|
protected function _modifyListQry($raw = false, $isfilter = false, $forceFrom = false, $forceTo = false, $listQry = '')
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$searchQry = array();
|
$searchQry = array();
|
||||||
$filterFrom = array();
|
$filterFrom = array();
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
@@ -3163,6 +3220,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
foreach($this->getFields() as $key => $var)
|
foreach($this->getFields() as $key => $var)
|
||||||
{
|
{
|
||||||
// disabled or system
|
// disabled or system
|
||||||
|
|
||||||
if((vartrue($var['nolist']) && !vartrue($var['filter'])) || null === $var['type'])
|
if((vartrue($var['nolist']) && !vartrue($var['filter'])) || null === $var['type'])
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@@ -3237,6 +3295,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//From
|
//From
|
||||||
$qry .= $tableSJoinArr ? ', '.implode(', ', $tableSJoinArr)." FROM ".$tableFrom : " FROM ".$tableFrom;
|
$qry .= $tableSJoinArr ? ', '.implode(', ', $tableSJoinArr)." FROM ".$tableFrom : " FROM ".$tableFrom;
|
||||||
|
|
||||||
@@ -3280,6 +3339,7 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
return $rawData;
|
return $rawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// join where
|
// join where
|
||||||
if(count($jwhere) > 0)
|
if(count($jwhere) > 0)
|
||||||
{
|
{
|
||||||
@@ -3303,6 +3363,8 @@ class e_admin_controller_ui extends e_admin_controller
|
|||||||
$searchQry[] = $this->listQrySql['db_where'];
|
$searchQry[] = $this->listQrySql['db_where'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// where query
|
// where query
|
||||||
if(count($searchQry) > 0)
|
if(count($searchQry) > 0)
|
||||||
|
Reference in New Issue
Block a user