You are here

public static function ProblemsStorage::load_problem_severity_count in Node Accessibility 8

Load count of problems by severity.

Parameters

int $severity_id: The severity id code

int|null $nid: (optional) The numeric node id to filter by.

int|null $vid: (optional) The numeric node revision id to filter by.

Return value

int|bool The total of problems for the severity is returned on success. FALSE is returned otherwise.

See also

QuailApiSettings::get_severity()

QuailApiSettings::get_severity_list()

1 call to ProblemsStorage::load_problem_severity_count()
NodeAccessibilityController::revisionOverview in src/Controller/NodeAccessibilityController.php
Generates an overview table of older revisions of a node.

File

src/ProblemsStorage.php, line 367

Class

ProblemsStorage
Class DatabaseStorage.

Namespace

Drupal\node_accessibility

Code

public static function load_problem_severity_count($severity_id, $nid = NULL, $vid = NULL) {
  if (!is_numeric($severity_id)) {
    return FALSE;
  }
  if (!is_null($nid) && !is_numeric($nid)) {
    return FALSE;
  }
  if (!is_null($vid) && !is_numeric($vid)) {
    return FALSE;
  }
  try {
    $query = \Drupal::database()
      ->select('node_accessibility_problems', 'nap');
    $query
      ->condition('nap.test_severity', $severity_id);
    if (is_numeric($nid)) {
      $query
        ->condition('nap.nid', $nid);
    }
    if (is_numeric($vid)) {
      $query
        ->condition('nap.vid', $vid);
    }
    $result = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    if (is_numeric($result)) {
      return (int) $result;
    }
  } catch (Exception $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to load problems.");
  } catch (Error $e) {
    \Drupal::logger('node_accessibility')
      ->error("Failed to load problems.");
  }
  return FALSE;
}