You are here

function node_accessibility_replace_problems in Node Accessibility 7

This stores validation problems for a single node to the database.

This will delete all pre-existing problems for the given node.

Parameters

int $nid: The node id.

int $vid: The node revision id.

array $problems: An array of arrays of test data containing the test problems

  • each nested array should containt 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_replace_problems()
node_accessibility_save_node_problems in ./node_accessibility.module
Saves the node report data to the database.

File

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

Code

function node_accessibility_replace_problems($nid, $vid, $problems) {
  if (!is_numeric($nid)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_numeric('nid');
    }
    return FALSE;
  }
  if (!is_numeric($vid)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_numeric('vid');
    }
    return FALSE;
  }
  if (!is_array($problems)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_array('problems');
    }
    return FALSE;
  }
  $result = FALSE;
  $transaction = db_transaction();
  try {
    $query = db_delete('node_accessibility_problems');
    $query
      ->condition('nid', $nid);
    $query
      ->condition('vid', $vid);
    $query
      ->execute();
    foreach ($problems as $problem) {
      $result = node_accessibility_save_problem($problem);

      // @todo handle return errors
    }

    // force transaction to execute
    unset($transaction);
  } catch (Exception $e) {
    $transaction
      ->rollback();
    if (class_exists('cf_error')) {
      cf_error::on_query_execution($e);
    }
    return FALSE;
  }
  return $result;
}