function tripal_organism_admin_validate

2.x tripal_organism.admin.inc tripal_organism_admin_validate($form, &$form_state)
3.x tripal_organism.admin.inc tripal_organism_admin_validate($form, &$form_state)
1.x tripal_organism.admin.inc tripal_organism_admin_validate($form, &$form_state)

Related topics

File

tripal_organism/includes/tripal_organism.admin.inc, line 229

Code

function tripal_organism_admin_validate($form, &$form_state) {
  global $user; // we need access to the user info
  $job_args = array();

  if ($form_state['values']['op'] == t('Submit Sync Job')) {

    // check to see if the user wants to sync chado and drupal.  If
    // so then we need to register a job to do so with tripal
    $organisms = $form_state['values']['organisms'];
    $do_all = FALSE;
    $to_sync = array();

    foreach ($organisms as $organism_id) {
      if (preg_match("/^all$/i", $organism_id)) {
        $do_all = TRUE;
      }
      if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
        // get the list of organisms
        $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
        $organism = db_fetch_object(chado_query($sql, $organism_id));
        $to_sync[$organism_id] = "$organism->genus $organism->species";
      }
    }

    // submit the job the tripal job manager
    if ($do_all) {
      tripal_add_job('Sync all organisms', 'tripal_organism', 
      'tripal_organism_sync_organisms', $job_args, $user->uid);
    }
    else {
      foreach ($to_sync as $organism_id => $name) {
        $job_args[0] = $organism_id;
        tripal_add_job("Sync organism: $name", 'tripal_organism', 
        'tripal_organism_sync_organisms', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Reindex Job if selected
  if ($form_state['values']['op'] == t('Reindex Features')) {
    $organisms = $form_state['values']['re-organisms'];
    foreach ($organisms as $organism_id) {
      if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
        // get the organism info
        $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
        $organism = db_fetch_object(chado_query($sql, $organism_id));
        $job_args[0] = $organism_id;
        tripal_add_job("Reindex features for organism: $organism->genus " .
        "$organism->species", 'tripal_organism', 
        'tripal_organism_reindex_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the taxonomy Job if selected
  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
    $organisms = $form_state['values']['tx-organisms'];
    foreach ($organisms as $organism_id) {
      if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
        // get the organism info
        $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
        $organism = db_fetch_object(chado_query($sql, $organism_id));
        $job_args[0] = $organism_id;
        tripal_add_job("Set taxonomy for features in organism: " .
          "$organism->genus $organism->species", 'tripal_organism', 
        'tripal_organism_taxonify_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Cleanup Job if selected
  if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
    tripal_add_job('Cleanup orphaned organisms', 'tripal_organism', 
    'tripal_organism_cleanup', $job_args, $user->uid);
  }
}