public static function ExtendComplete(&$object, $path) { global $relations; if ($relations == null) { throw new Exception("Relations not defined in config", 400); } $first = $path[0]; if (!isset($object[$first])) { if (!isset($object["__table"])) { return; } if (!isset($relations[$object["__table"]])) { throw new Exception("{$object["__table"]} not defined in relations", 400); } if (!isset($relations[$object["__table"]][$first])) { throw new Exception("{$first} not defined in relations of {$object["__table"]}", 400); } $relation = $relations[$object["__table"]][$first]; if (!isset($relation["type"]) || !isset($relation["ftable"])) { throw new Exception("Invalid configuration in {$first} of {$object["__table"]}. Requisites (type,ftable)", 400); } if (!isset($relation["key"])) { $relation["key"] = ArrestDB::TableKeyName($object["__table"]); } if (!isset($relation["fkey"])) { $relation["fkey"] = ArrestDB::TableKeyName($relation["ftable"]); } $id = $object[$relation["key"]]; if (function_exists("ArrestDB_allow")) { if ($relation["type"] == "object") { if (!ArrestDB_allow("GET_INTERNAL", $relation["ftable"], $id)) { throw new Exception("Cannot load {$relation["ftable"]} with identifier {$id}", 403); } } else { if (!ArrestDB_allow("GET_INTERNAL", $relation["ftable"], "")) { throw new Exception("Cannot load {$relation["ftable"]} with identifier {$id}", 403); } } } $query = []; $query["SELECT"] = "*"; if (function_exists("ArrestDB_tableAlias")) { $query["TABLE"] = ArrestDB_tableAlias($relation["ftable"]); } else { $query["TABLE"] = $relation["ftable"]; } if (!isset($relation["keytype"])) { $relation["keytype"] = "numeric"; } if ($relation["keytype"] == "string") { $query["WHERE"] = ["{$relation["fkey"]}='{$id}'"]; } else { $query["WHERE"] = ["{$relation["fkey"]}={$id}"]; } if (function_exists("ArrestDB_modify_query")) { $query = ArrestDB_modify_query("GET_INTERNAL", $relation["ftable"], $id, $query); } $query = ArrestDB::PrepareQueryGET($query); $result = ArrestDB::Query($query); if ($result === false) { $result = ArrestDB::$HTTP[404]; return $result; } if (function_exists("ArrestDB_postProcess")) { $result = ArrestDB_postProcess("GET_INTERNAL", $relation["ftable"], $id, $result); } foreach ($result as $k => $item) { $result[$k]["__table"] = $relation["ftable"]; } $path2 = $path; array_shift($path2); if (count($path2) > 0) { foreach ($result as $k => $item) { ArrestDB::ExtendComplete($result[$k], $path2); } } if ($relation["type"] == "object") { if (count($result) == 0) { return null; } if ($result != null) { $result = $result[0]; } } else { if ($result == null) { $result = []; } } $object[$path[0]] = $result; } else { /* if (isset($object[$first][0])) $result=$object[$first]; else $result=[$object[$first]]; */ $path2 = $path; array_shift($path2); $result =& $object[$first]; if (count($path2) > 0) { if (isset($result[0])) { foreach ($result as $k => $item) { ArrestDB::ExtendComplete($result[$k], $path2); } } else { ArrestDB::ExtendComplete($result, $path2); } } //$object[$path[0]]=$result; } }