cdm-dataportal / modules / cdm_dataportal / includes / pages.inc @ 6eaec849
History | View | Annotate | Download (47.1 KB)
1 |
<?php |
---|---|
2 |
/** |
3 |
* @file |
4 |
* Page functions. |
5 |
* |
6 |
* @copyright |
7 |
* (C) 2007-2012 EDIT |
8 |
* European Distributed Institute of Taxonomy |
9 |
* http://www.e-taxonomy.eu |
10 |
* |
11 |
* The contents of this module are subject to the Mozilla |
12 |
* Public License Version 1.1. |
13 |
* @see http://www.mozilla.org/MPL/MPL-1.1.html |
14 |
* |
15 |
* @author |
16 |
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org> |
17 |
*/ |
18 |
|
19 |
|
20 |
/** |
21 |
* Creates a render array representing the ocurrences associetad with the $taxon. |
22 |
* |
23 |
* The resulting render array contains two elements: |
24 |
* - 'map': A map showing all point locations of the occurences is availabale |
25 |
* - 'specimen_list': the list of occurences prepated as table for theme_table() |
26 |
* |
27 |
* @param object $taxon |
28 |
* A cdm Taxon object |
29 |
* @return |
30 |
* A render array suitable for drupal_render() |
31 |
* |
32 |
*/ |
33 |
function cdm_dataportal_taxon_page_specimens($taxon) { |
34 |
|
35 |
$render_array = array(); |
36 |
RenderHints::pushToRenderStack('taxon_page_specimens'); |
37 |
|
38 |
$relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT)); |
39 |
$relationship_choice['direct'] = get_selection($relationship_choice['direct']); |
40 |
$relationship_choice['invers'] = get_selection($relationship_choice['invers']); |
41 |
|
42 |
$by_associatedtaxon_query_parameters = array( |
43 |
'relationshipsInvers' => implode(',', $relationship_choice['invers']), |
44 |
'relationships' => implode(',', $relationship_choice['direct']), |
45 |
); |
46 |
|
47 |
if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) { |
48 |
$by_associatedtaxon_query_parameters = array_merge($by_associatedtaxon_query_parameters, $_REQUEST['pager']); |
49 |
} |
50 |
|
51 |
$by_associatedtaxon_query = http_build_query($by_associatedtaxon_query_parameters); |
52 |
|
53 |
$ws_string = 'specimensOrObservation'; |
54 |
if (variable_get('cdm_dataportal_specimen_derivate_tree')){ |
55 |
$ws_string .= "DTOs"; |
56 |
}else{ |
57 |
$ws_string .= "s"; |
58 |
} |
59 |
|
60 |
$specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, $ws_string)); |
61 |
if(!variable_get('cdm_dataportal_specimen_derivate_tree')) { |
62 |
$pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON, |
63 |
null, |
64 |
$by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid |
65 |
); |
66 |
$specimensOrObservations = array(); |
67 |
if (isset($pager->records[0])) { |
68 |
$specimensOrObservations = $pager->records; |
69 |
} |
70 |
} |
71 |
// cdm_ws_get(CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON, |
72 |
// null, |
73 |
// $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid |
74 |
// ); |
75 |
|
76 |
// $specimensOrObservations = array(); |
77 |
// if(isset($pager->records[0])){ |
78 |
// $specimensOrObservations = $pager->records; |
79 |
// } |
80 |
|
81 |
// order occurrences by date but types should be on top of the list |
82 |
$type_specimens = array(); |
83 |
$other_occurrences = array(); |
84 |
foreach ($specimensOrObservations as $occurrence) { |
85 |
$typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid); |
86 |
if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) { |
87 |
$type_specimens[] = $occurrence; |
88 |
} else { |
89 |
$other_occurrences[] = $occurrence; |
90 |
} |
91 |
} |
92 |
$specimensOrObservations = array_merge($type_specimens, $other_occurrences); |
93 |
|
94 |
// Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field |
95 |
if (!variable_get('cdm_dataportal_specimen_derivate_tree')) { |
96 |
foreach ($specimensOrObservations as &$occurrence) { |
97 |
$occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array( |
98 |
$occurrence->uuid, |
99 |
'fieldObjectMediaDTO', |
100 |
)); |
101 |
$occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array( |
102 |
$occurrence->uuid, |
103 |
'derivedUnitMedia', |
104 |
)); |
105 |
} |
106 |
} |
107 |
|
108 |
// --- get map service HTTP query parameters |
109 |
|
110 |
if (count($specimensOrObservations) > 0) { |
111 |
|
112 |
$occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid, $by_associatedtaxon_query); |
113 |
|
114 |
$map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT); |
115 |
if ($map_visibility == 'always' || |
116 |
variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' && |
117 |
(isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))) { |
118 |
$occurrence_query = $occurrence_queryDto->occurrenceQuery; |
119 |
$legend_format_query = null; |
120 |
$distribution_query = NULL; |
121 |
$render_array['map'] = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array()); |
122 |
} |
123 |
} |
124 |
|
125 |
// ------------------------------------------------------- |
126 |
|
127 |
|
128 |
|
129 |
if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){ |
130 |
|
131 |
//COMPRESSED SPECIMEN DERIVATE TABLE |
132 |
$associatedFieldUnitsQuery_parameters = array(); |
133 |
if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) { |
134 |
$associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']); |
135 |
} |
136 |
|
137 |
$by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters); |
138 |
$pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON, |
139 |
array($taxon->uuid, 'associatedFieldUnits'), |
140 |
$by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size') |
141 |
); |
142 |
|
143 |
if (isset($pager_field_units->records[0])) { |
144 |
$field_unit_uuids = array(); |
145 |
foreach ($pager_field_units->records as $field_unit) { |
146 |
$field_unit_uuids[] = $field_unit->uuid; |
147 |
} |
148 |
|
149 |
$render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids); |
150 |
} |
151 |
|
152 |
$render_array['pager'] = markup_to_render_array( |
153 |
theme('cdm_pager', array( |
154 |
'pager' => $pager_field_units, |
155 |
'path' => $_REQUEST['q'], |
156 |
'parameters' => $_REQUEST |
157 |
)), |
158 |
10 // weight |
159 |
); |
160 |
} |
161 |
else if(variable_get('cdm_dataportal_specimen_derivate_tree')){ |
162 |
$specimen_table = array( |
163 |
'#theme' => 'table', |
164 |
'#weight' => 2, |
165 |
// prefix attributes and rows with '#' to let it pass toF the theme function, |
166 |
// otherwise it is handled as child render array |
167 |
'#attributes' => array('class' => 'specimens'), |
168 |
'#rows' => array(), |
169 |
); |
170 |
$specimen_array = compose_specimen_array($specimensOrObservations); |
171 |
|
172 |
foreach($specimen_array as $value){ |
173 |
$renderArray = array( |
174 |
'#theme' => 'item_list', |
175 |
'#items' => array($value), |
176 |
'#type' => 'ul'); |
177 |
$output = drupal_render($renderArray); |
178 |
// $specimen_table['#rows'][] = array( |
179 |
// // An array of table rows. collabsible row |
180 |
// 'data' => "", |
181 |
// 'class' => array('expand_column') |
182 |
// ); |
183 |
$specimen_table['#rows'][] = array( |
184 |
// An array of table rows. Every row is an array of cells, or an associative array |
185 |
'data' => array($output), |
186 |
'class' => array( |
187 |
'descriptionElement', |
188 |
'descriptionElement_IndividualsAssociation' |
189 |
), |
190 |
); |
191 |
|
192 |
|
193 |
} |
194 |
|
195 |
$render_array['specimen_list'] = $specimen_table; |
196 |
|
197 |
|
198 |
} |
199 |
else{ |
200 |
//BOTTOM-UP-SPECIMEN-TABLE |
201 |
// --- generate the specimen list as table |
202 |
$specimen_table = array( |
203 |
'#theme' => 'table', |
204 |
'#weight' => 2, |
205 |
// prefix attributes and rows with '#' to let it pass toF the theme function, |
206 |
// otherwise it is handled as child render array |
207 |
'#attributes' => array('class' => 'specimens'), |
208 |
'#rows' => array(), |
209 |
); |
210 |
|
211 |
if ($specimensOrObservations) { |
212 |
|
213 |
foreach ($specimensOrObservations as $specimenOrObservation) { |
214 |
|
215 |
$mediaList = array(); |
216 |
if (is_array($specimenOrObservation->_fieldObjectMedia)) { |
217 |
$mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia); |
218 |
} |
219 |
if (is_array($specimenOrObservation->_derivedUnitMedia)) { |
220 |
$mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia); |
221 |
} |
222 |
|
223 |
|
224 |
// typelabel will contain the typeStatus |
225 |
$type_label = ''; |
226 |
$typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid); |
227 |
if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) { |
228 |
$type_status = array(); |
229 |
foreach ($typeDesignationPager->records as $typeDesignation) { |
230 |
if (isset($typeDesignation->typeStatus->representation_L10n)){ |
231 |
$type_status[] = $typeDesignation->typeStatus->representation_L10n; |
232 |
} |
233 |
} |
234 |
$type_label = implode(', ', $type_status); |
235 |
if($type_label){ |
236 |
$type_label .= ': ' ; |
237 |
} |
238 |
} |
239 |
|
240 |
// --- Specimen entry as dynamic label: |
241 |
// -> Dynabox for the specimenOrObservation |
242 |
$gallery_name = $specimenOrObservation->uuid; |
243 |
|
244 |
$derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid)); |
245 |
// --- Render associated media. |
246 |
$gallery_html = ''; |
247 |
if (count($mediaList) > 0) { |
248 |
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME); |
249 |
$captionElements = array( |
250 |
'#uri' => t('open media'), |
251 |
); |
252 |
|
253 |
$gallery_html = compose_cdm_media_gallerie(array( |
254 |
'mediaList' => $mediaList, |
255 |
'galleryName' => $gallery_name, |
256 |
'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'], |
257 |
'cols' => $gallery_settings['cdm_dataportal_media_cols'], |
258 |
'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null, |
259 |
'captionElements' => $captionElements, |
260 |
'mediaLinkType' => 'LIGHTBOX', |
261 |
'alternativeMediaUri' => NULL, |
262 |
'galleryLinkUri' => NULL, |
263 |
)); |
264 |
} |
265 |
//here we should use the data we already have |
266 |
$label_html = cdm_dynabox( |
267 |
$specimenOrObservation->uuid, |
268 |
$type_label . $specimenOrObservation->titleCache, |
269 |
$derived_unit_ws_request, |
270 |
'cdm_specimen_or_observation', |
271 |
'Click for details', |
272 |
array('div', 'div'), |
273 |
array(), |
274 |
null, // $content_element_selector |
275 |
'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback |
276 |
'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback |
277 |
); |
278 |
|
279 |
// --- Render associated media. |
280 |
$gallery_html = ''; |
281 |
if (count($mediaList) > 0) { |
282 |
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME); |
283 |
$captionElements = array( |
284 |
'#uri' => t('open media'), |
285 |
); |
286 |
|
287 |
$gallery_html = compose_cdm_media_gallerie(array( |
288 |
'mediaList' => $mediaList, |
289 |
'galleryName' => $gallery_name, |
290 |
'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'], |
291 |
'cols' => $gallery_settings['cdm_dataportal_media_cols'], |
292 |
'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null, |
293 |
'captionElements' => $captionElements, |
294 |
'mediaLinkType' => 'LIGHTBOX', |
295 |
'alternativeMediaUri' => NULL, |
296 |
'galleryLinkUri' => NULL, |
297 |
)); |
298 |
} |
299 |
|
300 |
$specimen_table['#rows'][] = array( |
301 |
// An array of table rows. Every row is an array of cells, or an associative array |
302 |
'data' => array( |
303 |
// Each cell can be either a string or an associative array |
304 |
$label_html . $gallery_html |
305 |
), |
306 |
'class' => array( |
307 |
'descriptionElement', |
308 |
'descriptionElement_IndividualsAssociation' |
309 |
), |
310 |
); |
311 |
} |
312 |
} |
313 |
|
314 |
$render_array['specimen_list'] = $specimen_table; |
315 |
$render_array['pager'] = markup_to_render_array( |
316 |
theme('cdm_pager', array( |
317 |
'pager' => $pager, |
318 |
'path' => $_REQUEST['q'], |
319 |
'parameters' => $_REQUEST, |
320 |
)), |
321 |
10 // weight |
322 |
); |
323 |
} |
324 |
|
325 |
RenderHints::popFromRenderStack(); |
326 |
return $render_array; |
327 |
} |
328 |
|
329 |
/** |
330 |
* Creates the drupal render array for the table showing all derivated which are |
331 |
* derive from a common gathering event. |
332 |
* |
333 |
* @param $field_unit_uuids array |
334 |
* An array of uuids for cdm FieldUnit entities. |
335 |
* |
336 |
* @return array |
337 |
* A drupal render array for a table |
338 |
* |
339 |
* @ingroup compose |
340 |
*/ |
341 |
function compose_specimen_table($field_unit_uuids) |
342 |
{ |
343 |
// get icon images |
344 |
$expand_icon = font_awesome_icon_markup( |
345 |
'fa-plus-square-o', |
346 |
array( |
347 |
'alt' => 'Show details', |
348 |
'class' => array('expand_icon') |
349 |
) |
350 |
); |
351 |
$collapse_icon = font_awesome_icon_markup( |
352 |
'fa-minus-square-o', |
353 |
array( |
354 |
'alt' => 'Show details', |
355 |
'class' => array('collapse_icon') |
356 |
) |
357 |
); |
358 |
$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>'; |
359 |
$checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>'; |
360 |
$sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>'; |
361 |
$character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>'; |
362 |
|
363 |
$rowcount = 0; |
364 |
$rows = array(); |
365 |
|
366 |
foreach ($field_unit_uuids as $field_unit_uuid) { |
367 |
|
368 |
//get derivate hierarchy for the FieldUnit |
369 |
$derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy')); |
370 |
if ($derivateHierarchy) { |
371 |
//summary row |
372 |
$rows[] = array( |
373 |
'data' => array( |
374 |
array( |
375 |
'data' => $expand_icon . $collapse_icon, |
376 |
'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column') |
377 |
), |
378 |
array( |
379 |
'data' => $derivateHierarchy->country, |
380 |
'class' => array('summary_row_cell') |
381 |
), |
382 |
array( |
383 |
'data' => $derivateHierarchy->date, |
384 |
'class' => array('summary_row_cell') |
385 |
), |
386 |
array( |
387 |
'data' => $derivateHierarchy->collectingString, |
388 |
'class' => array('summary_row_cell') |
389 |
), |
390 |
@array( |
391 |
'data' => $derivateHierarchy->herbarium, |
392 |
'class' => array('summary_row_cell') |
393 |
), |
394 |
array( |
395 |
'data' => $derivateHierarchy->hasType ? $checked_box_icon : "", |
396 |
'class' => array('summary_row_cell', 'summary_row_icon') |
397 |
), |
398 |
array( |
399 |
'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "", |
400 |
'class' => array('summary_row_cell', 'summary_row_icon') |
401 |
), |
402 |
array( |
403 |
'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " " |
404 |
. ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " " |
405 |
. ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""), |
406 |
'class' => array('summary_row_cell', 'summary_row_icon') |
407 |
) |
408 |
), |
409 |
'id' => 'derivate_summary' . $rowcount, // summary row id |
410 |
'class' => array('summary_row'), |
411 |
); |
412 |
|
413 |
//assemble field unit details |
414 |
$detail_html = ""; |
415 |
// - citation |
416 |
if ($derivateHierarchy->citation) { |
417 |
$detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>"; |
418 |
} |
419 |
//assemble specimen details |
420 |
if ($derivateHierarchy->derivates) { |
421 |
foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) { |
422 |
$detail_html .= "<br>"; |
423 |
$detail_html .= render_cdm_specimenDTO_page($preservedSpecimenDTO); |
424 |
} |
425 |
} |
426 |
$detail_html .= "<br>"; |
427 |
//detail row resp. one BIG detail cell |
428 |
$rows[] = array( |
429 |
'data' => array( |
430 |
array( |
431 |
'data' => "", //empty first column |
432 |
'class' => array('expand_column') |
433 |
), |
434 |
array( |
435 |
'data' => $detail_html, |
436 |
'colspan' => 7, |
437 |
), |
438 |
), |
439 |
'id' => 'derivate_details' . $rowcount,//details row ID |
440 |
'class' => array('detail_row'), |
441 |
); |
442 |
$rowcount++; |
443 |
} |
444 |
} |
445 |
|
446 |
$tableId = "derivate_hierarchy_table"; |
447 |
$derivateHierarchyTable = array( |
448 |
"#theme" => "table", |
449 |
"#weight" => 2, |
450 |
"#header" => array( |
451 |
array( |
452 |
'data' => "", |
453 |
'class' => array('expand_column') |
454 |
), |
455 |
"Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"), |
456 |
"#rows" => $rows, |
457 |
"#attributes" => array( |
458 |
"id" => $tableId, |
459 |
"border" => 2 |
460 |
) |
461 |
); |
462 |
|
463 |
//add toggle functionality to derivate hierarchy table |
464 |
drupal_add_js_rowToggle("#" . $tableId); |
465 |
|
466 |
return $derivateHierarchyTable; |
467 |
} |
468 |
|
469 |
function create_html_link($link, $openInExternalWindow=false){ |
470 |
$html = ""; |
471 |
if($link->uri && $link->uri!=""){ |
472 |
$html .= '<a href="' . $link->uri . '"'; |
473 |
if($openInExternalWindow){ |
474 |
$html .= ' target="_blank"'; |
475 |
} |
476 |
$html .= '>' . $link->linkText . '</a>'; |
477 |
} |
478 |
else{ |
479 |
$html .= $link->linkText; |
480 |
} |
481 |
return $html; |
482 |
} |
483 |
|
484 |
/** |
485 |
* Creates HTML links from the given link list concatenated by default by a comma. |
486 |
* @param $linkList the list with Link objects having "uri" and "linkText" as members |
487 |
* @return string the assembled HTML string containing the links |
488 |
*/ |
489 |
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ") |
490 |
{ |
491 |
$html = ""; |
492 |
if ($linkList) { |
493 |
foreach ($linkList as $link) { |
494 |
$html .= create_html_link($link, $openInExternalWindow).$separator; |
495 |
} |
496 |
$html = rtrim($html, $separator); |
497 |
} |
498 |
return $html; |
499 |
} |
500 |
|
501 |
/** |
502 |
* Composes a taxon page which can consist of multiple parts like |
503 |
* 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed |
504 |
* as tabs or as sections of a single page. |
505 |
* |
506 |
* It is headed by the name of the accepted taxon without author and reference. |
507 |
* |
508 |
* @param $taxon |
509 |
* The CDM Taxon Instance to compose the page for. |
510 |
* @param $page_part |
511 |
* Name of the part to display, valid values are: |
512 |
* - 'description' - for the general part |
513 |
* - 'images' |
514 |
* - 'synonymy' |
515 |
* - 'keys' |
516 |
* - 'all' |
517 |
* |
518 |
* @return array |
519 |
* A drupal render array |
520 |
* |
521 |
* @ingroup compose |
522 |
*/ |
523 |
function compose_cdm_taxon_page($taxon, $page_part = 'description') { |
524 |
|
525 |
// we better cache here since drupal_get_query_parameters has no internal static cache variable |
526 |
$http_request_params = drupal_get_query_parameters(); |
527 |
|
528 |
// add all mandatory js sources |
529 |
_add_js_footnotes(); |
530 |
|
531 |
|
532 |
$render_array = array(); |
533 |
$weight = 0; // the weight for the render array elements |
534 |
|
535 |
$tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT)); |
536 |
|
537 |
$page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all'; |
538 |
|
539 |
$synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1; |
540 |
if(!$synonymy_as_tab){ |
541 |
unset($tabsToDisplay["Synonymy"]); |
542 |
// the synonymy is located in the general part in this case |
543 |
if($page_part == 'synonymy'){ |
544 |
$page_part = 'description'; |
545 |
} |
546 |
} |
547 |
|
548 |
$media = _load_media_for_taxon($taxon); |
549 |
|
550 |
|
551 |
if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) { |
552 |
taxon_page_tabs_hidden_add('images'); |
553 |
} |
554 |
|
555 |
// --- GET specimensOrObservations --- // |
556 |
$specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount')); |
557 |
|
558 |
$specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0; |
559 |
if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) { |
560 |
taxon_page_tabs_hidden_add('specimens'); |
561 |
} |
562 |
|
563 |
// --- GET polytomousKeys --- // |
564 |
$polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid"); |
565 |
$identificationKeyCount = 0; |
566 |
if ($polytomousKeysPager) { |
567 |
$identificationKeyCount += $polytomousKeysPager->count; |
568 |
} |
569 |
if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) { |
570 |
taxon_page_tabs_hidden_add('keys'); |
571 |
} |
572 |
|
573 |
// --- GET TaxonNodeAgentRelations --- // |
574 |
$current_classification_uuid = get_current_classification_uuid(); |
575 |
$taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS, |
576 |
array( |
577 |
$taxon->uuid, |
578 |
$current_classification_uuid, |
579 |
), |
580 |
"pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible! |
581 |
); |
582 |
if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){ |
583 |
taxon_page_tabs_hidden_add('experts'); |
584 |
} |
585 |
|
586 |
if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') { |
587 |
taxon_page_tabs_hidden_add('synonymy'); |
588 |
} |
589 |
|
590 |
// -------------------------------------------- // |
591 |
|
592 |
if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) { |
593 |
$render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++); |
594 |
} |
595 |
|
596 |
// --- PAGE PART: DESCRIPTION --- // |
597 |
if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) { |
598 |
|
599 |
$merged_tree = merged_taxon_feature_tree($taxon); |
600 |
|
601 |
|
602 |
$render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab); |
603 |
$render_array['general']['#weight'] = $weight++; |
604 |
$render_array['general']['#prefix'] = '<div id="general" class="page-part">'; |
605 |
$render_array['general']['#suffix'] = '</div>'; |
606 |
} |
607 |
|
608 |
// --- PAGE PART: IMAGES --- // |
609 |
if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) { |
610 |
$images_html = '<div id="images" class="page-part">'; |
611 |
if ($page_part == 'all') { |
612 |
$images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>'; |
613 |
} |
614 |
// Get the image gallery as configured by the admin. |
615 |
$default_image_gallery = 'default'; |
616 |
$configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default'); |
617 |
$taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>'; |
618 |
if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){ |
619 |
// the fsi_gallery requires a flash plugin, in case the client browser is not supporting |
620 |
// flash we also need to provide an the default gallery as alternative |
621 |
$taxon_image_gallery = '<div id="default-gallery-viewer">' . |
622 |
call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array( |
623 |
$taxon, |
624 |
$media, |
625 |
)) |
626 |
. '</div>'; |
627 |
} |
628 |
if($configured_image_gallery_viewer == 'fsi'){ |
629 |
$taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' . |
630 |
call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array( |
631 |
$taxon, |
632 |
$media, |
633 |
)) |
634 |
. '</div>'; |
635 |
} |
636 |
$images_html .= $taxon_image_gallery; |
637 |
$images_html .= '</div>'; |
638 |
$render_array['images'] = markup_to_render_array($images_html, $weight++); |
639 |
} |
640 |
|
641 |
// --- PAGE PART: SYNONYMY --- // |
642 |
if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) { |
643 |
$synonymy_html = '<div id="synonymy" class="page-part">'; |
644 |
if ($page_part == 'all') { |
645 |
$synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>'; |
646 |
} |
647 |
$addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE); |
648 |
|
649 |
$synonym_a = compose_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon); |
650 |
$synonymy_html .= drupal_render($synonym_a); |
651 |
|
652 |
$synonymy_html .= '</div>'; |
653 |
$render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++); |
654 |
|
655 |
} |
656 |
|
657 |
// --- PAGE PART: SPECIMENS --- // |
658 |
if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) { |
659 |
$render_array['specimens'] = array( |
660 |
'#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''), |
661 |
'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array |
662 |
'#suffix' => '</div>', |
663 |
); |
664 |
} |
665 |
|
666 |
// --- PAGE PART: KEYS --- // |
667 |
if(!taxon_page_tabs_hidden_check('keys')){ |
668 |
if ($identificationKeyCount == 1 && $page_part == 'keys'){ |
669 |
drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid)); |
670 |
} |
671 |
else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) { |
672 |
$keys_html = '<div id="keys" class="page-part">'; |
673 |
if ($page_part == 'all') { |
674 |
$keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>'; |
675 |
} |
676 |
$keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid)); |
677 |
$keys_html .= '</div>'; |
678 |
$render_array['keys'] = markup_to_render_array($keys_html, $weight++); |
679 |
} |
680 |
} |
681 |
|
682 |
// --- PAGE PART: EXPERTS --- // |
683 |
|
684 |
if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) { |
685 |
$render_array['experts'] = array( |
686 |
'#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''), |
687 |
'content' => compose_cdm_taxon_page_experts($taxon), // returns render array |
688 |
'#suffix' => '</div>', |
689 |
); |
690 |
} |
691 |
|
692 |
// ------------------ END OF PARTS -------------- // |
693 |
|
694 |
// adjust weights of page and toc elements according to the settings |
695 |
$taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT); |
696 |
foreach($taxontabs_weights as $tab_key => $weight){ |
697 |
if(isset($render_array[$tab_key])){ |
698 |
$render_array[$tab_key]['#weight'] = $weight; |
699 |
} |
700 |
} |
701 |
|
702 |
|
703 |
// set up the TOC for the pages which contain all pageparts |
704 |
if($page_part == 'all') { |
705 |
|
706 |
asort($taxontabs_weights); |
707 |
foreach(array_keys($taxontabs_weights) as $tab_key){ |
708 |
if(isset($render_array[$tab_key])){ |
709 |
if($tab_key != 'general'){ |
710 |
// add entry for page part |
711 |
$toc_elements[] = array( |
712 |
'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)), |
713 |
'class' => array('page-part-toc-item-' . $tab_key) |
714 |
); |
715 |
} else { |
716 |
// add content of profile part instead |
717 |
if(isset($render_array['general'])) { |
718 |
// in case all tabs are shown at once the feature tocs |
719 |
// should be integrated into the tabs toc as sub list |
720 |
// and the profile image should be on top of the page |
721 |
if(isset($render_array['general']['taxon_description_feature_toc'])){; |
722 |
foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){ |
723 |
$toc_elements[] = $profile_toc_item; |
724 |
} |
725 |
unset($render_array['general']['taxon_description_feature_toc']); |
726 |
} |
727 |
} |
728 |
} |
729 |
} |
730 |
} |
731 |
|
732 |
// move profile image in page structure |
733 |
if(isset($render_array['general']['taxon_profile_image'])){ |
734 |
$render_array['profile_image'] = $render_array['general']['taxon_profile_image']; |
735 |
$render_array['profile_image']['#weight'] = -100; |
736 |
unset($render_array['general']['taxon_profile_image']); |
737 |
} |
738 |
|
739 |
// finally add the table of contents to the render array |
740 |
$render_array['toc'] = array( |
741 |
'#theme' => 'item_list', |
742 |
'#items' => $toc_elements, |
743 |
'#title' => t('Content'), |
744 |
'#weight' => -101, |
745 |
'#suffix' => '</div>', |
746 |
'#prefix'=> '<div id="page-toc">' |
747 |
); |
748 |
} |
749 |
|
750 |
|
751 |
return $render_array; |
752 |
} |
753 |
|
754 |
/** |
755 |
* TODO should this function really be a compose function? |
756 |
* For a compose function must there always be a theme function with the same name? (ak 8.8.2013) |
757 |
* |
758 |
* composes and returns an render array containing the components of the taxon profile tab: |
759 |
* - 'taxon_profile_image' |
760 |
* - 'taxon_description_feature_toc' |
761 |
* - 'taxon_description_features' |
762 |
* |
763 |
* |
764 |
* @param object taxon |
765 |
* @param object $merged_tree |
766 |
* @param object media |
767 |
* @param bool $add_synonymy |
768 |
* |
769 |
* @return array |
770 |
* A Drupal render array with the following elements: |
771 |
* - 'taxon_profile_image' |
772 |
* - 'taxon_description_feature_toc' |
773 |
* - 'taxon_description_features' |
774 |
* |
775 |
* @throws Exception |
776 |
* |
777 |
* @ingroup compose |
778 |
*/ |
779 |
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) { |
780 |
|
781 |
$render_array = array(); |
782 |
|
783 |
$taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT)); |
784 |
|
785 |
$hide_taxon_profile_image = FALSE; |
786 |
if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) { |
787 |
$rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99')); |
788 |
$hide_taxon_profile_image = ($rankCompare > -1); |
789 |
} |
790 |
|
791 |
if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) { |
792 |
|
793 |
$representationPart = new stdClass(); |
794 |
$attributes = array(); |
795 |
if (isset($media[0])) { |
796 |
// due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object |
797 |
// which only contains the thumbnail representation even if the height and width filters are not set. |
798 |
// --> |
799 |
$preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid); |
800 |
$preferred_representations = cdm_preferred_media_representations($preferred_media, array( |
801 |
'image/jpg', |
802 |
'image/jpeg', |
803 |
'image/png', |
804 |
'image/gif', |
805 |
), |
806 |
$taxon_profile_image_settings['maxextend'], |
807 |
$taxon_profile_image_settings['maxextend'] |
808 |
); |
809 |
if(count($preferred_representations) > 0){ |
810 |
|
811 |
$representation = array_shift($preferred_representations); |
812 |
$representationPart = $representation->parts[0]; |
813 |
$attributes['alt'] = $representationPart->uri; |
814 |
|
815 |
if (!empty($taxon_profile_image_settings['media_uri_query'])) { |
816 |
$representationPart->uri = $representationPart->uri |
817 |
. (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?') |
818 |
. $taxon_profile_image_settings['media_uri_query']; |
819 |
} |
820 |
} |
821 |
} |
822 |
else { |
823 |
if ($taxon_profile_image_settings['custom_placeholder_enabled']) { |
824 |
// show placeholder image instead |
825 |
if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) { |
826 |
// use the user provided image |
827 |
$profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']); |
828 |
$url = file_create_url($profile_image_file->uri); |
829 |
$image_info = image_get_info($profile_image_file->uri); |
830 |
$representationPart->width = $image_info['width']; |
831 |
$representationPart->height = $image_info['height']; |
832 |
$representationPart->uri = $url; |
833 |
} |
834 |
else { |
835 |
// use the hard coded default |
836 |
$representationPart->width = 184; |
837 |
$representationPart->height = 144; |
838 |
$representationPart->uri = base_path() . drupal_get_path('module', |
839 |
'cdm_dataportal') . '/images/no_picture.png'; |
840 |
} |
841 |
$attributes['alt'] = "no image available"; |
842 |
} |
843 |
} |
844 |
|
845 |
if (isset($representationPart->uri)) { |
846 |
$profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes); |
847 |
// NOTE: style="width:${maxextend}px' is needed for IE8 !!! |
848 |
$render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>', |
849 |
-101); |
850 |
} |
851 |
} |
852 |
|
853 |
if($add_synonymy){ |
854 |
$synonymy_a = compose_cdm_taxon_page_synonymy($taxon, true); |
855 |
$synonymy_a['#weight'] = -102; |
856 |
$render_array['synonymy'] = $synonymy_a; |
857 |
} |
858 |
|
859 |
$pseudo_feature_blocks = array(); |
860 |
$pseudo_feature_block_toc_items = array(); |
861 |
|
862 |
|
863 |
// Render the sections for each real feature |
864 |
$feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon); |
865 |
|
866 |
// Bibliography |
867 |
$bibliography_settings = get_bibliography_settings(); |
868 |
if($bibliography_settings['enabled'] == 1){ |
869 |
$bibliography_markup = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''); |
870 |
if($bibliography_markup) { |
871 |
$feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY'); |
872 |
$bibliography_block = feature_block(t('Bibliography'), $feature_bibliography); |
873 |
$bibliography_item = markup_to_render_array($bibliography_markup); |
874 |
$bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography); |
875 |
|
876 |
$pseudo_feature_block_toc_items['Bibliography']= 'bibliography'; |
877 |
$pseudo_feature_blocks[] = $bibliography_block; |
878 |
} |
879 |
} |
880 |
|
881 |
$render_array['taxon_description_features'] = _block_get_renderable_array( |
882 |
array_merge($feature_block_list, $pseudo_feature_blocks) |
883 |
); |
884 |
|
885 |
if($pseudo_feature_block_toc_items){ |
886 |
foreach ($pseudo_feature_block_toc_items as $label=>$fragment){ |
887 |
cdm_toc_list_add_item($label, $fragment); |
888 |
} |
889 |
} |
890 |
|
891 |
// create the table of content |
892 |
$toc = array( |
893 |
'#theme' => 'item_list', |
894 |
'#items' => cdm_toc_list(), |
895 |
'#title' => t('Content'), |
896 |
'#weight' => -100, // move to the top |
897 |
'#suffix' => '</div>', |
898 |
'#prefix'=> '<div id="page-toc">' |
899 |
); |
900 |
$render_array['taxon_description_feature_toc'] = $toc; |
901 |
|
902 |
return $render_array; |
903 |
} |
904 |
|
905 |
/** |
906 |
* composes and returns an render array for the experts associated with the given taxon |
907 |
* |
908 |
* @param object taxon |
909 |
* |
910 |
* @return array |
911 |
* A Drupal render array for a table with the experts |
912 |
* |
913 |
* @ingroup compose |
914 |
*/ |
915 |
function compose_cdm_taxon_page_experts($taxon){ |
916 |
|
917 |
$render_array = array(); |
918 |
if(!isset($taxon->uuid)){ |
919 |
return $render_array; |
920 |
} |
921 |
|
922 |
$current_classification_uuid = get_current_classification_uuid(); |
923 |
// TODO use cdm_ws_fetchall below but this failes! needs fix! |
924 |
$taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS, |
925 |
array( |
926 |
$taxon->uuid, |
927 |
$current_classification_uuid |
928 |
) |
929 |
); |
930 |
|
931 |
$header = array( |
932 |
array('data' => t('Expert')), |
933 |
array('data' => t('Role')) |
934 |
); |
935 |
$rows = array(); |
936 |
|
937 |
|
938 |
foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){ |
939 |
|
940 |
|
941 |
$expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid; |
942 |
$expert_details_container_id = 'expert_details_' . $expert_role_id; |
943 |
|
944 |
$agent_label_markup = cdm_dynabox( |
945 |
'expert_' . $expert_role_id, |
946 |
$taxon_node_agent_relation->agent->titleCache, |
947 |
// specifying both ends of the relationship will return only one record in the pager |
948 |
cdm_compose_url(CDM_WS_PORTAL_AGENT, |
949 |
array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'), |
950 |
'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid), |
951 |
'cdm_taxon_expert', |
952 |
'Click for details', |
953 |
array('div', 'div'), |
954 |
array(), // attributes |
955 |
'#' . $expert_details_container_id // $content_element_selector |
956 |
); |
957 |
|
958 |
// Expert and Role |
959 |
$rows[] = array( |
960 |
'data' => array( |
961 |
array( |
962 |
'data' => $agent_label_markup, |
963 |
'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent)) |
964 |
), |
965 |
array( |
966 |
'data' => $taxon_node_agent_relation->type->representation_L10n, |
967 |
'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type)) |
968 |
) |
969 |
) |
970 |
); |
971 |
// Agent details |
972 |
$rows[] = array( |
973 |
'data' => array( |
974 |
array( |
975 |
'data' => '<!-- expert_details_container -->', |
976 |
'id' => $expert_details_container_id, |
977 |
'colspan' => 2 |
978 |
) |
979 |
) |
980 |
); |
981 |
|
982 |
} |
983 |
|
984 |
|
985 |
$render_array['experts_table'] = array( |
986 |
'#theme' => 'table', |
987 |
'#header' => $header, |
988 |
'#rows' => $rows, |
989 |
); |
990 |
|
991 |
|
992 |
return $render_array; |
993 |
} |
994 |
|
995 |
|
996 |
/** |
997 |
* Manages the tabs to be hidden in the taxon page. |
998 |
* |
999 |
* The tabs are identified by their last menu link path element: |
1000 |
* - description |
1001 |
* - synonymy |
1002 |
* - images |
1003 |
* - specimens |
1004 |
* - key |
1005 |
* |
1006 |
* Internally the tabs are stored in a static variable which is |
1007 |
* managed by drupal_static(). |
1008 |
* |
1009 |
* @param string $add_tab |
1010 |
* Optional parameter. The given string will be added to the array of tabs |
1011 |
* |
1012 |
* @return |
1013 |
* The array of tabs |
1014 |
*/ |
1015 |
function taxon_page_tabs_hidden_add($add_tab = NULL) { |
1016 |
$tabs = &drupal_static('taxon_page_tabs_hidden'); |
1017 |
|
1018 |
if(!isset($tabs)){ |
1019 |
$tabs = array(); |
1020 |
} |
1021 |
|
1022 |
if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) { |
1023 |
$tabs[] = $add_tab; |
1024 |
} |
1025 |
|
1026 |
return $tabs; |
1027 |
} |
1028 |
|
1029 |
/** |
1030 |
* Manages the tabs to be hidden in the taxon page. |
1031 |
* |
1032 |
* The tabs names are identified by their last menu link path element: |
1033 |
* - description |
1034 |
* - synonymy |
1035 |
* - images |
1036 |
* - specimens |
1037 |
* - key |
1038 |
* |
1039 |
* Internally the tabs are stored in a static variable which is |
1040 |
* managed by drupal_static(). |
1041 |
* |
1042 |
* @param string $tabname |
1043 |
* The name of the tab to check |
1044 |
* |
1045 |
* @return boolean |
1046 |
* True if the tab or section is to be hidden |
1047 |
*/ |
1048 |
function taxon_page_tabs_hidden_check($tabname) { |
1049 |
|
1050 |
$tabs = &drupal_static('taxon_page_tabs_hidden'); |
1051 |
|
1052 |
if(!isset($tabs)){ |
1053 |
$tabs = array(); |
1054 |
} |
1055 |
|
1056 |
return array_search($tabname, $tabs) !== FALSE; |
1057 |
} |
1058 |
|
1059 |
/** |
1060 |
* Implements the hook_preprocess_HOOK() for theme_menu_local_tasks() |
1061 |
* |
1062 |
* - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add() |
1063 |
* - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!) |
1064 |
* |
1065 |
* @param array $variables |
1066 |
* The variables array |
1067 |
*/ |
1068 |
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) { |
1069 |
|
1070 |
$hidden_tabs = taxon_page_tabs_hidden_add(); |
1071 |
|
1072 |
if (is_array($variables['primary'])) { |
1073 |
foreach ($variables['primary'] as $key => &$element) { |
1074 |
|
1075 |
// 1. Remove the tabs to be hidden |
1076 |
foreach ($hidden_tabs as $tab) { |
1077 |
if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) { |
1078 |
// remove the tab |
1079 |
unset($variables['primary'][$key]); |
1080 |
} |
1081 |
} |
1082 |
} |
1083 |
} |
1084 |
} |
1085 |
|
1086 |
|
1087 |
|
1088 |
/** |
1089 |
* Implements the hook_preprocess_HOOK() for theme_menu_local_task() |
1090 |
* |
1091 |
* |
1092 |
* @param array $variables |
1093 |
* An associative array containing: |
1094 |
* - element: A render element containing: |
1095 |
* #link: A menu link array with 'title', 'href', and 'localized_options' keys. |
1096 |
* #active: A boolean indicating whether the local task is active. |
1097 |
* |
1098 |
*/ |
1099 |
function cdm_dataportal_preprocess_menu_local_task(&$variables) { |
1100 |
|
1101 |
$link = $variables['element']['#link']; |
1102 |
if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) { |
1103 |
$link['title'] = '<img class="refresh" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/view-refresh.png' . '" alt="' . check_plain($link['title']) . '" title="' . check_plain($link['title']) . '"/>'; |
1104 |
$link['localized_options']['html'] = TRUE; |
1105 |
|
1106 |
$variables['element']['#link'] = $link; |
1107 |
} |
1108 |
} |
1109 |
|
1110 |
/* =================== block composition ===================== */ |
1111 |
|
1112 |
/** |
1113 |
* Composes and returns an render array for the classification breadcrumbs of the given taxon. |
1114 |
* |
1115 |
* @param taxon |
1116 |
* |
1117 |
* @return array |
1118 |
* A Drupal render array for a table with the experts |
1119 |
* |
1120 |
* @ingroup compose |
1121 |
*/ |
1122 |
function compose_classification_breadcrumbs($taxon_uuid) { |
1123 |
|
1124 |
_add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button'); |
1125 |
|
1126 |
$render_array = array(); |
1127 |
|
1128 |
$render_array['#theme'] = 'item_list'; |
1129 |
$render_array['#type'] = 'ul'; |
1130 |
$render_array['#attributes'] = array( |
1131 |
'id' => 'classification-breadcrumbs', |
1132 |
'class' => 'breadcrumbs inline', |
1133 |
); |
1134 |
|
1135 |
$items = array(); |
1136 |
|
1137 |
$parent_taxon_nodes = null; |
1138 |
if($taxon_uuid){ |
1139 |
$parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid); |
1140 |
} |
1141 |
|
1142 |
$classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY); |
1143 |
// find current classification in list |
1144 |
$classification = null; |
1145 |
$current_classification_uuid = get_current_classification_uuid(); |
1146 |
foreach ($classifications as $classification){ |
1147 |
if($classification->uuid == $current_classification_uuid){ |
1148 |
break; |
1149 |
} |
1150 |
} |
1151 |
|
1152 |
$node_name = ''; |
1153 |
if(count($classifications) > 1 ){ |
1154 |
// need to add the current classification as first label |
1155 |
|
1156 |
$label = $classification->titleCache; |
1157 |
if(strlen($label) > 20){ |
1158 |
$label = substr($label, 0, strpos($label, ' ', 15)) . '...'; |
1159 |
} |
1160 |
$node_name = font_awesome_icon_markup('fa-th-list') . ' ' . l($label, '#', array( |
1161 |
'attributes' => array( |
1162 |
'class' => 'taxonomic-children-button classification-chooser', |
1163 |
'data-destination-uri' => drupal_get_destination(), |
1164 |
'data-cdm-align-with' => array('prev') |
1165 |
), |
1166 |
'html' => true |
1167 |
)); |
1168 |
} |
1169 |
|
1170 |
$rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT); |
1171 |
|
1172 |
$rank_separator = '<span> ' |
1173 |
. font_awesome_icon_markup('fa-chevron-right') |
1174 |
. ' </span>'; |
1175 |
$more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270'); |
1176 |
$more_children_label = '...'; |
1177 |
|
1178 |
$items[] = $node_name; |
1179 |
|
1180 |
$more_children_for = null; |
1181 |
if($parent_taxon_nodes){ |
1182 |
foreach ($parent_taxon_nodes as $node) { |
1183 |
|
1184 |
$is_first_item = count($items) == 0; |
1185 |
$is_last_item = count($items) == count($parent_taxon_nodes); |
1186 |
$node_name = cdm_dataportal_shortname_of($node); |
1187 |
$path = path_to_taxon($node->taxonUuid); |
1188 |
|
1189 |
if($node->taxonomicChildrenCount > 0) { |
1190 |
$more_children_for = $node->taxonUuid; |
1191 |
} else { |
1192 |
$more_children_for = null; |
1193 |
} |
1194 |
|
1195 |
// 'fa-sitemap' |
1196 |
|
1197 |
$items[] = |
1198 |
($is_first_item ? '' : ' ') |
1199 |
. $rank_separator |
1200 |
. l( |
1201 |
'<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>', |
1202 |
$path, |
1203 |
array( |
1204 |
'attributes' => array( |
1205 |
'class' => array('taxonomic-children-button'), |
1206 |
'data-cdm-taxon-uuid' => array($node->taxonUuid), |
1207 |
'data-cdm-classification-mode' => array('siblings'), |
1208 |
'data-cdm-align-with' => array('prev') |
1209 |
), |
1210 |
'html' => true |
1211 |
) |
1212 |
); |
1213 |
} |
1214 |
} |
1215 |
|
1216 |
// add more button to the end |
1217 |
if(!$parent_taxon_nodes) { |
1218 |
// not taxon focused yet, adding button to make the root nodes available |
1219 |
$items[] = '<span>' |
1220 |
. $more_children_icon . ' ' . |
1221 |
'<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid |
1222 |
. '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>' |
1223 |
. '</span>'; |
1224 |
} else if($more_children_for){ |
1225 |
// last parent item has child taxon nodes |
1226 |
$items[] = ' <span>' |
1227 |
. $more_children_icon . ' ' . |
1228 |
'<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for |
1229 |
. '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>' |
1230 |
. '</span>'; |
1231 |
|
1232 |
} |
1233 |
|
1234 |
$render_array['#items'] = $items; |
1235 |
|
1236 |
return $render_array; |
1237 |
} |
1238 |
|
1239 |
|
1240 |
/** |
1241 |
* @param $specimen_uuid |
1242 |
* @return array |
1243 |
* The drupal render array for the page |
1244 |
* |
1245 |
* @ingroup compose |
1246 |
*/ |
1247 |
function compose_cdm_specimen_page($specimen_uuid) |
1248 |
{ |
1249 |
drupal_set_title("Specimen Details"); |
1250 |
$render_array = array(); |
1251 |
RenderHints::pushToRenderStack('specimen_page'); |
1252 |
|
1253 |
$specimen_table = array( |
1254 |
'#theme' => 'table', |
1255 |
'#weight' => 2, |
1256 |
// prefix attributes and rows with '#' to let it pass toF the theme function, |
1257 |
// otherwise it is handled as child render array |
1258 |
|
1259 |
'#attributes' => array('class' => 'specimens'), |
1260 |
'#rows' => array(), |
1261 |
'#prefix' => '<div id="specimens">', |
1262 |
'#suffix' => '</div>', |
1263 |
|
1264 |
|
1265 |
); |
1266 |
$specimen = compose_cdm_specimen_or_observation($specimen_uuid, true); |
1267 |
$renderArray = array( |
1268 |
'#theme' => 'item_list', |
1269 |
'#items' => array($specimen), |
1270 |
'#type' => 'ul'); |
1271 |
$output = drupal_render($renderArray); |
1272 |
|
1273 |
$specimen_table['#rows'][] = array( |
1274 |
// An array of table rows. Every row is an array of cells, or an associative array |
1275 |
'data' => array($output), |
1276 |
'class' => array( |
1277 |
'descriptionElement', |
1278 |
'descriptionElement_IndividualsAssociation' |
1279 |
), |
1280 |
|
1281 |
); |
1282 |
|
1283 |
|
1284 |
// $detail_html = compose_cdm_specimen_or_observation($specimen_uuid, true); |
1285 |
// $render_array['markup'] = array( |
1286 |
// '#prefix' => '<div id="specimens" class="page">', |
1287 |
// 'content' => $specimen_table, |
1288 |
// '#suffix' => '</div>', |
1289 |
// ); |
1290 |
$render_array['markup'] = $specimen_table; |
1291 |
|
1292 |
RenderHints::popFromRenderStack(); |
1293 |
return $render_array; |
1294 |
} |
1295 |
|
1296 |
/** |
1297 |
* @param $named_area_uuid |
1298 |
* @return array |
1299 |
* The drupal render array for the page |
1300 |
* |
1301 |
* @ingroup compose |
1302 |
*/ |
1303 |
function compose_cdm_named_area_page($named_area_uuid) |
1304 |
{ |
1305 |
|
1306 |
$named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid)); |
1307 |
|
1308 |
$render_array = array(); |
1309 |
RenderHints::pushToRenderStack('named_area_page'); |
1310 |
|
1311 |
$groups = array(); |
1312 |
@_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n); |
1313 |
@_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary); |
1314 |
if(isset($named_area->level)) { |
1315 |
@_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n); |
1316 |
} |
1317 |
|
1318 |
$name_area_details_elements = array( |
1319 |
// '#title' => $title, |
1320 |
'#theme' => 'description_list', |
1321 |
'#groups' => $groups, |
1322 |
'#attributes' => array('class' => html_class_attribute_ref($named_area)), |
1323 |
); |
1324 |
|
1325 |
$render_array[] = $name_area_details_elements; |
1326 |
|
1327 |
RenderHints::popFromRenderStack(); |
1328 |
return $render_array; |
1329 |
} |
1330 |
|
1331 |
/** |
1332 |
* Provides the the label string for taxon page tabs. |
1333 |
* |
1334 |
* The $tabname as passed to the method will be returned if no override |
1335 |
* label is configured in the settings. |
1336 |
*/ |
1337 |
function cdm_taxonpage_tab_label($tabname) { |
1338 |
static $taxon_tabs_labels = null; |
1339 |
if($taxon_tabs_labels == null){ |
1340 |
$taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT); |
1341 |
} |
1342 |
$tabname_key = strtolower($tabname); |
1343 |
if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){ |
1344 |
return $taxon_tabs_labels[$tabname_key]; |
1345 |
} |
1346 |
return $tabname; |
1347 |
} |