Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise: Fix broken presentation when editing exercises with more than 100 questions - refs BT#22237 #5954

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions public/main/exercise/question_list_admin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cast statement must be followed by a single space


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 = '<ul class="pagination">';
for ($i = 1; $i <= $data['pageCount']; $i++) {
$pageContent = '<li><a href="'.$url.'&page='.$i.'">'.$i.'</a></li>';
if ($data['current'] == $i) {
$pageContent = '<li class="active"><a href="#" >'.$i.'</a></li>';
}
$render .= $pageContent;
}
$render .= '</ul>';

return $render;
};
echo $pagination;
$questionList = $objExercise->selectQuestionList(true, true);
$questionList = array_slice($questionList, $start, $length);
} else {
// Classic order
$questionList = $objExercise->selectQuestionList(true, true);
Expand Down Expand Up @@ -331,7 +309,17 @@
}

echo '</div>'; //question list div
// Pagination navigation
$totalPages = ceil($nbrQuestions / $length);
echo '<div class="pagination flex justify-center mt-4">';
for ($i = 1; $i <= $totalPages; $i++) {
$isActive = ($i == $page) ? 'bg-primary text-white' : 'border-gray-300 text-gray-700 hover:bg-gray-200';
echo '<a href="?'.http_build_query(array_merge($_GET, ['page' => $i])).'" class="mx-1 px-4 py-2 border '.$isActive.' rounded">'.$i.'</a>';
}
echo '</div>';
} 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');
}
Loading