/**
 * Obtain question fields for a QUIZ attempt with $acode id
 * @param MoodleQuickForm $mform
 * @param unknown_type $acode
 * @param unknown_type $jobid
 * @param unknown_type $warnings
 */
function display_questions(MoodleQuickForm $mform, $acode, $jobid, $warnings)
{
    $keys = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L');
    $rarray = array();
    $iarray = array();
    $keysarray = array();
    $iresponses = array();
    $labels = get_labels($acode, $jobid);
    //layout is the array with questions id. Warning does not correspond with actual order in page.
    $layout = get_layout($acode);
    $select = "activitycode={$acode} AND jobid={$jobid} AND label LIKE 'q%'";
    $options = get_records_select('blended_results', $select, 'page, id');
    /**
     * Convert to an array of questions
     */
    $questions = array();
    foreach ($options as $option) {
        $pos = strpos($option->label, '-');
        $qid = substr($option->label, 1, $pos - 1);
        $questions[$qid][] = $option;
    }
    $i = 1;
    $page = -1;
    /**
     * iterate according with the fieldset order
     */
    //	print_object($questions);die;
    //	foreach ($layout as $qid)
    foreach ($questions as $question) {
        //$question=$questions[(int)$qid];
        $optpage = $question[0]->page;
        if ($page != $optpage) {
            $page = $optpage;
            $mform->addElement('static', 'PAGE' . $page, get_string('page', 'blended') . ' ' . $page);
            $mform->addElement('html', '<hr/>');
        }
        //$idqs=select_question($labels,$numberofquestion,$acode);
        //	$defaults=get_question_values($question,$acode,$jobid);
        $returnvalues = create_question($mform, $i, $question, $keys, $warnings);
        //,$defaults->invalid);
        $invalid = $returnvalues->invalid;
        if (isset($returnvalues->radioindex)) {
            $radioindex = $returnvalues->radioindex;
        }
        if ($radioindex !== null) {
            $rarray[$radioindex] = 1;
        }
        //creo un array con los numeros radiobutton
        if ($invalid !== null) {
            $iarray[$radioindex] = 1;
            //$iresponses[$radioindex] = $defaults;
            $ilabels = get_ilabels($defaults);
            $iname = 'ilabel' . $radioindex;
            $mform->addElement('hidden', $iname, $ilabels);
        }
        $i++;
    }
    if (count($iarray) !== 0) {
        //print_object($iarray);
        print "<CENTER>Por favor, corrija manualmente las respuestas inválidas</CENTER>";
    }
    //print_object ($iarray);
    $keysarray = array_keys($rarray);
    $radiokeys = implode(',', $keysarray);
    $ikeysarray = array_keys($iarray);
    $invalidkeys = implode(',', $ikeysarray);
    //	print_object ($invalidkeys);
    //	print_object ($ilabels);
    $mform->addElement('hidden', 'radioindex', $radiokeys);
    if ($invalidkeys !== null) {
        $mform->addElement('hidden', 'invalidquestions', $invalidkeys);
    }
    return;
}
function create_category_from_json_array($data)
{
    $userName = (int) $_SESSION['userID'];
    $category_name = $data['category_name'];
    $number_of_exams = (int) $data['number_of_exams'];
    $catID = create_new_category($category_name, $number_of_exams);
    for ($i = 0; $i < $number_of_exams; $i++) {
        $examID = create_new_exam($data['exams'][$i]['exam_name'], $catID, $data['exams'][$i]['number_of_questions']);
        for ($y = 0; $y < $data['exams'][$i]['number_of_questions']; $y++) {
            $questionID = create_question($examID, $data['exams'][$i]['questions'][$y]['question_name'], $data['exams'][$i]['questions'][$y]['question_type'], $increment_questions = false);
            switch ($data['exams'][$i]['questions'][$y]['question_type']) {
                case 'single_answers':
                    create_single_answer($data['exams'][$i]['questions'][$y]['answers'], $questionID);
                    break;
                case 'mult_answers':
                    create_multiple_choice_answers_from_json($questionID, $data['exams'][$i]['questions'][$y]['answers']);
                    break;
                case 'keyword_answers':
                    create_keyword_answers($questionID, $data['exams'][$i]['questions'][$y]['answers']);
                    break;
            }
        }
    }
}
Beispiel #3
0
    method_not_allowed();
});
Flight::route('POST /single_use/auto_marking_test', function () {
    incl('test_auto_marking');
    test_auto_marking(Flight::request());
});
Flight::route('/single_use/auto_marking_test', function () {
    method_not_allowed();
});
Flight::route('POST /single_use/program_as_student_test', function () {
    incl('test_program_as_student');
    test_program_as_student(Flight::request());
});
Flight::route('/single_use/program_as_student_test', function () {
    method_not_allowed();
});
Flight::route('POST /single_use/auto_marking_sc_test', function () {
    incl('test_auto_marking_sc');
    test_auto_marking_sc(Flight::request());
});
Flight::route('/single_use/auto_marking_sc_test', function () {
    method_not_allowed();
});
Flight::route('POST /question_bank/questions', function () {
    incl('create_question');
    create_question(Flight::request());
});
Flight::route('/question_bank/questions', function () {
    method_not_allowed();
});
Flight::start();
/** J\"{a}rjest\"{a} kysymykset ajan mukaan
 * @param $end_array array
 * @param $tags_and_Qid array
 * @param $titles_and_Qid array
 * @param $titles array
 * @param $was_sent_at_times array
 * @param $usernames array
 * @param $user_ids array
 */
function organize_questions($end_array, $tags_and_Qid, $titles_and_Qid, $titles, $was_sent_at_times, $usernames, $user_ids)
{
    foreach ($end_array as $tags_and_Qid['question_id'] => $titles_and_Qid['title']) {
        // $title should be the actual string, not an array
        // $tags should be single, non-multidimensional array containing tag names
        // Grab the title
        $title = $titles[$tags_and_Qid['question_id']]['title'];
        // Grab the tags for the question
        $tags = $end_array[$tags_and_Qid['question_id']]['tag'];
        // Grab the username for the question
        $username = $usernames[$tags_and_Qid['question_id']]['username'];
        // Grab the user_id for the question
        $user_id = $user_ids[$tags_and_Qid['question_id']]['user_id'];
        // Grab the was_sent_at_time for the question
        $was_sent_at_time_unformatted = $was_sent_at_times[$tags_and_Qid['question_id']]['was_sent_at_time'];
        $was_sent_at_time_array = explode(" ", $was_sent_at_time_unformatted, 4);
        $was_sent_at_time = $was_sent_at_time_array[0];
        // Grap the question_id
        $question_id = $tags_and_Qid['question_id'];
        create_question($title, $tags, $question_id, $user_id, $username, $was_sent_at_time, "asked");
    }
}
<?php

session_start();
require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/sql_functions.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/session_functions.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/exam-simulator/private/functions/input.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $examID = fix_string($_POST['examID']);
    $question = fix_string($_POST['question']);
    $question_type = fix_string($_POST['questionType']);
    $questionID = create_question($examID, $question, $question_type);
    switch ($question_type) {
        case 'mult_answers':
            $json_assoc_array = json_decode($_POST['answers']);
            $mult_answers = fix_input_assoc_array($json_assoc_array);
            // assoc array e.g {answer : 'true'}
            create_multiple_choice_answers($questionID, $mult_answers);
            break;
        case 'single_answers':
            $answer = fix_string($_POST['answer']);
            create_single_answer($answer, $questionID);
            break;
        case 'keyword_answers':
            $keywords = json_decode($_POST['answers']);
            $keywords = fix_input_array($keywords);
            remove_non_alphanumeric($keywords);
            create_keyword_answers($questionID, $keywords);
            break;
    }
} else {
    go_home();