Skip to content

Commit

Permalink
Admin: Add config block_category_questions BT#17789 (WIP)
Browse files Browse the repository at this point in the history
Requires DB change.
  • Loading branch information
jmontoyaa committed Oct 29, 2020
1 parent 154dbe8 commit 9f573d9
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 80 deletions.
7 changes: 4 additions & 3 deletions main/exercise/exercise.class.php
Expand Up @@ -91,7 +91,6 @@ class Exercise
public $pageResultConfiguration;
public $preventBackwards;
public $currentQuestion;
public $currentBlockedCategories;
public $hideComment;
public $hideNoAnswer;
public $hideExpectedAnswer;
Expand Down Expand Up @@ -3220,6 +3219,7 @@ public function save_stat_track_exercise_info(
* @param array $questions_in_media
* @param string $currentAnswer
* @param array $myRemindList
* @param bool $showPreviousButton
*
* @return string
*/
Expand All @@ -3228,7 +3228,8 @@ public function show_button(
$questionNum,
$questions_in_media = [],
$currentAnswer = '',
$myRemindList = []
$myRemindList = [],
$showPreviousButton = true
) {
global $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id;
$nbrQuestions = $this->countQuestionsInExercise();
Expand Down Expand Up @@ -3332,7 +3333,7 @@ public function show_button(
}
}

if ($showPreview && 0 === $this->getPreventBackwards()) {
if ($showPreviousButton && $showPreview && 0 === $this->getPreventBackwards()) {
$buttonList[] = Display::button(
'previous_question_and_save',
get_lang('PreviousQuestion'),
Expand Down
175 changes: 175 additions & 0 deletions main/exercise/exercise_question_reminder.php
@@ -0,0 +1,175 @@
<?php

/* For licensing terms, see /license.txt */

use ChamiloSession as Session;

require_once __DIR__.'/../inc/global.inc.php';

if (false === api_get_configuration_value('block_category_questions')) {
api_not_allowed(true);
}

$this_section = SECTION_COURSES;
api_protect_course_script(true);
$origin = api_get_origin();

$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;
$exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
$currentQuestion = isset($_REQUEST['num']) ? (int) $_REQUEST['num'] : 1;
$exeId = isset($_REQUEST['exe_id']) ? (int) $_REQUEST['exe_id'] : 0;
$questionCategoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : 0;
$validateCategory = isset($_REQUEST['validate']) && 1 === (int) $_REQUEST['validate'];

/** @var Exercise $objExercise */
$objExercise = null;
$exerciseInSession = Session::read('objExercise');
if (!empty($exerciseInSession)) {
$objExercise = $exerciseInSession;
}

$category = new TestCategory();
$categoryObj = $category->getCategory($questionCategoryId);

if (empty($objExercise) || empty($questionCategoryId) || empty($exeId) || empty($categoryObj)) {
api_not_allowed(true);
}

$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;

/*
$clock_expired_time = ExerciseLib::get_session_time_control_key(
$objExercise->id,
$learnpath_id,
$learnpath_item_id
);
if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
$time_control = true;
}
if ($time_control) {
// Get time left for expiring time
$time_left = api_strtotime($clock_expired_time, 'UTC') - time();
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
$htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
$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');*/

$trackInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
if (empty($trackInfo)) {
api_not_allowed();
}
$blockedCategories = [];
if (isset($trackInfo['blocked_categories']) && !empty($trackInfo['blocked_categories'])) {
$blockedCategories = explode(',', $trackInfo['blocked_categories']);
}

if ($validateCategory) {
$blockedCategories[] = $categoryId;
$blockedCategories = array_unique($blockedCategories);
$value = implode(',', $blockedCategories);
$value = Database::escape_string($value);
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$sql = "UPDATE $table
SET blocked_categories = '$value'
WHERE exe_id = $exeId";
Database::query($sql);
api_location($url.'&num='.$currentQuestion);
}

$nameTools = get_lang('Exercises');
$interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
$hideHeaderAndFooter = in_array($origin, ['learnpath', 'embeddable']);

if (!$hideHeaderAndFooter) {
Display::display_header($nameTools, get_lang('Exercise'));
} else {
Display::display_reduced_header();
}

// I'm in a preview mode as course admin. Display the action menu.
if (api_is_course_admin() && !$hideHeaderAndFooter) {
echo '<div class="actions">';
echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
Display::return_icon('back.png', get_lang('GoBackToQuestionList'), [], 32).'</a>';
echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.
Display::return_icon('edit.png', get_lang('ModifyExercise'), [], 32).'</a>';
echo '</div>';
}
echo Display::page_header($categoryObj->name);
echo '<p>'.Security::remove_XSS($categoryObj->description).'</p>';
echo '<p>'.get_lang('BlockCategoryExplanation').'</p>';

if ($time_control) {
echo $objExercise->returnTimeLeftDiv();
}

echo Display::div('', ['id' => 'message']);

$previousQuestion = $currentQuestion - 1;
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 goBack() {
window.location = "'.$url.'&num='.$previousQuestion.'&" + lp_data;
}
function continueExercise() {
window.location = "'.$validateUrl.'&num='.$currentQuestion.'&" + lp_data;
}
function final_submit() {
window.location = "'.api_get_path(WEB_CODE_PATH).'exercise/exercise_result.php?'.api_get_cidreq().'&exe_id='.$exeId.'&" + lp_data;
}
</script>';

$exercise_result = $objExercise->getUserAnswersSavedInExercise($exeId);
echo '<div class="clear"></div><br />';
$table = '';
$counter = 0;
echo Display::div($table, ['class' => 'question-check-test']);

$exerciseActions = '';
if (!in_array($categoryId, $blockedCategories)) {
$exerciseActions = '&nbsp;'.Display::url(
get_lang('GoBack'),
'javascript://',
['onclick' => 'goBack();', 'class' => 'btn btn-default']
);
}
$exerciseActions .= '&nbsp;'.Display::url(
get_lang('ContinueTest'),
'javascript://',
['onclick' => 'continueExercise();', 'class' => 'btn btn-primary']
);
/*
$exerciseActions .= '&nbsp;'.Display::url(
get_lang('EndTest'),
'javascript://',
['onclick' => 'final_submit();', 'class' => 'btn btn-warning']
);*/

echo Display::div('', ['class' => 'clear']);
echo Display::div($exerciseActions, ['class' => 'form-actions']);

if (!$hideHeaderAndFooter) {
// We are not in learnpath tool or embeddable quiz
Display::display_footer();
} else {
Display::display_reduced_footer();
}
1 change: 0 additions & 1 deletion main/exercise/exercise_result.php
Expand Up @@ -31,7 +31,6 @@
}

$exeId = isset($_REQUEST['exe_id']) ? (int) $_REQUEST['exe_id'] : 0;

if (empty($objExercise)) {
// Redirect to the exercise overview
// Check if the exe_id exists
Expand Down

0 comments on commit 9f573d9

Please sign in to comment.