1 |
9cc1a3e2
|
Andreas Kohlbecker
|
<?php
|
2 |
e06884e4
|
Andreas Kohlbecker
|
// $Id$
|
3 |
9cc1a3e2
|
Andreas Kohlbecker
|
|
4 |
05fe0ad6
|
Andreas Kohlbecker
|
/*
|
5 |
|
|
* @file
|
6 |
|
|
* cdm_dataportal
|
7 |
67a4a4c6
|
Andreas Kohlbecker
|
*
|
8 |
05fe0ad6
|
Andreas Kohlbecker
|
* Copyright (C) 2007 EDIT
|
9 |
67a4a4c6
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
10 |
05fe0ad6
|
Andreas Kohlbecker
|
* http://www.e-taxonomy.eu
|
11 |
b6294bbf
|
Andreas Kohlbecker
|
*
|
12 |
05fe0ad6
|
Andreas Kohlbecker
|
*/
|
13 |
|
|
|
14 |
47a8c0dd
|
Andreas Kohlbecker
|
require_once('cdm_dataportal.theme.php');
|
15 |
9cc1a3e2
|
Andreas Kohlbecker
|
|
16 |
67a4a4c6
|
Andreas Kohlbecker
|
/* ====================== hook implementations ====================== */
|
17 |
9cc1a3e2
|
Andreas Kohlbecker
|
|
18 |
|
|
/**
|
19 |
bf910101
|
Andreas Kohlbecker
|
* Implementation of hook_help()
|
20 |
67a4a4c6
|
Andreas Kohlbecker
|
*
|
21 |
9cc1a3e2
|
Andreas Kohlbecker
|
* Display help and module information
|
22 |
|
|
* @param section which section of the site we're displaying help
|
23 |
|
|
* @return help text for section
|
24 |
|
|
*/
|
25 |
|
|
function cdm_dataportal_help($section='') {
|
26 |
|
|
|
27 |
67a4a4c6
|
Andreas Kohlbecker
|
$out = '';
|
28 |
|
|
switch ($section) {
|
29 |
|
|
case "admin/modules#description":
|
30 |
|
|
$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
|
31 |
|
|
break;
|
32 |
|
|
}
|
33 |
|
|
return $out;
|
34 |
9cc1a3e2
|
Andreas Kohlbecker
|
}
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
/**
|
38 |
bf910101
|
Andreas Kohlbecker
|
* Implementation of hook_perm()
|
39 |
67a4a4c6
|
Andreas Kohlbecker
|
*
|
40 |
9cc1a3e2
|
Andreas Kohlbecker
|
* Valid permissions for this module
|
41 |
|
|
* @return array An array of valid permissions for the portfolio module
|
42 |
|
|
*/
|
43 |
|
|
function cdm_dataportal_perm() {
|
44 |
67a4a4c6
|
Andreas Kohlbecker
|
return array(
|
45 |
9cc1a3e2
|
Andreas Kohlbecker
|
'administer cdm_dataportal',
|
46 |
|
|
'cdm_dataportal view notes',
|
47 |
67a4a4c6
|
Andreas Kohlbecker
|
//TODO which else permission are required? -> check the WP6 requirements document
|
48 |
|
|
);
|
49 |
9cc1a3e2
|
Andreas Kohlbecker
|
}
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
bf910101
|
Andreas Kohlbecker
|
* Implementation of hook_menu()
|
54 |
9cc1a3e2
|
Andreas Kohlbecker
|
*/
|
55 |
|
|
function cdm_dataportal_menu($may_cache) {
|
56 |
|
|
$items = array();
|
57 |
|
|
if ($may_cache) {
|
58 |
67a4a4c6
|
Andreas Kohlbecker
|
|
59 |
9cc1a3e2
|
Andreas Kohlbecker
|
$items[] = array(
|
60 |
|
|
'path' => 'admin/settings/cdm_dataportal',
|
61 |
|
|
'title' => t('CDM Dataportal'),
|
62 |
|
|
'description' => t('Setting for the CDM Dataportal'),
|
63 |
|
|
'access' => user_access('administer cdm_dataportal'),
|
64 |
|
|
'callback' => 'drupal_get_form',
|
65 |
|
|
'callback arguments' => 'cdm_dataportal_settings',
|
66 |
a22e3f38
|
Andreas Kohlbecker
|
);
|
67 |
|
|
|
68 |
812a9c04
|
Andreas Kohlbecker
|
/*$items[] = array(
|
69 |
a22e3f38
|
Andreas Kohlbecker
|
'path' => 'admin/settings/cdm_dataportal/ws',
|
70 |
|
|
'title' => t('Web Service'),
|
71 |
|
|
'description' => t('Setting for the CDM Dataportal'),
|
72 |
|
|
'access' => user_access('administer cdm_dataportal'),
|
73 |
|
|
'callback' => 'drupal_get_form',
|
74 |
|
|
'callback arguments' => 'cdm_dataportal_settings',
|
75 |
|
|
'weight' => 1,
|
76 |
|
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
77 |
812a9c04
|
Andreas Kohlbecker
|
);*/
|
78 |
a22e3f38
|
Andreas Kohlbecker
|
|
79 |
9cc1a3e2
|
Andreas Kohlbecker
|
$items[] = array(
|
80 |
|
|
'path' => 'cdm_dataportal/names',
|
81 |
|
|
'callback' => 'cdm_dataportal_view_names',
|
82 |
|
|
'access' => true,
|
83 |
|
|
'type' => MENU_CALLBACK,
|
84 |
67a4a4c6
|
Andreas Kohlbecker
|
);
|
85 |
|
|
// optional callback arguments: page
|
86 |
|
|
|
87 |
|
|
$items[] = array(
|
88 |
9cc1a3e2
|
Andreas Kohlbecker
|
'path' => 'cdm_dataportal/taxon',
|
89 |
|
|
'callback' => 'cdm_dataportal_view_taxon',
|
90 |
|
|
'access' => true,
|
91 |
|
|
'type' => MENU_CALLBACK,
|
92 |
67a4a4c6
|
Andreas Kohlbecker
|
// expected callback arguments: name_uuid
|
93 |
|
|
);
|
94 |
ee99abea
|
Andreas Kohlbecker
|
|
95 |
|
|
$items[] = array(
|
96 |
|
|
'path' => 'cdm_dataportal/search/taxon',
|
97 |
|
|
'callback' => 'cdm_dataportal_view_search_taxon',
|
98 |
|
|
'access' => true,
|
99 |
|
|
'type' => MENU_CALLBACK,
|
100 |
|
|
);
|
101 |
|
|
|
102 |
67a4a4c6
|
Andreas Kohlbecker
|
$items[] = array(
|
103 |
05fe0ad6
|
Andreas Kohlbecker
|
'path' => 'cdm/xml2json',
|
104 |
|
|
'callback' => 'cdm_view_xml2json',
|
105 |
|
|
'access' => true,
|
106 |
|
|
'type' => MENU_CALLBACK,
|
107 |
67a4a4c6
|
Andreas Kohlbecker
|
);
|
108 |
|
|
|
109 |
9cc1a3e2
|
Andreas Kohlbecker
|
}
|
110 |
2189699f
|
Andreas Kohlbecker
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
|
111 |
6611904c
|
Andreas Kohlbecker
|
//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
|
112 |
|
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
|
113 |
9cc1a3e2
|
Andreas Kohlbecker
|
return $items;
|
114 |
c0ac3382
|
Andreas Kohlbecker
|
|
115 |
9cc1a3e2
|
Andreas Kohlbecker
|
}
|
116 |
|
|
|
117 |
d946105e
|
Andreas Kohlbecker
|
/**
|
118 |
|
|
* Implementation of hook_block()
|
119 |
67a4a4c6
|
Andreas Kohlbecker
|
*
|
120 |
d946105e
|
Andreas Kohlbecker
|
* Provides the following blocks:
|
121 |
|
|
* 0: list of links useful during development
|
122 |
|
|
*
|
123 |
|
|
* @param String $op
|
124 |
|
|
* @param int $delta
|
125 |
|
|
*/
|
126 |
|
|
function cdm_dataportal_block($op='list', $delta=0) {
|
127 |
|
|
// listing of blocks, such as on the admin/block page
|
128 |
|
|
if ($op == "list") {
|
129 |
|
|
$block[0]["info"] = t("CDM DataPortal DevLinks");
|
130 |
67a4a4c6
|
Andreas Kohlbecker
|
$block[1]["info"] = t("CDM DataPortal Credits");
|
131 |
ee99abea
|
Andreas Kohlbecker
|
$block[2]["info"] = t("CDM Search Taxa");
|
132 |
f5b3d74e
|
Andreas Kohlbecker
|
$block[3]["info"] = t("CDM Filters");
|
133 |
d946105e
|
Andreas Kohlbecker
|
return $block;
|
134 |
|
|
}
|
135 |
|
|
else if ($op == 'view') {
|
136 |
|
|
switch($delta){
|
137 |
|
|
case 0:
|
138 |
|
|
$block['subject'] = t('CDM DataPortal DevLinks');
|
139 |
05fe0ad6
|
Andreas Kohlbecker
|
$block['content'] = '<ul>
|
140 |
67a4a4c6
|
Andreas Kohlbecker
|
<li>'.l('A Taxon Page', cdm_dataportal_taxon_path('5000001-stub')).'</li>
|
141 |
|
|
<li>'.l('Name List - page1 of A', 'cdm_dataportal/names/A/1')
|
142 |
|
|
//.'</li><li>'.l('xml2json', 'cdm/xml2json/namelist;startwith=A.xml')
|
143 |
|
|
.'</li>
|
144 |
05fe0ad6
|
Andreas Kohlbecker
|
</ul>';
|
145 |
d946105e
|
Andreas Kohlbecker
|
return $block;
|
146 |
67a4a4c6
|
Andreas Kohlbecker
|
case 1:
|
147 |
|
|
$block['subject'] = t('Credits');
|
148 |
c0ac3382
|
Andreas Kohlbecker
|
$block['content'] = theme('cdm_credits');
|
149 |
|
|
return $block;
|
150 |
ee99abea
|
Andreas Kohlbecker
|
case 2:
|
151 |
|
|
$block['subject'] = t('Search Taxa');
|
152 |
|
|
$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
|
153 |
|
|
return $block;
|
154 |
d946105e
|
Andreas Kohlbecker
|
}
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
|
158 |
9cc1a3e2
|
Andreas Kohlbecker
|
|
159 |
47a8c0dd
|
Andreas Kohlbecker
|
/**
|
160 |
|
|
* Implementation of hook_validate()
|
161 |
|
|
*
|
162 |
|
|
* @param $element
|
163 |
|
|
*/
|
164 |
afbbba9e
|
Andreas Kohlbecker
|
function cdm_dataportal_settings_validate($form_id, $form_values){
|
165 |
812a9c04
|
Andreas Kohlbecker
|
|
166 |
afbbba9e
|
Andreas Kohlbecker
|
if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
|
167 |
67a4a4c6
|
Andreas Kohlbecker
|
form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
|
168 |
|
|
}
|
169 |
812a9c04
|
Andreas Kohlbecker
|
|
170 |
|
|
$cdm_webservice_url_changed = variable_get('cdm_webservice_url', '') != $form_values['cdm_webservice_url'];
|
171 |
|
|
|
172 |
|
|
if ($cdm_webservice_url_changed) {
|
173 |
65c7a058
|
Andreas Kohlbecker
|
$form_values['cdm_secUuid_default'] = '';
|
174 |
|
|
//TODO does the currentSecUuid need to be stored?
|
175 |
|
|
// Yes - if switching to another concept is permanent until an other concept switch is used.
|
176 |
|
|
// NO - if a user only 'visits' other concepts until this context is left by visiting a non taxon page
|
177 |
|
|
// , or explicitly when a concept switch is used.
|
178 |
6e1ec3a4
|
Andreas Kohlbecker
|
// other concept could be activated permanently by personal preference settings
|
179 |
|
|
//
|
180 |
|
|
// >> NO seems to be the desired solution <<
|
181 |
|
|
//
|
182 |
65c7a058
|
Andreas Kohlbecker
|
_cdm_dataportal_set_currentSecUuid(false);
|
183 |
812a9c04
|
Andreas Kohlbecker
|
// reset all cdm related data stored in the session
|
184 |
6e1ec3a4
|
Andreas Kohlbecker
|
// cdm_dataportal_session_clear($form_values['cdm_webservice_url']); // cdm_webservice_url is not further stored here
|
185 |
fa68c2c5
|
Andreas Kohlbecker
|
// clear the cdm webservice cache
|
186 |
|
|
cache_clear_all(NULL, 'cache_cdm_ws');
|
187 |
6e1ec3a4
|
Andreas Kohlbecker
|
// better clear secref_cache since i can not be sure if the cache has not be used during this response
|
188 |
|
|
cdm_api_secref_cache_clear();
|
189 |
812a9c04
|
Andreas Kohlbecker
|
}
|
190 |
5d53a642
|
Andreas Kohlbecker
|
if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
|
191 |
|
|
cache_clear_all(NULL, 'cache_cdm_ws');
|
192 |
6e1ec3a4
|
Andreas Kohlbecker
|
// better clear secref_cache since i can not be sure if the cache has not be used during this response
|
193 |
|
|
cdm_api_secref_cache_clear();
|
194 |
5d53a642
|
Andreas Kohlbecker
|
}
|
195 |
812a9c04
|
Andreas Kohlbecker
|
|
196 |
47a8c0dd
|
Andreas Kohlbecker
|
}
|
197 |
|
|
|
198 |
44e02685
|
Andreas Kohlbecker
|
/*
|
199 |
a27e2588
|
Andreas Kohlbecker
|
function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
|
200 |
|
|
$_SESSION['cdm'] = null;
|
201 |
|
|
if(is_string($cdm_ws_uri_update)){
|
202 |
|
|
$_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
function cdm_dataportal_session_validate(){
|
207 |
|
|
|
208 |
|
|
if(!isset($_SESSION['cdm']['ws_uri'])){
|
209 |
|
|
$_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
|
210 |
|
|
} else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
|
211 |
|
|
cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
|
212 |
|
|
}
|
213 |
|
|
}
|
214 |
44e02685
|
Andreas Kohlbecker
|
*/
|
215 |
812a9c04
|
Andreas Kohlbecker
|
|
216 |
ee99abea
|
Andreas Kohlbecker
|
function cdm_dataportal_search_taxon_form(){
|
217 |
|
|
|
218 |
6611904c
|
Andreas Kohlbecker
|
$url = 'cdm_dataportal/search/taxon';
|
219 |
|
|
$form['#method'] = 'get';
|
220 |
|
|
$form['#process'] = array('cdm_dataportal_search_process' => array());
|
221 |
|
|
$form['#action'] = url($url, NULL, NULL, true);
|
222 |
|
|
|
223 |
ee99abea
|
Andreas Kohlbecker
|
$form['queryString'] = array(
|
224 |
|
|
'#type' => 'textfield',
|
225 |
|
|
'#size' => 20,
|
226 |
|
|
'#attributes' => array('title' => t('Enter the name or part of a name you wish to search for.')),
|
227 |
|
|
'#default_value' => (isset($_SESSION['cdm']['search']['queryString']) ? $_SESSION['cdm']['search']['queryString'] : ''),
|
228 |
|
|
);
|
229 |
81df545f
|
Andreas Kohlbecker
|
$form['mode'] = array(
|
230 |
|
|
'#type' => 'select',
|
231 |
|
|
'#title' => t('Search Mode'),
|
232 |
|
|
'#options' => array(
|
233 |
|
|
'EXACT' => t('Exact'),
|
234 |
|
|
'BEGINNING' => t('Beginning'),
|
235 |
|
|
'ANYWHERE' => t('Anywhere')
|
236 |
|
|
),
|
237 |
|
|
'#description' => t('* can always be used as wildcard'),
|
238 |
|
|
'#default_value' => (isset($_SESSION['cdm']['search']['mode']) ? $_SESSION['cdm']['search']['mode'] : 'start'),
|
239 |
|
|
);
|
240 |
|
|
|
241 |
|
|
/*$form['onlyAccepted'] = array(
|
242 |
ee99abea
|
Andreas Kohlbecker
|
'#type' => 'checkbox',
|
243 |
|
|
'#title' => t('Only Accepted'),
|
244 |
|
|
'#attributes' => array('title' => t('Search only for taxa which are accepted by the current treatment.')),
|
245 |
|
|
'#default_value' => isset($_SESSION['cdm']['search']['onlyAccepted']) && $_SESSION['cdm']['search']['onlyAccepted'],
|
246 |
|
|
);
|
247 |
81df545f
|
Andreas Kohlbecker
|
*/
|
248 |
ee99abea
|
Andreas Kohlbecker
|
/*
|
249 |
|
|
$form['vernacular'] = array(
|
250 |
|
|
'#type' => 'checkbox',
|
251 |
|
|
'#title' => t('Vernacular Names'),
|
252 |
|
|
'#attributes' => array('title' => t('Search for vernacular names.')),
|
253 |
|
|
'#default_value' => isset($_SESSION['cdm']['search']['vernacular']) && $_SESSION['cdm']['search']['vernacular'],
|
254 |
|
|
);
|
255 |
|
|
$form['language'] = array(
|
256 |
|
|
'#type' => 'select',
|
257 |
|
|
'#title' => t('Language'),
|
258 |
|
|
'#options' => array(
|
259 |
|
|
'*' => t('ALL')
|
260 |
|
|
),
|
261 |
|
|
'#description' => t('The language of the vernacular name'),
|
262 |
|
|
'#default_value' => (isset($_SESSION['cdm']['search']['language']) ? $_SESSION['cdm']['search']['language'] : ''),
|
263 |
|
|
);
|
264 |
|
|
*/
|
265 |
6611904c
|
Andreas Kohlbecker
|
$form['page'] = array(
|
266 |
|
|
'#type' => 'hidden',
|
267 |
|
|
'#value' => '1',
|
268 |
|
|
);
|
269 |
|
|
|
270 |
ee99abea
|
Andreas Kohlbecker
|
$form['submit'] = array(
|
271 |
|
|
'#type' => 'submit',
|
272 |
6611904c
|
Andreas Kohlbecker
|
'#name' => '',
|
273 |
ee99abea
|
Andreas Kohlbecker
|
'#value' => t('Search'),
|
274 |
|
|
);
|
275 |
6611904c
|
Andreas Kohlbecker
|
|
276 |
|
|
// clean URL get forms breaks if we don't give it a 'q'.
|
277 |
|
|
if (!(bool)variable_get('clean_url', '0')) {
|
278 |
|
|
$form['q'] = array(
|
279 |
|
|
'#type' => 'hidden',
|
280 |
|
|
'#value' => $url,
|
281 |
|
|
'#name' => 'q',
|
282 |
|
|
);
|
283 |
|
|
}
|
284 |
ee99abea
|
Andreas Kohlbecker
|
return $form;
|
285 |
|
|
}
|
286 |
|
|
|
287 |
81df545f
|
Andreas Kohlbecker
|
//TODO is this function REACHABLE and thus in use??
|
288 |
6611904c
|
Andreas Kohlbecker
|
function cdm_dataportal_search_process($form) {
|
289 |
|
|
unset($form['form_id']);
|
290 |
|
|
unset($form['form_token']);
|
291 |
|
|
return $form;
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
/**
|
295 |
|
|
* Filters $_REQUEST by a list of valid request parameters and also sets defaults if required.
|
296 |
|
|
* returns the processed request parameters submitted by the search form.
|
297 |
|
|
*/
|
298 |
|
|
function cdm_dataportal_search_form_request(){
|
299 |
|
|
// keys map $REQUEST Keys values are optional default parameters if not null
|
300 |
81df545f
|
Andreas Kohlbecker
|
static $search_form_params = array('queryString'=>null, 'onlyAccepted' =>'0', 'page'=>null, 'pagesize'=>15, 'mode'=>null);
|
301 |
6611904c
|
Andreas Kohlbecker
|
|
302 |
|
|
$form_params = array();
|
303 |
|
|
foreach($search_form_params as $key=>$default ){
|
304 |
|
|
$form_params[$key] = ( isset($_REQUEST[$key]) && $_REQUEST[$key] != '' ? $_REQUEST[$key] : $default);
|
305 |
|
|
}
|
306 |
81df545f
|
Andreas Kohlbecker
|
$_SESSION['cdm']['search'] = $form_params;
|
307 |
6611904c
|
Andreas Kohlbecker
|
return $form_params;
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
|
311 |
81df545f
|
Andreas Kohlbecker
|
/* UNREACHABLE since action of form directly links to view
|
312 |
ee99abea
|
Andreas Kohlbecker
|
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
|
313 |
|
|
|
314 |
|
|
$_SESSION['cdm']['search'] = $form_values;
|
315 |
|
|
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
|
316 |
cacc1bbf
|
Andreas Kohlbecker
|
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
|
317 |
|
|
//$paramstr = compose_url_prameterstr($form_values);
|
318 |
|
|
//return url('/cdm_dataportal/search/taxon/', $paramstr);
|
319 |
ee99abea
|
Andreas Kohlbecker
|
}
|
320 |
6611904c
|
Andreas Kohlbecker
|
*/
|
321 |
9cc1a3e2
|
Andreas Kohlbecker
|
/* ====================== menu callback functions ====================== */
|
322 |
|
|
|
323 |
|
|
/**
|
324 |
|
|
* Generate main administration form.
|
325 |
|
|
*
|
326 |
|
|
* @return
|
327 |
|
|
* An array containing form items to place on the module settings page.
|
328 |
|
|
*/
|
329 |
|
|
function cdm_dataportal_settings(){
|
330 |
|
|
|
331 |
2e748209
|
Andreas Kohlbecker
|
$form = cdm_api_settings_form();
|
332 |
80047c07
|
Andreas Kohlbecker
|
|
333 |
2e748209
|
Andreas Kohlbecker
|
//TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
|
334 |
6ee322a7
|
Andreas Kohlbecker
|
$form['cdm_dataportal'] = array(
|
335 |
|
|
'#type' => 'fieldset',
|
336 |
|
|
'#title' => t('CDM DataPortal'),
|
337 |
|
|
'#collapsible' => FALSE,
|
338 |
|
|
'#collapsed' => TRUE,
|
339 |
|
|
);
|
340 |
e38d39d6
|
Andreas Kohlbecker
|
|
341 |
|
|
$form['cdm_dataportal']['secuuid_widget'] = array(
|
342 |
|
|
'#type' => 'select_secuuid',
|
343 |
|
|
'#title' => t('Default Concept Reference'),
|
344 |
|
|
'#description' => t('The default \'sensu\' reference to start the cdm_dataportal with. Per user choices are possible and may override this value.'),
|
345 |
|
|
'#varname' => 'cdm_secUuid_default',
|
346 |
44e02685
|
Andreas Kohlbecker
|
'#multiple' => false
|
347 |
e38d39d6
|
Andreas Kohlbecker
|
);
|
348 |
a22e3f38
|
Andreas Kohlbecker
|
|
349 |
e38d39d6
|
Andreas Kohlbecker
|
return system_settings_form($form);
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
/**
|
353 |
|
|
* Implementation of hook_elements().
|
354 |
|
|
*/
|
355 |
|
|
function cdm_dataportal_elements() {
|
356 |
|
|
$type['select_secuuid'] = array(
|
357 |
|
|
'#input' => TRUE,
|
358 |
|
|
'#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
|
359 |
|
|
//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
|
360 |
|
|
//'#default_value' => array(),
|
361 |
e18349d4
|
Andreas Kohlbecker
|
);
|
362 |
e38d39d6
|
Andreas Kohlbecker
|
return $type;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
|
366 |
|
|
/*
|
367 |
|
|
*
|
368 |
|
|
*/
|
369 |
|
|
function cdm_dataportal_select_secuuid_expand($element){
|
370 |
e18349d4
|
Andreas Kohlbecker
|
|
371 |
e38d39d6
|
Andreas Kohlbecker
|
$element['#tree'] = FALSE;
|
372 |
|
|
|
373 |
|
|
// any value submitted?
|
374 |
|
|
if(isset($element['#post'][$element['#varname']])){
|
375 |
|
|
$selected_values = $element['#post'][$element['#varname']];
|
376 |
|
|
} else {
|
377 |
|
|
// use those store in drupal
|
378 |
|
|
$selected_values = variable_get( $element['#varname'], array());
|
379 |
|
|
}
|
380 |
|
|
if(!is_array($selected_values)){
|
381 |
|
|
$selected_values = array($selected_values);
|
382 |
|
|
}
|
383 |
|
|
$options = array();
|
384 |
|
|
foreach($selected_values as $secUuid){
|
385 |
44e02685
|
Andreas Kohlbecker
|
$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
|
386 |
e38d39d6
|
Andreas Kohlbecker
|
}
|
387 |
e18349d4
|
Andreas Kohlbecker
|
|
388 |
e38d39d6
|
Andreas Kohlbecker
|
$element[$element['#varname']] = array(
|
389 |
|
|
'#type' => 'select',
|
390 |
|
|
'#options' => $options,
|
391 |
|
|
'#default_value' => array_values($options),
|
392 |
|
|
'#size' => $element['#multiple'] ? 12 : 2,
|
393 |
|
|
'#multiple' => $element['#multiple'],
|
394 |
|
|
);
|
395 |
|
|
return $element;
|
396 |
|
|
}
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
9cc1a3e2
|
Andreas Kohlbecker
|
/**
|
401 |
|
|
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
|
402 |
|
|
*
|
403 |
55e5b62d
|
Andreas Kohlbecker
|
* TODO: parameters are still preliminar
|
404 |
9cc1a3e2
|
Andreas Kohlbecker
|
* @param String $page page number to diplay defaults to page 1
|
405 |
|
|
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
|
406 |
|
|
*/
|
407 |
afbbba9e
|
Andreas Kohlbecker
|
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
|
408 |
67a4a4c6
|
Andreas Kohlbecker
|
|
409 |
ee99abea
|
Andreas Kohlbecker
|
$request_params = array(
|
410 |
|
|
'q' => $beginsWith,
|
411 |
|
|
//'sec' = '',
|
412 |
|
|
//'higherTaxa' => getFiters(),
|
413 |
|
|
// 'matchAnywhere' => false, // default is false
|
414 |
|
|
'page' => $page,
|
415 |
|
|
'onlyAccepted' => $onlyAccepted,
|
416 |
|
|
'pagesize' => 20 /*$_SESSION['cdm']['namelist_pagesize'] */);
|
417 |
|
|
|
418 |
|
|
$taxonSTOs = cdm_ws_get(CDM_WS_FIND_TAXA, $request_params);
|
419 |
67a4a4c6
|
Andreas Kohlbecker
|
/*
|
420 |
|
|
* FIXME the filter for accepted names will be a form element, thus this widget
|
421 |
|
|
* should be generated via form api preferably as block
|
422 |
|
|
*/
|
423 |
|
|
//$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
|
424 |
|
|
//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
|
425 |
cacc1bbf
|
Andreas Kohlbecker
|
$out .= theme('cdm_listof_taxa', $taxonSTOs);
|
426 |
67a4a4c6
|
Andreas Kohlbecker
|
return $out;
|
427 |
9cc1a3e2
|
Andreas Kohlbecker
|
}
|
428 |
|
|
|
429 |
47a8c0dd
|
Andreas Kohlbecker
|
|
430 |
9cc1a3e2
|
Andreas Kohlbecker
|
/**
|
431 |
|
|
* The taxon page gives detailed information on a taxon, it shows:
|
432 |
|
|
* - Taxon name
|
433 |
67a4a4c6
|
Andreas Kohlbecker
|
* - Full list of synonyms homotypic synonyms on top, followed by the
|
434 |
|
|
* heterotypic and finally followed by misapplied names.
|
435 |
afbbba9e
|
Andreas Kohlbecker
|
* The list is ordered historically.
|
436 |
67a4a4c6
|
Andreas Kohlbecker
|
* - All facts associated with the very taxon concept and taxon name.
|
437 |
9cc1a3e2
|
Andreas Kohlbecker
|
*
|
438 |
67a4a4c6
|
Andreas Kohlbecker
|
* @param String $uuid the UUID of the taxon
|
439 |
9cc1a3e2
|
Andreas Kohlbecker
|
*/
|
440 |
660d36e4
|
Andreas Kohlbecker
|
function cdm_dataportal_view_taxon($uuid, $arg2 = null){
|
441 |
67a4a4c6
|
Andreas Kohlbecker
|
|
442 |
|
|
|
443 |
53a13220
|
Andreas Kohlbecker
|
if(isset($arg2) && !is_numeric($arg2)){
|
444 |
|
|
|
445 |
|
|
switch ($args[0]){
|
446 |
|
|
case 'alternatives':
|
447 |
|
|
$alternatives = cdm_ws_get(CDM_WS_TAXON_ALTERNATIVES, $uuid);
|
448 |
|
|
return theme('cdm_alternative_taxa', $alternatives);
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
} else {
|
452 |
|
|
|
453 |
|
|
// display the page for the taxon defined by $uuid
|
454 |
|
|
$taxonTO = cdm_ws_get(CDM_WS_TAXON ,$uuid);
|
455 |
a27e2588
|
Andreas Kohlbecker
|
if(!$taxonTO){
|
456 |
|
|
drupal_set_title(t('Taxon does not exist'));
|
457 |
|
|
return false;
|
458 |
|
|
}
|
459 |
bbd3b088
|
Andreas Kohlbecker
|
_cdm_dataportal_set_currentSecUuid($taxonTO->sec->uuid);
|
460 |
53a13220
|
Andreas Kohlbecker
|
|
461 |
|
|
drupal_set_title(theme('cdm_taxon', $taxonTO, true));
|
462 |
|
|
//TODO retrieve complete synonymy and other data
|
463 |
|
|
|
464 |
|
|
$out = theme('cdm_taxon_page', $taxonTO);
|
465 |
|
|
return $out;
|
466 |
|
|
}
|
467 |
|
|
}
|
468 |
67a4a4c6
|
Andreas Kohlbecker
|
|
469 |
ad497c90
|
Andreas Kohlbecker
|
|
470 |
9cc1a3e2
|
Andreas Kohlbecker
|
|
471 |
ee99abea
|
Andreas Kohlbecker
|
/**
|
472 |
|
|
* Expected URL request parameters:
|
473 |
|
|
* - text
|
474 |
|
|
* - language
|
475 |
|
|
* - vernacular
|
476 |
|
|
*
|
477 |
|
|
* future extensions to meet palmweb mockup requirements:
|
478 |
|
|
* - habitat
|
479 |
|
|
* - uses
|
480 |
|
|
* - conservation status
|
481 |
|
|
* - locality / tdwg region
|
482 |
|
|
*/
|
483 |
6611904c
|
Andreas Kohlbecker
|
function cdm_dataportal_view_search_taxon(){
|
484 |
ee99abea
|
Andreas Kohlbecker
|
|
485 |
6611904c
|
Andreas Kohlbecker
|
$request_params = cdm_dataportal_search_form_request();
|
486 |
|
|
$sw_params = array_replace_key($request_params, array('queryString'=> 10 ));
|
487 |
|
|
$resultPageSTO = cdm_ws_get(CDM_WS_FIND_TAXA, $sw_params);
|
488 |
|
|
$resultPageSTO->pageNumber = $request_params['page'];
|
489 |
|
|
return theme('cdm_search_results', $resultPageSTO, 'cdm_dataportal/search/taxon', $request_params);
|
490 |
ee99abea
|
Andreas Kohlbecker
|
}
|
491 |
|
|
|
492 |
f5b3d74e
|
Andreas Kohlbecker
|
|
493 |
47a8c0dd
|
Andreas Kohlbecker
|
|
494 |
05fe0ad6
|
Andreas Kohlbecker
|
function cdm_view_xml2json(){
|
495 |
|
|
$file = arg(2);
|
496 |
|
|
$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
|
497 |
|
|
return xml2json::transformXmlStringToJson($datastr);
|
498 |
|
|
|
499 |
|
|
}
|
500 |
|
|
|
501 |
fa97cd20
|
Andreas Kohlbecker
|
/**
|
502 |
|
|
* Get a term for the current locale from the $localised_terms array.
|
503 |
|
|
* Uses global variable $locale from drupal (see drupal functions locale_initialize() for details)
|
504 |
67a4a4c6
|
Andreas Kohlbecker
|
* Function name is adapted from the drupal function t().
|
505 |
fa97cd20
|
Andreas Kohlbecker
|
*
|
506 |
|
|
*/
|
507 |
|
|
function cdm_dataportal_t($localised_terms){
|
508 |
|
|
global $locale; // drupal variable containing the current locale
|
509 |
|
|
return cdm_get_localised_term($localised_terms, $locale);
|
510 |
|
|
}
|
511 |
|
|
|
512 |
47a8c0dd
|
Andreas Kohlbecker
|
/* ====================== other functions ====================== */
|
513 |
|
|
|
514 |
ec0c70d2
|
Andreas Kohlbecker
|
/**
|
515 |
|
|
* Enter description here...
|
516 |
|
|
*
|
517 |
|
|
* @param String $uuid the UUID of the taxon
|
518 |
|
|
* @return the URL
|
519 |
|
|
*/
|
520 |
|
|
function cdm_dataportal_taxon_path($uuid){
|
521 |
|
|
return 'cdm_dataportal/taxon/'.$uuid;
|
522 |
ad497c90
|
Andreas Kohlbecker
|
}
|
523 |
|
|
|
524 |
ec0c70d2
|
Andreas Kohlbecker
|
/**
|
525 |
|
|
* Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
|
526 |
|
|
* If the taggename if empty the fullname will be returned.
|
527 |
|
|
*
|
528 |
8c19e1a5
|
Andreas Kohlbecker
|
* @param unknown_type $NameSTO a NameSTO, TreeNode or NameTO instance
|
529 |
67a4a4c6
|
Andreas Kohlbecker
|
* @return string
|
530 |
ec0c70d2
|
Andreas Kohlbecker
|
*/
|
531 |
|
|
function cdm_dataportal_shortname_of($NameSTO){
|
532 |
67a4a4c6
|
Andreas Kohlbecker
|
|
533 |
fa68c2c5
|
Andreas Kohlbecker
|
$name = '';
|
534 |
|
|
// get all tagged text tokens of the scientific name
|
535 |
|
|
foreach($NameSTO->taggedName as $tagtxt){
|
536 |
|
|
if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
|
537 |
|
|
$name .= ($name ? ' ' : '').$tagtxt->text;
|
538 |
|
|
}
|
539 |
|
|
}
|
540 |
|
|
$name = trim($name);
|
541 |
ec0c70d2
|
Andreas Kohlbecker
|
if($name){
|
542 |
44e02685
|
Andreas Kohlbecker
|
if(strpos($name, 'Incertae sedis') === false && $pos = stripos($name, ' ')){
|
543 |
ec0c70d2
|
Andreas Kohlbecker
|
return substr($name, 0, 1).'. '.substr($name, $pos);
|
544 |
|
|
} else {
|
545 |
|
|
return $name;
|
546 |
|
|
}
|
547 |
|
|
} else {
|
548 |
|
|
return $NameSTO->fullname;
|
549 |
|
|
}
|
550 |
|
|
}
|
551 |
47a8c0dd
|
Andreas Kohlbecker
|
|
552 |
67a4a4c6
|
Andreas Kohlbecker
|
/**
|
553 |
44e02685
|
Andreas Kohlbecker
|
* @param UUID $secUuid
|
554 |
67a4a4c6
|
Andreas Kohlbecker
|
*/
|
555 |
27c1d8ec
|
Andreas Kohlbecker
|
function _cdm_dataportal_set_currentSecUuid($secUuid){
|
556 |
67a4a4c6
|
Andreas Kohlbecker
|
|
557 |
44e02685
|
Andreas Kohlbecker
|
if(is_array($secUuid)){
|
558 |
|
|
$secUuid = $secUuid[0];
|
559 |
|
|
}
|
560 |
c0ac3382
|
Andreas Kohlbecker
|
if( !isset($_SESSION['cdm']['currentSecRef']['uuid']) || $_SESSION['cdm']['currentSecRef']['uuid'] != $secUuid){
|
561 |
812a9c04
|
Andreas Kohlbecker
|
if(!$secUuid){
|
562 |
|
|
$_SESSION['cdm']['currentSecRef'] = null;
|
563 |
|
|
} else {
|
564 |
3c088755
|
Andreas Kohlbecker
|
$secRef = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE ,$secUuid);
|
565 |
44e02685
|
Andreas Kohlbecker
|
if(isset($secRef[0])){
|
566 |
|
|
$_SESSION['cdm']['currentSecRef'] = (array)($secRef[0]);
|
567 |
|
|
}
|
568 |
812a9c04
|
Andreas Kohlbecker
|
}
|
569 |
27c1d8ec
|
Andreas Kohlbecker
|
}
|
570 |
|
|
}
|
571 |
|
|
|
572 |
|
|
/**
|
573 |
|
|
* returns the current secRef array from the users session.
|
574 |
|
|
* If the according session variable is not jet set the default
|
575 |
812a9c04
|
Andreas Kohlbecker
|
* as configured in the setting is used otherwise null.
|
576 |
f5b3d74e
|
Andreas Kohlbecker
|
*
|
577 |
|
|
* currentSecRef['uuid']
|
578 |
|
|
* currentSecRef[....
|
579 |
27c1d8ec
|
Andreas Kohlbecker
|
*
|
580 |
|
|
* @return array
|
581 |
|
|
*/
|
582 |
1dbc28d9
|
Andreas Kohlbecker
|
function _cdm_dataportal_currentSecRef_array(){
|
583 |
27c1d8ec
|
Andreas Kohlbecker
|
|
584 |
c0ac3382
|
Andreas Kohlbecker
|
if( !isset($_SESSION['cdm']['currentSecRef']['uuid'])){
|
585 |
812a9c04
|
Andreas Kohlbecker
|
$secUuid = variable_get('cdm_secUuid_default', null);
|
586 |
27c1d8ec
|
Andreas Kohlbecker
|
_cdm_dataportal_set_currentSecUuid($secUuid);
|
587 |
67a4a4c6
|
Andreas Kohlbecker
|
}
|
588 |
27c1d8ec
|
Andreas Kohlbecker
|
return $_SESSION['cdm']['currentSecRef'];
|
589 |
67a4a4c6
|
Andreas Kohlbecker
|
}
|
590 |
|
|
|
591 |
81df545f
|
Andreas Kohlbecker
|
function _cdm_dataportal_acceptetByCurrentView($taxonTO){
|
592 |
|
|
$current_secref = _cdm_dataportal_currentSecRef_array();
|
593 |
|
|
|
594 |
|
|
return $current_secref->uuid == $taxonTO->secuuid && $taxonTO->accepted;
|
595 |
|
|
}
|
596 |
44e02685
|
Andreas Kohlbecker
|
|
597 |
47a8c0dd
|
Andreas Kohlbecker
|
/**
|
598 |
|
|
* @param $str the string to truncate
|
599 |
|
|
* @param $len the maximun length
|
600 |
|
|
* @param $appendix an optional appendix.
|
601 |
|
|
*
|
602 |
|
|
* @return the string truncated to the specified length or the original string as given as parameter.
|
603 |
|
|
* if an appendix has been defined the resulting string
|
604 |
|
|
* will have the specified length inculding the the appendix.
|
605 |
|
|
*/
|
606 |
|
|
function str_trunk(&$str, $len, $appendix=''){
|
607 |
67a4a4c6
|
Andreas Kohlbecker
|
if(strlen($str) >= $len )
|
608 |
|
|
return substr($str, 0, $len - strlen($appendix)).$appendix;
|
609 |
|
|
else
|
610 |
|
|
return $str;
|
611 |
47a8c0dd
|
Andreas Kohlbecker
|
}
|
612 |
|
|
|
613 |
|
|
/**
|
614 |
|
|
* @param string $str
|
615 |
|
|
* @param string $sub
|
616 |
|
|
* @return boolean
|
617 |
|
|
*/
|
618 |
|
|
function str_beginsWith( $str, $sub ) {
|
619 |
67a4a4c6
|
Andreas Kohlbecker
|
return ( substr( $str, 0, strlen( $sub ) ) === $sub );
|
620 |
47a8c0dd
|
Andreas Kohlbecker
|
}
|
621 |
|
|
|
622 |
|
|
/**
|
623 |
67a4a4c6
|
Andreas Kohlbecker
|
*
|
624 |
47a8c0dd
|
Andreas Kohlbecker
|
* @param string $str
|
625 |
|
|
* @param string $sub
|
626 |
|
|
* @return boolean
|
627 |
|
|
*/
|
628 |
|
|
function str_endsWith( $str, $sub ) {
|
629 |
67a4a4c6
|
Andreas Kohlbecker
|
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
|
630 |
47a8c0dd
|
Andreas Kohlbecker
|
}
|
631 |
cacc1bbf
|
Andreas Kohlbecker
|
|
632 |
6611904c
|
Andreas Kohlbecker
|
|
633 |
|
|
function array_replace_key($array, $replace_map){
|
634 |
|
|
foreach($replace_map as $key=>$newkey){
|
635 |
|
|
if(isset($array[$key])){
|
636 |
|
|
$array[$newkey] = $array[$key];
|
637 |
|
|
unset($array[$key]);
|
638 |
|
|
}
|
639 |
|
|
}
|
640 |
|
|
return $array;
|
641 |
|
|
}
|
642 |
|
|
|
643 |
|
|
|
644 |
cacc1bbf
|
Andreas Kohlbecker
|
function compose_url_prameterstr($parameters = array()){
|
645 |
|
|
$pstr = '';
|
646 |
|
|
foreach($parameters as $key=>$value){
|
647 |
6611904c
|
Andreas Kohlbecker
|
$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
|
648 |
cacc1bbf
|
Andreas Kohlbecker
|
}
|
649 |
|
|
return $pstr;
|
650 |
|
|
}
|
651 |
6f4dd14a
|
Andreas Kohlbecker
|
|