routeSQL : display the associated unique field to a foreign key instead of the numerical value
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2048 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
44
routeSQL.php
44
routeSQL.php
@@ -681,6 +681,50 @@ class routeSQL
|
||||
$vals[$this->objectDB->primary]) !== TRUE)
|
||||
unset ($data[$key]);
|
||||
}
|
||||
|
||||
// Get the non mandatory foreign keys and display them instead of the
|
||||
// unusable id
|
||||
$foreignData = array ();
|
||||
if (isset($this->objectDB->foreign))
|
||||
{
|
||||
foreach ($this->objectDB->foreign as $foreign=>$params)
|
||||
{
|
||||
if (! isset ($params[0]))
|
||||
throw new Exception ("Undefined foreign key", 500);
|
||||
if (! isset ($params[1]))
|
||||
throw new Exception ("Undefined foreign key column", 500);
|
||||
$class = $params[0];
|
||||
$column = $params[1];
|
||||
require_once ("models/model_$class.php");
|
||||
$foreignObject = new $class ($this->dsn, $this->username,
|
||||
$this->password, $this->driver_options);
|
||||
if (isset ($foreignObject->unique))
|
||||
{
|
||||
$tmpData = $foreignObject->read (null, array_merge (array ($column),
|
||||
$foreignObject->unique));
|
||||
$associated = array ();
|
||||
$unique = reset ($foreignObject->unique);
|
||||
foreach ($tmpData as $vals)
|
||||
{
|
||||
// TODO : If $foreignObject->unique is not an array ?
|
||||
// or multidimensionnal array
|
||||
$associated[$vals[$column]] = $vals[$unique];
|
||||
}
|
||||
// Add the unique text to the identifier
|
||||
foreach ($data as $line=>$vals)
|
||||
{
|
||||
foreach ($vals as $col=>$val)
|
||||
{
|
||||
if ($col === $foreign && isset ($associated[$val]))
|
||||
{
|
||||
$data[$line][$col] = $associated[$val];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nbentries = count ($data);
|
||||
if ($num > 1000)
|
||||
$route->redirect ("/".str_replace ("{chain}", $chain, $this->url_prefix)
|
||||
|
||||
Reference in New Issue
Block a user