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


PHP Answer::createAnswer方法代码示例

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


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

示例1: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param the formvalidator instance
  * @param the answers number to display
  */
 function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim(str_replace(['<p>', '</p>'], '', $form->getSubmitValue('answer[' . $i . ']')));
         $comment = trim(str_replace(['<p>', '</p>'], '', $form->getSubmitValue('comment[' . $i . ']')));
         $weighting = trim($form->getSubmitValue('weighting[' . $i . ']'));
         $goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
         if ($goodAnswer) {
             $weighting = abs($weighting);
         } else {
             $weighting = abs($weighting);
             $weighting = -$weighting;
         }
         if ($weighting > 0) {
             $questionWeighting += $weighting;
         }
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:32,代码来源:multiple_answer.class.php

示例2: lp_upload_quiz_action_handling


//.........这里部分代码省略.........
                            $numberRightAnswers++;
                        }
                    }
                    foreach ($answers_data as $answer_data) {
                        $answerValue = $answer_data[2];
                        $correct = 0;
                        $score = 0;
                        if (strtolower($answer_data[3]) == 'x') {
                            $correct = 1;
                            $score = $score_list[$i][3];
                            $comment = $feedback_true_list[$i][2];
                        } else {
                            $comment = $feedback_false_list[$i][2];
                            $floatVal = (double) $answer_data[3];
                            if (is_numeric($floatVal)) {
                                $score = $answer_data[3];
                            }
                        }
                        if ($useCustomScore) {
                            if ($correct) {
                                $score = $correctScore;
                            } else {
                                $score = $incorrectScore;
                            }
                        }
                        // Fixing scores:
                        switch ($detectQuestionType) {
                            case GLOBAL_MULTIPLE_ANSWER:
                                $score /= $numberRightAnswers;
                                break;
                            case UNIQUE_ANSWER:
                                break;
                            case MULTIPLE_ANSWER:
                                if (!$correct) {
                                    //$total = $total - $score;
                                }
                                break;
                        }
                        $objAnswer->createAnswer($answerValue, $correct, $comment, $score, $id);
                        $total += $score;
                        $id++;
                    }
                    $objAnswer->save();
                    $questionObj = Question::read($question_id, $courseId);
                    switch ($detectQuestionType) {
                        case GLOBAL_MULTIPLE_ANSWER:
                            $questionObj->updateWeighting($globalScore);
                            break;
                        case UNIQUE_ANSWER:
                        case MULTIPLE_ANSWER:
                        default:
                            $questionObj->updateWeighting($total);
                            break;
                    }
                    $questionObj->save();
                } else {
                    if ($detectQuestionType === FREE_ANSWER) {
                        $questionObj = Question::read($question_id, $courseId);
                        $globalScore = $score_list[$i][3];
                        $questionObj->updateWeighting($globalScore);
                        $questionObj->save();
                    }
                }
            }
        }
        if (isset($_SESSION['lpobject'])) {
            if ($debug > 0) {
                error_log('New LP - SESSION[lpobject] is defined', 0);
            }
            $oLP = unserialize($_SESSION['lpobject']);
            if (is_object($oLP)) {
                if ($debug > 0) {
                    error_log('New LP - oLP is object', 0);
                }
                if (empty($oLP->cc) or $oLP->cc != api_get_course_id()) {
                    if ($debug > 0) {
                        error_log('New LP - Course has changed, discard lp object', 0);
                    }
                    $oLP = null;
                    Session::erase('oLP');
                    Session::erase('lpobject');
                } else {
                    $_SESSION['oLP'] = $oLP;
                }
            }
        }
        if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) {
            $previous = $_SESSION['oLP']->select_previous_item_id();
            $parent = 0;
            // Add a Quiz as Lp Item
            $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quiz_title, '');
            // Redirect to home page for add more content
            header('location: ../newscorm/lp_controller.php?' . api_get_cidreq() . '&action=add_item&type=step&lp_id=' . Security::remove_XSS($_GET['lp_id']));
            exit;
        } else {
            //  header('location: exercise.php?' . api_get_cidreq());
            echo '<script>window.location.href = "' . api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidReq() . '&exerciseId=' . $quiz_id . '&session_id=' . api_get_session_id() . '"</script>';
        }
    }
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:101,代码来源:upload_exercise.php

示例3: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator $form
  */
 function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     // Score total
     $answer_score = trim($form->getSubmitValue('weighting[1]'));
     // Reponses correctes
     $nbr_corrects = 0;
     for ($i = 1; $i <= $nb_answers; $i++) {
         $goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
         if ($goodAnswer) {
             $nbr_corrects++;
         }
     }
     // Set question weighting (score total)
     $questionWeighting = $answer_score;
     // Set score per answer
     $nbr_corrects = $nbr_corrects == 0 ? 1 : $nbr_corrects;
     $answer_score = $nbr_corrects == 0 ? 0 : $answer_score;
     $answer_score = $answer_score / $nbr_corrects;
     //$answer_score �quivaut � la valeur d'une bonne r�ponse
     // cr�ation variable pour r�cuperer la valeur de la coche pour la prise en compte des n�gatifs
     $test = $form->getSubmitValue('pts');
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim($form->getSubmitValue('answer[' . $i . ']'));
         $comment = trim($form->getSubmitValue('comment[' . $i . ']'));
         $goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
         if ($goodAnswer) {
             $weighting = abs($answer_score);
         } else {
             if ($test == 1) {
                 $weighting = 0;
             } else {
                 $weighting = -abs($answer_score);
             }
         }
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question --> sert � donner le score total pendant l'examen
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:49,代码来源:global_multiple_answer.class.php

示例4: processAnswersCreation

 /**
  * Function which creates the form to create/edit the answers of the question
  * @param FormValidator $form
  */
 public function processAnswersCreation($form)
 {
     $answer = $form->getSubmitValue('answer');
     // Due the ckeditor transform the elements to their HTML value
     //$answer = api_html_entity_decode($answer, ENT_QUOTES, $charset);
     //$answer = htmlentities(api_utf8_encode($answer));
     // remove the :: eventually written by the user
     $answer = str_replace('::', '', $answer);
     // remove starting and ending space and &nbsp;
     $answer = api_preg_replace("/ /", " ", $answer);
     // start and end separator
     $blankStartSeparator = self::getStartSeparator($form->getSubmitValue('select_separator'));
     $blankEndSeparator = self::getEndSeparator($form->getSubmitValue('select_separator'));
     $blankStartSeparatorRegexp = self::escapeForRegexp($blankStartSeparator);
     $blankEndSeparatorRegexp = self::escapeForRegexp($blankEndSeparator);
     // remove spaces at the beginning and the end of text in square brackets
     $answer = preg_replace_callback("/" . $blankStartSeparatorRegexp . "[^]]+" . $blankEndSeparatorRegexp . "/", function ($matches) use($blankStartSeparator, $blankEndSeparator) {
         $matchingResult = $matches[0];
         $matchingResult = trim($matchingResult, $blankStartSeparator);
         $matchingResult = trim($matchingResult, $blankEndSeparator);
         $matchingResult = trim($matchingResult);
         // remove forbidden chars
         $matchingResult = str_replace("/\\/", "", $matchingResult);
         $matchingResult = str_replace('/"/', "", $matchingResult);
         return $blankStartSeparator . $matchingResult . $blankEndSeparator;
     }, $answer);
     // get the blanks weightings
     $nb = preg_match_all('/' . $blankStartSeparatorRegexp . '[^' . $blankStartSeparatorRegexp . ']*' . $blankEndSeparatorRegexp . '/', $answer, $blanks);
     if (isset($_GET['editQuestion'])) {
         $this->weighting = 0;
     }
     /* if we have some [tobefound] in the text
        build the string to save the following in the answers table
        <p>I use a [computer] and a [pen].</p>
        becomes
        <p>I use a [computer] and a [pen].</p>::100,50:100,50@1
            ++++++++-------**
            --- -- --- -- -
            A B  (C) (D)(E)
        +++++++ : required, weighting of each words
        ------- : optional, input width to display, 200 if not present
        ** : equal @1 if "Allow answers order switches" has been checked, @ otherwise
        A : weighting for the word [computer]
        B : weighting for the word [pen]
        C : input width for the word [computer]
        D : input width for the word [pen]
        E : equal @1 if "Allow answers order switches" has been checked, @ otherwise
        */
     if ($nb > 0) {
         $answer .= '::';
         // weighting
         for ($i = 0; $i < $nb; ++$i) {
             // enter the weighting of word $i
             $answer .= $form->getSubmitValue('weighting[' . $i . ']');
             // not the last word, add ","
             if ($i != $nb - 1) {
                 $answer .= ",";
             }
             // calculate the global weighting for the question
             $this->weighting += $form->getSubmitValue('weighting[' . $i . ']');
         }
         // input width
         $answer .= ":";
         for ($i = 0; $i < $nb; ++$i) {
             // enter the width of input for word $i
             $answer .= $form->getSubmitValue('sizeofinput[' . $i . ']');
             // not the last word, add ","
             if ($i != $nb - 1) {
                 $answer .= ",";
             }
         }
     }
     // write the blank separator code number
     // see function getAllowedSeparator
     /*
        0 [...]
        1 {...}
        2 (...)
        3 *...*
        4 #...#
        5 %...%
        6 $...$
     */
     $answer .= ":" . $form->getSubmitValue('select_separator');
     // Allow answers order switches
     $is_multiple = $form->getSubmitValue('multiple_answer');
     $answer .= '@' . $is_multiple;
     $this->save();
     $objAnswer = new Answer($this->id);
     $objAnswer->createAnswer($answer, 0, '', 0, 1);
     $objAnswer->save();
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:96,代码来源:fill_blanks.class.php

示例5: fill_db_course


//.........这里部分代码省略.........
                                     if ($path_documents . $value['file'] == '/certificates/default.html') {
                                         $example_cert_id = $image_id;
                                     }
                                     Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n                                            VALUES ({$course_id},'document',1,'{$now}','{$now}',{$image_id},'DocumentAdded',1,NULL,NULL,1)");
                                     $docId = Database::insert_id();
                                     if ($docId) {
                                         $sql = "UPDATE {$TABLEITEMPROPERTY} SET id = iid WHERE iid = {$docId}";
                                         Database::query($sql);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $agenda = new Agenda();
         $agenda->setType('course');
         $agenda->set_course($courseInfo);
         $agenda->addEvent($now, $now, 0, get_lang('AgendaCreationTitle'), get_lang('AgendaCreationContenu'));
         /*  Links tool */
         $link = new Link();
         $link->setCourse($courseInfo);
         $links = [['c_id' => $course_id, 'url' => 'http://www.google.com', 'title' => 'Google', 'description' => get_lang('Google'), 'category_id' => 0, 'on_homepage' => 0, 'target' => '_self', 'session_id' => 0], ['c_id' => $course_id, 'url' => 'http://www.wikipedia.org', 'title' => 'Wikipedia', 'description' => get_lang('Wikipedia'), 'category_id' => 0, 'on_homepage' => 0, 'target' => '_self', 'session_id' => 0]];
         foreach ($links as $params) {
             $link->save($params);
         }
         /* Announcement tool */
         AnnouncementManager::add_announcement(get_lang('AnnouncementExampleTitle'), get_lang('AnnouncementEx'), ['everyone' => 'everyone'], null, null, $now);
         $manager = Database::getManager();
         /* Introduction text */
         $intro_text = '<p style="text-align: center;">
                         <img src="' . api_get_path(REL_CODE_PATH) . 'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" />
                         <h2>' . self::lang2db(get_lang('IntroductionText')) . '</h2>
                      </p>';
         $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro();
         $toolIntro->setCId($course_id)->setId(TOOL_COURSE_HOMEPAGE)->setSessionId(0)->setIntroText($intro_text);
         $manager->persist($toolIntro);
         $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro();
         $toolIntro->setCId($course_id)->setId(TOOL_STUDENTPUBLICATION)->setSessionId(0)->setIntroText(get_lang('IntroductionTwo'));
         $manager->persist($toolIntro);
         $toolIntro = new Chamilo\CourseBundle\Entity\CToolIntro();
         $toolIntro->setCId($course_id)->setId(TOOL_WIKI)->setSessionId(0)->setIntroText(get_lang('IntroductionWiki'));
         $manager->persist($toolIntro);
         $manager->flush();
         /*  Exercise tool */
         $exercise = new Exercise($course_id);
         $exercise->exercise = get_lang('ExerciceEx');
         $html = '<table width="100%" border="0" cellpadding="0" cellspacing="0">
                     <tr>
                     <td width="110" valign="top" align="left">
                         <img src="' . api_get_path(WEB_CODE_PATH) . 'default_course_document/images/mr_dokeos/thinking.jpg">
                     </td>
                     <td valign="top" align="left">' . get_lang('Antique') . '</td></tr>
                 </table>';
         $exercise->type = 1;
         $exercise->setRandom(0);
         $exercise->active = 1;
         $exercise->results_disabled = 0;
         $exercise->description = $html;
         $exercise->save();
         $exercise_id = $exercise->id;
         $question = new MultipleAnswer();
         $question->question = get_lang('SocraticIrony');
         $question->description = get_lang('ManyAnswers');
         $question->weighting = 10;
         $question->position = 1;
         $question->course = $courseInfo;
         $question->save($exercise_id);
         $questionId = $question->id;
         $answer = new Answer($questionId, $courseInfo['real_id']);
         $answer->createAnswer(get_lang('Ridiculise'), 0, get_lang('NoPsychology'), -5, 1);
         $answer->createAnswer(get_lang('AdmitError'), 0, get_lang('NoSeduction'), -5, 2);
         $answer->createAnswer(get_lang('Force'), 1, get_lang('Indeed'), 5, 3);
         $answer->createAnswer(get_lang('Contradiction'), 1, get_lang('NotFalse'), 5, 4);
         $answer->save();
         /* Forum tool */
         require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
         $params = ['forum_category_title' => get_lang('ExampleForumCategory'), 'forum_category_comment' => ''];
         $forumCategoryId = store_forumcategory($params, $courseInfo, false);
         $params = ['forum_category' => $forumCategoryId, 'forum_title' => get_lang('ExampleForum'), 'forum_comment' => '', 'default_view_type_group' => ['default_view_type' => 'flat']];
         $forumId = store_forum($params, $courseInfo, true);
         $forumInfo = get_forum_information($forumId, $courseInfo['real_id']);
         $params = ['post_title' => get_lang('ExampleThread'), 'forum_id' => $forumId, 'post_text' => get_lang('ExampleThreadContent'), 'calification_notebook_title' => '', 'numeric_calification' => '', 'weight_calification' => '', 'forum_category' => $forumCategoryId, 'thread_peer_qualify' => 0];
         store_thread($forumInfo, $params, $courseInfo, false);
         /* Gradebook tool */
         $course_code = $courseInfo['code'];
         // father gradebook
         Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id)\n                VALUES ('{$course_code}','',1,'{$course_code}',0,100,0,75,NULL,{$example_cert_id})");
         $gbid = Database::insert_id();
         Database::query("INSERT INTO {$TABLEGRADEBOOK} (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id)\n                VALUES ('{$course_code}','',1,'{$course_code}',{$gbid},100,1,75,NULL,{$example_cert_id})");
         $gbid = Database::insert_id();
         Database::query("INSERT INTO {$TABLEGRADEBOOKLINK} (type, ref_id, user_id, course_code, category_id, created_at, weight, visible, locked)\n                VALUES (1,{$exercise_id},1,'{$course_code}',{$gbid},'{$now}',100,1,0)");
     }
     //Installing plugins in course
     $app_plugin = new AppPlugin();
     $app_plugin->install_course_plugins($course_id);
     $language_interface = $language_interface_original;
     return true;
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:add_course.lib.inc.php

示例6: processAnswersCreation

 /**
  * Receives the unique answer question type creation form data and creates
  * or updates the answers from that question
  * @param FormValidator $form
  */
 public function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $correct = $form->getSubmitValue('correct');
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim($form->getSubmitValue('answer[' . $i . ']'));
         $comment = trim($form->getSubmitValue('comment[' . $i . ']'));
         $weighting = trim($form->getSubmitValue('weighting[' . $i . ']'));
         $scenario = $form->getSubmitValue('scenario');
         //$list_destination = $form -> getSubmitValue('destination'.$i);
         //$destination_str = $form -> getSubmitValue('destination'.$i);
         $try = $scenario['try' . $i];
         $lp = $scenario['lp' . $i];
         $destination = $scenario['destination' . $i];
         $url = trim($scenario['url' . $i]);
         /*
                     How we are going to parse the destination value
         
                    here we parse the destination value which is a string
                     1@@3@@2;4;4;@@http://www.chamilo.org
         
                     where: try_again@@lp_id@@selected_questions@@url
         
                    try_again = is 1 || 0
                    lp_id = id of a learning path (0 if dont select)
                    selected_questions= ids of questions
                    url= an url
         
                     $destination_str='';
                     foreach ($list_destination as $destination_id)
                     {
                         $destination_str.=$destination_id.';';
                     }*/
         $goodAnswer = $correct == $i ? true : false;
         if ($goodAnswer) {
             $nbrGoodAnswers++;
             $weighting = abs($weighting);
             if ($weighting > 0) {
                 $questionWeighting += $weighting;
             }
         }
         if (empty($try)) {
             $try = 0;
         }
         if (empty($lp)) {
             $lp = 0;
         }
         if (empty($destination)) {
             $destination = 0;
         }
         if ($url == '') {
             $url = 0;
         }
         //1@@1;2;@@2;4;4;@@http://www.chamilo.org
         $dest = $try . '@@' . $lp . '@@' . $destination . '@@' . $url;
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:70,代码来源:unique_answer.class.php

示例7: trim

     }
     // end for()
     if (empty($msgErr)) {
         for ($i = 1; $i <= $nbrAnswers; $i++) {
             if ($debug > 0) {
                 echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
             }
             $reponse[$i] = trim($reponse[$i]);
             $comment[$i] = trim($comment[$i]);
             $weighting[$i] = $weighting[$i];
             //it can be float
             if ($weighting[$i]) {
                 $questionWeighting += $weighting[$i];
             }
             // creates answer
             $objAnswer->createAnswer($reponse[$i], '', $comment[$i], $weighting[$i], $i, $hotspot_coordinates[$i], $hotspot_type[$i]);
         }
         // end for()
         // saves the answers into the data base
         $objAnswer->save();
         // sets the total weighting of the question
         $objQuestion->updateWeighting($questionWeighting);
         $objQuestion->save($exerciseId);
         $editQuestion = $questionId;
         unset($modifyAnswers);
         echo '<script type="text/javascript">window.location.href="' . $hotspot_admin_url . '&message=ItemUpdated"</script>';
     }
     if ($debug > 0) {
         echo '$modifyIn was set - end' . "<br />\n";
     }
 } else {
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:hotspot_admin.inc.php

示例8: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator $form
  */
 function processAnswersCreation($form)
 {
     if (!self::isAnswered()) {
         $table = Database::get_course_table(TABLE_QUIZ_ANSWER);
         Database::delete($table, array('c_id = ? AND question_id = ?' => array($this->course['real_id'], $this->id)));
         $answer = $form->getSubmitValue('answer');
         $formula = $form->getSubmitValue('formula');
         $lowestValues = $form->getSubmitValue('lowestValue');
         $highestValues = $form->getSubmitValue('highestValue');
         $answerVariations = $form->getSubmitValue('answerVariations');
         $this->weighting = $form->getSubmitValue('weighting');
         // Create as many answers as $answerVariations
         for ($j = 0; $j < $answerVariations; $j++) {
             $auxAnswer = $answer;
             $auxFormula = $formula;
             $nb = preg_match_all('/\\[[^\\]]*\\]/', $auxAnswer, $blanks);
             if ($nb > 0) {
                 for ($i = 0; $i < $nb; ++$i) {
                     $blankItem = $blanks[0][$i];
                     $replace = array("[", "]");
                     $newBlankItem = str_replace($replace, "", $blankItem);
                     $newBlankItem = "[" . trim($newBlankItem) . "]";
                     // take random float values when one or both edge values have a decimal point
                     $randomValue = strpos($lowestValues[$i], '.') !== false || strpos($highestValues[$i], '.') !== false ? mt_rand($lowestValues[$i] * 100, $highestValues[$i] * 100) / 100 : mt_rand($lowestValues[$i], $highestValues[$i]);
                     $auxAnswer = str_replace($blankItem, $randomValue, $auxAnswer);
                     $auxFormula = str_replace($blankItem, $randomValue, $auxFormula);
                 }
                 $math = new EvalMath();
                 $result = $math->evaluate($auxFormula);
                 $result = number_format($result, 2, ".", "");
                 // Remove decimal trailing zeros
                 $result = rtrim($result, "0");
                 // If it is an integer (ends in .00) remove the decimal point
                 if (mb_substr($result, -1) === ".") {
                     $result = str_replace(".", "", $result);
                 }
                 // Attach formula
                 $auxAnswer .= " [" . $result . "]@@" . $formula;
             }
             $this->save();
             $objAnswer = new Answer($this->id);
             $objAnswer->createAnswer($auxAnswer, 1, '', $this->weighting, '');
             $objAnswer->position = array();
             $objAnswer->save();
         }
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:51,代码来源:calculated_answer.class.php

示例9: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator $form
  */
 public function processAnswersCreation($form)
 {
     $nb_matches = $form->getSubmitValue('nb_matches');
     $nb_options = $form->getSubmitValue('nb_options');
     $this->weighting = 0;
     $position = 0;
     $objAnswer = new Answer($this->id);
     // Insert the options
     for ($i = 1; $i <= $nb_options; ++$i) {
         $position++;
         $option = $form->getSubmitValue('option[' . $i . ']');
         $objAnswer->createAnswer($option, 0, '', 0, $position);
     }
     // Insert the answers
     for ($i = 1; $i <= $nb_matches; ++$i) {
         $position++;
         $answer = $form->getSubmitValue('answer[' . $i . ']');
         $matches = $form->getSubmitValue('matches[' . $i . ']');
         $weighting = $form->getSubmitValue('weighting[' . $i . ']');
         $this->weighting += $weighting;
         $objAnswer->createAnswer($answer, $matches, '', $weighting, $position);
     }
     $objAnswer->save();
     $this->save();
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:29,代码来源:matching.class.php

示例10: add_question

function add_question($node) {

	$objQuestion = new Question();
	$objQuestion->updateTitle(standard_text_escape($node->content));

	/**
	*Exercice type 1 refers to single response multiple choice question. 
	*Exercice type 2 refers to multiple response multiple choice question. 
	*QTILite allows only single response multiple choice questions.
	**/

	if($node->num_of_correct_answers > 1 ) {
		$objQuestion->updateType(2);
	} else {
		$objQuestion->updateType(1);
	}

	$objQuestion->save();

	$questionId = $objQuestion->selectId();

	$objAnswer = new Answer($questionId);
	$tmp_answer = array();

	if($node->answers) {
		foreach ($node->answers as $answer) {
			$objAnswer->createAnswer($answer['answer'], $answer['correct'], $answer['feedback'], $answer['weight'], 1);
		}
		$objAnswer->save();
	}
}
开发者ID:nikosv,项目名称:openeclass,代码行数:31,代码来源:imsqtilib.php

示例11: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator $form
  */
 public function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     $options_count = $form->getSubmitValue('options_count');
     $course_id = api_get_course_int_id();
     $correct = array();
     $options = Question::readQuestionOption($this->id, $course_id);
     if (!empty($options)) {
         foreach ($options as $option_data) {
             $id = $option_data['id'];
             unset($option_data['id']);
             Question::updateQuestionOption($id, $option_data, $course_id);
         }
     } else {
         for ($i = 1; $i <= 3; $i++) {
             $last_id = Question::saveQuestionOption($this->id, $this->options[$i], $course_id, $i);
             $correct[$i] = $last_id;
         }
     }
     /* Getting quiz_question_options (true, false, doubt) because
        it's possible that there are more options in the future */
     $new_options = Question::readQuestionOption($this->id, $course_id);
     $sorted_by_position = array();
     foreach ($new_options as $item) {
         $sorted_by_position[$item['position']] = $item;
     }
     /* Saving quiz_question.extra values that has the correct scores of
        the true, false, doubt options registered in this format
        XX:YY:ZZZ where XX is a float score value.*/
     $extra_values = array();
     for ($i = 1; $i <= 3; $i++) {
         $score = trim($form->getSubmitValue('option[' . $i . ']'));
         $extra_values[] = $score;
     }
     $this->setExtra(implode(':', $extra_values));
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim($form->getSubmitValue('answer[' . $i . ']'));
         $comment = trim($form->getSubmitValue('comment[' . $i . ']'));
         $goodAnswer = trim($form->getSubmitValue('correct[' . $i . ']'));
         if (empty($options)) {
             //If this is the first time that the question is created when
             // change the default values from the form 1 and 2 by the correct "option id" registered
             $goodAnswer = $sorted_by_position[$goodAnswer]['id'];
         }
         $questionWeighting += $extra_values[0];
         //By default 0 has the correct answers
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, '', $i);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:60,代码来源:multiple_answer_true_false.class.php

示例12: elseif

            } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
                if ($debug > 0) {
                    echo str_repeat('&nbsp;', 4) . '$answerType is MULTIPLE_ANSWER' . "<br />\n";
                }
                // a bad answer can't have a positive weighting
                $weighting[$i] = 0 - abs($weighting[$i]);
            }
            // checks if field is empty
            if (empty($reponse[$i]) && $reponse[$i] != '0') {
                $msgErr = get_lang('GiveAnswers');
                // clears answers already recorded into the Answer object
                $objAnswer->cancel();
                break;
            } else {
                // adds the answer into the object
                $objAnswer->createAnswer($reponse[$i], $goodAnswer, $comment[$i], $weighting[$i], $i);
                //added
                //if($_REQUEST['myid']==1)
                $mainurl = "admin.php";
                //	else
                //  $mainurl="question_pool.php";
                ?>
                <script>
                    window.location.href='<?php 
                echo $mainurl;
                ?>
';
                </script>
                <?php 
            }
        }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:answer_admin.inc.php

示例13: processAnswersCreation

 /**
  * abstract function which creates the form to create / edit the answers of the question
  * @param FormValidator instance
  */
 public function processAnswersCreation($form)
 {
     $questionWeighting = $nbrGoodAnswers = 0;
     $correct = $form->getSubmitValue('correct');
     $objAnswer = new Answer($this->id);
     $nb_answers = $form->getSubmitValue('nb_answers');
     for ($i = 1; $i <= $nb_answers; $i++) {
         $answer = trim($form->getSubmitValue('answer[' . $i . ']'));
         $comment = trim($form->getSubmitValue('comment[' . $i . ']'));
         $weighting = trim($form->getSubmitValue('weighting[' . $i . ']'));
         $scenario = $form->getSubmitValue('scenario');
         //$list_destination = $form -> getSubmitValue('destination'.$i);
         //$destination_str = $form -> getSubmitValue('destination'.$i);
         $try = $scenario['try' . $i];
         $lp = $scenario['lp' . $i];
         $destination = $scenario['destination' . $i];
         $url = trim($scenario['url' . $i]);
         $goodAnswer = $correct == $i ? true : false;
         if ($goodAnswer) {
             $nbrGoodAnswers++;
             $weighting = abs($weighting);
             if ($weighting > 0) {
                 $questionWeighting += $weighting;
             }
         }
         if (empty($try)) {
             $try = 0;
         }
         if (empty($lp)) {
             $lp = 0;
         }
         if (empty($destination)) {
             $destination = 0;
         }
         if ($url == '') {
             $url = 0;
         }
         //1@@1;2;@@2;4;4;@@http://www.chamilo.org
         $dest = $try . '@@' . $lp . '@@' . $destination . '@@' . $url;
         $objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting, $i, null, null, $dest);
     }
     // saves the answers into the data base
     $objAnswer->save();
     // sets the total weighting of the question
     $this->updateWeighting($questionWeighting);
     $this->save();
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:51,代码来源:unique_answer_image.class.php


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