path)) { return rest::invalid_request(); } $item = ORM::factory("item") ->where("relative_url_cache", $request->path) ->viewable() ->find(); if (!$item->loaded) { return rest::not_found("Resource: {$request->path} missing."); } $response_data = array("path" => $item->relative_url(), "title" => $item->title, "thumb_url" => $item->thumb_url(), "url" => $item->abs_url(), "description" => $item->description, "internet_address" => $item->slug); $children = self::_get_children($item, $request); if (!empty($children)) { $response_data["children"] = $children; } return rest::success(array($item->type => $response_data)); } private static function _get_children($item, $request) { $children = array(); $limit = empty($request->limit) ? null : $request->limit; $offset = empty($request->offset) ? null : $request->offset; $where = empty($request->filter) ? array() : array("type" => $request->filter); foreach ($item->viewable()->children($limit, $offset, $where) as $child) { $children[] = array("type" => $child->type, "has_children" => $child->children_count() > 0, "path" => $child->relative_url(), "title" => $child->title); } return $children; } }