taxonomy_service.module

Tracking 5.x-1.x branch
  1. drupal
    1. 5 contributions/services/services/taxonomy_service/taxonomy_service.module

The module which exposes services related to taxonomy system

Functions & methods

NameDescription
taxonomy_service_get_treeget terms in vocabulary
taxonomy_service_help
taxonomy_service_select_nodesselect_nodes
taxonomy_service_service

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * The module which exposes services related to taxonomy system
  5. */
  6. /**
  7. * Implementation of hook_help().
  8. */
  9. function taxonomy_service_help($section) {
  10. switch ($section) {
  11. case 'admin/help#services_taxonomy':
  12. return t('<p>Provides taxonomy methods to services applications. Requires services.module.</p>');
  13. case 'admin/modules#description':
  14. return t('Provides taxonomy methods to services applications. Requires services.module.');
  15. }
  16. }
  17. /**
  18. * Implementation of hook_service().
  19. */
  20. function taxonomy_service_service() {
  21. return array(
  22. array(
  23. '#method' => 'taxonomy.getTree',
  24. '#callback' => 'taxonomy_service_get_tree',
  25. '#args' => array(
  26. array(
  27. '#name' => 'vid',
  28. '#type' => 'int',
  29. '#description' => t('A vocabulary id.'),
  30. ),
  31. ),
  32. '#return' => 'struct',
  33. '#help' => t('Create a hierarchical representation of a vocabulary.')
  34. ),
  35. array(
  36. '#method' => 'taxonomy.selectNodes',
  37. '#callback' => 'taxonomy_service_select_nodes',
  38. '#args' => array(
  39. array(
  40. '#name' => 'tids',
  41. '#type' => 'array',
  42. '#description' => t('An array of term IDs to match.'),
  43. ),
  44. array(
  45. '#name' => 'fields',
  46. '#type' => 'array',
  47. '#optional' => TRUE,
  48. '#description' => t('A list of fields to return.'),
  49. ),
  50. array(
  51. '#name' => 'operator',
  52. '#type' => 'string',
  53. '#optional' => TRUE,
  54. '#description' => t('How to interpret multiple IDs in the array. Can be "or" or "and".'),
  55. ),
  56. array(
  57. '#name' => 'depth',
  58. '#type' => 'string',
  59. '#optional' => TRUE,
  60. '#description' => t('How many levels deep to traverse the taxonomy tree. Can be a nonnegative integer or "all".'),
  61. ),
  62. array(
  63. '#name' => 'pager',
  64. '#type' => 'boolean',
  65. '#optional' => TRUE,
  66. '#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).'),
  67. ),
  68. array(
  69. '#name' => 'order',
  70. '#type' => 'string',
  71. '#optional' => TRUE,
  72. '#description' => t('The order clause for the query that retrieve the nodes.'),
  73. ),
  74. ),
  75. '#return' => 'struct',
  76. '#help' => t('Finds all nodes that match selected taxonomy conditions.')
  77. ),
  78. );
  79. }
  80. /**
  81. * get terms in vocabulary
  82. */
  83. function taxonomy_service_get_tree($vid) {
  84. return taxonomy_get_tree($vid);
  85. }
  86. /**
  87. * select_nodes
  88. */
  89. function taxonomy_service_select_nodes($tids = array(), $fields = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = 'n.sticky DESC, n.created DESC') {
  90. $result = taxonomy_select_nodes($tids, $operator, $depth, $pager, $order);
  91. while ($node = db_fetch_object($result)) {
  92. $nodes[] = services_node_load(node_load($node->nid), $fields);
  93. }
  94. return $nodes;
  95. }