public static function QuailApiBase::load_tests in Quail API 8
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 QuailApiBase::load_tests()
- QuailApiBase::save_test in src/
QuailApiBase.php - This stores the quail test information in the drupal database.
File
- src/
QuailApiBase.php, line 32
Class
- QuailApiBase
- Class QuailApiBase.
Namespace
Drupal\quail_apiCode
public static function load_tests($conditions = [], $keyed = NULL) {
if (!is_array($conditions)) {
return [];
}
$query = \Drupal::database()
->select('quail_api_tests', 'qat');
$query
->fields('qat');
$query
->orderBy('qat.id', 'ASC');
$and = NULL;
if (isset($conditions['id']) && is_numeric($conditions['id'])) {
$and = new Condition('AND');
$and
->condition('id', $conditions['id'], '=');
}
if (isset($conditions['severity']) && is_numeric($conditions['severity'])) {
if (is_null($and)) {
$and = new Condition('AND');
}
$and
->condition('severity', $conditions['severity'], '=');
}
if (!empty($conditions['machine_name'])) {
if (is_null($and)) {
$and = new Condition('AND');
}
$and
->condition('machine_name', $conditions['machine_name'], '=');
}
if (is_object($and)) {
$query
->condition($and);
}
if ($keyed === 'id' || $keyed === 'machine_name') {
$results = [];
try {
$records = $query
->execute();
} catch (Exception $e) {
return [];
} catch (Error $e) {
return [];
}
foreach ($records as $record) {
if (!is_object($record)) {
continue;
}
$results[$record->{$keyed}] = $record;
}
return $results;
}
try {
return $query
->execute()
->fetchAll();
} catch (Exception $e) {
} catch (Error $e) {
}
return [];
}