You are here

function quail_api_load_tests in Quail API 7

Loads the quail test data.

Parameters

array $conditions: An array with the following possible keys:

  • id: The numeric id.
  • severity: A numeric value representing the severity (aka: display level) as defined by the quail library.
  • machine_name: The machine-friendly name for the test as defined by the quail library.

string|null $keyed: (optional) A string matching one of the following: 'id', 'machine_name'. When this is NULL, the default behavior is to return the array exactly as it was returned by the database call. When this is a valid string, the key names of the returned array will use the specified key name.

Return value

array An array of database results.

1 call to quail_api_load_tests()
quail_api_save_test in ./quail_api.module
This stores the quail test information in the drupal database.

File

./quail_api.module, line 772
Module file for the quail api.

Code

function quail_api_load_tests($conditions = array(), $keyed = NULL) {
  if (!is_array($conditions)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('conditions');
    }
    return array();
  }
  $query = db_select('quail_api_tests', 'qat');
  $query
    ->fields('qat');
  $query
    ->orderBy('qat.id', 'ASC');
  $and = NULL;
  if (isset($conditions['id']) && is_numeric($conditions['id'])) {
    $and = db_and();
    $and
      ->condition('id', $conditions['id'], '=');
  }
  if (isset($conditions['severity']) && is_numeric($conditions['severity'])) {
    if (is_null($and)) {
      $and = db_and();
    }
    $and
      ->condition('severity', $conditions['severity'], '=');
  }
  if (!empty($conditions['machine_name'])) {
    if (is_null($and)) {
      $and = db_and();
    }
    $and
      ->condition('machine_name', $conditions['machine_name'], '=');
  }
  if (is_object($and)) {
    $query
      ->condition($and);
  }
  if ($keyed === 'id' || $keyed === 'machine_name') {
    $results = array();
    try {
      $records = $query
        ->execute();
    } catch (Exception $e) {
      if (class_exists('cf_error')) {
        cf_error::on_query_execution($e);
      }
      return array();
    }
    foreach ($records as $record) {
      if (!is_object($record)) {
        continue;
      }
      $results[$record->{$keyed}] = $record;
    }
    return $results;
  }
  try {
    return $query
      ->execute()
      ->fetchAll();
  } catch (Exception $e) {
    if (class_exists('cf_error')) {
      cf_error::on_query_execution($e);
    }
  }
  return array();
}