[svn r17948] New code in tool exercise (questions with) developed by Nicolas Raynaud (Cyim) added by jmontoya FS#3515

skala
Julio Montoya 16 years ago
parent 58cd248ad0
commit 76ec824e7e
  1. 48
      main/exercice/question.class.php
  2. 9
      main/exercice/question_list_admin.inc.php
  3. 78
      main/exercice/question_pool.php
  4. 3
      main/inc/lib/add_course.lib.inc.php
  5. 1
      main/install/migrate-db-1.8.5-1.8.6-pre.sql

@ -1,4 +1,4 @@
<?php // $Id: question.class.php 17741 2009-01-15 17:36:02Z cfasanando $
<?php // $Id: question.class.php 17948 2009-01-22 21:39:22Z juliomontoya $
/*
==============================================================================
@ -28,7 +28,7 @@
* File containing the Question class.
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: question.class.php 17741 2009-01-15 17:36:02Z cfasanando $
* @version $Id: question.class.php 17948 2009-01-22 21:39:22Z juliomontoya $
*/
@ -62,9 +62,8 @@ abstract class Question
var $weighting;
var $position;
var $type;
var $level;
var $picture;
var $exerciseList; // array with the list of exercises which this question is in
static $typePicture = 'new_question.png';
@ -91,7 +90,7 @@ abstract class Question
$this->weighting=0;
$this->position=1;
$this->picture='';
$this->level = 0;
$this->exerciseList=array();
}
@ -109,7 +108,7 @@ abstract class Question
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql="SELECT question,description,ponderation,position,type,picture FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
$sql="SELECT question,description,ponderation,position,type,picture,level FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
$result=api_sql_query($sql,__FILE__,__LINE__);
@ -124,6 +123,7 @@ abstract class Question
$objQuestion->position=$object->position;
$objQuestion->type=$object->type;
$objQuestion->picture=$object->picture;
$objQuestion->level=(int) $object->level;
$sql="SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id='".intval($id)."'";
$result=api_sql_query($sql,__FILE__,__LINE__);
@ -209,6 +209,17 @@ abstract class Question
return $this->type;
}
/**
* returns the level of the question
*
* @author - Nicolas Raynaud
* @return - integer - level of the question, 0 by default.
*/
function selectLevel()
{
return $this->level;
}
/**
* returns the picture name
*
@ -286,6 +297,17 @@ abstract class Question
$this->position=$position;
}
/**
* changes the question level
*
* @author - Nicolas Raynaud
* @param - integer $level - question level
*/
function updateLevel($level)
{
$this->level=$level;
}
/**
* changes the answer type. If the user changes the type from "unique answer" to "multiple answers"
* (or conversely) answers are not deleted, otherwise yes
@ -564,6 +586,7 @@ abstract class Question
$position=$this->position;
$type=$this->type;
$picture=addslashes($this->picture);
$level=$this->level;
// question already exists
if(!empty($id))
@ -574,7 +597,8 @@ abstract class Question
ponderation ='".Database::escape_string($weighting)."',
position ='".Database::escape_string($position)."',
type ='".Database::escape_string($type)."',
picture ='".Database::escape_string($picture)."'
picture ='".Database::escape_string($picture)."',
level ='".Database::escape_string($level)."'
WHERE id='".Database::escape_string($id)."'";
api_sql_query($sql,__FILE__,__LINE__);
if(!empty($exerciseId)) {
@ -602,13 +626,14 @@ abstract class Question
$this -> updatePosition($current_position+1);
$position = $this -> position;
$sql="INSERT INTO $TBL_QUESTIONS(question,description,ponderation,position,type,picture) VALUES(
$sql="INSERT INTO $TBL_QUESTIONS(question,description,ponderation,position,type,picture,level) VALUES(
'".Database::escape_string($question)."',
'".Database::escape_string($description)."',
'".Database::escape_string($weighting)."',
'".Database::escape_string($position)."',
'".Database::escape_string($type)."',
'".Database::escape_string($picture)."'
'".Database::escape_string($picture)."'',
'".Database::escape_string($level)."'
)";
api_sql_query($sql,__FILE__,__LINE__);
@ -967,6 +992,9 @@ abstract class Question
$answerType= intval($_REQUEST['answerType']);
$form->addElement('hidden','answerType',$_REQUEST['answerType']);
// question level
$form->addElement('text','questionLevel',get_lang('Level'));
$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','questionLevel');
// html editor
global $fck_attribute;
@ -1001,6 +1029,7 @@ abstract class Question
$defaults = array();
$defaults['questionName'] = $this -> question;
$defaults['questionDescription'] = $this -> description;
$defaults['questionLevel'] = $this -> level;
$form -> setDefaults($defaults);
}
@ -1013,6 +1042,7 @@ abstract class Question
$this -> updateTitle($form->getSubmitValue('questionName'));
$this -> updateDescription($form->getSubmitValue('questionDescription'));
$this -> updateLevel($form->getSubmitValue('questionLevel'));
$this -> save($objExercise -> id);
// modify the exercise

@ -1,4 +1,4 @@
<?php // $Id: question_list_admin.inc.php 16726 2008-11-12 15:44:48Z pcool $
<?php // $Id: question_list_admin.inc.php 17948 2009-01-22 21:39:22Z juliomontoya $
/*
==============================================================================
@ -28,7 +28,7 @@
* Code library for HotPotatoes integration.
* @package dokeos.exercise
* @author
* @version $Id: question_list_admin.inc.php 16726 2008-11-12 15:44:48Z pcool $
* @version $Id: question_list_admin.inc.php 17948 2009-01-22 21:39:22Z juliomontoya $
*/
@ -94,6 +94,7 @@ echo '</div></div>';
<tr class="row_odd">
<th><?php echo get_lang('Question'); ?></th>
<th><?php echo get_lang('Type');?></th>
<th><?php echo get_lang('Level'); ?></th>
<th><?php echo get_lang('Export'); ?></th>
<th><?php echo get_lang('Modify'); ?></th>
</tr>
@ -113,7 +114,9 @@ if($nbrQuestions)
?>
<tr <?php if($i%2==0) echo 'class="row_odd"'; else echo 'class="row_even"'; ?>>
<td><?php echo "$i. ".$objQuestionTmp->selectTitle(); ?></td> <td><?php eval('echo get_lang('.get_class($objQuestionTmp).'::$explanationLangVar);'); ?></td>
<td><?php echo "$i. ".$objQuestionTmp->selectTitle(); ?></td>
<td><?php eval('echo get_lang('.get_class($objQuestionTmp).'::$explanationLangVar);'); ?></td>
<td align="center"><?php echo $objQuestionTmp->selectLevel(); ?></td>
<td align="center"><a href="<?php echo api_get_self(); ?>?action=exportqti2&questionId=<?php echo $id; ?>"><img src="../img/export.png" border="0" align="absmiddle" alt="IMS/QTI" /></a></td>
<td> <a href="<?php echo api_get_self(); ?>?myid=1&editQuestion=<?php echo $id; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>" /></a> <a href="<?php echo api_get_self(); ?>?deleteQuestion=<?php echo $id; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;"><img src="../img/delete.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Delete'); ?>" /></a>

@ -1,4 +1,4 @@
<?php // $Id: question_pool.php 17302 2008-12-15 21:13:36Z ivantcholakov $
<?php // $Id: question_pool.php 17948 2009-01-22 21:39:22Z juliomontoya $
/*
==============================================================================
@ -30,7 +30,7 @@
* One question can be in several exercises
* @package dokeos.exercise
* @author Olivier Brouckaert
* @version $Id: question_pool.php 17302 2008-12-15 21:13:36Z ivantcholakov $
* @version $Id: question_pool.php 17948 2009-01-22 21:39:22Z juliomontoya $
*/
// name of the language file that needs to be included
@ -63,6 +63,9 @@ if ( empty ( $fromExercise ) ) {
if(isset($_GET['exerciseId'])){
$exerciseId = intval($_GET['exerciseId']);
}
if(isset($_GET['exerciseLevel'])){
$exerciseLevel = intval($_GET['exerciseLevel']);
}
if(!empty($_GET['page'])){
$page = intval($_GET['page']);
}
@ -158,6 +161,8 @@ if($is_allowedToEdit)
<form method="get" action="<?php echo api_get_self(); ?>" style="display:inline;">
<input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
<?php echo get_lang('Filter'); ?> :
<select name="exerciseId">
@ -171,14 +176,38 @@ if($is_allowedToEdit)
// shows a list-box allowing to filter questions
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
?>
<option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
<?php
}
?>
</select> <input type="submit" value="<?php echo get_lang('Ok'); ?>">
</select>
<?php echo get_lang('Level'); ?> : <select name="exerciseLevel">
<option value="-1">-- <?php echo get_lang('AllExercises'); ?> --</option>
<?php
$sqlMaxLevel = "SELECT MAX(level) FROM $TBL_QUESTIONS";
$resultMaxLevel = api_sql_query($sqlMaxLevel,__FILE__,__LINE__);
if ($result0MaxLevel = Database::fetch_array($resultMaxLevel))
{
$maxLevel = $result0MaxLevel[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
}
?>
</select>
<input type="submit" value="<?php echo get_lang('Ok'); ?>">
</form>
</div>
@ -189,7 +218,9 @@ if($is_allowedToEdit)
// if we have selected an exercise in the list-box 'Filter'
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 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)
@ -203,14 +234,23 @@ if($is_allowedToEdit)
// ' 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.
$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
/*$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);
*/
$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.'\' ' : '');
}
// if we have not selected any option in the list-box 'Filter'
else
{
$sql="SELECT id,question,type FROM $TBL_QUESTIONS LIMIT $from, ".($limitQuestPage + 1);
//$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.'\' ' : '');
// forces the value to 0
$exerciseId=0;
}
@ -219,7 +259,7 @@ if($is_allowedToEdit)
$nbrQuestions=Database::num_rows($result);
echo '<tr>',
'<td colspan="',($fromExercise?2:3),'">',
'<td colspan="',($fromExercise?3:3),'">',
'<table border="0" cellpadding="0" cellspacing="0" width="100%">',
'<tr>',
'<td>';
@ -253,6 +293,7 @@ if($is_allowedToEdit)
if(!empty($fromExercise))
{
echo '<th>',get_lang('Question'),'</th>',
'<th>',get_lang('Level'),'</th>',
'<th>',get_lang('Reuse'),'</th>';
}
else
@ -287,14 +328,17 @@ if($is_allowedToEdit)
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>',
'</td>';
'<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
{
echo '<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 $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 '</tr>';
// skips the last question, that is only used to know if we have or not to create a link "Next page"
@ -310,7 +354,7 @@ if($is_allowedToEdit)
if(!$nbrQuestions)
{
echo '<tr>',
'<td colspan="',($fromExercise?2:3),'">',get_lang('NoQuestion'),'</td>',
'<td colspan="',($fromExercise?3:3),'">',get_lang('NoQuestion'),'</td>',
'</tr>';
}
echo '</table>';

@ -646,6 +646,7 @@ function update_Db_course($courseDbName)
position mediumint unsigned NOT NULL default 1,
type tinyint unsigned NOT NULL default 2,
picture varchar(50) default NULL,
level int unsigned NOT NULL default 0,
PRIMARY KEY (id)
)";
api_sql_query($sql, __FILE__, __LINE__);
@ -2194,7 +2195,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
api_sql_query("INSERT INTO `".$TABLEQUIZANSWERSLIST . "` VALUES ( '4', '1', '".lang2db(get_lang('Contradiction')) . "', '1', '".lang2db(get_lang('NotFalse')) . "', '5', '4','','','')", __FILE__, __LINE__);
$html=addslashes('<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="110" valign="top" align="left"><img src="'.api_get_path(WEB_CODE_PATH).'default_course_document/images/mr_dokeos/thinking.jpg"></td><td valign="top" align="left">'.lang2db(get_lang('Antique')).'</td></tr></table>');
api_sql_query('INSERT INTO `'.$TABLEQUIZ . '` (title, description, type, random, active, results_disabled ) VALUES ("'.lang2db(get_lang('ExerciceEx')) . '", "'.$html.'", "1", "0", "1", "0")', __FILE__, __LINE__);
api_sql_query("INSERT INTO `".$TABLEQUIZQUESTIONLIST . "` VALUES ( '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','')", __FILE__, __LINE__);
api_sql_query("INSERT INTO `".$TABLEQUIZQUESTIONLIST . "` VALUES ( '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','',0)", __FILE__, __LINE__);
api_sql_query("INSERT INTO `".$TABLEQUIZQUESTION . "` (question_id, exercice_id, question_order) VALUES (1,1,1)", __FILE__, __LINE__);

@ -191,3 +191,4 @@ INSERT INTO tool(name,link,image,visibility,admin,address,added_tool,target,cate
ALTER TABLE quiz ADD feedback_type int NOT NULL default 0;
ALTER TABLE quiz_answer ADD destination text NOT NULL;
CREATE TABLE glossary(glossary_id int unsigned NOT NULL auto_increment, name varchar(255) NOT NULL, description text not null, display_order int, PRIMARY KEY (glossary_id));
ALTER TABLE quiz_question ADD level int UNSIGNED NOT NULL default 0;

Loading…
Cancel
Save