Fixing update teachers

1.9.x
Julio Montoya 11 years ago
parent 034ea8afb6
commit c6eb4750b8
  1. 2
      main/admin/course_edit.php
  2. 2
      main/cron/import_csv.php
  3. 27
      main/inc/lib/course.lib.php

@ -265,7 +265,7 @@ if ($form->validate()) {
}
}
CourseManager::updateTeachers($course_code, $teachers, $course['add_teachers_to_sessions']);
CourseManager::updateTeachers($course_code, $teachers, true, $course['add_teachers_to_sessions'], true);
$sql = "INSERT IGNORE INTO ".$course_user_table . " SET
course_code = '".Database::escape_string($course_code). "',

@ -552,7 +552,7 @@ class ImportCsv
);
$result = CourseManager::update_attributes($courseInfo['real_id'], $params);
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true);
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true, false);
if ($result) {
$this->logger->addInfo("Courses - Course updated ".$courseInfo['code']);

@ -3999,7 +3999,7 @@ class CourseManager {
* @param bool $editTeacherInSessions
* @return bool
*/
public static function updateTeachers($course_code, $teachers, $deleteTeachersNotInList = true, $editTeacherInSessions = false)
public static function updateTeachers($course_code, $teachers, $deleteTeachersNotInList = true, $editTeacherInSessions = false, $deleteSessionTeacherNotInList = false)
{
if (empty($teachers)) {
@ -4048,12 +4048,31 @@ class CourseManager {
}
if ($editTeacherInSessions) {
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
$sessions = SessionManager::get_session_by_course($course_code);
$alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
if (!empty($sessions)) {
foreach ($sessions as $session) {
foreach ($alreadyAddedTeachers as $userId => $userInfo) {
SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
// Remove old and add new
if ($deleteSessionTeacherNotInList) {
$coachList = SessionManager::get_users_by_session($session['id'], 2);
// Deleting old coaches
if (!empty($coachList)) {
foreach ($coachList as $coach) {
SessionManager::set_coach_to_course_session($coach['user_id'], $session['id'], $course_code, true);
}
}
// Adding new coaches
foreach ($teachers as $userId) {
SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
}
} else {
// Add new
foreach ($alreadyAddedTeachers as $userId => $userInfo) {
SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
}
}
}
}

Loading…
Cancel
Save