Project

General

Profile

« Previous | Next » 

Revision 5a079dbf

Added by Andreas Kohlbecker over 5 years ago

ref #2985 units in min max measures only at the end and after the error value

View differences:

modules/cdm_dataportal/includes/common.inc
237 237
}
238 238

  
239 239
/**
240
 * Creates markup from a min max array.
241
 *
240 242
 * NOTE: use  min_max_array() to create an appropriate array
241 243
 *
242 244
 * @param $min_max
245
 *  the min-max array
246
 * @param $unit
247
 *  Defaults to no unit
243 248
 * @return string
244 249
 */
245
function min_max_markup($min_max) {
250
function min_max_markup($min_max, $unit = '') {
246 251

  
247 252
  $min_max_markup = '';
248 253
  // create min-max string
249 254
  if ($min_max['Min'] !== NULL && $min_max['Max'] !== NULL && $min_max['Min']->_value == $min_max['Max']->_value) {
255
    // min and max are identical
250 256
    $min_max['Average'] = $min_max['Min'];
251 257
    $min_max['Min'] = NULL;
252 258
    $min_max['Max'] = NULL;
......
254 260

  
255 261
  // check for inconsistent cases, eg. only Max and average given
256 262
  if ($min_max['Min'] === NULL && $min_max['Max'] !== NULL) {
263
    // min missing
257 264
    $min_max['Min'] = '?';
258 265
  }
259 266
  if ($min_max['Min'] !== NULL && $min_max['Max'] === NULL) {
267
    // max missing
260 268
    $min_max['Max'] = '?';
261 269
  }
262 270

  
......
282 290
      $min_max_markup .= $val_markup;
283 291
    }
284 292
  }
293
  return $min_max_markup . ' ' . $unit;
294
}
295

  
296
/**
297
 * Creates min max markup to represent a min-average-max measure optionally with an error value.
298
 *
299
 * The fields that are taken into account are:
300
 * - field_base_name = min
301
 * - field_base_nameMax = max
302
 * - field_base_nameText = free text
303
 * - field_base_nameError = error value
304
 *
305
 * @param $object
306
 *    The object having min max measurement fields
307
 * @param string $field_base_name
308
 *    The base name for all measurement fields. This name is at the same time the full name of the
309
 *    min value.
310
 * @return array
311
 *   the resulting min max array
312
 */
313
function min_max_measure($object, $field_base_name)
314
{
315
  static $default_unit = 'm';
316

  
317
  $min_max_array = min_max_array();
318
  if (is_numeric($object->$field_base_name)) {
319
    $min_max_array['Min'] = new stdClass();
320
    $min_max_array['Min']->_value = $object->$field_base_name;
321
  }
322

  
323
  $field_name = $field_base_name . 'Max';
324
  if (is_numeric($object->$field_name)) {
325
    $min_max_array['Max'] = new stdClass();
326
    $min_max_array['Max']->_value = $object->$field_name;
327
  }
328
  $min_max_markup = min_max_markup($min_max_array, $default_unit);
329

  
330
  $field_name = $field_base_name . 'Error';
331
  if (is_numeric($object->$field_name )) {
332
    $min_max_markup .= ' +/- ' . $object->$field_name . ' ' . $default_unit;
333
  }
334
  $field_name = $field_base_name . 'Text';
335
  if (is_string($object->$field_name)) {
336
    $min_max_markup .= ' ' . $object->$field_name;
337
  }
285 338
  return $min_max_markup;
286 339
}
287 340

  
modules/cdm_dataportal/includes/descriptions.inc
1154 1154
  $type_representation = NULL;
1155 1155
  $min_max = min_max_array();
1156 1156

  
1157

  
1158 1157
  $other_values = array();
1159 1158

  
1160 1159
  if (isset($element->statisticalValues)) {
modules/cdm_dataportal/includes/occurrences.inc
232 232

  
233 233

  
234 234
/**
235
 * Formats the given string to a label for displaying key-value pairs in HTML
235
 * Formats the given string to a label for displaying key-object pairs in HTML
236 236
 * @return string
237 237
 */
238 238
function create_label($label)
......
488 488
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
489 489
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
490 490
            if (isset($value->absoluteElevation)) {
491
                $min_max_array = min_max_array();
492
                if(is_numeric($value->absoluteElevation)){
493
                    $min_max_array['Min'] = new stdClass();
494
                    $min_max_array['Min']->_value = $value->absoluteElevation . ' m';
495
                }
496
                if(is_numeric($value->absoluteElevation)){
497
                    $min_max_array['Max'] = new stdClass();
498
                    $min_max_array['Max']->_value = $value->absoluteElevationMax . ' m';
499
                }
500
                $min_max_markup = min_max_markup($min_max_array);
501
                if(isset($value->absoluteElevationError)){
502
                    $min_max_markup .= ' +/-' .  $value->absoluteElevationError . ' m';
503
                }
504
                if(is_string($value->absoluteElevationText)){
505
                    $min_max_markup .= ' ' . $value->absoluteElevationText;
506
                }
507
                @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
491
              $min_max_markup = min_max_measure($value, 'absoluteElevation');
492
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
508 493
            }
509 494
            if (isset($value->distanceToGround)) {
510
              $min_max_array = min_max_array();
511
              if(is_numeric($value->distanceToGround)){
512
                  $min_max_array['Min'] = new stdClass();
513
                  $min_max_array['Min']->_value = $value->distanceToGround . ' m';
514
              }
515
              if(is_numeric($value->distanceToGround)){
516
                  $min_max_array['Max'] = new stdClass();
517
                  $min_max_array['Max']->_value = $value->distanceToGroundMax . ' m';
518
              }
519
              $min_max_markup = min_max_markup($min_max_array);
520
              if(isset($value->distanceToGroundError)){
521
                  $min_max_markup .= ' +/-' .  $value->distanceToGroundError . ' m';
522
              }
523
              if(is_string($value->distanceToGroundText)){
524
                  $min_max_markup .= ' ' . $value->distanceToGroundText;
525
              }
495
              $min_max_markup = min_max_measure($value, 'distanceToGround');
526 496
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
527 497
            }
528 498
            if (isset($value->distanceToWaterSurface)) {
529
              $min_max_array = min_max_array();
530
              if(is_numeric($value->distanceToWaterSurface)){
531
                  $min_max_array['Min'] = new stdClass();
532
                  $min_max_array['Min']->_value = $value->distanceToWaterSurface . ' m';
533
              }
534
              if(is_numeric($value->distanceToWaterSurface)){
535
                  $min_max_array['Max'] = new stdClass();
536
                  $min_max_array['Max']->_value = $value->distanceToWaterSurfaceMax . ' m';
537
              }
538
              $min_max_markup = min_max_markup($min_max_array);
539
              if(isset($value->distanceToWaterSurfaceError)){
540
                  $min_max_markup .= ' +/-' .  $value->distanceToWaterSurfaceError . ' m';
541
              }
542
              if(is_string($value->distanceToWaterSurfaceText)){
543
                  $min_max_markup .= ' ' . $value->distanceToWaterSurfaceText;
544
              }
499
              $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
545 500
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
546 501
            }
547 502

  

Also available in: Unified diff