protected function TripalWebService::addDocClass

3.x TripalWebService.inc protected TripalWebService::addDocClass($details = array(), $ops = array(), $props = array())

Defines an entity class for the web services.

A class defines a resource including information about its properties and the actions that can be performed. Each class as a unique @id, title, type and description. The $details parameter is used to provide this information. Additionally, a resource may support Create, Read Update and Delete (CRUD) operations. Those are defined using the $ops argument. Finally, resources may have properties (or fields). These properties should be defined using the $props arugment.

Parameters

$details.: An array of key/value pairs providing the details for the class. Valid keys include:

  • id: The unique IRI for this class.
  • term: the accession for the term for this class.
  • title: The title for the resource that this Class represents.
  • description: (Optional). A description of the resource.
  • subClassOf: (Optional). If this class is a subclass of another class then the value should be the @id of the parent class. This defaults to hydra:Resource. If no subClass is desired, set it to NULL.
  • type: (Optional). Indicates the type of class. Defaults to hydra:Class

@param $ops If the resource supports CRUD functionality then those functions should be defined using this argument. This is an associative array with the following keys: GET, POST, PUT, DELETE. These keys, if provided, indicate that a resource of this type can be retrieved (GET), created (POST), updated (PUT) or deleted (DELETE). The value for each key should be an associative array that supports the following keys: = type: the @id that determines the type of operation. This type should be specific to the resource, and it need not be a term from a real vocabulary. Use the '_:' prefix for the term. For example, for an 'Event' resource with a GET method, an appropriate type would be '_:event_retrieve'.

  • label: A label that describes the operation in the context of the resource.
  • description: A description for the operation. Can be set to NULL for no description.
  • expects: The information expected by the Web API.
  • returns: The @id of a Class that will be returned by the operation. Set to NULL if there is no return value.
  • statusCodes: An array of status codes that could be returned when an error occurs. Each element of the array is an associative array with two key/value pairs: 'code' and 'description'. Set the 'code' to be the HTTP code that can be returned on error and the 'description' to an error message appropriate for the error. For example an HTTP 404 error means "Not Found". You can sepecify this code and provide a description appropriate for the method and class.

@param $props. Defines the list of properties that the resource provides. This is an array of properties where each property is an associative array containing the following keys:

  • type: The @id of the type of property. Alternatively, this can be an instance of a TripalWebServiceResource when the property must support operations such as a property of type hydra:Link.
  • title: (Optional). The human-readable title of this property. If this key is absent then the title will be set to the term's title.
  • description: (Optional). A short description of this property. If this key is absent then the description will be set to the term's description.
  • required: Set to TRUE to indicate if this property is a required field when creating a new resource.
  • readable: Set to TRUE to indicate that the client can retrieve the property's value? altered by an update.
  • writeable: Set to TRUE if the client can alter the value of the property.
  • domain: the @id of the rdfs:domain.
  • range: the @id of the rdfs:range.
5 calls to TripalWebService::addDocClass()
TripalContentService_v0_1::addDocBundleClasses in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Adds classes for every content type to the documentation for this service.
TripalContentService_v0_1::addDocBundleCollectionClass in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Every content type (bundle) needs a collection class in the documentation.
TripalContentService_v0_1::addDocContentCollectionClass in tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc
Adds the content collection class to the document for this service.
TripalDocService_v0_1::addEntryPointClass in tripal_ws/includes/TripalWebService/TripalDocService_v0_1.inc
Generates the EntryPoint class for the API documents.
TripalWebService::__construct in tripal_ws/includes/TripalWebService.inc
Implements the constructor.

File

tripal_ws/includes/TripalWebService.inc, line 406

Class

TripalWebService

Code

protected function addDocClass($details = array(), $ops = array(), $props = array()) {
  $supported_class = new TripalWebServiceResource($this->getServicePath());

  // Add the context which all classes will need
  $supported_class->addContextItem('description', 'rdfs:comment');
  $supported_class->addContextItem('subClassOf', 'hydra:subClassOf');
  $supported_class->addContextItem('description', 'rdfs:comment');
  $supported_class->addContextItem('label', 'rdfs:label');

  // Set the Class ID.
  $class_id = $details['id'];
  $accession = $details['term'];
  if ($accession != $class_id) {
    $supported_class->addContextItem($accession, $class_id);
  }
  $supported_class->setID($accession);

  // Set the class Type.
  if (array_key_exists('type', $details)) {
    $supported_class->setType($details['type']);
  }
  else {
    $supported_class->setType('hydra:Class');
  }

  // Set title and description.
  $supported_class->addProperty('hydra:title', $details['title']);
  $supported_class->addProperty('hydra:description', array_key_exists('description', $details) ? $details['description'] : NULL);

  // Set the sub class.
  if (array_key_exists('subClassOf', $details)) {
    if ($details['subClassOf']) {
      $supported_class->addProperty('subClassOf', $details['subClassOf']);
    }
  }
  else {
    $supported_class->addProperty('subClassOf', 'hydra:Resource');
  }

  // Now add the supported operations.
  $class_ops = array();
  foreach ($ops as $op => $op_details) {
    $class_ops[] = $this->generateDocClassOp($supported_class, $op, $op_details);
  }
  $supported_class->addContextItem('supportedOperation', 'hydra:supportedOperation');
  $supported_class->addProperty('supportedOperation', $class_ops);

  // Now add in the supported proprerties.
  $class_props = array();
  foreach ($props as $prop) {
    $class_props[] = $this->generateDocClassProp($supported_class, $prop);
  }
  $supported_class->addContextItem('supportedProperty', 'hydra:supportedProperty');
  $supported_class->addProperty('supportedProperty', $class_props);

  $this->documentation[] = $supported_class;
}