Add "select all/unselect all" button when reviewing an exercise

See BT#14250
pull/2495/head
jmontoyaa 8 years ago
parent f958b79f26
commit 070258d122
  1. 54
      main/exercise/exercise.class.php
  2. 46
      main/exercise/exercise_reminder.php
  3. 31
      main/inc/ajax/exercise.ajax.php

@ -6649,9 +6649,9 @@ class Exercise
*/
public function get_stat_track_exercise_info_by_exe_id($exe_id)
{
$track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$exe_id = intval($exe_id);
$sql_track = "SELECT * FROM $track_exercises WHERE exe_id = $exe_id ";
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$exe_id = (int) $exe_id;
$sql_track = "SELECT * FROM $table WHERE exe_id = $exe_id ";
$result = Database::query($sql_track);
$new_array = [];
if (Database::num_rows($result) > 0) {
@ -6668,6 +6668,50 @@ class Exercise
return $new_array;
}
/**
* @param int $exeId
*
* @return bool
*/
public function removeAllQuestionToRemind($exeId)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$exeId = (int) $exeId;
if (empty($exeId)) {
return false;
}
$sql = "UPDATE $table
SET questions_to_check = ''
WHERE exe_id = $exeId ";
Database::query($sql);
return true;
}
/**
* @param int $exeId
* @param array $questionList
*
* @return bool
*/
public function addAllQuestionToRemind($exeId, $questionList = [])
{
$exeId = (int) $exeId;
if (empty($questionList)) {
return false;
}
$questionListToString = implode(',', $questionList);
$questionListToString = Database::escape_string($questionListToString);
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sql = "UPDATE $table
SET questions_to_check = '$questionListToString'
WHERE exe_id = $exeId";
Database::query($sql);
return true;
}
/**
* @param int $exe_id
* @param int $question_id
@ -6676,8 +6720,8 @@ class Exercise
public function editQuestionToRemind($exe_id, $question_id, $action = 'add')
{
$exercise_info = self::get_stat_track_exercise_info_by_exe_id($exe_id);
$question_id = intval($question_id);
$exe_id = intval($exe_id);
$question_id = (int) $question_id;
$exe_id = (int) $exe_id;
$track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
if ($exercise_info) {
if (empty($exercise_info['questions_to_check'])) {

@ -140,26 +140,46 @@ echo '<script>
//Normal inputs
window.location = "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 is_checked = 1;
var isChecked = 1;
$("input[type=checkbox]").each(function () {
if ($(this).attr("checked") == "checked") {
is_checked = 2;
if ($(this).prop("checked")) {
isChecked = 2;
return false;
}
});
if (is_checked == 1) {
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;
}
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).is(\':checked\')) {
if ($(obj).prop("checked")) {
action = "add";
} else {
action = "delete";
@ -167,7 +187,7 @@ echo '<script>
$.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(return_value) {
success: function(returnValue) {
}
});
}
@ -247,6 +267,18 @@ $exerciseActions = Display::url(
['onclick' => 'review_questions();', 'class' => 'btn btn-success']
);
$exerciseActions .= '&nbsp;'.Display::url(
get_lang('SelectAll'),
'javascript://',
['onclick' => 'changeOptionStatus(1);', 'class' => 'btn btn-default']
);
$exerciseActions .= '&nbsp;'.Display::url(
get_lang('UnSelectAll'),
'javascript://',
['onclick' => 'changeOptionStatus(0);', 'class' => 'btn btn-default']
);
$exerciseActions .= '&nbsp;'.Display::url(
get_lang('EndTest'),
'javascript://',

@ -357,15 +357,34 @@ switch ($action) {
case 'add_question_to_reminder':
/** @var Exercise $objExercise */
$objExercise = Session::read('objExercise');
if (empty($objExercise)) {
$exeId = isset($_REQUEST['exe_id']) ? $_REQUEST['exe_id'] : 0;
if (empty($objExercise) || empty($exeId)) {
echo 0;
exit;
} else {
$objExercise->editQuestionToRemind(
$_REQUEST['exe_id'],
$_REQUEST['question_id'],
$_REQUEST['action']
);
$option = isset($_GET['option']) ? $_GET['option'] : '';
switch ($option) {
case 'add_all':
$questionListInSession = Session::read('questionList');
$objExercise->addAllQuestionToRemind(
$exeId,
$questionListInSession
);
break;
case 'remove_all':
$objExercise->removeAllQuestionToRemind(
$exeId
);
break;
default:
$objExercise->editQuestionToRemind(
$exeId,
$_REQUEST['question_id'],
$_REQUEST['action']
);
break;
}
}
break;
case 'save_exercise_by_now':

Loading…
Cancel
Save