Project

General

Profile

« Previous | Next » 

Revision 7f36e33a

Added by Andreas Kohlbecker over 3 years ago

fix #8828 removing empty brackets from statistical values in QuantitativeData and cleaning up

View differences:

modules/cdm_dataportal/includes/common.inc
405 405
    // this trivial case needs to be displayed a simpler way
406 406
    $min_max_markup = str_replace($xbar_equals, '' , $other_vals_array['Average']);
407 407
    unset($other_vals_array['Average']);
408
  }
409
  if(count($other_vals_array)){
408 410
    $min_max_markup .= ' [' . join(';', $other_vals_array) . ']';
409
  } else {
410
    if(count($other_vals_array)){
411
      $min_max_markup .= ' [' . join(';', $other_vals_array) . ']';
412
    }
413 411
  }
414 412

  
415 413
  return $min_max_markup . ($unit ? ' ' . $unit : '');
416 414
}
417 415

  
418 416
/**
419
 * Calculates the required precision for the taget value to be significantly different from min and may and rounds it.
417
 * Calculates the required precision for the target value to be significantly different from min and may and rounds it.
420 418
 *
421 419
 * @param $target
422 420
 *    The statistical value to be rounded to the least significant precision
modules/cdm_dataportal/includes/descriptions.inc
1308 1308
  $out = '';
1309 1309
  $type_representation = NULL;
1310 1310
  $min_max = statistical_values_array();
1311
  $other_values = [];
1312 1311
  $sample_size_markup = null;
1313 1312

  
1314 1313
  if (isset($element->statisticalValues)) {
......
1331 1330
        $min_max[statistical_measure_term2min_max_key($statistical_val->type)] = $statistical_val;
1332 1331
      }
1333 1332
      else {
1334
        $other_values[] = $statistical_val;
1333
        drupal_set_message("Unsupported statistical value type: " . $statistical_val->type->uuid, "error");
1335 1334
      }
1336 1335
    } // end of loop over statisticalValues
1337 1336

  
1338 1337
    // create markup
1339

  
1340
    $min_max_markup = statistical_values($min_max);
1341

  
1342

  
1343
    foreach ($other_values as $statistical_val) {
1344
      $statistical_val_type_representation = NULL;
1345
      if (isset($statistical_val->type)) {
1346
        $statistical_val_type_representation = cdm_term_representation($statistical_val->type);
1347
      }
1348

  
1349
      $value_markup = '';
1350
      $type_markup = '';
1351
      switch (statistical_measure_term2min_max_key($statistical_val->type)){
1352
        case 'SampleSize':
1353
          $sample_size_markup = '<span class="' . html_class_attribute_ref($statistical_val) . ' ' . $statistical_val->type->termType . ' ">'
1354
            . '[' . $statistical_val->_value . ']</span>';
1355
          break;
1356
        case 'ExactValue':
1357
          $value_markup = '<span class="' . html_class_attribute_ref($statistical_val) . ' ' . $statistical_val->type->termType . ' ">'
1358
            . $statistical_val->_value . '</span>';
1359
          break;
1360
        default:
1361
        $value_markup = '<span class="' . html_class_attribute_ref($statistical_val) . ' ' . $statistical_val->type->termType . ' ">'
1362
          . $statistical_val->_value . '</span>';
1363
         $type_markup = ($statistical_val_type_representation ? ' <span class="type">' . $statistical_val_type_representation . '</span>' : '');
1364
      }
1365
      if($value_markup){
1366
        $other_values_markup[] = $value_markup . $type_markup;
1367
      }
1338
    $unit = null;
1339
    if (isset($element->unit)) {
1340
      $unit = ' <span class="unit" title="'
1341
        . cdm_term_representation($element->unit) . '">'
1342
        . cdm_term_representation_abbreviated($element->unit)
1343
        . '</span>';
1368 1344
    }
1369

  
1370
    $other_values_markup = trim(implode($other_values_markup, ', '));
1371
    $out .= $min_max_markup . ($other_values_markup ? $other_values_markup : '');
1372
    $out .= '</span>';
1373
  }
1374

  
1375
  if (isset($element->unit)) {
1376
    $out .= '<span class="unit" title="'
1377
      . cdm_term_representation($element->unit) . '">'
1378
      . cdm_term_representation_abbreviated($element->unit)
1379
      . '</span>';
1345
    $min_max_markup = statistical_values($min_max, $unit);
1346
    $out .= $min_max_markup . '</span>';
1380 1347
  }
1381 1348

  
1382 1349
  if($sample_size_markup){
modules/cdm_dataportal/test/phpUnit/src/unit/StatisticalValuesTest.php
87 87
    $this->assertEquals('2.2–8.7 [5;x̄=5;σ²=0.3;σ=0.12] cm', $this->html2text(statistical_values($stat_vals, 'cm')));
88 88
  }
89 89

  
90

  
91
  function test_statistical_values_no_brackets() {
92

  
93
    $stat_vals = $this->create_statistical_values(2.2,  8.7);
94
    $this->assertEquals('2.2–8.7 cm', $this->html2text(statistical_values($stat_vals, 'cm')));
95

  
96
    $stat_vals = $this->create_statistical_values(null,  null, 5.3);
97
    $this->assertEquals('5.3 m', $this->html2text(statistical_values($stat_vals, 'm')));
98
  }
99

  
90 100
}

Also available in: Unified diff