Project

General

Profile

Download (23.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities from the package model.common
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
 * @defgroup compose Compose functions
21
 * @{
22
 * Functions which are composing Drupal render arays
23
 *
24
 * The cdm_dataportal module needs to compose rather complex render arrays from
25
 * the data returned by the CDM REST service. The compose functions are
26
 * responsible for creating the render arrays.
27
 *
28
 * All these functions are also implementations of the compose_hook()
29
 * which is used in the proxy_content() function.
30
 * @}
31
 */
32

    
33
/**
34
 * Compose an render array from a CDM Marker object.
35
 *
36
 * compose_hook() implementation
37
 *
38
 * @param object $marker
39
 *   CDM instance of type Marker
40
 * @return array
41
 *   A drupal render array
42
 *
43
 * @ingroup compose
44
 */
45
function compose_cdm_marker($marker) {
46

    
47
  $render_array = array(
48
      // ---- generic
49
      //  these entries should be common to all cdm enitiy render arrays
50
      '#theme' => 'cdm_marker', // TODO   add alternative theme funcitons: 'cdm_marker_' . marker.type.label
51
      '#attributes' => array('class' => html_class_attribute_ref($marker)),
52

    
53
      // ---- individual
54
      '#label' => $marker->markerType->representation_L10n . ': ' . (($marker->flag !== TRUE ? t('yes') : t('no'))),
55
  );
56

    
57
  return $render_array;
58
}
59

    
60
/**
61
 * Checks if the given $cdm_entitiy has a marker the type references by the
62
 * $marker_type_uuid and returns TRUE if a matching marker has been found.
63
 *
64
 * @param object $cdm_entitiy A CDM Entity
65
 * @param string $marker_type_uuid
66
 */
67
function cdm_entity_has_marker($cdm_entitiy, $marker_type_uuid) {
68
  if(isset($cdm_entitiy->markers[0]) && !is_uuid($marker_type_uuid)){
69
    foreach ($cdm_entitiy->markers as $marker) {
70
      if(isset($marker->markerType) && $marker->markerType->uuid == $marker_type_uuid){
71
        return TRUE;
72
      }
73
    }
74
  }
75
  return FALSE;
76
}
77

    
78
/**
79
 * Sorts an array of CDM IdentifiableSource instances by 1. by the
80
 * author teams family names and 2. by the publication date.
81
 *
82
 * @param array $sources
83
 *    The array of CDM IdentifiableSource instances
84
 * @return array
85
 *  An array of drupal render arrays
86
 */
87
function oder_and_render_original_sources($sources){
88
    $sort_array = array();
89
    foreach ($sources as $source) {
90

    
91
      $order_key = '';
92

    
93
      // find the familynames
94
      if(isset($source->citation->uuid) && !isset($source->citation->authorship)){
95
        $authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $source->citation->uuid);
96

    
97
        $persons = array();
98
        if($authorteam->class == 'Team'){
99
          if(isset($authorteam->teamMembers)){
100
            $persons = $authorteam->teamMembers;
101
          }
102
        } else {
103
          $persons[] = $authorteam;
104
        }
105

    
106
        foreach($persons as $person){
107
          if(!empty($person->lastname)){
108
            $order_key .= $person->lastname;
109
          } else {
110
            $order_key .= $person->titleCache;
111
          }
112
        }
113
        if(empty($order_key)){
114
          $order_key = $authorteam->titleCache;
115
        }
116

    
117
      }
118
      $order_key = str_pad($order_key, 50);
119

    
120
      // add publication date to the key
121
      if(isset($source->citation->datePublished)){
122
        $order_key .= '_' . timePeriodAsOrderKey($source->citation->datePublished);
123
      } else {
124
        $order_key .= '_' . "0000";
125
      }
126

    
127
      // padd key until unique
128
      while(array_key_exists($order_key, $sort_array)){
129
        $order_key .= "_";
130
      }
131

    
132
      $sort_array[$order_key] = render_original_source($source);
133
    }
134
    ksort($sort_array);
135
    return array_values ($sort_array);
136
}
137

    
138
/**
139
 * Compare callback to be used in usort to sort image sources of CDM OriginalSource instances.
140
 *
141
 * TODO the compare strategy implemented in oder_and_render_original_sources() is probably better but is not taking the
142
 * originalName into account.
143
 *
144
 * @param $a
145
 * @param $b
146
 */
147
function compare_original_sources($a, $b){
148

    
149
  $a_string = '';
150
  if(isset($a->citation->titleCache)) {
151
    $a_string = $a->citation->titleCache;
152
  }
153
  if((isset($a->nameUsedInSource))){
154
    $a_string .= $a->nameUsedInSource->titleCache;
155
  } elseif (isset($a->originalNameString)){
156
    $a_string .= $a->originalNameString;
157
  }
158

    
159
  $b_string = '';
160
  if(isset($b->citation->titleCache)) {
161
    $b_string = $b->citation->titleCache;
162
  };
163
  if((isset($b->nameUsedInSource))){
164
    $b_string .= $b->nameUsedInSource->titleCache;
165
  } elseif (isset($b->originalNameString)){
166
    $b_string .= $b->originalNameString;
167
  }
168

    
169
  if ($a_string == $b_string) {
170
    return 0;
171
  }
172
  return ($a_string < $b_string) ? -1 : 1;
173
}
174

    
175
/**
176
 * Compare callback to be used in usort to sort image sources of CDM Media instances.
177
 *
178
 * @param $a
179
 * @param $b
180
 */
181
function compare_text_data($a, $b) {
182

    
183
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
184
    return 0;
185
  }
186
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
187
}
188

    
189
  /**
190
   * Compare two different footnotes objects.
191
   *
192
   * The comparison is based on the footnote key. The one which is
193
   * displayed as footnote number.
194
   *
195
   * @param mixed $a
196
   *   Footnote object $a.
197
   * @param mixed $b
198
   *   Footnote object $b.
199
   */
200
  function footnotes_key_compare($a, $b) {
201
    $res = 0;
202
    if (empty($a) || empty($b)) {
203
      return $res;
204
    }
205
    if ($a->keyStr < $b->keyStr) {
206
      $res = -1;
207
    }
208
    elseif ($a->keyStr > $b->keyStr) {
209
      $res = 1;
210
    }
211
    return $res;
212
  }
213

    
214
/**
215
 * Provides an explanatory text on the statistical values representation as generated by statistical_values()
216
 *
217
 * @return string
218
 *     the text
219
 */
220
  function statistical_values_explanation(){
221
    return t("A single or the first number in square brackets denotes sample size");
222
  }
223

    
224
/**
225
 * Creates an array suitable to be used in statistical_values()
226
 * The min max structure is suitable for being used in the context
227
 * of GatheringEvents and StatisticalMeasures (see render_quantitative_statistics()).
228
 *
229
 * The order of the items is important for the display and must not be changed.
230
 *
231
 * @return array
232
 */
233
function statistical_values_array() {
234

    
235
  $min_max = [
236
    'Min' => NULL,
237
    'TypicalLowerBoundary' => NULL,
238
    'TypicalUpperBoundary' => NULL,
239
    'Max' => NULL,
240
    'SampleSize' => NULL,
241
    'Average' => NULL,
242
    'Variance' => NULL,
243
    'StandardDeviation' => NULL,
244
  ];
245
  return $min_max;
246
}
247

    
248
/**
249
 * Creates markup from a min max array.
250
 *
251
 * NOTE: use  statistical_values_array() to create an appropriate array
252
 *
253
 * Internally Min will be translated to TypicalLowerBoundary if no such value is present.
254
 * The same also accounts for Max and TypicalUpperBoundary.
255
 *
256
 * For further details see #3742, #8766
257
 *
258
 * @param $stat_vals_arr
259
 *  the statistical values array as produced by statistical_values_array()
260
 * @param $unit
261
 *  Defaults to no unit
262
 * @return string
263
 */
264
function statistical_values($stat_vals_arr, $unit = '') {
265

    
266
  static $xbar_equals = 'x&#x304='; // x&#x304 is x-bar
267

    
268
  $min_max_markup = '';
269
  $other_vals_array = [];
270

    
271
  // --- sanitize values
272
  if(statistical_values_equals($stat_vals_arr, 'Min', 'TypicalLowerBoundary')){
273
    $stat_vals_arr['Min'] = NULL;
274
  }
275

    
276
  if(statistical_values_equals($stat_vals_arr, 'Max', 'TypicalUpperBoundary')){
277
    $stat_vals_arr['Max'] = NULL;
278
  }
279

    
280
  if($stat_vals_arr['TypicalLowerBoundary'] === null && $stat_vals_arr['Min'] !== null){
281
    $stat_vals_arr['TypicalLowerBoundary'] = $stat_vals_arr['Min'];
282
    $stat_vals_arr['Min'] = NULL;
283
  }
284

    
285
  if($stat_vals_arr['TypicalUpperBoundary'] === null && $stat_vals_arr['Max']  !== null){
286
    $stat_vals_arr['TypicalUpperBoundary'] = $stat_vals_arr['Max'];
287
    $stat_vals_arr['Max'] = NULL;
288
  }
289

    
290
  if (statistical_values_equals($stat_vals_arr, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
291
    $stat_vals_arr['Average'] = $stat_vals_arr['TypicalUpperBoundary'];
292
    $stat_vals_arr['TypicalLowerBoundary'] = NULL;
293
    $stat_vals_arr['TypicalUpperBoundary'] = NULL;
294
  }
295

    
296
  // --- check for inconsistent cases, eg. only Max and average given
297
  if ($stat_vals_arr['TypicalLowerBoundary'] === NULL && $stat_vals_arr['TypicalUpperBoundary']  !== null) {
298
    // min missing
299
    $stat_vals_arr['TypicalLowerBoundary'] = '?';
300
  }
301
  if ($stat_vals_arr['TypicalLowerBoundary'] !== null && $stat_vals_arr['TypicalUpperBoundary'] === NULL) {
302
    // max missing
303
    $stat_vals_arr['TypicalUpperBoundary'] = '?';
304
  }
305

    
306
  if($stat_vals_arr['Average'] && $stat_vals_arr['TypicalUpperBoundary'] !== null && $stat_vals_arr['TypicalLowerBoundary'] !== null) {
307
    statistical_values_adjust_significant_figures($stat_vals_arr['Average'], $stat_vals_arr['TypicalLowerBoundary'], $stat_vals_arr['TypicalUpperBoundary']);
308
  }
309

    
310
  foreach ($stat_vals_arr as $key => $statistical_val) {
311

    
312
    if ($statistical_val !== NULL) {
313
      if ($statistical_val == '?') {
314
        $val_markup = $statistical_val;
315
      } else {
316
        $val_markup = '<span class="'
317
            . html_class_attribute_ref($statistical_val) . ' '
318
            . (isset($statistical_val->type) ? $statistical_val->type->termType : '') . ' ' . $key .'" title="'. $key. '">'
319
            . $statistical_val->_value . '</span>';
320
      }
321

    
322
      switch ($key) {
323
        // ---- min_max_element
324
        case 'Min':
325
          $min_max_markup .= "($val_markup&ndash;)";
326
          break;
327
        case 'Max':
328
          $min_max_markup .= "(&ndash;$val_markup)";
329
          break;
330
        case 'TypicalLowerBoundary':
331
          $min_max_markup .= "$val_markup";
332
          break;
333
        case 'TypicalUpperBoundary':
334
          $min_max_markup .= "&ndash;$val_markup";
335
          break;
336
          // ---- other values
337
        case 'SampleSize':
338
          $other_vals_array[$key] = $val_markup;
339
          break;
340
        case 'Average':
341
          $other_vals_array[$key] = $xbar_equals . $val_markup;
342
          break;
343
        case 'Variance':
344
          $other_vals_array[$key] = 'σ²=' . $val_markup;
345
          break;
346
        case 'StandardDeviation':
347
          $other_vals_array[$key] = 'σ=' . $val_markup;
348
          break;
349
      }
350
    }
351
  }
352

    
353
  if(!$min_max_markup && $other_vals_array['Average']){
354
    // this could be the case in which we only have one value for Average
355
    // this trivial case needs to be displayed a simpler way
356
    $min_max_markup = str_replace($xbar_equals, '' ,$other_vals_array['Average']);
357
    if($other_vals_array['SampleSize']){
358
      $min_max_markup .= '['. $other_vals_array['SampleSize'] .']';
359
    }
360
  } else {
361
    if(count($other_vals_array)){
362
      $min_max_markup .= '[' . join(';', $other_vals_array) . ']';
363
    }
364
  }
365

    
366
  return $min_max_markup . ($unit ? ' ' . $unit : '');
367
}
368

    
369
/**
370
 * Calculates the required precision for the taget value to be significantly different from min and may and rounds it.
371
 *
372
 * @param $target
373
 *    The statistical value to be rounded to the least significant precision
374
 * @param $min
375
 *    The lower bound to calculate the least significant precision
376
 * @param $max
377
 *    The upper bound to calculate the least significant precision
378
 * @param int $threshold
379
 *    Per default 1, but can be set to any other value > 0 and < 1 to define
380
 *    another threshold for the transition to the next precision level.
381
 *    E.g. A value of 0.5 will cause values > 50 and <= 500 to be shown with
382
 *    a precision of 2, whereas with a threshold of 1 the values > 10 and <= 100
383
 *    will be shown with a precision of 2 figures
384
 */
385
function statistical_values_adjust_significant_figures(&$target, $min,  $max, $threshold = 1){
386

    
387
  $precision = 1;
388
  if($min->_value !== $max->_value){
389
    $precision = floor(log10(abs($max->_value - $min->_value) * (1 / $threshold)));
390
    // increase precision by one
391
    $precision += $precision < 0 ? - 1 : 1;
392
  }
393

    
394
  $target->_value = sigFig($target->_value, $precision);
395
}
396

    
397
/**
398
 * based on an idea taken from https://stackoverflow.com/questions/37618679/format-number-to-n-significant-digits-in-php#answer-48283297
399
 *
400
 * @param $value
401
 * @param $digits
402
 *
403
 * @return float|string
404
 */
405
function sigFig($value, $digits, $round_only = true)
406
{
407
  if ($value == 0) {
408
    $decimalPlaces = $digits - 1;
409
  } elseif ($value < 0) {
410
    $decimalPlaces = $digits - floor(log10($value * -1)) - 1;
411
  } else {
412
    $decimalPlaces = $digits - floor(log10($value)) - 1;
413
  }
414

    
415
  $answer = ($decimalPlaces > 0) && !$round_only ?
416
    number_format($value, $decimalPlaces) : round($value, abs($decimalPlaces));
417
  return $answer;
418
}
419

    
420

    
421

    
422
/**
423
 * Used internally in statistical_values() do determine equality of stat_vals_arr values
424
 *
425
 * @param $stat_vals_arr
426
 * @param $key1
427
 * @param $key2
428
 *
429
 * @return bool
430
 */
431
function statistical_values_equals($stat_vals_arr, $key1, $key2){
432

    
433
  return $stat_vals_arr[$key1] !== NULL && $stat_vals_arr[$key2] !== NULL && $stat_vals_arr[$key1]->_value ==  $stat_vals_arr[$key2]->_value;
434
}
435

    
436
/**
437
 * Creates min max markup to represent a min-average-max measure optionally with an error value.
438
 *
439
 * The fields that are taken into account are:
440
 * - field_base_name = min
441
 * - field_base_nameMax = max
442
 * - field_base_nameText = free text
443
 * - field_base_nameError = error value
444
 *
445
 * @param $object
446
 *    The object having min max measurement fields e.g.: GatheringEvent
447
 * @param string $field_base_name
448
 *    The base name for all measurement fields. This name is at the same time the full name of the
449
 *    min value.
450
 * @return string
451
 *   The markup for the min max
452
 *
453
 * @see statistical_values()
454
 */
455
function statistical_values_from_gathering_event($object, $field_base_name)
456
{
457
  static $default_unit = 'm';
458

    
459
  $field_name = $field_base_name . 'Text';
460
  if (@is_string($object->$field_name)) {
461
    // Freetext overrides all other data
462
    $min_max_markup = ' ' . $object->$field_name;
463
  } else {
464
    // create markup for the atomized min max data
465
    $min_max_array = statistical_values_array();
466
    if (@is_numeric($object->$field_base_name)) {
467
      $min_max_array['Min'] = new stdClass();
468
      $min_max_array['Min']->_value = $object->$field_base_name;
469
    }
470
    $field_name = $field_base_name . 'Max';
471
    if (@is_numeric($object->$field_name)) {
472
      $min_max_array['Max'] = new stdClass();
473
      $min_max_array['Max']->_value = $object->$field_name;
474
    }
475
    $min_max_markup = statistical_values($min_max_array, $default_unit);
476
  }
477

    
478
  return $min_max_markup;
479
}
480

    
481
// TODO  move below code into new file: agent.inc
482

    
483
/*
484
 * Compose an render array from a CDM TaxonNodeAgentRelation object as Taxon Expert.
485
 *
486
 * compose_hook() implementation
487
 *
488
 * @param object $taxon_node_agent_relation
489
 *   CDM instance of type TaxonNodeAgentRelation
490
 * @return array
491
 *   A drupal render array
492
 *
493
 * @ingroup compose
494
 */
495
function compose_cdm_taxon_expert($taxon_node_agent_relation) {
496

    
497
  $label_suffix = ':';
498

    
499
  if($taxon_node_agent_relation->class == 'DefaultPagerImpl'){
500
    // oops this is a pager
501
    // this situation will occur when this compose is executed
502
    // through the proxy_content() method
503
    $taxon_node_agent_relation = $taxon_node_agent_relation->records[0];
504

    
505
  }
506

    
507
  if(is_object($taxon_node_agent_relation->agent)) {
508
    $agent_details = compose_cdm_team_or_person_base($taxon_node_agent_relation->agent);
509
    // all data will be added to the groups of the agent_details render array
510
    $groups = &$agent_details[0]['#groups'];
511

    
512
    @_description_list_group_add($groups, t('Role'). $label_suffix, $taxon_node_agent_relation->type->representation_L10n);
513

    
514
    $family_tnars = cdm_ws_fetch_all(CDM_WS_PORTAL_AGENT . '/' . $taxon_node_agent_relation->agent->uuid . '/taxonNodeAgentRelations', array("rank"=>"Familia"));
515

    
516
    $taxa_markup = array(
517
      '#theme_wrappers' => array('container'),
518
      '#attributes' => array('class' => array('managed_taxa')),
519
      '#wrapper_attributes' => array('class' => 'sublist-container')
520
      );
521
    foreach($family_tnars as $tnar){
522
      if(is_object($tnar->taxonNode->taxon)){
523
        $taxa_markup[$tnar->taxonNode->taxon->titleCache] = markup_to_render_array(render_taxon_or_name($tnar->taxonNode->taxon, url(path_to_taxon($tnar->taxonNode->taxon->uuid))));
524
      }
525
    }
526
    ksort($taxa_markup);
527

    
528
    @_description_list_group_add($groups, t('Families'). $label_suffix, array($taxa_markup));
529

    
530
  }
531

    
532
  return $agent_details;
533
}
534

    
535

    
536
/*
537
 * Compose an render array from a CDM TeamOrPersonBase object.
538
 *
539
 * compose_hook() implementation
540
 *
541
 * TODO: currently mainly implemented for Agent, add Team details
542
 *
543
 * @param object $team_or_person
544
 *   CDM instance of type TeamOrPersonBase
545
 * @return array
546
 *   A drupal render array
547
 *
548
 * @ingroup compose
549
 */
550
function compose_cdm_team_or_person_base($team_or_person, $data = array()) {
551

    
552
  $groups = array();
553

    
554
  $label_suffix = ':';
555

    
556
  // $weight = 0;
557
  if($team_or_person){
558

    
559
    if(is_object($team_or_person->lifespan)){
560
      // ToDo render as date* - date† ?
561
      @_description_list_group_add($groups, t('Lifespan'). $label_suffix, timePeriodToString($team_or_person->lifespan) /*, '' , $weight++ */);
562
    }
563

    
564
    // nomenclaturalTitle
565
    @_description_list_group_add($groups, "Nomenclatural Title". $label_suffix, $team_or_person->nomenclaturalTitle);
566
    // collectorTitle
567
    @_description_list_group_add($groups, "Collector Title". $label_suffix, $team_or_person->collectorTitle);
568

    
569
    // institutionalMemberships
570
    if(is_array($team_or_person->institutionalMemberships)){
571

    
572
      $institutes_ra =  array();
573
      foreach($team_or_person->institutionalMemberships as $membership) {
574
        $membership_groups = array();
575
        @_description_list_group_add($membership_groups, t('Department'). $label_suffix, $membership->department);
576
        @_description_list_group_add($membership_groups, t('Role'). $label_suffix, $membership->role);
577
        if(is_object($membership->period)){
578
          @_description_list_group_add($membership_groups, t('Period'). $label_suffix, timePeriodToString($membership->period));
579
        }
580
        if(is_object($membership->institute->contact)){
581
          $institute_contact_details = compose_cdm_contact($membership->institute->contact, $membership->institute->titleCache);
582
          if(is_array($institute_contact_details[0]['#groups'])){
583
            $membership_groups = array_merge($membership_groups, $institute_contact_details[0]['#groups']);
584
          }
585
        }
586
        if(count($membership_groups) > 0){
587
          $institutes_ra[]  = array(
588
            '#title' => $membership->institute->titleCache,
589
            '#theme' => 'description_list',
590
            '#groups' => $membership_groups,
591
            '#attributes' => array('class' => html_class_attribute_ref($membership)),
592
            '#wrapper_attributes' => array('class' => 'sublist-container')
593
          );
594
        } else {
595
          // no further details for the membership, display the title
596
          $institutes_ra[] = markup_to_render_array('<h3>' . $membership->institute->titleCache . '</h3>');
597
        }
598

    
599
      }
600

    
601
      $label = count($institutes_ra) > 1 ? t('Institutes'):  t('Institute');
602
      @_description_list_group_add($groups, $label. $label_suffix, $institutes_ra /*, '' , $weight++ */);
603
    }
604

    
605

    
606
    // Contact
607
    $agent_contact_details = compose_cdm_contact($team_or_person->contact, $team_or_person->titleCache);
608
    if(is_array($agent_contact_details[0]['#groups'])){
609
      $groups = array_merge($groups, $agent_contact_details[0]['#groups']);
610
    }
611

    
612
    // additional data
613
    foreach($data as $key=>$value){
614
      @_description_list_group_add($sub_dl_groups, t('@key', array('@key' => $key)), $value /*, '' , $weight++ */);
615
    }
616

    
617
  }
618

    
619
  $team_or_person_details = array(
620
    '#title' => $team_or_person->titleCache,
621
    '#theme' => 'description_list',
622
    '#groups' => $groups,
623
    '#attributes' => array('class' => html_class_attribute_ref($team_or_person)),
624
  );
625
  return array($team_or_person_details);
626
}
627

    
628

    
629
/*
630
 * Compose an render array from a CDM Contact object.
631
 *
632
 * compose_hook() implementation
633
 *
634
 * TODO: currently mainly implemented for Agent, add Team details
635
 *
636
 * @param object $contact
637
 *   CDM instance of type Contact
638
 * @param $title
639
 *   The title for the description list header
640
 * @param $weight
641
 *   Optional weight for the description list entries
642
 * @return array
643
 *   A drupal render array
644
 *
645
 * @ingroup compose
646
 */
647
function compose_cdm_contact($contact, $title, $weight = 0)
648
{
649

    
650
  $groups = array();
651

    
652
  $contact_details = null;
653

    
654
  $label_suffix = ':';
655

    
656
  $contact_field_names_map = array(
657
    'emailAddresses' => t('Email'),
658
    'urls' => t('Urls'),
659
    'phoneNumbers' => t('Phone'),
660
    'faxNumbers' => t('Fax'),
661
  );
662

    
663
  // Contact
664
  if(is_object($contact)){
665
    if(isset($contact->addresses)){
666
      // TODO ....
667
      // $sub_groups = array();
668
      // foreach($contact->addresses as $address){
669
      //   @_description_list_group_add($sub_groups, $label, $contact->$fieldName, '', $weight++);
670
      // }
671
    }
672
    foreach($contact_field_names_map as $fieldName => $label){
673
      if(is_array($contact->$fieldName)){
674
        @_description_list_group_add($groups, $label . $label_suffix, $contact->$fieldName, '', $weight++);
675
      }
676
    }
677
    $contact_details = array(
678
      '#title' => $title,
679
      '#theme' => 'description_list',
680
      '#groups' => $groups
681
    );
682

    
683

    
684
  } else if(is_string($title)) {
685
    // if the contact entity is empty but the title is given anyway
686
    // we are only adding the title, using the description_list
687
    // structure is not possible since it would be empty due to
688
    // missing group data
689
    $contact_details = array('#markup' => '<h3>' . $title . '</h3>');
690
  }
691

    
692
  return array($contact_details);
693

    
694
}
695

    
696
/**
697
 * Compose an render array from a CDM Extension objects.
698
 *
699
 * @param $extensions
700
 *    An array of CDM Extension objects
701
 * @return array
702
 *   A render array containing the fields of the supplied $sequence
703
 *
704
 * @ingroup compose
705
 */
706
function compose_extensions($extensions)
707
{
708
  $extensions_render_array= null;
709
  $extensions_by_type = array();
710
  foreach ($extensions as $extension) {
711
    if (@is_string($extension->value)) {
712
      if (!isset($extensions_by_type[$extension->type->representation_L10n])) {
713
        $extensions_by_type[$extension->type->representation_L10n] = array();
714
      }
715
      $extensions_by_type[$extension->type->representation_L10n][] = markup_to_render_array($extension->value);
716
    }
717
  }
718

    
719
  if (count($extensions_by_type)) {
720
    $sub_dl_groups = array();
721
    foreach ($extensions_by_type as $type_label => $text_list) {
722
      @_description_list_group_add($sub_dl_groups, $type_label . ':', $text_list);
723
    }
724
    $extensions_render_array = array(
725
      array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
726
    );
727
    return $extensions_render_array;
728
  }
729
  return $extensions_render_array;
730
}
731

    
732
function formatParams($params) {
733
    if (is_array($params)){
734
        $keys =array_keys($params);
735
        $paramString = '';
736
        foreach ($keys as $k ){
737
            if ($k != 'pageNumber' && $k != 'pageSize'){
738
                $paramString .= ' -'.$k.'='.urlencode($params[$k]);
739
            }
740
        }
741
    }
742
    return $paramString;
743
}
744

    
745
function formatWSParams($params) {
746
    if (is_array($params)){
747
        $keys =array_keys($params);
748
        $paramString = '';
749
        foreach ($keys as $k ){
750
            if ($k != 'pageNumber' && $k != 'pageSize'){
751
                $paramString .= '&'.$k.'='.urlencode($params[$k]);
752
            }
753
        }
754
    }
755
    return $paramString;
756
}
757

    
758
/**
759
 *
760
 * @param $cdm_entity
761
 *
762
 * @return string the markup
763
 */
764
function render_cdm_entity_link($cdm_entity) {
765

    
766
  switch ($cdm_entity->class) {
767
    case 'TaxonDescription':
768
    case 'NameDescription':
769
    case 'SpecimenDescription':
770
      $link =  '<span class="' . html_class_attribute_ref($cdm_entity) . '">' . $cdm_entity->titleCache . '</span> ' . icon_link(path_to_description($cdm_entity->uuid));
771
      break;
772
    default:
773
      $link = '<span class="error">UNSUPPORTED CDM ENTITY TYPE</span>';
774
  }
775
  return $link;
776
}
777

    
778
/**
779
 * Creates an icon which links to the given path
780
 * @param $path
781
 *
782
 * @return string
783
 */
784
function icon_link($path, $fragment = '') {
785
  $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
786
  return $iconlink;
787
}
(1-1/10)