Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / pages.inc @ 46a93d1e

History | View | Annotate | Download (48.3 KB)

1
<?php
2
/**
3
 * @file
4
 * Page functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * 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 = array();
42
    if (variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_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
      if (isset($pager->records[0])) {
60
        $specimensOrObservations = $pager->records;
61
      }
62
      // cdm_ws_get(CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON,
63
      // null,
64
      // $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
65
      // );
66

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

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

    
90
    // -------------------------------------------------------
91

    
92
    if((variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE)){
93

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

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

    
110
          $render_array['derivate_hierarchy_table'] = compose_compressed_specimen_derivate_table($field_unit_uuids);
111
        }
112

    
113
        $render_array['pager'] = markup_to_render_array(
114
            theme('cdm_pager', array(
115
                'pager' => $pager_field_units,
116
                'path' => $_REQUEST['q'],
117
                'parameters' => $_REQUEST
118
            )),
119
            10 // weight
120
        );
121
    }
122
    else if((variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE)){ // FIXME this seems to be wrong
123
      $render_array['specimen_list'] = compose_specimen_table_top_down($fieldUnitDTOs);
124
      $render_array['specimen_list']['#weight'] = 2;
125
    } else {
126
      $specimen_table = compose_specimens_table_bottom_up($specimensOrObservations);
127

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

    
139
    RenderHints::popFromRenderStack();
140
    return $render_array;
141
}
142

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

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

    
161

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

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

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

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

    
221
  // add all mandatory js sources
222
  _add_js_footnotes();
223

    
224

    
225
  $render_array = array();
226
  $weight = 0; // the weight for the render array elements
227

    
228
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
229

    
230
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
231

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

    
241
  $media = _load_media_for_taxon($taxon);
242

    
243

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

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

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

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

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

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

    
283
  // -------------------------------------------- //
284

    
285
  if(variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1) && ( $page_part == 'description' || $page_part == 'synonymy' || $page_part == 'all')){
286
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, array($taxon->uuid));
287
    $render_array['taxon_node_status'] = compose_taxon_node_status($taxon_nodes);
288
    $render_array['taxon_node_status']['#weight'] = -100;
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
          $representationPart->width = $image_info['width'];
526
          $representationPart->height = $image_info['height'];
527
          $representationPart->uri = $url;
528
        }
529
        else {
530
          // use the hard coded default
531
          $representationPart->width = 184;
532
          $representationPart->height = 144;
533
          $representationPart->uri = base_path() . drupal_get_path('module',
534
              'cdm_dataportal') . '/images/no_picture.png';
535
        }
536
        $attributes['alt'] = "no image available";
537
      }
538
    }
539

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

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

    
557
  //  $pseudo_feature_block_toc_items = array();
558

    
559
  // Render the sections for each real feature
560
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
561

    
562
  // >>>>>>>>>>>>>>>>>>> PSEUDO FEATURES >>>>>>>>>>>>>>>>>>>
563
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
564

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

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

    
591
      $feature_block_list[$pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]] = $description_block;
592
      cdm_toc_list_add_item('Descriptions (aggregated)', 'aggregation_descriptions', null, false, $pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]);
593

    
594

    
595
  }
596

    
597
  // sort by weight
598
  ksort($feature_block_list);
599
  $render_array['taxon_description_features'] = _block_get_renderable_array($feature_block_list);
600

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

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

    
621
  return $render_array;
622
}
623

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

    
643

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

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

    
677
  RenderHints::pushToRenderStack('taxon_page_synonymy');
678

    
679
  // footnote key for the homotypic group and accepted taxon,
680
  // both should have the same footnote key
681
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
682

    
683
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, array($taxon->uuid));
684

    
685
  $out = '';
686

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

    
706
    $accepted_name .= '<div class="accepted-name">';
707
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
708

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

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

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

    
734

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

    
747
  RenderHints::popFromRenderStack();
748

    
749
  return markup_to_render_array($out);
750
}
751

    
752
/**
753
 * Provides the default configuration for handle_annotations_and_sources() in the
754
 * synonymy.
755
 *
756
 * @return bool[]
757
 */
758
function synonymy_annotations_and_source_config() {
759
  static $annotations_and_sources_config = null;
760
  if(!$annotations_and_sources_config){
761
    $bibliography_settings = get_bibliography_settings();
762
    $annotations_and_sources_config = [
763
      'sources_as_content' => FALSE,
764
      'link_to_name_used_in_source' => TRUE,
765
      'link_to_reference' => TRUE,
766
      'add_footnote_keys' => TRUE,
767
      'bibliography_aware' => $bibliography_settings['enabled'] == 1
768
    ];
769
  }
770
  return $annotations_and_sources_config;
771
}
772

    
773

    
774
/**
775
 * composes and returns an render array for the experts associated with the given taxon
776
 *
777
 * @param object taxon
778
 *
779
 * @return array
780
 *   A Drupal render array for a table with the experts
781
 *
782
 * @ingroup compose
783
 */
784
function compose_cdm_taxon_page_experts($taxon){
785

    
786
  $render_array = array();
787
  if(!isset($taxon->uuid)){
788
    return $render_array;
789
  }
790

    
791
  $current_classification_uuid = get_current_classification_uuid();
792
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
793
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
794
    array(
795
      $taxon->uuid,
796
      $current_classification_uuid
797
    )
798
  );
799

    
800
  $header = array(
801
    array('data' => t('Expert')),
802
    array('data' => t('Role'))
803
  );
804
  $rows = array();
805

    
806

    
807
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
808

    
809

    
810
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
811
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
812

    
813
    $agent_label_markup = cdm_dynabox(
814
      'expert_' . $expert_role_id,
815
      $taxon_node_agent_relation->agent->titleCache,
816
      // specifying both ends of the relationship will return only one record in the pager
817
      cdm_compose_ws_url(CDM_WS_PORTAL_AGENT,
818
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
819
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
820
      'cdm_taxon_expert',
821
      'Click for details',
822
      array('div', 'div'),
823
      array(), // attributes
824
      '#' . $expert_details_container_id // $content_element_selector
825
    );
826

    
827
    // Expert and Role
828
    $rows[] = array(
829
      'data' => array(
830
        array(
831
          'data' => $agent_label_markup,
832
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
833
        ),
834
        array(
835
          'data' => $taxon_node_agent_relation->type->representation_L10n,
836
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
837
        )
838
      )
839
    );
840
    // Agent details
841
    $rows[] = array(
842
      'data' => array(
843
        array(
844
          'data' => '<!-- expert_details_container -->',
845
          'id' => $expert_details_container_id,
846
          'colspan' => 2
847
        )
848
      )
849
    );
850

    
851
  }
852

    
853

    
854
  $render_array['experts_table'] = array(
855
    '#theme' => 'table',
856
    '#header' => $header,
857
    '#rows' => $rows,
858
  );
859

    
860

    
861
  return $render_array;
862
}
863

    
864

    
865
/**
866
 * Manages the tabs to be hidden in the taxon page.
867
 *
868
 * The tabs are identified by their last menu link path element:
869
 *  - description
870
 *  - synonymy
871
 *  - images
872
 *  - specimens
873
 *  - key
874
 *
875
 * Internally the tabs are stored in a static variable which is
876
 * managed by drupal_static().
877
 *
878
 * @param string $add_tab
879
 *   Optional parameter. The given string will be added to the array of tabs
880
 *
881
 * @return
882
 *   The array of tabs
883
 */
884
function taxon_page_tabs_hidden_add($add_tab = NULL) {
885
  $tabs = &drupal_static('taxon_page_tabs_hidden');
886

    
887
  if(!isset($tabs)){
888
    $tabs = array();
889
  }
890

    
891
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
892
    $tabs[] = $add_tab;
893
  }
894

    
895
  return $tabs;
896
}
897

    
898
/**
899
 * Manages the tabs to be hidden in the taxon page.
900
 *
901
 * The tabs names are identified by their last menu link path element:
902
 *  - description
903
 *  - synonymy
904
 *  - images
905
 *  - specimens
906
 *  - key
907
 *
908
 * Internally the tabs are stored in a static variable which is
909
 * managed by drupal_static().
910
 *
911
 * @param string $tabname
912
 *   The name of the tab to check
913
 *
914
 * @return boolean
915
 *   True if the tab or section is to be hidden
916
 */
917
function taxon_page_tabs_hidden_check($tabname) {
918

    
919
  $tabs = &drupal_static('taxon_page_tabs_hidden');
920

    
921
  if(!isset($tabs)){
922
    $tabs = array();
923
  }
924

    
925
  return array_search($tabname, $tabs) !== FALSE;
926
}
927

    
928
/**
929
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
930
 *
931
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
932
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
933
 *
934
 * @param array $variables
935
 *   The variables array
936
 */
937
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
938

    
939
  $hidden_tabs = taxon_page_tabs_hidden_add();
940

    
941
  if (!variable_get(CDM_SEARCH_BLAST_ENABLED)) {
942
      if (is_array($variables['primary'])) {
943
          foreach ($variables['primary'] as $key => &$element) {
944
              if ($element['#link']['path'] == 'cdm_dataportal/search/blast') {
945
                  // remove the tab
946
                  unset($variables['primary'][$key]);
947
              }
948

    
949
          }
950
      }
951
  }
952
  if (is_array($variables['primary'])) {
953
    foreach ($variables['primary'] as $key => &$element) {
954

    
955
      // 1. Remove the tabs to be hidden
956
      foreach ($hidden_tabs as $tab) {
957
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
958
          // remove the tab
959
          unset($variables['primary'][$key]);
960
        }
961
      }
962
    }
963
  }
964
}
965

    
966

    
967

    
968
/**
969
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
970
 *
971
 *
972
 * @param array $variables
973
 *   An associative array containing:
974
 *     - element: A render element containing:
975
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
976
 *          #active: A boolean indicating whether the local task is active.
977
 *
978
 */
979
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
980

    
981
  $link = $variables['element']['#link'];
982
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
983
    $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']) . '"/>';
984
    $link['localized_options']['html'] = TRUE;
985

    
986
    $variables['element']['#link'] = $link;
987
  }
988
}
989

    
990
/* =================== block composition ===================== */
991

    
992
/**
993
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
994
 *
995
 * @param taxon
996
 *
997
 * @return array
998
 *   A Drupal render array for a table with the experts
999
 *
1000
 * @ingroup compose
1001
 */
1002
function compose_classification_breadcrumbs($taxon_uuid) {
1003

    
1004
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1005

    
1006
  $render_array = array();
1007

    
1008
  $render_array['#theme'] = 'item_list';
1009
  $render_array['#type'] = 'ul';
1010
  $render_array['#attributes'] = array(
1011
    'id' => 'classification-breadcrumbs',
1012
    'class' => 'breadcrumbs inline',
1013
  );
1014

    
1015
  $items = array();
1016

    
1017
  $parent_taxon_nodes = null;
1018
  if($taxon_uuid){
1019
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1020
  }
1021

    
1022
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1023
  // find current classification in list
1024
  $classification = null;
1025
  $current_classification_uuid = get_current_classification_uuid();
1026
  foreach ($classifications as $classification){
1027
    if($classification->uuid == $current_classification_uuid){
1028
      break;
1029
    }
1030
  }
1031

    
1032
  $node_name = '';
1033
  if(count($classifications) > 1 ){
1034
    // need to add the current classification as first label
1035

    
1036
    $label = $classification->titleCache;
1037
    if(strlen($label) > 20){
1038
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1039
    }
1040
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1041
      'attributes' => array(
1042
        'class' => 'taxonomic-children-button classification-chooser',
1043
        'data-destination-uri' => drupal_get_destination(),
1044
        'data-cdm-align-with' => array('prev')
1045
      ),
1046
      'html' => true
1047
    ));
1048
  }
1049

    
1050
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1051

    
1052
  $rank_separator = '<span> '
1053
    . font_awesome_icon_markup('fa-chevron-right')
1054
    . ' </span>';
1055
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1056
  $more_children_label = '...';
1057

    
1058
  $items[] = $node_name;
1059

    
1060
  $more_children_for = null;
1061
  if($parent_taxon_nodes){
1062
    foreach ($parent_taxon_nodes as $node) {
1063

    
1064
      $is_first_item = count($items) == 0;
1065
      $is_last_item = count($items) == count($parent_taxon_nodes);
1066
      $node_name = cdm_dataportal_shortname_of($node);
1067
      $path = path_to_taxon($node->taxonUuid);
1068

    
1069
      if($node->taxonomicChildrenCount > 0) {
1070
        $more_children_for = $node->taxonUuid;
1071
      } else {
1072
        $more_children_for = null;
1073
      }
1074

    
1075
      // 'fa-sitemap'
1076

    
1077
      $items[] =
1078
        ($is_first_item ? '' : ' ')
1079
        . $rank_separator
1080
        . l(
1081
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1082
          $path,
1083
          array(
1084
            'attributes' => array(
1085
              'class' => array('taxonomic-children-button'),
1086
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1087
              'data-cdm-classification-mode' => array('siblings'),
1088
              'data-cdm-align-with' => array('prev')
1089
            ),
1090
            'html' => true
1091
          )
1092
        );
1093
      }
1094
    }
1095

    
1096
  // add more button to the end
1097
  if(!$parent_taxon_nodes) {
1098
    // not taxon focused yet, adding button to make  the root nodes available
1099
    $items[] = '<span>'
1100
      . $more_children_icon . '&nbsp;' .
1101
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1102
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1103
      . '</span>';
1104
  } else if($more_children_for){
1105
    // last parent item has child taxon nodes
1106
    $items[] = ' <span>'
1107
      . $more_children_icon . '&nbsp;' .
1108
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1109
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1110
      . '</span>';
1111

    
1112
  }
1113

    
1114
  $render_array['#items'] = $items;
1115

    
1116
  return $render_array;
1117
}
1118

    
1119

    
1120
/**
1121
 * @param $specimen_uuid
1122
 * @return array
1123
 *    The drupal render array for the page
1124
 *
1125
 * @ingroup compose
1126
 */
1127
function compose_cdm_specimen_page($specimen_uuid)
1128
{
1129
  drupal_set_title("Specimen Details");
1130
  RenderHints::pushToRenderStack('specimen_page');
1131

    
1132
  $specimen_table = array(
1133
      '#theme' => 'table',
1134
      '#weight' => 2,
1135
      // prefix attributes and rows with '#' to let it pass to the theme function,
1136
      // otherwise it is handled as child render array
1137

    
1138
    '#attributes' => array('class' => 'specimens'),
1139
      '#rows' => array(),
1140
      '#prefix' => '<div id="specimens">',
1141
      '#suffix' => '</div>',
1142

    
1143

    
1144
  );
1145
  $specimen = compose_cdm_specimen_or_observation($specimen_uuid, true);
1146
  /*
1147
  $render_array = array(
1148
          '#theme' => 'item_list',
1149
          '#items' => array($specimen),
1150
          '#type' => 'ul');
1151
  $output = drupal_render($render_array);
1152
 */
1153
  $specimen_table['#rows'][] = array(
1154
          // An array of table rows. Every row is an array of cells, or an associative array
1155
          'data' => $specimen,
1156
          'class' =>  array(
1157
              'descriptionElement',
1158
              'descriptionElement_IndividualsAssociation'
1159
          ),
1160
  );
1161

    
1162

    
1163
 // $detail_html = compose_cdm_specimen_or_observation($specimen_uuid, true);
1164
//    $render_array['markup'] = array(
1165
//        '#prefix' => '<div id="specimens" class="page">',
1166
//        'content' => $specimen_table,
1167
//        '#suffix' => '</div>',
1168
//    );
1169
  $render_array['specimen_table'] =  $specimen_table;
1170

    
1171
  RenderHints::popFromRenderStack();
1172
  return $specimen; // $render_array;
1173
}
1174

    
1175
/**
1176
 * @param $named_area_uuid
1177
 * @return array
1178
 *    The drupal render array for the page
1179
 *
1180
 * @ingroup compose
1181
 */
1182
function compose_cdm_named_area_page($named_area_uuid)
1183
{
1184

    
1185
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1186

    
1187
  $render_array = array();
1188
  RenderHints::pushToRenderStack('named_area_page');
1189

    
1190
  $groups = array();
1191
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1192
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1193
  if(isset($named_area->level)) {
1194
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1195
  }
1196

    
1197
  $name_area_details_elements = array(
1198
   // '#title' => $title,
1199
    '#theme' => 'description_list',
1200
    '#groups' => $groups,
1201
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1202
  );
1203

    
1204
  $render_array[] = $name_area_details_elements;
1205

    
1206
  RenderHints::popFromRenderStack();
1207
  return $render_array;
1208
}
1209

    
1210

    
1211
/**
1212
 * Returns a drupal render array for a single reference page.
1213
 *
1214
 * Composes a page with all data on a single reference.
1215
 *
1216
 * @param string $uuid
1217
 *   An uuid for a cdm reference.
1218
 *
1219
 * @return array
1220
 *  A drupal render array
1221
 *
1222
 * @throws Exception
1223
 *
1224
 * @ingroup compose
1225
 */
1226
function compose_cdm_reference_page($uuid) {
1227

    
1228
  $pathelement = "reference_page";
1229
  RenderHints::pushToRenderStack($pathelement);
1230
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1231
  if (!$reference) {
1232
    drupal_set_title(t('Reference does not exist'), PASS_THROUGH);
1233
    return "";
1234
  }
1235
  if (isset($reference->titleCache)) {
1236
    drupal_set_title($reference->titleCache, PASS_THROUGH);
1237
  }
1238

    
1239
  $field_order = array(
1240
    "title",
1241
    "abbrevTitle",
1242
    // "titleCache" abbrevTitleCache
1243
    // "citation",
1244
    "authorship",
1245
    "editor",
1246
    "publisher",
1247
    "placePublished",
1248
    "datePublished",
1249
    "year",
1250
    "edition",// Class Book.
1251
    "volume",// Class Article.
1252
    "seriesPart",
1253
    "inReference",
1254
    "nomRefBase", // Class BookSection, Book, Article.
1255
    "pages",// Class Article.
1256
    "series",// Class Article, PrintSeries.
1257
    "school",// Class Thesis.
1258
    "institution",// Class Report.
1259
    "organization",// Class Proceedings.
1260
    "nextVersion",
1261
    "previousVersion",
1262
    "isbn",// Class Book.
1263
    "issn",// Class Journal.
1264
    "doi",
1265
    "uri"
1266
  );
1267

    
1268
  $table_rows = array();
1269

    
1270
  if (!isset($reference->authorship)) {
1271
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
1272
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
1273
  }
1274

    
1275
  if (!isset($reference->inReference)) {
1276
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
1277
      $reference->uuid,
1278
      "inReference",
1279
    ));
1280
  }
1281

    
1282
  foreach ($field_order as $fieldname) {
1283

    
1284
    if (isset($reference->$fieldname)) {
1285

    
1286
      if ($fieldname == "datePublished") {
1287
        $period = $reference->$fieldname;
1288
        $datePublished = timePeriodToString($period);
1289
        if (isset($datePublished) && $datePublished != '') {
1290
          $table_rows[] = array(
1291
            t("Date published"),
1292
            $datePublished,
1293
          );
1294
        }
1295
      }
1296
      elseif ($fieldname == "doi" && is_object($reference->doi)) {
1297
        $table_rows[] = array(
1298
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1299
          cdm_doi($reference->doi, false)
1300
        );
1301
      }
1302
      elseif ($fieldname == "uri" && isset($reference->uri) && $reference->uri) {
1303
        $table_rows[] = array(
1304
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1305
          cdm_external_uri($reference->uri, false)
1306
        );
1307
      }
1308
      elseif (is_object($reference->$fieldname)) {
1309
        if ($fieldname == "authorship") {
1310
          $dump = $reference->$fieldname;
1311
          $teammembers = "teamMembers";
1312
          $team = $dump->$teammembers;
1313
          $nameArray = array();
1314

    
1315
          foreach ($team as $member) {
1316
            if (strlen($member->lastname) > 0) {
1317
              $nname = $member->lastname;
1318
              $name = $nname;
1319
              if (strlen($member->firstname) > 0) {
1320
                $vname = $member->firstname;
1321
                $name = $vname . " " . $nname;
1322
              }
1323
              $nameArray[] = $name;
1324
            }
1325
            else {
1326
              if (strlen($member->titleCache) > 0) {
1327
                $nameArray[] = $member->titleCache;
1328
              }
1329
            }
1330
          }
1331
          $value = join($nameArray, ", ");
1332
        }
1333
        elseif ($fieldname == "inReference") {
1334
          $type = $reference->$fieldname->type;
1335
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
1336
          switch ($type) {
1337
            case "Book":
1338
              $fieldname = "in book";
1339
              break;
1340
            case "Journal":
1341
              $fieldname = "in journal";
1342
              break;
1343
            case "Proceedings":
1344
              $fieldname = "in proceedings";
1345
              break;
1346
          }
1347
        }
1348
        else {
1349
          $value = $reference->$fieldname->titleCache;
1350
        }
1351

    
1352

    
1353
        if (isset($value) && $value != '') {
1354
          $table_rows[] = array(
1355
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1356
            $value,
1357
          );
1358
        }
1359

    
1360
      }
1361
      else {
1362
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
1363
          $table_rows[] = array(
1364
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1365
            $reference->$fieldname,
1366
          );
1367
        }
1368
      }
1369
    }
1370
  }
1371

    
1372
  $out = theme_table(array(
1373
    'header' => array(),
1374
    'rows' => $table_rows,
1375
    'attributes' => array(
1376
      'class' => html_class_attribute_ref($reference)
1377
    ),
1378
    'caption' => NULL,
1379
    'colgroups' => NULL,
1380
    'sticky' => NULL,
1381
    'empty' => NULL,
1382
  ));
1383

    
1384
  if(isset($reference->referenceAbstract)){
1385
    $out .= '<h2 class="block-title">Abstract</h2><div class="abstract">' . $reference->referenceAbstract . '</div>';
1386
  }
1387

    
1388

    
1389
  // Annotations below the table
1390
  $annotations = cdm_fetch_visible_annotations($reference);
1391
  $out .= cdm_annotations($annotations);
1392

    
1393
  $registration_working_set = cdm_ws_get("registrationWorkingSetDTO", array($uuid));
1394
  if($registration_working_set && count($registration_working_set->registrationDTOs) > 0){
1395
    $out .= "<h3>Nomenclatural acts:</h3><div class=\"cdm-item-list registration-item-list\">";
1396
    foreach($registration_working_set->registrationDTOs as $registration_dto){
1397
      if($registration_dto->status == "PUBLISHED"){
1398
        $registration_render_a = compose_registration_dto_compact($registration_dto, 'citation');
1399
        $registration_render_a["#prefix"] = "<div class=\"item item-registration\">";
1400
        $registration_render_a["#suffix"] = "</div>";
1401
        $out .= drupal_render($registration_render_a);
1402
      }
1403
    }
1404
    $out .= "</div>";
1405
  }
1406

    
1407
  RenderHints::popFromRenderStack();
1408

    
1409
  return markup_to_render_array($out);
1410
}
1411

    
1412
/**
1413
 * Provides the the label string for taxon page tabs.
1414
 *
1415
 * The $tabname as passed to the method will be returned if no override
1416
 * label is configured in the settings.
1417
 */
1418
function cdm_taxonpage_tab_label($tabname) {
1419
  static $taxon_tabs_labels = null;
1420
  if($taxon_tabs_labels == null){
1421
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1422
  }
1423
  $tabname_key = strtolower($tabname);
1424
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1425
    return $taxon_tabs_labels[$tabname_key];
1426
  }
1427
  return $tabname;
1428
}
Add picture from clipboard (Maximum size: 40 MB)