/** * Handle GET request without ID. */ public function indexAction() { $apiResources = $this->getFrontController()->getParam('api_resources'); // Add the site-specific URL to each API resource. foreach ($apiResources as $resource => &$resourceInfo) { $resourceInfo['url'] = Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/{$resource}"); } $this->_helper->jsonApi($apiResources); }
public function indexAction() { if (is_admin_theme()) { // There is no API endpoint on the admin theme. $this->_helper->redirector('index', 'index'); } $this->view->title = get_option('site_title'); $this->view->site_url = Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl('/site'); $this->view->resource_url = Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl('/resources'); }
function exhibit_builder_api_extend_items($extend, $args) { $item = $args['record']; $pages = get_db()->getTable('ExhibitPage')->findBy(array('item' => $item->id)); if (count($pages) == 1) { $page = $pages[0]; $extend['exhibit_pages'] = array('id' => $page->id, 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/exhibit_pages/{$page->id}"), 'resource' => 'exhibit_pages'); } else { $extend['exhibit_pages'] = array('count' => count($pages), 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/exhibit_pages?item={$item->id}"), 'resource' => 'exhibit_pages'); } return $extend; }
private function _filterApiExtendRecords($extend, $args) { $record = $args['record']; $recordClass = get_class($record); $extend['comments'] = array('count' => $this->_countComments($record), 'resource' => 'comments', 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/comments?record_type={$recordClass}&record_id={$record->id}")); return $extend; }
/** * Add geolocations to item API representations. * * @param array $extend * @param array $args * @return array */ public function filterApiExtendItems($extend, $args) { $item = $args['record']; $location = $this->_db->getTable('Location')->findBy(array('item_id' => $item->id)); if (!$location) { return $extend; } $locationId = $location[0]['id']; $extend['geolocations'] = array('id' => $locationId, 'url' => Omeka_Record_Api_AbstractRecordAdapter::getResourceUrl("/geolocations/{$locationId}"), 'resource' => 'geolocations'); return $extend; }
/** * Get the representation of a record. * * @param Omeka_Record_AbstractRecord $record * @param string $resource */ protected function _getRepresentation(Omeka_Record_Api_AbstractRecordAdapter $recordAdapter, Omeka_Record_AbstractRecord $record, $resource) { $extend = array(); $extendTemp = apply_filters("api_extend_{$resource}", array(), array('record' => $record)); $apiResources = $this->getFrontController()->getParam('api_resources'); // Validate each extended resource. Each must be registered as an API // resource and the content must contain "id" and "url" for one resource // or "count" and "url" for multiple resources. A "resource" is // recommended but not mandatory. Everything else passes through as // custom data that may be used for the client's convenience. foreach ($extendTemp as $extendResource => $extendContent) { if (is_array($extendContent) && array_key_exists($extendResource, $apiResources) && (array_key_exists('count', $extendContent) || array_key_exists('id', $extendContent)) && array_key_exists('url', $extendContent)) { $extend[$extendResource] = $extendContent; } } // Get the representation from the record adapter. $representation = $recordAdapter->getRepresentation($record); $representation['extended_resources'] = $extend; return $representation; }