Skip to content

Commit

Permalink
Session: Fix session course position handling in CSV export/import - …
Browse files Browse the repository at this point in the history
…refs BT#22234
  • Loading branch information
christianbeeznest committed Dec 10, 2024
1 parent e11bb25 commit f846c25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 4 additions & 2 deletions main/inc/lib/sessionmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5084,7 +5084,7 @@ public static function importCSV(
}
}

$session_name = $enreg['SessionName'];
$session_name = trim(trim(api_utf8_decode($enreg['SessionName']), '"'));

if ($debug) {
$logger->addInfo('---------------------------------------');
Expand Down Expand Up @@ -5536,6 +5536,7 @@ public static function importCSV(
}
}

$position = 0;
foreach ($courses as $course) {
$courseArray = bracketsToArray($course);
$course_code = $courseArray[0];
Expand All @@ -5546,7 +5547,7 @@ public static function importCSV(

// Adding the course to a session.
$sql = "INSERT IGNORE INTO $tbl_session_course
SET c_id = '$courseId', session_id='$session_id'";
SET c_id = '$courseId', session_id='$session_id', position = '$position'";
Database::query($sql);

self::installCourse($session_id, $courseInfo['real_id']);
Expand Down Expand Up @@ -5934,6 +5935,7 @@ public static function importCSV(
}
}
$inserted_in_course[$course_code] = $courseInfo['title'];
$position++;
}
}
$access_url_id = api_get_current_access_url_id();
Expand Down
11 changes: 7 additions & 4 deletions main/session/session_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,13 @@
}

// Courses
$sql = "SELECT DISTINCT c.code, sc.c_id
FROM $tbl_course c
INNER JOIN $tbl_session_course_user sc
ON c.id = sc.c_id AND sc.session_id = '".$row['id']."'";
$sql = "SELECT DISTINCT c.code, sc.c_id, sr.position
FROM $tbl_course c
INNER JOIN $tbl_session_course_user sc
ON c.id = sc.c_id AND sc.session_id = '".$row['id']."'
INNER JOIN $tbl_session_course sr
ON sc.session_id = sr.session_id AND sc.c_id = sr.c_id
ORDER BY sr.position ASC";

$rsCourses = Database::query($sql);

Expand Down
8 changes: 5 additions & 3 deletions main/session/session_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@
foreach ($root->Session as $node_session) {
$course_counter = 0;
$user_counter = 0;

$session_name = trim(api_utf8_decode($node_session->SessionName));
$session_name = trim(trim(api_utf8_decode($node_session->SessionName), '"'));
$coach = UserManager::purify_username(
api_utf8_decode($node_session->Coach),
$purification_option_for_usernames
Expand Down Expand Up @@ -345,6 +344,7 @@
}

// Adding courses to a session.
$position = 0;
foreach ($node_session->Course as $node_course) {
$course_code = Database::escape_string(trim(api_utf8_decode($node_course->CourseCode)));
// Verify that the course pointed by the course code node exists.
Expand All @@ -357,7 +357,8 @@
if (!$session_course_relation) {
$sql_course = "INSERT INTO $tbl_session_course SET
c_id = $courseId,
session_id = $session_id";
session_id = $session_id,
position = $position";
$rs_course = Database::query($sql_course);
SessionManager::installCourse($session_id, $courseId);
}
Expand Down Expand Up @@ -408,6 +409,7 @@
$sql = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE c_id='$courseId'";
Database::query($sql);
$inserted_in_course[$course_code] = $course_info['title'];
$position++;
}
}
Database::query("UPDATE $tbl_session SET nbr_users='$user_counter', nbr_courses='$course_counter' WHERE id='$session_id'");
Expand Down

0 comments on commit f846c25

Please sign in to comment.