function chado_library_validate

2.x tripal_library.chado_node.inc chado_library_validate($node, $form, &$form_state)
3.x tripal_library.chado_node.inc chado_library_validate($node, $form, &$form_state)
1.x tripal_library.module chado_library_validate($node)

Implements hook_validate().

Validates submission of form when adding or updating a library node

Related topics

File

legacy/tripal_library/includes/tripal_library.chado_node.inc, line 229
Implements the library node content type

Code

function chado_library_validate($node, $form, &$form_state) {

  // We only want to validate when the node is saved.
  // Since this validate can be called on AJAX and Deletion of the node
  // we need to make this check to ensure queries are not executed
  // without the proper values.
  if (property_exists($node, "op") and $node->op != 'Save') {
    return;
  }

  // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
  // need to validate during syncing so just skip it.
  if (!property_exists($node, 'nid') and property_exists($node, 'library_id') and $node->library_id != 0) {
    return;
  }

  // trim white space from text fields
  $node->libraryname = property_exists($node, 'libraryname') ? trim($node->libraryname) : '';
  $node->uniquename = property_exists($node, 'uniquename') ? trim($node->uniquename) : '';

  $lib = 0;
  // check to make sure the unique name on the library is unique
  // before we try to insert into chado.
  if (property_exists($node, 'library_id')) {
    $sql = "
      SELECT *
      FROM {library}
      WHERE uniquename = :uname AND NOT library_id = :library_id
    ";
    $lib = chado_query($sql, array(':uname' => $node->uniquename, ':library_id' => $node->library_id))->fetchObject();
  }
  else {
    $sql = "SELECT * FROM {library} WHERE uniquename = :uname";
    $lib = chado_query($sql, array(':uname' => $node->uniquename))->fetchObject();
  }
  if ($lib) {
    form_set_error('uniquename', t('The unique library name already exists. Please choose another'));
  }
}