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


PHP Answer::selectWeighting方法代码示例

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


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

示例1: 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

示例2: Answer

        } 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;
                    $totalScore+=$answerWeighting;
                }
                break;
            // for multiple answers
            case MULTIPLE_ANSWER : $studentChoice = @$choice[$answerId];
                if ($studentChoice) {
开发者ID:nikosv,项目名称:openeclass,代码行数:31,代码来源:showExerciseResult.php

示例3: createAnswersForm

 /**
  * function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $defaults = array();
     $nb_matches = $nb_options = 2;
     $matches = array();
     $answer = null;
     $counter = 1;
     if (isset($this->id)) {
         $answer = new Answer($this->id);
         $answer->read();
         if (count($answer->nbrAnswers) > 0) {
             for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                 $correct = $answer->isCorrect($i);
                 if (empty($correct)) {
                     $matches[$answer->selectAutoId($i)] = chr(64 + $counter);
                     $counter++;
                 }
             }
         }
     }
     if ($form->isSubmitted()) {
         $nb_matches = $form->getSubmitValue('nb_matches');
         $nb_options = $form->getSubmitValue('nb_options');
         if (isset($_POST['lessOptions'])) {
             $nb_matches--;
             $nb_options--;
         }
         if (isset($_POST['moreOptions'])) {
             $nb_matches++;
             $nb_options++;
         }
     } else {
         if (!empty($this->id)) {
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     if ($answer->isCorrect($i)) {
                         $nb_matches++;
                         $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                         $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
                         $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$i];
                     } else {
                         $nb_options++;
                         $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                     }
                 }
             }
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
             $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
             $defaults['matches[2]'] = '2';
             $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
     }
     if (empty($matches)) {
         for ($i = 1; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     } else {
         for ($i = $counter; $i <= $nb_options; ++$i) {
             // fill the array with A, B, C.....
             $matches[$i] = chr(64 + $i);
         }
     }
     $form->addElement('hidden', 'nb_matches', $nb_matches);
     $form->addElement('hidden', 'nb_options', $nb_options);
     // DISPLAY MATCHES
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="5%">' . get_lang('Number') . '</th>
                 <th width="70%">' . get_lang('Answer') . '</th>
                 <th width="15%">' . get_lang('MatchesTo') . '</th>
                 <th width="10%">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('MakeCorrespond'));
     $form->addHtml($html);
     if ($nb_matches < 1) {
         $nb_matches = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
         $form->addHtml('<tr>');
         $form->addHtml("<td>{$i}</td>");
         $form->addText("answer[{$i}]", null);
         $form->addSelect("matches[{$i}]", null, $matches);
         $form->addText("weighting[{$i}]", null, true, ['value' => 10]);
         $form->addHtml('</tr>');
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:matching.class.php

示例4: prepareQuiz

        /**
         * Exports an exercise as a SCO.
         * This method is intended to be called from the prepare method.
         *
         * @note There's a lot of nearly cut-and-paste from exercise.lib.php here
         *      because of some little differences...
         *      Perhaps something that could be refactorised ?
         *
         * @see prepare
         * @param $quizId The quiz
         * @param $raw_to_pass The needed score to attain
         * @return False on error, True if everything went well.
         * @author Thanos Kyritsis <atkyritsis@upnet.gr>
         * @author  Amand Tihon <amand@alrj.org>
         */
        function prepareQuiz($quizId, $raw_to_pass = 50) {
            global $langQuestion, $langOk, $langScore, $claro_stylesheet, $clarolineRepositorySys;
            global $charset, $langExerciseDone;
            // those two variables are needed by display_attached_file()
            global $attachedFilePathWeb;
            global $attachedFilePathSys;
            $attachedFilePathWeb = 'Exercises';
            $attachedFilePathSys = $this->destDir . '/Exercises';

// Generate standard page header
            $pageHeader = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=' . $charset . '">
<meta http-equiv="expires" content="Tue, 05 DEC 2000 07:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<link rel="stylesheet" type="text/css" href="bootstrap-custom.css" />
<link rel="stylesheet" type="text/css" href="' . $claro_stylesheet . '" media="screen, projection, tv" />
<script language="javascript" type="text/javascript" src="APIWrapper.js"></script>
<script language="javascript" type="text/javascript" src="scores.js"></script>
' . "\n";


            $pageBody = '<body onload="loadPage()">
    <div id="claroBody"><form id="quiz">
    <table class="table-default"><tr><td>' . "\n";


            // read the exercise
            $quiz = new Exercise();
            if (!$quiz->read($quizId)) {
                $this->error[] = $GLOBALS['langErrorLoadingExercise'];
                return false;
            }

            // Get the question list
            $questionList = $quiz->selectQuestionList();
            $questionCount = $quiz->selectNbrQuestions();

            // Keep track of raw scores (ponderation) for each question
            $questionPonderationList = array();

            // Keep track of correct texts for fill-in type questions
            $fillAnswerList = array();

            // Counter used to generate the elements' id. Incremented after every <input> or <select>
            $idCounter = 0;

            // Display each question
            $questionCount = 0;
            foreach ($questionList as $questionId) {
                // Update question number
                $questionCount++;

                // read the question, abort on error
                $question = new Question();
                if (!$question->read($questionId)) {
                    $this->error[] = $GLOBALS['langErrorLoadingQuestion'];
                    return false;
                }
                $qtype = $question->selectType();
                $qtitle = $question->selectTitle();
                $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;
                    }
//.........这里部分代码省略.........
开发者ID:nikosv,项目名称:openeclass,代码行数:101,代码来源:scormExport.inc.php

示例5: update_answer_records

 /**
  * Update user answers
  */
 private function update_answer_records($key, $value)
 {
     // construction of the Question object
     $objQuestionTmp = new Question();
     // reads question informations
     $objQuestionTmp->read($key);
     $question_type = $objQuestionTmp->selectType();
     $id = $this->id;
     $eurid = $_SESSION['exerciseUserRecordID'][$id];
     if ($question_type == FREE_TEXT) {
         if (!empty($value)) {
             Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, answer_id = 1, weight = NULL,\n                                          is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $value, $eurid, $key);
         } else {
             Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, \n                                          answer_id = 0, weight = 0, is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $value, $eurid, $key);
         }
     } elseif ($question_type == FILL_IN_BLANKS) {
         $objAnswersTmp = new Answer($key);
         $answer_field = $objAnswersTmp->selectAnswer(1);
         //splits answer string from weighting string
         list($answer, $answerWeighting) = explode('::', $answer_field);
         // splits weightings that are joined with a comma
         $rightAnswerWeighting = explode(',', $answerWeighting);
         //getting all matched strings between [ and ] delimeters
         preg_match_all('#\\[(.*?)\\]#', $answer, $match);
         foreach ($value as $row_key => $row_choice) {
             //if user's choice is right assign rightAnswerWeight else 0
             $weight = $row_choice == $match[1][$row_key - 1] ? $rightAnswerWeighting[$row_key - 1] : 0;
             Database::get()->query("UPDATE exercise_answer_record SET answer = ?s, weight = ?f, is_answered = 1 \n                                              WHERE eurid = ?d AND question_id = ?d AND answer_id = ?d", $row_choice, $weight, $eurid, $key, $row_key);
         }
     } elseif ($question_type == MULTIPLE_ANSWER) {
         if ($value == 0) {
             $row_key = 0;
             $answer_weight = 0;
             Database::get()->query("UPDATE exercise_answer_record SET is_answered= 1 WHERE eurid = ?d AND question_id = ?d", $eurid, $key);
         } else {
             $objAnswersTmp = new Answer($key);
             $i = 1;
             // the first time in the loop we should update in order to keep question position in the DB
             // and then insert a new record if there are more than one answers
             foreach ($value as $row_key => $row_choice) {
                 $answer_weight = $objAnswersTmp->selectWeighting($row_key);
                 if ($i == 1) {
                     Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1 WHERE eurid = ?d AND question_id = ?d", $row_key, $answer_weight, $eurid, $key);
                 } else {
                     Database::get()->query("INSERT INTO exercise_answer_record (eurid, question_id, answer_id, weight, is_answered)\n                                    VALUES (?d, ?d, ?d, ?f, 1)", $eurid, $key, $row_key, $answer_weight);
                 }
                 unset($answer_weight);
                 $i++;
             }
             unset($objAnswersTmp);
         }
     } elseif ($question_type == MATCHING) {
         $objAnswersTmp = new Answer($key);
         foreach ($value as $row_key => $row_choice) {
             // In matching questions isCorrect() returns position of left column answers while $row_key returns right column position
             $correct_match = $objAnswersTmp->isCorrect($row_key);
             if ($correct_match == $row_choice) {
                 $answer_weight = $objAnswersTmp->selectWeighting($row_key);
             } else {
                 $answer_weight = 0;
             }
             Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1\n                                        WHERE eurid = ?d AND question_id = ?d AND answer = ?d", $row_choice, $answer_weight, $eurid, $key, $row_key);
             unset($answer_weight);
         }
     } else {
         if ($value != 0) {
             $objAnswersTmp = new Answer($key);
             $answer_weight = $objAnswersTmp->selectWeighting($value);
         } else {
             $answer_weight = 0;
         }
         Database::get()->query("UPDATE exercise_answer_record SET answer_id = ?d, weight = ?f , is_answered = 1\n                                        WHERE eurid = ?d AND question_id = ?d", $value, $answer_weight, $eurid, $key);
     }
     unset($objQuestionTmp);
 }
开发者ID:kostastzo,项目名称:openeclass,代码行数:78,代码来源:exercise.class.php

示例6: createAnswersForm

 /**
  * Function which redefines Question::createAnswersForm
  * @param FormValidator $form
  */
 public function createAnswersForm($form)
 {
     $defaults = array();
     $nb_matches = $nb_options = 2;
     $matches = array();
     $answer = null;
     if ($form->isSubmitted()) {
         $nb_matches = $form->getSubmitValue('nb_matches');
         $nb_options = $form->getSubmitValue('nb_options');
         if (isset($_POST['lessMatches'])) {
             $nb_matches--;
         }
         if (isset($_POST['moreMatches'])) {
             $nb_matches++;
         }
         if (isset($_POST['lessOptions'])) {
             $nb_options--;
         }
         if (isset($_POST['moreOptions'])) {
             $nb_options++;
         }
     } else {
         if (!empty($this->id)) {
             $answer = new Answer($this->id);
             $answer->read();
             if (count($answer->nbrAnswers) > 0) {
                 $nb_matches = $nb_options = 0;
                 for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                     if ($answer->isCorrect($i)) {
                         $nb_matches++;
                         $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                         $defaults['weighting[' . $nb_matches . ']'] = float_format($answer->selectWeighting($i), 1);
                         $answerInfo = $answer->getAnswerByAutoId($answer->correct[$i]);
                         $defaults['matches[' . $nb_matches . ']'] = isset($answerInfo['answer']) ? $answerInfo['answer'] : '';
                     } else {
                         $nb_options++;
                         $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                     }
                 }
             }
         } else {
             $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
             $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
             $defaults['matches[2]'] = '2';
             $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
             $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
         }
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $matches[$i] = $i;
     }
     $form->addElement('hidden', 'nb_matches', $nb_matches);
     $form->addElement('hidden', 'nb_options', $nb_options);
     // DISPLAY MATCHES
     $html = '<table class="table table-striped table-hover">
         <thead>
             <tr>
                 <th width="85%">' . get_lang('Answer') . '</th>
                 <th width="15%">' . get_lang('MatchesTo') . '</th>
                 <th width="10">' . get_lang('Weighting') . '</th>
             </tr>
         </thead>
         <tbody>';
     $form->addHeader(get_lang('MakeCorrespond'));
     $form->addHtml($html);
     if ($nb_matches < 1) {
         $nb_matches = 1;
         Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
     }
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $renderer =& $form->defaultRenderer();
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "answer[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "matches[{$i}]");
         $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{element}</td>', "weighting[{$i}]");
         $form->addHtml('<tr>');
         $form->addText("answer[{$i}]", null);
         $form->addSelect("matches[{$i}]", null, $matches);
         $form->addText("weighting[{$i}]", null, true, ['value' => 10, 'style' => 'width: 60px;']);
         $form->addHtml('</tr>');
     }
     $form->addHtml('</tbody></table>');
     $renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches');
     $renderer->setElementTemplate('{element}</div></div>', 'moreMatches');
     global $text;
     $group = [$form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true), $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true), $form->addButtonSave($text, 'submitQuestion', true)];
     $form->addGroup($group);
     if (!empty($this->id)) {
         $form->setDefaults($defaults);
     } else {
         if ($this->isContent == 1) {
             $form->setDefaults($defaults);
         }
     }
     $form->setConstants(['nb_matches' => $nb_matches, 'nb_options' => $nb_options]);
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:99,代码来源:Draggable.php

示例7: createAnswersForm

    /**
     * Function which redefines Question::createAnswersForm
     * @param FormValidator instance
     */
    public function createAnswersForm($form)
    {
        $defaults = array();
        $nb_matches = $nb_options = 2;
        if ($form->isSubmitted()) {
            $nb_matches = $form->getSubmitValue('nb_matches');
            $nb_options = $form->getSubmitValue('nb_options');
            if (isset($_POST['lessMatches'])) {
                $nb_matches--;
            }
            if (isset($_POST['moreMatches'])) {
                $nb_matches++;
            }
            if (isset($_POST['lessOptions'])) {
                $nb_options--;
            }
            if (isset($_POST['moreOptions'])) {
                $nb_options++;
            }
        } else {
            if (!empty($this->id)) {
                $answer = new Answer($this->id, api_get_course_int_id());
                $answer->read();
                if (count($answer->nbrAnswers) > 0) {
                    $nb_matches = $nb_options = 0;
                    //for ($i = 1; $i <= $answer->nbrAnswers; $i++) {
                    foreach ($answer->answer as $answerId => $answer_item) {
                        //$answer_id = $answer->getRealAnswerIdFromList($answerId);
                        if ($answer->isCorrect($answerId)) {
                            $nb_matches++;
                            $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($answerId);
                            $defaults['weighting[' . $nb_matches . ']'] = Text::float_format($answer->selectWeighting($answerId), 1);
                            $defaults['matches[' . $nb_matches . ']'] = $answer->correct[$answerId];
                            //$nb_matches;
                        } else {
                            $nb_options++;
                            $defaults['option[' . $nb_options . ']'] = $nb_options;
                        }
                    }
                }
            } else {
                $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
                $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
                $defaults['matches[2]'] = '2';
                $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
                $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
            }
        }
        $a_matches = array();
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $a_matches[$i] = $i;
            // fill the array with A, B, C.....
        }
        $form->addElement('hidden', 'nb_matches', $nb_matches);
        $form->addElement('hidden', 'nb_options', $nb_options);
        // DISPLAY MATCHES
        $html = '<table class="data_table">
					<tr>
						<th width="40%">
							' . get_lang('Answer') . '
						</th>
						<th width="40%">
							' . get_lang('MatchesTo') . '
						</th>
						<th width="50px">
							' . get_lang('Weighting') . '
						</th>
					</tr>';
        $form->addElement('label', get_lang('MakeCorrespond') . '<br /> ' . Display::return_icon('fill_field.png'), $html);
        if ($nb_matches < 1) {
            $nb_matches = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $form->addElement('html', '<tr><td>');
            $group = array();
            $group[] = $form->createElement('text', 'answer[' . $i . ']', null, ' size="60" style="margin-left: 0em;"');
            $group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches);
            $group[] = $form->createElement('text', 'weighting[' . $i . ']', null, array('class' => 'span1', 'value' => 10));
            $form->addGroup($group, null, null, '</td><td>');
            $form->addElement('html', '</td></tr>');
            $defaults['option[' . $i . ']'] = $i;
        }
        $form->addElement('html', '</table></div></div>');
        $group = array();
        $group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
        $group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
        $group[] = $form->createElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
        $form->addGroup($group);
        $form->addElement('html', '</table></div></div>');
        if (!empty($this->id)) {
            $form->setDefaults($defaults);
        } else {
            if ($this->isContent == 1) {
                $form->setDefaults($defaults);
            }
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:draggable.class.php

示例8: createAnswersForm

    /**
     * Redefines Question::createAnswersForm
     * @param the formvalidator instance
     */
    function createAnswersForm($form)
    {
        $defaults = array();
        $navigator_info = api_get_navigator();
        $nb_matches = $nb_options = 2;
        if ($form->isSubmitted()) {
            $nb_matches = $form->getSubmitValue('nb_matches');
            $nb_options = $form->getSubmitValue('nb_options');
            if (isset($_POST['lessMatches'])) {
                $nb_matches--;
            }
            if (isset($_POST['moreMatches'])) {
                $nb_matches++;
            }
            if (isset($_POST['lessOptions'])) {
                $nb_options--;
            }
            if (isset($_POST['moreOptions'])) {
                $nb_options++;
            }
        } else {
            if (!empty($this->id)) {
                $answer = new Answer($this->id);
                $answer->read();
                if (count($answer->nbrAnswers) > 0) {
                    $a_matches = $a_options = array();
                    $nb_matches = $nb_options = 0;
                    foreach ($answer->answer as $i => $answer_item) {
                        if ($answer->isCorrect($i)) {
                            $nb_matches++;
                            $defaults['answer[' . $nb_matches . ']'] = $answer->selectAnswer($i);
                            $defaults['weighting[' . $nb_matches . ']'] = Text::float_format($answer->selectWeighting($i), 1);
                            $correct_answer_id = $answer->correct[$i];
                            $defaults['matches[' . $nb_matches . ']'] = $answer->getCorrectAnswerPosition($correct_answer_id);
                        } else {
                            $nb_options++;
                            $defaults['option[' . $nb_options . ']'] = $answer->selectAnswer($i);
                        }
                    }
                }
            } else {
                $defaults['answer[1]'] = get_lang('DefaultMakeCorrespond1');
                $defaults['answer[2]'] = get_lang('DefaultMakeCorrespond2');
                $defaults['matches[2]'] = '2';
                $defaults['option[1]'] = get_lang('DefaultMatchingOptA');
                $defaults['option[2]'] = get_lang('DefaultMatchingOptB');
            }
        }
        $a_matches = array();
        for ($i = 1; $i <= $nb_options; ++$i) {
            // fill the array with A, B, C.....
            $a_matches[$i] = chr(64 + $i);
        }
        $form->addElement('hidden', 'nb_matches', $nb_matches);
        $form->addElement('hidden', 'nb_options', $nb_options);
        // DISPLAY MATCHES
        $html = '<table class="data_table">
					<tr>
						<th width="10px">
							' . get_lang('Number') . '
						</th>
						<th width="40%">
							' . get_lang('Answer') . '
						</th>
						<th width="40%">
							' . get_lang('MatchesTo') . '
						</th>
						<th width="50px">
							' . get_lang('Weighting') . '
						</th>
					</tr>';
        $form->addElement('label', get_lang('MakeCorrespond') . '<br /> ' . Display::return_icon('fill_field.png'), $html);
        if ($nb_matches < 1) {
            $nb_matches = 1;
            Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
        }
        for ($i = 1; $i <= $nb_matches; ++$i) {
            $form->addElement('html', '<tr><td>');
            $group = array();
            $puce = $form->createElement('text', null, null, 'value="' . $i . '"');
            $puce->freeze();
            $group[] = $puce;
            $group[] = $form->createElement('text', 'answer[' . $i . ']', null, 'size="60" style="margin-left: 0em;"');
            $group[] = $form->createElement('select', 'matches[' . $i . ']', null, $a_matches);
            $group[] = $form->createElement('text', 'weighting[' . $i . ']', null, array('class' => 'span1', 'value' => 10));
            $form->addGroup($group, null, null, '</td><td>');
            $form->addElement('html', '</td></tr>');
        }
        $form->addElement('html', '</table></div></div>');
        $group = array();
        if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
            $group[] = $form->createElement('submit', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
            $group[] = $form->createElement('submit', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
        } else {
            $group[] = $form->createElement('style_submit_button', 'moreMatches', get_lang('AddElem'), 'class="btn plus"');
            $group[] = $form->createElement('style_submit_button', 'lessMatches', get_lang('DelElem'), 'class="btn minus"');
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:matching.class.php

示例9: manageAnswers

    /**
     * This function was originally found in the exercise_show.php
     * @param   int     exe id
     * @param   int     question id
     * @param   int     the choice the user selected
     * @param   array   the hotspot coordinates $hotspot[$question_id] = coordinates
     * @param   string  function is called from 'exercise_show' or 'exercise_result'
     * @param   bool    save results in the DB or just show the reponse
     * @param   bool    gets information from DB or from the current selection
     * @param   bool    show results or not
     * @todo    reduce parameters of this function
     * @return  string  html code
     */
    public function manageAnswers($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $hotspot_delineation_result = array(), $updateResults = false)
    {
        global $debug;
        global $learnpath_id, $learnpath_item_id;
        //needed in order to use in the exercise_attempt() for the time
        require_once api_get_path(LIBRARY_PATH) . 'geometry.lib.php';
        $feedback_type = $this->feedback_type;
        $propagate_neg = $this->selectPropagateNeg();
        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 = api_get_course_int_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 = intval($extra[0]);
            $false_score = intval($extra[1]);
            $doubt_score = intval($extra[2]);
        }
        $totalWeighting = 0;
        $totalScore = 0;
        // Destruction of the Question object
        unset($objQuestionTmp);
        // Construction of the Answer object
        $objAnswerTmp = new Answer($questionId, null, $this);
        $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
        if ($debug) {
            error_log('Count of answers: ' . $nbrAnswers);
            error_log('$answerType: ' . $answerType);
        }
        if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION) {
            $nbrAnswers = 1;
        }
        $nano = null;
        if ($answerType == ORAL_EXPRESSION) {
            $exe_info = get_exercise_results_by_attempt($exeId);
            $exe_info = $exe_info[$exeId];
            $params = array();
            $params['course_id'] = api_get_course_int_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();
            $params['exercise_id'] = isset($exe_info['exe_exo_id']) ? $exe_info['exe_exo_id'] : $this->id;
            $params['question_id'] = $questionId;
            $params['exe_id'] = isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId;
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:exercise.class.php


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