38 require_once realpath(dirname(__FILE__).
"/search_form.inc");
39 require_once realpath(dirname(__FILE__).
"/data_view.inc");
53 return $this->parent->class;
63 public abstract function format($items);
73 header(
"Content-Type: text/json");
86 header(
"Content-Type: text/xml");
104 foreach($obj->getFields() as $field => $type)
106 if ($obj->filter && $obj->filter->isExcluded($field))
continue;
107 $view->column($field,
"{".$field.
"}");
111 $view->writeExcelFile($this->
getClass().
"Results.xls");
124 $file = fopen(
'php://temp/maxmemory:'. (12*1024*1024),
'r+');
129 foreach($obj->getFields() as $field => $type)
131 if ($obj->filter && $obj->filter->isExcluded($field))
continue;
135 fputcsv($file, $columns);
137 foreach($items as $obj)
140 foreach($obj->getFields() as $field => $type)
142 if ($obj->filter && $obj->filter->isExcluded($field))
continue;
143 $values[] = $obj->get($field);
146 fputcsv($file, $values);
150 $output = stream_get_contents($file);
153 header(
"Content-Type: text/csv");
195 $template = file_get_contents($this->file);
197 $expr =
"\{".$class.
"\}(.*?)\{\/".$class.
"\}";
201 if (!preg_match(
"/$expr/si", $template, $matches))
203 throw new FakoliException(
"Badly formatted template $file - $expr<br><pre>$template<pre>");
206 $format = $matches[1];
210 $out = str_replace($matches[0], $result, $template);
212 header(
"Content-Type: $this->mimeType");
250 $this->
class = $class;
254 $this->format = isset($_GET[
"_format"]) ? $_GET[
"_format"] :
"json";
272 $parameters->fromGET();
276 $query = $parameters->generateConstraint();
279 ->filter($this->outputFilter)
282 if (!array_key_exists($this->format, $this->formatterMap))
284 throw new FakoliException(
"Unknown format");
298 $formatter->parent = $this;
299 $this->formatterMap[$name] = $formatter;
APIHelper is a class designed to simplify the sharing of data between applications.
registerFormat($name, $formatter)
Register a format and its associated formatter.
__construct($class, $searchFilter=null, $outputFilter=null, $constraints="")
Creates an APIHelper for the specified class.
query()
Process an API query.
APITemplate provides a simple template mechanism for transforming APIHelper output to meet 3rd-party ...
__construct($file, $mimeType="text/xml")
Creates a new APITemplate.
format($items)
Override this function to provide your format definition.
DataListView displays a list of DataItems (or InnerJoinResults) in tabular format.
static create($class, $constraints="")
Static factory method to create a new Query.
The SearchParameters class interprets the set of input parameters for a search and generates the corr...
formatItems($items, $template, $separator="")
Format a list of DataItems using the specified templated.
toXML($tag, $objects, $header=null)