Revision 87b304a7
Added by Andreas Kohlbecker about 8 years ago
modules/cdm_dataportal/includes/taxon.inc | ||
---|---|---|
311 | 311 |
return $out; |
312 | 312 |
} |
313 | 313 |
|
314 |
|
|
315 |
/** |
|
316 |
* Creates markup for a taxon which is the accepted of another one |
|
317 |
* |
|
318 |
* @param $accepted_for_uuid |
|
319 |
* The uuid of the accepted taxon |
|
320 |
*/ |
|
321 |
function cdm_accepted_for($accepted_for_uuid) { |
|
322 |
|
|
323 |
if(!is_uuid($accepted_for_uuid)){ |
|
324 |
return ''; |
|
325 |
} |
|
326 |
|
|
327 |
RenderHints::pushToRenderStack('acceptedFor'); |
|
328 |
$out = ''; |
|
329 |
|
|
330 |
$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $accepted_for_uuid); |
|
331 |
if ($synonym) { |
|
332 |
$out .= '<span class="acceptedFor">'; |
|
333 |
$out .= t('is accepted for '); |
|
334 |
if (isset($synonym->name->nomenclaturalReference)) { |
|
335 |
$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid)); |
|
336 |
} |
|
337 |
$out .= render_taxon_or_name($synonym->name, NULL, $referenceUri); |
|
338 |
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $synonym)); |
|
339 |
$out .= '</span>'; |
|
340 |
} |
|
341 |
RenderHints::popFromRenderStack(); |
|
342 |
return $out; |
|
343 |
} |
|
344 |
|
|
345 |
/** |
|
346 |
* Compose function for a list of taxa. |
|
347 |
* |
|
348 |
* This function is for example used toi display search results or the taxa for a taxon name in the name page. |
|
349 |
* |
|
350 |
* @param $taxon_list array |
|
351 |
* The list of CDM Taxon entities. e.g. The records array as contained in a pager object. |
|
352 |
* @param $freetext_search_results array |
|
353 |
* @param $show_classification boolean |
|
354 |
* |
|
355 |
* @ingroup compose |
|
356 |
* |
|
357 |
*/ |
|
358 |
function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) { |
|
359 |
|
|
360 |
$unclassified_snippet = '<span class="unclassified">' . t('unclassified') . '</span>'; |
|
361 |
|
|
362 |
RenderHints::pushToRenderStack('list_of_taxa'); |
|
363 |
|
|
364 |
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME); |
|
365 |
|
|
366 |
$showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails']; |
|
367 |
$showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails']; |
|
368 |
$searched_in_classification = cdm_dataportal_searched_in_classification(); |
|
369 |
$searched_in_classification_uuid = null; |
|
370 |
if(isset($searched_in_classification->uuid)){ |
|
371 |
$searched_in_classification_uuid = $searched_in_classification->uuid; |
|
372 |
} |
|
373 |
|
|
374 |
// .. Well, for sure not as performant as before, but better than nothing. |
|
375 |
$synonym_uuids = array(); |
|
376 |
$misappied_uuids = array(); |
|
377 |
foreach ($taxon_list as $taxon) { |
|
378 |
if ($taxon->class == "Synonym") { |
|
379 |
if (!array_key_exists($taxon->uuid, $synonym_uuids)) { |
|
380 |
$synonym_uuids[$taxon->uuid] = $taxon->uuid; |
|
381 |
} |
|
382 |
} |
|
383 |
elseif (!_cdm_dataportal_acceptedByCurrentView($taxon)) { |
|
384 |
// Assuming that it is a misappied name, will be further examined below. |
|
385 |
$misappied_uuids[$taxon->uuid] = $taxon->uuid; |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
// Batch service not jet implemented: |
|
390 |
// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, |
|
391 |
// join(',', $synonym_uuids)); |
|
392 |
// thus ... |
|
393 |
$table_of_accepted = array(); |
|
394 |
|
|
395 |
foreach ($synonym_uuids as $relatedUuid) { |
|
396 |
$table_of_accepted[$relatedUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array( |
|
397 |
$relatedUuid, |
|
398 |
$searched_in_classification_uuid, |
|
399 |
)); |
|
400 |
} |
|
401 |
|
|
402 |
foreach ($misappied_uuids as $relatedUuid) { |
|
403 |
$taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array( |
|
404 |
$relatedUuid, |
|
405 |
)); |
|
406 |
foreach ($taxonRelations as $relation) { |
|
407 |
if ($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) { |
|
408 |
$table_of_accepted[$relatedUuid][] = $relation->toTaxon; |
|
409 |
} |
|
410 |
} |
|
411 |
} |
|
412 |
|
|
413 |
$out = '<ul class="cdm_names" style="background-image: none;">'; |
|
414 |
$itemCnt = -1; |
|
415 |
foreach ($taxon_list as $taxon) { |
|
416 |
$itemCnt++; |
|
417 |
if (isset($table_of_accepted[$taxon->uuid])) { |
|
418 |
// Its a synonym or misapplied name. |
|
419 |
$is_synonym = isset($synonym_uuids[$taxon->uuid]); //TODO better use the $taxon->class attribute? |
|
420 |
$taxon_type = $is_synonym ? "Synonym" : "misapplied-name"; |
|
421 |
|
|
422 |
$acceptedTaxa = $table_of_accepted[$taxon->uuid]; |
|
423 |
|
|
424 |
if (count($acceptedTaxa) == 1) { |
|
425 |
|
|
426 |
$acceptedTaxon = $acceptedTaxa[0]; |
|
427 |
$taxonUri = uri_to_synonym($taxon->uuid, $acceptedTaxon->uuid, 'synonymy'); |
|
428 |
$referenceUri = ''; |
|
429 |
if (isset($acceptedTaxon->name->nomenclaturalReference)) { |
|
430 |
$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid)); |
|
431 |
} |
|
432 |
$taxon_or_name = $is_synonym ? $taxon->name : $taxon; |
|
433 |
// $taxon_or_name this is a trick to suppress the sec reference for sysnonyms |
|
434 |
// supplying the name will cause render_taxon_or_name() to not show the sec reference |
|
435 |
$out .= '<li class="' . $taxon_type . '">' . render_taxon_or_name($taxon_or_name, $taxonUri, $referenceUri); |
|
436 |
if ($show_classification) { |
|
437 |
$classifications = get_classifications_for_taxon($taxon); |
|
438 |
$classification_titles = array(); |
|
439 |
foreach ($classifications as $classification) { |
|
440 |
if (isset($classification->titleCache)) { |
|
441 |
$classification_titles[] = $classification->titleCache; |
|
442 |
} |
|
443 |
} |
|
444 |
if(count($classification_titles) == 0){ |
|
445 |
$classification_titles[] = $unclassified_snippet; |
|
446 |
} |
|
447 |
$out .= ' : <span class="classifications">' . implode(', ', $classification_titles) . '</span>'; |
|
448 |
} |
|
449 |
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon)); |
|
450 |
if ($showMedia_synonyms) { |
|
451 |
$out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $acceptedTaxon)); |
|
452 |
} |
|
453 |
} |
|
454 |
else { |
|
455 |
|
|
456 |
// TODO avoid using Ajax in the cdm_dynabox .... why? |
|
457 |
// TODO add media. |
|
458 |
$out .= cdm_dynabox( |
|
459 |
$taxon->uuid, |
|
460 |
render_taxon_or_name($taxon->name, NULL, NULL, FALSE), |
|
461 |
cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, |
|
462 |
array( |
|
463 |
$taxon->uuid, |
|
464 |
$searched_in_classification_uuid |
|
465 |
) |
|
466 |
), |
|
467 |
'cdm_list_of_taxa', |
|
468 |
'show accepted taxa of this ' . $taxon_type, |
|
469 |
array('li', 'ul'), |
|
470 |
array('class' => array($taxon_type)) |
|
471 |
); |
|
472 |
} |
|
473 |
} |
|
474 |
else { |
|
475 |
// Its a Taxon. |
|
476 |
$taxonUri = url(path_to_taxon($taxon->uuid)); |
|
477 |
$referenceUri = ''; |
|
478 |
if (isset($taxon->name->nomenclaturalReference)) { |
|
479 |
$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid)); |
|
480 |
} |
|
481 |
$out .= '<li class="Taxon">' . render_taxon_or_name($taxon, $taxonUri, $referenceUri); |
|
482 |
if ($show_classification) { |
|
483 |
$classifications = get_classifications_for_taxon($taxon); |
|
484 |
$classification_titles = array(); |
|
485 |
foreach ($classifications as $classification) { |
|
486 |
if (isset($classification->titleCache)) { |
|
487 |
$classification_titles[] = $classification->titleCache; |
|
488 |
} |
|
489 |
} |
|
490 |
if(count($classification_titles) == 0){ |
|
491 |
$classification_titles[] = $unclassified_snippet; |
|
492 |
} |
|
493 |
$out .= ' : <span class="classifications">' . implode(', ', $classification_titles) . '</span>'; |
|
494 |
} |
|
495 |
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon)); |
|
496 |
|
|
497 |
if ($showMedia_taxa) { |
|
498 |
$out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon)); |
|
499 |
} |
|
500 |
} |
|
501 |
|
|
502 |
/* |
|
503 |
* the score field will be empty in case of MultiTermQueries like |
|
504 |
* WildcardQueries, since these are constant score by default |
|
505 |
* since Lucene 2.9 |
|
506 |
*/ |
|
507 |
if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){ |
|
508 |
$percentage = ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100; |
|
509 |
$out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>'; |
|
510 |
$out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>'; |
|
511 |
} |
|
512 |
|
|
513 |
// Render highlighted fragments, these are made available by free text |
|
514 |
// searches. |
|
515 |
if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) { |
|
516 |
$field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap; |
|
517 |
if (count($field_fragments) > 0) { |
|
518 |
$fragments_out = ''; |
|
519 |
foreach ($field_fragments as $fieldName => $fragments) { |
|
520 |
$fragments_out .= '... <span class="' . $fieldName. '">' . filter_xss(join(" ... ", $fragments), array('b') ) . '</span>'; |
|
521 |
} |
|
522 |
$out .= '<div class="fragment_highlight">' . $fragments_out . ' ...</div>'; |
|
523 |
} |
|
524 |
} |
|
525 |
|
|
526 |
$out .= '</li>'; |
|
527 |
} |
|
528 |
|
|
529 |
$out .= '</ul>'; |
|
530 |
RenderHints::popFromRenderStack(); |
|
531 |
|
|
532 |
return markup_to_render_array($out); // TODO create render array of all list items in function |
|
533 |
} |
|
534 |
|
Also available in: Unified diff
refactoring: refactored functions moved into includes