function get_tripal_organism_admin_form_sync_set

1.x tripal_organism.admin.inc get_tripal_organism_admin_form_sync_set(&$form)

Related topics

1 call to get_tripal_organism_admin_form_sync_set()
tripal_organism_admin in tripal_organism/includes/tripal_organism.admin.inc
Administrative settings for chado_orgnism

File

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

Code

function get_tripal_organism_admin_form_sync_set(&$form) {
  // define the fieldsets
  $form['sync'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sync Organisms')
  );

  // before proceeding check to see if we have any
  // currently processing jobs. If so, we don't want
  // to give the opportunity to sync libraries
  $active_jobs = FALSE;
  if (tripal_get_module_active_jobs('tripal_organism')) {
    $active_jobs = TRUE;
  }

  if (!$active_jobs) {

    // get the list of organisms
    $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
    $org_rset = chado_query($sql);

    // if we've added any organisms to the list that can be synced
    // then we want to build the form components to allow the user
    // to select one or all of them.  Otherwise, just present
    // a message stating that all organisms are currently synced.
    $org_boxes = array();
    $added = 0;
    while ($organism = db_fetch_object($org_rset)) {
      // check to see if the organism is already present as a node in drupal.
      // if so, then skip it.
      $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d";
      if (!db_fetch_object(db_query($sql, $organism->organism_id))) {
        $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
        $added++;
      }
    }

    // if we have organisms we need to add to the checkbox then
    // build that form element
    if ($added > 0) {
      $org_boxes['all'] = "All Organisms";

      $form['sync']['organisms'] = array(
        '#title' => t('Available Organisms'),
        '#type' => t('checkboxes'),
        '#description' => t("Check the organisms you want to sync.  Drupal content will be created for each of the organisms listed above.  Select 'All Organisms' to sync all of them."),
        '#required' => FALSE,
        '#prefix' => '<div id="org_boxes">',
        '#suffix' => '</div>',
        '#options' => $org_boxes,
      );
      $form['sync']['button'] = array(
        '#type' => 'submit',
        '#value' => t('Submit Sync Job')
      );
    }
    // we don't have any organisms to select from
    else {
      $form['sync']['value'] = array(
        '#value' => t('All organisms in Chado are currently synced with Drupal.')
      );
    }
  }
  // we don't want to present a form since we have an active job running
  else {
    $form['sync']['value'] = array(
      '#value' => t('Currently, jobs exist related to chado organisms. Please check back later for organisms that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
    );
  }
}