function node_accessibility_save_node_problems in Node Accessibility 7
Saves the node report data to the database.
Parameters
int $nid: The node id of the node associated with the given reports.
int $vid: The node revision id of the node associated with the given reports.
array $reports: The reports array as returned by the quail library quail api reporter.
Return value
bool TRUE on success, FALSE otherwise.
4 calls to node_accessibility_save_node_problems()
- node_accessibility_accessibility_tab_page in includes/
pages.inc - Provides the accessibility tab page.
- node_accessibility_drush_callback_validate in ./
node_accessibility.drush.inc - Drush command callback.
- node_accessibility_operation_validate in ./
node_accessibility.module - Perform validation on any number of nodes.
- node_accessibility_validate_action in ./
node_accessibility.module - Performs accessibility validation on a given node.
File
- ./
node_accessibility.module, line 611 - Module file for the node accessibility project.
Code
function node_accessibility_save_node_problems($nid, $vid, $reports) {
if (!is_array($reports)) {
if (class_exists('cf_error')) {
cf_error::invalid_array('reports');
}
return FALSE;
}
$tests_known = (array) quail_api_load_tests(array(), 'machine_name');
$problems = array();
foreach ($reports as $severity => $severity_results) {
if ($severity != 'total') {
foreach ($severity_results as $test_name => $test_results) {
if ($test_name == 'total') {
continue;
}
if (!array_key_exists($test_name, $tests_known)) {
if (empty($test_results['body']['title']) || empty($test_results['body']['description'])) {
// @todo should this send a watchdog warning?
continue;
}
$test_data = array();
$test_data['machine_name'] = $test_name;
$test_data['severity'] = $severity;
$test_data['human_name'] = $test_results['body']['title'];
$test_data['description'] = $test_results['body']['description'];
$results = quail_api_save_test($test_data);
if ($results === FALSE) {
watchdog('node_accessibility', "Failed to insert :machine_name into quail api tests database table.", array(
':machine_name' => $test_name,
), WATCHDOG_ERROR);
continue;
}
// The row must be loaded from the database so that the id can be retrieved
$loaded_test = quail_api_load_tests(array(
'machine_name' => $test_name,
), NULL);
if (!isset($loaded_test['0']) || !is_object($loaded_test['0'])) {
watchdog('node_accessibility', "Failed to insert :machine_name problems into node accessibility tests database table because tests_known[:machine_name] is not a valid object.", array(
':machine_name' => $test_name,
), WATCHDOG_ERROR);
continue;
}
$tests_known[$test_name] = $loaded_test['0'];
}
foreach ($test_results['problems'] as $problem_name => $problem) {
if (empty($problem['line']) || empty($problem['element'])) {
// @todo should this send a watchdog warning?
continue;
}
$problem_data = array();
$problem_data['nid'] = $nid;
$problem_data['vid'] = $vid;
$problem_data['test_id'] = $tests_known[$test_name]->id;
$problem_data['line'] = $problem['line'];
$problem_data['element'] = $problem['element'];
$problems[] = $problem_data;
}
}
}
}
if (!empty($problems)) {
$results = node_accessibility_replace_problems($nid, $vid, $problems);
if ($results === FALSE) {
watchdog('node_accessibility', "Failed to insert :machine_name problems into node accessibility problems database table.", array(
':machine_name' => $test_name,
), WATCHDOG_ERROR);
}
}
}