Removing exit functions (used for testing) + some fixes when using hotspots see BT#1917

skala
Julio Montoya 14 years ago
parent bdfc7a6f57
commit e079bc18cf
  1. 32
      main/exercice/answer.class.php
  2. 58
      main/exercice/exercise.lib.php
  3. 59
      main/exercice/question.class.php
  4. 19
      main/exercice/question_admin.inc.php
  5. 17
      main/exercice/question_list_admin.inc.php
  6. 55
      main/exercice/question_pool.php

@ -24,7 +24,6 @@ class Answer
public $hotspot_coordinates;
public $hotspot_type;
public $destination;
// these arrays are used to save temporarily new answers
// then they are moved into the arrays above or deleted in the event of cancellation
public $new_answer;
@ -38,7 +37,7 @@ class Answer
public $nbrAnswers;
public $new_nbrAnswers;
public $new_destination; // id of the next question if feedback option is set to Directfeedback
public $course;
public $course; //Course information
/**
* constructor of the class
@ -452,8 +451,7 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function save()
{
function save() {
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$questionId=$this->questionId;
@ -503,7 +501,8 @@ class Answer
* Duplicates answers by copying them into another question
*
* @author Olivier Brouckaert
* @param int $newQuestionId - ID of the new question
* @param int question id
* @param array course info (result of the function api_get_course_info() )
*/
function duplicate($newQuestionId, $course_info = null) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
@ -516,20 +515,16 @@ class Answer
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $course_info['db_name']);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
var_dump($this->selectQuestionId(), $newQuestionId);
//Selecting origin options
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
//Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(),$this->course['db_name']);
var_dump($origin_options);
//var_dump($origin_options);
if (!empty($origin_options)) {
foreach($origin_options as $item) {
$new_option_list[]=$item['id'];
}
}
}
$destination_options = Question::readQuestionOption($newQuestionId,$course_info['db_name']);
$i=0;
@ -540,7 +535,7 @@ class Answer
$i++;
}
}
var_dump($fixed_list);
//var_dump($fixed_list);
}
// if at least one answer
@ -556,8 +551,7 @@ class Answer
$answer = Database::escape_string($this->answer[$i]);
$correct = Database::escape_string($this->correct[$i]);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
var_dump($correct);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
$correct = $fixed_list[intval($correct)];
}
@ -576,6 +570,4 @@ class Answer
}
}
}
endif;
?>
endif;

@ -31,20 +31,22 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
// Reads question informations.
if (!$objQuestionTmp = Question::read($questionId)) {
// question not found
// question not found
return false;
}
$answerType = $objQuestionTmp->selectType();
$pictureName = $objQuestionTmp->selectPicture();
if ($answerType != HOT_SPOT) {
// Question is not of type hotspot
if (!$onlyAnswers) {
$questionName=$objQuestionTmp->selectTitle();
$questionDescription=$objQuestionTmp->selectDescription();
$questionName=text_filter($questionName);
$questionName = $objQuestionTmp->selectTitle();
$questionDescription = $objQuestionTmp->selectDescription();
$questionName = text_filter($questionName);
if ($show_title) {
$s='<div id="question_title" class="sectiontitle">'.get_lang('Question').' ';
@ -69,8 +71,9 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
<td align='center' colspan='2'><img src='../document/download.php?doc_url=%2Fimages%2F'".$pictureName."' border='0'></td>
</tr>";
}
$s.= '</table>';
}
$s.= '</table>';
$s .= '<div class="rounded exercise_questions" style="width: 720px; padding: 3px;">';
$option_ie = '';
@ -87,13 +90,12 @@ 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);
$objAnswerTmp = new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$nbrAnswers = $objAnswerTmp->selectNbrAnswers();
$quiz_question_options = Question::readQuestionOption($questionId);
// For "matching" type here, we need something a little bit special
// because the match between the suggestions and the answers cannot be
// done easily (suggestions and answers are in the same table), so we
@ -218,9 +220,9 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
});
});
</script>
</script>
<?php
// Now navigate through the possible answers, using the max number of
// answers for the question as a limiter
$lines_count=1; // a counter for matching-type answers
@ -253,6 +255,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
if ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
// set $debug_mark_answer to true at function start to
// show the correct answer with a suffix '-x'
$help = $selected = '';
if ($debug_mark_answer) {
if ($answerCorrect) {
@ -477,7 +480,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
if ($freeze) {
echo Display::img($objQuestionTmp->selectPicturePath());
exit;
return;
}
// Get the answers, make a list
@ -1108,21 +1111,24 @@ function show_score($score, $weight, $show_porcentage = true) {
return $html;
}
/**
* Converts a score to the platform scale
* @param float score
* @param float weight
* @return float the score rounded converted to the new range
*/
function convert_score($score, $weight) {
$html = '';
$score_rounded = $score;
$score_rounded = $score;
if ($score != '' && $weight != '') {
$max_note = api_get_setting('exercise_max_score');
$min_note = api_get_setting('exercise_min_score');
if ($max_note != '' && $min_note != '') {
if (!empty($weight)) {
$score = $min_note + ($max_note - $min_note) * $score /$weight;
if (!empty($weight)) {
$score = $min_note + ($max_note - $min_note) * $score /$weight;
} else {
$score = $min_note;
$score = $min_note;
}
$score_rounded = round($score, 2);
}
@ -1131,13 +1137,23 @@ function convert_score($score, $weight) {
}
function get_all_exercises($course_info = null) {
function get_all_exercises($course_info = null, $session_id = 0) {
if(!empty($course_info)) {
$TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['db_name']);
} else {
$TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
}
return Database::select('*',$TBL_EXERCICES, array('where'=>array('active <> ?'=>'-1'), 'order'=>'title'));
if ($session_id == -1) {
$session_id = 0;
}
//var_dump($session_id);
if ($session_id == 0) {
$conditions = array('where'=>array('active <> ? AND session_id = ? '=>array('-1',$session_id)), 'order'=>'title');
} else {
$conditions = array('where'=>array('active <> ?'=>'-1'), 'order'=>'title');
}
//var_dump($conditions);
return Database::select('*',$TBL_EXERCICES, $conditions);
}

@ -93,25 +93,26 @@ abstract class Question
* @param - integer $id - question ID
* @return - boolean - true if question exists, otherwise false
*/
static function read($id, $course_id = null) {
static function read($id, $course_id = null) {
$id = intval($id);
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
} else {
global $course;
$course_info = api_get_course_info();
}
}
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST, $course_info['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['db_name']);
$id = intval($id);
$sql="SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE id= $id ";
$result=Database::query($sql);
// if the question has been found
if ($object=Database::fetch_object($result)) {
if ($object = Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type);
$objQuestion->id = $id;
$objQuestion->question = $object->question;
@ -133,7 +134,6 @@ abstract class Question
}
return $objQuestion;
}
// question not found
return false;
}
@ -384,8 +384,7 @@ abstract class Question
* @param - integer $Max - Maximum size
* @return - boolean - true if success, false if failed
*/
function resizePicture($Dimension, $Max)
{
function resizePicture($Dimension, $Max) {
global $picturePath;
// if the question has an ID
@ -492,28 +491,25 @@ abstract class Question
* @param - integer $questionId - ID of the target question
* @return - boolean - true if copied, otherwise false
*/
function exportPicture($questionId)
{
global $TBL_QUESTIONS, $picturePath;
function exportPicture($questionId, $course_info) {
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$destination_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images';
$source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images';
// if the question has got an ID and if the picture exists
if($this->id && !empty($this->picture))
{
if($this->id && !empty($this->picture)) {
$picture=explode('.',$this->picture);
$Extension=$picture[sizeof($picture)-1];
$picture='quiz-'.$questionId.'.'.$Extension;
$sql="UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string($picture)."' WHERE id='".Database::escape_string($questionId)."'";
Database::query($sql);
return @copy($picturePath.'/'.$this->picture,$picturePath.'/'.$picture)?true:false;
$sql="UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string($picture)."' WHERE id='".intval($questionId)."'";
Database::query($sql);
return @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture)?true:false;
}
return false;
}
/**
* saves the picture coming from POST into a temporary file
* Saves the picture coming from POST into a temporary file
* Temporary pictures are used when we don't want to save a picture right after a form submission.
* For example, if we first show a confirmation box.
*
@ -521,8 +517,7 @@ abstract class Question
* @param - string $Picture - temporary path of the picture to move
* @param - string $PictureName - Name of the picture
*/
function setTmpPicture($Picture,$PictureName)
{
function setTmpPicture($Picture,$PictureName) {
global $picturePath;
$PictureName=explode('.',$PictureName);
@ -925,8 +920,9 @@ abstract class Question
/**
* Duplicates the question
*
* @author - Olivier Brouckaert
* @return - integer - ID of the new question
* @author Olivier Brouckaert
* @param array Course info of the destination course
* @return int ID of the new question
*/
function duplicate($course_info = null) {
@ -935,7 +931,7 @@ abstract class Question
} else {
$course_info = $course_info;
}
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION, $course_info['db_name']);
$question = $this->question;
@ -946,19 +942,20 @@ abstract class Question
$level = intval($this->level);
$extra = $this->extra;
//Using the same method used in the course copy to transform URLs
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
if ($course_info['db_name'] != $this->course['db_name']) {
$description = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']);
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']);
}
$options = self::readQuestionOption($this->id);
$options = self::readQuestionOption($this->id);
//Inserting in the new course db / or the same course db
$sql="INSERT INTO $TBL_QUESTIONS(question, description, ponderation, position, type, level, extra ) VALUES('".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."' )";
Database::query($sql);
$new_question_id =Database::insert_id();
$new_question_id =Database::insert_id();
if (!empty($options)) {
//Saving the quiz_options
foreach ($options as $item) {
@ -968,8 +965,8 @@ abstract class Question
}
}
// duplicates the picture
$this->exportPicture($new_question_id);
// Duplicates the picture
$this->exportPicture($new_question_id, $course_info);
return $new_question_id;
}

@ -10,10 +10,7 @@
* @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
*/
/*
INIT SECTION
*/
/* INIT SECTION */
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'image.lib.php';
@ -22,9 +19,7 @@ if(!defined('ALLOWED_TO_INCLUDE')) {
exit();
}
// INIT QUESTION
if(isset($_GET['editQuestion'])) {
$objQuestion = Question::read ($_GET['editQuestion']);
$action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
@ -66,7 +61,6 @@ if(is_object($objQuestion)) {
// form title
$form->addElement('header', '', $text.': '.$form_title_extra);
// question form elements
$objQuestion -> createForm ($form,array('Height'=>150));
@ -100,14 +94,8 @@ if(is_object($objQuestion)) {
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'"</script>';
else
echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
} else {
/******************
* FORM DISPLAY
******************/
} else {
echo '<h3>'.$questionName.'</h3>';
if(!empty($pictureName)){
echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
}
@ -117,5 +105,4 @@ if(is_object($objQuestion)) {
// display the form
$form->display();
}
}
?>
}

@ -1,13 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Code library for HotPotatoes integration.
* @package chamilo.exercise
* @author
*/
/**
* QUESTION LIST ADMINISTRATION
*
@ -15,7 +13,6 @@
* It is included from the script admin.php
*
* @author Olivier Brouckaert
* @package chamilo.exercise
*/
// ALLOWED_TO_INCLUDE is defined in admin.php
@ -121,28 +118,30 @@ if ($nbrQuestions) {
$i=1;
if (is_array($questionList)) {
echo '<div id="question_list">';
foreach($questionList as $id) {
echo '<div id="question_list">';
foreach($questionList as $id) {
//To avoid warning messages
if (!is_numeric($id)) {
continue;
}
$objQuestionTmp = Question :: read($id);
$question_class = get_class($objQuestionTmp);
$question_class = get_class($objQuestionTmp);
$label = $question_class->$explanationLangVar;
$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'"><img src="../img/edit.gif" border="0" alt="'.get_lang('Modify').'" /></a>';
// this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
if ($show_quiz_edition) {
$delete_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'))).' \')) return false;"><img src="../img/delete.gif" border="0" alt="'.get_lang('Delete').'" /></a>';
$delete_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'))).' \')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
}
$actions = Display::tag('div',$edit_link.$delete_link, array('style'=>'float:right'));
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 '<div>';
echo '<p>';
echo $actions;
echo get_lang($question_class.$label);

@ -59,8 +59,7 @@ if(!empty($_GET['type'])){
$type = intval($_GET['type']);
}
$session_id = intval($_GET['session_id']);
$session_id = intval($_GET['session_id']);
$selected_course = intval($_GET['selected_course']);
@ -96,16 +95,18 @@ if ($is_allowedToEdit) {
$old_question_obj = Question::read($old_question_id, $origin_course_id);
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating question in the current course
//Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course);
//Reading new question
$new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise);
//Reading Answer obj from origin course
//Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read();
//Duplicating the answers in this course
//Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object
@ -119,7 +120,7 @@ if ($is_allowedToEdit) {
// adds the question ID represented by $recup into the list of questions for the current exercise
//$objExercise->addToList($new_id);
api_session_register('objExercise');
exit;
header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
exit();
@ -241,7 +242,7 @@ echo '<form name="question_pool" method="GET" action="'.$url.'" style="display:i
foreach ($course_list as $item) {
$course_select_list[$item['id']] = $item['title'];
}
echo get_lang('Course').' : ';
echo Display::select('selected_course', $course_select_list, $selected_course, array('onchange'=>'submit_form(this);'));
@ -259,7 +260,7 @@ echo '<form name="question_pool" method="GET" action="'.$url.'" style="display:i
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $db_name);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER, $db_name);
$exercise_list = get_all_exercises($course_info);
$exercise_list = get_all_exercises($course_info, $session_id);
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
@ -410,11 +411,15 @@ if ($exerciseId > 0) {
$main_question_list = array();
if (!empty($course_list))
foreach ($course_list as $course_item) {
if (!empty($selected_course) && $selected_course != '-1')
if (!empty($selected_course) && $selected_course != '-1') {
if ($selected_course != $course_item['id']) {
continue;
}
$exercise_list = get_all_exercises($course_item);
}
$exercise_list = get_all_exercises($course_item, $session_id);
//var_dump($exercise_list );
if (!empty($exercise_list)) {
foreach ($exercise_list as $exercise) {
@ -422,21 +427,23 @@ if ($exerciseId > 0) {
$my_exercise->read($exercise['id']);
if (!empty($my_exercise)) {
if (!empty($my_exercise->questionList))
foreach ($my_exercise->questionList as $question) {
$question_obj = Question::read($question['id'], $course_item['id']);
if ($exerciseLevel != '-1')
if ($exerciseLevel != $question_obj->level) {
continue;
if (!empty($my_exercise->questionList)) {
foreach ($my_exercise->questionList as $question_id) {
$question_obj = Question::read($question_id, $course_item['id']);
if ($exerciseLevel != '-1')
if ($exerciseLevel != $question_obj->level) {
continue;
}
if ($answerType != '-1')
if ($answerType != $question_obj->type) {
continue;
}
$question_row = array('id'=>$question_obj->id, 'question'=>$question_obj->question, 'type'=>$question_obj->type, 'level'=>$question_obj->level, 'exercise_id'=>$exercise['id']);
$main_question_list[] = $question_row;
}
if ($answerType != '-1')
if ($answerType != $question_obj->type) {
continue;
}
$question_row = array('id'=>$question_obj->id, 'question'=>$question_obj->question, 'type'=>$question_obj->type, 'level'=>$question_obj->level, 'exercise_id'=>$exercise['id']);
$main_question_list[] = $question_row;
}
}
}

Loading…
Cancel
Save