Now we can copy a question from other course see BT#1917

skala
Julio Montoya 14 years ago
parent cce4c6132f
commit 2281d534ae
  1. 96
      main/exercice/answer.class.php
  2. 33
      main/exercice/exercise.class.php
  3. 11
      main/exercice/exercise.lib.php
  4. 141
      main/exercice/question.class.php
  5. 9
      main/exercice/question_list_admin.inc.php
  6. 166
      main/exercice/question_pool.php

@ -38,6 +38,7 @@ class Answer
public $nbrAnswers;
public $new_nbrAnswers;
public $new_destination; // id of the next question if feedback option is set to Directfeedback
public $course;
/**
* constructor of the class
@ -45,7 +46,7 @@ class Answer
* @author Olivier Brouckaert
* @param integer Question ID that answers belong to
*/
function Answer($questionId) {
function Answer($questionId, $course_id = null) {
//$this->questionType=$questionType;
$this->questionId = intval($questionId);
$this->answer = array();
@ -58,11 +59,20 @@ class Answer
$this->destination = array();
// clears $new_* arrays
$this->cancel();
if (!empty($course_id)) {
$this->course_id = intval($course_id);
$course_info = api_get_course_info_by_id($this->course_id);
} else {
$course_info = api_get_course_info();
}
$this->course = $course_info;
// fills arrays
$objExercise = new Exercise();
$objExercise = new Exercise($this->course['real_id']);
$objExercise->read($_REQUEST['exerciseId']);
if($objExercise->random_answers=='1') {
if ($objExercise->random_answers=='1') {
$this->readOrderedBy('rand()', '');// randomize answers
} else {
$this->read(); // natural order
@ -91,9 +101,8 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function read() {
global $_course;
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
function read() {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$questionId=$this->questionId;
//$answerType=$this->selectType();
@ -127,8 +136,7 @@ class Answer
* @param string DESC or ASC
* @author Frederic Vauthier
*/
function readOrderedBy($field,$order='ASC') {
global $_course;
function readOrderedBy($field,$order='ASC') {
$field = Database::escape_string($field);
if (empty($field)) {
$field = 'position';
@ -137,7 +145,7 @@ class Answer
if ($order != 'ASC' && $order!='DESC') {
$order = 'ASC';
}
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$questionId=$this->questionId;
$sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " .
"FROM $TBL_ANSWER WHERE question_id='".$questionId."' " .
@ -223,7 +231,7 @@ class Answer
* return array answer by id else return a bool
*/
function selectAnswerByAutoId($auto_id) {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$auto_id = intval($auto_id);
$sql="SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'";
$rs = Database::query($sql);
@ -304,7 +312,7 @@ class Answer
*/
function getQuestionType()
{
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
$sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".$this->questionId."'";
$res = Database::query($sql);
if(Database::num_rows($res)<=0){
@ -424,7 +432,7 @@ class Answer
*/
function updateAnswers($answer,$comment,$weighting,$position,$destination)
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$questionId=$this->questionId;
$sql = "UPDATE $TBL_REPONSES SET " .
@ -446,7 +454,7 @@ class Answer
*/
function save()
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$questionId=$this->questionId;
@ -494,23 +502,65 @@ class Answer
/**
* Duplicates answers by copying them into another question
*
* @author - Olivier Brouckaert
* @param - integer $newQuestionId - ID of the new question
* @author Olivier Brouckaert
* @param int $newQuestionId - ID of the new question
*/
function duplicate($newQuestionId)
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
function duplicate($newQuestionId, $course_info = null) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
if (empty($course_info)) {
$course_info = $this->course;
} else {
$course_info = $course_info;
}
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $course_info['db_name']);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
var_dump($this->selectQuestionId(), $newQuestionId);
//Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(),$this->course['db_name']);
var_dump($origin_options);
if (!empty($origin_options)) {
foreach($origin_options as $item) {
$new_option_list[]=$item['id'];
}
}
$destination_options = Question::readQuestionOption($newQuestionId,$course_info['db_name']);
$i=0;
$fixed_list = array();
if (!empty($destination_options)) {
foreach($destination_options as $item) {
$fixed_list[$new_option_list[$i]] = $item['id'];
$i++;
}
}
var_dump($fixed_list);
}
// if at least one answer
if($this->nbrAnswers) {
if ($this->nbrAnswers) {
// inserts new answers into data base
$sql="INSERT INTO $TBL_REPONSES" .
"(id,question_id,answer,correct,comment," .
"ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES";
$sql="INSERT INTO $TBL_REPONSES (id,question_id,answer,correct,comment, ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES";
for($i=1;$i <= $this->nbrAnswers;$i++) {
if ($course_info['db_name'] != $this->course['db_name']) {
$this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->answer[$i],$this->course['id'], $course_info['id']) ;
$this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->comment[$i],$this->course['id'], $course_info['id']) ;
}
$answer = Database::escape_string($this->answer[$i]);
$correct = Database::escape_string($this->correct[$i]);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
var_dump($correct);
$correct = $fixed_list[intval($correct)];
}
$comment = Database::escape_string($this->comment[$i]);
$weighting = Database::escape_string($this->weighting[$i]);
$position = Database::escape_string($this->position[$i]);

@ -37,14 +37,16 @@ class Exercise {
public $start_time;
public $questionList; // array with the list of this exercise's questions
public $results_disabled;
public $expired_time;
public $expired_time;
public $course;
/**
* Constructor of the class
*
* @author - Olivier Brouckaert
*/
function Exercise() {
function Exercise($course_id = null) {
$this->id = 0;
$this->exercise = '';
$this->description = '';
@ -59,6 +61,15 @@ class Exercise {
$this->start_time = '0000-00-00 00:00:00';
$this->results_disabled = 1;
$this->expired_time = '0000-00-00 00:00:00';
if (!empty($course_id)) {
$this->course_id = intval($course_id);
$course_info = api_get_course_info_by_id($this->course_id);
} else {
$course_info = api_get_course_info();
}
$this->course = $course_info;
}
/**
@ -69,9 +80,9 @@ class Exercise {
* @return - boolean - true if exercise exists, otherwise false
*/
function read($id) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_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,$this->course['db_name']);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$this->course['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION,$this->course['db_name']);
#$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="SELECT title,description,sound,type,random, random_answers, active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
@ -377,9 +388,9 @@ class Exercise {
* @param - string $delete - ask to delete the file
*/
function updateSound($sound,$delete) {
global $audioPath, $documentPath,$_course, $_user;
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
global $audioPath, $documentPath;
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT, $this->course['db_name']);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$this->course['db_name']);
if ($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video'))) {
$this->sound=$sound['name'];
@ -393,7 +404,7 @@ class Exercise {
/*$query="INSERT INTO $TBL_DOCUMENT(path,filetype) VALUES "
." ('".str_replace($documentPath,'',$audioPath).'/'.$this->sound."','file')";
Database::query($query);*/
$id = add_document($_course,str_replace($documentPath,'',$audioPath).'/'.$this->sound,'file',$sound['size'],$sound['name']);
$id = add_document($this->course,str_replace($documentPath,'',$audioPath).'/'.$this->sound,'file',$sound['size'],$sound['name']);
//$id = Database::insert_id();
//$time = time();
@ -404,8 +415,8 @@ class Exercise {
." VALUES "
."('".TOOL_DOCUMENT."', $id, $_user['user_id'], 0, '$time', '$time', 'DocumentAdded' )";
Database::query($query);*/
api_item_property_update($_course, TOOL_DOCUMENT, $id, 'DocumentAdded',$_user['user_id']);
item_property_update_on_folder($_course,str_replace($documentPath,'',$audioPath),$_user['user_id']);
api_item_property_update($this->course, TOOL_DOCUMENT, $id, 'DocumentAdded',api_get_user_id());
item_property_update_on_folder($this->course,str_replace($documentPath,'',$audioPath),api_get_user_id());
}
}
} elseif($delete && is_file($audioPath.'/'.$this->sound)) {

@ -92,6 +92,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$quiz_question_options = Question::readQuestionOption($questionId);
// For "matching" type here, we need something a little bit special
// because the match between the suggestions and the answers cannot be
@ -301,10 +302,12 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
} elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
$options = array('type'=>'radio','name'=>'choice['.$questionId.']['.$numAnswer.']', 'class'=>'checkbox');
$s .='<tr>';
$s .= Display::tag('td', $answer);
foreach ($quiz_question_options as $id=>$item) {
$options['value'] = $id;
$s .= Display::tag('td', Display::tag('input','',$options ));
$s .= Display::tag('td', $answer);
if (!empty($quiz_question_options)) {
foreach ($quiz_question_options as $id=>$item) {
$options['value'] = $id;
$s .= Display::tag('td', Display::tag('input','',$options ));
}
}
$s.='<tr>';
}

@ -46,7 +46,8 @@ abstract class Question
public $picture;
public $exerciseList; // array with the list of exercises which this question is in
private $isContent;
public $course;
static $typePicture = 'new_question.png';
static $explanationLangVar = '';
static $questionTypes = array(
@ -92,20 +93,25 @@ abstract class Question
* @param - integer $id - question ID
* @return - boolean - true if question exists, otherwise false
*/
static function read($id)
{
global $_course;
$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,level,extra FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
static function read($id, $course_id = null) {
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
} else {
global $course;
$course_info = api_get_course_info();
}
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST, $course_info['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['db_name']);
$id = intval($id);
$sql="SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE id='".$id."'";
$result=Database::query($sql);
// if the question has been found
if($object=Database::fetch_object($result)) {
if ($object=Database::fetch_object($result)) {
$objQuestion = Question::getInstance($object->type);
$objQuestion->id = $id;
$objQuestion->question = $object->question;
@ -116,8 +122,9 @@ abstract class Question
$objQuestion->picture = $object->picture;
$objQuestion->level = (int) $object->level;
$objQuestion->extra = $object->extra;
$objQuestion->course = $course_info;
$sql="SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id='".intval($id)."'";
$sql="SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id='".$id."'";
$result=Database::query($sql);
// fills the array with the exercises which this question is in
@ -218,13 +225,11 @@ abstract class Question
return $this->picture;
}
function selectPicturePath() {
global $_course;
function selectPicturePath() {
if (!empty($this->picture)) {
return api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/images/'.$this->picture;
return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture;
}
return false;
return false;
}
/**
@ -312,7 +317,7 @@ abstract class Question
* @param - integer $type - answer type
*/
function updateType($type) {
global $TBL_REPONSES;
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
// if we really change the type
if($type != $this->type) {
@ -336,16 +341,16 @@ abstract class Question
* @return - boolean - true if uploaded, otherwise false
*/
function uploadPicture($Picture,$PictureName) {
global $picturePath, $_course, $_user;
global $picturePath;
if (!file_exists($picturePath)) {
if (mkdir($picturePath, api_get_permissions_for_new_directories())) {
// document path
$documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
$documentPath = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . "/document";
$path = str_replace($documentPath,'',$picturePath);
$title_path = basename($picturePath);
$doc_id = add_document($_course, $path, 'folder', 0,$title_path);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
$doc_id = add_document($this->course, $path, 'folder', 0,$title_path);
api_item_property_update($this->course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
}
}
@ -356,15 +361,15 @@ abstract class Question
if($extension == 'gif' || $extension == 'png') {
$o_img = new image($Picture);
$o_img->send_image('JPG',$picturePath.'/'.$this->picture);
$document_id = add_document($_course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture);
$document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture);
}
else
{
move_uploaded_file($Picture,$picturePath.'/'.$this->picture)?true:false;
}
$document_id = add_document($_course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture);
$document_id = add_document($this->course, '/images/'.$this->picture, 'file', filesize($picturePath.'/'.$this->picture),$this->picture);
if($document_id) {
return api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_user['user_id']);
return api_item_property_update($this->course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id);
}
}
@ -589,10 +594,9 @@ abstract class Question
* @param - integer $exerciseId - exercise ID if saving in an exercise
*/
function save($exerciseId=0) {
global $_course,$_user;
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
$id=$this->id;
$question=$this->question;
@ -618,7 +622,7 @@ abstract class Question
WHERE id='".Database::escape_string($id)."'";
Database::query($sql);
if(!empty($exerciseId)) {
api_item_property_update($_course, TOOL_QUIZ, $id,'QuizQuestionUpdated',$_user['user_id']);
api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionUpdated',api_get_user_id);
}
if (api_get_setting('search_enabled')=='true') {
if ($exerciseId != 0) {
@ -653,12 +657,12 @@ abstract class Question
$this->id=Database::insert_id();
api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizQuestionAdded',$_user['user_id']);
api_item_property_update($this->course, TOOL_QUIZ, $this->id,'QuizQuestionAdded',api_get_user_id());
// If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql="INSERT INTO $TBL_ANSWERS (`id` , `question_id` , `answer` , `correct` , `comment` , `ponderation` , `position` , `hotspot_coordinates` , `hotspot_type` ) VALUES ('1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
$sql="INSERT INTO $TBL_ANSWERS (id , question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type ) VALUES ('1', '".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
Database::query($sql);
}
@ -802,7 +806,7 @@ abstract class Question
* @param - boolean $fromSave - comming from $this->save() or not
*/
function addToList($exerciseId, $fromSave = FALSE) {
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course['db_name']);
$id = $this->id;
// checks if the exercise ID is not in the list
if (!in_array($exerciseId,$this->exerciseList)) {
@ -861,7 +865,7 @@ abstract class Question
}
/**
* deletes a question from the database
* Deletes a question from the database
* the parameter tells if the question is removed from all exercises (value = 0),
* or just from one exercise (value = exercise ID)
*
@ -871,9 +875,9 @@ abstract class Question
function delete($deleteFromEx=0) {
global $_course,$_user;
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course['db_name']);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
$id=$this->id;
@ -900,7 +904,7 @@ abstract class Question
$sql="DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($id)."'";
Database::query($sql);
api_item_property_update($_course, TOOL_QUIZ, $id,'QuizQuestionDeleted',$_user['user_id']);
api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id());
$this->removePicture();
// resets the object
@ -914,7 +918,7 @@ abstract class Question
// disassociate question with this exercise
$this -> search_engine_edit($deleteFromEx, FALSE, TRUE);
}
api_item_property_update($_course, TOOL_QUIZ, $id,'QuizQuestionDeleted',$_user['user_id']);
api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id());
}
}
@ -923,9 +927,16 @@ abstract class Question
*
* @author - Olivier Brouckaert
* @return - integer - ID of the new question
*/
function duplicate() {
global $TBL_QUESTIONS, $picturePath;
*/
function duplicate($course_info = null) {
if (empty($course_info)) {
$course_info = $this->course;
} else {
$course_info = $course_info;
}
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
$TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION, $course_info['db_name']);
$question = $this->question;
$description = $this->description;
@ -933,15 +944,34 @@ abstract class Question
$position = $this->position;
$type = $this->type;
$level = intval($this->level);
$sql="INSERT INTO $TBL_QUESTIONS(question, description, ponderation, position, type, 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($level)."')";
Database::query($sql);
$id=Database::insert_id();
$extra = $this->extra;
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
if ($course_info['db_name'] != $this->course['db_name']) {
$description = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']);
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']);
}
$options = self::readQuestionOption($this->id);
var_dump($options);
$sql="INSERT INTO $TBL_QUESTIONS(question, description, ponderation, position, type, level, extra ) VALUES('".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();
if (!empty($options)) {
//Saving the quiz_options
foreach ($options as $item) {
$item['question_id'] = $new_question_id;
unset($item['id']);
Database::insert($TBL_QUESTION_OPTIONS,$item);
}
}
// duplicates the picture
$this->exportPicture($id);
return $id;
$this->exportPicture($new_question_id);
return $new_question_id;
}
/**
@ -967,8 +997,7 @@ abstract class Question
* A subclass can redifine this function to add fields...
* @param FormValidator $form the formvalidator instance (by reference)
*/
function createForm (&$form,$fck_config=0)
{
function createForm (&$form,$fck_config=0) {
echo ' <style>
div.row div.label{ width: 5%; }
div.row div.formw{ width: 92%; }
@ -1227,9 +1256,13 @@ abstract class Question
}
static function readQuestionOption($question_id) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$result = Database::find($TBL_EXERCICE_QUESTION_OPTION, '*', array('question_id = ?' =>$question_id));
static function readQuestionOption($question_id, $db_name = null) {
if (empty($db_name)) {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
} else {
$TBL_EXERCICE_QUESTION_OPTION = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION, $db_name);
}
$result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where'=>array('question_id = ?' =>$question_id), 'order'=>'id'));
return $result;
}
}

@ -146,14 +146,9 @@ if ($nbrQuestions) {
echo '<p>';
echo $actions;
echo get_lang($question_class.$label);
echo '<br />';
echo '<br />';
echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
echo '<br />';
$description = $objQuestionTmp->selectDescription();
if (!empty($description)) {
echo get_lang('Description').': '.$description;
}
echo '<br />';
showQuestion($id, false, '', '',false, true);
echo '</p>';

@ -7,7 +7,7 @@
* One question can be in several exercises
* @package chamilo.exercise
* @author Olivier Brouckaert
* @version $Id: question_pool.php 20451 2009-05-10 12:02:22Z ivantcholakov $
* @author Julio Montoya adding support to query all questions from all session, courses, exercises
*/
// name of the language file that needs to be included
@ -16,17 +16,17 @@ $language_file='exercice';
require_once 'exercise.class.php';
require_once 'question.class.php';
require_once 'answer.class.php';
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
$this_section=SECTION_COURSES;
$is_allowedToEdit=api_is_allowed_to_edit(null,true);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
if ( empty ( $delete ) ) {
$delete = intval($_GET['delete']);
}
@ -60,17 +60,19 @@ if(!empty($_GET['type'])){
$type = intval($_GET['type']);
}
$session_id = intval($_GET['session_id']);
// maximum number of questions on a same page
$limitQuestPage=50;
// document path
/*// document path
$documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
// picture path
$picturePath=$documentPath.'/images';
*/
if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
$objExercise = new Exercise();
$objExercise = new Exercise();
$objExercise->read($fromExercise);
}
if(!($objExcercise instanceOf Exercise) && !empty($exerciseId)) {
@ -78,23 +80,32 @@ if(!($objExcercise instanceOf Exercise) && !empty($exerciseId)) {
$objExercise->read($exerciseId);
}
if($is_allowedToEdit) {
if ($is_allowedToEdit) {
//copy exercise
//Duplicating a Question
if ($copy_question != 0 && isset($fromExercise)) {
$old_question_id = $copy_question;
$old_question_obj = Question::read($old_question_id);
$origin_course_id = $_GET['course_id'];
$origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info();
$old_question_id = $copy_question;
//Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id);
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
$new_id = $old_question_obj->duplicate();
//Duplicating question in the current course
$new_id = $old_question_obj->duplicate($current_course);
$new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise);
$new_answer_obj = new Answer($old_question_id);
$new_question_obj->addToList($fromExercise);
//Reading Answer obj from origin course
$new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read();
$new_answer_obj->duplicate($new_id);
//Duplicating the answers in this course
$new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object
unset($new_question_obj);
@ -107,6 +118,7 @@ if($is_allowedToEdit) {
// adds the question ID represented by $recup into the list of questions for the current exercise
//$objExercise->addToList($new_id);
api_session_register('objExercise');
exit;
header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
exit();
@ -175,18 +187,21 @@ if (isset($_SESSION['gradebook'])){
}
if (!empty($gradebook) && $gradebook=='view') {
$interbreadcrumb[]= array (
'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
'name' => get_lang('ToolGradebook')
);
$interbreadcrumb[]= array ('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),'name' => get_lang('ToolGradebook'));
}
$nameTools=get_lang('QuestionPool');
$interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
$selected_course = 0;
// if admin of course
if($is_allowedToEdit) {
if ($is_allowedToEdit) {
$htmlHeadXtra[] = ' <script type="text/javascript">
function submit_form(obj) {
document.question_pool.submit();
}
</script>';
Display::display_header($nameTools,'Exercise');
echo '<h3>'.$nameTools.'</h3>';
echo '<div class="actions">';
@ -195,11 +210,57 @@ if($is_allowedToEdit) {
} else {
$url = api_get_self();
}
echo '<form method="GET" action="'.$url.'" style="display:inline;">';
echo '<form name="question_pool" method="GET" action="'.$url.'" style="display:inline;">';
if (isset($type)) {
echo '<input type="hidden" name="type" value="1">';
}
}
//echo '<input type="hidden" name="cidReq" value="'.api_get_cidreq().'">';
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
$session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
$session_select_list = array();
foreach($session_list as $item) {
$session_select_list[$item['id']] = $item['name'];
}
echo get_lang('Session').' : ';
echo Display::select('session_id', $session_select_list, $session_id, array('onchange'=>'submit_form(this);'));
if (!empty($session_id) && $session_id != '-1') {
$course_list = SessionManager::get_course_list_by_session_id($session_id);
} else {
$course_list =CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
}
$course_select_list = array();
foreach ($course_list as $item) {
$course_select_list[$item['id']] = $item['title'];
}
$selected_course = intval($_GET['selected_course']);
//echo Display::input('hidden', 'selected_course', $selected_course);
echo get_lang('Course').' : ';
echo Display::select('selected_course', $course_select_list, $selected_course, array('onchange'=>'submit_form(this);'));
if (empty($selected_course )) {
$current_course_info = api_get_course_info();
$db_name = $current_course_info ['db_name'];
} else {
$course_info = CourseManager::get_course_information_by_id($selected_course);
$db_name = $course_info['db_name'];
}
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $db_name);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST, $db_name);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $db_name);
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER, $db_name);
echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
echo get_lang('Exercice').' :';
echo '<select name="exerciseId">';
@ -220,27 +281,16 @@ if($is_allowedToEdit) {
</select>
&nbsp;
<?php
echo get_lang('Difficulty');
echo ' : <select name="exerciseLevel">';
//echo '<option value="-1">-- '.get_lang('AllExercises').' --</option>';
//level difficulty only from 1 to 5
if (!isset($exerciseLevel)) $exerciseLevel = -1;
for ($level = -1; $level <=5; $level++) {
$selected ='';
if ($level!=0) {
if ($exerciseLevel == $level)
$selected = ' selected="selected" ';
if ($level==-1) {
echo '<option value="'.$level.'" '.$selected.'>'.get_lang('Any').'</option>';
} else {
echo '<option value="'.$level.'" '.$selected.'>'.$level.'</option>';
}
}
}
echo '</select> ';
echo get_lang('Difficulty');
//level difficulty only from 1 to 5
echo Display::select('exerciseLevel', array(1,2,3,4,5), $exerciseLevel);
//
$question_list = Question::get_types_information();
$new_question_list = array();
foreach($question_list as $key=>$item) {
$new_question_list[$key] = get_lang($item[1]);
}
echo get_lang('AnswerType');
echo ' : <select name="answerType">';
//answer type
@ -261,7 +311,10 @@ if($is_allowedToEdit) {
}
}
}
echo '</select> ';
?>
<button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Filter') ?></button>
@ -280,6 +333,7 @@ if($is_allowedToEdit) {
<?php
$from=$page*$limitQuestPage;
// if we have selected an exercise in the list-box 'Filter'
var_dump($exerciseId);
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);
$where = '';
@ -369,7 +423,8 @@ if($is_allowedToEdit) {
$filter .= ' AND qu.type='.$answerType.' ';
}
$new_limit_page = $limitQuestPage + 1;
$sql="SELECT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q
var_dump($session_id);
echo $sql="SELECT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q
WHERE q.id=qt.exercice_id AND qu.id=qt.question_id AND qt.exercice_id<>".$fromExercise." $filter ORDER BY session_id ASC LIMIT $from, $new_limit_page";
// forces the value to 0
//echo $sql;
@ -463,10 +518,10 @@ if($is_allowedToEdit) {
'<td align="center"><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'">';
if ($row['session_id'] == $session_id){
echo '<img src="../img/view_more_stats.gif" border="0" title="'.get_lang('Reuse').'" alt="'.get_lang('Reuse').'"></a>';
}
echo ' <a href="',api_get_self(),'?',api_get_cidreq(),'&copy_question=',$row['id'],'&fromExercise=',$fromExercise,'">' .
'<img src="../img/cd.gif" border="0" title="'.get_lang('ReUseACopyInCurrentTest').'" alt="'.get_lang('ReUseACopyInCurrentTest').'"></a>';
}
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;copy_question='.$row['id'].'&course_id='.$selected_course.'&fromExercise=',$fromExercise,'">';
echo ' '.Display::return_icon('cd.gif', get_lang('ReUseACopyInCurrentTest'));
echo '</a>';
}
echo '</td>';
echo '</tr>';
@ -495,5 +550,4 @@ if($is_allowedToEdit) {
} else {
// if not admin of course
api_not_allowed(true);
}
?>
}
Loading…
Cancel
Save