private function TripalContentService_v0_1::doContentTypesList
3.x TripalContentService_v0_1.inc | private TripalContentService_v0_1::doContentTypesList() |
Creates a resources that contains the list of content types.
1 call to TripalContentService_v0_1::doContentTypesList()
- TripalContentService_v0_1::handleRequest in tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc
File
- tripal_ws/
includes/ TripalWebService/ TripalContentService_v0_1.inc, line 963
Class
Code
private function doContentTypesList() {
$service_path = $this->getServicePath();
$service_vocab = new TripalDocService_v0_1($this->base_path);
$this->resource = new TripalWebServiceCollection($service_path, $this->params);
$this->resource->addContextItem('vocab', $service_vocab->getServicePath());
$this->resource->addContextItem('Content_Collection', $service_vocab->getServicePath() . '#Content_Collection');
$this->resource->setType('Content_Collection');
$label = tripal_get_term_details('rdfs', 'label');
$this->addResourceProperty($this->resource, $label, 'Content Types');
// Get the list of published terms (these are the bundle IDs)
$bundles = db_select('tripal_bundle', 'tb')
->fields('tb')
->orderBy('tb.label', 'ASC')
->execute();
// Iterate through the terms and add an entry in the collection.
$i = 0;
while ($bundle = $bundles->fetchObject()) {
$entity = entity_load('TripalTerm', array('id' => $bundle->term_id));
$term = reset($entity);
$vocab = $term->vocab;
// Convert the term to a simple array
$term = tripal_get_term_details($term->vocab->vocabulary, $term->accession);
$member = new TripalWebServiceResource($service_path);
$member->setID(preg_replace('/[^\w]/', '_', $bundle->label));
$vocab_service = new TripalDocService_v0_1($this->base_path);
$member->addContextItem('vocab', $vocab_service->getServicePath() . '#');
$accession = preg_replace('/[^\w]/', '_', $bundle->label . ' Collection');
$member->addContextItem($accession, 'vocab:' . $accession);
$member->setType($accession);
// Make sure the term has a URL.
$url = $term['url'];
if (!$url) {
throw new Exception(t('Missing a URL for the term: @term.', array('@term' => $term['vocabulary']['short_name'] . ':' . $term['accession'])));
}
$this->addResourceProperty($member, $label, $bundle->label . ' Collection');
$member->addContextItem('description', 'rdfs:comment');
// Get the bundle description. If no description is provided then
// use the term definition
$description = trim(tripal_get_bundle_variable('description', $bundle->id));
if (!$description) {
$description = $term['definition'];
}
if (!$description) {
$description = '';
}
$member->addProperty('description', 'A collection of ' . $bundle->label . ' resources: ' . lcfirst($description));
$this->resource->addMember($member);
}
}