You are here

public static function ProblemsStorage::restructure_results in Node Accessibility 8

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 $severitys: (optional) An array of display levels as returned by QuailApiSettings::get_severity(). If NULL is passed, then this will auto-call QuailApiSettings::get_severity().

Return value

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

1 call to ProblemsStorage::restructure_results()
ValidateFormBase::buildForm in src/Form/ValidateFormBase.php
Form constructor.

File

src/ProblemsStorage.php, line 575

Class

ProblemsStorage
Class DatabaseStorage.

Namespace

Drupal\node_accessibility

Code

public static function restructure_results($nid, $vid, $severitys = NULL) {
  $problems = (array) self::load_problems([
    'nid' => $nid,
    'vid' => $vid,
  ], NULL);
  $tests = QuailApiBase::load_tests([], 'id');
  $results = [];
  if (!is_array($severitys)) {
    $severitys = QuailApiSettings::get_severity();
  }
  foreach ($severitys as $key => $value) {
    if (empty($value['id'])) {
      continue;
    }
    $results[$value['id']] = [
      '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] = [];
      $results[$test->severity][$test->machine_name]['body'] = [];
      $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'] = [];
    }
    $problem = [];
    $problem['line'] = $problem_data->line;
    $problem['element'] = $problem_data->element;
    $results[$test->severity][$test->machine_name]['problems'][] = $problem;
    $results[$test->severity]['total']++;
  }
  return $results;
}