atr_form_review

Versions
6.1
atr_form_review()

Form builder; manually configure and start a text review.

Code

atr/includes/atr.admin.inc, line 25

<?php
function atr_form_review() {
  drupal_add_js(drupal_get_path('module', 'atr') . '/js/atr.js');
  drupal_add_css(drupal_get_path('module', 'atr') . '/css/atr.css');

  $form = array(
    // The form may contain file uploads.
    '#attributes' => array('enctype' => "multipart/form-data"),
  );

  // If certain conditions haven't been met, disable the submit button.
  $disabled = FALSE;

  // Source selector.
  $source_info = module_invoke_all('atr_source_info');
  if (count($source_info)) {
    // Render a fieldset and checkbox for every text source.
    foreach ($source_info as $name => $source) {
      $form[$name] = array(
        '#type' => 'fieldset',
        '#title' => $source,
      );
      $form[$name][$name . '_toggle'] = array(
        '#type' => 'checkbox',
        '#title' => t('Extract texts from @text_source.', array('@text_source' => $source)),
        '#attributes' => array(
          'class' => 'atr-settings-toggle',
        ),
      );
      $form[$name]['settings'] = array(
        '#prefix' => '<div class="edit-' . $name . '-toggle js-hide">',
        '#suffix' => '</div>',
      );
    }
  }
  else {
    drupal_set_message(t('You have yet no text sources to use for this review. Please <a href="!modules">enable modules</a> that provide them.', array('!modules' => url('admin/build/modules'))), 'warning');
    $disabled = TRUE;
  }

  // Settings profile selector.
  $result = db_query("SELECT pid FROM {atr_profile} ORDER BY title ASC");
  $profile_options = array();
  $profile_language = array();
  while ($profile = atr_profile_load(db_result($result))) {
    if ($profile->methods) {
      $title = theme('atr_profile', $profile);
      $profile_options[$profile->pid] = $title;
      $profile_language[$profile->pid] = $profile->language;
    }
  }
  $first_profile_pid = end(array_flip(array_reverse($profile_options, TRUE)));
  $count = count($profile_options);
  if ($count > 1) {
    $form['pid'] = array(
      '#type' => 'radios',
      '#title' => t('Settings profile'),
      '#options' => $profile_options,
      '#default_value' => $first_profile_pid,
    );
  }
  elseif ($count == 1) {
    $form['pid'] = array(
      '#type' => 'value',
      '#value' => array_pop(array_flip($profile_options)),
    );
    $form['profile_label'] = array(
      '#type' => 'item',
      '#title' => t('Settings profile'),
      '#description' => t('<a href="@settings">Settings profiles</a> define how to review texts.', array('@settings' => url('atr/profile'))),
      '#value' => array_pop($profile_options),
    );
  }
  else {
    drupal_set_message(t('You have yet no <a href="@profile_add">settings profile</a> to use for this review.', array('@profile_add' => url('atr/profile/add'))), 'warning');
    $disabled = TRUE;
  }

  $languages = atr_languages();
  if (!in_array('zxx', $profile_language)) {
    $languages = array_intersect_key($languages, array_flip($profile_language));
  }
  drupal_add_js(array('atrProfileLanguage' => $profile_language), 'setting');
  $form['language'] = array(
    '#type' => 'select',
    '#title' => t('Text language'),
    '#options' => array_merge(array('zxx' => '<' . t('none') . '>'), $languages),
    '#default_value' => $profile_language[$first_profile_pid],
    '#required' => TRUE,
    '#disabled' => $profile_language[$first_profile_pid] != 'zxx',
  );

  $form['start'] = array(
    '#type' => 'submit',
    '#value' => t('Start review'),
    '#disabled' => $disabled,
  );

  return $form;
}
?>