Exercises: Allow question reminder when using category groups BT#17789

pull/3600/head^2
Julio Montoya 5 years ago
parent b7ac4cd19d
commit a3bcb2ad2a
  1. 123
      main/exercise/exercise.class.php
  2. 15
      main/exercise/exercise_question_reminder.php
  3. 118
      main/exercise/exercise_reminder.php
  4. 11
      main/inc/ajax/exercise.ajax.php
  5. 1
      plugin/exercise_signature/lib/ExerciseSignature.php

@ -10129,7 +10129,6 @@ class Exercise
public function getUserAnswersSavedInExercise($attemptId)
{
$exerciseResult = [];
$attemptList = Event::getAllExerciseEventByExeId($attemptId);
foreach ($attemptList as $questionId => $options) {
@ -10748,4 +10747,126 @@ class Exercise
get_lang('ShowResultsToStudents')
);
}
public function getReminderTable($questionList, $exercise_stat_info)
{
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
$learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? (int) $_REQUEST['learnpath_item_view_id'] : 0;
$remind_list = $exercise_stat_info['questions_to_check'];
$remind_list = explode(',', $remind_list);
$exeId = $exercise_stat_info['exe_id'];
$exerciseId = $exercise_stat_info['exe_exo_id'];
$exercise_result = $this->getUserAnswersSavedInExercise($exeId);
$content = Display::label(get_lang('QuestionWithNoAnswer'), 'danger');
$content .= '<div class="clear"></div><br />';
$table = '';
$counter = 0;
// Loop over all question to show results for each of them, one by one
foreach ($questionList as $questionId) {
// destruction of the Question object
unset($objQuestionTmp);
// creates a temporary Question object
$objQuestionTmp = Question:: read($questionId);
$check_id = 'remind_list['.$questionId.']';
$attributes = ['id' => $check_id, 'onclick' => "save_remind_item(this, '$questionId');"];
if (in_array($questionId, $remind_list)) {
$attributes['checked'] = 1;
}
$checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
$checkbox = '<div class="pretty p-svg p-curve">
'.$checkbox.'
<div class="state p-primary ">
<svg class="svg svg-icon" viewBox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white;fill:white;"></path>
</svg>
<label>&nbsp;</label>
</div>
</div>';
$counter++;
$questionTitle = $counter.'. '.strip_tags($objQuestionTmp->selectTitle());
// Check if the question doesn't have an answer
if (!in_array($questionId, $exercise_result)) {
$questionTitle = Display::label($questionTitle, 'danger');
}
$label_attributes = [];
$label_attributes['for'] = $check_id;
$questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
$table .= Display::div($questionTitle, ['class' => 'exercise_reminder_item ']);
}
$content .= Display::div('', ['id' => 'message']).
Display::div($table, ['class' => 'question-check-test']);
$content .= '<script>
var lp_data = $.param({
"learnpath_id": '.$learnpath_id.',
"learnpath_item_id" : '.$learnpath_item_id.',
"learnpath_item_view_id": '.$learnpath_item_view_id.'
});
function final_submit() {
// Normal inputs
window.location = "'.api_get_path(WEB_CODE_PATH).'exercise/exercise_result.php?'.api_get_cidreq().'&exe_id='.$exeId.'&" + lp_data;
}
function changeOptionStatus(status)
{
$("input[type=checkbox]").each(function () {
$(this).prop("checked", status);
});
var action = "";
var extraOption = "remove_all";
if (status == 1) {
extraOption = "add_all";
}
$.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
data: "option="+extraOption+"&exe_id='.$exeId.'&action="+action,
success: function(returnValue) {
}
});
}
function review_questions() {
var isChecked = 1;
$("input[type=checkbox]").each(function () {
if ($(this).prop("checked")) {
isChecked = 2;
return false;
}
});
if (isChecked == 1) {
$("#message").addClass("warning-message");
$("#message").html("'.addslashes(get_lang('SelectAQuestionToReview')).'");
} else {
window.location = "exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&reminder=2&" + lp_data;
}
}
function save_remind_item(obj, question_id) {
var action = "";
if ($(obj).prop("checked")) {
action = "add";
} else {
action = "delete";
}
$.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
data: "question_id="+question_id+"&exe_id='.$exeId.'&action="+action,
success: function(returnValue) {
}
});
}
</script>';
return $content;
}
}

@ -41,9 +41,8 @@ $categoryId = $categoryObj->id;
$params = "exe_id=$exeId&exerciseId=$exerciseId&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq();
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise_submit.php?'.$params;
$validateUrl = api_get_self().'?'.$params.'&category_id='.$categoryId.'&validate=1';
$time_control = false;
/*
$time_control = false;
$clock_expired_time = ExerciseLib::get_session_time_control_key(
$objExercise->id,
$learnpath_id,
@ -64,7 +63,7 @@ if ($time_control) {
$htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
$htmlHeadXtra[] = $objExercise->showTimeControlJS($time_left);
}
$htmlHeadXtra[] = api_get_css_asset('pretty-checkbox/dist/pretty-checkbox.min.css');*/
$htmlHeadXtra[] = api_get_css_asset('pretty-checkbox/dist/pretty-checkbox.min.css');
$trackInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
if (empty($trackInfo)) {
@ -111,12 +110,20 @@ echo Display::page_header($categoryObj->name);
echo '<p>'.Security::remove_XSS($categoryObj->description).'</p>';
echo '<p>'.get_lang('BlockCategoryExplanation').'</p>';
if ($objExercise->review_answers) {
$questionList = [];
$categoryList = Session::read('categoryList');
if (isset($categoryList[$categoryId])) {
$questionList = $categoryList[$categoryId];
}
echo $objExercise->getReminderTable($questionList, $trackInfo);
}
if ($time_control) {
echo $objExercise->returnTimeLeftDiv();
}
echo Display::div('', ['id' => 'message']);
$previousQuestion = $currentQuestion - 1;
echo '<script>
var lp_data = $.param({

@ -66,8 +66,8 @@ if (isset($_GET['exe_id'])) {
}
$exe_id = (int) Session::read('exe_id');
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
$question_list = [];
if (!empty($exercise_stat_info['data_tracking'])) {
$question_list = explode(',', $exercise_stat_info['data_tracking']);
}
@ -78,7 +78,6 @@ if (empty($exercise_stat_info) || empty($question_list)) {
$nameTools = get_lang('Exercises');
$interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
$hideHeaderAndFooter = in_array($origin, ['learnpath', 'embeddable']);
if (!$hideHeaderAndFooter) {
@ -88,8 +87,6 @@ if (!$hideHeaderAndFooter) {
Display::display_reduced_header();
}
/* DISPLAY AND MAIN PROCESS */
// I'm in a preview mode as course admin. Display the action menu.
if (api_is_course_admin() && !$hideHeaderAndFooter) {
echo '<div class="actions">';
@ -104,118 +101,7 @@ echo Display::page_header(get_lang('QuestionsToReview'));
if ($time_control) {
echo $objExercise->returnTimeLeftDiv();
}
echo Display::div('', ['id' => 'message']);
echo '<script>
var lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
function final_submit() {
// Normal inputs
window.location = "'.api_get_path(WEB_CODE_PATH).'exercise/exercise_result.php?'.api_get_cidreq().'&exe_id='.$exe_id.'&" + lp_data;
}
function changeOptionStatus(status)
{
$("input[type=checkbox]").each(function () {
$(this).prop("checked", status);
});
var action = "";
var extraOption = "remove_all";
if (status == 1) {
extraOption = "add_all";
}
$.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
data: "option="+extraOption+"&exe_id='.$exe_id.'&action="+action,
success: function(returnValue) {
}
});
}
function review_questions() {
var isChecked = 1;
$("input[type=checkbox]").each(function () {
if ($(this).prop("checked")) {
isChecked = 2;
return false;
}
});
if (isChecked == 1) {
$("#message").addClass("warning-message");
$("#message").html("'.addslashes(get_lang('SelectAQuestionToReview')).'");
} else {
window.location = "exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&reminder=2&" + lp_data;
}
}
function save_remind_item(obj, question_id) {
var action = "";
if ($(obj).prop("checked")) {
action = "add";
} else {
action = "delete";
}
$.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
data: "question_id="+question_id+"&exe_id='.$exe_id.'&action="+action,
success: function(returnValue) {
}
});
}
</script>';
$attempt_list = Event::getAllExerciseEventByExeId($exe_id);
$remind_list = $exercise_stat_info['questions_to_check'];
$remind_list = explode(',', $remind_list);
$exercise_result = $objExercise->getUserAnswersSavedInExercise($exe_id);
echo Display::label(get_lang('QuestionWithNoAnswer'), 'danger');
echo '<div class="clear"></div><br />';
$table = '';
$counter = 0;
// Loop over all question to show results for each of them, one by one
foreach ($question_list as $questionId) {
// destruction of the Question object
unset($objQuestionTmp);
// creates a temporary Question object
$objQuestionTmp = Question:: read($questionId);
$check_id = 'remind_list['.$questionId.']';
$attributes = ['id' => $check_id, 'onclick' => "save_remind_item(this, '$questionId');"];
if (in_array($questionId, $remind_list)) {
$attributes['checked'] = 1;
}
$checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
$checkbox = '<div class="pretty p-svg p-curve">
'.$checkbox.'
<div class="state p-primary ">
<svg class="svg svg-icon" viewBox="0 0 20 20">
<path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white;fill:white;"></path>
</svg>
<label>&nbsp;</label>
</div>
</div>';
$counter++;
$questionTitle = $counter.'. '.strip_tags($objQuestionTmp->selectTitle());
// Check if the question doesn't have an answer
if (!in_array($questionId, $exercise_result)) {
$questionTitle = Display::label($questionTitle, 'danger');
}
$label_attributes = [];
$label_attributes['for'] = $check_id;
$questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
$table .= Display::div($questionTitle, ['class' => 'exercise_reminder_item ']);
} // end foreach() block that loops over all questions
echo Display::div($table, ['class' => 'question-check-test']);
echo $objExercise->getReminderTable($question_list, $exercise_stat_info);
$exerciseActions = Display::url(
get_lang('ReviewQuestions'),

@ -356,15 +356,10 @@ switch ($action) {
switch ($option) {
case 'add_all':
$questionListInSession = Session::read('questionList');
$objExercise->addAllQuestionToRemind(
$exeId,
$questionListInSession
);
$objExercise->addAllQuestionToRemind($exeId, $questionListInSession);
break;
case 'remove_all':
$objExercise->removeAllQuestionToRemind(
$exeId
);
$objExercise->removeAllQuestionToRemind($exeId);
break;
default:
$objExercise->editQuestionToRemind(
@ -374,6 +369,8 @@ switch ($action) {
);
break;
}
echo 1;
exit;
}
break;
case 'save_exercise_by_now':

@ -43,7 +43,6 @@ class ExerciseSignaturePlugin extends Plugin
return false;
}
public static function saveSignature($userId, $trackInfo, $file)
{
if (false === self::validateSignatureAccess($userId, $trackInfo)) {

Loading…
Cancel
Save