/** * Get the REST representation of an item. * * @param Item $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/items/{$record->id}"), 'public' => (bool) $record->public, 'featured' => (bool) $record->featured, 'added' => self::getDate($record->added), 'modified' => self::getDate($record->modified)); if ($record->item_type_id) { $representation['item_type'] = array('id' => $record->item_type_id, 'url' => self::getResourceUrl("/item_types/{$record->item_type_id}"), 'name' => $record->Type->name, 'resource' => 'item_types'); } else { $representation['item_type'] = null; } if ($record->collection_id) { //check that user has access to the collection $collection = $record->getCollection(); if (is_allowed($collection, 'show')) { $representation['collection'] = array('id' => $record->collection_id, 'url' => self::getResourceUrl("/collections/{$record->collection_id}"), 'resource' => 'collections'); } else { $representation['collection'] = null; } } else { $representation['collection'] = null; } if ($record->owner_id) { $representation['owner'] = array('id' => $record->owner_id, 'url' => self::getResourceUrl("/users/{$record->owner_id}"), 'resource' => 'users'); } else { $representation['owner'] = null; } $representation['files'] = array('count' => $record->getTable('File')->count(array('item_id' => $record->id)), 'url' => self::getResourceUrl("/files?item={$record->id}"), 'resource' => 'files'); $representation['tags'] = $this->getTagRepresentations($record); $representation['element_texts'] = $this->getElementTextRepresentations($record); return $representation; }
/** * Set POST data to an item type. * * @param ItemType $data * @param mixed $data */ public function setPostData(Omeka_Record_AbstractRecord $record, $data) { if (isset($data->name)) { $record->name = $data->name; } if (isset($data->description)) { $record->description = $data->description; } if (isset($data->elements) && is_array($data->elements)) { $elements = array(); foreach ($data->elements as $element) { if (!is_object($element)) { continue; } $elements[] = $record->getTable('Element')->find($element->id); } $record->addElements($elements); } }
/** * Get the REST API representation for an element set. * * @param ElementSet $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/element_sets/{$record->id}"), 'name' => $record->name, 'description' => $record->description, 'record_type' => $record->record_type, 'elements' => array('count' => $record->getTable('Element')->count(array('element_set' => $record->id)), 'url' => self::getResourceUrl("/elements?element_set={$record->id}"), 'resource' => 'elements')); return $representation; }
/** * Reload a record. * * @param Omeka_Record_AbstractRecord $record A record to reload. * @return Omeka_Record_AbstractRecord The reloaded record. */ protected function _reload($record) { return $record->getTable()->find($record->id); }
/** * Get the REST API representation for Collection * * @param Collection $record * @return array */ public function getRepresentation(Omeka_Record_AbstractRecord $record) { $representation = array('id' => $record->id, 'url' => self::getResourceUrl("/collections/{$record->id}"), 'public' => (bool) $record->public, 'featured' => (bool) $record->featured, 'added' => self::getDate($record->added), 'modified' => self::getDate($record->modified), 'owner' => array('id' => $record->owner_id, 'url' => self::getResourceUrl("/users/{$record->owner_id}"), 'resource' => 'users'), 'items' => array('count' => $record->getTable('Item')->count(array('collection_id' => $record->id)), 'url' => self::getResourceUrl("/items?collection={$record->id}"), 'resource' => 'items'), 'element_texts' => $this->getElementTextRepresentations($record)); return $representation; }