public function OBOImporter::formValidate

3.x OBOImporter.inc public OBOImporter::formValidate($form, &$form_state)

Overrides TripalImporter::formValidate

See also

TripalImporter::formValidate()

File

tripal_chado/includes/TripalImporter/OBOImporter.inc, line 320

Class

OBOImporter

Code

public function formValidate($form, &$form_state) {
  $obo_id = $form_state['values']['obo_id'];
  $obo_name = trim($form_state['values']['obo_name']);
  $obo_url = trim($form_state['values']['obo_url']);
  $obo_file = trim($form_state['values']['obo_file']);
  $uobo_name = array_key_exists('uobo_name', $form_state['values']) ? trim($form_state['values']['uobo_name']) : '';
  $uobo_url = array_key_exists('uobo_url', $form_state['values']) ? trim($form_state['values']['uobo_url']) : '';
  $uobo_file = array_key_exists('uobo_file', $form_state['values']) ? trim($form_state['values']['uobo_file']) : '';

  // Make sure if the name is changed it doesn't conflict with another OBO.
  if ($form_state['clicked_button']['#name'] == 'update_obo_details' or 
    $form_state['clicked_button']['#name'] == 'update_load_obo') {
    // Get the current record
    $vocab = db_select('tripal_cv_obo', 't')
      ->fields('t', array('obo_id', 'name', 'path'))
      ->condition('name', $uobo_name)
      ->execute()
      ->fetchObject();
    if ($vocab and $vocab->obo_id != $obo_id) {
      form_set_error('uobo_name', 'The vocabulary name must be different from existing vocabularies');
    }
    // Make sure the file exists. First check if it is a relative path
    $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $uobo_file;
    if (!file_exists($dfile)) {
      if (!file_exists($uobo_file)) {
        form_set_error('uobo_file', 'The specified path does not exist or cannot be read.');
      }
    }
    if (!$uobo_url and !$uobo_file) {
      form_set_error('uobo_url', 'Please provide a URL or a path for the vocabulary.');
    }
    if ($uobo_url and $uobo_file) {
      form_set_error('uobo_url', 'Please provide only a URL or a path for the vocabulary, but not both.');
    }
  }
  if ($form_state['clicked_button']['#name'] == 'add_new_obo') {
    // Get the current record
    $vocab = db_select('tripal_cv_obo', 't')
      ->fields('t', array('obo_id', 'name', 'path'))
      ->condition('name', $obo_name)
      ->execute()
      ->fetchObject();
    if ($vocab) {
      form_set_error('obo_name', 'The vocabulary name must be different from existing vocabularies');
    }
    // Make sure the file exists. First check if it is a relative path
    $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $obo_file;
    if (!file_exists($dfile)) {
      if (!file_exists($obo_file)) {
        form_set_error('obo_file', 'The specified path does not exist or cannot be read.');
      }
    }
    if (!$obo_url and !$obo_file) {
      form_set_error('obo_url', 'Please provide a URL or a path for the vocabulary.');
    }
    if ($obo_url and $obo_file) {
      form_set_error('obo_url', 'Please provide only a URL or a path for the vocabulary, but not both.');
    }
  }
}