Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / common.inc @ 2f4646e0

History | View | Annotate | Download (21.8 KB)

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
  foreach ($stat_vals_arr as $key => $statistical_val) {
307

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

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

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

    
362
  return $min_max_markup . ($unit ? ' ' . $unit : '');
363
}
364

    
365
/**
366
 * Used internally in statistical_values() do determine equality of stat_vals_arr values
367
 *
368
 * @param $stat_vals_arr
369
 * @param $key1
370
 * @param $key2
371
 *
372
 * @return bool
373
 */
374
function statistical_values_equals($stat_vals_arr, $key1, $key2){
375

    
376
  return $stat_vals_arr[$key1] !== NULL && $stat_vals_arr[$key2] !== NULL && $stat_vals_arr[$key1]->_value ==  $stat_vals_arr[$key2]->_value;
377
}
378

    
379
/**
380
 * Creates min max markup to represent a min-average-max measure optionally with an error value.
381
 *
382
 * The fields that are taken into account are:
383
 * - field_base_name = min
384
 * - field_base_nameMax = max
385
 * - field_base_nameText = free text
386
 * - field_base_nameError = error value
387
 *
388
 * @param $object
389
 *    The object having min max measurement fields e.g.: GatheringEvent
390
 * @param string $field_base_name
391
 *    The base name for all measurement fields. This name is at the same time the full name of the
392
 *    min value.
393
 * @return string
394
 *   The markup for the min max
395
 *
396
 * @see statistical_values()
397
 */
398
function statistical_values_from_gathering_event($object, $field_base_name)
399
{
400
  static $default_unit = 'm';
401

    
402
  $field_name = $field_base_name . 'Text';
403
  if (@is_string($object->$field_name)) {
404
    // Freetext overrides all other data
405
    $min_max_markup = ' ' . $object->$field_name;
406
  } else {
407
    // create markup for the atomized min max data
408
    $min_max_array = statistical_values_array();
409
    if (@is_numeric($object->$field_base_name)) {
410
      $min_max_array['Min'] = new stdClass();
411
      $min_max_array['Min']->_value = $object->$field_base_name;
412
    }
413
    $field_name = $field_base_name . 'Max';
414
    if (@is_numeric($object->$field_name)) {
415
      $min_max_array['Max'] = new stdClass();
416
      $min_max_array['Max']->_value = $object->$field_name;
417
    }
418
    $min_max_markup = statistical_values($min_max_array, $default_unit);
419
  }
420

    
421
  return $min_max_markup;
422
}
423

    
424
// TODO  move below code into new file: agent.inc
425

    
426
/*
427
 * Compose an render array from a CDM TaxonNodeAgentRelation object as Taxon Expert.
428
 *
429
 * compose_hook() implementation
430
 *
431
 * @param object $taxon_node_agent_relation
432
 *   CDM instance of type TaxonNodeAgentRelation
433
 * @return array
434
 *   A drupal render array
435
 *
436
 * @ingroup compose
437
 */
438
function compose_cdm_taxon_expert($taxon_node_agent_relation) {
439

    
440
  $label_suffix = ':';
441

    
442
  if($taxon_node_agent_relation->class == 'DefaultPagerImpl'){
443
    // oops this is a pager
444
    // this situation will occur when this compose is executed
445
    // through the proxy_content() method
446
    $taxon_node_agent_relation = $taxon_node_agent_relation->records[0];
447

    
448
  }
449

    
450
  if(is_object($taxon_node_agent_relation->agent)) {
451
    $agent_details = compose_cdm_team_or_person_base($taxon_node_agent_relation->agent);
452
    // all data will be added to the groups of the agent_details render array
453
    $groups = &$agent_details[0]['#groups'];
454

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

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

    
459
    $taxa_markup = array(
460
      '#theme_wrappers' => array('container'),
461
      '#attributes' => array('class' => array('managed_taxa')),
462
      '#wrapper_attributes' => array('class' => 'sublist-container')
463
      );
464
    foreach($family_tnars as $tnar){
465
      if(is_object($tnar->taxonNode->taxon)){
466
        $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))));
467
      }
468
    }
469
    ksort($taxa_markup);
470

    
471
    @_description_list_group_add($groups, t('Families'). $label_suffix, array($taxa_markup));
472

    
473
  }
474

    
475
  return $agent_details;
476
}
477

    
478

    
479
/*
480
 * Compose an render array from a CDM TeamOrPersonBase object.
481
 *
482
 * compose_hook() implementation
483
 *
484
 * TODO: currently mainly implemented for Agent, add Team details
485
 *
486
 * @param object $team_or_person
487
 *   CDM instance of type TeamOrPersonBase
488
 * @return array
489
 *   A drupal render array
490
 *
491
 * @ingroup compose
492
 */
493
function compose_cdm_team_or_person_base($team_or_person, $data = array()) {
494

    
495
  $groups = array();
496

    
497
  $label_suffix = ':';
498

    
499
  // $weight = 0;
500
  if($team_or_person){
501

    
502
    if(is_object($team_or_person->lifespan)){
503
      // ToDo render as date* - date† ?
504
      @_description_list_group_add($groups, t('Lifespan'). $label_suffix, timePeriodToString($team_or_person->lifespan) /*, '' , $weight++ */);
505
    }
506

    
507
    // nomenclaturalTitle
508
    @_description_list_group_add($groups, "Nomenclatural Title". $label_suffix, $team_or_person->nomenclaturalTitle);
509
    // collectorTitle
510
    @_description_list_group_add($groups, "Collector Title". $label_suffix, $team_or_person->collectorTitle);
511

    
512
    // institutionalMemberships
513
    if(is_array($team_or_person->institutionalMemberships)){
514

    
515
      $institutes_ra =  array();
516
      foreach($team_or_person->institutionalMemberships as $membership) {
517
        $membership_groups = array();
518
        @_description_list_group_add($membership_groups, t('Department'). $label_suffix, $membership->department);
519
        @_description_list_group_add($membership_groups, t('Role'). $label_suffix, $membership->role);
520
        if(is_object($membership->period)){
521
          @_description_list_group_add($membership_groups, t('Period'). $label_suffix, timePeriodToString($membership->period));
522
        }
523
        if(is_object($membership->institute->contact)){
524
          $institute_contact_details = compose_cdm_contact($membership->institute->contact, $membership->institute->titleCache);
525
          if(is_array($institute_contact_details[0]['#groups'])){
526
            $membership_groups = array_merge($membership_groups, $institute_contact_details[0]['#groups']);
527
          }
528
        }
529
        if(count($membership_groups) > 0){
530
          $institutes_ra[]  = array(
531
            '#title' => $membership->institute->titleCache,
532
            '#theme' => 'description_list',
533
            '#groups' => $membership_groups,
534
            '#attributes' => array('class' => html_class_attribute_ref($membership)),
535
            '#wrapper_attributes' => array('class' => 'sublist-container')
536
          );
537
        } else {
538
          // no further details for the membership, display the title
539
          $institutes_ra[] = markup_to_render_array('<h3>' . $membership->institute->titleCache . '</h3>');
540
        }
541

    
542
      }
543

    
544
      $label = count($institutes_ra) > 1 ? t('Institutes'):  t('Institute');
545
      @_description_list_group_add($groups, $label. $label_suffix, $institutes_ra /*, '' , $weight++ */);
546
    }
547

    
548

    
549
    // Contact
550
    $agent_contact_details = compose_cdm_contact($team_or_person->contact, $team_or_person->titleCache);
551
    if(is_array($agent_contact_details[0]['#groups'])){
552
      $groups = array_merge($groups, $agent_contact_details[0]['#groups']);
553
    }
554

    
555
    // additional data
556
    foreach($data as $key=>$value){
557
      @_description_list_group_add($sub_dl_groups, t('@key', array('@key' => $key)), $value /*, '' , $weight++ */);
558
    }
559

    
560
  }
561

    
562
  $team_or_person_details = array(
563
    '#title' => $team_or_person->titleCache,
564
    '#theme' => 'description_list',
565
    '#groups' => $groups,
566
    '#attributes' => array('class' => html_class_attribute_ref($team_or_person)),
567
  );
568
  return array($team_or_person_details);
569
}
570

    
571

    
572
/*
573
 * Compose an render array from a CDM Contact object.
574
 *
575
 * compose_hook() implementation
576
 *
577
 * TODO: currently mainly implemented for Agent, add Team details
578
 *
579
 * @param object $contact
580
 *   CDM instance of type Contact
581
 * @param $title
582
 *   The title for the description list header
583
 * @param $weight
584
 *   Optional weight for the description list entries
585
 * @return array
586
 *   A drupal render array
587
 *
588
 * @ingroup compose
589
 */
590
function compose_cdm_contact($contact, $title, $weight = 0)
591
{
592

    
593
  $groups = array();
594

    
595
  $contact_details = null;
596

    
597
  $label_suffix = ':';
598

    
599
  $contact_field_names_map = array(
600
    'emailAddresses' => t('Email'),
601
    'urls' => t('Urls'),
602
    'phoneNumbers' => t('Phone'),
603
    'faxNumbers' => t('Fax'),
604
  );
605

    
606
  // Contact
607
  if(is_object($contact)){
608
    if(isset($contact->addresses)){
609
      // TODO ....
610
      // $sub_groups = array();
611
      // foreach($contact->addresses as $address){
612
      //   @_description_list_group_add($sub_groups, $label, $contact->$fieldName, '', $weight++);
613
      // }
614
    }
615
    foreach($contact_field_names_map as $fieldName => $label){
616
      if(is_array($contact->$fieldName)){
617
        @_description_list_group_add($groups, $label . $label_suffix, $contact->$fieldName, '', $weight++);
618
      }
619
    }
620
    $contact_details = array(
621
      '#title' => $title,
622
      '#theme' => 'description_list',
623
      '#groups' => $groups
624
    );
625

    
626

    
627
  } else if(is_string($title)) {
628
    // if the contact entity is empty but the title is given anyway
629
    // we are only adding the title, using the description_list
630
    // structure is not possible since it would be empty due to
631
    // missing group data
632
    $contact_details = array('#markup' => '<h3>' . $title . '</h3>');
633
  }
634

    
635
  return array($contact_details);
636

    
637
}
638

    
639
/**
640
 * Compose an render array from a CDM Extension objects.
641
 *
642
 * @param $extensions
643
 *    An array of CDM Extension objects
644
 * @return array
645
 *   A render array containing the fields of the supplied $sequence
646
 *
647
 * @ingroup compose
648
 */
649
function compose_extensions($extensions)
650
{
651
  $extensions_render_array= null;
652
  $extensions_by_type = array();
653
  foreach ($extensions as $extension) {
654
    if (@is_string($extension->value)) {
655
      if (!isset($extensions_by_type[$extension->type->representation_L10n])) {
656
        $extensions_by_type[$extension->type->representation_L10n] = array();
657
      }
658
      $extensions_by_type[$extension->type->representation_L10n][] = markup_to_render_array($extension->value);
659
    }
660
  }
661

    
662
  if (count($extensions_by_type)) {
663
    $sub_dl_groups = array();
664
    foreach ($extensions_by_type as $type_label => $text_list) {
665
      @_description_list_group_add($sub_dl_groups, $type_label . ':', $text_list);
666
    }
667
    $extensions_render_array = array(
668
      array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
669
    );
670
    return $extensions_render_array;
671
  }
672
  return $extensions_render_array;
673
}
674

    
675
function formatParams($params) {
676
    if (is_array($params)){
677
        $keys =array_keys($params);
678
        $paramString = '';
679
        foreach ($keys as $k ){
680
            if ($k != 'pageNumber' && $k != 'pageSize'){
681
                $paramString .= ' -'.$k.'='.urlencode($params[$k]);
682
            }
683
        }
684
    }
685
    return $paramString;
686
}
687

    
688
function formatWSParams($params) {
689
    if (is_array($params)){
690
        $keys =array_keys($params);
691
        $paramString = '';
692
        foreach ($keys as $k ){
693
            if ($k != 'pageNumber' && $k != 'pageSize'){
694
                $paramString .= '&'.$k.'='.urlencode($params[$k]);
695
            }
696
        }
697
    }
698
    return $paramString;
699
}
700

    
701
/**
702
 *
703
 * @param $cdm_entity
704
 *
705
 * @return string the markup
706
 */
707
function render_cdm_entity_link($cdm_entity) {
708

    
709
  switch ($cdm_entity->class) {
710
    case 'TaxonDescription':
711
    case 'NameDescription':
712
    case 'SpecimenDescription':
713
      $link =  '<span class="' . html_class_attribute_ref($cdm_entity) . '">' . $cdm_entity->titleCache . '</span> ' . icon_link(path_to_description($cdm_entity->uuid));
714
      break;
715
    default:
716
      $link = '<span class="error">UNSUPPORTED CDM ENTITY TYPE</span>';
717
  }
718
  return $link;
719
}
720

    
721
/**
722
 * Creates an icon which links to the given path
723
 * @param $path
724
 *
725
 * @return string
726
 */
727
function icon_link($path, $fragment = '') {
728
  $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
729
  return $iconlink;
730
}
Add picture from clipboard (Maximum size: 40 MB)