Minor - Update from 1.11.x, fix behat tests

pull/3432/head
Julio Montoya 4 years ago
parent f362361831
commit d48f33036d
  1. 23
      public/main/exercise/exercise.class.php
  2. 12
      public/main/exercise/exercise.php
  3. 64
      public/main/exercise/exercise_report.php
  4. 6
      public/main/exercise/upload_exercise.php
  5. 1
      public/main/inc/lib/api.lib.php

@ -99,6 +99,8 @@ class Exercise
public $hideComment;
public $hideNoAnswer;
public $hideExpectedAnswer;
public $forceShowExpectedChoiceColumn;
public $disableHideCorrectAnsweredQuestions;
/**
* Constructor of the class.
@ -143,6 +145,7 @@ class Exercise
$this->hideComment = false;
$this->hideNoAnswer = false;
$this->hideExpectedAnswer = false;
$this->disableHideCorrectAnsweredQuestions = false;
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
@ -2102,6 +2105,12 @@ class Exercise
null,
get_lang('HideCategoryTable')
),
$form->createElement(
'checkbox',
'hide_correct_answered_questions',
null,
get_lang('HideCorrectAnsweredQuestions')
),
];
$form->addGroup(
$group,
@ -9060,7 +9069,7 @@ class Exercise
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq(
).'&choice=enable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
).'&action=enable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
} else {
$actions .= Display::url(
@ -9071,21 +9080,21 @@ class Exercise
ICON_SIZE_SMALL
),
'exercise.php?'.api_get_cidreq(
).'&choice=disable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
).'&action=disable_launch&sec_token='.$token.'&exerciseId='.$exerciseId
);
}
}
// Export
$actions .= Display::url(
Display::return_icon('cd.png', get_lang('CopyExercise')),
Display::return_icon('cd.png', get_lang('Copy this exercise as a new one')),
'',
[
'onclick' => "javascript:if(!confirm('".addslashes(
api_htmlentities(get_lang('AreYouSureToCopy'), ENT_QUOTES, $charset)
api_htmlentities(get_lang('Are you sure to copy'), ENT_QUOTES, $charset)
)." ".addslashes($title)."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq(
).'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$exerciseId,
).'&action=copy_exercise&sec_token='.$token.'&exerciseId='.$exerciseId,
]
);
@ -9110,7 +9119,7 @@ class Exercise
)
)." ".addslashes($title)."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq(
).'&choice=clean_results&sec_token='.$token.'&exerciseId='.$exerciseId,
).'&action=clean_results&sec_token='.$token.'&exerciseId='.$exerciseId,
]
);
} else {
@ -9261,7 +9270,7 @@ class Exercise
api_htmlentities(get_lang('AreYouSureToDeleteJS'), ENT_QUOTES, $charset)
)." ".addslashes($exercise->getUnformattedTitle())."?"."')) return false;",
'href' => 'exercise.php?'.api_get_cidreq(
).'&choice=delete&sec_token='.$token.'&exerciseId='.$exerciseId,
).'&action=delete&sec_token='.$token.'&exerciseId='.$exerciseId,
]
);
} else {

@ -59,7 +59,7 @@ $file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) :
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : null;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : null;
$categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : 0;
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$action = $_REQUEST['action'] ?? '';
$keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : '';
$exerciseRepo = Container::getQuizRepository();
@ -77,18 +77,14 @@ if (api_is_in_gradebook()) {
}
$nameTools = get_lang('Tests');
// Simple actions
if ($is_allowedToEdit && !empty($action)) {
$objExerciseTmp = new Exercise();
$exercise_action_locked = api_resource_is_locked_by_gradebook(
$exerciseId,
LINK_EXERCISE
);
$exercise_action_locked = api_resource_is_locked_by_gradebook($exerciseId, LINK_EXERCISE);
$result = $objExerciseTmp->read($exerciseId);
if (empty($result)) {
api_not_allowed();
api_not_allowed(true);
}
switch ($action) {
@ -182,7 +178,7 @@ if ($is_allowedToEdit && !empty($action)) {
}
break;
case 'copy_exercise': //copy an exercise
case 'copy_exercise':
api_set_more_memory_and_time_limits();
$objExerciseTmp->copyExercise();
Display::addFlash(Display::return_message(

@ -171,41 +171,62 @@ if (isset($_REQUEST['comments']) &&
$lp_item_view_id = (int) $track_exercise_info['orig_lp_item_view_id'];
$exerciseId = $track_exercise_info['exe_exo_id'];
$exeWeighting = $track_exercise_info['max_score'];
$attemptData = Event::get_exercise_results_by_attempt($id);
$questionListData = [];
if ($attemptData && $attemptData[$id] && $attemptData[$id]['question_list']) {
$questionListData = $attemptData[$id]['question_list'];
}
$post_content_id = [];
$comments_exist = false;
$questionListInPost = [];
foreach ($_POST as $key_index => $key_value) {
$my_post_info = explode('_', $key_index);
$post_content_id[] = isset($my_post_info[1]) ? $my_post_info[1] : null;
if ('comments' === $my_post_info[0]) {
$comments_exist = true;
$questionListInPost[] = $my_post_info[1];
}
}
$loop_in_track = true === $comments_exist ? count($_POST) / 2 : count($_POST);
if (true === $comments_exist) {
$array_content_id_exe = array_slice($post_content_id, $loop_in_track);
} else {
$array_content_id_exe = $post_content_id;
}
for ($i = 0; $i < $loop_in_track; $i++) {
$my_marks = isset($_POST['marks_'.$array_content_id_exe[$i]]) ? $_POST['marks_'.$array_content_id_exe[$i]] : 0;
$my_comments = '';
if (isset($_POST['comments_'.$array_content_id_exe[$i]])) {
$my_comments = $_POST['comments_'.$array_content_id_exe[$i]];
}
$my_questionid = (int) $array_content_id_exe[$i];
foreach ($questionListInPost as $questionId) {
$marks = $_POST['marks_'.$questionId] ?? 0;
$my_comments = $_POST['comments_'.$questionId] ?? '';
$params = [
'marks' => $my_marks,
'teacher_comment' => $my_comments,
];
$question = Question::read($questionId);
if (false === $question) {
continue;
}
// From the database.
$marksFromDatabase = $questionListData[$questionId]['marks'];
if (in_array($question->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
// From the form.
$params['marks'] = $marks;
if ($marksFromDatabase != $marks) {
Event::addEvent(
LOG_QUESTION_SCORE_UPDATE,
LOG_EXERCISE_ATTEMPT_QUESTION_ID,
[
'exe_id' => $id,
'question_id' => $questionId,
'old_marks' => $marksFromDatabase,
'new_marks' => $marks,
]
);
}
} else {
$marks = $marksFromDatabase;
}
Database::update(
$TBL_TRACK_ATTEMPT,
$params,
['question_id = ? AND exe_id = ?' => [$my_questionid, $id]]
['question_id = ? AND exe_id = ?' => [$questionId, $id]]
);
$recording = new TrackEAttemptRecording();
@ -222,15 +243,6 @@ if (isset($_REQUEST['comments']) &&
$em = Database::getManager();
$em->persist($recording);
$em->flush();
/*$params = [
'marks' => $my_marks,
//'insert_date' => api_get_utc_datetime(),
'author' => api_get_user_id(),
'teacher_comment' => $my_comments,
'session_id' => api_get_session_id(),
];
Database::insert($TBL_TRACK_ATTEMPT_RECORDING, $params);*/
}
$useEvaluationPlugin = false;

@ -70,8 +70,9 @@ function lp_upload_quiz_main()
$form->addElement('header', get_lang('Import quiz from Excel'));
$form->addElement('file', 'user_upload_quiz', get_lang('File upload'));
$link = '<a href="../exercise/quiz_template.xls">'.
Display::return_icon('export_excel.png', get_lang('Download the Excel Template')).get_lang('Download the Excel Template').'</a>';
$label = Display::return_icon('export_excel.png', get_lang('Download the Excel Template')).
get_lang('Download the Excel Template');
$link = '<a href="../exercise/quiz_template.xls">'.$label.'</a>';
$form->addElement('label', '', $link);
$table = new HTML_Table(['class' => 'table']);
@ -154,6 +155,7 @@ function lp_upload_quiz_action_handling()
$quizTitle = '';
$objPHPExcel = PHPExcel_IOFactory::load($_FILES['user_upload_quiz']['tmp_name']);
$objPHPExcel->setActiveSheetIndex(0);
$worksheet = $objPHPExcel->getActiveSheet();
$highestRow = $worksheet->getHighestRow(); // e.g. 10

@ -231,6 +231,7 @@ define('LOG_EXERCISE_RESULT_DELETE', 'exe_result_deleted');
define('LOG_EXERCISE_ATTEMPT_DELETE', 'exe_attempt_deleted');
define('LOG_LP_ATTEMPT_DELETE', 'lp_attempt_deleted');
define('LOG_QUESTION_RESULT_DELETE', 'qst_attempt_deleted');
define('LOG_QUESTION_SCORE_UPDATE', 'score_attempt_updated');
define('LOG_MY_FOLDER_CREATE', 'my_folder_created');
define('LOG_MY_FOLDER_CHANGE', 'my_folder_changed');

Loading…
Cancel
Save