当前位置: 首页>>代码示例>>PHP>>正文


PHP Answer::selectNbrAnswers方法代码示例

本文整理汇总了PHP中Answer::selectNbrAnswers方法的典型用法代码示例。如果您正苦于以下问题:PHP Answer::selectNbrAnswers方法的具体用法?PHP Answer::selectNbrAnswers怎么用?PHP Answer::selectNbrAnswers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Answer的用法示例。


在下文中一共展示了Answer::selectNbrAnswers方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Answer

?>
<table border="0" align="center" cellpadding="2" cellspacing="2" width="100%">
<h4>
  <?php 
echo "Add Feedback";
?>
</h4>
<?php 
$id = $_REQUEST['question'];
$objQuestionTmp = Question::read($id);
echo "<tr><td><b>" . get_lang('Question') . " : </b>";
echo $objQuestionTmp->selectTitle();
echo "</td></tr>";
echo " <br><tr><td><b><br>" . get_lang('Answer') . " : </b></td></tr>";
$objAnswerTmp = new Answer($id);
$num = $objAnswerTmp->selectNbrAnswers();
$objAnswerTmp->read();
for ($i = 1; $i <= $num; $i++) {
    echo "<tr><td width='10%'> ";
    $ans = $objAnswerTmp->answer[$i];
    $form = new FormValidator('feedbackform', 'post', api_get_self() . "?" . api_get_cidreq() . "&modifyQuestion=" . $modifyQuestion . "&newQuestion=" . $newQuestion);
    $obj_registration_form = new HTML_QuickForm('frmRegistration', 'POST');
    $renderer =& $obj_registration_form->defaultRenderer();
    $renderer->setElementTemplate('<tr>
	<td align="left" style="" valign="top" width=30%>{label}
		<!-- BEGIN required --><span style="color: #ff0000">*</span><!-- END required -->
	</td>
	<td align="left" width=70%>{element}
		<!-- BEGIN error --><br /><span style="color: #ff0000;font-size:10px">{error}</span><!-- END error -->
	</td>
</tr>');
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:feedback.php

示例2: elseif

                        <td valign='top'><b>$langComment</b></td>
                        </tr>";
        } elseif ($answerType == FILL_IN_BLANKS || $answerType == FILL_IN_BLANKS_TOLERANT) {
            echo "<tr>
                        <td class='even'><b>$langAnswer</b></td>
                        </tr>";
        } else {
            echo "<tr class='even'>
                        <td><b>$langElementList</b></td>
                        <td><b>$langCorrespondsTo</b></td>
                        </tr>";
        }
    }
    // construction of the Answer object
    $objAnswerTmp = new Answer($questionId);
    $nbrAnswers = $objAnswerTmp->selectNbrAnswers();

    for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
        $answer = $objAnswerTmp->selectAnswer($answerId);
        $answerComment = $objAnswerTmp->selectComment($answerId);
        $answerCorrect = $objAnswerTmp->isCorrect($answerId);
        $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
        // support for math symbols
        $answer = mathfilter($answer, 12, "$webDir/courses/mathimg/");
        $answerComment = mathfilter($answerComment, 12, "$webDir/courses/mathimg/");

        switch ($answerType) {
            // for unique answer
            case UNIQUE_ANSWER : $studentChoice = ($choice == $answerId) ? 1 : 0;
                if ($studentChoice) {
                    $questionScore+=$answerWeighting;
开发者ID:nikosv,项目名称:openeclass,代码行数:31,代码来源:showExerciseResult.php

示例3: successRate

 /**
  *
  * Calculate Question success rate
  */        
 function successRate($exerciseId = NULL) {
     $id = $this->id;
     $type = $this->type;           
     $objAnswerTmp = new Answer($id);
     $nbrAnswers = $objAnswerTmp->selectNbrAnswers();               
     $q_correct_answers_sql = '';
     $q_incorrect_answers_sql = '';
     $extra_sql = '';
     $query_vars = array($id, ATTEMPT_COMPLETED);         
     if(isset($exerciseId)) {
         $extra_sql = " AND b.eid = ?d";
         $query_vars[] = $exerciseId;
     }         
     $total_answer_attempts = Database::get()->querySingle("SELECT COUNT(DISTINCT a.eurid) AS count
             FROM exercise_answer_record a, exercise_user_record b
             WHERE a.eurid = b.eurid AND a.question_id = ?d AND b.attempt_status=?d$extra_sql", $query_vars)->count;
     
     //BUILDING CORRECT ANSWER QUERY BASED ON QUESTION TYPE
     if($type == UNIQUE_ANSWER || $type == MULTIPLE_ANSWER || $type == TRUE_FALSE){ //works wrong for MULTIPLE_ANSWER                           
         $i=1;
         for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
             if ($objAnswerTmp->isCorrect($answerId)) {
                 $q_correct_answers_sql .= ($i!=1) ? ' OR ' : '';
                 $q_correct_answers_sql .= 'a.answer_id = '.$objAnswerTmp->selectPosition($answerId);
                 $q_incorrect_answers_sql .= ($i!=1) ? ' AND ' : '';  
                 $q_incorrect_answers_sql .= 'a.answer_id != '.$objAnswerTmp->selectPosition($answerId);                                         
                 $i++;                        
             }
         }
         $q_correct_answers_cnt = $i-1;
     } elseif ($type == MATCHING) { // to be done
             $i = 1;
             for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                 //must get answer id ONLY where correct value existS
                 $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                 if ($answerCorrect) {
                     $q_correct_answers_sql .= ($i!=1) ? " OR " : "";
                     $q_correct_answers_sql .= "(a.answer = $answerId AND a.answer_id = $answerCorrect)";
                     $q_incorrect_answers_sql .= ($i!=1) ? " OR " : "";
                     $q_incorrect_answers_sql .= "(a.answer = $answerId AND a.answer_id != $answerCorrect)";                            
                     $i++;
                 }
             }
             $q_correct_answers_cnt = $i-1;
     } elseif ($type == FILL_IN_BLANKS || $type == FILL_IN_BLANKS_TOLERANT) { // Works Great                              
        $answer_field = $objAnswerTmp->selectAnswer($nbrAnswers);
        //splits answer string from weighting string
        list($answer, $answerWeighting) = explode('::', $answer_field);
        //getting all matched strings between [ and ] delimeters
        preg_match_all('#(?<=\[)(?!/?m)[^\]]+#', $answer, $match);
        $i=1;
        $sql_binary_comparison = $type == FILL_IN_BLANKS ? 'BINARY ' : '';
        foreach ($match[0] as $answers){
             $correct_answers = preg_split('/\s*,\s*/', $answers);
             $j=1;
             $q_correct_answers_sql .= ($i!=1) ? ' OR ' : '';
             $q_incorrect_answers_sql .= ($i!=1) ? ' OR ' : '';
             foreach ($correct_answers as $value){
                 $q_correct_answers_sql .= ($j!=1) ? ' OR ' : '';
                 $q_correct_answers_sql .= "(a.answer = $sql_binary_comparison'$value' AND a.answer_id = $i)";
                 $q_incorrect_answers_sql .= ($j!=1) ? ' AND ' : '';                     
                 $q_incorrect_answers_sql .= "(a.answer != $sql_binary_comparison'$value' AND a.answer_id = $i)";
                 $j++;
             }                    
             $i++;
        }
        $q_correct_answers_cnt = $i-1;
     }
     //FIND CORRECT ANSWER ATTEMPTS
     if ($type == FREE_TEXT) {
         // This query gets answers which where graded with queston maximum grade
         $correct_answer_attempts = Database::get()->querySingle("SELECT COUNT(DISTINCT a.eurid) AS count
                 FROM exercise_answer_record a, exercise_user_record b, exercise_question c
                 WHERE a.eurid = b.eurid AND a.question_id = c.id AND a.weight=c.weight AND a.question_id = ?d AND b.attempt_status=?d$extra_sql", $query_vars)->count;                           
     } else {
         // One Query to Rule Them All (except free text questions)
         // This query groups attempts and counts correct and incorrect answers
         // then counts attempts where (correct answers == total anticipated correct attempts)
         // and (incorrect answers == 0) (this control is necessary mostly in cases of MULTIPLE ANSWER type)               
         if ($q_correct_answers_cnt > 0) {
             $correct_answer_attempts = Database::get()->querySingle("
                 SELECT COUNT(*) AS counter FROM(
                     SELECT a.eurid, 
                     SUM($q_correct_answers_sql) as correct_answer_cnt,
                     SUM($q_incorrect_answers_sql) as incorrect_answer_cnt
                     FROM exercise_answer_record a, exercise_user_record b
                     WHERE a.eurid = b.eurid AND a.question_id = ?d AND b.attempt_status = ?d$extra_sql
                     GROUP BY(a.eurid) HAVING correct_answer_cnt = $q_correct_answers_cnt AND incorrect_answer_cnt = 0
                 )sub", $query_vars)->counter;
         } else {
             $correct_answer_attempts = 0;
         }
     }
     if ($total_answer_attempts>0) {
         $successRate = round($correct_answer_attempts/$total_answer_attempts*100, 2);
     } else {
//.........这里部分代码省略.........
开发者ID:nikosv,项目名称:openeclass,代码行数:101,代码来源:question.class.php

示例4: showQuestion

    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $origin  i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool   $show_title
     * @param bool   $freeze
     * @param array  $user_choice
     * @param bool   $show_comment
     * @param bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">
                           <table class="data_table">';
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                    if ($answerCorrect == 0) {
                        // options (A, B, C, ...) that will be put into the list-box
                        // have the "correct" field set to 0 because they are answer
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $letter++;
                    }
                }
                $i = 1;
                $select_items[0]['id'] = 0;
                $select_items[0]['letter'] = '--';
                $select_items[0]['answer'] = '';
                foreach ($answer_matching as $id => $value) {
                    $select_items[$i]['id'] = $value['id_auto'];
                    $select_items[$i]['letter'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
                    foreach ($user_choice as $item) {
                        $user_choice_array_position[$item['position']] = $item['answer'];
//.........这里部分代码省略.........
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.lib.php

示例5: manage_answer

 /**
  * This function was originally found in the exercise_show.php
  * @param int       $exeId
  * @param int       $questionId
  * @param int       $choice the user selected
  * @param string    $from  function is called from 'exercise_show' or 'exercise_result'
  * @param array     $exerciseResultCoordinates the hotspot coordinates $hotspot[$question_id] = coordinates
  * @param bool      $saved_results save results in the DB or just show the reponse
  * @param bool      $from_database gets information from DB or from the current selection
  * @param bool      $show_result show results or not
  * @param int       $propagate_neg
  * @param array     $hotspot_delineation_result
  *
  * @todo    reduce parameters of this function
  * @return  string  html code
  */
 public function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0, $hotspot_delineation_result = array())
 {
     global $debug;
     //needed in order to use in the exercise_attempt() for the time
     global $learnpath_id, $learnpath_item_id;
     require_once api_get_path(LIBRARY_PATH) . 'geometry.lib.php';
     $feedback_type = $this->selectFeedbackType();
     $results_disabled = $this->selectResultsDisabled();
     if ($debug) {
         error_log("<------ manage_answer ------> ");
         error_log('exe_id: ' . $exeId);
         error_log('$from:  ' . $from);
         error_log('$saved_results: ' . intval($saved_results));
         error_log('$from_database: ' . intval($from_database));
         error_log('$show_result: ' . $show_result);
         error_log('$propagate_neg: ' . $propagate_neg);
         error_log('$exerciseResultCoordinates: ' . print_r($exerciseResultCoordinates, 1));
         error_log('$hotspot_delineation_result: ' . print_r($hotspot_delineation_result, 1));
         error_log('$learnpath_id: ' . $learnpath_id);
         error_log('$learnpath_item_id: ' . $learnpath_item_id);
         error_log('$choice: ' . print_r($choice, 1));
     }
     $extra_data = array();
     $final_overlap = 0;
     $final_missing = 0;
     $final_excess = 0;
     $overlap_color = 0;
     $missing_color = 0;
     $excess_color = 0;
     $threadhold1 = 0;
     $threadhold2 = 0;
     $threadhold3 = 0;
     $arrques = null;
     $arrans = null;
     $questionId = intval($questionId);
     $exeId = intval($exeId);
     $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
     // Creates a temporary Question object
     $course_id = $this->course_id;
     $objQuestionTmp = Question::read($questionId, $course_id);
     if ($objQuestionTmp === false) {
         return false;
     }
     $questionName = $objQuestionTmp->selectTitle();
     $questionWeighting = $objQuestionTmp->selectWeighting();
     $answerType = $objQuestionTmp->selectType();
     $quesId = $objQuestionTmp->selectId();
     $extra = $objQuestionTmp->extra;
     $next = 1;
     //not for now
     // Extra information of the question
     if (!empty($extra)) {
         $extra = explode(':', $extra);
         if ($debug) {
             error_log(print_r($extra, 1));
         }
         // Fixes problems with negatives values using intval
         $true_score = floatval(trim($extra[0]));
         $false_score = floatval(trim($extra[1]));
         $doubt_score = floatval(trim($extra[2]));
     }
     $totalWeighting = 0;
     $totalScore = 0;
     // Destruction of the Question object
     unset($objQuestionTmp);
     // Construction of the Answer object
     $objAnswerTmp = new Answer($questionId);
     $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
     if ($debug) {
         error_log('Count of answers: ' . $nbrAnswers);
         error_log('$answerType: ' . $answerType);
     }
     if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION || $answerType == CALCULATED_ANSWER) {
         $nbrAnswers = 1;
     }
     $nano = null;
     if ($answerType == ORAL_EXPRESSION) {
         $exe_info = Event::get_exercise_results_by_attempt($exeId);
         $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null;
         $params = array();
         $params['course_id'] = $course_id;
         $params['session_id'] = api_get_session_id();
         $params['user_id'] = isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id();
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.class.php

示例6: array

        $column++;
    }
    $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
    $row++;
}
$content = $table->toHtml();
// Format B
$headers = array(get_lang('Question'), get_lang('Answer'), get_lang('Correct'), get_lang('NumberStudentWhoSelectedIt'));
$data = array();
if (!empty($question_list)) {
    $id = 0;
    foreach ($question_list as $question_id) {
        $question_obj = Question::read($question_id);
        $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, $courseCode, $sessionId);
        $answer = new Answer($question_id);
        $answer_count = $answer->selectNbrAnswers();
        for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
            $answer_info = $answer->selectAnswer($answer_id);
            $is_correct = $answer->isCorrect($answer_id);
            $correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
            $real_answer_id = $answer->selectAutoId($answer_id);
            // Overwriting values depending of the question
            switch ($question_obj->type) {
                case FILL_IN_BLANKS:
                    $answer_info_db = $answer_info;
                    $answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
                    $correct_answer = $is_correct;
                    $answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
                    $counter = 0;
                    foreach ($answers as $answer_item) {
                        if ($counter == 0) {
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:stats.php

示例7: showQuestion

    /**
     * Shows a question
     *
     * @param int    $questionId question id
     * @param bool   $only_questions if true only show the questions, no exercise title
     * @param bool   $origin  i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool   $show_title
     * @param bool   $freeze
     * @param array  $user_choice
     * @param bool   $show_comment
     * @param bool   $exercise_feedback
     * @param bool   $show_answers
     * */
    public static function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
    {
        $course_id = api_get_course_int_id();
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        // Reads question information
        if (!($objQuestionTmp = Question::read($questionId))) {
            // Question not found
            return false;
        }
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = '';
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    TestCategory::displayCategoryAndTitle($objQuestionTmp->id);
                    echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                }
                if (!empty($questionDescription)) {
                    echo Display::div($questionDescription, array('class' => 'question_description'));
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return '';
            }
            echo '<div class="question_options row">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="col-md-12 ui-widget ui-helper-clearfix">
                        <div class="clearfix">
                        <ul class="exercise-draggable-answer ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= <<<HTML
                        <div id="drag{$questionId}_question" class="drag_question">
                            <table class="data_table">
HTML;
                }
                // Iterate through answers
                $x = 1;
                //mark letters for each answer
                $letter = 'A';
                $answer_matching = array();
                $cpt1 = array();
                for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                    $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                    $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                    if ($answerCorrect == 0) {
                        // options (A, B, C, ...) that will be put into the list-box
                        // have the "correct" field set to 0 because they are answer
                        $cpt1[$x] = $letter;
                        $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                        $x++;
                        $letter++;
                    }
                }
                $i = 1;
                $select_items[0]['id'] = 0;
                $select_items[0]['letter'] = '--';
                $select_items[0]['answer'] = '';
                foreach ($answer_matching as $id => $value) {
                    $select_items[$i]['id'] = $value['id'];
                    $select_items[$i]['letter'] = $cpt1[$id];
                    $select_items[$i]['answer'] = $value['answer'];
                    $i++;
                }
                $user_choice_array_position = array();
                if (!empty($user_choice)) {
//.........这里部分代码省略.........
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.lib.php

示例8: prepareQuiz


//.........这里部分代码省略.........
                $qdescription = $question->selectDescription();
                $questionPonderationList[$questionId] = $question->selectWeighting();

                // Generic display, valid for all kind of question
                $pageBody .= '<table class="table-default">
                <tr><th valign="top" colspan="2">' . $langQuestion . ' ' . $questionCount . '</th></tr>
                <tfoot>
                        <tr><td valign="top" colspan="2">' . $qtitle . '</td></tr>
                        <tr><td valign="top" colspan="2"><i>' . parse_user_text($qdescription) . '</i></td></tr>' . "\n";

                // Attached file, if it exists.
                //$attachedFile = $question->selectAttachedFile();
                if (!empty($attachedFile)) {
                    // copy the attached file
                    if (!claro_copy_file($this->srcDirExercise . '/' . $attachedFile, $this->destDir . '/Exercises')) {
                        $this->error[] = $GLOBALS['langErrorCopyAttachedFile'] . $attachedFile;
                        return false;
                    }

                    // Ok, if it was an mp3, we need to copy the flash mp3-player too.
                    $extension = substr(strrchr($attachedFile, '.'), 1);
                    if ($extension == 'mp3') {
                        $this->mp3Found = true;
                    }

                    $pageBody .= '<tr><td colspan="2">' . display_attached_file($attachedFile) . '</td></tr>' . "\n";
                }

                /*
                 * Display the possible answers
                 */

                $answer = new Answer($questionId);
                $answerCount = $answer->selectNbrAnswers();

                // Used for matching:
                $letterCounter = 'A';
                $choiceCounter = 1;
                $Select = array();

                for ($answerId = 1; $answerId <= $answerCount; $answerId++) {
                    $answerText = $answer->selectAnswer($answerId);
                    $answerCorrect = $answer->isCorrect($answerId);

                    // Unique answer
                    if ($qtype == UNIQUE_ANSWER || $qtype == TRUE_FALSE) {
                        // Construct the identifier
                        $htmlQuestionId = 'unique_' . $questionCount . '_x';

                        $pageBody .= '<tr><td width="5%" align="center">
                        <input type="radio" name="' . $htmlQuestionId . '"
                        id="scorm_' . $idCounter . '"
                        value="' . $answer->selectWeighting($answerId) . '"></td>
                    <td width="95%"><label for="scorm_' . $idCounter . '">' . $answerText . '</label>
                    </td></tr>';

                        $idCounter++;
                    }
                    // Multiple answers
                    elseif ($qtype == MULTIPLE_ANSWER) {
                        // Construct the identifier
                        $htmlQuestionId = 'multiple_' . $questionCount . '_' . $answerId;

                        // Compute the score modifier if this answer is checked
                        $raw = $answer->selectWeighting($answerId);
开发者ID:nikosv,项目名称:openeclass,代码行数:66,代码来源:scormExport.inc.php

示例9: showQuestion

/**
 * Shows a question
 *
 * @param int    $questionId question id
 * @param bool   $only_questions if true only show the questions, no exercise title
 * @param bool   $origin  i.e = learnpath
 * @param string $current_item current item from the list of questions
 * @param bool   $show_title
 * @param bool   $freeze
 * @param array  $user_choice
 * @param bool   $show_comment
 * @param bool   $exercise_feedback
 * @param bool   $show_answers
 * */
function showQuestion($questionId, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false)
{
    // Text direction for the current language
    $is_ltr_text_direction = api_get_text_direction() != 'rtl';
    // Change false to true in the following line to enable answer hinting
    $debug_mark_answer = $show_answers;
    //api_is_allowed_to_edit() && false;
    // Reads question information
    if (!($objQuestionTmp = Question::read($questionId))) {
        // Question not found
        return false;
    }
    if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
        $show_comment = false;
    }
    $answerType = $objQuestionTmp->selectType();
    $pictureName = $objQuestionTmp->selectPicture();
    $s = '';
    if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
        // Question is not a hotspot
        if (!$only_questions) {
            $questionDescription = $objQuestionTmp->selectDescription();
            if ($show_title) {
                Testcategory::displayCategoryAndTitle($objQuestionTmp->id);
                echo Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
            }
            if (!empty($questionDescription)) {
                echo Display::div($questionDescription, array('class' => 'question_description'));
            }
        }
        if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
            return '';
        }
        echo '<div class="question_options">';
        // construction of the Answer object (also gets all answers details)
        $objAnswerTmp = new Answer($questionId);
        $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
        $course_id = api_get_course_int_id();
        $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
        // For "matching" type here, we need something a little bit special
        // because the match between the suggestions and the answers cannot be
        // done easily (suggestions and answers are in the same table), so we
        // have to go through answers first (elems with "correct" value to 0).
        $select_items = array();
        //This will contain the number of answers on the left side. We call them
        // suggestions here, for the sake of comprehensions, while the ones
        // on the right side are called answers
        $num_suggestions = 0;
        if ($answerType == MATCHING) {
            $s .= '<table class="data_table">';
            // Iterate through answers
            $x = 1;
            //mark letters for each answer
            $letter = 'A';
            $answer_matching = array();
            $cpt1 = array();
            for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                $numAnswer = $objAnswerTmp->selectAutoId($answerId);
                $answer = $objAnswerTmp->selectAnswer($answerId);
                if ($answerCorrect == 0) {
                    // options (A, B, C, ...) that will be put into the list-box
                    // have the "correct" field set to 0 because they are answer
                    $cpt1[$x] = $letter;
                    $answer_matching[$x] = $objAnswerTmp->selectAnswerByAutoId($numAnswer);
                    $x++;
                    $letter++;
                }
            }
            $i = 1;
            $select_items[0]['id'] = 0;
            $select_items[0]['letter'] = '--';
            $select_items[0]['answer'] = '';
            foreach ($answer_matching as $id => $value) {
                $select_items[$i]['id'] = $value['id'];
                $select_items[$i]['letter'] = $cpt1[$id];
                $select_items[$i]['answer'] = $value['answer'];
                $i++;
            }
            $user_choice_array_position = array();
            if (!empty($user_choice)) {
                foreach ($user_choice as $item) {
                    $user_choice_array_position[$item['position']] = $item['answer'];
                }
            }
            $num_suggestions = $nbrAnswers - $x + 1;
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:exercise.lib.php

示例10: showQuestion

    /**
     * Shows a question
     * @param Question $objQuestionTmp
     * @param bool $only_questions if true only show the questions, no exercise title
     * @param bool $origin origin i.e = learnpath
     * @param string $current_item current item from the list of questions
     * @param bool $show_title
     * @param bool $freeze
     * @param array $user_choice
     * @param bool $show_comment
     * @param null $exercise_feedback
     * @param bool $show_answers
     * @param null $modelType
     * @param bool $categoryMinusOne
     * @return bool|null|string
     */
    public function showQuestion(Question $objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false, $modelType = null, $categoryMinusOne = true)
    {
        // Text direction for the current language
        //$is_ltr_text_direction = api_get_text_direction() != 'rtl';
        // Change false to true in the following line to enable answer hinting
        $debug_mark_answer = $show_answers;
        //api_is_allowed_to_edit() && false;
        // Reads question information
        if (!$objQuestionTmp) {
            // Question not found
            return false;
        }
        $html = null;
        $questionId = $objQuestionTmp->id;
        if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) {
            $show_comment = false;
        }
        $answerType = $objQuestionTmp->selectType();
        $pictureName = $objQuestionTmp->selectPicture();
        $s = null;
        $form = new FormValidator('question');
        $renderer = $form->defaultRenderer();
        $form_template = '{content}';
        $renderer->setFormTemplate($form_template);
        if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
            // Question is not a hotspot
            if (!$only_questions) {
                $questionDescription = $objQuestionTmp->selectDescription();
                if ($show_title) {
                    $categoryName = TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne);
                    $html .= $categoryName;
                    $html .= Display::div($current_item . '. ' . $objQuestionTmp->selectTitle(), array('class' => 'question_title'));
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                } else {
                    $html .= '<div class="media">';
                    $html .= '<div class="pull-left">';
                    $html .= '<div class="media-object">';
                    $html .= Display::div($current_item, array('class' => 'question_no_title'));
                    $html .= '</div>';
                    $html .= '</div>';
                    $html .= '<div class="media-body">';
                    if (!empty($questionDescription)) {
                        $html .= Display::div($questionDescription, array('class' => 'question_description'));
                    }
                    $html .= '</div>';
                    $html .= '</div>';
                }
            }
            if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) {
                return null;
            }
            $html .= '<div class="question_options">';
            // construction of the Answer object (also gets all answers details)
            $objAnswerTmp = new Answer($questionId, null, $this);
            $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
            $course_id = api_get_course_int_id();
            $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
            // For "matching" type here, we need something a little bit special
            // because the match between the suggestions and the answers cannot be
            // done easily (suggestions and answers are in the same table), so we
            // have to go through answers first (elems with "correct" value to 0).
            $select_items = array();
            //This will contain the number of answers on the left side. We call them
            // suggestions here, for the sake of comprehensions, while the ones
            // on the right side are called answers
            $num_suggestions = 0;
            if ($answerType == MATCHING || $answerType == DRAGGABLE) {
                if ($answerType == DRAGGABLE) {
                    $s .= '<div class="ui-widget ui-helper-clearfix">
                            <ul class="drag_question ui-helper-reset ui-helper-clearfix">';
                } else {
                    $s .= '<div id="drag' . $questionId . '_question" class="drag_question">';
                    $s .= '<table class="data_table">';
                }
                $j = 1;
                //iterate through answers
                $letter = 'A';
                //mark letters for each answer
                $answer_matching = array();
                $capital_letter = array();
                //for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
                foreach ($objAnswerTmp->answer as $answerId => $answer_item) {
//.........这里部分代码省略.........
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:101,代码来源:exercise.class.php

示例11: foreach

 /**
  * Save User Unanswered Questions either as answered (default behaviour)
  * or as unanswered by passing parameter 0 to the function
  * (Used for sequential exercises on time expiration 
  * and when student wants to temporary save his answers)
  */
 function save_unanswered($as_answered = 1)
 {
     $id = $this->id;
     $eurid = $_SESSION['exerciseUserRecordID'][$id];
     $question_ids = Database::get()->queryArray('SELECT DISTINCT question_id FROM exercise_answer_record WHERE eurid = ?d AND is_answered = 1', $eurid);
     if (count($question_ids) > 0) {
         foreach ($question_ids as $row) {
             $answered_question_ids[] = $row->question_id;
         }
     } else {
         $answered_question_ids = array();
     }
     $questionList = $_SESSION['questionList'][$id];
     $unanswered_questions = array_diff($questionList, $answered_question_ids);
     foreach ($unanswered_questions as $question_id) {
         // construction of the Question object
         $objQuestionTmp = new Question();
         // reads question informations
         $objQuestionTmp->read($question_id);
         $question_type = $objQuestionTmp->selectType();
         if ($question_type == MATCHING) {
             // construction of the Answer object
             $objAnswerTmp = new Answer($question_id);
             $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
             for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                 //must get answer id ONLY where correct value existS
                 $answerCorrect = $objAnswerTmp->isCorrect($answerId);
                 if ($answerCorrect) {
                     $value[$answerId] = 0;
                 }
             }
             unset($objAnswerTmp);
         } else {
             if ($question_type == FILL_IN_BLANKS) {
                 // construction of the Answer object
                 $objAnswerTmp = new Answer($question_id);
                 $answer = $objAnswerTmp->selectAnswer(1);
                 // construction of the Answer object
                 list($answer, $answerWeighting) = explode('::', $answer);
                 $answerWeighting = explode(',', $answerWeighting);
                 $nbrAnswers = count($answerWeighting);
                 for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
                     $value[$answerId] = '';
                 }
             } elseif ($question_type == FREE_TEXT) {
                 $value = '';
             } else {
                 $value = 0;
             }
         }
         $this->insert_answer_records($question_id, $value, $as_answered);
         unset($value);
     }
 }
开发者ID:kostastzo,项目名称:openeclass,代码行数:60,代码来源:exercise.class.php

示例12: showQuestion

function showQuestion(&$objQuestionTmp, $exerciseResult = array())
{
    global $tool_content, $picturePath, $langNoAnswer, $langQuestion, $langColumnA, $langColumnB, $langMakeCorrespond, $langInfoGrades, $i, $exerciseType, $nbrQuestions, $langInfoGrade;
    $questionId = $objQuestionTmp->id;
    $questionWeight = $objQuestionTmp->selectWeighting();
    $answerType = $objQuestionTmp->selectType();
    $message = $langInfoGrades;
    if (intval($questionWeight) == $questionWeight) {
        $questionWeight = intval($questionWeight);
    }
    if ($questionWeight == 1) {
        $message = $langInfoGrade;
    }
    $questionName = $objQuestionTmp->selectTitle();
    $questionDescription = $objQuestionTmp->selectDescription();
    $questionDescription_temp = $questionDescription;
    $questionTypeWord = $objQuestionTmp->selectTypeWord($answerType);
    $tool_content .= "\n            <div class='panel panel-success'>\n              <div class='panel-heading'>\n                <h3 class='panel-title'>{$langQuestion} : {$i} ({$questionWeight} {$message})" . ($exerciseType == 2 ? " / " . $nbrQuestions : "") . "</h3>\n              </div>\n              <div class='panel-body'>\n                    <h4>{$questionName} <br> \n                        <small>{$questionTypeWord}</small>\n                    </h4>\n                    {$questionDescription_temp}\n                    <div class='text-center'>\n                        " . (file_exists($picturePath . '/quiz-' . $questionId) ? "<img src='../../{$picturePath}/quiz-{$questionId}'>" : "") . "\n                    </div>";
    // construction of the Answer object
    $objAnswerTmp = new Answer($questionId);
    $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
    if ($answerType == FREE_TEXT) {
        $text = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : '';
        $tool_content .= rich_text_editor('choice[' . $questionId . ']', 14, 90, $text);
    }
    if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == TRUE_FALSE) {
        $tool_content .= "<input type='hidden' name='choice[{$questionId}]' value='0' />";
    }
    // only used for the answer type "Matching"
    if ($answerType == MATCHING && $nbrAnswers > 0) {
        $cpt1 = 'A';
        $cpt2 = 1;
        $Select = array();
        $tool_content .= "\n                      <table class='table-default'>\n                      <tr>\n                        <th>{$langColumnA}</th>\n                        <th>{$langMakeCorrespond}</th>\n                        <th>{$langColumnB}</th>\n                      </tr>";
    }
    if ($answerType == FILL_IN_BLANKS) {
        $tool_content .= "<div class='form-inline'>";
    }
    for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
        $answer = $objAnswerTmp->selectAnswer($answerId);
        $answer = mathfilter($answer, 12, '../../courses/mathimg/');
        $answerCorrect = $objAnswerTmp->isCorrect($answerId);
        if ($answerType == FILL_IN_BLANKS) {
            // splits text and weightings that are joined with the character '::'
            list($answer) = explode('::', $answer);
            // replaces [blank] by an input field
            $replace_callback = function () use($questionId, $exerciseResult) {
                static $id = 0;
                $id++;
                $value = isset($exerciseResult[$questionId][$id]) ? 'value = ' . $exerciseResult[$questionId][$id] : '';
                return "<input type='text' name='choice[{$questionId}][{$id}]' {$value}>";
            };
            $answer = preg_replace_callback('/\\[[^]]+\\]/', $replace_callback, standard_text_escape($answer));
        }
        // unique answer
        if ($answerType == UNIQUE_ANSWER) {
            $checked = isset($exerciseResult[$questionId]) && $exerciseResult[$questionId] == $answerId ? 'checked="checked"' : '';
            $tool_content .= "\n                        <div class='radio'>\n                          <label>\n                            <input type='radio' name='choice[{$questionId}]' value='{$answerId}' {$checked}>\n                            " . standard_text_escape($answer) . "\n                          </label>\n                        </div>";
        } elseif ($answerType == MULTIPLE_ANSWER) {
            $checked = isset($exerciseResult[$questionId][$answerId]) && $exerciseResult[$questionId][$answerId] == 1 ? 'checked="checked"' : '';
            $tool_content .= "\n                        <div class='checkbox'>\n                          <label>\n                            <input type='checkbox' name='choice[{$questionId}][{$answerId}]' value='1' {$checked}>\n                            " . standard_text_escape($answer) . "\n                          </label>\n                        </div>";
        } elseif ($answerType == FILL_IN_BLANKS) {
            $tool_content .= $answer;
        } elseif ($answerType == MATCHING) {
            if (!$answerCorrect) {
                // options (A, B, C, ...) that will be put into the list-box
                $Select[$answerId]['Lettre'] = $cpt1++;
                // answers that will be shown at the right side
                $Select[$answerId]['Reponse'] = standard_text_escape($answer);
            } else {
                $tool_content .= "\n\t\t\t\t    <tr>\n\t\t\t\t      <td><b>{$cpt2}.</b> " . standard_text_escape($answer) . "</td>\n\t\t\t\t      <td><div align='left'>\n\t\t\t\t       <select name='choice[{$questionId}][{$answerId}]'>\n\t\t\t\t\t <option value='0'>--</option>";
                // fills the list-box
                foreach ($Select as $key => $val) {
                    $selected = isset($exerciseResult[$questionId][$answerId]) && $exerciseResult[$questionId][$answerId] == $key ? 'selected="selected"' : '';
                    $tool_content .= "\n\t\t\t\t\t<option value=\"" . q($key) . "\" {$selected}>{$val['Lettre']}</option>";
                }
                $tool_content .= "</select></div></td><td width='200'>";
                if (isset($Select[$cpt2])) {
                    $tool_content .= '<b>' . q($Select[$cpt2]['Lettre']) . '.</b> ' . $Select[$cpt2]['Reponse'];
                } else {
                    $tool_content .= '&nbsp;';
                }
                $tool_content .= "</td></tr>";
                $cpt2++;
                // if the left side of the "matching" has been completely shown
                if ($answerId == $nbrAnswers) {
                    // if it remains answers to shown at the right side
                    while (isset($Select[$cpt2])) {
                        $tool_content .= "\n                                              <tr class='even'>\n                                                <td colspan='2'>\n                                                  <table width='100%'>\n                                                  <tr>\n                                                  <td width='200'>&nbsp;</td>\n                                                  <td width='100'>&nbsp;</td>\n                                                  <td width='200' valign='top'>" . "<b>" . q($Select[$cpt2]['Lettre']) . ".</b> " . q($Select[$cpt2]['Reponse']) . "\n                                                  </td>\n                                                  </tr>\n                                                  </table>\n                                                </td>\n                                              </tr>";
                        $cpt2++;
                    }
                    // end while()
                }
                // end if()
            }
        } elseif ($answerType == TRUE_FALSE) {
            $checked = isset($exerciseResult[$questionId]) && $exerciseResult[$questionId] == $answerId ? 'checked="checked"' : '';
            $tool_content .= "\n                        <div class='radio'>\n                          <label>\n                            <input type='radio' name='choice[{$questionId}]' value='{$answerId}' {$checked}>\n                            " . standard_text_escape($answer) . "\n                          </label>\n                        </div>";
        }
    }
//.........这里部分代码省略.........
开发者ID:kostastzo,项目名称:openeclass,代码行数:101,代码来源:exercise.lib.php

示例13: showQuestion

function showQuestion($questionId, $onlyAnswers = false)
{
    global $picturePath, $urlServer;
    global $langNoAnswer, $langColumnA, $langColumnB, $langMakeCorrespond;
    // construction of the Question object
    $objQuestionTmp = new Question();
    // reads question informations
    if (!$objQuestionTmp->read($questionId)) {
        // question not found
        return false;
    }
    $answerType = $objQuestionTmp->selectType();
    if (!$onlyAnswers) {
        $questionName = $objQuestionTmp->selectTitle();
        $questionDescription = $objQuestionTmp->selectDescription();
        $questionDescription_temp = standard_text_escape($questionDescription);
        echo "<tr class='even'>\n                    <td colspan='2'><b>" . q($questionName) . "</b><br />\n                    {$questionDescription_temp}\n                    </td>\n                    </tr>";
        if (file_exists($picturePath . '/quiz-' . $questionId)) {
            echo "<tr class='even'>\n                        <td class='center' colspan='2'><img src='{$urlServer}/{$picturePath}/quiz-{$questionId}' /></td>\n                      </tr>";
        }
    }
    // end if(!$onlyAnswers)
    // construction of the Answer object
    $objAnswerTmp = new Answer($questionId);
    $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
    // only used for the answer type "Matching"
    if ($answerType == MATCHING) {
        $cpt1 = 'A';
        $cpt2 = 1;
        $select = array();
        echo "\n              <tr class='even'>\n                <td colspan='2'>\n                  <table class='tbl_border' width='100%'>\n                  <tr>\n                    <th width='200'>{$langColumnA}</th>\n                    <th width='130'>{$langMakeCorrespond}</th>\n                    <th width='200'>{$langColumnB}</th>\n                  </tr>\n                  </table>\n                </td>\n              </tr>";
    }
    for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
        $answer = $objAnswerTmp->selectAnswer($answerId);
        $answer = mathfilter($answer, 12, '../../courses/mathimg/');
        $answerCorrect = $objAnswerTmp->isCorrect($answerId);
        if ($answerType == FILL_IN_BLANKS) {
            // splits text and weightings that are joined with the character '::'
            list($answer) = explode('::', $answer);
            // replaces [blank] by an input field
            $answer = preg_replace('/\\[[^]]+\\]/', '<input type="text" name="choice[' . $questionId . '][]" size="10" />', standard_text_escape($answer));
        }
        // unique answer
        if ($answerType == UNIQUE_ANSWER) {
            echo "\n                      <tr class='even'>\n                        <td class='center' width='1'>\n                          <input type='radio' name='choice[{$questionId}]' value='{$answerId}' />\n                        </td>\n                        <td>" . standard_text_escape($answer) . "</td>\n                      </tr>";
        } elseif ($answerType == MULTIPLE_ANSWER) {
            echo "\n                      <tr class='even'>\n                        <td width='1' align='center'>\n                          <input type='checkbox' name='choice[{$questionId}][{$answerId}]' value='1' />\n                        </td>\n                        <td>" . standard_text_escape($answer) . "</td>\n                      </tr>";
        } elseif ($answerType == FILL_IN_BLANKS) {
            echo "\n                      <tr class='even'>\n                        <td colspan='2'>" . $answer . "</td>\n                      </tr>";
        } elseif ($answerType == MATCHING) {
            if (!$answerCorrect) {
                // options (A, B, C, ...) that will be put into the list-box
                $select[$answerId]['Lettre'] = $cpt1++;
                // answers that will be shown at the right side
                $select[$answerId]['Reponse'] = standard_text_escape($answer);
            } else {
                echo "<tr class='even'>\n                                <td colspan='2'>\n                                  <table class='tbl'>\n                                  <tr>\n                                    <td width='200'><b>{$cpt2}.</b> " . standard_text_escape($answer) . "</td>\n                                    <td width='130'><div align='center'>\n                                     <select name='choice[{$questionId}][{$answerId}]'>\n                                       <option value='0'>--</option>";
                // fills the list-box
                foreach ($select as $key => $val) {
                    echo "<option value=\"{$key}\">{$val['Lettre']}</option>";
                }
                echo "</select></div></td>\n                                    <td width='200'>";
                if (isset($select[$cpt2])) {
                    echo '<b>' . $select[$cpt2]['Lettre'] . '.</b> ' . $select[$cpt2]['Reponse'];
                } else {
                    echo '&nbsp;';
                }
                echo "</td></tr></table></td></tr>";
                $cpt2++;
                // if the left side of the "matching" has been completely shown
                if ($answerId == $nbrAnswers) {
                    // if it remains answers to shown at the right side
                    while (isset($select[$cpt2])) {
                        echo "<tr class='even'>\n                                                <td colspan='2'>\n                                                  <table>\n                                                  <tr>\n                                                    <td width='60%' colspan='2'>&nbsp;</td>\n                                                    <td width='40%' align='right' valign='top'>" . "<b>" . $select[$cpt2]['Lettre'] . ".</b> " . $select[$cpt2]['Reponse'] . "</td>\n                                                  </tr>\n                                                  </table>\n                                                </td>\n                                              </tr>";
                        $cpt2++;
                    }
                    // end while()
                }
                // end if()
            }
        } elseif ($answerType == TRUE_FALSE) {
            echo "<tr class='even'>\n                                <td width='1' align='center'>\n                                <input type='radio' name='choice[{$questionId}]' value='{$answerId}' />\n                                </td><td>{$answer}</td>\n                                </tr>";
        }
    }
    // end for()
    if (!$nbrAnswers) {
        echo "<tr><td colspan='2'><div class='alert alert-danger'>{$langNoAnswer}</div></td></tr>";
    }
    // destruction of the Answer object
    unset($objAnswerTmp);
    // destruction of the Question object
    unset($objQuestionTmp);
    return $nbrAnswers;
}
开发者ID:kostastzo,项目名称:openeclass,代码行数:94,代码来源:showExercise.php

示例14: exportIMSQTI

function exportIMSQTI($result) {

	$xml_qti = '<?xml version = "1.0" encoding = "UTF-8" standalone = "no"?>
	<!DOCTYPE questestinterop SYSTEM "fims_qtilitev1p2p1.dtd">
	<questestinterop></questestinterop>';

	$xml_qti = qp($xml_qti);

	$answers_xml = array();

	$xml = "";
	foreach ($result as $row) {

		$supported_question_types = array("1", "5");
		if (!in_array($row->type, $supported_question_types)) {
			continue;
		}

		$xml .= '
		<item title="' . $row->id . '" ident="question' . $row->id . '">
			<presentation>
				<material>
					<mattext>'. $row->question .'</mattext>
				</material>
			</presentation>
			<response_lid rcardinality = "Single" rtiming = "No">
			<render_choice></render_choice>
			</response_lid>
		</item>
		';
	}

	$xml_qti->branch()->find('questestinterop')->append($xml);

	foreach ($result as $row) {

		$objAnswerTmp = new Answer($row->id);

		$responses = "";
		$respconditions = "";
		$itemfeedbacks = "";
		for( $i=1 ; $i <= $objAnswerTmp->selectNbrAnswers() ; $i++ ) {
			$responses .= '
			<response_label ident="question' . $row->id . 'answer'. $i .'">
			<material>
				<mattext>'. $objAnswerTmp->answer[$i] .'</mattext>
			</material>
			</response_label>';

			$respconditions .=  '
			<respcondition>
				<conditionvar>
					<varequal>question' . $row->id . 'answer'. $i .'</varequal>
				</conditionvar>
				<setvar action = "Set">'.$objAnswerTmp->weighting[$i].'</setvar>
				<displayfeedback feedbacktype = "Response" linkrefid = "question' . $row->id . 'feedback'. $i .'"/>
				</respcondition>';

				$itemfeedbacks .= '
				<itemfeedback ident = "question' . $row->id . 'feedback'. $i .'" view = "Candidate">
					<material>
						<mattext>'. $objAnswerTmp->comment[$i] .'</mattext>
					</material>
				</itemfeedback>
				';
			}

			$xml_qti->branch()->find('item[ident="question'. $row->id .'"]>response_lid>render_choice')->append($responses);
			$xml_qti->branch()->find('item[ident="question'. $row->id .'"]')->append('&#x9;<resprocessing>' . $respconditions . '</resprocessing>');
			$xml_qti->branch()->find('item[ident="question'. $row->id .'"]')->append($itemfeedbacks);
		}

		return $xml_qti->writeXML();
	}
开发者ID:nikosv,项目名称:openeclass,代码行数:74,代码来源:imsqtilib.php


注:本文中的Answer::selectNbrAnswers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。