Project

General

Profile

Download (49.2 KB) Statistics
| Branch: | Tag: | Revision:
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
 * Composes 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 array
30
 *   A render array suitable for drupal_render()
31
 *
32
 * @ingroup Compose
33
 *
34
 */
35
function compose_cdm_taxon_page_specimens($taxon) {
36

    
37
    $render_array = array();
38
    RenderHints::pushToRenderStack('taxon_page_specimens');
39

    
40
  $root_unit_dtos = null;
41
  $specimensOrObservations = array();
42
  $current_view_mode = variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT);
43
  if ($current_view_mode == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE || $current_view_mode == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE){
44
      // get fieldUnitDTOs
45
      $root_unit_dtos = cdm_ws_get(CDM_WS_PORTAL_TAXON_ROOTUNIT_DTOS, array( $taxon->uuid));
46
      $root_unit_dtos = order_fieldUnitDtos_by_date_and_type($root_unit_dtos);
47
    } else {
48
      // $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
49
      // extend by associated taxas occurrences
50
      $relationship_filter_query_parameters = relationship_filter_query_parameters();
51

    
52
      if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
53
        $relationship_filter_query_parameters = array_merge($relationship_filter_query_parameters, $_REQUEST['pager']);
54
      }
55
      $by_associatedtaxon_query = http_build_query($relationship_filter_query_parameters);
56
      $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
57
        null,
58
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
59
      );
60
      if (isset($pager->records[0])) {
61
        $specimensOrObservations = $pager->records;
62
      }
63
      // cdm_ws_get(CDM_WS_OCCURRENCE_ROOTUNIT_DTO_BY_ASSOCIATEDTAXON // was CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON,
64
      // null,
65
      // $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
66
      // );
67

    
68
      // $specimensOrObservations = array();
69
      // if(isset($pager->records[0])){
70
      //    $specimensOrObservations =  $pager->records;
71
      // }
72
      // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
73
      foreach ($specimensOrObservations as &$occurrence) {
74
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
75
          $occurrence->uuid,
76
          'fieldObjectMediaDTO',
77
        ));
78
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
79
          $occurrence->uuid,
80
          'derivedUnitMedia',
81
        ));
82
      }
83
      $specimensOrObservations = order_specimens_or_observations_by_date_and_type($specimensOrObservations);
84
    }
85

    
86
    // --- get map service HTTP query parameters
87
    if (count($specimensOrObservations) > 0 || $root_unit_dtos > 0) {
88
        $render_array['map'] = occurrence_map_query_parameters($taxon);
89
    }
90

    
91
    // -------------------------------------------------------
92

    
93
    if(($current_view_mode == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE)){
94

    
95
        //COMPRESSED SPECIMEN DERIVATE TABLE
96
        $pager_root_units = cdm_ws_page(
97
          cdm_compose_url(CDM_WS_PORTAL_TAXON_ASSOCIATED_ROOTUNITS, [$taxon->uuid]),
98
          variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT) * 2,
99
          isset($_REQUEST['pager']['pageNumber']) ? isset($_REQUEST['pager']['pageNumber']) : 0
100
        );
101

    
102
        if (isset($pager_root_units->records[0])) {
103
          $root_unit_uuids = array();
104
          foreach ($pager_root_units->records as $root_unit) {
105
            $root_unit_uuids[] = $root_unit->uuid;
106
          }
107

    
108
          $render_array['derivate_hierarchy_table'] = compose_compressed_specimen_derivate_table($root_unit_uuids);
109
        }
110

    
111
        $render_array['pager'] = markup_to_render_array(
112
            theme('cdm_pager', array(
113
                'pager' => $pager_root_units,
114
                'path' => $_REQUEST['q'],
115
                'parameters' => $_REQUEST
116
            )),
117
            10 // weight
118
        );
119
    }
120
    else if(($current_view_mode == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE)){ // FIXME this seems to be wrong
121
      $render_array['specimen_list'] = compose_specimen_table_top_down_new($root_unit_dtos);
122
      $render_array['specimen_list']['#weight'] = 2;
123
    } else {
124
      $specimen_table = compose_specimens_table_bottom_up($specimensOrObservations);
125

    
126
      $render_array['specimen_list'] = $specimen_table;
127
      $render_array['pager'] = markup_to_render_array(
128
        theme('cdm_pager', array(
129
          'pager' => $pager,
130
          'path' => $_REQUEST['q'],
131
          'parameters' => $_REQUEST,
132
        )),
133
        10 // weight
134
      );
135
    }
136

    
137
    RenderHints::popFromRenderStack();
138
    return $render_array;
139
}
140

    
141
/**
142
 * @return array
143
 *
144
 * TODO move to cdm_dataportal.module or api.module?
145
 */
146
function relationship_filter_query_parameters()
147
{
148
  $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
149
  $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
150
  $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
151

    
152
  $by_associatedtaxon_query_parameters = array(
153
    'relationshipsInvers' => implode(',', $relationship_choice['invers']),
154
    'relationships' => implode(',', $relationship_choice['direct']),
155
  );
156
  return $by_associatedtaxon_query_parameters;
157
}
158

    
159

    
160
function create_html_link($link, $openInExternalWindow=false){
161
    $html = "";
162
    if($link->uri && $link->uri!=""){
163
        $html .= '<a  href="' . $link->uri . '"';
164
        if($openInExternalWindow){
165
            $html .= ' target="_blank"';
166
        }
167
        $html .= '>' . $link->linkText . '</a>';
168
    }
169
    else{
170
        $html .= $link->linkText;
171
    }
172
    return $html;
173
}
174

    
175
/**
176
 * Creates HTML links from the given link list concatenated by default by a comma.
177
 * @param array $linkList list with Link objects having "uri" and "linkText" as members
178
 * @return string the assembled HTML string containing the links
179
 */
180
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
181
{
182
    $html = "";
183
    if ($linkList) {
184
        foreach ($linkList as $link) {
185
            $html .= create_html_link($link, $openInExternalWindow).$separator;
186
        }
187
        $html = rtrim($html, $separator);
188
    }
189
    return $html;
190
}
191

    
192
/**
193
 * Composes a taxon page which can consist of multiple parts like
194
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
195
 * as tabs or as sections of a single page.
196
 *
197
 * It is headed by the name of the accepted taxon without author and reference.
198
 *
199
 * @param $taxon
200
 *   The CDM Taxon Instance to compose the page for.
201
 * @param $page_part
202
 *   Name of the part to display, valid values are:
203
 *    - 'description' -  for the general part
204
 *    - 'images'
205
 *    - 'synonymy'
206
 *    - 'keys'
207
 *    - 'all'
208
 *
209
 * @return array
210
 *   A drupal render array
211
 *
212
 * @ingroup compose
213
 */
214
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
215

    
216
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
217
  $http_request_params = drupal_get_query_parameters();
218

    
219
  // add all mandatory js sources
220
  _add_js_footnotes();
221

    
222

    
223
  $render_array = array();
224
  $weight = 0; // the weight for the render array elements
225

    
226
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
227

    
228
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
229

    
230
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
231
  if(!$synonymy_as_tab){
232
    unset($tabsToDisplay["Synonymy"]);
233
    // the synonymy is located in the general part in this case
234
    if($page_part == 'synonymy'){
235
      $page_part = 'description';
236
    }
237
  }
238

    
239
  $media = _load_media_for_taxon($taxon);
240

    
241

    
242
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
243
    taxon_page_tabs_hidden_add('images');
244
  }
245

    
246
  // --- GET specimensOrObservations --- //
247
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
248

    
249
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
250
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
251
    taxon_page_tabs_hidden_add('specimens');
252
  }
253

    
254
  // --- GET polytomousKeys --- //
255
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
256
  $identificationKeyCount = 0;
257
  if ($polytomousKeysPager) {
258
    $identificationKeyCount += $polytomousKeysPager->count;
259
  }
260
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
261
    taxon_page_tabs_hidden_add('keys');
262
  }
263

    
264
  // --- GET TaxonNodeAgentRelations --- //
265
  $current_classification_uuid = get_current_classification_uuid();
266
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
267
      array(
268
          $taxon->uuid,
269
          $current_classification_uuid,
270
      ),
271
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
272
  );
273
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
274
      taxon_page_tabs_hidden_add('experts');
275
  }
276

    
277
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
278
    taxon_page_tabs_hidden_add('synonymy');
279
  }
280

    
281
  // -------------------------------------------- //
282

    
283
  if(variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1) && ( $page_part == 'description' || $page_part == 'synonymy' || $page_part == 'all')){
284
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, array($taxon->uuid));
285
    if(is_array($taxon_nodes)){
286
      $render_array['taxon_node_status'] = compose_taxon_node_status($taxon_nodes);
287
      $render_array['taxon_node_status']['#weight'] = -100;
288
    }
289
  }
290

    
291
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
292
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
293
  }
294

    
295
  // --- PAGE PART: DESCRIPTION --- //
296
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
297

    
298
    $merged_tree = merged_taxon_feature_tree($taxon);
299

    
300

    
301
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
302
    $render_array['general']['#weight'] = $weight++;
303
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
304
    $render_array['general']['#suffix'] = '</div>';
305
  }
306

    
307
  // --- PAGE PART: IMAGES --- //
308
  if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) {
309
    $images_html = '<div id="images" class="page-part">';
310
    if ($page_part == 'all') {
311
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
312
    }
313
    // Get the image gallery as configured by the admin.
314
    $configured_image_gallery_viewer = variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT);
315
    if($configured_image_gallery_viewer != 'fsi'){
316
      $images_html .= render_taxon_media_gallery($taxon, $configured_image_gallery_viewer, $media);
317
    } else {
318
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
319
      // flash we also need to provide an the default gallery as alternative
320
      $images_html .= render_taxon_media_gallery($taxon, CDM_MEDIA_GALLERY_VIEWER_DEFAULT, $media);
321
      $images_html .= render_taxon_media_gallery($taxon, $configured_image_gallery_viewer, $media);
322
    }
323
    $images_html .= '</div>'; // END of <div id="images">
324
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
325
  }
326

    
327
  // --- PAGE PART: SYNONYMY --- //
328
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
329
    $synonymy_html = '<div id="synonymy" class="page-part">';
330
    if ($page_part == 'all') {
331
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
332
    }
333
    $addAcceptedTaxon = variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT);
334

    
335
    $synonym_a = compose_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon);
336
    $synonymy_html .= drupal_render($synonym_a);
337

    
338
    $synonymy_html .= '</div>';
339
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
340

    
341
  }
342

    
343
  // --- PAGE PART: SPECIMENS --- //
344
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
345
    $render_array['specimens'] = array(
346
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
347
        'content' => compose_cdm_taxon_page_specimens($taxon), // returns render array
348
        '#suffix' => '</div>',
349
    );
350
  }
351

    
352
  // --- PAGE PART: KEYS --- //
353
  if(!taxon_page_tabs_hidden_check('keys')){
354
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
355
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
356
    }
357
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
358
      $keys_html = '<div id="keys" class="page-part">';
359
      if ($page_part == 'all') {
360
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
361
      }
362
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
363
      $keys_html .= '</div>';
364
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
365
    }
366
  }
367

    
368
  // --- PAGE PART: EXPERTS --- //
369

    
370
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
371
    $render_array['experts'] = array(
372
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
373
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
374
        '#suffix' => '</div>',
375
    );
376
  }
377

    
378
  // ------------------ END OF PARTS -------------- //
379

    
380
  // adjust weights of page and toc elements according to the settings
381
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
382
  foreach($taxontabs_weights as $tab_key => $weight){
383
    if(isset($render_array[$tab_key])){
384
      $render_array[$tab_key]['#weight'] = $weight;
385
    }
386
  }
387

    
388

    
389
  // set up the TOC and pseudo feature blocks for the pages which contain all page parts
390
  if($page_part == 'all' && (!isset( $render_array['general']) || count($render_array['general']) == 0 )) {
391

    
392
    $bibliography_block = make_bibliography_feature_block();
393
    if($bibliography_block){
394
      $render_array['bibliography_block'] = _block_get_renderable_array([$bibliography_block]);
395
      $render_array['bibliography_block']['#weight'] = 100;
396
      cdm_toc_list_add_item('Bibliography', 'bibliography', null, false, $render_array['bibliography_block']['#weight']);
397
    }
398

    
399
    $toc_elements = [];
400
    asort($taxontabs_weights);
401
    foreach(array_keys($taxontabs_weights) as $tab_key){
402
      if(isset($render_array[$tab_key])){
403
        if($tab_key != 'general'){
404
          // add entry for page part
405
          $toc_elements[] = array(
406
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
407
              'class' => array('page-part-toc-item-' . $tab_key)
408
          );
409
        } else {
410
          // add content of profile part instead
411
          if(isset($render_array['general'])) {
412
            // in case all tabs are shown at once the feature tocs
413
            // should be integrated into the tabs toc as sub list
414
            // and the profile image should be on top of the page
415
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
416
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
417
              $toc_elements[] = $profile_toc_item;
418
            }
419
            unset($render_array['general']['taxon_description_feature_toc']);
420
            }
421
          }
422
        }
423
      }
424
    }
425

    
426
    // move profile image in page structure
427
    if(isset($render_array['general']['taxon_profile_image'])){
428
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
429
      $render_array['profile_image']['#weight'] = -100;
430
      unset($render_array['general']['taxon_profile_image']);
431
    }
432

    
433
    // finally add the table of contents to the render array
434
    $render_array['toc'] = array(
435
        '#theme' => 'item_list',
436
        '#items' => $toc_elements,
437
        '#title' => t('Content'),
438
        '#weight' => -101,
439
        '#suffix' => '</div>',
440
        '#prefix'=> '<div id="page-toc">'
441
    );
442

    
443
  }
444

    
445

    
446
  return $render_array;
447
}
448

    
449
/**
450
 * TODO should this function really be a compose function?
451
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
452
 *
453
 * composes and returns an render array containing the components of the taxon profile tab:
454
 *  - 'taxon_profile_image'
455
 *  - 'taxon_description_feature_toc'
456
 *  - 'taxon_description_features'
457
 *
458
 *
459
 * @param object taxon
460
 * @param object $merged_tree
461
 * @param object media
462
 * @param bool $add_synonymy
463
 *
464
 * @return array
465
 *   A Drupal render array with the following elements:
466
 *     - 'taxon_profile_image'
467
 *     - 'taxon_description_feature_toc'
468
 *     - 'taxon_description_features'
469
 *
470
 * @throws Exception
471
 *
472
 * @ingroup compose
473
 */
474
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
475

    
476
  $render_array = array();
477

    
478
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
479

    
480
  $hide_taxon_profile_image = FALSE;
481
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
482
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
483
    $hide_taxon_profile_image = ($rankCompare > -1);
484
  }
485

    
486
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
487

    
488
    $representationPart = new stdClass();
489
    $attributes = array();
490
    if (isset($media[0])) {
491
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
492
      // which only contains the thumbnail representation even if the height and width filters are not set.
493
      // -->
494
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
495
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
496
        'image/jpg',
497
        'image/jpeg',
498
        'image/png',
499
        'image/gif',
500
      ),
501
        $taxon_profile_image_settings['maxextend'],
502
        $taxon_profile_image_settings['maxextend']
503
      );
504
      if(count($preferred_representations) > 0){
505

    
506
        $representation = array_shift($preferred_representations);
507
        $representationPart = $representation->parts[0];
508
        $attributes['alt'] = $representationPart->uri;
509

    
510
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
511
          $representationPart->uri = $representationPart->uri
512
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
513
            . $taxon_profile_image_settings['media_uri_query'];
514
        }
515
      }
516
    }
517
    else {
518
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
519
        // show placeholder image instead
520
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
521
          // use the user provided image
522
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
523
          $url = file_create_url($profile_image_file->uri);
524
          $image_info = image_get_info($profile_image_file->uri);
525
          if($image_info){
526
            $representationPart->width = $image_info['width'];
527
            $representationPart->height = $image_info['height'];
528
            $representationPart->uri = $url;
529
          }
530
        }
531
        if(!isset($representationPart->width)){
532
          // either no custom placeholder defined or $image_info could not be loaded
533
          // use the hard coded default
534
          $representationPart->width = 184;
535
          $representationPart->height = 144;
536
          $representationPart->uri = base_path() . drupal_get_path('module',
537
              'cdm_dataportal') . '/images/no_picture.png';
538
        }
539
        $attributes['alt'] = "no image available";
540
      }
541
    }
542

    
543
    if (isset($representationPart->uri)) {
544
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
545
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
546
      $max_extend_with = $taxon_profile_image_settings['maxextend'] . 'px';
547
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $max_extend_with . '">' . $profile_image . '</div>',
548
        -101);
549
    }
550
  }
551

    
552
  if($add_synonymy){
553
    $synonymy_a = compose_cdm_taxon_page_synonymy($taxon, true);
554
    $synonymy_a['#weight'] = -102;
555
    $synonymy_a['#prefix'] = '<div id="synonymy">';
556
    $synonymy_a['#suffix'] = '</div>';
557
    $render_array['synonymy'] = $synonymy_a;
558
  }
559

    
560
  //  $pseudo_feature_block_toc_items = array();
561

    
562
  // Render the sections for each real feature
563
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
564

    
565
  // >>>>>>>>>>>>>>>>>>> PSEUDO FEATURES >>>>>>>>>>>>>>>>>>>
566
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
567

    
568
  // Bibliography
569
  $bibliography_block = make_bibliography_feature_block();
570
  if($bibliography_block){
571
    $feature_block_list[$pseudo_feature_weights[PSEUDO_FEATURE_BIBLIOGRAPHY]] = $bibliography_block;
572
    cdm_toc_list_add_item('Bibliography', 'bibliography', null, false, $pseudo_feature_weights[PSEUDO_FEATURE_BIBLIOGRAPHY]);
573
  }
574

    
575
  // Descriptions (aggregated)
576
  $descriptionTypes = array();
577
  $descriptionTypes['descriptionTypes'] = ("AGGREGATED_STRUC_DESC");
578
  $aggregatedDescriptions = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXON . '/' . $taxon->uuid . '/descriptions', $descriptionTypes);
579
  if (isset($aggregatedDescriptions) and !empty($aggregatedDescriptions)) {
580
      // if($feature_block_list) ....TODO
581
      $feature_description = make_pseudo_feature('Descriptions (aggregated)', PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS);
582
      $description_item = '';
583
      foreach ($aggregatedDescriptions as $description) {
584
        $description_item = '<div class="' . html_class_attribute_ref($description) . '">';
585
        $description_item .= render_description_string(get_root_nodes_for_dataset($description));
586
        $description_item .= ' ' . icon_link(path_to_description($description->uuid));
587
        $description_item .= '<div class="content-caption">'. statistical_values_explanation() . '</div>';
588
        $description_item .= '</div>';
589
      }
590
      $description_block = feature_block(t('Descriptions (aggregated)'), $feature_description);
591
      $description_block->content = [];
592
      $description_block->content[] = compose_feature_block_wrap_elements([$description_item], $feature_description);
593

    
594
      $feature_block_list[$pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]] = $description_block;
595
      cdm_toc_list_add_item('Descriptions (aggregated)', 'aggregation_descriptions', null, false, $pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]);
596

    
597

    
598
  }
599

    
600
  // sort by weight
601
  ksort($feature_block_list);
602
  $render_array['taxon_description_features'] = _block_get_renderable_array($feature_block_list);
603

    
604
/*  // update TOC
605
  if ($pseudo_feature_block_toc_items){
606
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
607
      cdm_toc_list_add_item($label, $fragment);
608
    }
609
  }
610
*/
611
  // <<<<<<<<<<<<<<<<<<< PSEUDO FEATURES <<<<<<<<<<<<<<<<<<<
612

    
613
  // create the table of content
614
  $toc = array(
615
      '#theme' => 'item_list',
616
    '#items' => cdm_toc_list(),
617
      '#title' => t('Content'),
618
    '#weight' => -100,                  // move to the top
619
      '#suffix' => '</div>',
620
      '#prefix'=> '<div id="page-toc">'
621
  );
622
  $render_array['taxon_description_feature_toc'] = $toc;
623

    
624
  return $render_array;
625
}
626

    
627
/**
628
 * @return object|\stdclass
629
 */
630
function make_bibliography_feature_block() {
631
  $bibliography_block = null;
632
  $bibliography_settings = get_bibliography_settings();
633
  if ($bibliography_settings['enabled'] == 1) {
634
    $bibliography_markup = FootnoteManager::renderFootnoteList(PSEUDO_FEATURE_BIBLIOGRAPHY, '');
635
    if ($bibliography_markup) {
636
      $feature_bibliography = make_pseudo_feature('Bibliography', PSEUDO_FEATURE_BIBLIOGRAPHY);
637
      $bibliography_item = markup_to_render_array($bibliography_markup);
638
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
639
      $bibliography_block->content = [];
640
      $bibliography_block->content[] = compose_feature_block_wrap_elements([$bibliography_item], $feature_bibliography);
641
    }
642
  }
643
  return $bibliography_block;
644
}
645

    
646

    
647
/**
648
 * Renders the link which will lead to the specimen detail page
649
 * @param object $specimen
650
 *    the cdm specimen entity which will be linked to
651
 *
652
 * @return string
653
 *     the markup for the link
654
 */
655
function render_cdm_specimen_link($specimen) {
656
  $path = path_to_specimen($specimen->uuid);
657
  $attributes['class'][] = html_class_attribute_ref($specimen);
658
  return $specimen->titleCache.icon_link($path);
659
}
660

    
661
/**
662
 * Returns HTML containing the synonymy for the accepted taxon.
663
 *
664
 * Shows the whole synonymy for the accepted taxon.
665
 * The synonymy list is headed by the complete scientific name
666
 * of the accepted taxon with nomenclatural reference.
667
 *
668
 * @param object $taxon
669
 * @param boolean $add_accepted_taxon
670
 *
671
 * @return array
672
 *  Drupal render array for the synonymy
673
 *
674
 * @throws Exception
675
 *
676
 * @ingroup compose
677
 */
678
function compose_cdm_taxon_page_synonymy($taxon, $add_accepted_taxon) {
679

    
680
  RenderHints::pushToRenderStack('taxon_page_synonymy');
681

    
682
  // footnote key for the homotypic group and accepted taxon,
683
  // both should have the same footnote key
684
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
685

    
686
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, array($taxon->uuid));
687

    
688
  $out = '';
689

    
690
  // Render accepted taxon.
691
  //
692
  // foonotes of the accepted taxon will be rendered in the homotypic group section
693
  // even if there are not synonyms in the homotypic group
694
  // homotypic group and accepted taxon should have the same footnote key
695
  $referenceUri = '';
696
  if ($add_accepted_taxon) {
697
    // set new render path for the accepted taxon so
698
    // it can be styled differently via the name render part definitions
699
    RenderHints::pushToRenderStack('accepted_taxon');
700
    $accepted_name = '';
701
    if (variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0)) {
702
      $label = variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT);
703
      $accepted_name .= '<div class="secReference"><span class="label">' . t($label) . ':</span> ' . $taxon->sec->titleCache . '</div>';
704
    }
705
    if (isset($taxon->name->nomenclaturalSource->citation)) {
706
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalSource->citation->uuid));
707
    }
708

    
709
    $accepted_name .= '<div class="accepted-name">';
710
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
711

    
712
    $name_relations = cdm_name_relationships_for_taxon($taxon);
713
    $name_relationships = compose_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
714
    // Render relationships of accepted name.
715
    if(isset($name_relationships['list']['items'][0])){
716
      $accepted_name .= ' ' . drupal_render($name_relationships);
717
    }
718
    $accepted_name .= '</div>';
719
    RenderHints::popFromRenderStack();
720
  }
721

    
722
  // --- Render homotypic synonymy group
723
  if (!empty($accepted_name)) {
724
    $out .= $accepted_name;
725
  }
726

    
727
  // Render the homotypicSynonymyGroup including the type information.
728
  $out .= theme(
729
    'cdm_homotypicSynonymyGroup',
730
    array(
731
      'synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup,
732
      'accepted_taxon_name_uuid' => $taxon->name->uuid
733
    )
734
  );
735

    
736

    
737
  // Render accepted taxon heterotypic synonymy groups.
738
  if ($synomymie->heterotypicSynonymyGroups) {
739
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
740
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
741
    }
742
  }
743
  // Render taxon relationships.
744
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
745
    $taxonRelationshipsDTO = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS_DTO, $taxon->uuid);
746
    $out .= cdm_taxonRelationships($taxonRelationshipsDTO, $taxon);
747
  }
748

    
749
  RenderHints::popFromRenderStack();
750

    
751
  return markup_to_render_array($out);
752
}
753

    
754

    
755
/**
756
 * composes and returns an render array for the experts associated with the given taxon
757
 *
758
 * @param object taxon
759
 *
760
 * @return array
761
 *   A Drupal render array for a table with the experts
762
 *
763
 * @ingroup compose
764
 */
765
function compose_cdm_taxon_page_experts($taxon){
766

    
767
  $render_array = array();
768
  if(!isset($taxon->uuid)){
769
    return $render_array;
770
  }
771

    
772
  $current_classification_uuid = get_current_classification_uuid();
773
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
774
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
775
    array(
776
      $taxon->uuid,
777
      $current_classification_uuid
778
    )
779
  );
780

    
781
  $header = array(
782
    array('data' => t('Expert')),
783
    array('data' => t('Role'))
784
  );
785
  $rows = array();
786

    
787

    
788
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
789

    
790

    
791
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
792
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
793

    
794
    $agent_label_markup = cdm_dynabox(
795
      'expert_' . $expert_role_id,
796
      $taxon_node_agent_relation->agent->titleCache,
797
      // specifying both ends of the relationship will return only one record in the pager
798
      cdm_compose_ws_url(CDM_WS_PORTAL_AGENT,
799
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
800
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
801
      'cdm_taxon_expert',
802
      'Click for details',
803
      array('div', 'div'),
804
      array(), // attributes
805
      '#' . $expert_details_container_id // $content_element_selector
806
    );
807

    
808
    // Expert and Role
809
    $rows[] = array(
810
      'data' => array(
811
        array(
812
          'data' => $agent_label_markup,
813
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
814
        ),
815
        array(
816
          'data' => $taxon_node_agent_relation->type->representation_L10n,
817
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
818
        )
819
      )
820
    );
821
    // Agent details
822
    $rows[] = array(
823
      'data' => array(
824
        array(
825
          'data' => '<!-- expert_details_container -->',
826
          'id' => $expert_details_container_id,
827
          'colspan' => 2
828
        )
829
      )
830
    );
831

    
832
  }
833

    
834

    
835
  $render_array['experts_table'] = array(
836
    '#theme' => 'table',
837
    '#header' => $header,
838
    '#rows' => $rows,
839
  );
840

    
841

    
842
  return $render_array;
843
}
844

    
845

    
846
/**
847
 * Manages the tabs to be hidden in the taxon page.
848
 *
849
 * The tabs are identified by their last menu link path element:
850
 *  - description
851
 *  - synonymy
852
 *  - images
853
 *  - specimens
854
 *  - key
855
 *
856
 * Internally the tabs are stored in a static variable which is
857
 * managed by drupal_static().
858
 *
859
 * @param string $add_tab
860
 *   Optional parameter. The given string will be added to the array of tabs
861
 *
862
 * @return array
863
 *   The array of tabs
864
 */
865
function taxon_page_tabs_hidden_add($add_tab = NULL) {
866
  $tabs = &drupal_static('taxon_page_tabs_hidden');
867

    
868
  if(!isset($tabs)){
869
    $tabs = array();
870
  }
871

    
872
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
873
    $tabs[] = $add_tab;
874
  }
875

    
876
  return $tabs;
877
}
878

    
879
/**
880
 * Manages the tabs to be hidden in the taxon page.
881
 *
882
 * The tabs names are identified by their last menu link path element:
883
 *  - description
884
 *  - synonymy
885
 *  - images
886
 *  - specimens
887
 *  - key
888
 *
889
 * Internally the tabs are stored in a static variable which is
890
 * managed by drupal_static().
891
 *
892
 * @param string $tabname
893
 *   The name of the tab to check
894
 *
895
 * @return boolean
896
 *   True if the tab or section is to be hidden
897
 */
898
function taxon_page_tabs_hidden_check($tabname) {
899

    
900
  $tabs = &drupal_static('taxon_page_tabs_hidden');
901

    
902
  if(!isset($tabs)){
903
    $tabs = array();
904
  }
905

    
906
  return array_search($tabname, $tabs) !== FALSE;
907
}
908

    
909
/**
910
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
911
 *
912
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
913
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
914
 *
915
 * @param array $variables
916
 *   The variables array
917
 */
918
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
919

    
920
  $hidden_tabs = taxon_page_tabs_hidden_add();
921

    
922
  if (!variable_get(CDM_SEARCH_BLAST_ENABLED)) {
923
      if (is_array($variables['primary'])) {
924
          foreach ($variables['primary'] as $key => &$element) {
925
              if ($element['#link']['path'] == 'cdm_dataportal/search/blast') {
926
                  // remove the tab
927
                  unset($variables['primary'][$key]);
928
              }
929

    
930
          }
931
      }
932
  }
933
  if (is_array($variables['primary'])) {
934
    foreach ($variables['primary'] as $key => &$element) {
935

    
936
      // 1. Remove the tabs to be hidden
937
      foreach ($hidden_tabs as $tab) {
938
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
939
          // remove the tab
940
          unset($variables['primary'][$key]);
941
        }
942
      }
943
    }
944
  }
945
}
946

    
947

    
948

    
949
/**
950
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
951
 *
952
 *
953
 * @param array $variables
954
 *   An associative array containing:
955
 *     - element: A render element containing:
956
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
957
 *          #active: A boolean indicating whether the local task is active.
958
 *
959
 */
960
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
961

    
962
  $link = $variables['element']['#link'];
963
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
964
    $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']) . '"/>';
965
    $link['localized_options']['html'] = TRUE;
966

    
967
    $variables['element']['#link'] = $link;
968
  }
969
}
970

    
971
/* =================== block composition ===================== */
972

    
973
/**
974
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
975
 *
976
 * @param $taxon_uuid
977
 *
978
 * @return array
979
 *   A Drupal render array for a table with the experts
980
 *
981
 * @ingroup compose
982
 */
983
function compose_classification_breadcrumbs($taxon_uuid) {
984

    
985
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
986

    
987
  $render_array = array();
988

    
989
  $render_array['#theme'] = 'item_list';
990
  $render_array['#type'] = 'ul';
991
  $render_array['#attributes'] = array(
992
    'id' => 'classification-breadcrumbs',
993
    'class' => 'breadcrumbs inline',
994
  );
995

    
996
  $items = array();
997

    
998
  $parent_taxon_nodes = null;
999
  if($taxon_uuid){
1000
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1001
  }
1002

    
1003
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1004
  // find current classification in list
1005
  $classification = null;
1006
  $current_classification_uuid = get_current_classification_uuid();
1007
  foreach ($classifications as $classification){
1008
    if($classification->uuid == $current_classification_uuid){
1009
      break;
1010
    }
1011
  }
1012

    
1013
  $node_name = '';
1014
  if(count($classifications) > 1 ){
1015
    // need to add the current classification as first label
1016

    
1017
    $label = $classification->titleCache;
1018
    if(strlen($label) > 20){
1019
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1020
    }
1021
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1022
      'attributes' => array(
1023
        'class' => 'taxonomic-children-button classification-chooser',
1024
        'data-destination-uri' => drupal_get_destination(),
1025
        'data-cdm-align-with' => array('prev')
1026
      ),
1027
      'html' => true
1028
    ));
1029
  }
1030

    
1031
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1032

    
1033
  $rank_separator = '<span> '
1034
    . font_awesome_icon_markup('fa-chevron-right')
1035
    . ' </span>';
1036
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1037
  $more_children_label = '...';
1038

    
1039
  $items[] = $node_name;
1040

    
1041
  $more_children_for = null;
1042
  if($parent_taxon_nodes){
1043
    foreach ($parent_taxon_nodes as $node) {
1044

    
1045
      $is_first_item = count($items) == 0;
1046
      $is_last_item = count($items) == count($parent_taxon_nodes);
1047
      $node_name = cdm_dataportal_shortname_of($node);
1048
      $path = path_to_taxon($node->taxonUuid);
1049

    
1050
      if($node->taxonomicChildrenCount > 0) {
1051
        $more_children_for = $node->taxonUuid;
1052
      } else {
1053
        $more_children_for = null;
1054
      }
1055

    
1056
      // 'fa-sitemap'
1057

    
1058
      $items[] =
1059
        ($is_first_item ? '' : ' ')
1060
        . $rank_separator
1061
        . l(
1062
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1063
          $path,
1064
          array(
1065
            'attributes' => array(
1066
              'class' => array('taxonomic-children-button'),
1067
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1068
              'data-cdm-classification-mode' => array('siblings'),
1069
              'data-cdm-align-with' => array('prev')
1070
            ),
1071
            'html' => true
1072
          )
1073
        );
1074
      }
1075
    }
1076

    
1077
  // add more button to the end
1078
  if(!$parent_taxon_nodes) {
1079
    // not taxon focused yet, adding button to make  the root nodes available
1080
    $items[] = '<span>'
1081
      . $more_children_icon . '&nbsp;' .
1082
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1083
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1084
      . '</span>';
1085
  } else if($more_children_for){
1086
    // last parent item has child taxon nodes
1087
    $items[] = ' <span>'
1088
      . $more_children_icon . '&nbsp;' .
1089
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1090
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1091
      . '</span>';
1092

    
1093
  }
1094

    
1095
  $render_array['#items'] = $items;
1096

    
1097
  return $render_array;
1098
}
1099

    
1100

    
1101
/**
1102
 *
1103
 * @param $specimen_or_observation
1104
 *   A CDM SpecimenOrObservation entity
1105
 *
1106
 * @return array
1107
 *    The drupal render array for the page
1108
 *
1109
 * @ingroup compose
1110
 */
1111
function compose_cdm_specimen_page($specimen_or_observation)
1112
{
1113
  drupal_set_title("Specimen Details");
1114
  RenderHints::pushToRenderStack('specimen_page');
1115

    
1116
  $specimen_table = array(
1117
      '#theme' => 'table',
1118
      '#weight' => 2,
1119
      // prefix attributes and rows with '#' to let it pass to the theme function,
1120
      // otherwise it is handled as child render array
1121

    
1122
    '#attributes' => array('class' => 'specimens'),
1123
      '#rows' => array(),
1124
      '#prefix' => '<div id="specimens">',
1125
      '#suffix' => '</div>',
1126

    
1127

    
1128
  );
1129
  $specimen_markup = compose_cdm_specimen_or_observation($specimen_or_observation, true);
1130

    
1131
  $specimen_table['#rows'][] = array(
1132
          // An array of table rows. Every row is an array of cells, or an associative array
1133
          'data' => $specimen_markup,
1134
          'class' =>  array(
1135
              'descriptionElement',
1136
              'descriptionElement_IndividualsAssociation'
1137
          ),
1138
  );
1139

    
1140
  $render_array['specimen_table'] =  $specimen_table;
1141

    
1142
  RenderHints::popFromRenderStack();
1143
  return $specimen_markup; // $render_array;
1144
}
1145

    
1146
/**
1147
 * @param $named_area_uuid
1148
 * @return array
1149
 *    The drupal render array for the page
1150
 *
1151
 * @ingroup compose
1152
 */
1153
function compose_cdm_named_area_page($named_area_uuid)
1154
{
1155

    
1156
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1157

    
1158
  $render_array = array();
1159
  RenderHints::pushToRenderStack('named_area_page');
1160

    
1161
  $groups = array();
1162
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1163
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1164
  if(isset($named_area->level)) {
1165
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1166
  }
1167

    
1168
  $name_area_details_elements = array(
1169
   // '#title' => $title,
1170
    '#theme' => 'description_list',
1171
    '#groups' => $groups,
1172
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1173
  );
1174

    
1175
  $render_array[] = $name_area_details_elements;
1176

    
1177
  RenderHints::popFromRenderStack();
1178
  return $render_array;
1179
}
1180

    
1181

    
1182
/**
1183
 * Returns a drupal render array for a single reference page.
1184
 *
1185
 * Composes a page with all data on a single reference.
1186
 *
1187
 * @param string $uuid
1188
 *   An uuid for a cdm reference.
1189
 *
1190
 * @return array
1191
 *  A drupal render array
1192
 *
1193
 * @throws Exception
1194
 *
1195
 * @ingroup compose
1196
 */
1197
function compose_cdm_reference_page($uuid) {
1198

    
1199
  $pathelement = "reference_page";
1200
  RenderHints::pushToRenderStack($pathelement);
1201
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1202
  if (!$reference) {
1203
    drupal_set_title(t('Reference does not exist'), PASS_THROUGH);
1204
    return "";
1205
  }
1206
  if (isset($reference->titleCache)) {
1207
    drupal_set_title($reference->titleCache, PASS_THROUGH);
1208
  }
1209

    
1210
  $field_order = array(
1211
    "title",
1212
    "abbrevTitle",
1213
    // "titleCache" abbrevTitleCache
1214
    // "citation",
1215
    "authorship",
1216
    "editor",
1217
    "publisher",
1218
    "placePublished",
1219
    "datePublished",
1220
    "year",
1221
    "edition",// Class Book.
1222
    "volume",// Class Article.
1223
    "seriesPart",
1224
    "inReference",
1225
    "nomRefBase", // Class BookSection, Book, Article.
1226
    "pages",// Class Article.
1227
    "series",// Class Article, PrintSeries.
1228
    "school",// Class Thesis.
1229
    "institution",// Class Report.
1230
    "organization",// Class Proceedings.
1231
    "nextVersion",
1232
    "previousVersion",
1233
    "isbn",// Class Book.
1234
    "issn",// Class Journal.
1235
    "doi",
1236
    "uri"
1237
  );
1238

    
1239
  $table_rows = array();
1240

    
1241
  if (!isset($reference->authorship)) {
1242
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
1243
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
1244
  }
1245

    
1246
  if (!isset($reference->inReference)) {
1247
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
1248
      $reference->uuid,
1249
      "inReference",
1250
    ));
1251
  }
1252

    
1253
  foreach ($field_order as $fieldname) {
1254

    
1255
    if (isset($reference->$fieldname)) {
1256

    
1257
      if ($fieldname == "datePublished") {
1258
        $period = $reference->$fieldname;
1259
        $datePublished = timePeriodToString($period);
1260
        if (isset($datePublished) && $datePublished != '') {
1261
          $table_rows[] = array(
1262
            t("Date published"),
1263
            $datePublished,
1264
          );
1265
        }
1266
      }
1267
      elseif ($fieldname == "doi" && is_object($reference->doi)) {
1268
        $table_rows[] = array(
1269
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1270
          cdm_doi($reference->doi, false)
1271
        );
1272
      }
1273
      elseif ($fieldname == "uri" && isset($reference->uri) && $reference->uri) {
1274
        $table_rows[] = array(
1275
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1276
          cdm_external_uri($reference->uri, false)
1277
        );
1278
      }
1279
      elseif (is_object($reference->$fieldname)) {
1280
        if ($fieldname == "authorship") {
1281
          $dump = $reference->$fieldname;
1282
          $teammembers = "teamMembers";
1283
          $team = $dump->$teammembers;
1284
          $nameArray = array();
1285

    
1286
          foreach ($team as $member) {
1287
            if (strlen($member->lastname) > 0) {
1288
              $nname = $member->lastname;
1289
              $name = $nname;
1290
              if (strlen($member->firstname) > 0) {
1291
                $vname = $member->firstname;
1292
                $name = $vname . " " . $nname;
1293
              }
1294
              $nameArray[] = $name;
1295
            }
1296
            else {
1297
              if (strlen($member->titleCache) > 0) {
1298
                $nameArray[] = $member->titleCache;
1299
              }
1300
            }
1301
          }
1302
          $value = join($nameArray, ", ");
1303
        }
1304
        elseif ($fieldname == "inReference") {
1305
          $type = $reference->$fieldname->type;
1306
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
1307
          switch ($type) {
1308
            case "Book":
1309
              $fieldname = "in book";
1310
              break;
1311
            case "Journal":
1312
              $fieldname = "in journal";
1313
              break;
1314
            case "Proceedings":
1315
              $fieldname = "in proceedings";
1316
              break;
1317
          }
1318
        }
1319
        else {
1320
          $value = $reference->$fieldname->titleCache;
1321
        }
1322

    
1323

    
1324
        if (isset($value) && $value != '') {
1325
          $table_rows[] = array(
1326
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1327
            $value,
1328
          );
1329
        }
1330

    
1331
      }
1332
      else {
1333
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
1334
          $table_rows[] = array(
1335
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1336
            $reference->$fieldname,
1337
          );
1338
        }
1339
      }
1340
    }
1341
  }
1342

    
1343
  $out = theme_table(array(
1344
    'header' => array(),
1345
    'rows' => $table_rows,
1346
    'attributes' => array(
1347
      'class' => html_class_attribute_ref($reference)
1348
    ),
1349
    'caption' => NULL,
1350
    'colgroups' => NULL,
1351
    'sticky' => NULL,
1352
    'empty' => NULL,
1353
  ));
1354

    
1355
  if(isset($reference->referenceAbstract)){
1356
    $out .= '<h2 class="block-title">Abstract</h2><div class="abstract">' . $reference->referenceAbstract . '</div>';
1357
  }
1358

    
1359

    
1360
  // Annotations below the table
1361
  $annotations = cdm_fetch_visible_annotations($reference);
1362
  $out .= cdm_annotations($annotations);
1363

    
1364
  $registration_working_set = cdm_ws_get("registrationWorkingSetDTO", array($uuid));
1365
  if($registration_working_set && count($registration_working_set->registrationDTOs) > 0){
1366
    $out .= "<h3>Nomenclatural acts:</h3><div class=\"cdm-item-list registration-item-list\">";
1367
    foreach($registration_working_set->registrationDTOs as $registration_dto){
1368
      if($registration_dto->status == "PUBLISHED"){
1369
        $registration_render_a = compose_registration_dto_compact($registration_dto, 'citation');
1370
        $registration_render_a["#prefix"] = "<div class=\"item item-registration\">";
1371
        $registration_render_a["#suffix"] = "</div>";
1372
        $out .= drupal_render($registration_render_a);
1373
      }
1374
    }
1375
    $out .= "</div>";
1376
  }
1377

    
1378
  RenderHints::popFromRenderStack();
1379

    
1380
  return markup_to_render_array($out);
1381
}
1382

    
1383
/**
1384
 * Provides the the label string for taxon page tabs.
1385
 *
1386
 * The $tabname as passed to the method will be returned if no override
1387
 * label is configured in the settings.
1388
 *
1389
 * @param $tabname
1390
 *
1391
 * @return mixed
1392
 */
1393
function cdm_taxonpage_tab_label($tabname) {
1394
  static $taxon_tabs_labels = null;
1395
  if($taxon_tabs_labels == null){
1396
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1397
  }
1398
  $tabname_key = strtolower($tabname);
1399
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1400
    return $taxon_tabs_labels[$tabname_key];
1401
  }
1402
  return $tabname;
1403
}
1404

    
1405
/**
1406
 *  Returns HTML for the default title of a specimen page.
1407
 *  The returned title is a the identifier of the specimen.
1408
 *
1409
 * @param object $occurrence
1410
 *  The CDM SpecimenOrObservation instance
1411
 *     being formatted for the title.
1412
 *
1413
 * @return string
1414
 *  Markup for the title of a specimen page
1415
 */
1416
function render_specimen_page_title($occurrence)
1417
{
1418
  RenderHints::pushToRenderStack('render_specimen_page_title');
1419
  $out = '';
1420
  list($specimenID, $collection) = specimen_id_and_collection_for($occurrence);
1421
  if ($occurrence->class == 'FieldUnit'){
1422
    $out .= '<span class="type-label">Field unit: </span>';
1423
  }else{
1424
    $out .= '<span class="type-label">Specimen:  </span>';
1425
  }
1426

    
1427
  if($collection){
1428
    $out .= $collection." ";
1429
  }
1430
  $out .= $specimenID;
1431

    
1432
  RenderHints::popFromRenderStack();
1433

    
1434
  return '<span class="' . $occurrence->class . '">' . $out . '</span>';
1435
}
1436

    
1437
/**
1438
 * Returns HTML for the default title of a specimen page.
1439
 * The returned title is a the identifier of the specimen.
1440
 *
1441
 * @param object $occurrence_dto
1442
 *   An dto for a cdm SpecimenOrObservation entity
1443
 *
1444
 * @return string
1445
 *  Markup for the title of a specimen page
1446
 *
1447
 */
1448
function render_cdm_specimen_dto_page_title($occurrence_dto)
1449
{
1450
  RenderHints::pushToRenderStack('render_specimen_page_title');
1451
  $out = '';
1452
  list($specimenID, $collection) = specimen_id_and_collection_for($occurrence_dto);
1453
  if ($occurrence_dto->class == 'FieldUnit'){
1454
    $out .= "FieldUnit ";
1455
  }else{
1456
    $out .= "Specimen ";
1457
  }
1458
  if($collection){
1459
    $out .= $collection." ";
1460
  }
1461
  $out .= $specimenID;
1462

    
1463
  RenderHints::popFromRenderStack();
1464
  return '<span class="' . $occurrence_dto->class . '">' . $out . '</span>';
1465
}
1466

    
(10-10/15)