Fixiong exercise UNIQUE_ANSWER_NO_OPTION

skala
Julio Montoya 15 years ago
parent 7624621780
commit 6faecd5023
  1. 3
      main/exercice/admin.php
  2. 39
      main/exercice/answer.class.php
  3. 3
      main/exercice/exercice.php
  4. 2
      main/exercice/exercise.class.php
  5. 9
      main/exercice/exercise.lib.php
  6. 1
      main/exercice/question_admin.inc.php
  7. 63
      main/exercice/question_list_admin.inc.php
  8. 132
      main/exercice/unique_answer_no_option.class.php

@ -500,5 +500,4 @@ api_session_register('objExercise');
api_session_register('objQuestion');
api_session_register('objAnswer');
Display::display_footer();
?>
Display::display_footer();

@ -45,10 +45,9 @@ class Answer
* @author Olivier Brouckaert
* @param integer Question ID that answers belong to
*/
function Answer($questionId)
{
function Answer($questionId) {
//$this->questionType=$questionType;
$this->questionId = (int)$questionId;
$this->questionId = intval($questionId);
$this->answer = array();
$this->correct = array();
$this->comment = array();
@ -75,8 +74,7 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function cancel()
{
function cancel() {
$this->new_answer = array();
$this->new_correct = array();
$this->new_comment = array();
@ -93,8 +91,7 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function read()
{
function read() {
global $_course;
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
@ -102,7 +99,7 @@ class Answer
//$answerType=$this->selectType();
$sql="SELECT id,answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination, id_auto FROM
$TBL_ANSWER WHERE question_id ='".Database::escape_string($questionId)."' ORDER BY position";
$TBL_ANSWER WHERE question_id ='".$questionId."' ORDER BY position";
$result=Database::query($sql);
@ -130,24 +127,20 @@ class Answer
* @param string DESC or ASC
* @author Frederic Vauthier
*/
function readOrderedBy($field,$order=ASC)
{
function readOrderedBy($field,$order='ASC') {
global $_course;
$field = Database::escape_string($field);
if(empty($field)) {
if (empty($field)) {
$field = 'position';
}
if($order != 'ASC' and $order!='DESC')
{
if ($order != 'ASC' && $order!='DESC') {
$order = 'ASC';
}
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId=$this->questionId;
//$answerType=$this->selectType();
$sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " .
"FROM $TBL_ANSWER WHERE question_id='".Database::escape_string($questionId)."' " .
"FROM $TBL_ANSWER WHERE question_id='".$questionId."' " .
"ORDER BY $field $order";
$result=Database::query($sql);
@ -155,8 +148,7 @@ class Answer
$i=1;
// while a record is found
while($object=Database::fetch_object($result))
{
while($object=Database::fetch_object($result)) {
$this->answer[$i] = $object->answer;
$this->correct[$i] = $object->correct;
$this->comment[$i] = $object->comment;
@ -231,7 +223,6 @@ class Answer
* return array answer by id else return a bool
*/
function selectAnswerByAutoId($auto_id) {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$auto_id = intval($auto_id);
$sql="SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'";
@ -252,8 +243,7 @@ class Answer
* @param - integer $id - answer ID
* @return - bool - answer title
*/
function selectAnswerIdByPosition($pos)
{
function selectAnswerIdByPosition($pos) {
foreach ($this->position as $k => $v) {
if ($v != $pos) { continue; }
return $k;
@ -266,8 +256,7 @@ class Answer
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting
*/
function getAnswersList($decode = false)
{
function getAnswersList($decode = false) {
$list = array();
for($i = 1; $i<=$this->nbrAnswers;$i++){
if(!empty($this->answer[$i])){
@ -316,7 +305,7 @@ class Answer
function getQuestionType()
{
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".Database::escape_string($this->questionId)."'";
$sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".$this->questionId."'";
$res = Database::query($sql);
if(Database::num_rows($res)<=0){
return null;

@ -827,8 +827,7 @@ if ($show == 'test') {
echo '<br />'.get_count_exam_results($row['id']).' '.get_lang('Attempts');
//Special buttons
echo '<div class="operations">';
echo '<div class="operations">';
echo Display::url(Display::return_icon('quiz.gif',get_lang('Questions'), array('width'=>'22px'))." ".get_lang('Questions'),'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
echo ' ';
echo Display::url(Display::return_icon('preview.gif',get_lang('Preview'), array('width'=>'22px'))." ".get_lang('Preview'), 'exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id']);

@ -2388,7 +2388,7 @@ class Exercise {
} elseif ($answerType == FREE_ANSWER) {
$answer = $choice;
exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
} elseif ($answerType == UNIQUE_ANSWER) {
} elseif ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
$answer = $choice;
exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
} elseif ($answerType == HOT_SPOT) {

@ -88,6 +88,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$s .= '<table width="720" class="exercise_options" style="width: 720px;'.$option_ie.' background-color:#fff;">';
// construction of the Answer object (also gets all answers details)
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$quiz_question_options = Question::readQuestionOption($questionId);
@ -255,15 +256,15 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
if ($debug_mark_answer) {
if ($answerCorrect) {
$help = 'x-';
$selected = 'checked="checked"';
$selected = 'checked';
}
}
$answer = text_filter($answer);
$answer = Security::remove_XSS($answer, STUDENT);
$s .= '<input type="hidden" name="choice2['.$questionId.']" value="0" />'.
$s .= Display::input('hidden','choice2['.$questionId.']','0').
'<tr><td colspan="3"><div class="u-m-answer"><p style="float: '.($is_ltr_text_direction ? 'left' : 'right').'; padding-'.($is_ltr_text_direction ? 'right' : 'left').': 4px;">'.
'<span><input class="checkbox" type="radio" name="choice['.$questionId.']" value="'.$numAnswer.'" '.$selected.' /></span></p>'.
'<span>'.Display::input('radio','choice['.$questionId.']', $numAnswer, array('class'=>'checkbox','selected'=>$selected)).'</span></p>'.
'<div style="margin-'.($is_ltr_text_direction ? 'left' : 'right').': 24px;">'.
$answer.
'</div></div></td></tr>';
@ -413,6 +414,8 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
}
} // end for()
//Adding divs for the new MATCHING interface
if ($answerType == MATCHING && !$freeze) {

@ -90,6 +90,7 @@ if(is_object($objQuestion)) {
// question
$objQuestion -> processCreation($form,$objExercise);
// answers
$objQuestion -> processAnswersCreation($form,$nb_answers);
// TODO: maybe here is the better place to index this tool, including answers text

@ -119,6 +119,7 @@ if ($nbrQuestions) {
$questionList=$my_exercise->selectQuestionList();
$i=1;
if (is_array($questionList)) {
echo '<div id="question_list">';
foreach($questionList as $id) {
@ -140,49 +141,25 @@ if ($nbrQuestions) {
echo '<div id="question_id_list_'.$id.'" >';
$move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved'));
echo Display::tag('h3','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().'</a>');
echo '<div>';
echo '<p>';
echo $actions;
echo get_lang($question_class.$label);
echo '<br />';
echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
echo '<br />';
$description = $objQuestionTmp->selectDescription();
if (!empty($description)) {
echo get_lang('Description').': '.$description;
}
showQuestion($id, false, '', '',false, true);
/*
if($i != 1) { ?>
<a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq() ?>&moveUp=<?php echo $id; ?>&token=<?php echo $token; ?>"><img src="../img/up.gif" border="0" alt="<?php echo get_lang('MoveUp'); ?>"></a>
<?php if($i == $nbrQuestions) {
echo '<img src="../img/down_na.gif">';
}
}
if($i != $nbrQuestions) {
if($i == 1){
echo '<img src="../img/up_na.gif">';
}
?>
<a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq() ?>&moveDown=<?php echo $id; ?>&token=<?php echo $token; ?>"><img src="../img/down.gif" border="0" alt="<?php echo get_lang('MoveDown'); ?>"></a>
<?php } ?>
<?php
$i++;
*/
echo '</p>';
echo '</div>';
echo '</div>';
unset($objQuestionTmp);
echo '<div>';
echo '<p>';
echo $actions;
echo get_lang($question_class.$label);
echo '<br />';
echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
echo '<br />';
$description = $objQuestionTmp->selectDescription();
if (!empty($description)) {
echo get_lang('Description').': '.$description;
}
showQuestion($id, false, '', '',false, true);
echo '</p>';
echo '</div>';
echo '</div>';
unset($objQuestionTmp);
}
echo '</div>';
}

@ -249,52 +249,51 @@ class UniqueAnswerNoOption extends Question {
}
//Adding I don't know question option
$i = 666;
$form -> addElement ('html', '<tr>');
$defaults['answer['.$i.']'] = get_lang('DontKnow');
$defaults['weighting['.$i.']'] = 0;
$defaults['scenario']=$temp_scenario;
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>','html');
$answer_number=$form->addElement('text', null,null,'value="-"');
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
/* // direct feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
//Adding extra feedback fields
$group = array();
$group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' );
$group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id);
$group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question);
$group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px'));
$form -> addGroup($group, 'scenario', 'scenario');
$renderer->setGroupElementTemplate('<div class="exercise_scenario_label">{label}</div><div class="exercise_scenario_element">{element}</div>','scenario');*/
}
//$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
$form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0" readonly="readonly" ');
$form->addElement ('html', '</tr>');
//Adding the "I don't know" question answer
if(empty($this -> id)) {
$i = 666;
$form -> addElement ('html', '<tr>');
$defaults['answer['.$i.']'] = get_lang('DontKnow');
$defaults['weighting['.$i.']'] = 0;
$defaults['scenario']=$temp_scenario;
$renderer = & $form->defaultRenderer();
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>');
$renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error --><br/>{element}</td>','html');
$answer_number=$form->addElement('text', null,null,'value="-"');
$answer_number->freeze();
$form->addElement('radio', 'correct', null, null, $i, 'class="checkbox" style="margin-left: 0em;"');
$form->addElement('html_editor', 'answer['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
$form->addRule('answer['.$i.']', get_lang('ThisFieldIsRequired'), 'required');
if ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_END) {
// feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
} elseif ($obj_ex->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
/* // direct feedback
$form->addElement('html_editor', 'comment['.$i.']', null, 'style="vertical-align:middle"', $editor_config);
//Adding extra feedback fields
$group = array();
$group['try'.$i] =&$form->createElement('checkbox', 'try'.$i,get_lang('TryAgain').': ' );
$group['lp'.$i] =&$form->createElement('select', 'lp'.$i,get_lang('SeeTheory').': ',$select_lp_id);
$group['destination'.$i]=&$form->createElement('select', 'destination'.$i, get_lang('GoToQuestion').': ' ,$select_question);
$group['url'.$i] =&$form->createElement('text', 'url'.$i,get_lang('Other').': ',array('size'=>'25px'));
$form -> addGroup($group, 'scenario', 'scenario');
$renderer->setGroupElementTemplate('<div class="exercise_scenario_label">{label}</div><div class="exercise_scenario_element">{element}</div>','scenario');*/
}
//$form->addElement('select', 'destination'.$i, get_lang('SelectQuestion').' : ',$select_question,'multiple');
$form->addElement('text', 'weighting['.$i.']', null, 'style="vertical-align:middle;margin-left: 0em;" size="5" value="0" readonly="readonly" ');
$form->addElement ('html', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$navigator_info = api_get_navigator();
@ -347,16 +346,16 @@ class UniqueAnswerNoOption extends Question {
$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.']'));
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');
echo '<pre>';
//$list_destination = $form -> getSubmitValue('destination'.$i);
//$destination_str = $form -> getSubmitValue('destination'.$i);
@ -387,12 +386,10 @@ class UniqueAnswerNoOption extends Question {
$goodAnswer= ($correct == $i) ? true : false;
if($goodAnswer)
{
if($goodAnswer) {
$nbrGoodAnswers++;
$weighting = abs($weighting);
if($weighting > 0)
{
if($weighting > 0) {
$questionWeighting += $weighting;
}
}
@ -400,30 +397,33 @@ class UniqueAnswerNoOption extends Question {
if (empty($try))
$try=0;
if (empty($lp))
{
if (empty($lp)) {
$lp=0;
}
if (empty($destination))
{
if (empty($destination)) {
$destination=0;
}
if ($url=='')
{
if ($url=='') {
$url=0;
}
//1@@1;2;@@2;4;4;@@http://www.dokeos.com
//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);
}
//Create 666 answer
$i = 666;
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$goodAnswer= ($correct == $i) ? true : false;
$dest = '';
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i,NULL,NULL,$dest);
// saves the answers into the data base
$objAnswer -> save();

Loading…
Cancel
Save