Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent ff8070f853
commit 68dc01e348
  1. 5
      main/exercice/exercise_result.php
  2. 33
      main/exercice/exercise_show.php
  3. 116
      main/exercice/exercise_submit.php

@ -13,9 +13,6 @@
* *
* @todo split more code up in functions, move functions to library? * @todo split more code up in functions, move functions to library?
*/ */
/**
* Code
*/
use \ChamiloSession as Session; use \ChamiloSession as Session;
@ -179,7 +176,7 @@ if ($origin != 'learnpath') {
Session::erase('exe_id'); Session::erase('exe_id');
} }
//record the results in the learning path, using the SCORM interface (API) // Record the results in the learning path, using the SCORM interface (API)
echo "<script>window.parent.API.void_save_asset('$total_score', '$total_weight', 0, 'completed');</script>"; echo "<script>window.parent.API.void_save_asset('$total_score', '$total_weight', 0, 'completed');</script>";
echo '<script type="text/javascript">'.$href.'</script>'; echo '<script type="text/javascript">'.$href.'</script>';
echo '</body></html>'; echo '</body></html>';

@ -56,7 +56,6 @@ if (empty($objExercise)) { $objExercise = isset($_SESSION['objExercis
if (empty($exeId)) { $exeId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;} if (empty($exeId)) { $exeId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;}
if (empty($action)) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;} if (empty($action)) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;}
$id = intval($_REQUEST['id']); //exe id $id = intval($_REQUEST['id']); //exe id
if (empty($id)) { if (empty($id)) {
@ -216,19 +215,23 @@ $arrques = array();
$arrans = array(); $arrans = array();
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." "; $user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
$query = "SELECT attempts.question_id, answer FROM ".$TBL_TRACK_ATTEMPT." as attempts $sql = "SELECT attempts.question_id, answer
INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id FROM ".$TBL_TRACK_ATTEMPT." as attempts
INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices
ON stats_exercices.exe_id=attempts.exe_id
INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions
ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id ON
AND quizz_rel_questions.question_id = attempts.question_id quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND
AND quizz_rel_questions.c_id=".api_get_course_int_id()." quizz_rel_questions.question_id = attempts.question_id AND
quizz_rel_questions.c_id=".api_get_course_int_id()."
INNER JOIN ".$TBL_QUESTIONS." AS questions INNER JOIN ".$TBL_QUESTIONS." AS questions
ON questions.id=quizz_rel_questions.question_id ON
AND questions.c_id = ".api_get_course_int_id()." questions.id=quizz_rel_questions.question_id AND
questions.c_id = ".api_get_course_int_id()."
WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
GROUP BY quizz_rel_questions.question_order, attempts.question_id"; GROUP BY quizz_rel_questions.question_order, attempts.question_id";
$result = Database::query($query); $result = Database::query($sql);
$question_list_from_database = array(); $question_list_from_database = array();
$exerciseResult = array(); $exerciseResult = array();
@ -267,10 +270,9 @@ foreach ($questionList as $questionId) {
$objQuestionTmp = Question::read($questionId); $objQuestionTmp = Question::read($questionId);
$total_weighting +=$objQuestionTmp->selectWeighting(); $total_weighting +=$objQuestionTmp->selectWeighting();
} }
$counter = 1;
$counter = 1;
$exercise_content = null; $exercise_content = null;
$category_list = array(); $category_list = array();
foreach ($questionList as $questionId) { foreach ($questionList as $questionId) {
@ -626,7 +628,6 @@ foreach ($questionList as $questionId) {
$exercise_content .= $question_content; $exercise_content .= $question_content;
} // end of large foreach on questions } // end of large foreach on questions
$total_score_text = null; $total_score_text = null;
//Total score //Total score
@ -644,8 +645,10 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
if (!empty($category_list) && ($show_results || $show_only_total_score)) { if (!empty($category_list) && ($show_results || $show_only_total_score)) {
//Adding total //Adding total
$category_list['total'] = array('score' => $my_total_score_temp, 'total' => $totalWeighting); $category_list['total'] = array(
'score' => $my_total_score_temp,
'total' => $totalWeighting
);
echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list); echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
} }
@ -712,7 +715,7 @@ if ($origin != 'learnpath') {
} }
} }
//destroying the session // Destroying the session
Session::erase('questionList'); Session::erase('questionList');
unset ($questionList); unset ($questionList);

@ -24,9 +24,6 @@
* Adding reminder + ajax support (2011) * Adding reminder + ajax support (2011)
* Modified by hubert.borderiou (2011-10-21 question category) * Modified by hubert.borderiou (2011-10-21 question category)
*/ */
/**
* Code
*/
use \ChamiloSession as Session; use \ChamiloSession as Session;
@ -43,7 +40,10 @@ require_once 'exercise.lib.php';
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
if ($debug) { error_log('--- Enter to the exercise_submit.php ---- '); error_log('0. POST variables : '.print_r($_POST,1)); } if ($debug) {
error_log('--- Enter to the exercise_submit.php ---- ');
error_log('0. POST variables : ' . print_r($_POST, 1));
}
// Notice for unauthorized people. // Notice for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true);
@ -51,8 +51,8 @@ api_protect_course_script(true);
$is_allowedToEdit = api_is_allowed_to_edit(null,true); $is_allowedToEdit = api_is_allowed_to_edit(null,true);
if (api_get_setting('show_glossary_in_extra_tools') == 'true') { if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
$htmlHeadXtra[] = api_get_js('glossary.js'); //Glossary $htmlHeadXtra[] = api_get_js('glossary.js');
$htmlHeadXtra[] = api_get_js('jquery.highlight.js'); //highlight $htmlHeadXtra[] = api_get_js('jquery.highlight.js');
} }
//This library is necessary for the time control feature //This library is necessary for the time control feature
@ -90,7 +90,9 @@ $error = '';
//Table calls //Table calls
$exercice_attemp_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $exercice_attemp_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
/* Teacher takes an exam and want to see a preview, we delete the objExercise from the session in order to get the latest changes in the exercise */ /* Teacher takes an exam and want to see a preview,
we delete the objExercise from the session in order to get the latest
changes in the exercise */
if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['preview'] == 1 ) { if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['preview'] == 1 ) {
Session::erase('objExercise'); Session::erase('objExercise');
} }
@ -104,7 +106,9 @@ if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUES
unset($_SESSION['questionList']); unset($_SESSION['questionList']);
// if the specified exercise doesn't exist or is disabled // if the specified exercise doesn't exist or is disabled
if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) { if (!$objExercise->read($exerciseId) ||
(!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath')
) {
if ($debug) {error_log('1.1. Error while reading the exercise'); }; if ($debug) {error_log('1.1. Error while reading the exercise'); };
unset ($objExercise); unset ($objExercise);
$error = get_lang('ExerciseNotFound'); $error = get_lang('ExerciseNotFound');
@ -128,8 +132,7 @@ if (!is_object($objExercise)) {
exit; exit;
} }
// If reminder ends we jump to the exercise_reminder
//if reminder ends we jump to the exercise_reminder
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
if ($remind_question_id == -1) { if ($remind_question_id == -1) {
header('Location: exercise_reminder.php?origin='.$origin.'&exerciseId='.$exerciseId); header('Location: exercise_reminder.php?origin='.$origin.'&exerciseId='.$exerciseId);
@ -159,7 +162,13 @@ $show_clock = true;
$user_id = api_get_user_id(); $user_id = api_get_user_id();
if ($objExercise->selectAttempts() > 0) { if ($objExercise->selectAttempts() > 0) {
$attempt_html = ''; $attempt_html = '';
$attempt_count = get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $attempt_count = get_attempt_count(
$user_id,
$exerciseId,
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id
);
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
$show_clock = false; $show_clock = false;
@ -168,7 +177,12 @@ if ($objExercise->selectAttempts() > 0) {
if ($objExercise->results_disabled == 0 && $origin != 'learnpath') { if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
// Showing latest attempt according with task BT#1628 // Showing latest attempt according with task BT#1628
$exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id()); $exercise_stat_info = get_exercise_results_by_user(
$user_id,
$exerciseId,
api_get_course_id(),
api_get_session_id()
);
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
$max_exe_id = max(array_keys($exercise_stat_info)); $max_exe_id = max(array_keys($exercise_stat_info));
@ -213,11 +227,12 @@ if ($objExercise->selectAttempts() > 0) {
} }
} }
if ($debug) { error_log("4. Setting the exe_id: $exe_id");} ; if ($debug) {
error_log("4. Setting the exe_id: $exe_id");
}
// 5. Getting user exercise info (if the user took the exam before) - generating exe_id // 5. Getting user exercise info (if the user took the exam before) - generating exe_id
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
$clock_expired_time = null; $clock_expired_time = null;
if (empty($exercise_stat_info)) { if (empty($exercise_stat_info)) {
@ -242,8 +257,19 @@ if (empty($exercise_stat_info)) {
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
} }
$exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $questionList, $total_weight); $exe_id = $objExercise->save_stat_track_exercise_info(
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $clock_expired_time,
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id,
$questionList,
$total_weight
);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info(
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id
);
if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id"); if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
} else { } else {
$exe_id = $exercise_stat_info['exe_id']; $exe_id = $exercise_stat_info['exe_id'];
@ -274,7 +300,6 @@ if ($reminder == 2 && empty($my_remind_list)) {
* 7. Loading Time control parameters * 7. Loading Time control parameters
* If the expired time is major that zero(0) then the expired time is compute on this time. * If the expired time is major that zero(0) then the expired time is compute on this time.
*/ */
if ($time_control) { if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled'); if ($debug) error_log('7.1. Time control is enabled');
if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key); if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
@ -286,10 +311,12 @@ if ($time_control) {
if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
$expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
//Get the last attempt of an exercice // Get the last attempt of an exercise
$last_attempt_date = get_last_attempt_date_of_exercise($exercise_stat_info['exe_id']); $last_attempt_date = get_last_attempt_date_of_exercise($exercise_stat_info['exe_id']);
//This means that the user enters the exam but do not answer the first question we get the date from the track_e_exercises not from the track_et_attempt see #2069 /* This means that the user enters the exam but do not answer the
first question we get the date from the track_e_exercises not from
the track_et_attempt see #2069 */
if (empty($last_attempt_date)) { if (empty($last_attempt_date)) {
$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
@ -311,13 +338,14 @@ if ($time_control) {
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
// First we update the attempt to today // First we update the attempt to today
// How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so /* How the expired time is changed into "track_e_exercices" table,
then the last attempt for this student should be changed too */
$sql = "UPDATE $exercice_attemp_table SET $sql = "UPDATE $exercice_attemp_table SET
tms = '".api_get_utc_datetime()."' tms = '".api_get_utc_datetime()."'
WHERE WHERE
exe_id = '".$exercise_stat_info['exe_id']."' AND exe_id = '".$exercise_stat_info['exe_id']."' AND
tms = '".$last_attempt_date."' "; tms = '".$last_attempt_date."' ";
if ($debug) {error_log('7.10. $sql_track_e_exe2: '.$sql_track_e_exe); } if ($debug) {error_log('7.10. $sql: '.$sql); }
Database::query($sql); Database::query($sql);
//Sessions that contain the expired time //Sessions that contain the expired time
@ -437,7 +465,6 @@ if ($formSent && isset($_POST)) {
if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); } if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); }
} }
// the script "exercise_result.php" will take the variable $exerciseResult from the session // the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult', $exerciseResult); Session::write('exerciseResult', $exerciseResult);
Session::write('remind_list', $remind_list); Session::write('remind_list', $remind_list);
@ -502,8 +529,7 @@ if ($formSent && isset($_POST)) {
if ($debug) { error_log('9. $formSent was NOT sent'); } if ($debug) { error_log('9. $formSent was NOT sent'); }
} }
// if questionNum comes from POST and not from GET // If questionNum comes from POST and not from GET
if (!$current_question || $_REQUEST['num']) { if (!$current_question || $_REQUEST['num']) {
if (!$current_question) { if (!$current_question) {
$current_question = 1; $current_question = 1;
@ -513,7 +539,9 @@ if (!$current_question || $_REQUEST['num']) {
} }
if ($question_count != 0) { if ($question_count != 0) {
if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question > $question_count)) { if (($objExercise->type == ALL_ON_ONE_PAGE ||
$current_question > $question_count)
) {
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
@ -662,9 +690,17 @@ if ($limit_time_exists) {
// Blocking empty start times see BT#2800 // Blocking empty start times see BT#2800
global $_custom; global $_custom;
if (isset($_custom['exercises_hidden_when_no_start_date']) && $_custom['exercises_hidden_when_no_start_date']) { if (isset($_custom['exercises_hidden_when_no_start_date']) &&
$_custom['exercises_hidden_when_no_start_date']
) {
if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') { if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') {
Display :: display_warning_message(sprintf(get_lang('ExerciseNoStartedYet'), $exercise_title, $objExercise->selectAttempts())); Display:: display_warning_message(
sprintf(
get_lang('ExerciseNoStartedYet'),
$exercise_title,
$objExercise->selectAttempts()
)
);
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
Display :: display_footer(); Display :: display_footer();
} }
@ -677,7 +713,6 @@ if ($time_control) {
echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciceExpiredTimeMessage').'</div>'; echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciceExpiredTimeMessage').'</div>';
} }
if (!empty($objExercise->description)) { if (!empty($objExercise->description)) {
echo "<script> echo "<script>
$(function() { $(function() {
@ -718,7 +753,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1]; $remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1; $current_question = $i + 1;
} else { } else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please // We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1;
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
@ -730,7 +766,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1]; $remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} else { } else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please // We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1;
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
@ -745,7 +782,6 @@ if ($reminder == 2) {
exit; exit;
} }
} }
//var_dump($remind_question_id, $my_remind_list, $data_tracking, $current_question);
} }
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
@ -1047,7 +1083,7 @@ if (!empty($error)) {
// Shows the question and its answers // Shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false); showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
//BUtton save and continue // Button save and continue
switch ($objExercise->type) { switch ($objExercise->type) {
case ONE_PER_PAGE: case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question); $exercise_actions .= $objExercise->show_button($questionId, $current_question);
@ -1061,7 +1097,19 @@ if (!empty($error)) {
// Checkbox review answers // Checkbox review answers
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
$remind_question_div = Display::tag('label', Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes).get_lang('ReviewQuestionLater'), array('class' => 'checkbox', 'for' =>'remind_list['.$questionId.']')); $remind_question_div = Display::tag(
'label',
Display::input(
'checkbox',
'remind_list[' . $questionId . ']',
'',
$attributes
) . get_lang('ReviewQuestionLater'),
array(
'class' => 'checkbox',
'for' => 'remind_list[' . $questionId . ']'
)
);
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button')); $exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
} }
echo Display::div($exercise_actions, array('class'=>'form-actions')); echo Display::div($exercise_actions, array('class'=>'form-actions'));
@ -1083,7 +1131,7 @@ if (!empty($error)) {
} }
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
//so we are not in learnpath tool // So we are not in learnpath tool
echo '</div>'; //End glossary div echo '</div>'; //End glossary div
Display :: display_footer(); Display :: display_footer();
} else { } else {

Loading…
Cancel
Save