Cleaning code

skala
Julio Montoya 15 years ago
parent 983029325e
commit 8fac19f38b
  1. 129
      main/exercice/answer.class.php
  2. 78
      main/exercice/question.class.php

@ -1,35 +1,16 @@
<?php
/*
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See "documentation/licence.html" more details.
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
*/
/* For licensing terms, see /license.txt */
/**
* This class allows to instantiate an object of type Answer
* 5 arrays are created to receive the attributes of each answer belonging to a specified question
* @package dokeos.exercise
* @package chamilo.exercise
* @author Olivier Brouckaert
* @version $Id: answer.class.php 21172 2009-06-01 20:58:05Z darkvela $
*/
if(!class_exists('Answer')):
class Answer
{
var $questionId;
@ -67,51 +48,48 @@ class Answer
function Answer($questionId)
{
//$this->questionType=$questionType;
$this->questionId=(int)$questionId;
$this->answer=array();
$this->correct=array();
$this->comment=array();
$this->weighting=array();
$this->position=array();
$this->hotspot_coordinates=array();
$this->hotspot_type=array();
$this->destination= array();
$this->questionId = (int)$questionId;
$this->answer = array();
$this->correct = array();
$this->comment = array();
$this->weighting = array();
$this->position = array();
$this->hotspot_coordinates = array();
$this->hotspot_type = array();
$this->destination = array();
// clears $new_* arrays
$this->cancel();
// fills arrays
$objExercise = new Exercise();
$objExercise->read($_REQUEST['exerciseId']);
if($objExercise->random_answers=='1')
{
$objExercise->read($_REQUEST['exerciseId']);
if($objExercise->random_answers=='1') {
$this->readOrderedBy('rand()', '');// randomize answers
}
else
{
} else {
$this->read(); // natural order
}
}
/**
* clears $new_* arrays
* Clears $new_* arrays
*
* @author - Olivier Brouckaert
*/
function cancel()
{
$this->new_answer=array();
$this->new_correct=array();
$this->new_comment=array();
$this->new_weighting=array();
$this->new_position=array();
$this->new_hotspot_coordinates=array();
$this->new_hotspot_type=array();
$this->new_nbrAnswers=0;
$this->new_destination=array();
$this->new_answer = array();
$this->new_correct = array();
$this->new_comment = array();
$this->new_weighting = array();
$this->new_position = array();
$this->new_hotspot_coordinates = array();
$this->new_hotspot_type = array();
$this->new_nbrAnswers = 0;
$this->new_destination = array();
}
/**
* reads answer informations from the data base
* Reads answer informations from the data base
*
* @author - Olivier Brouckaert
*/
@ -131,21 +109,19 @@ class Answer
$i=1;
// while a record is found
while($object=Database::fetch_object($result))
{
$this->id[$i]=$object->id;
$this->answer[$i]=$object->answer;
$this->correct[$i]=$object->correct;
$this->comment[$i]=$object->comment;
$this->weighting[$i]=$object->ponderation;
$this->position[$i]=$object->position;
$this->hotspot_coordinates[$i]=$object->hotspot_coordinates;
$this->hotspot_type[$i]=$object->hotspot_type;
$this->destination[$i]=$object->destination;
$this->autoId[$i]=$object->id_auto;
while($object=Database::fetch_object($result)) {
$this->id[$i] = $object->id;
$this->answer[$i] = $object->answer;
$this->correct[$i] = $object->correct;
$this->comment[$i] = $object->comment;
$this->weighting[$i] = $object->ponderation;
$this->position[$i] = $object->position;
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
$this->hotspot_type[$i] = $object->hotspot_type;
$this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto;
$i++;
}
$this->nbrAnswers=$i-1;
}
/**
@ -158,8 +134,7 @@ class Answer
{
global $_course;
$field = Database::escape_string($field);
if(empty($field))
{
if(empty($field)) {
$field = 'position';
}
if($order != 'ASC' and $order!='DESC')
@ -182,16 +157,15 @@ class Answer
// while a record is found
while($object=Database::fetch_object($result))
{
$this->answer[$i]=$object->answer;
$this->correct[$i]=$object->correct;
$this->comment[$i]=$object->comment;
$this->weighting[$i]=$object->ponderation;
$this->position[$i]=$object->position;
$this->destination[$i]=$object->destination;
$this->autoId[$i]=$object->id_auto;
$this->answer[$i] = $object->answer;
$this->correct[$i] = $object->correct;
$this->comment[$i] = $object->comment;
$this->weighting[$i] = $object->ponderation;
$this->position[$i] = $object->position;
$this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto;
$i++;
}
$this->nbrAnswers=$i-1;
}
@ -470,7 +444,7 @@ class Answer
}
/**
* records answers into the data base
* Records answers into the data base
*
* @author - Olivier Brouckaert
*/
@ -489,8 +463,7 @@ class Answer
"(id,question_id,answer,correct,comment," .
"ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES";
for($i=1;$i <= $this->new_nbrAnswers;$i++)
{
for($i=1;$i <= $this->new_nbrAnswers;$i++) {
$answer = Database::escape_string($this->new_answer[$i]);
$correct = Database::escape_string($this->new_correct[$i]);
$comment = Database::escape_string($this->new_comment[$i]);
@ -522,7 +495,7 @@ class Answer
}
/**
* duplicates answers by copying them into another question
* Duplicates answers by copying them into another question
*
* @author - Olivier Brouckaert
* @param - integer $newQuestionId - ID of the new question
@ -532,15 +505,13 @@ class Answer
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
// 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";
for($i=1;$i <= $this->nbrAnswers;$i++)
{
for($i=1;$i <= $this->nbrAnswers;$i++) {
$answer = Database::escape_string($this->answer[$i]);
$correct = Database::escape_string($this->correct[$i]);
$comment = Database::escape_string($this->comment[$i]);
@ -560,4 +531,4 @@ class Answer
}
endif;
?>
?>

@ -1,10 +1,9 @@
<?php // $Id: question.class.php 22257 2009-07-20 17:50:09Z juliomontoya $
/* For licensing terms, see /dokeos_license.txt */
/* For licensing terms, see /license.txt */
/**
* File containing the Question class.
* @package dokeos.exercise
* @package chamilo.exercise
* @author Olivier Brouckaert
* @version $Id: question.class.php 22257 2009-07-20 17:50:09Z juliomontoya $
*/
@ -13,24 +12,23 @@
if(!class_exists('Question')):
// answer types
define('UNIQUE_ANSWER', 1);
define('MULTIPLE_ANSWER', 2);
define('FILL_IN_BLANKS', 3);
define('MATCHING', 4);
define('FREE_ANSWER', 5);
define('HOT_SPOT', 6);
define('HOT_SPOT_ORDER', 7);
define('HOT_SPOT_DELINEATION', 8);
define('UNIQUE_ANSWER', 1);
define('MULTIPLE_ANSWER', 2);
define('FILL_IN_BLANKS', 3);
define('MATCHING', 4);
define('FREE_ANSWER', 5);
define('HOT_SPOT', 6);
define('HOT_SPOT_ORDER', 7);
define('HOT_SPOT_DELINEATION', 8);
define('MULTIPLE_ANSWER_COMBINATION', 9);
/**
CLASS QUESTION
QUESTION CLASS
*
* This class allows to instantiate an object of type Question
*
* @author Olivier Brouckaert, original author
* @author Patrick Cool, LaTeX support
* @package dokeos.exercise
*/
abstract class Question
{
@ -47,12 +45,12 @@ abstract class Question
static $typePicture = 'new_question.png';
static $explanationLangVar = '';
static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'),
UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'),
MULTIPLE_ANSWER => array('multiple_answer.class.php' , 'MultipleAnswer'),
FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'),
MATCHING => array('matching.class.php' , 'Matching'),
FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'),
HOT_SPOT => array('hotspot.class.php' , 'HotSpot'),
FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'),
MATCHING => array('matching.class.php' , 'Matching'),
FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'),
HOT_SPOT => array('hotspot.class.php' , 'HotSpot'),
MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php' , 'MultipleAnswerCombination'),
);
@ -73,7 +71,7 @@ abstract class Question
}
/**
* reads question informations from the data base
* Reads question informations from the data base
*
* @author - Olivier Brouckaert
* @param - integer $id - question ID
@ -94,22 +92,21 @@ abstract class Question
// if the question has been found
if($object=Database::fetch_object($result))
{
$objQuestion = Question::getInstance($object->type);
$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 = Question::getInstance($object->type);
$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;
$sql="SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE question_id='".intval($id)."'";
$result=Database::query($sql);
// fills the array with the exercises which this question is in
while($object=Database::fetch_object($result))
{
while($object=Database::fetch_object($result)) {
$objQuestion->exerciseList[]=$object->exercice_id;
}
@ -518,9 +515,18 @@ abstract class Question
// saves the picture into a temporary file
@move_uploaded_file($Picture,$picturePath.'/tmp.'.$Extension);
}
/**
Sets the title
*/
public function setTitle($title)
{
$this->question = $title;
}
/**
* moves the temporary question "tmp" to "quiz-$questionId"
* Moves the temporary question "tmp" to "quiz-$questionId"
* Temporary pictures are used when we don't want to save a picture right after a form submission.
* For example, if we first show a confirmation box.
*
@ -603,7 +609,8 @@ abstract class Question
}
}
} else {// creates a new question
} else {
// creates a new question
$sql="SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question WHERE question.id=test_question.question_id AND test_question.exercice_id='".Database::escape_string($exerciseId)."'";
$result=Database::query($sql);
$current_position=Database::result($result,0,0);
@ -886,7 +893,7 @@ abstract class Question
}
/**
* duplicates the question
* Duplicates the question
*
* @author - Olivier Brouckaert
* @return - integer - ID of the new question
@ -1150,8 +1157,7 @@ abstract class Question
static function updateId()
{
return self::$questionTypes;
}
}
}
endif;
?>
?>
Loading…
Cancel
Save