You are here

function node_accessibility_save_problem in Node Accessibility 7

This stores a validation problem for a given node to the database.

Parameters

array $problem_data: An array of test data with the following keys:

  • nid: The node id of the node.
  • vid: The node revision id of the node.
  • test_id: The id of the problem.
  • line: The line number of the problem.
  • element: The html markup of the problem.

Return value

int|false The return states of either FALSE, SAVED_NEW, or SAVED_UPDATED.

1 call to node_accessibility_save_problem()
node_accessibility_replace_problems in ./node_accessibility.module
This stores validation problems for a single node to the database.

File

./node_accessibility.module, line 1066
Module file for the node accessibility project.

Code

function node_accessibility_save_problem($problem_data) {
  if (!is_array($problem_data)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('problem_data');
    }
    return FALSE;
  }
  $result = FALSE;
  $columns = array(
    'nid',
    'vid',
    'test_id',
    'line',
    'element',
  );
  foreach ($columns as $key) {
    if (empty($problem_data[$key])) {
      if (class_exists('cf_error')) {
        cf_error::missing_array_key('problem_data', $key);
      }
      return FALSE;
    }
  }
  $data = array();
  $primary_key = array();
  $results = FALSE;
  if (!empty($problem_data['id'])) {
    if (!is_numeric($problem_data['id'])) {
      if (class_exists('cf_error')) {
        cf_error::invalid_numeric('problem_data[id]');
      }
      return FALSE;
    }
    $results = node_accessibility_load_problems(array(
      'id' => $problem_data['id'],
    ), NULL);
    if (is_array($results) && !empty($results)) {
      $data['id'] = $problem_data['id'];
      $primary_key[] = 'id';
    }
    else {

      // if a specific id is requested but does not exist, then it cannot be updated.
      return FALSE;
    }
  }
  $data['nid'] = $problem_data['nid'];
  $data['vid'] = $problem_data['vid'];
  $data['test_id'] = $problem_data['test_id'];
  $data['line'] = $problem_data['line'];
  $data['element'] = $problem_data['element'];
  $result = drupal_write_record('node_accessibility_problems', $data, $primary_key);
  return $result;
}