You are here

function node_accessibility_restructure_results in Node Accessibility 7

This restructures an array of problems as returned from database calls.

The data is converted into a format that can be processed by the quail api theme functions.

Parameters

int $nid: A node id the results belong to.

int $vid: A node revision id the results belong to.

array|null $display_levels: (optional) An array of display levels as returned by quail_api_get_display_levels(). If NULL is passed, then this will auto-call quail_api_get_display_levels().

Return value

array An array of database results in a format that can be processed by the quail_api theme functions.

1 call to node_accessibility_restructure_results()
node_accessibility_accessibility_tab_page in includes/pages.inc
Provides the accessibility tab page.

File

./node_accessibility.module, line 1145
Module file for the node accessibility project.

Code

function node_accessibility_restructure_results($nid, $vid, $display_levels = NULL) {
  $problems = (array) node_accessibility_load_problems(array(
    'nid' => $nid,
    'vid' => $vid,
  ), NULL);
  $tests = quail_api_load_tests(array(), 'id');
  $results = array();
  if (!is_array($display_levels)) {
    $display_levels = quail_api_get_display_levels(NULL);
  }
  foreach ($display_levels as $key => $value) {
    if (empty($value['id'])) {
      continue;
    }
    $results[$value['id']] = array(
      'total' => 0,
    );
  }
  foreach ($problems as $problem_key => $problem_data) {
    if (!is_object($problem_data)) {
      continue;
    }
    $test = $tests[$problem_data->test_id];
    if (!isset($results[$test->severity][$test->machine_name])) {
      $results[$test->severity][$test->machine_name] = array();
      $results[$test->severity][$test->machine_name]['body'] = array();
      $results[$test->severity][$test->machine_name]['body']['title'] = $test->human_name;
      $results[$test->severity][$test->machine_name]['body']['description'] = $test->description;
      $results[$test->severity][$test->machine_name]['problems'] = array();
    }
    $problem = array();
    $problem['line'] = $problem_data->line;
    $problem['element'] = $problem_data->element;
    $results[$test->severity][$test->machine_name]['problems'][] = $problem;
    $results[$test->severity]['total']++;
  }
  return $results;
}