public function entries()
{
$collection = $this->param("collection", null);
$entries = [];
if ($collection) {
$col = "collection" . $collection["_id"];
$options = [];
if (array_key_exists("sortfield", $collection) && $collection["sortfield"] && array_key_exists("sortorder", $collection) && $collection["sortorder"]) {
$options["sort"] = [];
$options["sort"][$collection["sortfield"]] = (int) $collection["sortorder"];
}
if ($filter = $this->param("filter", null)) {
$options["filter"] = is_string($filter) ? json_decode($filter, true) : $filter;
}
if ($limit = $this->param("limit", null)) {
$options["limit"] = $limit;
}
if ($sort = $this->param("sort", null)) {
$options["sort"] = $sort;
}
if ($skip = $this->param("skip", null)) {
$options["skip"] = $skip;
}
$entries = $this->app->db->find("collections/{$col}", $options);
}
return json_encode($entries->toArray());
}