Project

General

Profile

Revision 0e414cc1

ID0e414cc1ad6b178dd09a57eed2bd47d25d07677a
Parent 8867b63b
Child dfd71699

Added by Andreas Kohlbecker 11 months ago

fix #8807 adaptive headers in description table

View differences:

modules/cdm_dataportal/includes/descriptions.inc
2267 2267

  
2268 2268
  $root_nodes = get_root_nodes_for_dataset($description);
2269 2269

  
2270
  $header = ['Feature/Character', 'State'];
2271 2270

  
2272 2271
  $rows = [];
2273 2272
  $rows = description_element_table_rows($root_nodes, $rows);
2274 2273

  
2274
  // --- create headers
2275
  $header = [1 => [], 2 => []];
2276

  
2277
  foreach($rows as $row) {
2278
    if(array_search('Character', $row['class']) && array_search('Character', $header[1]) === false){
2279
      $header[1][] = 'Character';
2280
    } elseif (array_search('Feature', $row['class']) && array_search('Feature', $header[1]) === false){
2281
      $header[1][] = 'Feature';
2282
    }
2283
    if(array_search('has_state', $row['class']) && array_search('States', $header[2]) === false){
2284
      $header[2][] = 'States';
2285
    } elseif (array_search('has_values', $row['class']) && array_search('Values', $header[2]) === false){
2286
      $header[2][] = 'Values';
2287
    }
2288
  }
2289
  asort($header[1]);
2290
  asort($header[2]);
2291
  $header[1] = join('/', $header[1]);
2292
  $header[2] = join('/', $header[2]);
2293

  
2294
  // ---
2295

  
2275 2296
  if (!empty($rows)) {
2276 2297
    $render_array['table'] = markup_to_render_array(theme('table', [
2277 2298
      'header' => $header,
......
2346 2367
}
2347 2368

  
2348 2369
/**
2349
 * Recursively creates an array of row items to be used in theme_table
2370
 * Recursively creates an array of row items to be used in theme_table.
2371
 *
2372
 * The array items will have am element 'class' with information on the
2373
 * nature of the DescriptionElement ('has_values' | 'has_state') and on the
2374
 * type of the FeatureNode ('Feature' | 'Character')
2350 2375
 *
2351 2376
 * @param array $root_nodes
2352 2377
 * @param array $row_items
......
2359 2384
 *
2360 2385
 */
2361 2386
function description_element_table_rows($root_nodes, $row_items, $level = 0) {
2387

  
2362 2388
  $indent_string = '   ';
2363 2389
  foreach ($root_nodes as $root_node) {
2364 2390
    if(isset($root_node->descriptionElements)) {
2365 2391
      foreach ($root_node->descriptionElements as $element) {
2366 2392
        $level_indent = str_pad('', $level * strlen($indent_string), $indent_string);
2367 2393
        switch ($element->class) {
2394
          case 'QuantitativeData':
2395
            $row_items[] = [
2396
              'data' => [
2397
                [
2398
                  'data' => markup_to_render_array($level_indent . $element->feature->representation_L10n),
2399
                  'class' => ['level_' . $level]
2400
                ],
2401
                render_quantitative_statistics($element)
2402
              ],
2403
              'class' => ['level_' . $level, 'has_values', $element->feature->class]
2404
            ];
2405
            break;
2368 2406
          case 'CategoricalData':
2407
            default:
2369 2408
            if (!empty($element->stateData)) {
2370 2409
              $row_items[] = [
2371 2410
                'data' => [
......
2375 2414
                  ],
2376 2415
                  render_state_data($element),
2377 2416
                ],
2378
                'class' => ['level_' . $level]
2417
                'class' => ['level_' . $level, 'has_state', $element->feature->class]
2379 2418
              ];
2380 2419
            }
2381 2420
            break;
2382
          case 'QuantitativeData':
2383
            $row_items[] = [
2384
              'data' => [
2385
                [
2386
                  'data' => markup_to_render_array($level_indent . $element->feature->representation_L10n),
2387
                  'class' => ['level_' . $level]
2388
                ],
2389
                render_quantitative_statistics($element)
2390
              ],
2391
              'class' => ['level_' . $level]
2392
            ];
2393
            break;
2394 2421
        }
2395 2422
      }
2396 2423
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)