Minor - fixing format code

1.9.x
Julio Montoya 12 years ago
parent 837d3e5107
commit 93dfcfa961
  1. 7
      main/exercice/admin.php
  2. 133
      main/exercice/answer.class.php
  3. 77
      main/exercice/fill_blanks.class.php

@ -303,7 +303,10 @@ function multiple_answer_true_false_onchange(variable) {
var result = variable.checked;
var id = variable.id;
var weight_id = "weighting_" + id;
var array_result=new Array(); array_result[1]="1"; array_result[0]= "-0.50"; array_result[-1]= "0";
var array_result=new Array();
array_result[1]="1";
array_result[0]= "-0.50";
array_result[-1]= "0";
if (result) {
result = 1;
} else {
@ -513,4 +516,4 @@ if (!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspot
Session::write('objExercise', $objExercise);
Session::write('objQuestion', $objQuestion);
Session::write('objAnswer', $objAnswer);
Display::display_footer();
Display::display_footer();

@ -49,7 +49,7 @@ class Answer {
* @param integer Question ID that answers belong to
*/
function Answer($questionId, $course_id = null) {
$this->questionId = intval($questionId);
$this->answer = array();
$this->correct = array();
@ -61,19 +61,19 @@ class Answer {
$this->destination = array();
// clears $new_* arrays
$this->cancel();
if (!empty($course_id)) {
if (!empty($course_id)) {
$course_info = api_get_course_info_by_id($course_id);
} else {
} else {
$course_info = api_get_course_info();
}
$this->course = $course_info;
$this->course_id = $course_info['real_id'];
$this->course_id = $course_info['real_id'];
// fills arrays
$objExercise = new Exercise($this->course_id);
$objExercise->read($_REQUEST['exerciseId']);
$objExercise->read($_REQUEST['exerciseId']);
if ($objExercise->random_answers=='1') {
$this->readOrderedBy('rand()', '');// randomize answers
} else {
@ -103,10 +103,10 @@ class Answer {
*
* @author - Olivier Brouckaert
*/
function read() {
function read() {
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = $this->questionId;
$sql="SELECT id, id_auto, answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM
$TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position";
@ -119,7 +119,7 @@ class Answer {
$this->answer[$i] = $object->answer;
$this->correct[$i] = $object->correct;
$this->comment[$i] = $object->comment;
$this->weighting[$i] = $object->ponderation;
$this->weighting[$i] = $object->ponderation;
$this->position[$i] = $object->position;
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
$this->hotspot_type[$i] = $object->hotspot_type;
@ -135,30 +135,30 @@ class Answer {
* @param string DESC or ASC
* @author Frederic Vauthier
*/
function readOrderedBy($field, $order='ASC') {
function readOrderedBy($field, $order='ASC') {
$field = Database::escape_string($field);
if (empty($field)) {
$field = 'position';
}
if ($order != 'ASC' && $order!='DESC') {
$order = 'ASC';
}
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
$questionId=intval($this->questionId);
$sql = "SELECT type FROM $TBL_QUIZ WHERE c_id = {$this->course_id} AND id = $questionId";
$result_question=Database::query($sql);
$question_type=Database::fetch_array($result_question);
$sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " .
"FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id='".$questionId."' " .
"ORDER BY $field $order";
$result=Database::query($sql);
"ORDER BY $field $order";
$result=Database::query($sql);
$i=1;
// while a record is found
$doubt_data = null;
@ -175,9 +175,9 @@ class Answer {
$this->destination[$i] = $object->destination;
$this->autoId[$i] = $object->id_auto;
$i++;
}
if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
}
if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
$this->answer[$i] = $doubt_data->answer;
$this->correct[$i] = $doubt_data->correct;
$this->comment[$i] = $doubt_data->comment;
@ -185,7 +185,7 @@ class Answer {
$this->position[$i] = $doubt_data->position;
$this->destination[$i] = $doubt_data->destination;
$this->autoId[$i] = $doubt_data->id_auto;
$i++;
$i++;
}
$this->nbrAnswers=$i-1;
}
@ -246,8 +246,8 @@ 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);
$auto_id = intval($auto_id);
$sql="SELECT id, answer FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND id_auto='$auto_id'";
$rs = Database::query($sql);
@ -283,13 +283,13 @@ class Answer {
$list = array();
for($i = 1; $i<=$this->nbrAnswers;$i++){
if(!empty($this->answer[$i])){
//Avoid problems when parsing elements with accents
if ($decode) {
$this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
$this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
}
$list[] = array(
'id' => $i,
'answer' => $this->answer[$i],
@ -420,7 +420,8 @@ class Answer {
* @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, $destination='') {
function createAnswer($answer,$correct,$comment,$weighting, $position, $new_hotspot_coordinates = null, $new_hotspot_type = null, $destination='')
{
$this->new_nbrAnswers++;
$id=$this->new_nbrAnswers;
$this->new_answer[$id]=$answer;
@ -442,16 +443,17 @@ class Answer {
* @param integer Answer weighting
* @param integer Answer position
*/
function updateAnswers($answer,$comment, $correct, $weighting,$position,$destination) {
function updateAnswers($answer,$comment, $correct, $weighting, $position, $destination)
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$questionId=$this->questionId;
$sql = "UPDATE $TBL_REPONSES SET
$sql = "UPDATE $TBL_REPONSES SET
answer = '".Database::escape_string($answer)."',
comment = '".Database::escape_string($comment)."',
correct = '".Database::escape_string($correct)."',
ponderation = '".Database::escape_string($weighting)."',
position = '".Database::escape_string($position)."',
correct = '".Database::escape_string($correct)."',
ponderation = '".Database::escape_string($weighting)."',
position = '".Database::escape_string($position)."',
destination = '".Database::escape_string($destination)."'
WHERE c_id = {$this->course_id} AND id = '".Database::escape_string($position)."'
AND question_id = '".Database::escape_string($questionId)."'";
@ -463,17 +465,17 @@ class Answer {
*
* @author - Olivier Brouckaert
*/
function save() {
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
function save()
{
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = intval($this->questionId);
$c_id = $this->course['real_id'];
// inserts new answers into data base
$flag = 0;
$sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates,hotspot_type, destination) VALUES ";
$sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination) VALUES ";
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]);
@ -482,17 +484,26 @@ class Answer {
$hotspot_coordinates = Database::escape_string($this->new_hotspot_coordinates[$i]);
$hotspot_type = Database::escape_string($this->new_hotspot_type[$i]);
$destination = Database::escape_string($this->new_destination[$i]);
if (!(isset($this->position[$i]))) {
$flag = 1;
$sql.="($c_id, '$i','$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),";
} else {
// https://support.chamilo.org/issues/6558
// function updateAnswers already escape_string, error if we do it twice. Feed function updateAnswers with none escaped strings
$this->updateAnswers($this->new_answer[$i], $this->new_comment[$i], $this->new_correct[$i], $this->new_weighting[$i], $this->new_position[$i], $this->new_destination[$i]);
$this->updateAnswers(
$this->new_answer[$i],
$this->new_comment[$i],
$this->new_correct[$i],
$this->new_weighting[$i],
$this->new_position[$i],
$this->new_destination[$i]
);
}
}
if ($flag == 1) {
$sql = api_substr($sql,0,-1);
$sql = api_substr($sql,0,-1);
Database::query($sql);
}
if (count($this->position) > $this->new_nbrAnswers) {
@ -503,7 +514,7 @@ class Answer {
Database::query($sql);
$i++;
}
}
// moves $new_* arrays
@ -518,7 +529,7 @@ class Answer {
$this->nbrAnswers=$this->new_nbrAnswers;
$this->destination=$this->new_destination;
// clears $new_* arrays
$this->cancel();
}
/**
@ -526,38 +537,38 @@ class Answer {
*
* @author Olivier Brouckaert
* @param int question id
* @param array destination course info (result of the function api_get_course_info() )
* @param array destination course info (result of the function api_get_course_info() )
*/
function duplicate($newQuestionId, $course_info = null) {
function duplicate($newQuestionId, $course_info = null) {
if (empty($course_info)) {
$course_info = $this->course;
} else {
$course_info = $course_info;
}
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
//Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']);
if (!empty($origin_options)) {
foreach($origin_options as $item) {
$new_option_list[]=$item['id'];
}
}
$destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
$i=0;
$fixed_list = array();
if (!empty($destination_options)) {
foreach($destination_options as $item) {
foreach($destination_options as $item) {
$fixed_list[$new_option_list[$i]] = $item['id'];
$i++;
}
}
}
}
// if at least one answer
@ -565,20 +576,20 @@ class Answer {
// inserts new answers into data base
$sql = "INSERT INTO $TBL_REPONSES (c_id, id,question_id,answer,correct,comment, ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES";
$c_id = $course_info['real_id'];
for ($i=1;$i <= $this->nbrAnswers;$i++) {
if ($this->course['id'] != $course_info['id']) {
if ($this->course['id'] != $course_info['id']) {
$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']) ;
$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 || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ) {
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ) {
$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]);
@ -593,4 +604,4 @@ class Answer {
}
}
}
endif;
endif;

@ -11,8 +11,6 @@
* Code
*/
if(!class_exists('FillBlanks')):
/**
CLASS FillBlanks
*
@ -45,7 +43,7 @@ class FillBlanks extends Question
*/
function createAnswersForm ($form) {
$defaults = array();
if (!empty($this->id)) {
$objAnswer = new answer($this->id);
@ -60,13 +58,15 @@ class FillBlanks extends Question
//make sure we only take the last bit to find special marks
$sz = count($pre_array);
$is_set_switchable = explode('@', $pre_array[$sz-1]);
if ($is_set_switchable[1]) {
$defaults['multiple_answer']=1;
$defaults['multiple_answer'] = 1;
} else {
$defaults['multiple_answer']=0;
$defaults['multiple_answer'] = 0;
}
//take the complete string except after the last '::'
//Take the complete string except after the last '::'
$defaults['answer'] = '';
for ($i=0;$i<($sz-1);$i++) {
$defaults['answer'] .= $pre_array[$i];
@ -77,21 +77,21 @@ class FillBlanks extends Question
}
// javascript
echo '<script type="text/javascript">
function FCKeditor_OnComplete( editorInstance ) {
if (window.attachEvent) {
echo '<script>
function FCKeditor_OnComplete( editorInstance ) {
if (window.attachEvent) {
editorInstance.EditorDocument.attachEvent("onkeyup", updateBlanks) ;
} else {
} else {
editorInstance.EditorDocument.addEventListener("keyup",updateBlanks,true);
}
}
}
var firstTime = true;
function updateBlanks() {
function updateBlanks() {
if (firstTime) {
field = document.getElementById("answer");
var answer = field.value;
var answer = field.value;
} else {
var oEditor = FCKeditorAPI.GetInstance(\'answer\');
answer = oEditor.GetXHTML( true ) ;
@ -99,7 +99,7 @@ class FillBlanks extends Question
var blanks = answer.match(/\[[^\]]*\]/g);
var fields = "<div class=\"control-group\"><label class=\"control-label\">'.get_lang('Weighting').'</label><div class=\"controls\"><table>";
if (blanks!=null) {
for (i=0 ; i<blanks.length ; i++){
if (document.getElementById("weighting["+i+"]"))
@ -114,8 +114,9 @@ class FillBlanks extends Question
if (firstTime) {
firstTime = false;
';
if (count($a_weightings)>0) {
foreach($a_weightings as $i=>$weighting) {
if (count($a_weightings) > 0) {
foreach($a_weightings as $i => $weighting) {
echo 'document.getElementById("weighting['.$i.']").value = "'.$weighting.'";';
}
}
@ -139,12 +140,12 @@ class FillBlanks extends Question
global $text, $class;
// setting the save button here and not in the question class.php
$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
if (!empty($this -> id)) {
$form -> setDefaults($defaults);
} else {
if ($this -> isContent == 1) {
$form -> setDefaults($defaults);
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
}
@ -157,8 +158,7 @@ class FillBlanks extends Question
function processAnswersCreation($form)
{
global $charset;
$answer = $form -> getSubmitValue('answer');
$answer = $form->getSubmitValue('answer');
//Due the fckeditor transform the elements to their HTML value
$answer = api_html_entity_decode($answer, ENT_QUOTES, $charset);
@ -167,37 +167,36 @@ class FillBlanks extends Question
// get the blanks weightings
$nb = preg_match_all('/\[[^\]]*\]/', $answer, $blanks);
if(isset($_GET['editQuestion']))
{
if (isset($_GET['editQuestion'])) {
$this -> weighting = 0;
}
if($nb>0)
{
if ($nb>0) {
$answer .= '::';
for($i=0 ; $i<$nb ; ++$i)
{
$answer .= $form -> getSubmitValue('weighting['.$i.']').',';
$this -> weighting += $form -> getSubmitValue('weighting['.$i.']');
for($i=0 ; $i<$nb ; ++$i) {
$answer .= $form->getSubmitValue('weighting['.$i.']').',';
$this -> weighting += $form->getSubmitValue('weighting['.$i.']');
}
$answer = api_substr($answer,0,-1);
}
$is_multiple = $form -> getSubmitValue('multiple_answer');
$is_multiple = $form->getSubmitValue('multiple_answer');
$answer.='@'.$is_multiple;
$this -> save();
$this->save();
$objAnswer = new answer($this->id);
$objAnswer->createAnswer($answer,0,'',0,'');
$objAnswer->createAnswer($answer, 0, '', 0, '');
$objAnswer->save();
}
function return_header($feedback_type = null, $counter = null, $score = null) {
function return_header($feedback_type = null, $counter = null, $score = null)
{
$header = parent::return_header($feedback_type, $counter, $score);
$header .= '<table class="'.$this->question_table_class .'">
$header .= '<table class="'.$this->question_table_class .'">
<tr>
<th>'.get_lang("Answer").'</th>
</tr>';
return $header;
return $header;
}
}
endif;
Loading…
Cancel
Save