Revision d8e85b2d
Added by Andreas Kohlbecker over 9 years ago
7.x/modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
293 | 293 |
return $occurrence_featureTree; |
294 | 294 |
} |
295 | 295 |
|
296 |
/** |
|
297 |
* Transforms the list of the given term base instances to a alphabetical ordered options array. |
|
298 |
* |
|
299 |
* The options array is suitable for drupal form API elements that allow multiple choices. |
|
300 |
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#options |
|
301 |
* |
|
302 |
* @param array $terms |
|
303 |
* a list of CDM DefinedTermBase instances |
|
304 |
* |
|
305 |
* @return array |
|
306 |
* the terms in an array as options for a form element that allows multiple choices. |
|
307 |
*/ |
|
308 |
function cdm_terms_as_options($terms){ |
|
309 |
$options = array(); |
|
310 |
if(isset($terms) && is_array($terms)){ |
|
311 |
foreach ($terms as $term){ |
|
312 |
$options[$term->uuid] = $term->representation_L10n; |
|
313 |
} |
|
314 |
} |
|
315 |
array_multisort($options, SORT_ASC); |
|
316 |
return $options; |
|
317 |
} |
|
318 |
|
|
319 | 296 |
/** |
320 | 297 |
* Returns the FeatureTree for structured descriptions |
321 | 298 |
* |
... | ... | |
1223 | 1200 |
return $response; |
1224 | 1201 |
} |
1225 | 1202 |
|
1226 |
/** |
|
1227 |
* @todo Please document this function. |
|
1228 |
* @see http://drupal.org/node/1354 |
|
1229 |
*/ |
|
1230 |
function cdm_rankVocabulary_as_option() { |
|
1231 |
$options = cdm_Vocabulary_as_option(UUID_RANK); |
|
1232 |
array_unshift ($options, ""); |
|
1233 |
return $options; |
|
1234 |
} |
|
1203 |
|
|
1204 |
// =============================Terms and Vocabularies ========================================= // |
|
1235 | 1205 |
|
1236 | 1206 |
/** |
1237 | 1207 |
* |
... | ... | |
1251 | 1221 |
return ''; |
1252 | 1222 |
} |
1253 | 1223 |
|
1224 |
/** |
|
1225 |
* Transforms the list of the given term base instances to a alphabetical ordered options array. |
|
1226 |
* |
|
1227 |
* The options array is suitable for drupal form API elements that allow multiple choices. |
|
1228 |
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#options |
|
1229 |
* |
|
1230 |
* @param array $terms |
|
1231 |
* a list of CDM DefinedTermBase instances |
|
1232 |
* |
|
1233 |
* @param $sort_by |
|
1234 |
* Optionally sort option SORT_NATURAL (default: sorts after the cdm order index ), |
|
1235 |
* to sort alphabetically: SORT_ASC, SORT_DESC |
|
1236 |
* |
|
1237 |
* @param $term_label_callback |
|
1238 |
* A callback function to override the term representations |
|
1239 |
* |
|
1240 |
* @return array |
|
1241 |
* the terms in an array as options for a form element that allows multiple choices. |
|
1242 |
*/ |
|
1243 |
function cdm_terms_as_options($terms, $sort_by = SORT_NATURAL, $term_label_callback = NULL){ |
|
1244 |
$options = array(); |
|
1245 |
if(isset($terms) && is_array($terms)){ |
|
1246 |
foreach ($terms as $term){ |
|
1247 |
if ($term_label_callback && function_exists($term_label_callback)) { |
|
1248 |
$options[$term->uuid] = call_user_func($term_label_callback, $term); |
|
1249 |
} else { |
|
1250 |
//TODO use cdm_term_representation() here? |
|
1251 |
$options[$term->uuid] = t($term->representation_L10n); |
|
1252 |
} |
|
1253 |
} |
|
1254 |
} |
|
1255 |
switch($sort_by){ |
|
1256 |
case SORT_NATURAL: array_reverse($options); |
|
1257 |
break; |
|
1258 |
default: array_multisort($options, SORT_ASC); |
|
1259 |
} |
|
1260 |
|
|
1261 |
return $options; |
|
1262 |
} |
|
1263 |
|
|
1264 |
/** |
|
1265 |
* @todo Please document this function. |
|
1266 |
* @see http://drupal.org/node/1354 |
|
1267 |
*/ |
|
1268 |
function cdm_Vocabulary_as_option($vocabularyUuid, $term_label_callback = NULL) { |
|
1269 |
static $vocabularyOptions = array(); |
|
1270 |
|
|
1271 |
if (!isset($vocabularyOptions[$vocabularyUuid])) { |
|
1272 |
$terms = cdm_ws_fetch_all('termVocabulary/' . $vocabularyUuid . '/terms'); |
|
1273 |
$vocabularyOptions[$vocabularyUuid] = cdm_terms_as_options($terms, SORT_NATURAL, $term_label_callback); |
|
1274 |
} |
|
1275 |
return $vocabularyOptions[$vocabularyUuid]; |
|
1276 |
} |
|
1277 |
|
|
1278 |
/** |
|
1279 |
* @param $term_type one of |
|
1280 |
* - Unknown |
|
1281 |
* - Language |
|
1282 |
* - NamedArea |
|
1283 |
* - Rank |
|
1284 |
* - Feature |
|
1285 |
* - AnnotationType |
|
1286 |
* - MarkerType |
|
1287 |
* - ExtensionType |
|
1288 |
* - DerivationEventType |
|
1289 |
* - PresenceAbsenceTerm |
|
1290 |
* - NomenclaturalStatusType |
|
1291 |
* - NameRelationshipType |
|
1292 |
* - HybridRelationshipType |
|
1293 |
* - SynonymRelationshipType |
|
1294 |
* - TaxonRelationshipType |
|
1295 |
* - NameTypeDesignationStatus |
|
1296 |
* - SpecimenTypeDesignationStatus |
|
1297 |
* - InstitutionType |
|
1298 |
* - NamedAreaType |
|
1299 |
* - NamedAreaLevel |
|
1300 |
* - RightsType |
|
1301 |
* - MeasurementUnit |
|
1302 |
* - StatisticalMeasure |
|
1303 |
* - MaterialOrMethod |
|
1304 |
* - Material |
|
1305 |
* - Method |
|
1306 |
* - Modifier |
|
1307 |
* - Scope |
|
1308 |
* - Stage |
|
1309 |
* - KindOfUnit |
|
1310 |
* - Sex |
|
1311 |
* - ReferenceSystem |
|
1312 |
* - State |
|
1313 |
* - NaturalLanguageTerm |
|
1314 |
* - TextFormat |
|
1315 |
* - DeterminationModifier |
|
1316 |
* - DnaMarker |
|
1317 |
*/ |
|
1318 |
function cdm_terms_by_type_as_option($term_type, $sort_by = SORT_NATURAL, $term_label_callback = NULL){ |
|
1319 |
$terms = cdm_ws_fetch_all(CDM_WS_TERM, array('class' => $term_type)); |
|
1320 |
return cdm_terms_as_options($terms, $sort_by, $term_label_callback); |
|
1321 |
} |
|
1322 |
|
|
1323 |
/** |
|
1324 |
* @todo Please document this function. |
|
1325 |
* @see http://drupal.org/node/1354 |
|
1326 |
*/ |
|
1327 |
function cdm_rankVocabulary_as_option() { |
|
1328 |
$options = cdm_Vocabulary_as_option(UUID_RANK); |
|
1329 |
array_unshift ($options, ""); |
|
1330 |
return $options; |
|
1331 |
} |
|
1332 |
|
|
1333 |
/** |
|
1334 |
* @todo Please document this function. |
|
1335 |
* @see http://drupal.org/node/1354 |
|
1336 |
*/ |
|
1337 |
function _cdm_relationship_type_term_label_callback($term) { |
|
1338 |
if (isset($term->representation_L10n_abbreviatedLabel)) { |
|
1339 |
return $term->representation_L10n_abbreviatedLabel . ' : ' . t($term->representation_L10n); |
|
1340 |
} |
|
1341 |
else { |
|
1342 |
return t($term->representation_L10n); |
|
1343 |
} |
|
1344 |
} |
|
1345 |
|
|
1346 |
// ========================================================================================== // |
|
1254 | 1347 |
/** |
1255 | 1348 |
* @todo Improve documentation of this function. |
1256 | 1349 |
* |
... | ... | |
1288 | 1381 |
return $options; |
1289 | 1382 |
} |
1290 | 1383 |
|
1291 |
/** |
|
1292 |
* @todo Please document this function. |
|
1293 |
* @see http://drupal.org/node/1354 |
|
1294 |
*/ |
|
1295 |
function cdm_Vocabulary_as_option($vocabularyUuid, $term_label_callback = NULL) { |
|
1296 |
static $vocabularyOptions = array(); |
|
1297 |
|
|
1298 |
if (!isset($vocabularyOptions[$vocabularyUuid])) { |
|
1299 |
$terms = cdm_ws_fetch_all('termVocabulary/' . $vocabularyUuid . '/terms'); |
|
1300 |
$vocabularyOptions[$vocabularyUuid] = array(); |
|
1301 |
|
|
1302 |
if ($terms) { |
|
1303 |
foreach ($terms as $term) { |
|
1304 |
if ($term_label_callback && function_exists($term_label_callback)) { |
|
1305 |
$vocabularyOptions[$vocabularyUuid][$term->uuid] = call_user_func($term_label_callback, $term); |
|
1306 |
} |
|
1307 |
else { |
|
1308 |
$vocabularyOptions[$vocabularyUuid][$term->uuid] = t($term->representation_L10n); |
|
1309 |
} |
|
1310 |
} |
|
1311 |
array_reverse($vocabularyOptions[$vocabularyUuid]); |
|
1312 |
} |
|
1313 |
} |
|
1314 |
return $vocabularyOptions[$vocabularyUuid]; |
|
1315 |
} |
|
1316 |
|
|
1317 |
/** |
|
1318 |
* @todo Please document this function. |
|
1319 |
* @see http://drupal.org/node/1354 |
|
1320 |
*/ |
|
1321 |
function _cdm_relationship_type_term_label_callback($term) { |
|
1322 |
if (isset($term->representation_L10n_abbreviatedLabel)) { |
|
1323 |
return $term->representation_L10n_abbreviatedLabel . ' : ' . t($term->representation_L10n); |
|
1324 |
} |
|
1325 |
else { |
|
1326 |
return t($term->representation_L10n); |
|
1327 |
} |
|
1328 |
} |
|
1329 | 1384 |
|
1330 | 1385 |
/** |
1331 | 1386 |
* Fetches all TaxonDescription descriptions elements wich are accociated to the |
... | ... | |
1392 | 1447 |
$annotations = array(); |
1393 | 1448 |
foreach ($cdmBase->annotations as $annotation) { |
1394 | 1449 |
if ($includeTypes) { |
1395 |
if ((isset($annotation->annotationType->uuid) && in_array($annotation->annotationType->uuid, $includeTypes, TRUE)) || ($annotation->annotationType === NULL && in_array('NULL_VALUE', $includeTypes, TRUE))) { |
|
1450 |
if ( |
|
1451 |
( isset($annotation->annotationType->uuid) && in_array($annotation->annotationType->uuid, $includeTypes, TRUE) ) |
|
1452 |
|| ($annotation->annotationType === NULL && in_array('NULL_VALUE', $includeTypes, TRUE)) |
|
1453 |
) { |
|
1396 | 1454 |
$annotations[] = $annotation; |
1397 | 1455 |
} |
1398 | 1456 |
} |
Also available in: Unified diff
refactoring term and vocabulary functions