You are here

function questions_import_validate_aiken in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 includes/questions_import/questions_import.admin.inc \questions_import_validate_aiken()
1 call to questions_import_validate_aiken()
questions_import_form_validate in includes/questions_import/questions_import.admin.inc

File

includes/questions_import/questions_import.admin.inc, line 189

Code

function questions_import_validate_aiken($file, $separator, $question_type) {
  $error_msg = '';
  $row = 0;
  $lines = file($file->filepath);
  if (empty($lines) || count($lines) < 4) {
    return '<p>' . t('Invalid number of lines or no lines were found in @filename.', array(
      '@filename' => $file->filename,
    )) . '</p>';
  }
  if ($question_type = 'multichoice') {
    while (!empty($lines)) {

      // while not empty of file content
      while ($current_line = trim(array_shift($lines))) {
        if (empty($current_line)) {
          break;
        }
        $line[] = $current_line;
      }

      // it should have read a questions, choices and its correct answer
      if (count($line) < 4) {
        $error_msg .= '<p>' . t('Error around line : @line_number', array(
          '@line_number' => $row,
        )) . '</p>';
      }
      $answer = trim(array_pop($line));
      if (stristr($answer, 'ANSWER') === FALSE) {
        $error_msg .= '<p>' . t('Error around line : @line_number', array(
          '@line_number' => $row,
        )) . '</p>';
      }

      // now $line is left only with choices which looks like A) Moodle B) ATutor C) Claroline D) Blackboard etc

      /*  foreach ($line as $l) {
          // yet to add more validation code
          } */
      ++$row;
    }
  }
  $error_msg .= !empty($error_msg) ? '<p>' . t('Aiken Import Failed. These lines were found to have an invalid number of fields in @filename.', array(
    '@filename' => $file->filename,
  )) . '</p>' : '';
  return $error_msg;
}