You are here

function questions_import_form in Quiz 6.6

Same name and namespace in other branches
  1. 6.3 includes/questions_import/questions_import.admin.inc \questions_import_form()

@function Implementation of hook_form() provides form to upload questions

Return value

FAPI form array

1 string reference to 'questions_import_form'
questions_import_menu in includes/questions_import/questions_import.module

File

includes/questions_import/questions_import.admin.inc, line 37
Administration file for Questions Import module

Code

function questions_import_form() {

  // hook_init() includes the CSS and JS to create hide/show effect in form.
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  $form['quiz_destination'] = array(
    '#type' => 'fieldset',
    '#title' => t('Questions destination'),
    '#collapse' => FALSE,
  );
  $form['quiz_destination']['destination_type'] = array(
    '#type' => 'select',
    '#title' => t('Import destination'),
    // TODO option for existing item collection
    '#options' => array(
      'new_qcollection' => t('New item collection'),
      'new_quiz' => t('New quiz'),
      'existing_quiz' => t('Existing quiz'),
    ),
    '#required' => TRUE,
  );
  $form['quiz_destination']['destination_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Name of new node'),
    '#default_value' => t('<unnamed>'),
    '#description' => t('Name for the new quiz or item collection'),
    '#size' => 30,
    '#required' => TRUE,
  );
  $options = quiz_get_all_quiz_title();

  // $options is an array with nid as index and quiz node's title as value
  $form['quiz_destination']['quiz_node'] = array(
    '#type' => 'select',
    '#title' => t('Existing quiz'),
    '#options' => $options,
    '#description' => count($options) ? t('Select the quiz node for which you want to add questions') : t('No quiz contents where found. To !create_a_quiz go to Content Management -> Create Content -> Quiz.', array(
      '!create_a_quiz' => l(t('create a quiz'), 'node/add/quiz'),
    )),
  );
  $form['quiz_import'] = array(
    '#type' => 'fieldset',
    '#title' => t('Questions source'),
    '#description' => t('Questions import module allows the user with role "quiz author" to create a bulk of questions from portable text file (like CSV, XML etc) where questions are defined in some predefined format.'),
    '#collapse' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['quiz_import']['import_type'] = array(
    '#type' => 'select',
    '#title' => t('Import type'),
    '#options' => questions_import_type(),
    '#description' => t('Select the import type (sample files !csv, !aiken, !gift, !learnwise, !qti_v1p2)', questions_import_get_sample_file_link()),
    '#required' => TRUE,
  );
  $form['quiz_import']['field_separator'] = array(
    '#type' => 'textfield',
    '#title' => t('CSV Field Separator'),
    '#default_value' => t(','),
    '#description' => t('Special character used to separator the fields usually , : or ; '),
    '#size' => 1,
  );

  //'upload' index will be used in file_check_upload()
  $form['quiz_import']['upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload'),
    '#size' => 30,
    '#description' => t('Upload the file that has quiz questions'),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $formats = filter_formats();
  foreach ($formats as $info) {
    $format_options[$info->format] = $info->name;
  }
  $form['advanced']['input_format'] = array(
    '#type' => 'select',
    '#title' => t('Input format'),
    '#options' => $format_options,
    '#required' => TRUE,
  );
  $form['advanced']['ignore_filename_extensions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore filename extension'),
    '#default_value' => FALSE,
    '#description' => t('Normally this form checks that the suffix of the uploaded file.  This allows you to skip that.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  $form['#validate'][] = 'questions_import_form_validate';
  $form['#submit'][] = 'questions_import_form_submit';
  return $form;
}