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

  

Also available in: Unified diff