function tripal_featuremap_admin_validate

1.x tripal_featuremap.admin.inc tripal_featuremap_admin_validate($form, &$form_state)

Related topics

File

tripal_featuremap/includes/tripal_featuremap.admin.inc, line 222

Code

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

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

    // 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
    $featuremaps = $form_state['values']['featuremaps'];
    $do_all = FALSE;
    $to_sync = array();

    foreach ($featuremaps as $featuremap_id) {
      if (preg_match("/^all$/i", $featuremap_id)) {
        $do_all = TRUE;
      }
      if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
        // get the map info
        $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
        $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
        $to_sync[$featuremap_id] = $featuremap->name;
      }
    }

    // submit the job to the tripal job manager
    if ($do_all) {
      tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
    }
    else {
      foreach ($to_sync as $featuremap_id => $name) {
        $job_args[0] = $featuremap_id;
        tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Reindex Job if selected
  if ($form_state['values']['op'] == t('Reindex Features')) {
    $featuremaps = $form_state['values']['re-maps'];
    foreach ($featuremaps as $featuremap_id) {
      if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
        // get the map info
        $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
        $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
        $job_args[0] = $featuremap_id;
        tripal_add_job("Reindex features for map: $featuremap->name", 'tripal_featuremap', 
        'tripal_featuremap_reindex_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Taxonomy Job if selected
  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
    $featuremaps = $form_state['values']['tx-maps'];
    foreach ($featuremaps as $featuremap_id) {
      if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
        // get the map info
        $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
        $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
        $job_args[0] = $featuremap_id;
        tripal_add_job("Set taxonomy for features in map: $featuremap->name", 'tripal_featuremap', 
        'tripal_featuremap_taxonify_features', $job_args, $user->uid);
      }
    }
  }
  // -------------------------------------
  // Submit the Cleanup Job if selected
  if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
    tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap', 
    'tripal_featuremap_cleanup', $job_args, $user->uid);
  }
}