[svn r18411] Fixing the querys in the question pool. If a DirectFeedback questions is enabled we filter the type of question that could be added ( see FS#3612)

skala
Julio Montoya 16 years ago
parent 0ba7067370
commit 2c00c0b885
  1. 48
      main/exercice/question.class.php
  2. 7
      main/exercice/question_list_admin.inc.php
  3. 220
      main/exercice/question_pool.php
  4. 6
      main/exercice/unique_answer.class.php

@ -1,4 +1,4 @@
<?php // $Id: question.class.php 18005 2009-01-26 18:00:46Z juliomontoya $
<?php // $Id: question.class.php 18411 2009-02-10 17:59:08Z juliomontoya $
/*
==============================================================================
@ -28,7 +28,7 @@
* File containing the Question class.
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: question.class.php 18005 2009-01-26 18:00:46Z juliomontoya $
* @version $Id: question.class.php 18411 2009-02-10 17:59:08Z juliomontoya $
*/
@ -798,18 +798,12 @@ abstract class Question
function addToList($exerciseId, $fromSave=FALSE)
{
global $TBL_EXERCICE_QUESTION;
$id=$this->id;
// checks if the exercise ID is not in the list
if(!in_array($exerciseId,$this->exerciseList))
{
// checks if the exercise ID is not in the list
if(!in_array($exerciseId,$this->exerciseList)) {
$this->exerciseList[]=$exerciseId;
$sql="INSERT INTO $TBL_EXERCICE_QUESTION(question_id,exercice_id) VALUES('".Database::escape_string($id)."','".Database::escape_string($exerciseId)."')";
$sql="INSERT INTO $TBL_EXERCICE_QUESTION (question_id, exercice_id) VALUES('".Database::escape_string($id)."','".Database::escape_string($exerciseId)."')";
api_sql_query($sql,__FILE__,__LINE__);
// we do not want to reindex if we had just saved adnd indexed the question
if (!$fromSave) {
$this->search_engine_edit($exerciseId, TRUE);
@ -1066,16 +1060,22 @@ abstract class Question
/**
* Displays the menu of question types
*/
static function display_type_menu ()
static function display_type_menu ($feedbacktype = 0)
{
global $exerciseId;
echo '<div >';
foreach(self::$questionTypes as $i=>$a_type)
{
echo '<div>';
// 1. by default we show all the question types
$question_type_custom_list = self::$questionTypes;
if (!isset($feedbacktype)) $feedbacktype=0;
if ($feedbacktype==1) {
//2. but if it is a feedback DIRECT we only show the UNIQUE_ANSWER type that is currently available
$question_type_custom_list = array ( UNIQUE_ANSWER => self::$questionTypes[UNIQUE_ANSWER]);
}
foreach ($question_type_custom_list as $i=>$a_type) {
// include the class of the type
include_once($a_type[0]);
include_once($a_type[0]);
// get the picture of the type and the langvar which describes it
eval('$img = '.$a_type[1].'::$typePicture;');
eval('$explanation = get_lang('.$a_type[1].'::$explanationLangVar);');
@ -1089,11 +1089,16 @@ abstract class Question
echo $explanation;
echo '</div>';
echo '</a>';
echo '</div>';
echo '</div>';
}
echo '<div id="answer_type_'.$i.'" style="float: left; width:120px; text-align:center">';
echo '<a href="question_pool.php?fromExercise='.$exerciseId.'">';
if ($feedbacktype==1)
echo '<a href="question_pool.php?type=1&fromExercise='.$exerciseId.'">';
else
echo '<a href="question_pool.php?fromExercise='.$exerciseId.'">';
echo '<div>';
Display::display_icon('database.gif', get_lang('GetExistingQuestion'), array('align'=>'middle'));
echo '</div>';
@ -1104,7 +1109,6 @@ abstract class Question
echo '</div>';
echo '</div>';
echo '<div style="clear:both"></div>';
}
}
endif;

@ -1,4 +1,4 @@
<?php // $Id: question_list_admin.inc.php 18005 2009-01-26 18:00:46Z juliomontoya $
<?php // $Id: question_list_admin.inc.php 18411 2009-02-10 17:59:08Z juliomontoya $
/*
==============================================================================
@ -28,7 +28,7 @@
* Code library for HotPotatoes integration.
* @package dokeos.exercise
* @author
* @version $Id: question_list_admin.inc.php 18005 2009-01-26 18:00:46Z juliomontoya $
* @version $Id: question_list_admin.inc.php 18411 2009-02-10 17:59:08Z juliomontoya $
*/
@ -84,7 +84,8 @@ if($deleteQuestion)
unset($objQuestionTmp);
}
echo '<div class="actionsbig">';
Question :: display_type_menu ();
//we filter the type of questions we can add
Question :: display_type_menu ($objExercise->feedbacktype);
echo '</div></div>';
?>

@ -1,10 +1,10 @@
<?php // $Id: question_pool.php 18159 2009-02-02 17:30:00Z herodoto $
<?php // $Id: question_pool.php 18411 2009-02-10 17:59:08Z juliomontoya $
/*
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
Copyright (c) 2004-2009 Dokeos SPRL
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) various contributors
@ -30,7 +30,7 @@
* One question can be in several exercises
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: question_pool.php 18159 2009-02-02 17:30:00Z herodoto $
* @version $Id: question_pool.php 18411 2009-02-10 17:59:08Z juliomontoya $
*/
// name of the language file that needs to be included
@ -39,7 +39,6 @@ $language_file='exercice';
include('exercise.class.php');
include('question.class.php');
include('answer.class.php');
include('../inc/global.inc.php');
$this_section=SECTION_COURSES;
@ -70,6 +69,11 @@ if(!empty($_GET['page'])){
$page = intval($_GET['page']);
}
//only that type of question
if(!empty($_GET['type'])){
$type = intval($_GET['type']);
}
// maximum number of questions on a same page
$limitQuestPage=50;
@ -127,9 +131,7 @@ if($is_allowedToEdit)
}
// adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup);
api_session_register('objExercise');
header("Location: admin.php?exerciseId=$fromExercise");
exit();
}
@ -149,106 +151,149 @@ if($is_allowedToEdit)
<div class="actions">
<?php
if(!empty($fromExercise))
{
if(!empty($fromExercise)) {
echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId=',$fromExercise,'">'.Display::return_icon('quiz.gif', get_lang('GoBackToEx')),get_lang('GoBackToEx'),'</a>';
}
else
{
} else {
echo '<a href="admin.php?',api_get_cidreq(),'&newQuestion=yes">'.Display::return_icon('new_test.gif'),get_lang('NewQu'),'</a>';
}
if (isset($type)) {
$url = api_get_self().'?type=1';
} else {
$url = api_get_self();
}
?>
<form method="get" action="<?php echo api_get_self(); ?>" style="display:inline;">
<form method="get" action="<?php echo $url; ?>" style="display:inline;">
<?php
if (isset($type)) {
echo '<input type="hidden" name="type" value="1">';
}
?>
<input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
<?php echo get_lang('Filter'); ?> :
<select name="exerciseId">
<option value="0">-- <?php echo get_lang('AllExercises'); ?> --</option>
<option value="-1" <?php if($exerciseId == -1) echo 'selected="selected"'; ?>>-- <?php echo get_lang('OrphanQuestions'); ?> --</option>
<?php
$sql="SELECT id,title FROM $TBL_EXERCICES WHERE id<>'".Database::escape_string($fromExercise)."' AND active<>'-1' ORDER BY id";
$result=api_sql_query($sql,__FILE__,__LINE__);
// shows a list-box allowing to filter questions
while($row=Database::fetch_array($result))
{
while($row=Database::fetch_array($result)) {
?>
<option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
<?php
}
?>
</select>
<?php echo get_lang('Difficulty'); ?> : <select name="exerciseLevel">
<option value="-1">-- <?php echo get_lang('AllExercises'); ?> --</option>
<?php
$sql = "SELECT MAX(level) FROM $TBL_QUESTIONS";
$result = api_sql_query($sql,__FILE__,__LINE__);
if ($row = Database::fetch_array($result)) {
$maxLevel = $row[0];
} else {
$maxLevel = -1;
}
for ($level = 0; $level <= $maxLevel; $level++) {
?>
<option value="<?php echo $level; ?>" <?php if($exerciseLevel == $level) echo 'selected="selected"'; ?>><?php echo $level; ?></option>
<?php
&nbsp;
<?php
echo get_lang('Difficulty');
echo ' : <select name="exerciseLevel">';
//echo '<option value="-1">-- '.get_lang('AllExercises').' --</option>';
if (!isset($exerciseLevel)) $exerciseLevel = -1;
for ($level = -1; $level <=5; $level++) {
$selected ='';
if ($exerciseLevel == $level)
$selected = ' selected="selected" ';
if ($level==-1) {
echo '<option value="'.$level.'" '.$selected.'>-- '.get_lang('AllExercises').' --</option>';
} else {
echo '<option value="'.$level.'" '.$selected.'>'.$level.'</option>';
}
}
?>
</select>
<input type="submit" value="<?php echo get_lang('Ok'); ?>">
echo '</select> ';
?>
<input type="submit" value="<?php echo get_lang('Ok'); ?>">
</form>
</div>
<table class="data_table">
<?php
$from=$page*$limitQuestPage;
// if we have selected an exercise in the list-box 'Filter'
if($exerciseId > 0)
{
if ($exerciseId > 0) {
//$sql="SELECT id,question,type FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ORDER BY question_order LIMIT $from, ".($limitQuestPage + 1);
$sql="SELECT id,question,type,level FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ".
(!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'AND level=\''.$exerciseLevel.'\' ' : '')."ORDER BY question_order";
}
// if we have selected the option 'Orphan questions' in the list-box 'Filter'
elseif($exerciseId == -1)
{
// Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted.
$where = '';
if (isset($type) && $type==1) {
$where = ' type = 1 AND ';
}
if (isset($exerciseLevel) && $exerciseLevel != -1) {
$where .= ' level='.$exerciseLevel.' AND ';
}
$sql="SELECT id,question,type,level
FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS
WHERE $where question_id=id AND exercice_id='".Database::escape_string($exerciseId)."'
ORDER BY question_order";
} elseif($exerciseId == -1) {
// if we have selected the option 'Orphan questions' in the list-box 'Filter'
// 1. Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted.
//$sql='SELECT id, question, type, exercice_id FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id WHERE exercice_id IS NULL LIMIT $from, '.($limitQuestPage + 1);
// New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table).
// 2. New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table).
//$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
// ' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
// ' as exercices ON exercice_id=exercices.id WHERE exercices.active = -1 LIMIT $from, '.($limitQuestPage + 1);
// This is more safe to changes, it is a mix between old and new logic.
// 3. This is more safe to changes, it is a mix between old and new logic.
/*$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1);
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1);
*/
$sql='SELECT id, question, type, exercice_id,level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id AND exercice_id IS NULL '.
/* 4. Query changed because of the Level feature implemented
$sql='SELECT id, question, type, exercice_id,level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
ON questions.id=quizz_questions.question_id AND exercice_id IS NULL '.
(!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : '');
*/
// 5. this is the combination of the 3 and 4 query because of the level feature implementation
// we filter the type of question, because in the DirectFeedback we can only add questions with type=1 = UNIQUE_ANSWER
$type_where= '';
if (isset($type) && $type==1) {
$type_where = ' AND questions.type = 1 ';
}
$level_where = '';
if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
$level_where = ' level='.$exerciseLevel.' AND ';
}
$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level
FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.' as exercices
ON exercice_id=exercices.id
WHERE '.$level_where.' (quizz_questions.exercice_id IS NULL OR exercices.active = -1 ) '.$type_where.'
LIMIT '.$from.', '.($limitQuestPage + 1);
}
// if we have not selected any option in the list-box 'Filter'
else
{
} else {
// if we have not selected any option in the list-box 'Filter'
//$sql="SELECT id,question,type FROM $TBL_QUESTIONS LIMIT $from, ".($limitQuestPage + 1);
$sql="SELECT id,question,type,level FROM $TBL_QUESTIONS ".
(!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : '');
$where = '';
if (isset($type)&& $type==1){
$where = ' WHERE type = 1 ';
}
if (isset($exerciseLevel) && $exerciseLevel != -1) {
if (strlen($where)>0)
$where .= ' AND level='.$exerciseLevel.' ';
else
$where = ' WHERE level='.$exerciseLevel.' ';
}
$sql="SELECT id,question,type,level FROM $TBL_QUESTIONS $where ";
// forces the value to 0
//echo $sql;
$exerciseId=0;
}
$result=api_sql_query($sql,__FILE__,__LINE__);
$nbrQuestions=Database::num_rows($result);
@ -260,21 +305,15 @@ if($is_allowedToEdit)
echo '</td>',
'<td align="right">';
if(!empty($page))
{
if(!empty($page)) {
echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page-1),'">&lt;&lt; ',get_lang('PreviousPage'),'</a> |';
}
elseif($nbrQuestions > $limitQuestPage)
{
} elseif($nbrQuestions > $limitQuestPage) {
echo '&lt;&lt; ',get_lang('PreviousPage'),' |';
}
if($nbrQuestions > $limitQuestPage)
{
if($nbrQuestions > $limitQuestPage) {
echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page+1),'">',get_lang('NextPage'),' &gt;&gt;</a>';
}
elseif($page)
{
} elseif($page) {
echo ' ',get_lang('NextPage'),' &gt;&gt;';
}
echo '</td>
@ -284,23 +323,21 @@ if($is_allowedToEdit)
</tr>
<tr bgcolor="#e6e6e6">';
if(!empty($fromExercise))
{
if(!empty($fromExercise)) {
echo '<th>',get_lang('Question'),'</th>',
'<th>',get_lang('Level'),'</th>',
'<th>',get_lang('Reuse'),'</th>';
}
else
{
} else {
echo '<td width="60%" align="center">',get_lang('Question'),'</td>',
'<td width="20%" align="center">',get_lang('Modify'),'</td>',
'<td width="20%" align="center">',get_lang('Delete'),'</td>';
}
echo '</tr>';
$i=1;
//print_r($objExercise->questionList);
while ($row = Database::fetch_array($result))
{
echo '<pre>';
echo '</pre>';
while ($row = Database::fetch_array($result)) {
// if we come from the exercise administration to get a question,
// don't show the questions already used by that exercise
@ -312,32 +349,27 @@ if($is_allowedToEdit)
// original recipe -
//if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (!$objExercise->isInList($row['id'])))
if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) )
{
if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) ) {
echo '<tr ',($i%2==0?'class="row_odd"':'class="row_even"'),'>';
echo ' <td><a href="admin.php?',api_get_cidreq(),'&editQuestion=',$row['id'],'&fromExercise=',$fromExercise,'">',$row['question'],'</a></td>';
echo ' <td>';
if (empty($fromExercise))
{
if (empty($fromExercise)) {
echo '<a href="admin.php?',api_get_cidreq(),'?editQuestion=',$row['id'],'"><img src="../img/edit.gif" border="0" alt="',get_lang('Modify'),'"></a>',
'</td>',
'<td align="center">',
'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
//'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
}
else
{
} else {
//echo $row['level'],'</td>',
// '<td><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'"><img src="../img/view_more_stats.gif" border="0" alt="',get_lang('Reuse'),'"></a>';
echo $row['level'],'</td>',
'<td><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'"><img src="../img/view_more_stats.gif" border="0" alt="',get_lang('Reuse'),'"></a>';
}
echo ' </td>';
echo '</td>';
echo '</tr>';
// skips the last question, that is only used to know if we have or not to create a link "Next page"
if($i == $limitQuestPage)
{
if($i == $limitQuestPage) {
break;
}
@ -345,18 +377,16 @@ if($is_allowedToEdit)
}
}
if(!$nbrQuestions)
{
if (!$nbrQuestions) {
echo '<tr>',
'<td colspan="',($fromExercise?3:3),'">',get_lang('NoQuestion'),'</td>',
'</tr>';
}
echo '</table>';
Display::display_footer();
}
// if not admin of course
else
{
} else {
// if not admin of course
api_not_allowed(true);
}
?>
?>

@ -48,6 +48,8 @@ class UniqueAnswer extends Question {
* Constructor
*/
function UniqueAnswer(){
//this is highly important
parent::question();
$this -> type = UNIQUE_ANSWER;
}
@ -57,7 +59,6 @@ class UniqueAnswer extends Question {
* @param the answers number to display
*/
function createAnswersForm ($form) {
// getting the exercise list
$obj_ex =$_SESSION['objExercise'];
// multiple
@ -144,8 +145,7 @@ class UniqueAnswer extends Question {
require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
foreach ($question_list as $key=>$questionid)
{
foreach ($question_list as $key=>$questionid) {
$question = Question::read($questionid);
$select_question[$questionid]='Q'.$key.' :'.cut($question->selectTitle(),20);
}

Loading…
Cancel
Save