Add advanced test option to allow teacher to hide categories name for students

-ref #294
skala
Hubert Borderiou 13 years ago
parent 8257aaebc4
commit 2d8a9b5fae
  1. 44
      main/exercice/exercise.class.php
  2. 1
      main/exercice/exercise.lib.php
  3. 4
      main/exercice/result.php
  4. 11
      main/exercice/testcategory.class.php
  5. 1
      main/inc/lib/add_course.lib.inc.php
  6. 1
      main/install/migrate-db-1.8.8-1.9.0-pre.sql

@ -5,8 +5,7 @@
* @package chamilo.exercise
* @author Olivier Brouckaert
* @author Julio Montoya Cleaning exercises
* Modified by Hubert Borderiou 2011-10-21 (question category)
* Add text when finished : ALTER TABLE c_quiz ADD text_when_finished TEXT AFTER random_by_category
* Modified by Hubert Borderiou #294
*/
/**
* Code
@ -53,6 +52,7 @@ class Exercise {
public $review_answers; //
public $randomByCat;
public $text_when_finished; //
public $display_category_name; //
/**
@ -79,6 +79,7 @@ class Exercise {
$this->review_answers = false;
$this->randomByCat = 0; //
$this->text_when_finished = ""; //
$this->display_category_name = 0; //
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
@ -121,6 +122,7 @@ class Exercise {
$this->propagate_neg = $object->propagate_neg;
$this->randomByCat = $object->random_by_category; //
$this->text_when_finished = $object->text_when_finished; //
$this->display_category_name = $object->display_category_name; //
$this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
@ -241,6 +243,27 @@ class Exercise {
return $this->type;
}
/**
* @author - hubert borderiou 30-11-11
* @return - integer : do we display the question category name for students
*/
function selectDisplayCategoryName() {
return $this->display_category_name;
}
/**
* @author - hubert borderiou 30-11-11
* @return - : modify object to update the switch display_category_name
* $in_txt is an integer 0 or 1
*/
function updateDisplayCategoryName($in_txt) {
$this->display_category_name = $in_txt;
}
/**
* @author - hubert borderiou 28-11-11
* @return - html text : the text to display ay the end of the test.
@ -616,7 +639,6 @@ class Exercise {
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_QUIZ_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$id = $this->id;
$exercise = $this->exercise;
$description = $this->description;
@ -632,6 +654,7 @@ class Exercise {
$randomByCat = $this->randomByCat;
$text_when_finished = Security::remove_XSS($this->text_when_finished, COURSEMANAGER); //
$display_category_name = intval($this->display_category_name); //
$session_id = api_get_session_id();
@ -667,6 +690,7 @@ class Exercise {
review_answers ='".Database::escape_string($review_answers)."',
random_by_category='".Database::escape_string($randomByCat)."',
text_when_finished = '".Database::escape_string($text_when_finished)."',
display_category_name = '".Database::escape_string($display_category_name)."',
results_disabled='".Database::escape_string($results_disabled)."'";
}
@ -681,7 +705,7 @@ class Exercise {
}
} else {
// creates a new exercise
$sql="INSERT INTO $TBL_EXERCICES (c_id, start_time, end_time, title, description, sound, type, random, random_answers, active, results_disabled, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category, text_when_finished)
$sql="INSERT INTO $TBL_EXERCICES (c_id, start_time, end_time, title, description, sound, type, random, random_answers, active, results_disabled, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category, text_when_finished, display_category_name)
VALUES(
".$this->course_id.",
'$start_time','$end_time',
@ -699,7 +723,8 @@ class Exercise {
'".Database::escape_string($session_id)."',
'".Database::escape_string($review_answers)."',
'".Database::escape_string($randomByCat)."',
'".Database::escape_string($text_when_finished)."'
'".Database::escape_string($text_when_finished)."',
'".Database::escape_string($display_category_name)."'
)";
Database::query($sql);
$this->id = Database::insert_id();
@ -958,6 +983,12 @@ class Exercise {
$form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'));
$form->addElement('html','<div class="clear">&nbsp;</div>');
// add the radio display the category name for student
$radio_display_cat_name = array();
$radio_display_cat_name[] = FormValidator::createElement('radio', 'display_category_name', null, get_lang('Yes'),'1');
$radio_display_cat_name[] = FormValidator::createElement('radio', 'display_category_name', null, get_lang('No'),'0');
$form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'));
//Attempts
$attempt_option=range(0,10);
$attempt_option[0]=get_lang('Infinite');
@ -1081,6 +1112,7 @@ class Exercise {
$defaults['review_answers'] = $this->review_answers;
$defaults['randomByCat'] = $this->selectRandomByCat(); //
$defaults['text_when_finished'] = $this->selectTextWhenFinished(); //
$defaults['display_category_name'] = $this->selectDisplayCategoryName(); //
if (($this->start_time!='0000-00-00 00:00:00'))
$defaults['activate_start_date_check'] = 1;
@ -1108,6 +1140,7 @@ class Exercise {
$defaults['randomByCat'] = 0; //
$defaults['text_when_finished'] = ""; //
$defaults['start_time'] = date('Y-m-d 12:00:00');
$defaults['display_category_name'] = 1; //
$defaults['end_time'] = date('Y-m-d 12:00:00',time()+84600);
}
} else {
@ -1138,6 +1171,7 @@ class Exercise {
$this->updatePropagateNegative($form->getSubmitValue('propagate_neg'));
$this->updateRandomByCat($form->getSubmitValue('randomByCat')); //
$this->updateTextWhenFinished($form->getSubmitValue('text_when_finished')); //
$this->updateDisplayCategoryName($form->getSubmitValue('display_category_name')); //
$this->updateReviewAnswers($form->getSubmitValue('review_answers'));
if ($form->getSubmitValue('activate_start_date_check') == 1) {

@ -63,7 +63,6 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
if (!$only_questions) {
$questionDescription = $objQuestionTmp->selectDescription();
if ($show_title) {
Testcategory::displayCategoryAndTitle($objQuestionTmp->id); //
echo Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class'=>'question_title'));

@ -77,6 +77,7 @@ if ($show_headers) {
$show_results = true;
$show_only_total_score = false;
$display_category_name = 1;
// Avoiding the "Score 0/0" message when the exe_id is not set
if (!empty($track_exercise_info)) {
@ -84,6 +85,7 @@ if (!empty($track_exercise_info)) {
$exerciseDescription = $track_exercise_info['description'];
// if the results_disabled of the Quiz is 1 when block the script
$result_disabled = $track_exercise_info['results_disabled'];
$display_category_name = $track_exercise_info['display_category_name'];
if (!(api_is_platform_admin() || api_is_course_admin()) ) {
if ($result_disabled == EXERCISE_FEEDBACK_TYPE_DIRECT) {
@ -134,7 +136,7 @@ if (!empty($question_list)) {
if ($show_results) {
// display question category, if any
Testcategory::displayCategoryAndTitle($questionId);
Testcategory::displayCategoryAndTitle($questionId, $display_category_name );
echo $objQuestionTmp->return_header($objExercise->feedbacktype, $counter);
}
$counter++;

@ -353,10 +353,15 @@ class Testcategory {
}
/**
* display the category and the title
* display the category
*/
function displayCategoryAndTitle($in_questionID) {
if (Testcategory::getCategoryNameForQuestion($in_questionID) != "") {
public static function displayCategoryAndTitle($in_questionID, $in_display_category_name = 1) {
$is_student = !(api_is_allowed_to_edit(null,true) || api_is_session_admin());
$objExercise = $_SESSION['objExercise'];
if (!empty($objExercise)) {
$in_display_category_name = $objExercise->display_category_name;
}
if (Testcategory::getCategoryNameForQuestion($in_questionID) != "" && ($in_display_category_name == 1 || !$is_student)) {
echo "<div id=\"question_title\" class=\"sectiontitle\" style='font-size:110%; margin-top:20px; padding-top:10px'>";
echo "<div style='font-size:110%;font-weight:normal; margin-bottom:5px; padding:0px 10px 5px 10px;'>";
echo get_lang('Category').": ".Testcategory::getCategoryNameForQuestion($in_questionID);

@ -714,6 +714,7 @@ function update_Db_course($course_db_name = null) {
review_answers INT NOT NULL DEFAULT 0,
random_by_category INT NOT NULL DEFAULT 0,
text_when_finished TEXT default NULL,
display_category_name TINYINT NOT NULL DEFAULT 1,
PRIMARY KEY (c_id, id)
)" . $charset_clause;
Database::query($sql);

@ -149,3 +149,4 @@ ALTER TABLE student_publication ADD COLUMN contains_file INTEGER NOT NULL DEFAUL
ALTER TABLE student_publication ADD COLUMN allow_text_assignment INTEGER NOT NULL DEFAULT 0;
ALTER TABLE quiz ADD COLUMN random_by_category INT NOT NULL DEFAULT 0;
ALTER TABLE quiz ADD text_when_finished TEXT default NULL;
ALTER TABLE c_quiz ADD display_category_name TINYINT NOT NULL DEFAULT 1;
Loading…
Cancel
Save