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

Internal: Add session replication, reinscription logic, and child session hierarchy for course expiration - refs BT#22057 #5831

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ba4e25b
Internal: Add session replication, reinscription logic, and child ses…
christianbeeznest Sep 30, 2024
c3312db
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Oct 9, 2024
7f6e7ae
Session: Add settings and interface fields for session and lesson fun…
christianbeeznest Oct 9, 2024
3f353ef
Resolved merge conflicts with upstream/master
christianbeeznest Oct 9, 2024
2bf9adf
Internal: Add missing settings in migration - refs BT#22057
christianbeeznest Nov 26, 2024
d507e64
Resolved merge conflicts with upstream/master
christianbeeznest Nov 27, 2024
66a227d
Internal: Fix error type for validity_id_days field
christianbeeznest Nov 27, 2024
42f207b
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Nov 27, 2024
353c19a
Internal: Fix session duplication and reinscription logic improvement…
christianbeeznest Nov 27, 2024
238cbdb
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Nov 28, 2024
e9cca0b
Internal: Improve session reinscription logic using direct CLpView va…
christianbeeznest Nov 28, 2024
9cbcca1
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Nov 29, 2024
ba09140
Internal: Fix session duplication and reinscription logic - refs BT#2…
christianbeeznest Nov 29, 2024
8f8fa4f
Adding changes from upstream/master
christianbeeznest Dec 4, 2024
7b66599
Internal: Implement automatic session repetition and coach notificati…
christianbeeznest Dec 4, 2024
ad82e0b
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Dec 18, 2024
3b34dc1
Internal: Reinscription logic updated to use sessions' validity and g…
christianbeeznest Dec 18, 2024
47b034c
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Dec 31, 2024
8ca3304
Internal: Fix gradebook duplication, session course inclusion, query …
christianbeeznest Dec 31, 2024
4bb5dc7
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest Jan 6, 2025
b21643c
Session: Adjust session-repetition logic and data association - refs …
christianbeeznest Jan 6, 2025
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
Prev Previous commit
Next Next commit
Adding changes from upstream/master
  • Loading branch information
christianbeeznest committed Dec 4, 2024
commit 8f8fa4f161f409549be9e18fe382b7c4b8ffbbd0
197 changes: 193 additions & 4 deletions public/main/inc/lib/sessionmanager.lib.php
Original file line number Diff line number Diff line change
@@ -232,9 +232,9 @@ public static function create_session(
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification)
->setNotifyBoss((bool) $notifyBoss)
->setParentId($parentId)
->setDaysToReinscription($daysBeforeFinishingForReinscription)
->setDaysToReinscription((int) $daysBeforeFinishingForReinscription)
->setLastRepetition($lastRepetition)
->setDaysToNewRepetition($daysBeforeFinishingToCreateNewRepetition);
->setDaysToNewRepetition((int) $daysBeforeFinishingToCreateNewRepetition);

foreach ($coachesId as $coachId) {
$session->addGeneralCoach(api_get_user_entity($coachId));
@@ -1877,9 +1877,9 @@ public static function edit_session(
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification)
->setNotifyBoss((bool) $notifyBoss)
->setParentId($parentId)
->setDaysToReinscription($daysBeforeFinishingForReinscription)
->setDaysToReinscription((int) $daysBeforeFinishingForReinscription)
->setLastRepetition($lastRepetition)
->setDaysToNewRepetition($daysBeforeFinishingToCreateNewRepetition)
->setDaysToNewRepetition((int) $daysBeforeFinishingToCreateNewRepetition)
->setAccessStartDate(null)
->setAccessStartDate(null)
->setDisplayStartDate(null)
@@ -8897,6 +8897,7 @@ public static function getGridColumns(
'name' => 'title',
'index' => 's.title',
'width' => '260px',
'width' => '300',
'align' => 'left',
'search' => 'true',
'searchoptions' => ['sopt' => $operators],
@@ -10332,4 +10333,192 @@ public static function getListOfParentSessions(): array

return $sessions;
}


/**
* Method to export sessions data as CSV
*/
public static function exportSessionsAsCSV(array $selectedSessions): void
{
$csvData = [];
$headersGenerated = false;
$csvHeaders = [];

foreach ($selectedSessions as $sessionId) {
$courses = SessionManager::get_course_list_by_session_id($sessionId);

if (!empty($courses)) {
foreach ($courses as $course) {
$courseCode = $course['course_code'];
$courseId = $course['id'];
$studentList = CourseManager::get_student_list_from_course_code(
$courseCode,
true,
$sessionId
);

$userIds = array_keys($studentList);

[$generatedHeaders, $csvContent] = self::generateSessionCourseReportData($sessionId, $courseId, $userIds);

if (!$headersGenerated) {
$csvHeaders = $generatedHeaders;
$headersGenerated = true;
}

foreach ($csvContent as $row) {
$csvData[] = $row;
}
}
}
}

if (!empty($csvData)) {
array_unshift($csvData, $csvHeaders);
$filename = 'export_session_courses_reports_complete_' . date('Y-m-d_H-i-s') . '.csv';
Export::arrayToCsvSimple($csvData, $filename);
exit;
}
}

/**
* Exports session data as a ZIP file with CSVs and sends it for download.
*/
public static function exportSessionsAsZip(array $sessionList): void
{
$tempZipFile = api_get_path(SYS_ARCHIVE_PATH) . api_get_unique_id() . '.zip';
$tempDir = dirname($tempZipFile);

if (!is_dir($tempDir) || !is_writable($tempDir)) {
exit("The directory for creating the ZIP file does not exist or lacks write permissions: $tempDir");
}

$zip = new \ZipArchive();
if ($zip->open($tempZipFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
exit("Unable to open the ZIP file for writing: $tempZipFile");
}

foreach ($sessionList as $sessionItemId) {
$courses = SessionManager::get_course_list_by_session_id($sessionItemId);

if (!empty($courses)) {
foreach ($courses as $course) {
$courseCode = $course['course_code'];
$courseId = $course['id'];
$studentList = CourseManager::get_student_list_from_course_code($courseCode, true, $sessionItemId);
$userIds = array_keys($studentList);

[$csvHeaders, $csvContent] = self::generateSessionCourseReportData($sessionItemId, $courseId, $userIds);
array_unshift($csvContent, $csvHeaders);

$sessionInfo = api_get_session_info($sessionItemId);
$courseInfo = api_get_course_info_by_id($courseId);
$csvFileName = $sessionInfo['name'] . '_' . $courseInfo['name'] . '.csv';

$csvFilePath = Export::arrayToCsvSimple($csvContent, $csvFileName, true);

if ($csvFilePath && file_exists($csvFilePath)) {
$zip->addFile($csvFilePath, $csvFileName);
}
}
}
}

if (!$zip->close()) {
exit("Could not close the ZIP file correctly.");
}

if (file_exists($tempZipFile)) {
DocumentManager::file_send_for_download($tempZipFile, true);
unlink($tempZipFile);
} else {
exit("The ZIP file was not created correctly.");
}
}

private static function generateSessionCourseReportData($sessionId, $courseId, $userIds): array
{
$em = Database::getManager();
$sessionRepository = $em->getRepository(Session::class);
$session = $sessionRepository->find($sessionId);

if (!$session instanceof Session) {
throw new \InvalidArgumentException("Invalid session object for session ID $sessionId");
}

$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];

$csvHeaders = [
get_lang('Session name'),
get_lang('Session access dates'),
get_lang('Session display dates'),
get_lang('Course name'),
get_lang('Official code'),
get_lang('First name'),
get_lang('Last name'),
get_lang('Login'),
get_lang('Training time'),
get_lang('Course progress'),
get_lang('Exercise progress'),
get_lang('Exercise average'),
get_lang('Score'),
get_lang('Score') . ' - ' . get_lang('Best attempt'),
get_lang('Student_publication'),
get_lang('Messages'),
get_lang('Classes'),
get_lang('Registration date'),
get_lang('First login in course'),
get_lang('Latest login in course'),
];

$csvData = TrackingCourseLog::getUserData(
null,
count($userIds),
null,
null,
[],
true,
true,
$courseCode,
$sessionId,
true,
$userIds
);

$rawCsvContent = ChamiloSession::read('csv_content');

if (empty($rawCsvContent)) {
throw new \RuntimeException("No CSV content found in session for course $courseCode and session $sessionId.");
}

$csvContent = [];
foreach ($rawCsvContent as $row) {
$alignedRow = [
$row['session_name'] ?? '',
$row['session_startdate'] ?? '',
$row['session_enddate'] ?? '',
$row['course_name'] ?? '',
$row['official_code'] ?? '',
$row['firstname'] ?? '',
$row['lastname'] ?? '',
$row['username'] ?? '',
$row['time'] ?? '',
$row['average_progress'] ?? '',
$row['exercise_progress'] ?? '',
$row['exercise_average'] ?? '',
$row['student_score'] ?? '',
$row['student_score_best'] ?? '',
$row['count_assignments'] ?? '',
$row['count_messages'] ?? '',
$row['classes'] ?? '',
$row['registered_at'] ?? '',
$row['first_connection'] ?? '',
$row['last_connection'] ?? '',
];
$csvContent[] = $alignedRow;
}

return [$csvHeaders, $csvContent];
}
}
1 change: 1 addition & 0 deletions public/phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php phpinfo(); ?>
Copy link

Choose a reason for hiding this comment

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

A closing tag is not permitted at the end of a PHP file

Copy link

Choose a reason for hiding this comment

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

A closing tag is not permitted at the end of a PHP file

Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.