public function RestWSFormatXML::queryResource in RESTful Web Services 7.2
Overrides RestWSBaseFormat::queryResource().
Overrides RestWSBaseFormat::queryResource
File
- ./
restws.formats.inc, line 526 - RESTful web services module formats.
Class
- RestWSFormatXML
- A formatter for XML.
Code
public function queryResource($resourceController, $payload) {
$xml = new DOMDocument('1.0', 'utf-8');
$element = $xml
->createElement('list');
$rest_controls = restws_meta_controls();
$parameters = drupal_get_query_parameters();
$properties = $resourceController
->propertyInfo();
$split_parameters = $this
->splitParameters($properties, $parameters);
$links = $this
->generateQueryURIs($resourceController, $parameters, $split_parameters['filters']);
foreach ($links as $rel => $link) {
$item = $xml
->createElement('link');
$item
->setAttribute('rel', $rel);
$item
->setAttribute('href', $link);
$element
->appendChild($item);
}
$full = isset($split_parameters['meta_controls'][$rest_controls['full']]) ? $split_parameters['meta_controls'][$rest_controls['full']] : 1;
$result = $resourceController
->query($split_parameters['filters'], $split_parameters['meta_controls']);
if ($full === '0') {
foreach ($result as $id) {
$item = $xml
->createElement($resourceController
->resource());
self::setXMLReference($item, $resourceController
->resource(), $id);
$element
->appendChild($item);
}
}
else {
foreach ($result as $id) {
$item = $xml
->createElement($resourceController
->resource());
self::addToXML($xml, $item, $resourceController
->wrapper($id));
$element
->appendChild($item);
}
}
$xml
->appendChild($element);
$function = __FUNCTION__;
drupal_alter('restws_response', $xml, $function, $this->formatName, $resourceController);
return $xml
->saveXML();
}