Commit | Line | Data |
---|---|---|
1c21f490 MS |
1 | <?php |
2 | // Pull in the NuSOAP code | |
3 | require_once('nusoap/lib/nusoap.php'); | |
4 | require("siap_ws_utils.php"); | |
5 | ||
6 | // Create the server instance | |
7 | $server = new soap_server(); | |
8 | // Initialize WSDL support | |
9 | $server->configureWSDL('siapwsdl', 'urn:siapwsdl'); | |
10 | ||
11 | ||
12 | // Register the data structures used by the service | |
13 | $server->wsdl->addComplexType( | |
14 | 'SearchRequest', | |
15 | 'complexType', | |
16 | 'struct', | |
17 | 'all', | |
18 | '', | |
19 | array | |
20 | ( | |
21 | 'palavra' => array('name' => 'palavra', 'type' => 'xsd:string'), | |
22 | 'procedencia' => array('name' => 'procedencia', 'type' => 'xsd:int'), | |
23 | 'sistema' => array('name' => 'sistema', 'type' => 'xsd:int'), | |
24 | 'patologia' => array('name' => 'patologia', 'type' => 'xsd:int'), | |
25 | ) | |
26 | ); | |
27 | ||
28 | $server->wsdl->addComplexType( | |
29 | 'SearchResults', | |
30 | 'complexType', | |
31 | 'array', | |
32 | 'all', | |
33 | '', | |
34 | array | |
35 | ( | |
36 | 'nome' => array('name' => 'nome', 'type' => 'xsd:string'), | |
37 | 'url'=> array('name'=> 'url', 'type'=> 'xsd:string'), | |
38 | 'procedencia' => array('name' => 'procedencia', 'type' => 'xsd:string'), | |
39 | 'sistema' => array('name' => 'sistema', 'type' => 'xsd:string'), | |
40 | 'patologia' => array('name' => 'patologia', 'type' => 'xsd:string'), | |
41 | ) | |
42 | ); | |
43 | ||
44 | $server->wsdl->addComplexType( | |
45 | 'WordList', | |
46 | 'complexType', | |
47 | 'array', | |
48 | 'sequence', | |
49 | '', | |
50 | array( | |
51 | 'id' => array('name' => 'id', 'type' => 'xsd:int'), | |
52 | 'nome' => array('name' => 'nome', 'type' => 'xsd:string') | |
53 | ) | |
54 | ); | |
55 | ||
56 | $server->register('get_search_types', // method name | |
57 | array(), // input parameters | |
58 | array('return' => 'tns:WordList'), // output parameters | |
59 | 'urn:siapwsdl', // namespace | |
60 | 'urn:siapwsdl#get_search_types', // soapaction | |
61 | 'rpc', // style | |
62 | 'encoded', // use | |
63 | 'Get an image from the SIAP database' // documentation | |
64 | ); | |
65 | ||
66 | $server->register('get_search_type_keywords', // method name | |
67 | array('search_type' => 'xsd:int'), // input parameters | |
68 | array('return' => 'tns:WordList'), // output parameters | |
69 | 'urn:siapwsdl', // namespace | |
70 | 'urn:siapwsdl#get_search_type_keywords', // soapaction | |
71 | 'rpc', // style | |
72 | 'encoded', // use | |
73 | 'Get an image from the SIAP database' // documentation | |
74 | ); | |
75 | ||
76 | $server->register('search', // method name | |
77 | array('search_request' => 'tns:SearchRequest'), // input parameters | |
78 | array('return' => 'tns:SearchResults'), // output parameters | |
79 | 'urn:siapwsdl', // namespace | |
80 | 'urn:siapwsdl#search', // soapaction | |
81 | 'rpc', // style | |
82 | 'encoded', // use | |
83 | 'Perform a search in the SIAP database' // documentation | |
84 | ); | |
85 | ||
86 | function get_search_types() | |
87 | { | |
88 | // Not available in the database. | |
89 | // Those are the search types available for images. | |
90 | $search_types = array(); | |
91 | $search_types[] = array('id' => 1, 'nome' => 'Procedência'); | |
92 | $search_types[] = array('id' => 2, 'nome' => 'Sistema'); | |
93 | $search_types[] = array('id' => 3, 'nome' => 'Patologia'); | |
94 | return $search_types; | |
95 | } | |
96 | ||
97 | function get_search_type_keywords($search_type) | |
98 | { | |
99 | $ret = array(); | |
100 | switch($search_type) | |
101 | { | |
102 | case 1: | |
103 | $ret = get_keywords_by_search_type("procedencia"); | |
104 | break; | |
105 | case 2: | |
106 | $ret = get_keywords_by_search_type("sistema"); | |
107 | break; | |
108 | case 3: | |
109 | $ret = get_keywords_by_search_type("patologia"); | |
110 | break; | |
111 | } | |
112 | ||
113 | return $ret; | |
114 | } | |
115 | ||
486b041e MS |
116 | function get_search_keyword($search_request, $search_keyword){ |
117 | if (array_key_exists($search_keyword, $search_request)) { | |
118 | return $search_request[$search_keyword]; | |
119 | } else { | |
120 | return ''; | |
121 | } | |
122 | } | |
1c21f490 MS |
123 | |
124 | function search($search_request) { | |
486b041e MS |
125 | $palavra = get_search_keyword($search_request, 'palavra'); |
126 | $procedencia = get_search_keyword($search_request, 'procedencia'); | |
127 | $sistema = get_search_keyword($search_request, 'sistema'); | |
128 | $patologia = get_search_keyword($search_request, 'patologia'); | |
129 | $result = simple_search($palavra, $procedencia, $sistema, $patologia); | |
1c21f490 MS |
130 | return $result; |
131 | } | |
132 | ||
133 | ||
134 | // Use the request to (try to) invoke the service | |
135 | $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; | |
136 | $server->service($HTTP_RAW_POST_DATA); | |
137 | ?> |