Project

General

Profile

« Previous | Next » 

Revision 2f4646e0

Added by Andreas Kohlbecker over 4 years 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;

Also available in: Unified diff