Exercise: Add extra feature in pending exercises - refs BT#19279

pull/4038/head
Christian 4 years ago
parent b7fcd77f82
commit a30b67ab8b
  1. 63
      main/exercise/pending.php
  2. 2
      main/inc/ajax/model.ajax.php
  3. 149
      main/inc/lib/exercise.lib.php
  4. 3
      main/install/configuration.dist.php

@ -13,6 +13,7 @@ $filter_user = isset($_REQUEST['filter_by_user']) ? (int) $_REQUEST['filter_by_u
$courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0;
$exerciseId = isset($_REQUEST['exercise_id']) ? (int) $_REQUEST['exercise_id'] : 0;
$statusId = isset($_REQUEST['status']) ? (int) $_REQUEST['status'] : 0;
$exportXls = isset($_REQUEST['export_xls']) && !empty($_REQUEST['export_xls']) ? (int) $_REQUEST['export_xls'] : 0;
$action = $_REQUEST['a'] ?? null;
api_block_anonymous_users();
@ -28,7 +29,8 @@ switch ($action) {
$results = ExerciseLib::get_all_exercises_for_course_id(
null,
0,
$courseId
$courseId,
false
);
if (!empty($results)) {
foreach ($results as $exercise) {
@ -111,7 +113,41 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
}
}
$htmlHeadXtra[] = '<script>
$(function() {
$("#export-xls").bind("click", function(e) {
e.preventDefault();
var input = $("<input>", {
type: "hidden",
name: "export_xls",
value: "1"
});
$("#pending").append(input);
$("#pending").submit();
});
$("#pending_pendingSubmit").bind("click", function(e) {
e.preventDefault();
if ($("input[name=\"export_xls\"]").length > 0) {
$("input[name=\"export_xls\"]").remove();
}
$("#pending").submit();
});
});
</script>';
if ($exportXls) {
ExerciseLib::exportPendingAttemptsToExcel($_REQUEST);
}
Display::display_header(get_lang('PendingAttempts'));
$actions = '';
$actions .= Display::url(
Display::return_icon('excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM),
'#',
['id' => 'export-xls']
);
echo Display::div($actions, ['class' => 'actions']);
$token = Security::get_token();
$extra = '<script>
$(function() {
@ -198,7 +234,8 @@ $extra .= '</div>';
echo $extra;
$courses = CourseManager::get_courses_list_by_user_id($userId, false, false, false);
$showAttemptsInSessions = api_get_configuration_value('show_exercise_attempts_in_all_user_sessions');
$courses = CourseManager::get_courses_list_by_user_id($userId, $showAttemptsInSessions, false, false);
$form = new FormValidator('pending', 'GET');
$courses = array_column($courses, 'title', 'real_id');
@ -218,10 +255,12 @@ $status = [
1 => get_lang('All'),
2 => get_lang('Validated'),
3 => get_lang('NotValidated'),
4 => get_lang('Unclosed'),
5 => get_lang('Ongoing'),
];
$form->addSelect('status', get_lang('Status'), $status);
$form->addButtonSearch(get_lang('Search'));
$form->addButtonSearch(get_lang('Search'), 'pendingSubmit');
$content = $form->returnForm();
echo $content;
@ -251,7 +290,8 @@ $columns = [
get_lang('Score'),
get_lang('IP'),
get_lang('Status'),
//get_lang('ToolLearnpath'),
get_lang('Corrector'),
get_lang('CorrectionDate'),
get_lang('Actions'),
];
@ -303,7 +343,20 @@ $column_model = [
'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'),
],*/
],
//['name' => 'lp', 'index' => 'orig_lp_id', 'width' => '60', 'align' => 'left', 'search' => 'false'],
[
'name' => 'qualificator_fullname',
'index' => 'qualificator_fullname',
'width' => '20',
'align' => 'left',
'search' => 'true',
],
[
'name' => 'date_of_qualification',
'index' => 'date_of_qualification',
'width' => '20',
'align' => 'left',
'search' => 'true',
],
[
'name' => 'actions',
'index' => 'actions',

@ -1588,6 +1588,8 @@ switch ($action) {
'score',
'user_ip',
'status',
'qualificator_fullname',
'date_of_qualification',
'actions',
];
$officialCodeInList = api_get_setting('show_official_code_exercise_result_list');

@ -2163,6 +2163,109 @@ HOTSPOT;
return $attempt;
}
/**
* Export the pending attempts to excel.
*
* @params $values
*/
public static function exportPendingAttemptsToExcel($values)
{
$headers = [
get_lang('Course'),
get_lang('Exercise'),
get_lang('FirstName'),
get_lang('LastName'),
get_lang('LoginName'),
get_lang('Duration').' ('.get_lang('MinMinute').')',
get_lang('StartDate'),
get_lang('EndDate'),
get_lang('Score'),
get_lang('IP'),
get_lang('Status'),
get_lang('Corrector'),
get_lang('CorrectionDate'),
];
$tableXls[] = $headers;
$courseId = $values['course_id'] ?? 0;
$exerciseId = $values['exercise_id'] ?? 0;
$status = $values['status'] ?? 0;
$whereCondition = '';
if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
$filter_user = (int) $_GET['filter_by_user'];
if (empty($whereCondition)) {
$whereCondition .= " te.exe_user_id = '$filter_user'";
} else {
$whereCondition .= " AND te.exe_user_id = '$filter_user'";
}
}
if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) {
$groupIdFromToolbar = (int) $_GET['group_id_in_toolbar'];
if (!empty($groupIdFromToolbar)) {
if (empty($whereCondition)) {
$whereCondition .= " te.group_id = '$groupIdFromToolbar'";
} else {
$whereCondition .= " AND group_id = '$groupIdFromToolbar'";
}
}
}
if (!empty($whereCondition)) {
$whereCondition = " AND $whereCondition";
}
if (!empty($courseId)) {
$whereCondition .= " AND te.c_id = $courseId";
}
$result = ExerciseLib::get_exam_results_data(
0,
10000000,
'c_id',
'asc',
$exerciseId,
$whereCondition,
false,
null,
false,
false,
[],
false,
false,
false,
true,
$status
);
if (!empty($result)) {
foreach ($result as $attempt) {
$data = [
$attempt['course'],
$attempt['exercise'],
$attempt['firstname'],
$attempt['lastname'],
$attempt['username'],
$attempt['exe_duration'],
$attempt['start_date'],
$attempt['exe_date'],
strip_tags($attempt['score']),
$attempt['user_ip'],
strip_tags($attempt['status']),
$attempt['qualificator_fullname'],
$attempt['date_of_qualification'],
];
$tableXls[] = $data;
}
}
$fileName = get_lang('PendingAttempts').'_'.api_get_local_time();
Export::arrayToXls($tableXls, $fileName);
return true;
}
/**
* Gets exercise results.
*
@ -2283,6 +2386,22 @@ HOTSPOT;
$sessionCondition = '';
}
$showAttemptsInSessions = api_get_configuration_value('show_exercise_attempts_in_all_user_sessions');
if ($showAttemptsInSessions) {
$sessions = SessionManager::get_sessions_by_general_coach(api_get_user_id());
if (!empty($sessions)) {
$sessionIds = [];
foreach ($sessions as $session) {
$sessionIds[] = $session['id'];
}
$session_id_and = " AND te.session_id IN(".implode(',', $sessionIds).")";
$sessionCondition = " AND ttte.session_id IN(".implode(',', $sessionIds).")";
} else {
return false;
}
}
$exercise_where = '';
$exerciseFilter = '';
if (!empty($exercise_id)) {
@ -2299,7 +2418,7 @@ HOTSPOT;
// sql for chamilo-type tests for teacher / tutor view
$sql_inner_join_tbl_track_exercices = "
(
SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised
SELECT DISTINCT ttte.*, if(tr.exe_id,1, 0) as revised, tr.author as corrector, tr.insert_date as correction_date
FROM $TBL_TRACK_EXERCICES ttte
LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr
ON (ttte.exe_id = tr.exe_id)
@ -2444,7 +2563,9 @@ HOTSPOT;
group_name,
group_id,
orig_lp_id,
te.user_ip";
te.user_ip,
corrector,
correction_date";
}
$sql = " $sql_select
@ -2610,6 +2731,21 @@ HOTSPOT;
}
}
if (4 == $status && 2 != $revised) {
// Filter by status "unclosed"
continue;
}
if (5 == $status && 3 != $revised) {
// Filter by status "ongoing"
continue;
}
if (3 == $status && in_array($revised, [1, 2, 3])) {
// Filter by status "not validated"
continue;
}
if ($from_gradebook && ($is_allowedToEdit)) {
if (in_array(
$attempt['username'].$attempt['firstname'].$attempt['lastname'],
@ -2968,6 +3104,15 @@ HOTSPOT;
$attempt['session_access_start_date'] = $sessionStartAccessDate;
$attempt['status'] = $revisedLabel;
$attempt['score'] = $score;
$attempt['qualificator_fullname'] = '';
$attempt['date_of_qualification'] = '';
if (!empty($attempt['corrector'])) {
$qualificatorAuthor = api_get_user_info($attempt['corrector']);
$attempt['qualificator_fullname'] = api_get_person_name($qualificatorAuthor['firstname'], $qualificatorAuthor['lastname']);
}
if (!empty($attempt['correction_date'])) {
$attempt['date_of_qualification'] = api_convert_and_format_date($attempt['correction_date'], DATE_TIME_FORMAT_SHORT);
}
$attempt['score_percentage'] = self::show_score(
$my_res,
$my_total,

@ -1899,6 +1899,9 @@ ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763AD3ED51C FOREIGN KEY (gr
// Shows exercise session attempts in the base course.
// $_configuration['show_exercise_session_attempts_in_base_course'] = false;
// Shows exercise attempts in sessions where user is general coach
// $_configuration['show_exercise_attempts_in_all_user_sessions'] = true;
// Allow coach users to always edit announcements inside active/past sessions.
// $_configuration['allow_coach_to_edit_announcements'] = false;

Loading…
Cancel
Save