function get_tripal_project_admin_form_sync_set

1.x tripal_project.admin.inc get_tripal_project_admin_form_sync_set(&$form)

Related topics

1 call to get_tripal_project_admin_form_sync_set()
tripal_project_admin in tripal_project/includes/tripal_project.admin.inc

File

tripal_project/includes/tripal_project.admin.inc, line 66
@todo Add file header description

Code

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

  // 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_project')) {
    $active_jobs = TRUE;
  }

  if (!$active_jobs) {

    // get the list of projects
    $sql = "SELECT * FROM {project} ORDER BY name";
    $org_rset = chado_query($sql);

    // if we've added any projects 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 projects are currently synced.
    $proj_boxes = array();
    $added = 0;
    while ($project = db_fetch_object($org_rset)) {
      // check to see if the project is already present as a node in drupal.
      // if so, then skip it.
      $sql = "SELECT * FROM {chado_project} WHERE project_id = %d";
      if (!db_fetch_object(db_query($sql, $project->project_id))) {
        $proj_boxes[$project->project_id] = $project->name;
        $added++;
      }
    }

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

      $form['sync']['projects'] = array(
        '#title' => t('Available Projects'),
        '#type' => t('checkboxes'),
        '#description' => t("Check the projects you want to sync.  Drupal content will be created for each of the projects listed above.  Select 'All Projects' to sync all of them."),
        '#required' => FALSE,
        '#prefix' => '<div id="org_boxes">',
        '#suffix' => '</div>',
        '#options' => $proj_boxes,
      );
      $form['sync']['button'] = array(
        '#type' => 'submit',
        '#value' => t('Submit Sync Job')
      );
    }
    // we don't have any projects to select from
    else {
      $form['sync']['value'] = array(
        '#value' => t('All projects 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 projects. Please check back later for projects that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
    );
  }
}