-
Notifications
You must be signed in to change notification settings - Fork 522
Quiz: reimplement export all result functionnality from 1.11.x - refs #6837 #6918
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
Merged
+237
−0
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
819031d
Refactor: use the old version of the file to add the page export_exer…
c9468a0
Minor: Adjust height and line height for the select
125527c
Minor: changing error messages
f9cf3c0
Update quiz repository retrieval in export script
christianbeeznest 895011b
Remove getCQuizRepository method
christianbeeznest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| <?php | ||
| /* For licensing terms, see /license.txt */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Chamilo\CoreBundle\Framework\Container; | ||
|
|
||
| $cidReset = true; | ||
| require_once __DIR__ . '/../inc/global.inc.php'; | ||
|
|
||
| api_protect_admin_script(true); | ||
|
|
||
| // Setting the section (for the tabs). | ||
| $this_section = SECTION_PLATFORM_ADMIN; | ||
|
|
||
| $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')]; | ||
|
|
||
| $toolName = get_lang('Export all exercise results'); | ||
|
|
||
| // Get request parameters | ||
| $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : null; | ||
| $courseId = isset($_GET['selected_course']) ? (int) $_GET['selected_course'] : null; | ||
| $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null; | ||
|
|
||
| // Get repositories | ||
| $user = api_get_user_entity(api_get_user_id()); | ||
| $sessionRepository = Container::getSessionRepository(); | ||
| $courseRepository = Container::getCourseRepository(); | ||
| $cQuizRepository = Container::getCQuizRepository(); | ||
|
|
||
| // Load sessions using repository | ||
| $sessionSelectList = [0 => get_lang('Select')]; | ||
| try { | ||
| if (api_is_platform_admin()) { | ||
| $sessionList = $sessionRepository->findAll(); | ||
| } else { | ||
| $sessionList = $sessionRepository->getSessionsByUser($user, api_get_url_entity())->getQuery()->getResult(); | ||
| } | ||
|
|
||
| foreach ($sessionList as $session) { | ||
| $sessionSelectList[$session->getId()] = $session->getTitle(); | ||
| } | ||
| } catch (Exception $e) { | ||
| error_log('Error loading sessions: ' . $e->getMessage()); | ||
| $sessionSelectList = [0 => get_lang('Error loading sessions')]; | ||
| } | ||
|
|
||
| // Load courses using repository based on selected session | ||
| $courseSelectList = [0 => get_lang('Select a session first')]; | ||
| if (!empty($sessionId) && $sessionId > 0) { | ||
| try { | ||
| $sessionEntity = $sessionRepository->find($sessionId); | ||
| if ($sessionEntity) { | ||
| $courseSelectList = [0 => get_lang('Select')]; | ||
| $sessionCourses = $sessionEntity->getCourses(); | ||
| foreach ($sessionCourses as $sessionCourse) { | ||
| $course = $sessionCourse->getCourse(); | ||
| $courseSelectList[$course->getId()] = $course->getTitle(); | ||
| } | ||
| } else { | ||
| $courseSelectList = [0 => get_lang('Session not found')]; | ||
| } | ||
| } catch (Exception $e) { | ||
| error_log('Error loading courses for session ' . $sessionId . ': ' . $e->getMessage()); | ||
| $courseSelectList = [0 => get_lang('Error loading courses')]; | ||
| } | ||
| } | ||
|
|
||
| // Load exercises using repository based on selected course and session | ||
| $exerciseSelectList = [0 => get_lang('Select a course first')]; | ||
| if (!empty($courseId) && $courseId > 0) { | ||
| try { | ||
| $courseEntity = $courseRepository->find($courseId); | ||
| $sessionEntity = $sessionId ? $sessionRepository->find($sessionId) : null; | ||
|
|
||
| if ($courseEntity) { | ||
| $exerciseList = $cQuizRepository->findAllByCourse($courseEntity, $sessionEntity); | ||
| $exerciseList = $exerciseList->getQuery()->getResult(); | ||
|
|
||
| if (!empty($exerciseList)) { | ||
| $exerciseSelectList = [0 => get_lang('Select')]; | ||
| foreach ($exerciseList as $exercise) { | ||
| $exerciseSelectList[$exercise->getIid()] = $exercise->getTitle(); | ||
| } | ||
| } else { | ||
| $exerciseSelectList = [0 => get_lang('No exercises found')]; | ||
| } | ||
| } else { | ||
| $exerciseSelectList = [0 => get_lang('Course not found')]; | ||
| } | ||
| } catch (Exception $e) { | ||
| error_log('Error loading exercises for course ' . $courseId . ': ' . $e->getMessage()); | ||
| $exerciseSelectList = [0 => get_lang('Error loading exercises')]; | ||
| } | ||
| } | ||
|
|
||
| // JavaScript for form submission (page reload on change) | ||
| $htmlHeadXtra[] = " | ||
| <style> | ||
| .select2-selection, .select2-selection__rendered { | ||
| height: 38px !important; | ||
| line-height: 38px !important; | ||
| } | ||
| </style> | ||
| <script> | ||
| $(document).ready(function() { | ||
| // Initialize Select2 | ||
| $('.select2').select2({ | ||
| width: '100%', | ||
| placeholder: '" . addslashes(get_lang('Select')) . "', | ||
| allowClear: true | ||
| }); | ||
| // Session change handler - reload page with new session | ||
| $('#session_id').on('change', function() { | ||
| var sessionId = $(this).val(); | ||
| if (sessionId && sessionId != '0') { | ||
| window.location.href = '" . api_get_self() . "?session_id=' + sessionId; | ||
| } else { | ||
| window.location.href = '" . api_get_self() . "'; | ||
| } | ||
| }); | ||
| // Course change handler - reload page with session and course | ||
| $('#selected_course').on('change', function() { | ||
| var courseId = $(this).val(); | ||
| var sessionId = $('#session_id').val() || 0; | ||
| if (courseId && courseId != '0') { | ||
| window.location.href = '" . api_get_self() . "?session_id=' + sessionId + '&selected_course=' + courseId; | ||
| } else if (sessionId && sessionId != '0') { | ||
| window.location.href = '" . api_get_self() . "?session_id=' + sessionId; | ||
| } else { | ||
| window.location.href = '" . api_get_self() . "'; | ||
| } | ||
| }); | ||
| }); | ||
| </script>"; | ||
|
|
||
| // Form creation | ||
| $form = new FormValidator('export_all_results_form', 'POST'); | ||
| $form->addHeader(get_lang('Export all exercise results')); | ||
|
|
||
| // Add form elements with Select2 | ||
| $form->addSelect( | ||
| 'session_id', | ||
| get_lang('Session'), | ||
| $sessionSelectList, | ||
| [ | ||
| 'id' => 'session_id', | ||
| 'class' => 'select2 form-control' | ||
| ] | ||
| )->setSelected($sessionId); | ||
|
|
||
| if (empty($sessionId) || $sessionId == 0) { | ||
| $form->addSelect( | ||
| 'selected_course', | ||
| get_lang('Course'), | ||
| $courseSelectList, | ||
| [ | ||
| 'id' => 'selected_course', | ||
| 'class' => 'select2 form-control', | ||
| 'disabled' => true | ||
| ] | ||
| ); | ||
| } else { | ||
| $form->addSelect( | ||
| 'selected_course', | ||
| get_lang('Course'), | ||
| $courseSelectList, | ||
| [ | ||
| 'id' => 'selected_course', | ||
| 'class' => 'select2 form-control', | ||
| ] | ||
| )->setSelected($courseId); | ||
| } | ||
|
|
||
| if (empty($courseId) || $courseId == 0) { | ||
| $form->addSelect( | ||
| 'exerciseId', | ||
| get_lang('Exercise'), | ||
| $exerciseSelectList, | ||
| [ | ||
| 'id' => 'exerciseId', | ||
| 'class' => 'select2 form-control', | ||
| 'disabled' => true | ||
| ] | ||
| ); | ||
| } else { | ||
| $form->addSelect( | ||
| 'exerciseId', | ||
| get_lang('Exercise'), | ||
| $exerciseSelectList, | ||
| [ | ||
| 'id' => 'exerciseId', | ||
| 'class' => 'select2 form-control', | ||
| ] | ||
| )->setSelected($exerciseId); | ||
| } | ||
|
|
||
| // Date filters | ||
| $form->addDateTimePicker('start_date', get_lang('Start date')); | ||
| $form->addDateTimePicker('end_date', get_lang('End date')); | ||
|
|
||
| // Validation rules | ||
| $form->addRule('session_id', get_lang('Required field'), 'required'); | ||
| $form->addRule('selected_course', get_lang('Required field'), 'required'); | ||
| $form->addRule('exerciseId', get_lang('Required field'), 'required'); | ||
|
|
||
| // Export button | ||
| $form->addButtonExport(get_lang('Export'), 'submit'); | ||
|
|
||
| // Process form submission | ||
| if ($form->validate()) { | ||
| $values = $form->getSubmitValues(); | ||
|
|
||
| $sessionId = (int) $values['session_id']; | ||
| $courseId = (int) $values['selected_course']; | ||
| $exerciseId = (int) $values['exerciseId']; | ||
|
|
||
| $filterDates = [ | ||
| 'start_date' => (!empty($values['start_date']) ? $values['start_date'] : ''), | ||
| 'end_date' => (!empty($values['end_date']) ? $values['end_date'] : ''), | ||
| ]; | ||
|
|
||
| try { | ||
| ExerciseLib::exportExerciseAllResultsZip($sessionId, $courseId, $exerciseId, $filterDates); | ||
| } catch (Exception $e) { | ||
| Display::addFlash(Display::return_message(get_lang('Export failed') . ': ' . $e->getMessage(), 'error')); | ||
| error_log('Exercise export error: ' . $e->getMessage()); | ||
| } | ||
| } | ||
|
|
||
| Display::display_header($toolName); | ||
|
|
||
| $form->display(); | ||
|
|
||
| Display::display_footer(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.