Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent ff8070f853
commit 68dc01e348
  1. 13
      main/exercice/exercise_result.php
  2. 47
      main/exercice/exercise_show.php
  3. 188
      main/exercice/exercise_submit.php

@ -13,9 +13,6 @@
*
* @todo split more code up in functions, move functions to library?
*/
/**
* Code
*/
use \ChamiloSession as Session;
@ -103,15 +100,15 @@ if (api_is_course_admin() && $origin != 'learnpath') {
echo '</div>';
}
$feedback_type = $objExercise->feedback_type;
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$feedback_type = $objExercise->feedback_type;
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
if (!empty($exercise_stat_info['data_tracking'])) {
$question_list = explode(',', $exercise_stat_info['data_tracking']);
}
$learnpath_id = $exercise_stat_info['orig_lp_id'];
$learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
$learnpath_id = $exercise_stat_info['orig_lp_id'];
$learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
$learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
if ($origin == 'learnpath') {
@ -179,7 +176,7 @@ if ($origin != 'learnpath') {
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 type="text/javascript">'.$href.'</script>';
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($action)) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;}
$id = intval($_REQUEST['id']); //exe id
if (empty($id)) {
@ -216,19 +215,23 @@ $arrques = array();
$arrans = array();
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
$query = "SELECT attempts.question_id, answer 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
ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
AND 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
ON 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
GROUP BY quizz_rel_questions.question_order, attempts.question_id";
$result = Database::query($query);
$sql = "SELECT attempts.question_id, answer
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
ON
quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND
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
ON
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
GROUP BY quizz_rel_questions.question_order, attempts.question_id";
$result = Database::query($sql);
$question_list_from_database = array();
$exerciseResult = array();
@ -242,11 +245,11 @@ while ($row = Database::fetch_array($result)) {
if (!empty($track_exercise_info['data_tracking'])) {
$temp_question_list = explode(',', $track_exercise_info['data_tracking']);
//Getting question list from data_tracking
// Getting question list from data_tracking
if (!empty($temp_question_list)) {
$questionList = $temp_question_list;
}
//If for some reason data_tracking is empty we select the question list from db
// If for some reason data_tracking is empty we select the question list from db
if (empty($questionList)) {
$questionList = $question_list_from_database;
}
@ -267,10 +270,9 @@ foreach ($questionList as $questionId) {
$objQuestionTmp = Question::read($questionId);
$total_weighting +=$objQuestionTmp->selectWeighting();
}
$counter = 1;
$counter = 1;
$exercise_content = null;
$category_list = array();
foreach ($questionList as $questionId) {
@ -626,7 +628,6 @@ foreach ($questionList as $questionId) {
$exercise_content .= $question_content;
} // end of large foreach on questions
$total_score_text = null;
//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)) {
//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);
}
@ -712,7 +715,7 @@ if ($origin != 'learnpath') {
}
}
//destroying the session
// Destroying the session
Session::erase('questionList');
unset ($questionList);

@ -24,9 +24,6 @@
* Adding reminder + ajax support (2011)
* Modified by hubert.borderiou (2011-10-21 question category)
*/
/**
* Code
*/
use \ChamiloSession as Session;
@ -43,7 +40,10 @@ require_once 'exercise.lib.php';
$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.
api_protect_course_script(true);
@ -51,8 +51,8 @@ api_protect_course_script(true);
$is_allowedToEdit = api_is_allowed_to_edit(null,true);
if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
$htmlHeadXtra[] = api_get_js('glossary.js'); //Glossary
$htmlHeadXtra[] = api_get_js('jquery.highlight.js'); //highlight
$htmlHeadXtra[] = api_get_js('glossary.js');
$htmlHeadXtra[] = api_get_js('jquery.highlight.js');
}
//This library is necessary for the time control feature
@ -64,14 +64,14 @@ $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
// General parameters passed via POST/GET
$learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0;
$learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0;
$learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0;
$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
$exerciseResult = isset($_REQUEST['exerciseResult']) ? $_REQUEST['exerciseResult'] : null;
@ -90,7 +90,9 @@ $error = '';
//Table calls
$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 ) {
Session::erase('objExercise');
}
@ -104,13 +106,15 @@ if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUES
unset($_SESSION['questionList']);
// 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'); };
unset ($objExercise);
$error = get_lang('ExerciseNotFound');
} else {
// Saves the object into the session
Session::write('objExercise',$objExercise);
Session::write('objExercise', $objExercise);
if ($debug) {error_log('1.1. $_SESSION[objExercise] was unset - set now - end'); };
}
}
@ -128,8 +132,7 @@ if (!is_object($objExercise)) {
exit;
}
//if reminder ends we jump to the exercise_reminder
// If reminder ends we jump to the exercise_reminder
if ($objExercise->review_answers) {
if ($remind_question_id == -1) {
header('Location: exercise_reminder.php?origin='.$origin.'&exerciseId='.$exerciseId);
@ -137,8 +140,8 @@ if ($objExercise->review_answers) {
}
}
$current_timestamp = time();
$my_remind_list = array();
$current_timestamp = time();
$my_remind_list = array();
$time_control = false;
if ($objExercise->expired_time != 0) {
@ -159,7 +162,13 @@ $show_clock = true;
$user_id = api_get_user_id();
if ($objExercise->selectAttempts() > 0) {
$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()) {
$show_clock = false;
@ -167,8 +176,13 @@ if ($objExercise->selectAttempts() > 0) {
if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
//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());
// 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()
);
if (!empty($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);
$clock_expired_time = null;
if (empty($exercise_stat_info)) {
@ -242,15 +257,26 @@ if (empty($exercise_stat_info)) {
$_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] ); };
}
$exe_id = $objExercise->save_stat_track_exercise_info($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);
$exe_id = $objExercise->save_stat_track_exercise_info(
$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");
} else {
$exe_id = $exercise_stat_info['exe_id'];
if ($debug) error_log("5 exercise_stat_info[] exists getting exe_id $exe_id ");
}
//Array to check in order to block the chat
// Array to check in order to block the chat
create_chat_exercise_session($exe_id);
if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); };
@ -274,7 +300,6 @@ if ($reminder == 2 && empty($my_remind_list)) {
* 7. Loading Time control parameters
* If the expired time is major that zero(0) then the expired time is compute on this time.
*/
if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled');
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'); };
$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); }
//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']);
//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)) {
$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);
@ -311,13 +338,14 @@ if ($time_control) {
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
// 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
tms = '".api_get_utc_datetime()."'
WHERE
exe_id = '".$exercise_stat_info['exe_id']."' AND
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);
//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)); }
}
// the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult', $exerciseResult);
Session::write('remind_list', $remind_list);
@ -502,8 +529,7 @@ if ($formSent && isset($_POST)) {
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) {
$current_question = 1;
@ -513,7 +539,9 @@ if (!$current_question || $_REQUEST['num']) {
}
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()) {
// goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) {
@ -628,9 +656,9 @@ if ($is_visible_return['value'] == false) {
$limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time();
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time();
if ($objExercise->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
@ -662,9 +690,17 @@ if ($limit_time_exists) {
// Blocking empty start times see BT#2800
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') {
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') {
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>';
}
if (!empty($objExercise->description)) {
echo "<script>
$(function() {
@ -718,7 +753,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1;
} 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
}
break 2;
@ -730,7 +766,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1; // last question
} 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
}
break 2;
@ -745,7 +782,6 @@ if ($reminder == 2) {
exit;
}
}
//var_dump($remind_question_id, $my_remind_list, $data_tracking, $current_question);
}
if ($objExercise->review_answers) {
@ -981,7 +1017,7 @@ if (!empty($error)) {
<input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id . '" />
<input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id . '" />';
//Show list of questions
// Show list of questions
$i = 1;
$attempt_list = array();
@ -1040,32 +1076,44 @@ if (!empty($error)) {
$remind_highlight = ' remind_highlight ';
}
//Showing the question
// Showing the question
echo '<div id="question_div_'.$questionId.'" class="main_question '.$remind_highlight.'" >';
// Shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
//BUtton save and continue
switch ($objExercise->type) {
case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question);
break;
case ALL_ON_ONE_PAGE :
$button = '<a href="javascript://" class="btn" onclick="save_now(\''.$questionId.'\'); ">'.get_lang('SaveForNow').'</a>';
$button .= '<span id="save_for_now_'.$questionId.'"></span>&nbsp;';
$exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
break;
}
// Shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
// Button save and continue
switch ($objExercise->type) {
case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question);
break;
case ALL_ON_ONE_PAGE :
$button = '<a href="javascript://" class="btn" onclick="save_now(\''.$questionId.'\'); ">'.get_lang('SaveForNow').'</a>';
$button .= '<span id="save_for_now_'.$questionId.'"></span>&nbsp;';
$exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
break;
}
//Checkbox 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.']'));
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
}
echo Display::div($exercise_actions, array('class'=>'form-actions'));
echo '</div>';
// Checkbox 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 . ']'
)
);
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
}
echo Display::div($exercise_actions, array('class'=>'form-actions'));
echo '</div>';
$i++;
// for sequential exercises
@ -1083,7 +1131,7 @@ if (!empty($error)) {
}
if ($origin != 'learnpath') {
//so we are not in learnpath tool
// So we are not in learnpath tool
echo '</div>'; //End glossary div
Display :: display_footer();
} else {

Loading…
Cancel
Save