private function TripalContentService_v0_1::doEntity
3.x TripalContentService_v0_1.inc | private TripalContentService_v0_1::doEntity($ctype, $entity_id) |
Creates a resource for a single entity.
1 call to TripalContentService_v0_1::doEntity()
- TripalContentService_v0_1::handleRequest in tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc
File
- tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc, line 181
Class
Code
private function doEntity($ctype, $entity_id) {
$service_path = $this->getServicePath() . '/' . urlencode($ctype);
$this->resource = new TripalWebServiceResource($service_path);
// Get the TripalBundle, TripalTerm and TripalVocab type for this type.
$bundle = tripal_load_bundle_entity(array('label' => $ctype));
$term = entity_load('TripalTerm', array('id' => $bundle->term_id));
$term = reset($term);
// Convert the $term to a simple array
$term = tripal_get_term_details($term->vocab->vocabulary, $term->accession);
// Add the vocabulary to the context.
$this->resource->addContextItem($term['name'], $term['url']);
// Get the TripalEntity.
$entity = tripal_load_entity('TripalEntity', array('id' => $entity_id));
$entity = reset($entity);
// If we couldn't match this field argument to a field and entity then return
if (!$entity) {
throw new Exception("Cannot find this record.");
}
// Check that the user has access to this entity. If not then the
// function call will throw an error.
$this->checkAccess($entity);
$itemPage = tripal_get_term_details('schema', 'ItemPage');
$label = tripal_get_term_details('rdfs', 'label');
$this->resource->setID($entity_id);
$this->setResourceType($this->resource, $term);
$this->addResourceProperty($this->resource, $label, $entity->title);
$this->addResourceProperty($this->resource, $itemPage, url('/bio_data/' . $entity->id, array('absolute' => TRUE)));
// Add in the entitie's fields.
$this->addEntityFields($this->resource, $entity, $bundle, $term, $service_path);
}