public function TripalWebServiceCollection::getData
3.x TripalWebServiceCollection.inc | public TripalWebServiceCollection::getData() |
Retrieves the data section of the resource.
The JSON-LD response constists of two sections the '@context' section and the data section. This function only returns the data section for this resource
Return value
An associative array containing the data section of the response.
Overrides TripalWebServiceResource::getData
File
- tripal_ws/
includes/ TripalWebServiceCollection.inc, line 120
Class
Code
public function getData() {
$data = $this->data;
$data['totalItems'] = 0;
if ($this->doPaging == TRUE) {
// Save any parameters provided by the user
$saved_params = '';
foreach ($this->params as $pkey => $pval) {
if (in_array($pkey, array('page', 'limit', 'first', 'last', 'next', 'prev'))) {
continue;
}
$saved_params .= '&' . $pkey . '=' . $pval;
}
$data['totalItems'] = $this->totalItems;
$total_pages = ceil($this->totalItems / $this->itemsPerPage);
$page = $this->page;
$limit = $this->itemsPerPage;
if ($this->totalItems > 0) {
$data['view'] = array(
'@id' => $this->service_path . '?' . implode('&', array_merge(array("page=$page", "limit=$limit"))) . $saved_params,
'@type' => 'PartialCollectionView',
'first' => $this->service_path . '?' . implode('&', array_merge(array("page=1", "limit=$limit"))) . $saved_params,
'last' => $this->service_path . '?' . implode('&', array_merge(array("page=$total_pages", "limit=$limit"))) . $saved_params,
);
$prev = $page - 1;
$next = $page + 1;
if ($prev > 0) {
$data['view']['previous'] = $this->service_path . '?' . implode('&', array("page=$prev", "limit=$limit")) . $saved_params;
}
if ($next < $total_pages) {
$data['view']['next'] = $this->service_path . '?' . implode('&', array("page=$next", "limit=$limit")) . $saved_params;
}
}
}
else {
$data['totalItems'] = count($this->members);
}
$member_data = array();
foreach ($this->members as $key => $member) {
$member_data[] = $member->getData();
}
$data['member'] = $member_data;
// If paging of this collection is enabled then add the pager control links.
return $data;
}