You are here

function quiz_question_revision_actions in Quiz 7.4

Same name and namespace in other branches
  1. 8.4 question_types/quiz_question/quiz_question.pages.inc \quiz_question_revision_actions()
  2. 6.4 question_types/quiz_question/quiz_question.pages.inc \quiz_question_revision_actions()
  3. 7 question_types/quiz_question/quiz_question.pages.inc \quiz_question_revision_actions()

Create the form for the revision actions page

Form for deciding what to do with the quizzes a question is member of when the question is revised

Parameters

$form_state:

$nid: Question node id

$vid: Question node version id

Return value

FAPI form array

2 string references to 'quiz_question_revision_actions'
QuizQuestion::save in question_types/quiz_question/quiz_question.core.inc
Responsible for handling insert/update of question-specific data. This is typically called from within the Node API, so there is no need to save the node.
quiz_question_menu in question_types/quiz_question/quiz_question.module
Implements hook_menu().

File

question_types/quiz_question/quiz_question.pages.inc, line 22
User page callbacks for the quiz_question module.

Code

function quiz_question_revision_actions($form, $form_state, $nid, $vid) {

  // If no questions were kept we shouldn't get here...
  if (!isset($_SESSION['quiz_question_kept'])) {
    drupal_goto('node/' . $nid);
  }
  $form = array();
  $form['q_nid'] = array(
    '#type' => 'value',
    '#value' => intval($nid),
  );
  $form['q_vid'] = array(
    '#type' => 'value',
    '#value' => intval($vid),
  );

  // Fetch data for all the quizzes that was kept
  $quiz_nids = array();
  $quiz_vids = array();
  foreach ($_SESSION['quiz_question_kept'] as $nid_vid) {
    $temp = explode('-', $nid_vid);
    if (_quiz_is_int($temp[0], 0) && _quiz_is_int($temp[1], 0)) {
      $quiz_nids[] = $temp[0];
      $quiz_vids[] = $temp[1];
    }
  }
  $quizzes = array();
  $sql = 'SELECT nr.nid, nr.vid, nr.title, n.status FROM {node_revision} nr
          JOIN {node} n ON n.nid = nr.nid
          WHERE nr.vid IN (:vids)';
  $res = db_query($sql, array(
    ':vids' => $quiz_vids,
  ));

  //while ($res_o = db_fetch_object($res)) {
  foreach ($res as $res_o) {
    $res_o->answered = quiz_has_been_answered($res_o);
    $quizzes[] = $res_o;
  }
  $text = t('You have created a new revision of a question that belongs to %num quizzes. Choose what you want to do with the different quizzes.', array(
    '%num' => count($quizzes),
  ));
  $form['intro'] = array(
    '#markup' => $text,
  );
  $form['quizzes'] = array();

  // Create a form element for each quiz
  foreach ($quizzes as $quiz) {
    $published = $quiz->status == 1 ? t('published') : t('unpublished');
    $answered = $quiz->answered ? t('answered') : t('unanswered');

    // We fetch the revision options from a helper function
    $options = _quiz_question_revision_options($quiz->status == 1, $quiz->answered);
    $form['quizzes'][$quiz->nid . '-' . $quiz->vid . '-' . $quiz->status . '-' . ($quiz->answered ? '1' : '0')] = array(
      '#type' => 'radios',
      '#title' => check_plain($quiz->title) . ' (' . $published . ' ' . t('and') . ' ' . $answered . ')',
      '#default_value' => $options['default'],
      '#options' => $options['options'],
    );
    $form['quizzes'][$quiz->vid]['#quiz_title'] = $quiz->title;
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  $form['#submit'] = array(
    'quiz_question_revision_actions_submit',
  );

  // Help texts
  $form['update_expl'] = array(
    '#type' => 'item',
    '#title' => t('Update'),
    '#value' => t('Replace the old revision of the question with the new revision.'),
  );
  $form['revise_expl'] = array(
    '#type' => 'item',
    '#title' => t('Revise'),
    '#value' => t('If a quiz has been answered you should make a new revision to ensure that existing answer statistics and reports remain correct.'),
    '#description' => t('If the new revision of the question only correct spelling errors etc. you don\'t need to revise.'),
  );
  return $form;
}