diff --git a/routeSQL.php b/routeSQL.php index e8b0d74..eb15454 100644 --- a/routeSQL.php +++ b/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)