Internal: Refactor exercise list to use resources

pull/3466/head
Julio Montoya 4 years ago
parent 81664309ec
commit 26a1d264af
  1. 76
      public/main/exercise/exercise.class.php
  2. 4
      public/main/exercise/exercise_result.php
  3. 2
      public/main/exercise/overview.php
  4. 7
      public/main/exercise/result.php
  5. 6
      public/main/inc/lib/exercise.lib.php

@ -8566,8 +8566,10 @@ class Exercise
$session_img = null;
//$session_img = api_get_session_image($row['session_id'], $userInfo['status']);
$startTime = $exerciseEntity->getStartTime();
$endTime = $exerciseEntity->getEndTime();
$time_limits = false;
if (!empty($row['start_time']) || !empty($row['end_time'])) {
if (!empty($startTime) || !empty($endTime)) {
$time_limits = true;
}
@ -8575,15 +8577,14 @@ class Exercise
if ($time_limits) {
// check if start time
$start_time = false;
if (!empty($row['start_time'])) {
$start_time = api_strtotime($row['start_time'], 'UTC');
if (!empty($startTime)) {
$start_time = api_strtotime($startTime->format('Y-m-d H:i:s'), 'UTC');
}
$end_time = false;
if (!empty($row['end_time'])) {
$end_time = api_strtotime($row['end_time'], 'UTC');
if (!empty($endTime)) {
$end_time = api_strtotime($endTime->format('Y-m-d H:i:s'), 'UTC');
}
$now = time();
//If both "clocks" are enable
if ($start_time && $end_time) {
if ($now > $start_time && $end_time > $now) {
@ -8609,7 +8610,7 @@ class Exercise
if (isset($_custom['exercises_hidden_when_no_start_date']) &&
$_custom['exercises_hidden_when_no_start_date']
) {
if (empty($row['start_time'])) {
if (empty($startTime)) {
$time_limits = true;
$is_actived_time = false;
}
@ -8966,14 +8967,9 @@ class Exercise
$currentRow['count_questions'] = $number_of_questions;
} else {
// Student only.
$visibility = api_get_item_visibility(
$courseInfo,
TOOL_QUIZ,
$exerciseId,
$sessionId
);
$visibility = $exerciseEntity->isVisible($course, null);
if ($visibility == 0) {
if (false === $visibility) {
continue;
}
@ -8982,8 +8978,6 @@ class Exercise
// Link of the exercise.
$currentRow['title'] = $url.' '.$session_img;
// This query might be improved later on by ordering by the new "tms" field rather than by exe_id
// Don't remove this marker: note-query-exe-results
$sql = "SELECT * FROM $TBL_TRACK_EXERCISES
@ -9001,8 +8995,7 @@ class Exercise
$num = Database :: num_rows($qryres);
// Hide the results.
$my_result_disabled = $row['results_disabled'];
$my_result_disabled = $exerciseEntity->getResultsDisabled();
$attempt_text = '-';
// Time limits are on
if ($time_limits) {
@ -9023,14 +9016,14 @@ class Exercise
// More than one attempt
if ($num > 0) {
$row_track = Database :: fetch_array($qryres);
$attempt_text = get_lang('LatestAttempt').' : ';
$attempt_text = get_lang('Latest attempt').' : ';
$attempt_text .= ExerciseLib::show_score(
$row_track['exe_result'],
$row_track['exe_weighting']
);
} else {
//No attempts
$attempt_text = get_lang('NotAttempted');
$attempt_text = get_lang('Not attempted');
}
} else {
$attempt_text = '-';
@ -9038,37 +9031,34 @@ class Exercise
} else {
// Quiz not ready due to time limits
//@todo use the is_visible function
if (!empty($row['start_time']) && !empty($row['end_time'])) {
if (!empty($startTime) && !empty($endTime)) {
$today = time();
$start_time = api_strtotime($row['start_time'], 'UTC');
$end_time = api_strtotime($row['end_time'], 'UTC');
if ($today < $start_time) {
$attempt_text = sprintf(
get_lang('ExerciseWillBeActivatedFromXToY'),
api_convert_and_format_date($row['start_time']),
api_convert_and_format_date($row['end_time'])
api_convert_and_format_date($start_time),
api_convert_and_format_date($end_time)
);
} else {
if ($today > $end_time) {
$attempt_text = sprintf(
get_lang('ExerciseWasActivatedFromXToY'),
api_convert_and_format_date($row['start_time']),
api_convert_and_format_date($row['end_time'])
api_convert_and_format_date($start_time),
api_convert_and_format_date($end_time)
);
}
}
} else {
//$attempt_text = get_lang('ExamNotAvailableAtThisTime');
if (!empty($row['start_time'])) {
if (!empty($startTime)) {
$attempt_text = sprintf(
get_lang('ExerciseAvailableFromX'),
api_convert_and_format_date($row['start_time'])
api_convert_and_format_date($start_time)
);
}
if (!empty($row['end_time'])) {
if (!empty($endTime)) {
$attempt_text = sprintf(
get_lang('ExerciseAvailableUntilX'),
api_convert_and_format_date($row['end_time'])
api_convert_and_format_date($end_time)
);
}
}
@ -9095,14 +9085,10 @@ class Exercise
$row_track['exe_weighting']
);
} else {
$attempt_text = get_lang('NotAttempted');
$attempt_text = get_lang('Not attempted');
}
}
}
if ($returnData) {
$attempt_text = $num;
}
}
$currentRow['attempt'] = $attempt_text;
@ -9130,14 +9116,6 @@ class Exercise
$currentRow[] = '<a href="exercise_report.php?'.api_get_cidreq().'&id='.$exerciseId.'">'.
Display::return_icon('test_results.png', get_lang('Results'), '', ICON_SIZE_SMALL).'</a>';
}
if ($returnData) {
$currentRow['id'] = $exercise->id;
$currentRow['url'] = $webPath.'exercise/overview.php?'
.api_get_cidreq_params($courseInfo['code'], $sessionId).'&'
."$mylpid$mylpitemid&id={$exerciseId}";
$currentRow['name'] = $currentRow[0];
}
}
$tableRows[] = $currentRow;
}
@ -9164,8 +9142,8 @@ class Exercise
$table->setTableData($tableRows);
$table->setTotalNumberOfItems($total);
$table->set_additional_parameters([
'cidReq' => api_get_course_id(),
'id_session' => api_get_session_id(),
'cid' => api_get_course_int_id(),
'sid' => api_get_session_id(),
'category_id' => $categoryId,
]);
@ -9181,10 +9159,10 @@ class Exercise
if ($is_allowedToEdit) {
$table->set_header($i++, '', false, 'width="18px"');
}
$table->set_header($i++, get_lang('ExerciseName'), false);
$table->set_header($i++, get_lang('Test name'), false);
if ($is_allowedToEdit) {
$table->set_header($i++, get_lang('QuantityQuestions'), false);
$table->set_header($i++, get_lang('Questions'), false);
$table->set_header($i++, get_lang('Actions'), false);
} else {
$table->set_header($i++, get_lang('Status'), false);

@ -235,7 +235,7 @@ ExerciseLib::delete_chat_exercise_session($exe_id);
if (!in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
$pageBottom .= '<div class="question-return">';
$pageBottom .= Display::url(
get_lang('ReturnToCourseHomepage'),
get_lang('Return to Course Homepage'),
api_get_course_url(),
['class' => 'btn btn-primary']
);
@ -287,7 +287,7 @@ function showEmbeddableFinishButton()
{
$js = '<script>
$(function () {
$(\'.btn-close-quiz\').on(\'click\', function () {
$(\'.btn-close-quiz\').on(\'click\', function () {
window.parent.$(\'video:not(.skip), audio:not(.skip)\').get(0).play();
});
});

@ -19,7 +19,7 @@ $htmlHeadXtra[] = $js;
api_protect_course_script(true);
$sessionId = api_get_session_id();
$courseCode = api_get_course_id();
$exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
$exercise_id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$objExercise = new Exercise();
$result = $objExercise->read($exercise_id, true);

@ -18,6 +18,7 @@ $origin = api_get_origin();
if (in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
$show_headers = false;
}
$is_courseTutor = api_is_course_tutor();
api_protect_course_script($show_headers);
@ -102,9 +103,9 @@ $pageContent = ob_get_contents();
ob_end_clean();
$template = new Template('', $show_headers, $show_headers);
$template->assign('page_top', '');
$template->assign('page_bottom', '');
$template->assign('page_content', $pageContent);
$layout = $template->fetch(
$template->get_template('exercise/result.tpl')
);
$layout = $template->fetch($template->get_template('exercise/result.tpl'));
$template->assign('content', $layout);
$template->display_one_col_template();

@ -1629,11 +1629,11 @@ HOTSPOT;
$sql = " SELECT q.*, tee.*
FROM $quizTable as q
INNER JOIN $trackExerciseTable as tee
ON q.id = tee.exe_exo_id
ON q.iid = tee.exe_exo_id
INNER JOIN $courseTable c
ON c.id = tee.c_id
WHERE tee.exe_id = $exeId
AND q.c_id = c.id";
WHERE
tee.exe_id = $exeId AND q.c_id = c.id";
$sqlResult = Database::query($sql);
if (Database::num_rows($sqlResult)) {

Loading…
Cancel
Save