From e079bc18cfe7b8cffbe527b56a9dd4ce422b563d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 3 Jan 2011 13:57:10 +0100 Subject: [PATCH] Removing exit functions (used for testing) + some fixes when using hotspots see BT#1917 --- main/exercice/answer.class.php | 32 +++++------- main/exercice/exercise.lib.php | 58 ++++++++++++++-------- main/exercice/question.class.php | 59 +++++++++++------------ main/exercice/question_admin.inc.php | 19 ++------ main/exercice/question_list_admin.inc.php | 17 +++---- main/exercice/question_pool.php | 55 ++++++++++++--------- 6 files changed, 119 insertions(+), 121 deletions(-) diff --git a/main/exercice/answer.class.php b/main/exercice/answer.class.php index 1d0f755aef..5d3a38b61d 100755 --- a/main/exercice/answer.class.php +++ b/main/exercice/answer.class.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; -?> \ No newline at end of file +endif; \ No newline at end of file diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 40f055fc9e..ce89113119 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -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='
'.get_lang('Question').' '; @@ -69,8 +71,9 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre "; } + $s.= ''; } - $s.= ''; + $s .= '
'; $option_ie = ''; @@ -87,13 +90,12 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre $s .= ''; // 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 }); }); - - + 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); } diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index fb78a4534a..cc1b599e5d 100755 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -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; } diff --git a/main/exercice/question_admin.inc.php b/main/exercice/question_admin.inc.php index c406af69fc..85226f3ea8 100755 --- a/main/exercice/question_admin.inc.php +++ b/main/exercice/question_admin.inc.php @@ -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 ''; else echo ''; - } else { - - /****************** - * FORM DISPLAY - ******************/ + } else { echo '

'.$questionName.'

'; - - if(!empty($pictureName)){ echo ''; } @@ -117,5 +105,4 @@ if(is_object($objQuestion)) { // display the form $form->display(); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/main/exercice/question_list_admin.inc.php b/main/exercice/question_list_admin.inc.php index 9898c1f35f..3e5f51342a 100755 --- a/main/exercice/question_list_admin.inc.php +++ b/main/exercice/question_list_admin.inc.php @@ -1,13 +1,11 @@ '; - foreach($questionList as $id) { + + echo '
'; + + 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 = ''.get_lang('Modify').''; // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications if ($show_quiz_edition) { - $delete_link = ''.get_lang('Delete').''; + $delete_link = ''.Display::return_icon('delete.gif',get_lang('Delete')).''; } $actions = Display::tag('div',$edit_link.$delete_link, array('style'=>'float:right')); echo '
'; $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved')); echo Display::tag('h3',''.$move.' '.$objQuestionTmp->selectTitle().''); - echo '
'; - + echo '
'; echo '

'; echo $actions; echo get_lang($question_class.$label); diff --git a/main/exercice/question_pool.php b/main/exercice/question_pool.php index fa065ec689..e4af9a893a 100755 --- a/main/exercice/question_pool.php +++ b/main/exercice/question_pool.php @@ -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 '
'; @@ -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; } } }