diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php
index f58a85dd33..82e8c68337 100644
--- a/main/exercice/exercice.php
+++ b/main/exercice/exercice.php
@@ -723,7 +723,7 @@ if ($show == 'test') {
if ($is_allowedToEdit) {
$headers = array(array('name' => get_lang('ExerciseName')),
- array('name' => get_lang('QuantityQuestions'), 'params' => array('width'=>'80px')),
+ array('name' => get_lang('QuantityQuestions'), 'params' => array('width'=>'100px')),
array('name' => get_lang('Actions'), 'params' => array('width'=>'180px')));
} else {
$headers = array(array('name' => get_lang('ExerciseName')),
@@ -861,19 +861,24 @@ if ($show == 'test') {
// Number of questions
$random_label = '';
- if ($row['random'] > 0) {
+ if ($row['random'] > 0 || $row['random'] == -1) {
+ // if random == -1 means use random questions with all questions
+ $random_number_of_question = $row['random'];
+ if ($random_number_of_question == -1) {
+ $random_number_of_question = $rowi;
+ }
if ($row['random_by_category'] > 0) {
if (!class_exists("testcategory.class.php")) include_once "testcategory.class.php" ;
- $nbQuestionsTotal = Testcategory::getNumberOfQuestionRandomByCategory($exid, $row['random']);
+ $nbQuestionsTotal = Testcategory::getNumberOfQuestionRandomByCategory($exid, $random_number_of_question);
$number_of_questions .= $nbQuestionsTotal." ";
$number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase") ;
$number_of_questions .= " - ";
- $number_of_questions .= $row['random'].' '.get_lang('QuestionByCategory');
+ $number_of_questions .= Testcategory::getNumberMaxQuestionByCat($exid).' '.get_lang('QuestionByCategory');
} else {
$random_label = ' ('.get_lang('Random').') ';
- $number_of_questions = $row['random'] . ' ' .$random_label.' '.$textByCategory;
+ $number_of_questions = $random_number_of_question . ' ' .$random_label.' '.$textByCategory;
//Bug if we set a random value bigger than the real number of questions
- if ($row['random'] > $rowi) {
+ if ($random_number_of_question > $rowi) {
$number_of_questions = $rowi. ' ' .$random_label;
}
}
diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php
index 1c9b30af19..c743bd7e11 100644
--- a/main/exercice/exercise.class.php
+++ b/main/exercice/exercise.class.php
@@ -283,7 +283,6 @@ class Exercise {
}
-
/**
* tells if questions are selected randomly, and if so returns the draws
*
@@ -301,7 +300,7 @@ class Exercise {
* @return - integer - 0 if not random, otherwise the draws
*/
function isRandom() {
- if($this->random > 0){
+ if($this->random > 0 || $this->random == -1) {
return true;
} else {
return false;
@@ -384,29 +383,34 @@ class Exercise {
* @author - Olivier Brouckaert
* @return - array - if the exercise is not set to take questions randomly, returns the question list
* without randomizing, otherwise, returns the list with questions selected randomly
+ * Modified by Hubert Borderiou 15 nov 2011
*/
function selectRandomList() {
$nbQuestions = $this->selectNbrQuestions();
$temp_list = $this->questionList;
-
+
//Not a random exercise, or if there are not at least 2 questions
if($this->random == 0 || $nbQuestions < 2) {
return $this->questionList;
}
-
if ($nbQuestions != 0) {
shuffle($temp_list);
$my_random_list = array_combine(range(1,$nbQuestions),$temp_list);
$my_question_list = array();
- $i = 0;
- foreach ($my_random_list as $item) {
- if ($i < $this->random) {
- $my_question_list[$i] = $item;
- } else {
- break;
+ // $this->random == -1 if random with all questions
+ if ($this->random > 0) {
+ $i = 0;
+ foreach ($my_random_list as $item) {
+ if ($i < $this->random) {
+ $my_question_list[$i] = $item;
+ } else {
+ break;
+ }
+ $i++;
}
- $i++;
- }
+ } else {
+ $my_question_list = $my_random_list;
+ }
return $my_question_list;
}
}
@@ -740,7 +744,7 @@ class Exercise {
return false;
} else {
if ($this->isRandom()) {
- if (count($this->questionList) >= $this->random) {
+ if (count($this->questionList) >= $this->random && $this->random > 0) {
$this->random -= 1;
$this->save();
}
@@ -908,11 +912,12 @@ class Exercise {
}
}
+ // number of random question
$option = array();
$max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ;
$option = range(0,$max);
$option[0] = get_lang('No');
-
+ $option[-1] = get_lang('Everybody'); // #3942
$form->addElement('select', 'randomQuestions',array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id'=>'randomQuestions','class'=>'chzn-select'));
//random answers
@@ -3326,10 +3331,14 @@ class Exercise {
*/
// If test option is Grouped By Categories
if ($isRandomByCategory == 2) {
- $tabCategoryQuestions = Testcategory::sortTabByBracketLabel($tabCategoryQuestions); // 24-02-2011 hub pour projet Bernard Ycard
+ $tabCategoryQuestions = Testcategory::sortTabByBracketLabel($tabCategoryQuestions);
}
while (list($cat_id, $tabquestion) = each($tabCategoryQuestions)) {
- $questionList = array_merge($questionList, Testcategory::getNElementsFromArray($tabquestion, $this->random));
+ $number_of_random_question = $this->random;
+ if ($this->random == -1) {
+ $number_of_random_question = count($this->questionList);
+ }
+ $questionList = array_merge($questionList, Testcategory::getNElementsFromArray($tabquestion, $number_of_random_question));
}
// shuffle the question list if test is not grouped by categories
if ($isRandomByCategory == 1) {
diff --git a/main/exercice/question_list_admin.inc.php b/main/exercice/question_list_admin.inc.php
index d495222372..8fd5068c32 100644
--- a/main/exercice/question_list_admin.inc.php
+++ b/main/exercice/question_list_admin.inc.php
@@ -30,7 +30,6 @@ if ($deleteQuestion) {
if ($objExercise->removeFromList($deleteQuestion)) {
$nbrQuestions--;
}
- //Random -1 if
}
// destruction of the Question object
unset($objQuestionTmp);
diff --git a/main/exercice/question_pool.php b/main/exercice/question_pool.php
index f0cb807aee..2c3f27ba98 100644
--- a/main/exercice/question_pool.php
+++ b/main/exercice/question_pool.php
@@ -1,4 +1,6 @@
';
}
else {
echo ''.Display::return_icon('back.png', get_lang('BackToExercisesList'),'','32').'';
- echo "".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."";
+ echo "".Display::return_icon('add_question.gif', get_lang('NewQu'), '', 32)."";
$titleAdd = get_lang('manageAllQuestions');
}
echo '';
@@ -614,13 +616,16 @@ foreach ($main_question_list as $tabQuestion) {
$row[] = get_question_type_for_question($selected_course, $tabQuestion['id']);
$row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']);
$row[] = $tabQuestion['level'];
+
+ echo "HUBC exerciseId=$exerciseId
";
+
$row[] = get_action_icon_for_question($actionIcon1, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel,
- $answerType, $session_id).
+ $answerType, $session_id, $exerciseId).
" ".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
- $session_id);
+ $session_id, $exerciseId);
$data[] = $row;
}
Display :: display_sortable_table($header, $data, '', array('per_page_default'=>999,'per_page'=>999,'page_nr'=>1));
@@ -680,13 +685,16 @@ function get_a_tag_for_question($in_addA, $in_fromex, $in_questionid, $in_questi
// return the html code for delete, add, clone, edit a question
// hubert.borderiou 13-10-2011
function get_action_icon_for_question($in_action, $from_exercice, $in_questionid, $in_questiontype, $in_questionname,
- $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id
+ $in_selected_course, $in_courseCategoryId, $in_exerciseLevel, $in_answerType, $in_session_id, $in_exercice_id
) {
$res = "";
- $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$from_exercice&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
+ $getParams = "&selected_course=$in_selected_course&courseCategoryId=$in_courseCategoryId&exerciseId=$in_exercice_id&exerciseLevel=$in_exerciseLevel&answerType=$in_answerType&session_id=$in_session_id";
+
+ echo $getParams."
";
+
switch ($in_action) {
case "delete" :
- $res = "";
+ $res = "";
$res .= Display::return_icon("delete.gif", get_lang('Delete'));
$res .= "";
break;
diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php
index d911929e32..e84dc40fa8 100644
--- a/main/exercice/testcategory.class.php
+++ b/main/exercice/testcategory.class.php
@@ -417,6 +417,27 @@ class Testcategory {
}
return $totalcatscore;
}
+
+
+ /**
+ * return the number max of question in a category
+ * count the number of questions in all categories, and return the max
+ * @author - hubert borderiou
+ */
+ public static function getNumberMaxQuestionByCat($in_testid) {
+ $res_num_max = 0;
+ // foreach question
+ $tabcatid = Testcategory::getListOfCategoriesIDForTest($in_testid);
+ for ($i=0; $i < count($tabcatid); $i++) {
+ if ($tabcatid[$i] > 0) { // 0 = no category for this question
+ $nbQuestionInThisCat = Testcategory::getNumberOfQuestionsInCategoryForTest($in_testid, $tabcatid[$i]);
+ if ($nbQuestionInThisCat > $res_num_max) {
+ $res_num_max = $nbQuestionInThisCat;
+ }
+ }
+ }
+ return $res_num_max;
+ }
}
endif;
?>
diff --git a/main/lang/english/exercice.inc.php b/main/lang/english/exercice.inc.php
index f7ff7b9d98..b9b1c975fe 100644
--- a/main/lang/english/exercice.inc.php
+++ b/main/lang/english/exercice.inc.php
@@ -421,7 +421,7 @@ $ReviewQuestions = "Review selected questions";
$YouTriedToResolveThisExerciseEarlier = "You have tried to resolve this question earlier";
$ThereAreNoQuestionsForThisExercise = "There are no questions for this exercise";
// question category
-$QuestionByCategory = "question(s) par catégories";
+$QuestionByCategory = "question(s) by categories";
$QuestionLowerCase = "question";
$QuestionUpperCaseFirstLetter = "Question";
$QuestionsLowerCase = "questions";