Don't delete teachers

1.9.x
Julio Montoya 11 years ago
parent 77d22f7656
commit 2ee6607f14
  1. 2
      main/cron/import_csv.php
  2. 25
      main/inc/lib/course.lib.php

@ -552,7 +552,7 @@ class ImportCsv
);
$result = CourseManager::update_attributes($courseInfo['real_id'], $params);
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], true);
CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true);
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, $editTeacherInSessions = false)
public static function updateTeachers($course_code, $teachers, $deleteTeachersNotInList = true, $editTeacherInSessions = false)
{
if (empty($teachers)) {
@ -4013,16 +4013,19 @@ class CourseManager {
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
// Delete only teacher relations that doesn't match the selected teachers
$cond = null;
if (count($teachers)>0) {
foreach($teachers as $key) {
$cond.= " AND user_id <> '".$key."'";
if ($deleteTeachersNotInList) {
// Delete only teacher relations that doesn't match the selected teachers
$cond = null;
if (count($teachers)>0) {
foreach($teachers as $key) {
$cond.= " AND user_id <> '".$key."'";
}
}
}
$sql = 'DELETE FROM '.$course_user_table.' WHERE course_code="'.Database::escape_string($course_code).'" AND status="1"'.$cond;
Database::query($sql);
$sql = 'DELETE FROM '.$course_user_table.' WHERE course_code="'.Database::escape_string($course_code).'" AND status="1"'.$cond;
Database::query($sql);
}
if (count($teachers) > 0) {
foreach ($teachers as $key) {
@ -4053,7 +4056,7 @@ class CourseManager {
foreach ($teachers as $userId) {
SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
}
/*$teachersToDelete = array();
$teachersToDelete = array();
if (!empty($alreadyAddedTeachers)) {
$teachersToDelete = array_diff(array_keys($alreadyAddedTeachers), $teachers);
}
@ -4062,7 +4065,7 @@ class CourseManager {
foreach ($teachersToDelete as $userId) {
SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code, true);
}
}*/
}
}
}
}

Loading…
Cancel
Save