Merging from 1.9.x + allowing multiple categories per question see #5715

skala
Julio Montoya 13 years ago
parent 951930c15c
commit c7e5752e01
  1. 102
      main/exercice/exercise.class.php
  2. 37
      main/exercice/exercise.lib.php
  3. 265
      main/exercice/exercise_show.php
  4. 7
      main/exercice/exercise_submit.php
  5. 17
      main/exercice/hotpotatoes.lib.php
  6. 152
      main/exercice/question.class.php
  7. 15
      main/exercice/question_list_admin.inc.php
  8. 53
      main/exercice/question_pool.php
  9. 174
      main/exercice/testcategory.class.php

@ -99,10 +99,9 @@ class Exercise {
* @param - integer $id - exercise ID
* @return - boolean - true if exercise exists, otherwise false
*/
function read($id) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
function read($id) {
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$id = intval($id);
if (empty($this->course_id)) {
return false;
@ -139,33 +138,19 @@ class Exercise {
$this->start_time = $object->start_time;
}
$this->expired_time = $object->expired_time; //control time
$sql = "SELECT e.question_id, e.question_order FROM $TBL_EXERCICE_QUESTION e, $TBL_QUESTIONS q
WHERE e.question_id = q.id AND
e.exercice_id = '".Database::escape_string($id)."' AND
e.c_id = ".$this->course_id." AND
q.c_id = ".$this->course_id."
ORDER BY question_order";
$result = Database::query($sql);
// fills the array with the question ID for this exercise
// the key of the array is the question position
while ($new_object = Database::fetch_object($result)) {
$this->questionList[$new_object->question_order]= $new_object->question_id;
}
//Checking if question_order is correctly set
$this->questionList = $this->selectQuestionList(true);
//overload questions list with recorded questions list
//load questions only for exercises of type 'one question per page'
//this is needed only is there is no questions
//
//
// @todo not sure were in the code this is used somebody mess with the exercise tool
// @todo don't know who add that config and why $_configuration['live_exercise_tracking']
global $_configuration, $questionList;
if ($this->type == ONE_PER_PAGE && $_SERVER['REQUEST_METHOD'] != 'POST' && defined('QUESTION_LIST_ALREADY_LOGGED') &&
isset($_configuration['live_exercise_tracking']) && $_configuration['live_exercise_tracking']) {
//if(empty($_SESSION['questionList']))
isset($_configuration['live_exercise_tracking']) && $_configuration['live_exercise_tracking']) {
$this->questionList = $questionList;
}
return true;
@ -306,8 +291,7 @@ class Exercise {
$res = 0;
if ($this->randomByCat == 1) {
$res = 1;
}
else if ($this->randomByCat == 2) {
} else if ($this->randomByCat == 2) {
$res = 2;
}
return $res;
@ -389,18 +373,39 @@ class Exercise {
if ($from_db && !empty($this->id)) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT DISTINCT e.question_order
FROM $TBL_EXERCICE_QUESTION e INNER JOIN $TBL_QUESTIONS q
ON (e.question_id = q.id AND e.c_id = ".$this->course_id." AND q.c_id = ".$this->course_id.")
WHERE e.exercice_id = '".Database::escape_string($this->id)."'";
$result = Database::query($sql);
$count_question_orders = Database::num_rows($result);
$sql = "SELECT e.question_id, e.question_order
FROM $TBL_EXERCICE_QUESTION e INNER JOIN $TBL_QUESTIONS q
ON (e.question_id = q.id AND e.c_id = ".$this->course_id." AND q.c_id = ".$this->course_id.")
WHERE e.exercice_id = '".Database::escape_string($this->id)."'
ORDER BY question_order";
$result = Database::query($sql);
$sql = "SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION eq , $TBL_QUESTIONS q
WHERE eq.question_id = q.id AND
exercice_id='".$this->id."' AND
eq.c_id = {$this->course_id} AND
q.c_id = {$this->course_id}
ORDER BY question_order";
$result = Database::query($sql);
$question_list = array();
// fills the array with the question ID for this exercise
// the key of the array is the question position
$temp_question_list = array();
$counter = 1;
$question_list = array();
while ($new_object = Database::fetch_object($result)) {
$question_list[$new_object->question_order]= $new_object->question_id;
$temp_question_list[$counter] = $new_object->question_id;
$counter++;
}
if (!empty($temp_question_list)) {
if (count($temp_question_list) != $count_question_orders) {
$question_list = $temp_question_list;
}
}
return $question_list;
}
return $this->questionList;
@ -1692,8 +1697,7 @@ class Exercise {
}
function send_form() {
//console.log('send_form');
function send_form() {
if ($('#exercise_form').length) {
$('#exercise_form').submit();
} else {
@ -2234,7 +2238,7 @@ class Exercise {
$resfill = Database::query($queryfill);
$str = Database::result($resfill,0,'answer');
preg_match_all('#\[([^[]*)\]#', $str, $arr);
api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
$str = str_replace('\r\n', '', $str);
$choice = $arr[1];
@ -2247,10 +2251,13 @@ class Exercise {
} else {
$choice[$j] = trim($choice[$j]);
}
$user_tags[] = api_strtolower($choice[$j]);
//No idea why we api_strtolower user reponses
//$user_tags[] = api_strtolower($choice[$j]);
$user_tags[] = $choice[$j];
//put the contents of the [] answer tag into correct_tags[]
$correct_tags[] = api_strtolower(api_substr($temp, 0, $pos));
//$correct_tags[] = api_strtolower(api_substr($temp, 0, $pos));
$correct_tags[] = api_substr($temp, 0, $pos);
$j++;
$temp = api_substr($temp, $pos +1);
}
@ -3375,7 +3382,10 @@ class Exercise {
if ($objExercise->selectPropagateNeg() == 0 && $totalScore < 0) {
$totalScore = 0;
}
$result = array('score' => $totalScore, 'weight' =>$track_exercise_info['exe_weighting']);
$result = array(
'score' => $totalScore,
'weight' => $track_exercise_info['exe_weighting']
);
}
return $result;
}
@ -3472,15 +3482,13 @@ class Exercise {
function get_validated_question_list() {
$tabres = array();
$isRandomByCategory = $this->isRandomByCat();
if (!$isRandomByCategory) {
if ($isRandomByCategory == 0) {
if ($this->isRandom()) {
$tabres = $this->selectRandomList();
}
else {
} else {
$tabres = $this->selectQuestionList();
}
}
else {
} else {
if ($this->isRandom()) {
if (!class_exists("Testcategory")) {
require_once("testcategory.class.php");
@ -3523,13 +3531,13 @@ class Exercise {
shuffle($questionList); // or not
}
$tabres = $questionList;
}
else {
} else {
// Problem, random by category has been selected and we have no $this->isRandom nnumber of question selected
// Should not happened
}
}
return $tabres; }
return $tabres;
}
public function get_stat_track_exercise_info_by_exe_id($exe_id) {
$track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);

@ -52,7 +52,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
if (!$only_questions) {
$questionDescription = $objQuestionTmp->selectDescription();
if ($show_title) {
Testcategory::displayCategoryAndTitle($objQuestionTmp->id); //
echo Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id);
echo Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class'=>'question_title'));
}
if (!empty($questionDescription)) {
@ -135,8 +135,10 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
$s .= '</td></tr>';
} elseif ($answerType == ORAL_EXPRESSION) {
//Add nanog
if (api_get_setting('enable_nanogong') == 'true') {
if (api_get_setting('enable_nanogong') == 'true') {
require_once api_get_path(LIBRARY_PATH).'nanogong.lib.php';
//@todo pass this as a parameter
global $exercise_stat_info, $exerciseId, $exe_id;
@ -417,9 +419,9 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
if (!empty($value[0])) {
$value = str_replace('&nbsp;', '', trim($value[0]));
}
$correct_item = preg_quote($correct_item);
$correct_item = preg_quote($correct_item);
$correct_item = api_preg_replace('|/|', '\/', $correct_item); // to prevent error if there is a / in the text to find
$answer = api_preg_replace('/'.$correct_item.'/', Display::input('text', "choice[$questionId][]", $value), $answer);
//$answer = api_preg_replace('/\['.$correct_item.'+\]/', Display::input('text', "choice[$questionId][]", $value), $answer);
}
$i++;
}
@ -510,7 +512,8 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
} elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
// Question is a HOT_SPOT
//checking document/images visibility
if (api_is_platform_admin() || api_is_course_admin()) {
if (api_is_platform_admin() || api_is_course_admin()) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
$course = api_get_course_info();
$doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName);
if (is_numeric($doc_id)) {
@ -561,7 +564,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
if (!$only_questions) {
if ($show_title) {
Testcategory::displayCategoryAndTitle($objQuestionTmp->id);
echo Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id);
echo '<div class="question_title">'.$current_item.'. '.$questionName.'</div>';
}
//@todo I need to the get the feedback type
@ -718,10 +721,19 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
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();
if (!empty($exe_id)) {
$sql_fb_type = 'SELECT * FROM '.$TBL_EXERCICES.' as e INNER JOIN '.$TBL_TRACK_EXERCICES.' as te ON (e.id=te.exe_exo_id) WHERE te.exe_id='.$exe_id;
$sql_fb_type = "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.code = tee.exe_cours_id
WHERE tee.exe_id=$exe_id
AND q.c_id=c.id";
$res_fb_type = Database::query($sql_fb_type);
$result = Database::fetch_array($res_fb_type, 'ASSOC');
}
@ -2034,8 +2046,15 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
//Getting attempt info
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$question_list = array();
if (!empty($exercise_stat_info['data_tracking'])) {
$question_list = explode(',', $exercise_stat_info['data_tracking']);
} else {
//Try getting the question list only if save result is off
if ($save_user_result == false) {
$question_list = $objExercise->get_validated_question_list();
}
error_log("Data tracking is empty! exe_id: $exe_id");
}
$counter = 1;
@ -2130,7 +2149,7 @@ function display_question_list_by_attempt($objExercise, $exe_id, $save_user_resu
$question_content .= $objQuestionTmp->return_header(null, $counter, $score);
// display question category, if any
$question_content .= Testcategory::returnCategoryAndTitle($questionId);
$question_content .= Testcategory::getCategoryNamesForQuestion($questionId);
}
$counter++;

@ -61,6 +61,7 @@ $id = intval($_REQUEST['id']); //exe id
if (empty($id)) {
api_not_allowed(true);
}
$is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
//if (api_is_coach(api_get_session_id(), api_get_course_id())) {
@ -227,7 +228,7 @@ $arrques = array();
$arrans = array();
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
$query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts
$query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts
INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id
INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions
ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
@ -352,136 +353,136 @@ foreach ($questionList as $questionId) {
}
} else if($answerType == HOT_SPOT_DELINEATION) {
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
$final_overlap = $question_result['extra']['final_overlap'];
$final_missing = $question_result['extra']['final_missing'];
$final_excess = $question_result['extra']['final_excess'];
$overlap_color = $question_result['extra']['overlap_color'];
$missing_color = $question_result['extra']['missing_color'];
$excess_color = $question_result['extra']['excess_color'];
$threadhold1 = $question_result['extra']['threadhold1'];
$threadhold2 = $question_result['extra']['threadhold2'];
$threadhold3 = $question_result['extra']['threadhold3'];
if ($show_results) {
if ($overlap_color) {
$overlap_color='green';
} else {
$overlap_color='red';
}
if ($missing_color) {
$missing_color='green';
} else {
$missing_color='red';
}
if ($excess_color) {
$excess_color='green';
} else {
$excess_color='red';
}
if (!is_numeric($final_overlap)) {
$final_overlap = 0;
}
if (!is_numeric($final_missing)) {
$final_missing = 0;
}
if (!is_numeric($final_excess)) {
$final_excess = 0;
}
if ($final_excess>100) {
$final_excess = 100;
}
$table_resume='<table class="data_table">
<tr class="row_odd" >
<td></td>
<td ><b>'.get_lang('Requirements').'</b></td>
<td><b>'.get_lang('YourAnswer').'</b></td>
</tr>
<tr class="row_even">
<td><b>'.get_lang('Overlap').'</b></td>
<td>'.get_lang('Min').' '.$threadhold1.'</td>
<td><div style="color:'.$overlap_color.'">'.(($final_overlap < 0)?0:intval($final_overlap)).'</div></td>
</tr>
<tr>
<td><b>'.get_lang('Excess').'</b></td>
<td>'.get_lang('Max').' '.$threadhold2.'</td>
<td><div style="color:'.$excess_color.'">'.(($final_excess < 0)?0:intval($final_excess)).'</div></td>
</tr>
<tr class="row_even">
<td><b>'.get_lang('Missing').'</b></td>
<td>'.get_lang('Max').' '.$threadhold3.'</td>
<td><div style="color:'.$missing_color.'">'.(($final_missing < 0)?0:intval($final_missing)).'</div></td>
</tr></table>';
if ($answerType!= HOT_SPOT_DELINEATION) {
$item_list=explode('@@',$destination);
//print_R($item_list);
$try = $item_list[0];
$lp = $item_list[1];
$destinationid= $item_list[2];
$url=$item_list[3];
$table_resume='';
} else {
if ($next==0) {
$try = $try_hotspot;
$lp = $lp_hotspot;
$destinationid= $select_question_hotspot;
$url=$url_hotspot;
} else {
//show if no error
//echo 'no error';
$comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
$answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
}
}
echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
if ($answerType == HOT_SPOT_DELINEATION) {
if ($organs_at_risk_hit>0) {
$message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
$message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
} else {
$message='<p>'.get_lang('YourDelineation').'</p>';
$message.=$table_resume;
$message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
}
$message.='<p>'.$comment.'</p>';
echo $message;
} else {
echo '<p>'.$comment.'</p>';
}
//showing the score
$queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resfree = Database::query($queryfree);
$questionScore= Database::result($resfree,0,"marks");
$totalScore+=$questionScore;
echo '</table></td></tr>';
echo '<tr>
<td colspan="2">
<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" />
</object>
</td>
</tr>
</table>';
}
$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
$questionScore = $question_result['score'];
$totalScore += $question_result['score'];
$final_overlap = $question_result['extra']['final_overlap'];
$final_missing = $question_result['extra']['final_missing'];
$final_excess = $question_result['extra']['final_excess'];
$overlap_color = $question_result['extra']['overlap_color'];
$missing_color = $question_result['extra']['missing_color'];
$excess_color = $question_result['extra']['excess_color'];
$threadhold1 = $question_result['extra']['threadhold1'];
$threadhold2 = $question_result['extra']['threadhold2'];
$threadhold3 = $question_result['extra']['threadhold3'];
if ($show_results) {
if ($overlap_color) {
$overlap_color='green';
} else {
$overlap_color='red';
}
if ($missing_color) {
$missing_color='green';
} else {
$missing_color='red';
}
if ($excess_color) {
$excess_color='green';
} else {
$excess_color='red';
}
if (!is_numeric($final_overlap)) {
$final_overlap = 0;
}
if (!is_numeric($final_missing)) {
$final_missing = 0;
}
if (!is_numeric($final_excess)) {
$final_excess = 0;
}
if ($final_excess>100) {
$final_excess = 100;
}
$table_resume='<table class="data_table">
<tr class="row_odd" >
<td></td>
<td ><b>'.get_lang('Requirements').'</b></td>
<td><b>'.get_lang('YourAnswer').'</b></td>
</tr>
<tr class="row_even">
<td><b>'.get_lang('Overlap').'</b></td>
<td>'.get_lang('Min').' '.$threadhold1.'</td>
<td><div style="color:'.$overlap_color.'">'.(($final_overlap < 0)?0:intval($final_overlap)).'</div></td>
</tr>
<tr>
<td><b>'.get_lang('Excess').'</b></td>
<td>'.get_lang('Max').' '.$threadhold2.'</td>
<td><div style="color:'.$excess_color.'">'.(($final_excess < 0)?0:intval($final_excess)).'</div></td>
</tr>
<tr class="row_even">
<td><b>'.get_lang('Missing').'</b></td>
<td>'.get_lang('Max').' '.$threadhold3.'</td>
<td><div style="color:'.$missing_color.'">'.(($final_missing < 0)?0:intval($final_missing)).'</div></td>
</tr></table>';
if ($answerType!= HOT_SPOT_DELINEATION) {
$item_list=explode('@@',$destination);
//print_R($item_list);
$try = $item_list[0];
$lp = $item_list[1];
$destinationid= $item_list[2];
$url=$item_list[3];
$table_resume='';
} else {
if ($next==0) {
$try = $try_hotspot;
$lp = $lp_hotspot;
$destinationid= $select_question_hotspot;
$url=$url_hotspot;
} else {
//show if no error
//echo 'no error';
$comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
$answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
}
}
echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
if ($answerType == HOT_SPOT_DELINEATION) {
if ($organs_at_risk_hit>0) {
$message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
$message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
} else {
$message='<p>'.get_lang('YourDelineation').'</p>';
$message.=$table_resume;
$message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
}
$message.='<p>'.$comment.'</p>';
echo $message;
} else {
echo '<p>'.$comment.'</p>';
}
//showing the score
$queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
$resfree = Database::query($queryfree);
$questionScore= Database::result($resfree,0,"marks");
$totalScore+=$questionScore;
echo '</table></td></tr>';
echo '<tr>
<td colspan="2">
<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" />
</object>
</td>
</tr>
</table>';
}
}
if ($show_results) {
@ -602,7 +603,7 @@ foreach ($questionList as $questionId) {
$question_content .= $objQuestionTmp->return_header(null, $counter, $score);
// display question category, if any
$question_content .= Testcategory::returnCategoryAndTitle($questionId);
$question_content .= Testcategory::getCategoryNamesForQuestion($questionId);
}
$counter++;

@ -158,7 +158,7 @@ $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
if ($time_control) {
//Get the expired time of the current exercice in track_e_exercices
$total_seconds = $objExercise->expired_time*60;
$total_seconds = $objExercise->expired_time*60;
}
$show_clock = true;
@ -350,7 +350,6 @@ $exercise_title = $objExercise->selectTitle();
$exercise_description = $objExercise->selectDescription();
$exercise_sound = $objExercise->selectSound();
//if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
//in LP's is enabled the "remember question" feature?
if (!isset($_SESSION['questionList'])) {
@ -359,7 +358,7 @@ if (!isset($_SESSION['questionList'])) {
if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
$questionList = explode(',', $exercise_stat_info['data_tracking']);
}
Session::write('questionList',$questionList);
Session::write('questionList', $questionList);
if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
} else {
if (isset($objExercise) && isset($_SESSION['objExercise'])) {
@ -837,6 +836,7 @@ if (!empty($error)) {
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'");
$.ajax({
type:"post",
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
success: function(return_value) {
@ -900,6 +900,7 @@ if (!empty($error)) {
$("#save_all_reponse").html("'.addslashes(Display::return_icon('loading1.gif')).'");
$.ajax({
type:"post",
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,
success: function(return_value) {

@ -76,12 +76,14 @@ function GetComment($path, $course_code = '') {
global $dbTable;
$course_info = api_get_course_info($course_code);
$path = Database::escape_string($path);
$query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']} AND path='$path'";
$result = Database::query($query);
while ($row = Database::fetch_array($result)) {
return $row[0];
if (!empty($course_info) && !empty($path)) {
$query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']} AND path='$path'";
$result = Database::query($query);
while ($row = Database::fetch_array($result)) {
return $row[0];
}
}
return '';
return null;
}
/**
@ -97,7 +99,7 @@ function SetComment($path, $comment) {
$course_id = api_get_course_int_id();
$query = "UPDATE $dbTable SET comment='$comment' WHERE $course_id AND path='$path'";
$result = Database::query($query);
return "$result";
return $result;
}
/**
@ -106,6 +108,9 @@ function SetComment($path, $comment) {
* @return string The file contents or false on security error
*/
function ReadFileCont($full_file_path) {
if (empty($full_file_path)) {
return false;
}
if (Security::check_abs_path(dirname($full_file_path).'/', api_get_path(SYS_COURSE_PATH))) {
if (is_file($full_file_path)) {
if (!($fp = fopen(urldecode($full_file_path), 'r'))) {

@ -57,7 +57,7 @@ abstract class Question
public $level;
public $picture;
public $exerciseList; // array with the list of exercises which this question is in
public $category;
public $category_list;
private $isContent;
public $course;
static $typePicture = 'new_question.png';
@ -95,7 +95,7 @@ abstract class Question
$this->position=1;
$this->picture='';
$this->level = 1;
$this->category=0;
$this->category_list = array();
$this->extra=''; // This variable is used when loading an exercise like an scenario with an special hotspot: final_overlap, final_missing, final_excess
$this->exerciseList=array();
$this->course = api_get_course_info();
@ -144,18 +144,18 @@ abstract class Question
$objQuestion = Question::getInstance($object->type);
if (!empty($objQuestion)) {
$objQuestion->id = $id;
$objQuestion->question = $object->question;
$objQuestion->description = $object->description;
$objQuestion->weighting = $object->ponderation;
$objQuestion->position = $object->position;
$objQuestion->type = $object->type;
$objQuestion->picture = $object->picture;
$objQuestion->level = (int) $object->level;
$objQuestion->extra = $object->extra;
$objQuestion->course = $course_info;
$objQuestion->category = Testcategory::getCategoryForQuestion($id);
$objQuestion->id = $id;
$objQuestion->question = $object->question;
$objQuestion->description = $object->description;
$objQuestion->weighting = $object->ponderation;
$objQuestion->position = $object->position;
$objQuestion->type = $object->type;
$objQuestion->picture = $object->picture;
$objQuestion->level = (int) $object->level;
$objQuestion->extra = $object->extra;
$objQuestion->course = $course_info;
$objQuestion->category_list = Testcategory::getCategoryForQuestion($id);
$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id";
$result_exercise_list = Database::query($sql);
@ -317,8 +317,8 @@ abstract class Question
* @author - Hubert Borderiou 12-10-2011
* @param - array of category $in_category
*/
function updateCategory($in_category) {
$this->category=$in_category;
function updateCategory($category_list) {
$this->category_list = $category_list;
}
/**
@ -334,10 +334,44 @@ abstract class Question
* @param - interger $in_positive
*/
function updateUncheckedMayScore($in_positive) {
$this->uncheckedMayScore=$in_positive;
$this->uncheckedMayScore = $in_positive;
}
/**
* Save category of a question
*
* A question can have n categories
* if category is empty, then question has no category then delete the category entry
*
* @param - int $in_positive
* @author - Julio Montoya - Adding multiple cat support
*/
function saveCategories($category_list) {
if (empty($category_list)) {
$this->deleteCategory();
} else {
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
// update or add category for a question
foreach ($category_list as $category_id) {
$category_id = intval($category_id);
$question_id = Database::escape_string($this->id);
$sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY WHERE category_id = $category_id AND question_id = $question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
$row = Database::fetch_array($res);
if ($row['nb'] > 0) {
//DO nothing
//$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id = $category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
//$res = Database::query($sql);
} else {
$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY (c_id, question_id, category_id) VALUES (".api_get_course_int_id().", $question_id, $category_id)";
$res = Database::query($sql);
}
}
}
}
/**
* @author - Hubert Borderiou 12-10-2011
* @param - interger $in_positive
* in this version, a question can only have 1 category
@ -363,7 +397,7 @@ abstract class Question
$res = Database::query($sql);
}
}
}
}
/**
* @author hubert borderiou 12-10-2011
@ -374,10 +408,9 @@ abstract class Question
function deleteCategory() {
$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$question_id = Database::escape_string($this->id);
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
$res = Database::query($sql);
}
$sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY WHERE question_id = $question_id AND c_id = ".api_get_course_int_id();
Database::query($sql);
}
/**
* changes the question position
@ -386,7 +419,7 @@ abstract class Question
* @param - integer $position - question position
*/
function updatePosition($position) {
$this->position=$position;
$this->position = $position;
}
/**
@ -666,10 +699,9 @@ abstract class Question
$extra = $this->extra;
$c_id = $this->course['real_id'];
$category = $this->category;
// question already exists
if(!empty($id)) {
if (!empty($id)) {
$sql="UPDATE $TBL_QUESTIONS SET
question ='".Database::escape_string($question)."',
description ='".Database::escape_string($description)."',
@ -681,7 +713,9 @@ abstract class Question
level ='".Database::escape_string($level)."'
WHERE c_id = $c_id AND id='".Database::escape_string($id)."'";
Database::query($sql);
$this->saveCategory($category);
$this->saveCategories($category);
if (!empty($exerciseId)) {
api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionUpdated',api_get_user_id());
}
@ -1039,7 +1073,7 @@ abstract class Question
//Inserting in the new course db / or the same course db
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra )
VALUES('$course_id', '".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)."' )";
VALUES ('$course_id', '".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();
@ -1171,6 +1205,7 @@ abstract class Question
if(is_array($fck_config)){
$editor_config = array_merge($editor_config, $fck_config);
}
if(!api_is_allowed_to_edit(null,true)) $editor_config['UserStatus'] = 'student';
$form->addElement('advanced_settings','
@ -1184,28 +1219,45 @@ abstract class Question
// Advanced parameters
$form->addElement('advanced_settings','<a href="javascript:void(0)" onclick="visiblerDevisibler(\'id_advancedOption\')"><img id="id_advancedOptionImg" style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang("AdvancedParameters").'</a>');
$select_level = array (1=>1,2=>2,3=>3,4=>4,5=>5);
$select_level = array (
1=>1,
2=>2,
3=>3,
4=>4,
5=>5
);
$form->addElement('html','<div id="id_advancedOption" style="display:none;">');
$form->addElement('select', 'questionLevel',get_lang('Difficulty'), $select_level);
$form->addElement('select', 'questionLevel', get_lang('Difficulty'), $select_level);
// categories
$tabCat = array();
$tabCat = Testcategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $tabCat);
// Categories
$category_list = Testcategory::getCategoriesIdAndName();
$form->addElement('select', 'questionCategory', get_lang('Category'), $category_list, array('multiple' => 'multiple'));
// hidden values
$form->addElement('hidden','myid',$_REQUEST['myid']);
$form->addElement('hidden', 'myid', $_REQUEST['myid']);
if (!isset($_GET['fromExercise'])) {
switch($answerType) {
case 1: $this->question = get_lang('DefaultUniqueQuestion'); break;
case 2: $this->question = get_lang('DefaultMultipleQuestion'); break;
case 3: $this->question = get_lang('DefaultFillBlankQuestion'); break;
case 4: $this->question = get_lang('DefaultMathingQuestion'); break;
case 5: $this->question = get_lang('DefaultOpenQuestion'); break;
case 9: $this->question = get_lang('DefaultMultipleQuestion'); break;
switch ($answerType) {
case 1:
$this->question = get_lang('DefaultUniqueQuestion');
break;
case 2:
$this->question = get_lang('DefaultMultipleQuestion');
break;
case 3:
$this->question = get_lang('DefaultFillBlankQuestion');
break;
case 4:
$this->question = get_lang('DefaultMathingQuestion');
break;
case 5:
$this->question = get_lang('DefaultOpenQuestion');
break;
case 9:
$this->question = get_lang('DefaultMultipleQuestion');
break;
}
}
@ -1213,10 +1265,10 @@ abstract class Question
// default values
$defaults = array();
$defaults['questionName'] = $this -> question;
$defaults['questionDescription'] = $this -> description;
$defaults['questionLevel'] = $this -> level;
$defaults['questionCategory'] = $this->category;
$defaults['questionName'] = $this->question;
$defaults['questionDescription'] = $this->description;
$defaults['questionLevel'] = $this->level;
$defaults['questionCategory'] = $this->category_list;
//Came from he question pool
if (isset($_GET['fromExercise'])) {
@ -1239,13 +1291,13 @@ abstract class Question
* @param Exercise $objExercise the Exercise instance
*/
function processCreation ($form, $objExercise) {
$this -> updateTitle($form->getSubmitValue('questionName'));
$this -> updateDescription($form->getSubmitValue('questionDescription'));
$this -> updateLevel($form->getSubmitValue('questionLevel'));
$this->updateTitle($form->getSubmitValue('questionName'));
$this->updateDescription($form->getSubmitValue('questionDescription'));
$this->updateLevel($form->getSubmitValue('questionLevel'));
$this->updateCategory($form->getSubmitValue('questionCategory'));
$this -> save($objExercise -> id);
$this->save($objExercise->id);
// modify the exercise
$objExercise->addToList($this -> id);
$objExercise->addToList($this->id);
$objExercise->update_question_positions();
}

@ -171,7 +171,9 @@ if (!$inATest) {
$styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
$styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
$styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
$category_list = Testcategory::getCategoryListName();
if (is_array($questionList)) {
foreach ($questionList as $id) {
//To avoid warning messages
@ -203,11 +205,14 @@ if (!$inATest) {
$questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
// Question category
$txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
if (empty($txtQuestionCat)) {
$txtQuestionCat = "-";
$category_labels = Testcategory::return_category_labels($objQuestionTmp->category_list, $category_list);
if (empty($category_labels)) {
$category_labels = "-";
}
$questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
$questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;">'.$category_labels.'</a>', array('style'=>$styleCat));
// Question level
$txtQuestionLevel = $objQuestionTmp->level;

@ -413,7 +413,7 @@ if ($exerciseId > 0) {
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc ";
$where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
$where .= " AND crc.c_id = $selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
}
if (isset($exerciseLevel) && $exerciseLevel != -1) {
$where .= ' AND level='.$exerciseLevel;
@ -431,9 +431,9 @@ if ($exerciseId > 0) {
$from
WHERE
qt.question_id=qu.id
AND qt.exercice_id=$exerciseId
AND qt.c_id=$selected_course
AND qu.c_id=$selected_course
AND qt.exercice_id = $exerciseId
AND qt.c_id = $selected_course
AND qu.c_id = $selected_course
$where
ORDER BY
question_order";
@ -449,7 +449,7 @@ if ($exerciseId > 0) {
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc ";
$level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
$level_where .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id = $courseCategoryId";
}
if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
$level_where = ' AND level='.$exerciseLevel;
@ -458,19 +458,23 @@ if ($exerciseId > 0) {
if (isset($answerType) && $answerType >0 -1 ) {
$answer_where = ' AND type='.$answerType;
}
$sql = "SELECT DISTINCT * FROM $TBL_QUESTIONS qu $from WHERE qu.c_id=$selected_course AND qu.id NOT IN (SELECT question_id FROM $TBL_EXERCICE_QUESTION WHERE c_id=$selected_course ) $level_where $answer_where";
$sql = "SELECT DISTINCT * FROM $TBL_QUESTIONS qu $from
WHERE qu.c_id=$selected_course AND qu.id NOT IN (
SELECT question_id FROM $TBL_EXERCICE_QUESTION
WHERE c_id=$selected_course
) $level_where $answer_where";
$result = Database::query($sql);
while($row = Database::fetch_array($result, 'ASSOC')) {
$main_question_list[] = $row;
}
}
else {
} else {
//
// All tests for selected course
//
// if we have not selected any option in the list-box 'Filter'
$filter = '';
$from = '';
if (isset($courseCategoryId) && $courseCategoryId > 0) {
$from = ", $TBL_COURSE_REL_CATEGORY crc ";
$filter .= " AND crc.c_id=$selected_course AND crc.question_id=qu.id AND crc.category_id=$courseCategoryId";
@ -481,14 +485,6 @@ else {
if (isset($answerType) && $answerType > 0) {
$filter .= ' AND qu.type='.$answerType.' ';
}
// // why these lines ?
// if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
// $filter .= ' AND qu.type <> '.HOT_SPOT_DELINEATION.' ';
// }
// // fwhy
//
// if in session
//
if (!empty($session_id) && $session_id != '-1') {
$main_question_list = array();
if (!empty($course_list))
@ -515,8 +511,9 @@ else {
if ($answerType != $question_obj->type) {
continue;
}
$category_list = Testcategory::getCategoryForQuestion($question_obj->id, $selected_course);
if ($courseCategoryId > 0 && Testcategory::getCategoryForQuestion($question_obj->id, $selected_course)) {
if ($courseCategoryId > 0 && !empty($category_list)) {
continue;
}
if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
@ -614,6 +611,7 @@ $header[] = array($actionLabel, false, array("style"=>"text-align:center"), arra
$data = array();
if (is_array($main_question_list)) {
$all_category_list = Testcategory::getCategoryListName($selected_course);
foreach ($main_question_list as $tabQuestion) {
$row = array();
@ -628,9 +626,16 @@ if (is_array($main_question_list)) {
$row[] = $question_type;
$row[] = get_question_categorie_for_question($selected_course, $tabQuestion['id']);
$row[] = $tabQuestion['level'];
$row[] = get_action_icon_for_question($actionIcon1, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel,
$answerType, $session_id, $exerciseId).
$row[] = get_action_icon_for_question($actionIcon1,
$fromExercise,
$tabQuestion['id'],
$tabQuestion['type'],
$tabQuestion['question'],
$selected_course,
$courseCategoryId,
$exerciseLevel,
$answerType,
$session_id, $exerciseId).
"&nbsp;".
get_action_icon_for_question($actionIcon2, $fromExercise, $tabQuestion['id'], $tabQuestion['type'],
$tabQuestion['question'], $selected_course, $courseCategoryId, $exerciseLevel, $answerType,
@ -783,7 +788,9 @@ function get_question_type_for_question($in_selectedcourse, $in_questionid) {
// return the name of the category for the question in a course
// hubert.borderiou 13-10-2011
function get_question_categorie_for_question($in_courseid, $in_questionid) {
$cat = Testcategory::getCategoryNameForQuestion($in_questionid, $in_courseid);
return $cat;
function get_question_categorie_for_question($course_id, $question_id) {
global $all_category_list;
$objQuestionTmp = Question :: read($question_id, $course_id);
return Testcategory::return_category_labels($objQuestionTmp->category_list, $all_category_list);
}

@ -165,28 +165,54 @@ class Testcategory {
In this version, a question has only 1 testcategory.
Return the testcategory id, 0 if none
*/
public static function getCategoryForQuestion($in_questionid, $in_courseid="") {
$result = 0; // result
public static function getCategoryForQuestion($in_questionid, $in_courseid = null) {
$result = array(); // result
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
}
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$question_id = Database::escape_string($in_questionid);
$sql = "SELECT category_id FROM $t_cattable WHERE question_id='$question_id' AND c_id=$in_courseid";
$res = Database::query($sql);
$data = Database::fetch_array($res);
$sql = "SELECT category_id FROM $t_cattable WHERE question_id = '$question_id' AND c_id = $in_courseid";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
$result = $data['category_id'];
while ($row = Database::fetch_array($res)) {
$result[] = $row['category_id'];
}
}
return $result;
}
}
public static function getCategoryNamesForQuestion($in_questionid, $in_courseid = null, $display_into_labels = true) {
$result = array(); // result
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
}
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$table_category = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$question_id = Database::escape_string($in_questionid);
$sql = "SELECT c.title FROM $t_cattable qc INNER JOIN $table_category c
ON (qc.category_id = c.id AND qc.c_id = $in_courseid AND c.c_id = $in_courseid)
WHERE question_id = '$question_id' ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) {
$result[] = $row['title'];
}
}
if ($display_into_labels) {
$html = self::draw_category_label($result, 'header');
return $html;
}
return $result;
}
/**
* true if question id has a category
*/
public static function isQuestionHasCategory($in_questionid) {
if (Testcategory::getCategoryForQuestion($in_questionid) > 0) {
$category_list = Testcategory::getCategoryForQuestion($in_questionid);
if (!empty($category_list)) {
return true;
}
return false;
@ -194,19 +220,23 @@ class Testcategory {
/**
* @todo fix this
Return the category name for question with question_id = $in_questionid
In this version, a question has only 1 category.
Return the category id, "" if none
*/
public static function getCategoryNameForQuestion($in_questionid, $in_courseid="") {
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
}
$catid = Testcategory::getCategoryForQuestion($in_questionid, $in_courseid);
$result = ""; // result
public static function getCategoryNameForQuestion($question_id, $course_id = null) {
if (empty($course_id) || $course_id == "") {
$course_id = api_get_course_int_id();
}
$course_id = intval($course_id);
$category_list = Testcategory::getCategoryForQuestion($question_id, $course_id);
$result = array(); // result
$t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$catid = Database::escape_string($catid);
$sql = "SELECT title FROM $t_cattable WHERE id='$catid' AND c_id=$in_courseid";
$sql = "SELECT title FROM $t_cattable WHERE id='$catid' AND c_id = $course_id";
$res = Database::query($sql);
$data = Database::fetch_array($res);
if (Database::num_rows($res) > 0) {
@ -219,21 +249,25 @@ class Testcategory {
* return the list of differents categories ID for a test
* input : test_id
* return : array of category id (integer)
* hubert.borderiou 07-04-2011
* @author hubert.borderiou 07-04-2011, Julio Montoya
*/
public static function getListOfCategoriesIDForTest($in_testid) {
public static function getListOfCategoriesIDForTest($exercise_id) {
// parcourir les questions d'un test, recup les categories uniques dans un tableau
$tabcat = array();
$categories_in_exercise = array();
$quiz = new Exercise();
$quiz->read($in_testid);
$tabQuestionList = $quiz->selectQuestionList();
$quiz->read($exercise_id);
$question_list = $quiz->selectQuestionList();
// the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
for ($i=1; $i <= count($tabQuestionList); $i++) {
if (!in_array(Testcategory::getCategoryForQuestion($tabQuestionList[$i]), $tabcat)) {
$tabcat[] = Testcategory::getCategoryForQuestion($tabQuestionList[$i]);
}
}
return $tabcat;
for ($i=1; $i <= count($question_list); $i++) {
$category_list = Testcategory::getCategoryForQuestion($question_list[$i]);
if (!empty($category_list)) {
$categories_in_exercise = array_merge($categories_in_exercise, $category_list);
}
}
if (!empty($categories_in_exercise)) {
array_filter($categories_in_exercise);
}
return $categories_in_exercise;
}
@ -261,8 +295,7 @@ class Testcategory {
*/
public static function getNumberOfCategoriesForTest($in_testid) {
return count(Testcategory::getListOfCategoriesIDForTest($in_testid));
}
}
/**
* return the number of question of a category id in a test
@ -313,7 +346,7 @@ class Testcategory {
* tabresult[0] = get_lang('NoCategory');
*
*/
static function getCategoriesIdAndName($in_courseid="") {
static function getCategoriesIdAndName($in_courseid = "") {
if (empty($in_courseid) || $in_courseid=="") {
$in_courseid = api_get_course_int_id();
}
@ -332,8 +365,7 @@ class Testcategory {
* In this version, a question has 0 or 1 category
*/
function getQuestionsByCat($in_exerciceId) {
$tabres = array();
$TBL_EXERCICE = Database::get_course_table(TABLE_QUIZ_TEST);
$tabres = 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);
$in_exerciceId = intval($in_exerciceId);
@ -362,30 +394,6 @@ class Testcategory {
return $tabres;
}
/**
* display the category
*/
public static function displayCategoryAndTitle($in_questionID, $in_display_category_name = 1) {
echo self::returnCategoryAndTitle($in_questionID, $in_display_category_name);
}
public static function returnCategoryAndTitle($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;
}
$content = null;
if (Testcategory::getCategoryNameForQuestion($in_questionID) != "" && ($in_display_category_name == 1 || !$is_student)) {
$content .= '<div class="page-header">';
$content .= '<h4>'.get_lang('Category').": ".Testcategory::getCategoryNameForQuestion($in_questionID).'</h4>';
$content .= "</div>";
}
return $content;
}
/**
* Display signs [+] and/or (>0) after question title if question has options
* scoreAlwaysPositive and/or uncheckedMayScore
@ -463,5 +471,57 @@ class Testcategory {
}
return $res_num_max;
}
public function getCategoryListName($course_id = null) {
$category_list = self::getCategoryListInfo(null, $course_id);
$category_name_list = array();
if (!empty($category_list)) {
foreach($category_list as $category) {
$category_name_list[$category->id] = $category->name;
}
}
return $category_name_list;
}
public function return_category_labels($category_list, $all_categories) {
$category_list_to_render = array();
foreach ($category_list as $category_id) {
$category_name = null;
if (!isset($all_categories[$category_id])) {
$category_name = get_lang('Untitled');
} else {
$category_name = cut($all_categories[$category_id], 15);
}
$category_list_to_render[] = $category_name;
}
$html = self::draw_category_label($category_list_to_render, 'label');
return $html;
}
static function draw_category_label($category_list, $type = 'label') {
$new_category_list = array();
foreach ($category_list as $category_name) {
switch ($type) {
case 'label':
$new_category_list[] = Display::label($category_name, 'info');
break;
case 'header':
$new_category_list[] = $category_name;
break;
}
}
$html = null;
if (!empty($new_category_list)) {
switch ($type) {
case 'label':
$html = implode(' ', $new_category_list);
break;
case 'header':
$html = Display::page_subheader3(get_lang('Category').': '.implode(', ', $new_category_list));
}
}
return $html;
}
}
endif;
Loading…
Cancel
Save