Project

General

Profile

Download (3.33 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * @file
6
 * Functions which are required or useful when accessing and processing CDM Data Store Webservices
7
 * 
8
 * Naming conventions:
9
 * ----------------------
10
 * 
11
 *  - all webservice access methods are prefixed with cdm_ws
12
 */
13

    
14
/**
15
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas 
16
 * each item will provided with a class attribute which set to the key of the TaggedText item.
17
 *
18
 * @param TaggedText $tag
19
 * @return String of HTML 
20
 */
21
function cdm_taggedtext2html(array $taggedText, $tag = 'span'){
22
   foreach($taggedText as $class=>$value){
23
     $out .= '<'.$tag.' class="'.$class.'">'.$value.'</ '.$tag.'>';
24
   }
25
   return $out;
26
}
27

    
28
/**
29
 * @return string
30
 * @param string $url
31
 * @desc Return string content from a remote file
32
 * @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
33
*/
34
function get_content($url)
35
{
36
    $ch = curl_init();
37

    
38
    curl_setopt ($ch, CURLOPT_URL, $url);
39
    curl_setopt ($ch, CURLOPT_HEADER, 0);
40

    
41
    ob_start();
42

    
43
    curl_exec ($ch);
44
    curl_close ($ch);
45
    $string = ob_get_contents();
46

    
47
    ob_end_clean();
48
   
49
    return $string;    
50
}
51

    
52
/**
53
 * Loads the XML response for the given url from the CDM Data Store Webservice.
54
 * The XML is turned into a object wich is retuned. Incase of an error a 
55
 * approriate watchdog message is generated and the function returns false.
56
 * 
57
 * //TODO are we going to support JSON services ?
58
 *
59
 * @param String $url the relative url of the web service call. 
60
 *        Relative means relative to the web service base url which is stored in cdm_webservice_url
61
 * @return An object or false
62
 */
63
function cdm_ws_load($url){
64

    
65
  if(variable_get('cdm_webservice_isStub', 0)){
66
    $url = urlencode($url);
67
  }
68
  
69
  //TODO get_content() requires the php curl extension to be installed, maybe we should chose an other function
70
  $data = get_content($url);
71
  
72

    
73
  
74
  if(!$obj){
75
    $backtrace = debug_backtrace();
76
    watchdog('CDM', $backtrace[1]['function'].' - failed to load '.$url, WATCHDOG_ERROR);
77
  }
78
  $obj->ws_url = $url;
79
  
80
  return $obj;
81
}
82

    
83

    
84
/**
85
 * The whatis service returns the type 
86
 * i.e. DTO class name and simplename & cdm class name and simplename of the instance referenced by the $uuid parameter. 
87
 * 
88
 *
89
 * @param unknown_type $uuid
90
 * @return false if the cdm store contains no matching instance. 
91
 * An associative array with the following key-value pairs:
92
 *   - 'cdmName':       name of the cdm class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.model.taxon.Taxon
93
 *   - 'cdmSimpleName': simple name of the cdm class as returned by Class.getSimpleName(), e.g. Taxon
94
 *   - 'dtoName':       name of the DTO class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.dto.TaxonTO
95
 *   - 'dtoSimpleName': simple name of the TDO class as returned by Class.getSimpleName(), e.g. TaxonTO
96
 */
97
function cdm_ws_whatis($uuid){
98
  return cdm_ws_load("whatis/?uuid=$uuid");
99
}
100

    
101
/**
102
 * load a name from the CDM Webservice
103
 *
104
 * @param String $uuid
105
 * @return a NameTO instance or false 
106
 */
107
function cdm_ws_get_name($uuid){
108
  return cdm_ws_load("name/?uuid=$uuid");
109
}
110

    
111
/**
112
 * load a list of names from the CDM Webservice
113
 *
114
 * @param unknown_type $page
115
 * @param unknown_type $hide_unaccepted
116
 */
117
function cdm_ws_name_list($page = 1, $onlyAccepted){
118
   
119
}
    (1-1/1)