/** * Returns assets from the database * * @param int|string $folder Folder ID or String (/Workspace/.../) * @param string $view View name (e.g. display, details) * @param string $fields field1,field2 or * (optional) * @param string $order field-name asc|desc (optional) * @param int|string $limit Numeric limit or offset,limit (optional) * @param array $items Asset-IDs (optional) * @param string $filter Syntax: field|operation|search-string[||field|operation|search-string] * operation: like,nlike,starts,eq,neq,lt,gt,oneof * @param boolean $apply_filter Apply output filters (sgsML) * @param boolean $totals Output with totals: Array(total=>num of rows, rows=>...) * @return array Array with associative Arrays for each asset found */ static function asset_get_rows($folder, $view = "display", $fields = "*", $order = "", $limit = "", array $items = array(), $filter = "", $apply_filter = false, $totals = false) { self::_require_access($folder, "read", $view); if (!preg_match("/^[a-z0-9 ,]+\$/i", $order)) { $order = ""; } if (!preg_match("/^[a-z0-9 ,]+\$/i", $fields)) { $fields = "*"; } if (!preg_match("/^[0-9 ,]+\$/i", $limit)) { $limit = "20"; } $sgsml = new sgsml($folder, $view, $items, false); $sgsml->set_filter($filter); $rows = $sgsml->get_rows($fields, $order, explode(",", $limit)); // TODO2 optimize? if ($rows === "error") { throw new SoapFault("1", "SQL error"); } foreach ($rows as $key => $row) { foreach ($row as $field_name => $value) { if (!isset($sgsml->current_fields[$field_name])) { unset($rows[$key][$field_name]); continue; } $rows[$key][$field_name] = $sgsml->restore_field($field_name, $value, $row); if ($apply_filter) { $rows[$key][$field_name] = $sgsml->filter_field($field_name, $value, $row); } } } if ($totals) { return array("total" => $sgsml->get_count(), "rows" => $rows); } return $rows; }