Project

General

Profile

Download (47.5 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
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
    $fieldUnitDTOs = null;
41
    $specimensOrObservations = null;
42
    if (variable_get('cdm_dataportal_specimen_derivate_tree')){
43
      // get fieldUnitDTOs
44
      $fieldUnitDTOs = cdm_ws_get(CDM_WS_TAXON_FIELDUNIT_DTOS, array( $taxon->uuid));
45
      $fieldUnitDTOs = order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs);
46
    } else {
47
      // $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
48
      // extend by associated taxas occurrences
49
      $relationship_filter_query_parameters = relationship_filter_query_parameters();
50

    
51
      if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
52
        $relationship_filter_query_parameters = array_merge($relationship_filter_query_parameters, $_REQUEST['pager']);
53
      }
54
      $by_associatedtaxon_query = http_build_query($relationship_filter_query_parameters);
55
      $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
56
        null,
57
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
58
      );
59
      $specimensOrObservations = array();
60
      if (isset($pager->records[0])) {
61
        $specimensOrObservations = $pager->records;
62
      }
63
      // cdm_ws_get(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 || $fieldUnitDTOs > 0) {
88
        $render_array['map'] = occurrence_map_query_parameters($taxon);
89
    }
90

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

    
93
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
94

    
95
        //COMPRESSED SPECIMEN DERIVATE TABLE
96
        $associatedFieldUnitsQuery_parameters = array();
97
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
98
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
99
        }
100

    
101
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
102
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
103
            array($taxon->uuid, 'associatedFieldUnits'),
104
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
105
        );
106

    
107
        if (isset($pager_field_units->records[0])) {
108
          $field_unit_uuids = array();
109
          foreach ($pager_field_units->records as $field_unit) {
110
            $field_unit_uuids[] = $field_unit->uuid;
111
          }
112

    
113
          $render_array['derivate_hierarchy_table'] = compose_compressed_specimen_derivate_table($field_unit_uuids);
114
        }
115

    
116
        $render_array['pager'] = markup_to_render_array(
117
            theme('cdm_pager', array(
118
                'pager' => $pager_field_units,
119
                'path' => $_REQUEST['q'],
120
                'parameters' => $_REQUEST
121
            )),
122
            10 // weight
123
        );
124
    }
125
    else if(variable_get('cdm_dataportal_specimen_derivate_tree')){
126
      $render_array['specimen_list'] = compose_specimen_table_top_down($fieldUnitDTOs);
127
      $render_array['specimen_list']['#weight'] = 2;
128
    } else {
129
      $specimen_table = compose_specimens_table_bottom_up($specimensOrObservations);
130

    
131
      $render_array['specimen_list'] = $specimen_table;
132
      $render_array['pager'] = markup_to_render_array(
133
        theme('cdm_pager', array(
134
          'pager' => $pager,
135
          'path' => $_REQUEST['q'],
136
          'parameters' => $_REQUEST,
137
        )),
138
        10 // weight
139
      );
140
    }
141

    
142
    RenderHints::popFromRenderStack();
143
    return $render_array;
144
}
145

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

    
157
  $by_associatedtaxon_query_parameters = array(
158
    'relationshipsInvers' => implode(',', $relationship_choice['invers']),
159
    'relationships' => implode(',', $relationship_choice['direct']),
160
  );
161
  return $by_associatedtaxon_query_parameters;
162
}
163

    
164

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

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

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

    
221
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
222
  $http_request_params = drupal_get_query_parameters();
223

    
224
  // add all mandatory js sources
225
  _add_js_footnotes();
226

    
227

    
228
  $render_array = array();
229
  $weight = 0; // the weight for the render array elements
230

    
231
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
232

    
233
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
234

    
235
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
236
  if(!$synonymy_as_tab){
237
    unset($tabsToDisplay["Synonymy"]);
238
    // the synonymy is located in the general part in this case
239
    if($page_part == 'synonymy'){
240
      $page_part = 'description';
241
    }
242
  }
243

    
244
  $media = _load_media_for_taxon($taxon);
245

    
246

    
247
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
248
    taxon_page_tabs_hidden_add('images');
249
  }
250

    
251
  // --- GET specimensOrObservations --- //
252
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
253

    
254
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
255
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
256
    taxon_page_tabs_hidden_add('specimens');
257
  }
258

    
259
  // --- GET polytomousKeys --- //
260
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
261
  $identificationKeyCount = 0;
262
  if ($polytomousKeysPager) {
263
    $identificationKeyCount += $polytomousKeysPager->count;
264
  }
265
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
266
    taxon_page_tabs_hidden_add('keys');
267
  }
268

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

    
282
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
283
    taxon_page_tabs_hidden_add('synonymy');
284
  }
285

    
286
  // -------------------------------------------- //
287

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

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

    
298
  // --- PAGE PART: DESCRIPTION --- //
299
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
300

    
301
    $merged_tree = merged_taxon_feature_tree($taxon);
302

    
303

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

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

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

    
338
    $synonym_a = compose_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon);
339
    $synonymy_html .= drupal_render($synonym_a);
340

    
341
    $synonymy_html .= '</div>';
342
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
343

    
344
  }
345

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

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

    
371
  // --- PAGE PART: EXPERTS --- //
372

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

    
381
  // ------------------ END OF PARTS -------------- //
382

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

    
391

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

    
421
    // move profile image in page structure
422
    if(isset($render_array['general']['taxon_profile_image'])){
423
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
424
      $render_array['profile_image']['#weight'] = -100;
425
      unset($render_array['general']['taxon_profile_image']);
426
    }
427

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

    
438
  }
439

    
440

    
441
  return $render_array;
442
}
443

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

    
471
  $render_array = array();
472

    
473
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
474

    
475
  $hide_taxon_profile_image = FALSE;
476
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
477
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
478
    $hide_taxon_profile_image = ($rankCompare > -1);
479
  }
480

    
481
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
482

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

    
501
        $representation = array_shift($preferred_representations);
502
        $representationPart = $representation->parts[0];
503
        $attributes['alt'] = $representationPart->uri;
504

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

    
535
    if (isset($representationPart->uri)) {
536
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
537
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
538
      $max_extend_with = $taxon_profile_image_settings['maxextend'] . 'px';
539
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $max_extend_with . '">' . $profile_image . '</div>',
540
        -101);
541
    }
542
  }
543

    
544
  if($add_synonymy){
545
    $synonymy_a = compose_cdm_taxon_page_synonymy($taxon, true);
546
    $synonymy_a['#weight'] = -102;
547
    $synonymy_a['#prefix'] = '<div id="synonymy">';
548
    $synonymy_a['#suffix'] = '</div>';
549
    $render_array['synonymy'] = $synonymy_a;
550
  }
551

    
552
//  $pseudo_feature_block_toc_items = array();
553

    
554

    
555
  // Render the sections for each real feature
556
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
557

    
558
  // >>>>>>>>>>>>>>>>>>> PSEUDO FEATURES >>>>>>>>>>>>>>>>>>>
559
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
560
  // Bibliography
561
  $bibliography_settings = get_bibliography_settings();
562
  if($bibliography_settings['enabled'] == 1){
563
    $bibliography_markup = FootnoteManager::renderFootnoteList(PSEUDO_FEATURE_BIBLIOGRAPHY, '');
564
    if($bibliography_markup) {
565
      $feature_bibliography = make_pseudo_feature('Bibliography', PSEUDO_FEATURE_BIBLIOGRAPHY);
566
      $bibliography_item = markup_to_render_array($bibliography_markup);
567
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
568
      $bibliography_block->content = array();
569
      $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
570

    
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

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

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

    
598

    
599
  }
600

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

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

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

    
625
  return $render_array;
626
}
627

    
628

    
629
/**
630
 * Renders the link which will lead to the specimen detail page
631
 * @param object $specimen
632
 *    the cdm specimen entity which will be linked to
633
 *
634
 * @return string
635
 *     the markup for the link
636
 */
637
function render_cdm_specimen_link($specimen) {
638
  $path = path_to_specimen($specimen->uuid);
639
  $attributes['class'][] = html_class_attribute_ref($specimen);
640
  return $specimen->titleCache.icon_link($path);
641
}
642

    
643
/**
644
 * Returns HTML containing the synonymy for the accepted taxon.
645
 *
646
 * Shows the whole synonymy for the accepted taxon.
647
 * The synonymy list is headed by the complete scientific name
648
 * of the accepted taxon with nomenclatural reference.
649
 *
650
 * @param object $taxon
651
 * @param boolean $add_accepted_taxon
652
 *
653
 * @return array
654
 *  Drupal render array for the synonymy
655
 *
656
 * @throws Exception
657
 *
658
 * @ingroup compose
659
 */
660
function compose_cdm_taxon_page_synonymy($taxon, $add_accepted_taxon) {
661

    
662
  RenderHints::pushToRenderStack('taxon_page_synonymy');
663

    
664
  // footnote key for the homotypic group and accepted taxon,
665
  // both should have the same footnote key
666
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
667

    
668
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, array($taxon->uuid));
669

    
670
  $out = '';
671

    
672
  // Render accepted taxon.
673
  //
674
  // foonotes of the accepted taxon will be rendered in the homotypic group section
675
  // even if there are not synonyms in the homotypic group
676
  // homotypic group and accepted taxon should have the same footnote key
677
  $referenceUri = '';
678
  if ($add_accepted_taxon) {
679
    // remember the last part of the render path
680
    $synonymy_render_path = RenderHints::getRenderPath();
681
    // set new render path for the accepted taxon so
682
    // it can be styled differently via the name render part definitions
683
    RenderHints::pushToRenderStack('accepted_taxon');
684
    $accepted_name = '';
685
    if (variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0)) {
686
      $label = variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT);
687
      $accepted_name .= '<div class="secReference"><span class="label">' . t($label) . ':</span> ' . $taxon->sec->titleCache . '</div>';
688
    }
689
    if (isset($taxon->name->nomenclaturalReference)) {
690
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
691
    }
692

    
693
    $accepted_name .= '<div class="accepted-name">';
694
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
695

    
696
    $name_relations = cdm_name_relationships_for_taxon($taxon);
697
    $name_relationships = compose_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
698
    // Render relationships of accepted name.
699
    if(isset($name_relationships['list']['items'][0])){
700
      $accepted_name .= ' ' . drupal_render($name_relationships);
701
    }
702

    
703
    // handle annotations of the name and taxon
704
    $special_annotations_array = array();
705
    $special_annotations_array[] = $taxon->name;
706
    $special_annotations_array[] = $taxon;
707
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
708
        'cdmBase_list' => $special_annotations_array,
709
        'footnote_list_key' => $synonymy_render_path . '-annotations')
710
    );
711
    $accepted_name .= '</div>';
712
    RenderHints::popFromRenderStack();
713
  }
714

    
715
  // --- Render homotypic synonymy group
716
  if (!empty($accepted_name)) {
717
    $out .= $accepted_name;
718
  }
719

    
720
  // Render the homotypicSynonymyGroup including the type information.
721
  $out .= theme(
722
    'cdm_homotypicSynonymyGroup',
723
    array(
724
      'synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup,
725
      'accepted_taxon_name_uuid' => $taxon->name->uuid
726
    )
727
  );
728

    
729

    
730
  // Render accepted taxon heterotypic synonymy groups.
731
  if ($synomymie->heterotypicSynonymyGroups) {
732
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
733
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
734
    }
735
  }
736
  // Render taxon relationships.
737
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
738
    $taxonRelationshipsDTO = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS_DTO, $taxon->uuid);
739
    $out .= cdm_taxonRelationships($taxonRelationshipsDTO, $taxon);
740
  }
741

    
742
  RenderHints::popFromRenderStack();
743

    
744
  return markup_to_render_array($out);
745
}
746

    
747

    
748
/**
749
 * composes and returns an render array for the experts associated with the given taxon
750
 *
751
 * @param object taxon
752
 *
753
 * @return array
754
 *   A Drupal render array for a table with the experts
755
 *
756
 * @ingroup compose
757
 */
758
function compose_cdm_taxon_page_experts($taxon){
759

    
760
  $render_array = array();
761
  if(!isset($taxon->uuid)){
762
    return $render_array;
763
  }
764

    
765
  $current_classification_uuid = get_current_classification_uuid();
766
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
767
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
768
    array(
769
      $taxon->uuid,
770
      $current_classification_uuid
771
    )
772
  );
773

    
774
  $header = array(
775
    array('data' => t('Expert')),
776
    array('data' => t('Role'))
777
  );
778
  $rows = array();
779

    
780

    
781
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
782

    
783

    
784
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
785
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
786

    
787
    $agent_label_markup = cdm_dynabox(
788
      'expert_' . $expert_role_id,
789
      $taxon_node_agent_relation->agent->titleCache,
790
      // specifying both ends of the relationship will return only one record in the pager
791
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
792
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
793
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
794
      'cdm_taxon_expert',
795
      'Click for details',
796
      array('div', 'div'),
797
      array(), // attributes
798
      '#' . $expert_details_container_id // $content_element_selector
799
    );
800

    
801
    // Expert and Role
802
    $rows[] = array(
803
      'data' => array(
804
        array(
805
          'data' => $agent_label_markup,
806
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
807
        ),
808
        array(
809
          'data' => $taxon_node_agent_relation->type->representation_L10n,
810
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
811
        )
812
      )
813
    );
814
    // Agent details
815
    $rows[] = array(
816
      'data' => array(
817
        array(
818
          'data' => '<!-- expert_details_container -->',
819
          'id' => $expert_details_container_id,
820
          'colspan' => 2
821
        )
822
      )
823
    );
824

    
825
  }
826

    
827

    
828
  $render_array['experts_table'] = array(
829
    '#theme' => 'table',
830
    '#header' => $header,
831
    '#rows' => $rows,
832
  );
833

    
834

    
835
  return $render_array;
836
}
837

    
838

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

    
861
  if(!isset($tabs)){
862
    $tabs = array();
863
  }
864

    
865
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
866
    $tabs[] = $add_tab;
867
  }
868

    
869
  return $tabs;
870
}
871

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

    
893
  $tabs = &drupal_static('taxon_page_tabs_hidden');
894

    
895
  if(!isset($tabs)){
896
    $tabs = array();
897
  }
898

    
899
  return array_search($tabname, $tabs) !== FALSE;
900
}
901

    
902
/**
903
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
904
 *
905
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
906
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
907
 *
908
 * @param array $variables
909
 *   The variables array
910
 */
911
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
912

    
913
  $hidden_tabs = taxon_page_tabs_hidden_add();
914

    
915
  if (!variable_get(CDM_SEARCH_BLAST_ENABLED)) {
916
      if (is_array($variables['primary'])) {
917
          foreach ($variables['primary'] as $key => &$element) {
918
              if ($element['#link']['path'] == 'cdm_dataportal/search/blast') {
919
                  // remove the tab
920
                  unset($variables['primary'][$key]);
921
              }
922

    
923
          }
924
      }
925
  }
926
  if (is_array($variables['primary'])) {
927
    foreach ($variables['primary'] as $key => &$element) {
928

    
929
      // 1. Remove the tabs to be hidden
930
      foreach ($hidden_tabs as $tab) {
931
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
932
          // remove the tab
933
          unset($variables['primary'][$key]);
934
        }
935
      }
936
    }
937
  }
938
}
939

    
940

    
941

    
942
/**
943
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
944
 *
945
 *
946
 * @param array $variables
947
 *   An associative array containing:
948
 *     - element: A render element containing:
949
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
950
 *          #active: A boolean indicating whether the local task is active.
951
 *
952
 */
953
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
954

    
955
  $link = $variables['element']['#link'];
956
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
957
    $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']) . '"/>';
958
    $link['localized_options']['html'] = TRUE;
959

    
960
    $variables['element']['#link'] = $link;
961
  }
962
}
963

    
964
/* =================== block composition ===================== */
965

    
966
/**
967
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
968
 *
969
 * @param taxon
970
 *
971
 * @return array
972
 *   A Drupal render array for a table with the experts
973
 *
974
 * @ingroup compose
975
 */
976
function compose_classification_breadcrumbs($taxon_uuid) {
977

    
978
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
979

    
980
  $render_array = array();
981

    
982
  $render_array['#theme'] = 'item_list';
983
  $render_array['#type'] = 'ul';
984
  $render_array['#attributes'] = array(
985
    'id' => 'classification-breadcrumbs',
986
    'class' => 'breadcrumbs inline',
987
  );
988

    
989
  $items = array();
990

    
991
  $parent_taxon_nodes = null;
992
  if($taxon_uuid){
993
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
994
  }
995

    
996
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
997
  // find current classification in list
998
  $classification = null;
999
  $current_classification_uuid = get_current_classification_uuid();
1000
  foreach ($classifications as $classification){
1001
    if($classification->uuid == $current_classification_uuid){
1002
      break;
1003
    }
1004
  }
1005

    
1006
  $node_name = '';
1007
  if(count($classifications) > 1 ){
1008
    // need to add the current classification as first label
1009

    
1010
    $label = $classification->titleCache;
1011
    if(strlen($label) > 20){
1012
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1013
    }
1014
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1015
      'attributes' => array(
1016
        'class' => 'taxonomic-children-button classification-chooser',
1017
        'data-destination-uri' => drupal_get_destination(),
1018
        'data-cdm-align-with' => array('prev')
1019
      ),
1020
      'html' => true
1021
    ));
1022
  }
1023

    
1024
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1025

    
1026
  $rank_separator = '<span> '
1027
    . font_awesome_icon_markup('fa-chevron-right')
1028
    . ' </span>';
1029
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1030
  $more_children_label = '...';
1031

    
1032
  $items[] = $node_name;
1033

    
1034
  $more_children_for = null;
1035
  if($parent_taxon_nodes){
1036
    foreach ($parent_taxon_nodes as $node) {
1037

    
1038
      $is_first_item = count($items) == 0;
1039
      $is_last_item = count($items) == count($parent_taxon_nodes);
1040
      $node_name = cdm_dataportal_shortname_of($node);
1041
      $path = path_to_taxon($node->taxonUuid);
1042

    
1043
      if($node->taxonomicChildrenCount > 0) {
1044
        $more_children_for = $node->taxonUuid;
1045
      } else {
1046
        $more_children_for = null;
1047
      }
1048

    
1049
      // 'fa-sitemap'
1050

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

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

    
1086
  }
1087

    
1088
  $render_array['#items'] = $items;
1089

    
1090
  return $render_array;
1091
}
1092

    
1093

    
1094
/**
1095
 * @param $specimen_uuid
1096
 * @return array
1097
 *    The drupal render array for the page
1098
 *
1099
 * @ingroup compose
1100
 */
1101
function compose_cdm_specimen_page($specimen_uuid)
1102
{
1103
  drupal_set_title("Specimen Details");
1104
  RenderHints::pushToRenderStack('specimen_page');
1105

    
1106
  $specimen_table = array(
1107
      '#theme' => 'table',
1108
      '#weight' => 2,
1109
      // prefix attributes and rows with '#' to let it pass to the theme function,
1110
      // otherwise it is handled as child render array
1111

    
1112
    '#attributes' => array('class' => 'specimens'),
1113
      '#rows' => array(),
1114
      '#prefix' => '<div id="specimens">',
1115
      '#suffix' => '</div>',
1116

    
1117

    
1118
  );
1119
  $specimen = compose_cdm_specimen_or_observation($specimen_uuid, true);
1120
  /*
1121
  $render_array = array(
1122
          '#theme' => 'item_list',
1123
          '#items' => array($specimen),
1124
          '#type' => 'ul');
1125
  $output = drupal_render($render_array);
1126
 */
1127
  $specimen_table['#rows'][] = array(
1128
          // An array of table rows. Every row is an array of cells, or an associative array
1129
          'data' => $specimen,
1130
          'class' =>  array(
1131
              'descriptionElement',
1132
              'descriptionElement_IndividualsAssociation'
1133
          ),
1134
  );
1135

    
1136

    
1137
 // $detail_html = compose_cdm_specimen_or_observation($specimen_uuid, true);
1138
//    $render_array['markup'] = array(
1139
//        '#prefix' => '<div id="specimens" class="page">',
1140
//        'content' => $specimen_table,
1141
//        '#suffix' => '</div>',
1142
//    );
1143
  $render_array['specimen_table'] =  $specimen_table;
1144

    
1145
  RenderHints::popFromRenderStack();
1146
  return $specimen; // $render_array;
1147
}
1148

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

    
1159
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1160

    
1161
  $render_array = array();
1162
  RenderHints::pushToRenderStack('named_area_page');
1163

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

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

    
1178
  $render_array[] = $name_area_details_elements;
1179

    
1180
  RenderHints::popFromRenderStack();
1181
  return $render_array;
1182
}
1183

    
1184

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

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

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

    
1242
  $table_rows = array();
1243

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

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

    
1256
  foreach ($field_order as $fieldname) {
1257

    
1258
    if (isset($reference->$fieldname)) {
1259

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

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

    
1326

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

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

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

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

    
1362

    
1363
  // Annotations below the table
1364
  $annotations = cdm_fetch_visible_annotations($reference);
1365
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
1366

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

    
1381
  RenderHints::popFromRenderStack();
1382

    
1383
  return markup_to_render_array($out);
1384
}
1385

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