Skip to content

Commit 13a8fbf

Browse files
committed
Merge branch '1.11.x' of https://github.com/chamilo/chamilo-lms into 1.11.x
2 parents 2865726 + 3f18c7a commit 13a8fbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1157
-646
lines changed

main/admin/questions.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/* For licensing terms, see /license.txt */
44

55
use Chamilo\CourseBundle\Entity\CQuizQuestion;
6+
use Knp\Component\Pager\Paginator;
7+
use Doctrine\Common\Collections\Criteria;
68

79
/**
810
* @package chamilo.admin
@@ -38,7 +40,7 @@
3840

3941
$em = Database::getManager();
4042
$repo = $em->getRepository('ChamiloCourseBundle:CQuizQuestion');
41-
$criteria = new \Doctrine\Common\Collections\Criteria();
43+
$criteria = new Criteria();
4244
if (!empty($id)) {
4345
$criteria->where($criteria->expr()->eq('iid', $id));
4446
}
@@ -65,7 +67,7 @@
6567

6668
$questionCount = count($questions);
6769

68-
$paginator = new Knp\Component\Pager\Paginator();
70+
$paginator = new Paginator();
6971
$pagination = $paginator->paginate($questions, $page, $length);
7072
$pagination->setItemNumberPerPage($length);
7173
$pagination->setCurrentPageNumber($page);
@@ -89,10 +91,14 @@
8991
$url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?';
9092
$exerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?';
9193
foreach ($pagination as $question) {
94+
$courseId = $question->getCId();
95+
$courseInfo = api_get_course_info_by_id($courseId);
96+
$courseCode = $courseInfo['code'];
97+
$question->courseCode = $courseCode;
9298
// Creating empty exercise
9399
$exercise = new Exercise();
94-
$exercise->course_id = $question->getCId();
95-
$questionObject = Question::read($question->getId(), $question->getCId());
100+
$exercise->course_id = $courseId;
101+
$questionObject = Question::read($question->getId(), $courseId);
96102

97103
ob_start();
98104
ExerciseLib::showQuestion(
@@ -108,8 +114,6 @@
108114
true
109115
);
110116
$question->questionData = ob_get_contents();
111-
$courseInfo = api_get_course_info_by_id($exercise->course_id);
112-
$courseCode = $courseInfo['code'];
113117

114118
$exerciseData = '';
115119
$exerciseId = 0;
@@ -124,22 +128,21 @@
124128
Display::return_icon('edit.png', get_lang('Edit')),
125129
$url.http_build_query([
126130
'cidReq' => $courseCode,
131+
'id_session' => $exercise->sessionId,
127132
'myid' => 1,
128133
'exerciseId' => $exerciseId,
129134
'type' => $question->getType(),
130-
'editQuestion' => $question->getId()
131-
]),
132-
['target' => '_blank']
135+
'editQuestion' => $question->getId(),
136+
])
133137
);
134138
}
135-
$question->questionData .= '<br />'. $exerciseData;
139+
$question->questionData .= '<br />'.$exerciseData;
136140
} else {
137141
$question->questionData .= get_lang('Course').': '.Display::url(
138142
$courseInfo['name'],
139143
$exerciseUrl.http_build_query([
140-
'cidReq' => $courseCode
141-
]),
142-
['target' => '_blank']
144+
'cidReq' => $courseCode,
145+
])
143146
);
144147
}
145148
ob_end_clean();

main/exercise/admin.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
$is_allowedToEdit = api_is_allowed_to_edit(null, true, false, false);
5757
$sessionId = api_get_session_id();
5858
$studentViewActive = api_is_student_view_active();
59+
$showPagination = api_get_configuration_value('show_question_pagination');
60+
5961
if (!$is_allowedToEdit) {
6062
api_not_allowed(true);
6163
}
6264

63-
if (empty($exerciseId)) {
64-
$exerciseId = isset($_GET['exerciseId']) ? intval($_GET['exerciseId']) : '0';
65-
}
65+
$exerciseId = isset($_GET['exerciseId']) ? (int) $_GET['exerciseId'] : '0';
6666

6767
/* stripslashes POST data */
6868
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -79,11 +79,7 @@
7979
}
8080

8181
$newQuestion = isset($_GET['newQuestion']) ? $_GET['newQuestion'] : 0;
82-
83-
if (empty($modifyAnswers)) {
84-
$modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
85-
}
86-
82+
$modifyAnswers = isset($_GET['modifyAnswers']) ? $_GET['modifyAnswers'] : 0;
8783
$editQuestion = isset($_GET['editQuestion']) ? $_GET['editQuestion'] : 0;
8884

8985
if (empty($modifyQuestion)) {
@@ -167,8 +163,12 @@
167163

168164
// creation of a new exercise if wrong or not specified exercise ID
169165
if ($exerciseId) {
170-
$showPagination = api_get_configuration_value('show_question_pagination');
171-
$objExercise->read($exerciseId, $showPagination > 0 ? false : true);
166+
$parseQuestionList = $showPagination > 0 ? false : true;
167+
if ($editQuestion) {
168+
$parseQuestionList = false;
169+
$showPagination = true;
170+
}
171+
$objExercise->read($exerciseId, $parseQuestionList);
172172
}
173173
// saves the object into the session
174174
Session::write('objExercise', $objExercise);
@@ -284,21 +284,21 @@
284284
$interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
285285
if (isset($_GET['newQuestion']) || isset($_GET['editQuestion'])) {
286286
$interbreadcrumb[] = [
287-
"url" => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(),
288-
"name" => $objExercise->selectTitle(true),
287+
'url' => "admin.php?exerciseId=".$objExercise->id.'&'.api_get_cidreq(),
288+
'name' => $objExercise->selectTitle(true),
289289
];
290290
} else {
291291
$interbreadcrumb[] = [
292-
"url" => "#",
293-
"name" => $objExercise->selectTitle(true),
292+
'url' => '#',
293+
'name' => $objExercise->selectTitle(true),
294294
];
295295
}
296296

297297
// shows a link to go back to the question pool
298298
if (!$exerciseId && $nameTools != get_lang('ExerciseManagement')) {
299299
$interbreadcrumb[] = [
300-
"url" => api_get_path(WEB_CODE_PATH)."exercise/question_pool.php?fromExercise=$fromExercise&".api_get_cidreq(),
301-
"name" => get_lang('QuestionPool'),
300+
'url' => api_get_path(WEB_CODE_PATH)."exercise/question_pool.php?fromExercise=$fromExercise&".api_get_cidreq(),
301+
'name' => get_lang('QuestionPool'),
302302
];
303303
}
304304

@@ -353,12 +353,14 @@
353353
Display::return_icon('settings.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>';
354354

355355
$maxScoreAllQuestions = 0;
356-
$questionList = $objExercise->selectQuestionList(true, true);
357-
if (!empty($questionList)) {
358-
foreach ($questionList as $questionItemId) {
359-
$question = Question::read($questionItemId);
360-
if ($question) {
361-
$maxScoreAllQuestions += $question->selectWeighting();
356+
if ($showPagination === false) {
357+
$questionList = $objExercise->selectQuestionList(true, true);
358+
if (!empty($questionList)) {
359+
foreach ($questionList as $questionItemId) {
360+
$question = Question::read($questionItemId);
361+
if ($question) {
362+
$maxScoreAllQuestions += $question->selectWeighting();
363+
}
362364
}
363365
}
364366
}
@@ -367,7 +369,6 @@
367369
if ($objExercise->added_in_lp()) {
368370
echo Display::return_message(get_lang('AddedToLPCannotBeAccessed'), 'warning');
369371
}
370-
371372
if ($editQuestion && $objQuestion->existsInAnotherExercises()) {
372373
echo Display::return_message(
373374
Display::returnFontAwesomeIcon('exclamation-triangle"')
@@ -377,17 +378,18 @@
377378
);
378379
}
379380

380-
echo '<div class="alert alert-info">';
381-
echo sprintf(
382-
get_lang('XQuestionsWithTotalScoreY'),
383-
$nbrQuestions,
384-
$maxScoreAllQuestions
385-
);
386-
381+
$alert = '';
382+
if ($showPagination === false) {
383+
$alert .= sprintf(
384+
get_lang('XQuestionsWithTotalScoreY'),
385+
$nbrQuestions,
386+
$maxScoreAllQuestions
387+
);
388+
}
387389
if ($objExercise->random > 0) {
388-
echo '<br />'.sprintf(get_lang('OnlyXQuestionsPickedRandomly'), $objExercise->random);
390+
$alert .= '<br />'.sprintf(get_lang('OnlyXQuestionsPickedRandomly'), $objExercise->random);
389391
}
390-
echo '</div>';
392+
echo Display::return_message($alert);
391393
} elseif (isset($_GET['newQuestion'])) {
392394
// we are in create a new question from question pool not in a test
393395
echo '<div class="actions">';
@@ -412,7 +414,6 @@
412414
$objExercise->edit_exercise_in_lp = true;
413415
require 'question_admin.inc.php';
414416
}
415-
416417
if ($editQuestion) {
417418
// Question preview if teacher clicked the "switch to student"
418419
if ($studentViewActive && $is_allowedToEdit) {

main/exercise/answer.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct($questionId, $course_id = 0, $exercise = null)
8080
// fills arrays
8181
$objExercise = new Exercise($this->course_id);
8282
$exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
83-
$objExercise->read($exerciseId);
83+
$objExercise->read($exerciseId, false);
8484
} else {
8585
$objExercise = $exercise;
8686
}

main/exercise/exercise.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public function read($id, $parseQuestionList = true)
186186
$this->text_when_finished = $object->text_when_finished;
187187
$this->display_category_name = $object->display_category_name;
188188
$this->pass_percentage = $object->pass_percentage;
189-
$this->sessionId = $object->session_id;
190189
$this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE);
191190
$this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
192191
$this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null;
@@ -218,10 +217,9 @@ public function read($id, $parseQuestionList = true)
218217

219218
$this->force_edit_exercise_in_lp = api_get_configuration_value('force_edit_exercise_in_lp');
220219

220+
$this->edit_exercise_in_lp = true;
221221
if ($this->exercise_was_added_in_lp) {
222222
$this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true;
223-
} else {
224-
$this->edit_exercise_in_lp = true;
225223
}
226224

227225
if (!empty($object->end_time)) {

0 commit comments

Comments
 (0)