Project

General

Profile

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

    
19

    
20
/**
21
 * Composes a render array representing the ocurrences associetad with the $taxon.
22
 *
23
 * The resulting render array contains two elements:
24
 *  - 'map': A map showing all point locations of the occurences is availabale
25
 *  - 'specimen_list': the list of occurences prepated as table for theme_table()
26
 *
27
 * @param object $taxon
28
 *   A cdm Taxon object
29
 * @return array
30
 *   A render array suitable for drupal_render()
31
 *
32
 * @ingroup Compose
33
 *
34
 */
35
function compose_cdm_taxon_page_specimens($taxon) {
36

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

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

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

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

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

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

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

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

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

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

    
111
        $render_array['pager'] = markup_to_render_array(
112
            theme('cdm_pager', array(
113
                'pager' => $pager_root_units,
114
                'path' => $_REQUEST['q'],
115
                'parameters' => $_REQUEST
116
            )),
117
            10 // weight
118
        );
119
    }
120
    else if(($current_view_mode == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE)){ // FIXME this seems to be wrong
121
      $derivationTreeComposer = new DerivationTreeComposer($root_unit_dtos);
122
      $derivationTreeComposer->setWithDetails(true);
123
      $render_array['specimen_list'] = $derivationTreeComposer->compose();
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 array $linkList 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
    if(is_array($taxon_nodes)){
288
      $render_array['taxon_node_status'] = compose_taxon_node_status($taxon_nodes);
289
      $render_array['taxon_node_status']['#weight'] = -100;
290
    }
291
  }
292

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

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

    
300
    $merged_tree = merged_taxon_feature_tree($taxon);
301

    
302

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

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

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

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

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

    
343
  }
344

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

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

    
370
  // --- PAGE PART: EXPERTS --- //
371

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

    
380
  // ------------------ END OF PARTS -------------- //
381

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

    
390

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

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

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

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

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

    
445
  }
446

    
447

    
448
  return $render_array;
449
}
450

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

    
478
  $render_array = array();
479

    
480
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
481

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

    
488
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
489

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

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

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

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

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

    
562
  //  $pseudo_feature_block_toc_items = array();
563

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

    
567
  // >>>>>>>>>>>>>>>>>>> PSEUDO FEATURES >>>>>>>>>>>>>>>>>>>
568
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
569

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

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

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

    
599

    
600
  }
601

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

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

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

    
626
  return $render_array;
627
}
628

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

    
648

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

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

    
682
  RenderHints::pushToRenderStack('taxon_page_synonymy');
683

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

    
688
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, array($taxon->uuid));
689

    
690
  $out = '';
691

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

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

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

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

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

    
738

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

    
751
  RenderHints::popFromRenderStack();
752

    
753
  return markup_to_render_array($out);
754
}
755

    
756

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

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

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

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

    
789

    
790
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
791

    
792

    
793
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
794
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
795

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

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

    
834
  }
835

    
836

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

    
843

    
844
  return $render_array;
845
}
846

    
847

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

    
870
  if(!isset($tabs)){
871
    $tabs = array();
872
  }
873

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

    
878
  return $tabs;
879
}
880

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

    
902
  $tabs = &drupal_static('taxon_page_tabs_hidden');
903

    
904
  if(!isset($tabs)){
905
    $tabs = array();
906
  }
907

    
908
  return array_search($tabname, $tabs) !== FALSE;
909
}
910

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

    
922
  $hidden_tabs = taxon_page_tabs_hidden_add();
923

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

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

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

    
949

    
950

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

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

    
969
    $variables['element']['#link'] = $link;
970
  }
971
}
972

    
973
/* =================== block composition ===================== */
974

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

    
987
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
988

    
989
  $render_array = array();
990

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

    
998
  $items = array();
999

    
1000
  $parent_taxon_nodes = null;
1001
  if($taxon_uuid){
1002
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1003
  }
1004

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

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

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

    
1033
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1034

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

    
1041
  $items[] = $node_name;
1042

    
1043
  $more_children_for = null;
1044
  if($parent_taxon_nodes){
1045
    foreach ($parent_taxon_nodes as $node) {
1046

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

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

    
1058
      // 'fa-sitemap'
1059

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

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

    
1095
  }
1096

    
1097
  $render_array['#items'] = $items;
1098

    
1099
  return $render_array;
1100
}
1101

    
1102

    
1103
/**
1104
 *
1105
 * @param $sob_dto
1106
 *   A SpecimenOrObservationDTO
1107
 *
1108
 * @return array
1109
 *    The drupal render array for the page
1110
 *
1111
 * @ingroup compose
1112
 */
1113
function compose_cdm_specimen_page($sob_dto)
1114
{
1115
  drupal_set_title($sob_dto->label);
1116
  RenderHints::pushToRenderStack('specimen_page');
1117
  $render_array = compose_cdm_specimen_or_observation_new($sob_dto);
1118
  RenderHints::popFromRenderStack();
1119
  return $render_array;
1120
}
1121

    
1122
/**
1123
 * @param $named_area_uuid
1124
 * @return array
1125
 *    The drupal render array for the page
1126
 *
1127
 * @ingroup compose
1128
 */
1129
function compose_cdm_named_area_page($named_area_uuid)
1130
{
1131

    
1132
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1133

    
1134
  $render_array = array();
1135
  RenderHints::pushToRenderStack('named_area_page');
1136

    
1137
  $groups = array();
1138
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1139
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1140
  if(isset($named_area->level)) {
1141
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1142
  }
1143

    
1144
  $name_area_details_elements = array(
1145
   // '#title' => $title,
1146
    '#theme' => 'description_list',
1147
    '#groups' => $groups,
1148
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1149
  );
1150

    
1151
  $render_array[] = $name_area_details_elements;
1152

    
1153
  RenderHints::popFromRenderStack();
1154
  return $render_array;
1155
}
1156

    
1157

    
1158
/**
1159
 * Returns a drupal render array for a single reference page.
1160
 *
1161
 * Composes a page with all data on a single reference.
1162
 *
1163
 * @param string $uuid
1164
 *   An uuid for a cdm reference.
1165
 *
1166
 * @return array
1167
 *  A drupal render array
1168
 *
1169
 * @throws Exception
1170
 *
1171
 * @ingroup compose
1172
 */
1173
function compose_cdm_reference_page($uuid) {
1174

    
1175
  $pathelement = "reference_page";
1176
  RenderHints::pushToRenderStack($pathelement);
1177
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1178
  if (!$reference) {
1179
    drupal_set_title(t('Reference does not exist'), PASS_THROUGH);
1180
    return "";
1181
  }
1182
  if (isset($reference->titleCache)) {
1183
    drupal_set_title($reference->titleCache, PASS_THROUGH);
1184
  }
1185

    
1186
  $field_order = array(
1187
    "title",
1188
    "abbrevTitle",
1189
    // "titleCache" abbrevTitleCache
1190
    // "citation",
1191
    "authorship",
1192
    "editor",
1193
    "publisher",
1194
    "placePublished",
1195
    "datePublished",
1196
    "year",
1197
    "edition",// Class Book.
1198
    "volume",// Class Article.
1199
    "seriesPart",
1200
    "inReference",
1201
    "nomRefBase", // Class BookSection, Book, Article.
1202
    "pages",// Class Article.
1203
    "series",// Class Article, PrintSeries.
1204
    "school",// Class Thesis.
1205
    "institution",// Class Report.
1206
    "organization",// Class Proceedings.
1207
    "nextVersion",
1208
    "previousVersion",
1209
    "isbn",// Class Book.
1210
    "issn",// Class Journal.
1211
    "doi",
1212
    "uri"
1213
  );
1214

    
1215
  $table_rows = array();
1216

    
1217
  if (!isset($reference->authorship)) {
1218
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
1219
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
1220
  }
1221

    
1222
  if (!isset($reference->inReference)) {
1223
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
1224
      $reference->uuid,
1225
      "inReference",
1226
    ));
1227
  }
1228

    
1229
  foreach ($field_order as $fieldname) {
1230

    
1231
    if (isset($reference->$fieldname)) {
1232

    
1233
      if ($fieldname == "datePublished") {
1234
        $period = $reference->$fieldname;
1235
        $datePublished = timePeriodToString($period);
1236
        if (isset($datePublished) && $datePublished != '') {
1237
          $table_rows[] = array(
1238
            t("Date published"),
1239
            $datePublished,
1240
          );
1241
        }
1242
      }
1243
      elseif ($fieldname == "doi" && is_object($reference->doi)) {
1244
        $table_rows[] = array(
1245
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1246
          cdm_doi($reference->doi, false)
1247
        );
1248
      }
1249
      elseif ($fieldname == "uri" && isset($reference->uri) && $reference->uri) {
1250
        $table_rows[] = array(
1251
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1252
          cdm_external_uri($reference->uri, false)
1253
        );
1254
      }
1255
      elseif (is_object($reference->$fieldname)) {
1256
        if ($fieldname == "authorship") {
1257
          $dump = $reference->$fieldname;
1258
          $teammembers = "teamMembers";
1259
          $team = $dump->$teammembers;
1260
          $nameArray = array();
1261

    
1262
          foreach ($team as $member) {
1263
            if (strlen($member->lastname) > 0) {
1264
              $nname = $member->lastname;
1265
              $name = $nname;
1266
              if (strlen($member->firstname) > 0) {
1267
                $vname = $member->firstname;
1268
                $name = $vname . " " . $nname;
1269
              }
1270
              $nameArray[] = $name;
1271
            }
1272
            else {
1273
              if (strlen($member->titleCache) > 0) {
1274
                $nameArray[] = $member->titleCache;
1275
              }
1276
            }
1277
          }
1278
          $value = join($nameArray, ", ");
1279
        }
1280
        elseif ($fieldname == "inReference") {
1281
          $type = $reference->$fieldname->type;
1282
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
1283
          switch ($type) {
1284
            case "Book":
1285
              $fieldname = "in book";
1286
              break;
1287
            case "Journal":
1288
              $fieldname = "in journal";
1289
              break;
1290
            case "Proceedings":
1291
              $fieldname = "in proceedings";
1292
              break;
1293
          }
1294
        }
1295
        else {
1296
          $value = $reference->$fieldname->titleCache;
1297
        }
1298

    
1299

    
1300
        if (isset($value) && $value != '') {
1301
          $table_rows[] = array(
1302
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1303
            $value,
1304
          );
1305
        }
1306

    
1307
      }
1308
      else {
1309
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
1310
          $table_rows[] = array(
1311
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1312
            $reference->$fieldname,
1313
          );
1314
        }
1315
      }
1316
    }
1317
  }
1318

    
1319
  $out = theme_table(array(
1320
    'header' => array(),
1321
    'rows' => $table_rows,
1322
    'attributes' => array(
1323
      'class' => html_class_attribute_ref($reference)
1324
    ),
1325
    'caption' => NULL,
1326
    'colgroups' => NULL,
1327
    'sticky' => NULL,
1328
    'empty' => NULL,
1329
  ));
1330

    
1331
  if(isset($reference->referenceAbstract)){
1332
    $out .= '<h2 class="block-title">Abstract</h2><div class="abstract">' . $reference->referenceAbstract . '</div>';
1333
  }
1334

    
1335

    
1336
  // Annotations below the table
1337
  $annotations = cdm_fetch_visible_annotations($reference);
1338
  $out .= cdm_annotations($annotations);
1339

    
1340
  $registration_working_set = cdm_ws_get("registrationWorkingSetDTO", array($uuid));
1341
  if($registration_working_set && count($registration_working_set->registrationDTOs) > 0){
1342
    $out .= "<h3>Nomenclatural acts:</h3><div class=\"cdm-item-list registration-item-list\">";
1343
    foreach($registration_working_set->registrationDTOs as $registration_dto){
1344
      if($registration_dto->status == "PUBLISHED"){
1345
        $registration_render_a = compose_registration_dto_compact($registration_dto, 'citation');
1346
        $registration_render_a["#prefix"] = "<div class=\"item item-registration\">";
1347
        $registration_render_a["#suffix"] = "</div>";
1348
        $out .= drupal_render($registration_render_a);
1349
      }
1350
    }
1351
    $out .= "</div>";
1352
  }
1353

    
1354
  RenderHints::popFromRenderStack();
1355

    
1356
  return markup_to_render_array($out);
1357
}
1358

    
1359
/**
1360
 * Provides the the label string for taxon page tabs.
1361
 *
1362
 * The $tabname as passed to the method will be returned if no override
1363
 * label is configured in the settings.
1364
 *
1365
 * @param $tabname
1366
 *
1367
 * @return mixed
1368
 */
1369
function cdm_taxonpage_tab_label($tabname) {
1370
  static $taxon_tabs_labels = null;
1371
  if($taxon_tabs_labels == null){
1372
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1373
  }
1374
  $tabname_key = strtolower($tabname);
1375
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1376
    return $taxon_tabs_labels[$tabname_key];
1377
  }
1378
  return $tabname;
1379
}
1380

    
1381
/**
1382
 *  Returns HTML for the default title of a specimen page.
1383
 *  The returned title is a the identifier of the specimen.
1384
 *
1385
 * @param object $sob_dto
1386
 *  A SpecimenOrObservationDTO to create a tile string for.
1387
 *
1388
 * @return string
1389
 *  Markup for the title of a specimen page
1390
 */
1391
function render_specimen_page_title($sob_dto)
1392
{
1393
  RenderHints::pushToRenderStack('render_specimen_page_title');
1394
  $out = '';
1395
  if ($sob_dto->type == 'FieldUnit'){
1396
    $out .= '<span class="type-label">Field unit: </span>';
1397
  }else{
1398
    $out .= '<span class="type-label">Specimen:  </span>';
1399
    $out .= $sob_dto->specimenIdentifier;
1400
  }
1401
  RenderHints::popFromRenderStack();
1402

    
1403
  return '<span class="' . html_class_attribute_ref($sob_dto) . '">' . $out . '</span>';
1404
}
1405

    
1406
/**
1407
 * Returns HTML for the default title of a specimen page.
1408
 * The returned title is a the identifier of the specimen.
1409
 *
1410
 * @param object $occurrence_dto
1411
 *   An dto for a cdm SpecimenOrObservation entity
1412
 *
1413
 * @return string
1414
 *  Markup for the title of a specimen page
1415
 *
1416
 */
1417
function render_cdm_specimen_dto_page_title($occurrence_dto)
1418
{
1419
  RenderHints::pushToRenderStack('render_specimen_page_title');
1420
  $out = '';
1421
  list($specimenID, $collection) = specimen_id_and_collection_for($occurrence_dto);
1422
  if ($occurrence_dto->class == 'FieldUnit'){
1423
    $out .= "FieldUnit ";
1424
  }else{
1425
    $out .= "Specimen ";
1426
  }
1427
  if($collection){
1428
    $out .= $collection." ";
1429
  }
1430
  $out .= $specimenID;
1431

    
1432
  RenderHints::popFromRenderStack();
1433
  return '<span class="' . $occurrence_dto->class . '">' . $out . '</span>';
1434
}
1435

    
(10-10/15)