public function TripalContentService_v0_1::handleRequest

3.x TripalContentService_v0_1.inc public TripalContentService_v0_1::handleRequest()

Overrides TripalWebService::handleRequest

See also

TripalWebService::handleRequest()

File

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

Class

TripalContentService_v0_1

Code

public function handleRequest() {

  // Get the content type.
  $ctype = (count($this->path) > 0) ? $this->path[0] : '';
  $entity_id = (count($this->path) > 1) ? $this->path[1] : '';
  $expfield = (count($this->path) > 2) ? $this->path[2] : '';

  // is this a valid content type?
  if ($ctype) {
    // Get the list of published terms (these are the bundle IDs)
    $bquery = db_select('tripal_bundle', 'tb');
    $bquery->join('tripal_term', 'tt', 'tt.id = tb.term_id');
    $bquery->join('tripal_vocab', 'tv', 'tv.id = tt.vocab_id');
    $bquery->fields('tb', array('label'));
    $bquery->fields('tt', array('accession'));
    $bquery->fields('tv', array('vocabulary'));
    $bquery->orderBy('tb.label', 'ASC');
    $bundles = $bquery->execute();

    // Iterate through the terms convert the santized name to the real label.
    $i = 0;
    $ctype_lookup = array();
    $found = FALSE;
    while ($bundle = $bundles->fetchObject()) {
      if ($ctype == preg_replace('/[^\w]/', '_', $bundle->label)) {
        $ctype = $bundle->label;
        $found = TRUE;
      }
      if ($ctype == $bundle->vocabulary . ':' . $bundle->accession) {
        $ctype = $bundle->label;
        $found = TRUE;
      }
    }

    if (!$found) {
      throw new Exception('Invalid content type: ' . $ctype);
    }
  }

  // If we have a content type then list all of the entities that belong
  // to it.
  if ($ctype and !$entity_id and !$expfield) {
    $this->doEntityList($ctype);
  }
  // If we have an entity ID then build the resource for a single entity.
  else if ($ctype and $entity_id and !$expfield) {
    $this->doEntity($ctype, $entity_id);
  }
  else if ($ctype and $entity_id and $expfield) {
    $this->doExpandedField($ctype, $entity_id, $expfield);
  }
  // Otherwise just list all of the available content types.
  else {
    $this->doContentTypesList();
  }
}