Project

General

Profile

Revision 2f4646e0

ID2f4646e09c98b115f5ff80a147d44a86309d3a85
Parent cd3ea2e8
Child 793df790

Added by Andreas Kohlbecker 7 months ago

ref #8786 renaming all min_max_() functions to statistical_values_()

View differences:

modules/cdm_dataportal/includes/common.inc
212 212
  }
213 213

  
214 214
/**
215
 * Provides an explanatory text on the statistical values representation as generated by min_max_markup()
215
 * Provides an explanatory text on the statistical values representation as generated by statistical_values()
216 216
 *
217 217
 * @return string
218 218
 *     the text
......
222 222
  }
223 223

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

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

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

  
......
269 269
  $other_vals_array = [];
270 270

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

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

  
280
  if($min_max['TypicalLowerBoundary'] === null && $min_max['Min'] !== null){
281
    $min_max['TypicalLowerBoundary'] = $min_max['Min'];
282
    $min_max['Min'] = NULL;
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 283
  }
284 284

  
285
  if($min_max['TypicalUpperBoundary'] === null && $min_max['Max']  !== null){
286
    $min_max['TypicalUpperBoundary'] = $min_max['Max'];
287
    $min_max['Max'] = NULL;
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 288
  }
289 289

  
290
  if (min_max_equals($min_max, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
291
    $min_max['Average'] = $min_max['TypicalUpperBoundary'];
292
    $min_max['TypicalLowerBoundary'] = NULL;
293
    $min_max['TypicalUpperBoundary'] = NULL;
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 294
  }
295 295

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

  
306
  foreach ($min_max as $key => $statistical_val) {
306
  foreach ($stat_vals_arr as $key => $statistical_val) {
307 307

  
308 308
    if ($statistical_val !== NULL) {
309 309
      if ($statistical_val == '?') {
......
363 363
}
364 364

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

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

  
379 379
/**
......
392 392
 *    min value.
393 393
 * @return string
394 394
 *   The markup for the min max
395
 *
396
 * @see statistical_values()
395 397
 */
396
function min_max_measure($object, $field_base_name)
398
function statistical_values_from_gathering_event($object, $field_base_name)
397 399
{
398 400
  static $default_unit = 'm';
399 401

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

  
419 421
  return $min_max_markup;
modules/cdm_dataportal/includes/descriptions.inc
1307 1307

  
1308 1308
  $out = '';
1309 1309
  $type_representation = NULL;
1310
  $min_max = min_max_array();
1310
  $min_max = statistical_values_array();
1311 1311
  $other_values = [];
1312 1312
  $sample_size_markup = null;
1313 1313

  
......
1337 1337

  
1338 1338
    // create markup
1339 1339

  
1340
    $min_max_markup = min_max_markup($min_max);
1340
    $min_max_markup = statistical_values($min_max);
1341 1341

  
1342 1342

  
1343 1343
    foreach ($other_values as $statistical_val) {
modules/cdm_dataportal/includes/occurrences.inc
679 679
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
680 680
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
681 681
                        if (isset($value->absoluteElevation)) {
682
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
682
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
683 683
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
684 684
                        }
685 685
                        if (isset($value->distanceToGround)) {
686
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
686
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
687 687
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
688 688
                        }
689 689
                        if (isset($value->distanceToWaterSurface)) {
690
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
690
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
691 691
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
692 692
                        }
693 693
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
......
1424 1424
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1425 1425
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1426 1426
                        if (isset($value->absoluteElevation)) {
1427
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1427
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
1428 1428
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1429 1429
                        }
1430 1430
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1431
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1431
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
1432 1432
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1433 1433
                        }
1434 1434
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1435
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1435
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
1436 1436
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1437 1437
                        }
1438 1438

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)