Add conversion from single answer to multiple answer and viceversa - refs #7485

1.10.x
Imanol Losada 10 years ago committed by Yannick Warnier
parent cfdce0d76b
commit 1a18a4cdd0
  1. 15
      main/exercice/admin.php
  2. 55
      main/exercice/question.class.php

@ -109,7 +109,6 @@ $cancelExercise = isset($cancelExercise) ? $cancelExercise : null;
$cancelAnswers = isset($cancelAnswers) ? $cancelAnswers : null;
$modifyIn = isset($modifyIn) ? $modifyIn : null;
$cancelQuestion = isset($cancelQuestion) ? $cancelQuestion : null;
$_course = api_get_course_info();
/* Cleaning all incomplete attempts of the admin/teacher to avoid weird problems
when changing the exercise settings, number of questions, etc */
@ -124,6 +123,10 @@ Event::delete_all_incomplete_attempts(
// get from session
$objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;
$objQuestion = isset($_SESSION['objQuestion']) ? $_SESSION['objQuestion'] : null;
if (isset($_REQUEST['convertAnswer'])) {
$objQuestion = $objQuestion->swapAnswerTypes();
$_SESSION['objQuestion'] = $objQuestion;
}
$objAnswer = isset($_SESSION['objAnswer']) ? $_SESSION['objAnswer'] : null;
// document path
@ -187,6 +190,8 @@ if (!is_object($objExercise)) {
// Exercise can be edited in their course.
if ($objExercise->sessionId != $sessionId) {
api_not_allowed(true);
/*header('Location: '.api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq());
exit;*/
}
// doesn't select the exercise ID if we come from the question pool
@ -274,7 +279,6 @@ if ($cancelAnswers) {
$editQuestion=$modifyAnswers;
unset($modifyAnswers);
}
$nameTools = null;
// modifies the query string that is used in the link of tool name
if ($editQuestion || $modifyQuestion || $newQuestion || $modifyAnswers) {
@ -292,9 +296,9 @@ if (!empty($gradebook) && $gradebook=='view') {
);
}
$interbreadcrumb[] = array("url" => "exercice.php?".api_get_cidreq(),"name" => get_lang('Exercices'));
$interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
if (isset($_GET['newQuestion']) || isset($_GET['editQuestion']) ) {
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(), "name" => $objExercise->name);
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$objExercise->id, "name" => $objExercise->name);
} else {
$interbreadcrumb[] = array("url" => "#", "name" => $objExercise->name);
}
@ -332,6 +336,8 @@ function multiple_answer_true_false_onchange(variable) {
}
document.getElementById(weight_id).value = array_result[result];
}
</script>';
$htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
@ -521,6 +527,7 @@ if ($newQuestion || $editQuestion) {
if ($newQuestion == 'yes') {
$objExercise->edit_exercise_in_lp = true;
}
require 'question_admin.inc.php';
}

@ -683,8 +683,7 @@ abstract class Question
* @author Olivier Brouckaert
* @param integer $exerciseId - exercise ID if saving in an exercise
*/
public function save($exerciseId=0)
{
function save($exerciseId=0) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
@ -700,6 +699,7 @@ abstract class Question
$c_id = $this->course['real_id'];
$category = $this->category;
// question already exists
if(!empty($id)) {
$sql="UPDATE $TBL_QUESTIONS SET
@ -1143,13 +1143,24 @@ abstract class Question
* A subclass can redifine this function to add fields...
* @param FormValidator $form the formvalidator instance (by reference)
*/
function createForm (&$form, $fck_config=0)
{
function createForm (&$form, $fck_config=0) {
echo '<style>
.media { display:none;}
</style>';
echo '<script>
// hack to hide http://cksource.com/forums/viewtopic.php?f=6&t=8700
function FCKeditor_OnComplete( editorInstance ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstance.Name )) {
HideFCKEditorByInstanceName (editorInstance.Name);
}
}
function HideFCKEditorByInstanceName ( editorInstanceName ) {
if (document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className == "HideFCKEditor" ) {
document.getElementById ( \'HiddenFCK\' + editorInstanceName ).className = "media";
}
}
function show_media(){
var my_display = document.getElementById(\'HiddenFCKquestionDescription\').style.display;
@ -1206,7 +1217,7 @@ abstract class Question
<a href="javascript://" onclick=" return show_media()"><span id="media_icon"><img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('EnrichQuestion').'</span></a>
');
$form->addElement ('html','<div class="HideFCKEditor" id="HiddenFCKquestionDescription" style="display:none">');
$form->addElement ('html','<div class="HideFCKEditor" id="HiddenFCKquestionDescription" >');
$form->add_html_editor('questionDescription', get_lang('QuestionDescription'), false, false, $editor_config);
$form->addElement ('html','</div>');
@ -1232,6 +1243,11 @@ abstract class Question
$tabCat = Testcategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat);
if (in_array($this->type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER))) {
$buttonValue = $this->type == UNIQUE_ANSWER ? 'ConvertToMultipleAnswer' : 'ConvertToUniqueAnswer';
$form->addElement('button', 'convertAnswer', get_lang($buttonValue));
}
//Medias
//$course_medias = Question::prepare_course_media_select(api_get_course_int_id());
//$form->addElement('select', 'parent_id', get_lang('AttachToMedia'), $course_medias);
@ -1611,4 +1627,31 @@ abstract class Question
}
return $html;
}
/**
* Swap between unique and multiple type answers
* @return object
*/
function swapAnswerTypes()
{
$oppositeAnswers = array(
UNIQUE_ANSWER => MULTIPLE_ANSWER,
MULTIPLE_ANSWER => UNIQUE_ANSWER
);
$this->type = $oppositeAnswers[$this->type];
Database::update(
Database::get_course_table(TABLE_QUIZ_QUESTION),
array('type' => $this->type),
array('c_id = ? AND id = ?' => array($this->course['real_id'], $this->id))
);
$answerClasses = array(
UNIQUE_ANSWER => 'UniqueAnswer',
MULTIPLE_ANSWER => 'MultipleAnswer'
);
$swappedAnswer = new $answerClasses[$this->type];
foreach ($this as $key => $value) {
$swappedAnswer->$key = $value;
}
return $swappedAnswer;
}
}

Loading…
Cancel
Save