private function TripalContentService_v0_1::doExpandedField

3.x TripalContentService_v0_1.inc private TripalContentService_v0_1::doExpandedField($ctype, $entity_id, $expfield)

Creates a resource for an expanded field of an entity.

1 call to TripalContentService_v0_1::doExpandedField()

File

tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc, line 107

Class

TripalContentService_v0_1

Code

private function doExpandedField($ctype, $entity_id, $expfield) {
  $service_path = $this->getServicePath() . '/' . urlencode($ctype) . '/' . $entity_id;
  $this->resource = new TripalWebServiceResource($service_path);

  // Get the TripalBundle, TripalTerm and TripalVocab for this type.
  $bundle = tripal_load_bundle_entity(array('label' => $ctype));

  // Find the field that matches the field name provided by the user.
  list($field, $instance, $term) = $this->findField($bundle, $expfield);

  if (!$field) {
    throw new Exception("Could not find a matching field for the name: $expfield");
  }

  // Get the TripalEntity
  $entity = tripal_load_entity('TripalEntity', array('id' => $entity_id), FALSE, array($field['id']));
  $entity = reset($entity);

  // If we couldn't find the entity then fail.
  if (!$entity) {
    throw new Exception("Cannot find the record with id $entity_id.");
  }

  // Check that the user has access to this entity.  If not then the
  // function call will throw an error.
  $this->checkAccess($entity);


  // Next add in the ID and Type for this resources.
  $this->setResourceType($this->resource, $term);
  $this->resource->setID(urlencode($term['name']));

  if (!property_exists($entity, $field['field_name'])) {
    // Attach the field and then add its values to the response.
    field_attach_load($entity->type, array($entity->id => $entity), 
    FIELD_LOAD_CURRENT, array('field_id' => $field['id']));
  }

  $this->addEntityField($this->resource, $term, $entity, $bundle, $field, $instance, $service_path, $expfield);
}