Remove c_id warning message. Now if a calculated question is answered it can be edited - refs #7212

1.9.x
Imanol Losada 12 years ago
parent ce8f8d4301
commit cc2b1c5c0a
  1. 123
      main/exercice/calculated_answer.class.php
  2. 22
      main/exercice/question_list_admin.inc.php
  3. 47
      main/lang/english/exercice.inc.php
  4. 1
      main/lang/spanish/exercice.inc.php

@ -179,54 +179,64 @@ class CalculatedAnswer extends Question
*/
function processAnswersCreation($form)
{
global $charset;
$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');
//Remove previous answers
Database::delete("c_quiz_answer", array('question_id = ?' => $this->id));
// 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);
}
require_once(api_get_path(LIBRARY_PATH).'evalmath.class.php');
$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);
if (!self::isAnswered()) {
// Can't use TABLE_QUIZ_ANSWER because it returns "quiz_answer"
// instead of "c_quiz_answer"
$table = Database::get_main_table("c_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);
}
require_once(api_get_path(LIBRARY_PATH).'evalmath.class.php');
$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;
}
// Attach formula
$auxAnswer .= " [".$result."]@@".$formula;
$this->save();
$objAnswer = new answer($this->id);
$objAnswer->createAnswer($auxAnswer, 1, '', $this->weighting, null);
$objAnswer->position = array();
$objAnswer->save();
}
$this->save();
$objAnswer = new answer($this->id);
$objAnswer->createAnswer($auxAnswer, 1, '', $this->weighting, null);
$objAnswer->position = array();
$objAnswer->save();
}
}
@ -245,4 +255,25 @@ class CalculatedAnswer extends Question
</tr>';
return $header;
}
/**
* Returns true if the current question has been attempted to be answered
* @return boolean
*/
public function isAnswered()
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$result = Database::select(
'question_id',
$table,
array(
'where' => array(
'question_id = ?' => array(
$this->id
)
)
)
);
return empty($result) ? false : true;
}
}

@ -170,7 +170,27 @@ if (!$inATest) {
$question_class = get_class($objQuestionTmp);
$clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
/*$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
if ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) {
$edit_link = '<a>'.Display::return_icon('edit_na.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
}*/
$edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
'<a>'.Display::return_icon(
'edit_na.png',
get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
array(),
ICON_SIZE_SMALL
).'</a>' :
'<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
Display::return_icon(
'edit.png',
get_lang('Modify'),
array(),
ICON_SIZE_SMALL
).'</a>';
if ($objExercise->edit_exercise_in_lp == true) {
$delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';

@ -2,6 +2,7 @@
/*
for more information: see languages.txt in the lang folder.
*/
$QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy = "Question edition is not available because the question has been already answered. However, you can copy and modify it.";
$SelectADateOnTheCalendar = "Select a date from the calendar";
$AreYouSureDeleteTestResultBeforeDateD = "Are you sure you want to clean results for this test before the selected date ?";
$CleanStudentsResultsBeforeDate = "Clean all results before a selected date";
@ -9,18 +10,18 @@ $AreYouSureToEmptyAllTestResults = "Clear all learners results for every exercis
$CleanAllStudentsResultsForAllTests = "Are you sure to delete all test's results ?";
$TestFeedbackNotShown = "This test is configured not to display feedback to learners. Comments will not be seen at the end of the test, but may be useful for you, as teacher, when reviewing the question details.";
$FeedbackDisplayOptions = "How should we show the feedback/comment for each question? This option defines how it will be shown to the learner when taking the test. We recommend you try different options by editing your test options before having learners take it.";
$ImportAikenQuizExplanationExample = "This is the text for question 1
A. Answer 1
B. Answer 2
C. Answer 3
ANSWER: B
This is the text for question 2
A. Answer 1
B. Answer 2
C. Answer 3
D. Answer 4
ANSWER: D
$ImportAikenQuizExplanationExample = "This is the text for question 1
A. Answer 1
B. Answer 2
C. Answer 3
ANSWER: B
This is the text for question 2
A. Answer 1
B. Answer 2
C. Answer 3
D. Answer 4
ANSWER: D
ANSWER_EXPLANATION: this is an optional feedback comment that will appear next to the correct answer.";
$ImportAikenQuizExplanation = "The Aiken format comes in a simple text (.txt) file, with several question blocks, each separated by a blank line. The first line is the question, the answer lines are prefixed by a letter and a dot, and the correct answer comes next with the ANSWER: prefix. See example below.";
$ExerciseAikenErrorNoAnswerOptionGiven = "The imported file has at least one question without any answer (or the answers do not include the required prefix letter). Please make sure each question has at least one answer and that it is prefixed by a letter and a dot or a parenthesis, like this: A. answer one";
@ -36,18 +37,18 @@ $YesImSure = "Yes, I'm sure!";
$NoIWantToTurnBack = "No, I want to continue the exercise.";
$QuestionReused = "Question added in the exercise";
$QuestionCopied = "Question copied to the exercise";
$ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected = "-1 = All questions will be selected.
$ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected = "-1 = All questions will be selected.
0 = No questions will be selected.";
$EmailNotificationTemplateDescription = "You can customize the email sent to users when they finished the exercise. You can use tags like these:
1. {{ student.username }}
2. {{ student.firstname }}
3. {{ student.lastname }}
4. {{ student.official_code }}
5. {{ exercise.title }}
6. {{ exercise.start_time }}
7. {{ exercise.end_time }}
8. {{ course.title }}
$EmailNotificationTemplateDescription = "You can customize the email sent to users when they finished the exercise. You can use tags like these:
1. {{ student.username }}
2. {{ student.firstname }}
3. {{ student.lastname }}
4. {{ student.official_code }}
5. {{ exercise.title }}
6. {{ exercise.start_time }}
7. {{ exercise.end_time }}
8. {{ course.title }}
9. {{ course.code }}";
$EmailNotificationTemplate = "Email notification template";
$ExerciseEndButtonDisconnect = "Logout";

@ -2,6 +2,7 @@
/*
for more information: see languages.txt in the lang folder.
*/
$QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy = "No puede editar la pregunta porque alguien ya la respondió. Sin embargo, puede copiarla y modificar dicha copia.";
$SelectADateOnTheCalendar = "Seleccione una fecha del calendario";
$AreYouSureDeleteTestResultBeforeDateD = "¿Está seguro que desea eliminar los resultados de este ejercicio antes de la fecha seleccionada?";
$CleanStudentsResultsBeforeDate = "Eliminar todos los resultados antes de la fecha selecionada";

Loading…
Cancel
Save