From 25aa71fd77334557c205678563351f683a5ba363 Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Thu, 5 Dec 2024 12:54:52 -0500 Subject: [PATCH] Exercise: Fix broken presentation when editing exercises with more than 100 questions - refs BT#22237 --- .../main/exercise/question_list_admin.inc.php | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/public/main/exercise/question_list_admin.inc.php b/public/main/exercise/question_list_admin.inc.php index 5f5c2a4a3e1..591063d9dd4 100644 --- a/public/main/exercise/question_list_admin.inc.php +++ b/public/main/exercise/question_list_admin.inc.php @@ -135,11 +135,7 @@ //deletes a session when using don't know question type (ugly fix) Session::erase('less_answer'); -// If we are in a test -$inATest = isset($exerciseId) && $exerciseId > 0; -if (!$inATest) { - echo Display::return_message(get_lang('Choose question type'), 'warning'); -} else { +if (isset($exerciseId) && $exerciseId > 0) { if ($nbrQuestions) { // In the building exercise mode show question list ordered as is. $objExercise->setCategoriesGrouping(false); @@ -149,32 +145,14 @@ $objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED; $allowQuestionOrdering = true; $showPagination = api_get_setting('exercise.show_question_pagination'); + $length = api_get_setting('exercise.question_pagination_length'); + $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; + if (!empty($showPagination) && $nbrQuestions > $showPagination) { - $length = api_get_setting('exercise.question_pagination_length'); - $url = api_get_self().'?'.api_get_cidreq(); - // Use pagination for exercise with more than 200 questions. $allowQuestionOrdering = false; $start = ($page - 1) * $length; - $questionList = $objExercise->getQuestionForTeacher($start, $length); - $paginator = new Knp\Component\Pager\Paginator(); - $pagination = $paginator->paginate([]); - $pagination->setTotalItemCount($nbrQuestions); - $pagination->setItemNumberPerPage($length); - $pagination->setCurrentPageNumber($page); - $pagination->renderer = function ($data) use ($url) { - $render = ''; - - return $render; - }; - echo $pagination; + $questionList = $objExercise->selectQuestionList(true, true); + $questionList = array_slice($questionList, $start, $length); } else { // Classic order $questionList = $objExercise->selectQuestionList(true, true); @@ -331,7 +309,17 @@ } echo ''; //question list div + // Pagination navigation + $totalPages = ceil($nbrQuestions / $length); + echo ''; } else { echo Display::return_message(get_lang('Questions list (there is no question so far).'), 'warning'); } +} else { + echo Display::return_message(get_lang('Choose question type'), 'warning'); }