Source for file answer.class.php
Documentation is available at answer.class.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.
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
* 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
* @author Olivier Brouckaert
* @version $Id: answer.class.php 13732 2007-11-21 15:19:33Z yannoo $
// these arrays are used to save temporarily new answers
// then they are moved into the arrays above or deleted in the event of cancellation
* constructor of the class
* @author Olivier Brouckaert
* @param integer Question ID that answers belong to
$this->questionType= $questionType;
* @author - Olivier Brouckaert
* reads answer informations from the data base
* @author - Olivier Brouckaert
//$answerType=$this->selectType();
$sql= "SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type FROM $TBL_ANSWER WHERE question_id='$questionId' ORDER BY position";
// while a record is found
$this->answer[$i]= $object->answer;
$this->correct[$i]= $object->correct;
$this->comment[$i]= $object->comment;
* reads answer informations from the data base ordered by parameter
* @param string Field we want to order by
* @param string DESC or ASC
* @author Frederic Vauthier
if($order != 'ASC' and $order!= 'DESC'){
//$answerType=$this->selectType();
$sql= "SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type " .
"WHERE question_id='$questionId' " .
"ORDER BY $field $order";
// while a record is found
$this->answer[$i]= $object->answer;
$this->correct[$i]= $object->correct;
$this->comment[$i]= $object->comment;
* returns the number of answers in this question
* @author - Olivier Brouckaert
* @return - integer - number of answers
* returns the question ID which the answers belong to
* @author - Olivier Brouckaert
* @return - integer - the question ID
* returns the answer title
* @author - Olivier Brouckaert
* @param - integer $id - answer ID
* @return - string - answer title
* Returns a list of answers
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting
if(!empty($this->answer[$i])){
* Returns a list of grades
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of grades where grade=weighting (?)
if(!empty($this->answer[$i])){
* Returns the question type
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return integer The type of the question this answer is bound to
$sql = "SELECT * FROM $TBL_QUESTIONS WHERE id = '". $this->questionId. "'";
* tells if answer is correct or not
* @author - Olivier Brouckaert
* @param - integer $id - answer ID
* @return - integer - 0 if bad answer, not 0 if good answer
* @author - Olivier Brouckaert
* @param - integer $id - answer ID
* @return - string - answer comment
* returns answer weighting
* @author - Olivier Brouckaert
* @param - integer $id - answer ID
* @return - integer - answer weighting
* returns answer position
* @author - Olivier Brouckaert
* @param - integer $id - answer ID
* @return - integer - answer position
* returns answer hotspot coordinates
* @author Olivier Brouckaert
* @param integer Answer ID
* @return integer Answer position
* returns answer hotspot type
* @param integer Answer ID
* @return integer Answer position
* @author Olivier Brouckaert
* @param string answer title
* @param integer 0 if bad answer, not 0 if good answer
* @param string answer comment
* @param integer answer weighting
* @param integer answer position
* @param coordinates Coordinates for hotspot exercises (optional)
* @param integer Type for hotspot exercises (optional)
function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = NULL, $new_hotspot_type = NULL)
* @param string Answer title
* @param string Answer comment
* @param integer Answer weighting
* @param integer Answer position
$sql = "UPDATE $TBL_REPONSES SET " .
"`answer` = '$answer', " .
"`comment` = '$comment', " .
"`ponderation` = '$weighting', " .
"`position` = '$position' " .
"WHERE `id` =$position " .
"AND `question_id` =$questionId";
* records answers into the data base
* @author - Olivier Brouckaert
// removes old answers before inserting of new ones
$sql= "DELETE FROM $TBL_REPONSES WHERE question_id='$questionId'";
// inserts new answers into data base
$sql= "INSERT INTO $TBL_REPONSES" .
"(id,question_id,answer,correct,comment," .
"ponderation,position,hotspot_coordinates,hotspot_type) VALUES";
$sql.= "('$i','$questionId','$answer','$correct','$comment',
'$weighting','$position','$hotspot_coordinates','$hotspot_type'),";
* duplicates answers by copying them into another question
* @author - Olivier Brouckaert
* @param - integer $newQuestionId - ID of the new question
// if at least one answer
// inserts new answers into data base
$sql= "INSERT INTO $TBL_REPONSES" .
"(id,question_id,answer,correct,comment," .
"ponderation,position,hotspot_coordinates,hotspot_type) VALUES";
$sql.= "('$i','$newQuestionId','$answer','$correct','$comment'," .
"'$weighting','$position','$hotspot_coordinates','$hotspot_type'),";
|