Fixing diffirent bugs due recent merge with the global and multiple categories in exercises see BT#5638

skala
Julio Montoya 12 years ago
parent 0d46406004
commit a80068100d
  1. 30
      main/exercice/answer.class.php
  2. 1
      main/exercice/exercice.php
  3. 46
      main/exercice/exercise.class.php
  4. 54
      main/exercice/exercise.lib.php
  5. 1
      main/exercice/export/scorm/scorm_classes.php
  6. 1
      main/exercice/fill_blanks.class.php
  7. 2
      main/exercice/matching.class.php
  8. 4
      main/exercice/multiple_answer.class.php
  9. 2
      main/exercice/multiple_answer_combination.class.php
  10. 44
      main/exercice/question.class.php
  11. 30
      main/exercice/testcategory.class.php
  12. 71
      main/exercice/tests_category.php
  13. 2
      main/exercice/unique_answer.class.php
  14. 2
      main/exercice/unique_answer_no_option.class.php
  15. 1
      main/inc/lib/display.lib.php
  16. 4
      main/inc/lib/events.lib.inc.php
  17. 7
      main/newscorm/learnpath_functions.inc.php

@ -119,9 +119,9 @@ class Answer
/*$sql = "SELECT id, id_auto, answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM
$TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position";
*/
$sql = "SELECT iid, answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination
$sql = "SELECT iid, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination
FROM $TBL_ANSWER
WHERE question_id ='".$questionId."' ORDER BY position";
WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position";
$result = Database::query($sql);
$counter = 1;
@ -210,7 +210,7 @@ class Answer
$this->weighting[$i] = $doubt_data->ponderation;
$this->position[$i] = $doubt_data->position;
$this->destination[$i] = $doubt_data->destination;
//$this->autoId[$i] = $doubt_data->id_auto;
//$this->autoId[$i] = $doubt_data->id_auto;
}
$this->nbrAnswers = count($this->answer);
}
@ -255,9 +255,9 @@ class Answer
* @author - Julio Montoya
* @return - integer - the question ID
*/
function selectDestination($id)
public function selectDestination($id)
{
return $this->destination[$id];
return isset($this->destination[$id]) ? $this->destination[$id] : null;
}
/**
@ -267,9 +267,9 @@ class Answer
* @param - integer $id - answer ID
* @return - string - answer title
*/
function selectAnswer($id)
public function selectAnswer($id)
{
return $this->answer[$id];
return isset($this->answer[$id]) ? $this->answer[$id] : null;
}
/**
@ -297,7 +297,7 @@ class Answer
* @param - integer $id - answer ID
* @return - bool - answer title
*/
function selectAnswerIdByPosition($pos)
public function selectAnswerIdByPosition($pos)
{
foreach ($this->position as $k => $v) {
if ($v != $pos) {
@ -460,7 +460,7 @@ class Answer
}
/**
* returns answer hotspot coordinates
* Returns answer hotspot coordinates
*
* @author Olivier Brouckaert
* @param integer Answer ID
@ -468,11 +468,11 @@ class Answer
*/
function selectHotspotCoordinates($id)
{
return $this->hotspot_coordinates[$id];
return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
}
/**
* returns answer hotspot type
* Returns answer hotspot type
*
* @author Toon Keppens
* @param integer Answer ID
@ -480,11 +480,11 @@ class Answer
*/
function selectHotspotType($id)
{
return $this->hotspot_type[$id];
return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
}
/**
* creates a new answer
* Creates a new answer
*
* @author Olivier Brouckaert
* @param string answer title
@ -495,7 +495,7 @@ class Answer
* @param coordinates Coordinates for hotspot exercises (optional)
* @param integer Type for hotspot exercises (optional)
*/
function createAnswer(
public function createAnswer(
$answer,
$correct,
$comment,
@ -693,7 +693,7 @@ class Answer
}
if (self::getQuestionType() == MATCHING) {
if (!empty($correct_answers)) {
foreach($correct_answers as $new_id => $correct_id) {
foreach ($correct_answers as $new_id => $correct_id) {
$correct = $new_ids[$correct_id];
$sql = "UPDATE $TBL_REPONSES SET correct = $correct WHERE iid = $new_id";
Database::query($sql);

@ -38,7 +38,6 @@ require_once 'exercise.class.php';
require_once 'exercise.lib.php';
require_once 'question.class.php';
require_once 'answer.class.php';
require_once 'testcategory.class.php';
require_once 'hotpotatoes.lib.php';
/* Constants and variables */

@ -577,7 +577,9 @@ class Exercise
$cat = new Testcategory();
//$categories_added_in_exercise = $this->get_categories_with_name_in_exercise();
$categories_added_in_exercise = $cat->get_category_exercise_tree($this->id, $this->course['real_id']);
shuffle($categories_added_in_exercise);
if (!empty($categories_added_in_exercise)) {
shuffle($categories_added_in_exercise);
}
break;
case EXERCISE_CATEGORY_RANDOM_ORDERED:
$cat = new Testcategory();
@ -614,7 +616,7 @@ class Exercise
}
if (!empty($question_list_based_in_categories)) {
$question_list = array_flatten($question_list_based_in_categories);
$question_list = ArrayClass::array_flatten($question_list_based_in_categories);
}
}
}
@ -911,7 +913,6 @@ class Exercise
$text_when_finished = $this->text_when_finished;
$display_category_name = intval($this->display_category_name);
$pass_percentage = intval($this->pass_percentage);
$session_id = api_get_session_id();
//If direct we do not show results
@ -959,7 +960,7 @@ class Exercise
pass_percentage = '".Database::escape_string($pass_percentage)."',
results_disabled='".Database::escape_string($results_disabled)."'";
}
$sql .= " WHERE iid = '".Database::escape_string($id)."'";
$sql .= " WHERE iid = ".Database::escape_string($id)." AND c_id = {$this->course_id}";
Database::query($sql);
// update into the item_property table
@ -2118,7 +2119,11 @@ class Exercise
}
}
public function set_autolaunch() {
/**
*
*/
public function set_autolaunch()
{
$table = Database::get_course_table(TABLE_QUIZ_TEST);
$session_id = api_get_session_id();
@ -2956,23 +2961,22 @@ class Exercise
$answer .= $temp;
break;
}
if ($from_database) {
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' AND question_id= '".Database::escape_string(
$questionId
)."'";
$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = ".$exeId." AND question_id= ".Database::escape_string($questionId);
$resfill = Database::query($queryfill);
$str = Database::result($resfill, 0, 'answer');
api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
$str = str_replace('\r\n', '', $str);
$choice = $arr[1];
$tmp = api_strrpos($choice[$j], ' / ');
$choice[$j] = api_substr($choice[$j], 0, $tmp);
$choice[$j] = trim($choice[$j]);
//Needed to let characters ' and " to work as part of an answer
$choice[$j] = stripslashes($choice[$j]);
if (Database::num_rows($resfill)) {
$str = Database::result($resfill, 0, 'answer');
api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
$str = str_replace('\r\n', '', $str);
$choice = $arr[1];
$tmp = api_strrpos($choice[$j], ' / ');
$choice[$j] = api_substr($choice[$j], 0, $tmp);
$choice[$j] = trim($choice[$j]);
//Needed to let characters ' and " to work as part of an answer
$choice[$j] = stripslashes($choice[$j]);
}
} else {
$choice[$j] = trim($choice[$j]);
}
@ -5053,7 +5057,7 @@ class Exercise
{
$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
if (!empty($this->id)) {
$sql = "SELECT SUM(count_questions) count_questions FROM $table WHERE exercise_id = {$this->id}";
$sql = "SELECT SUM(count_questions) count_questions FROM $table WHERE exercise_id = {$this->id} AND c_id = {$this->course_id}";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database::fetch_array($result);

@ -869,22 +869,26 @@ function showQuestion($objQuestionTmp, $only_questions = false, $origin = false,
return $nbrAnswers;
}
/**
* @param int $exe_id
* @return array
*/
function get_exercise_track_exercise_info($exe_id)
{
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_COURSE = Database::get_main_table(TABLE_MAIN_COURSE);
$exe_id = intval($exe_id);
$result = array();
$result_array = array();
if (!empty($exe_id)) {
$sql = "SELECT q.*, tee.*
FROM $TBL_EXERCICES as q
INNER JOIN $TBL_TRACK_EXERCICES as tee
ON q.id=tee.exe_exo_id
INNER JOIN $TBL_COURSE c
ON c.id = tee.c_id
WHERE tee.exe_id = $exe_id
AND q.c_id=c.id";
FROM $TBL_EXERCICES as q
INNER JOIN $TBL_TRACK_EXERCICES as tee
ON q.iid = tee.exe_exo_id
INNER JOIN $TBL_COURSE c
ON c.id = tee.c_id
WHERE tee.exe_id = $exe_id
AND q.c_id = c.id";
$result = Database::query($sql);
$result_array = Database::fetch_array($result, 'ASSOC');
@ -900,7 +904,7 @@ function exercise_time_control_is_valid($exercise_id, $lp_id = 0, $lp_item_id =
$course_id = api_get_course_int_id();
$exercise_id = intval($exercise_id);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE c_id = $course_id AND id = $exercise_id";
$sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE c_id = $course_id AND iid = $exercise_id";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
if (!empty($row['expired_time'])) {
@ -2337,10 +2341,10 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
foreach ($question_list as $questionId) {
// creates a temporary Question object
// Creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
//this variable commes from exercise_submit_modal.php
// This variable commes from exercise_submit_modal.php
ob_start();
$hotspot_delineation_result = null;
@ -2363,24 +2367,23 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
$my_total_score = $result['score'];
$my_total_weight = $result['weight'];
//Category report
// Category report
$category_was_added_for_this_test = false;
if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
$category_list[$objQuestionTmp->category]['score'] += $my_total_score;
$category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
$category_was_added_for_this_test = true;
}
if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
foreach ($objQuestionTmp->category_list as $category_id) {
if (!isset($category_list[$category_id])) {
$category_list[$category_id] = array();
$category_list[$category_id]['score'] = 0;
$category_list[$category_id]['total'] = 0;
}
$category_list[$category_id]['score'] += $my_total_score;
$category_list[$category_id]['total'] += $my_total_weight;
$category_was_added_for_this_test = true;
}
}
//No category for this question!
// No category for this question!
if ($category_was_added_for_this_test == false) {
$category_list['none'] = array();
$category_list['none']['score'] += $my_total_score;
@ -2467,7 +2470,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
$learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
if (api_is_allowed_to_session_edit()) {
update_event_exercise($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array(), $end_date);
update_event_exercise($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $exercise_stat_info['exe_duration'], '', array());
}
// Send notification ..
@ -2478,6 +2481,13 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
}
}
/**
* @param $objExercise
* @param $score
* @param $weight
* @param bool $check_pass_percentage
* @return string
*/
function get_question_ribbon($objExercise, $score, $weight, $check_pass_percentage = false)
{
$ribbon = '<div class="ribbon">';
@ -2503,8 +2513,6 @@ function get_question_ribbon($objExercise, $score, $weight, $check_pass_percenta
if ($check_pass_percentage) {
$ribbon .= show_success_message($score, $weight, $objExercise->selectPassPercentage());
}
$ribbon .= '</div>';
return $ribbon;
}
}

@ -12,7 +12,6 @@ if ( count( get_included_files() ) == 1 ) die( '---' );
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/testcategory.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/unique_answer.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/multiple_answer.class.php';

@ -43,6 +43,7 @@ class FillBlanks extends Question
*/
function createAnswersForm ($form) {
$defaults = array();
$a_weightings = null;
if (!empty($this->id)) {
$objAnswer = new Answer($this->id);

@ -69,7 +69,7 @@ class Matching extends Question
if ($answer->isCorrect($i)) {
$nb_matches++;
$defaults['answer['.$nb_matches.']'] = $answer->selectAnswer($i);
$defaults['weighting['.$nb_matches.']'] = float_format($answer->selectWeighting($i), 1);
$defaults['weighting['.$nb_matches.']'] = Text::float_format($answer->selectWeighting($i), 1);
$correct_answer_id = $answer->correct[$i];
$defaults['matches['.$nb_matches.']'] = $answer->getCorrectAnswerPosition($correct_answer_id);
} else {

@ -86,11 +86,11 @@ class MultipleAnswer extends Question {
}
for ($i = 1 ; $i <= $nb_answers ; ++$i) {
if(is_object($answer)) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = float_format($answer->weighting[$answer_id], 1);
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');

@ -84,7 +84,7 @@ class MultipleAnswerCombination extends Question
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = float_format($answer->weighting[$answer_id], 1);
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');

@ -11,7 +11,6 @@
* Code
*/
// Question types
define('UNIQUE_ANSWER', 1);
define('MULTIPLE_ANSWER', 2);
@ -59,7 +58,7 @@ abstract class Question
public $exerciseList; // array with the list of exercises which this question is in
public $category_list;
public $parent_id;
private $isContent;
public $isContent;
public $course;
static $typePicture = 'new_question.png';
static $explanationLangVar = '';
@ -121,6 +120,11 @@ abstract class Question
return $this->isContent = $isContent;
}
/**
* @param string $title
* @param int $course_id
* @return mixed|bool
*/
public function readByTitle($title, $course_id = null) {
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
@ -139,6 +143,7 @@ abstract class Question
}
return false;
}
/**
* Reads question informations from the data base
*
@ -165,7 +170,7 @@ abstract class Question
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id ";
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE iid = $id AND c_id = $course_id";
$result = Database::query($sql);
@ -217,10 +222,10 @@ abstract class Question
}
/**
* returns the question ID
* Returns the question ID
*
* @author - Olivier Brouckaert
* @return - integer - question ID
* @return int - question ID
*/
function selectId()
{
@ -228,10 +233,10 @@ abstract class Question
}
/**
* returns the question title
* Returns the question title
*
* @author - Olivier Brouckaert
* @return - string - question title
* @return string - question title
*/
function selectTitle()
{
@ -242,7 +247,7 @@ abstract class Question
* returns the question description
*
* @author - Olivier Brouckaert
* @return - string - question description
* @return string - question description
*/
function selectDescription()
{
@ -255,7 +260,7 @@ abstract class Question
* returns the question weighting
*
* @author - Olivier Brouckaert
* @return - integer - question weighting
* @return int - question weighting
*/
function selectWeighting()
{
@ -266,7 +271,7 @@ abstract class Question
* returns the question position
*
* @author - Olivier Brouckaert
* @return - integer - question position
* @return int - question position
*/
function selectPosition()
{
@ -277,7 +282,7 @@ abstract class Question
* returns the answer type
*
* @author - Olivier Brouckaert
* @return - integer - answer type
* @return int - answer type
*/
function selectType()
{
@ -288,7 +293,7 @@ abstract class Question
* returns the level of the question
*
* @author - Nicolas Raynaud
* @return - integer - level of the question, 0 by default.
* @return int - level of the question, 0 by default.
*/
function selectLevel()
{
@ -299,7 +304,7 @@ abstract class Question
* returns the picture name
*
* @author - Olivier Brouckaert
* @return - string - picture name
* @return string - picture name
*/
function selectPicture()
{
@ -319,7 +324,7 @@ abstract class Question
* returns the array with the exercise ID list
*
* @author - Olivier Brouckaert
* @return - array - list of exercise ID which the question is in
* @return array - list of exercise ID which the question is in
*/
function selectExerciseList()
{
@ -330,14 +335,18 @@ abstract class Question
* returns the number of exercises which this question is in
*
* @author - Olivier Brouckaert
* @return - integer - number of exercises
* @return integer - number of exercises
*/
function selectNbrExercises()
{
return sizeof($this->exerciseList);
}
function updateCourse($course_id) {
/**
* @param $course_id
*/
function updateCourse($course_id)
{
$this->course = api_get_course_info_by_id($course_id);
}
/**
@ -833,7 +842,7 @@ abstract class Question
extra ='".Database::escape_string($extra)."',
level ='".Database::escape_string($level)."',
parent_id = ".$this->parent_id."
WHERE iid = '".Database::escape_string($id)."'";
WHERE c_id = $c_id AND iid = '".Database::escape_string($id)."'";
Database::query($sql);
$this->saveCategories($category_list);
@ -1731,6 +1740,7 @@ abstract class Question
}
$question_title = $this->question;
$header = null;
// Display question category, if any
if ($show_media) {
$header .= $this->show_media_content();

@ -62,15 +62,15 @@ class Testcategory
/**
* Return the Testcategory object with id=in_id
* @param $in_id
* @param int $id
* @return bool
* @assert () === false
*/
function getCategory($in_id) {
function getCategory($id) {
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$in_id = Database::escape_string($in_id);
$sql = "SELECT * FROM $t_cattable WHERE iid = $in_id ";
$in_id = Database::escape_string($id);
$sql = "SELECT * FROM $t_cattable WHERE iid = $id ";
$res = Database::query($sql);
$numrows = Database::num_rows($res);
if ($numrows > 0) {
@ -88,7 +88,8 @@ class Testcategory
* Add Testcategory in the database if name doesn't already exists
*
*/
function addCategoryInBDD() {
function addCategoryInBDD()
{
$t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$v_name = Database::escape_string($this->name);
$v_description = Database::escape_string($this->description);
@ -549,18 +550,20 @@ class Testcategory
* $categories[1][30] = 10, array with category id = 1 and question_id = 10
* A question has "n" categories
*/
static function getQuestionsByCat($exerciceId, $check_in_question_list = array()) {
static function getQuestionsByCat($exerciseId, $check_in_question_list = array()) {
$categories = array();
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$exerciceId = intval($exerciceId);
$exerciseId = intval($exerciseId);
$sql = "SELECT DISTINCT qrc.question_id, qrc.category_id
FROM $TBL_QUESTION_REL_CATEGORY qrc, $TBL_EXERCICE_QUESTION eq
WHERE exercice_id = $exerciceId AND
WHERE exercice_id = $exerciseId AND
eq.question_id = qrc.question_id AND
eq.c_id =".api_get_course_int_id()." AND
eq.c_id = qrc.c_id
ORDER BY category_id, question_id";
$res = Database::query($sql);
while ($data = Database::fetch_array($res)) {
if (!empty($check_in_question_list)) {
@ -569,7 +572,7 @@ class Testcategory
}
}
if (!is_array($categories[$data['category_id']])) {
if (!isset($categories[$data['category_id']]) OR !is_array($categories[$data['category_id']])) {
$categories[$data['category_id']] = array();
}
@ -802,16 +805,17 @@ class Testcategory
}
/**
* @param $exercise_id
* @param $course_id
* @param null $order
* @param int $exercise_id
* @param int $course_id
* @param string $order
* @return bool
*/
function get_category_exercise_tree($exercise_id, $course_id, $order = null)
{
$table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY);
$table_category = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$sql = "SELECT * FROM $table qc INNER JOIN $table_category c ON (category_id = c.iid) WHERE exercise_id = {$exercise_id} AND qc.c_id = {$course_id} ";
$sql = "SELECT * FROM $table qc INNER JOIN $table_category c ON (category_id = c.iid)
WHERE exercise_id = {$exercise_id} AND qc.c_id = {$course_id} ";
if (!empty($order)) {
$sql .= "ORDER BY $order";

@ -264,43 +264,44 @@ function display_add_category($type) {
function display_categories($type = 'simple') {
$cat = new Testcategory();
$categories = $cat->get_category_tree_by_type($type);
if (!empty($categories)) {
foreach ($categories as $row) {
// Title with number of questions in the category
$category_id = $row['id'];
$tmpobj = new Testcategory($category_id);
$nb_question = $tmpobj->getCategoryQuestionsNumber();
echo '<div class="sectiontitle" id="id_cat'.$category_id.'">';
$nb_question_label = $nb_question == 1 ? $nb_question . ' ' . get_lang('Question') : $nb_question . ' ' . get_lang('Questions');
$global_label = null;
if ($row['c_id'] == 0) {
$global_label = ' '.Display::label(get_lang('Global'), 'info');
}
echo "<span style='float:right'>" . $nb_question_label . "</span>";
$style = 'margin-left:' . $row['depth'] * 20 . 'px; margin-right:10px;';
echo $title = Display::div($row['title'].$global_label, array('style' => $style));
echo '</div>';
echo '<div class="sectioncomment">';
echo $row['description'];
echo '</div>';
echo '<div>';
if ($row['c_id'] == 0 && $type == 'simple') {
echo Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
} else {
echo '<a href="'.api_get_self().'?action=editcategory&category_id='.$category_id.'&type='.$type.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
}
foreach ($categories as $row) {
// Title with number of questions in the category
$category_id = $row['id'];
$tmpobj = new Testcategory($category_id);
$nb_question = $tmpobj->getCategoryQuestionsNumber();
echo '<div class="sectiontitle" id="id_cat'.$category_id.'">';
$nb_question_label = $nb_question == 1 ? $nb_question . ' ' . get_lang('Question') : $nb_question . ' ' . get_lang('Questions');
$global_label = null;
if ($row['c_id'] == 0) {
$global_label = ' '.Display::label(get_lang('Global'), 'info');
}
echo "<span style='float:right'>" . $nb_question_label . "</span>";
$style = 'margin-left:' . $row['depth'] * 20 . 'px; margin-right:10px;';
echo $title = Display::div($row['title'].$global_label, array('style' => $style));
echo '</div>';
echo '<div class="sectioncomment">';
echo $row['description'];
echo '</div>';
echo '<div>';
if ($row['c_id'] == 0 && $type == 'simple') {
echo Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL);
} else {
echo '<a href="'.api_get_self().'?action=editcategory&category_id='.$category_id.'&type='.$type.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
}
if ($nb_question > 0 || ($row['c_id'] == 0 && $type == 'simple')){
echo '<a href="javascript:void(0)" onclick="alert(\'' . protectJSDialogQuote(get_lang('CannotDeleteCategory')) . '\')">';
echo Display::return_icon('delete_na.png', get_lang('CannotDeleteCategory'), array(), ICON_SIZE_SMALL);
echo '</a>';
} else {
$rowname = protectJSDialogQuote($row['title']);
echo ' <a href="'.api_get_self().'?action=deletecategory&amp;category_id='.$category_id.'&type='.$type.'"';
echo 'onclick="return confirmDelete(\''.protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure').'['.$rowname).'] ?\', \'id_cat'.$category_id.'\');">';
echo Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
if ($nb_question > 0 || ($row['c_id'] == 0 && $type == 'simple')){
echo '<a href="javascript:void(0)" onclick="alert(\'' . protectJSDialogQuote(get_lang('CannotDeleteCategory')) . '\')">';
echo Display::return_icon('delete_na.png', get_lang('CannotDeleteCategory'), array(), ICON_SIZE_SMALL);
echo '</a>';
} else {
$rowname = protectJSDialogQuote($row['title']);
echo ' <a href="'.api_get_self().'?action=deletecategory&amp;category_id='.$category_id.'&type='.$type.'"';
echo 'onclick="return confirmDelete(\''.protectJSDialogQuote(get_lang('DeleteCategoryAreYouSure').'['.$rowname).'] ?\', \'id_cat'.$category_id.'\');">';
echo Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
}
echo '</div>';
}
echo '</div>';
}
}

@ -149,7 +149,7 @@ class UniqueAnswer extends Question
}
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = float_format($answer->weighting[$answer_id], 1);
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$item_list = explode('@@', $answer->destination[$answer_id]);

@ -146,7 +146,7 @@ class UniqueAnswerNoOption extends Question
$correct = $i;
}
$answer_result = $answer->answer[$answer_id];
$weight_result = float_format($answer->weighting[$answer_id], 1);
$weight_result = Text::float_format($answer->weighting[$answer_id], 1);
if ($nb_answers == $i) {
$weight_result = '0';
}

@ -57,7 +57,6 @@ class Display
$app->run();
}
/**
* Displays the reduced page header (without banner)
*/

@ -328,7 +328,7 @@ function event_link($link_id)
* @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
* @desc Record result of user when an exercice was done
*/
function update_event_exercise($exeid, $exo_id, $score, $weigh, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $status = '', $remind_list = array() , $end_date = null) {
function update_event_exercise($exeid, $exo_id, $score, $weight, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $status = '', $remind_list = array() , $end_date = null) {
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
global $debug;
if ($debug) {
@ -336,7 +336,7 @@ function update_event_exercise($exeid, $exo_id, $score, $weigh, $session_id, $le
error_log('duration:'.$duration);
}
if ($exeid != '') {
if (!empty($exeid)) {
// Validation in case of fraud with actived control time
if (!exercise_time_control_is_valid($exo_id, $learnpath_id, $learnpath_item_id)) {
$score = 0;

@ -1273,12 +1273,9 @@ function exporttofile($filename, $LPname, $LPid, $content)
*/
function export_exercise($item_id)
{
global $expdir, $_course, $_configuration, $_SESSION, $_SERVER, $language_interface, $langExerciseNotFound, $langQuestion, $langOk, $origin, $questionNum;
$exerciseId = $item_id;
require_once '../exercice/testcategory.class.php';
require_once '../exercice/exercise.class.php';
require_once '../exercice/question.class.php';
require_once '../exercice/answer.class.php';
@ -1401,7 +1398,7 @@ function export_exercise($item_id)
continue;
} else {
// if the user has already answered this question:
if (isset ($exerciseResult[$questionId])) {
if (isset($exerciseResult[$questionId])) {
// Construction of the Question object.
$objQuestionTmp = new Question();
@ -2381,4 +2378,4 @@ function rcopy($source, $dest)
return true;
}
}
}
}
Loading…
Cancel
Save