You are here

taxonomy_service.module in Services 5

The module which exposes services related to taxonomy system

File

services/taxonomy_service/taxonomy_service.module
View source
<?php

/**
 * @file
 * The module which exposes services related to taxonomy system
 */

/**
 * Implementation of hook_help().
 */
function taxonomy_service_help($section) {
  switch ($section) {
    case 'admin/help#services_taxonomy':
      return t('<p>Provides taxonomy methods to services applications.  Requires services.module.</p>');
    case 'admin/modules#description':
      return t('Provides taxonomy methods to services applications.  Requires services.module.');
  }
}

/**
 * Implementation of hook_service().
 */
function taxonomy_service_service() {
  return array(
    array(
      '#method' => 'taxonomy.getTree',
      '#callback' => 'taxonomy_service_get_tree',
      '#args' => array(
        array(
          '#name' => 'vid',
          '#type' => 'int',
          '#description' => t('A vocabulary id.'),
        ),
      ),
      '#return' => 'struct',
      '#help' => t('Create a hierarchical representation of a vocabulary.'),
    ),
    array(
      '#method' => 'taxonomy.selectNodes',
      '#callback' => 'taxonomy_service_select_nodes',
      '#args' => array(
        array(
          '#name' => 'tids',
          '#type' => 'array',
          '#description' => t('An array of term IDs to match.'),
        ),
        array(
          '#name' => 'fields',
          '#type' => 'array',
          '#optional' => TRUE,
          '#description' => t('A list of fields to return.'),
        ),
        array(
          '#name' => 'operator',
          '#type' => 'string',
          '#optional' => TRUE,
          '#description' => t('How to interpret multiple IDs in the array. Can be "or" or "and".'),
        ),
        array(
          '#name' => 'depth',
          '#type' => 'string',
          '#optional' => TRUE,
          '#description' => t('How many levels deep to traverse the taxonomy tree. Can be a nonnegative integer or "all".'),
        ),
        array(
          '#name' => 'pager',
          '#type' => 'boolean',
          '#optional' => TRUE,
          '#description' => t('Whether the nodes are to be used with a pager (the case on most Drupal pages) or not (in an XML feed, for example).'),
        ),
        array(
          '#name' => 'order',
          '#type' => 'string',
          '#optional' => TRUE,
          '#description' => t('The order clause for the query that retrieve the nodes.'),
        ),
      ),
      '#return' => 'struct',
      '#help' => t('Finds all nodes that match selected taxonomy conditions.'),
    ),
  );
}

/**
 * get terms in vocabulary
 */
function taxonomy_service_get_tree($vid) {
  return taxonomy_get_tree($vid);
}

/**
 * select_nodes
 */
function taxonomy_service_select_nodes($tids = array(), $fields = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = 'n.sticky DESC, n.created DESC') {
  $result = taxonomy_select_nodes($tids, $operator, $depth, $pager, $order);
  while ($node = db_fetch_object($result)) {
    $nodes[] = services_node_load(node_load($node->nid), $fields);
  }
  return $nodes;
}

Functions

Namesort descending Description
taxonomy_service_get_tree get terms in vocabulary
taxonomy_service_help Implementation of hook_help().
taxonomy_service_select_nodes select_nodes
taxonomy_service_service Implementation of hook_service().