当前位置: 首页>>代码示例>>PHP>>正文


PHP SessionManager::get_session_by_course方法代码示例

本文整理汇总了PHP中SessionManager::get_session_by_course方法的典型用法代码示例。如果您正苦于以下问题:PHP SessionManager::get_session_by_course方法的具体用法?PHP SessionManager::get_session_by_course怎么用?PHP SessionManager::get_session_by_course使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionManager的用法示例。


在下文中一共展示了SessionManager::get_session_by_course方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_exercise_progress

 /**
  * Get the progress of a exercise
  * @param   int $sessionId  The session ID (session.id)
  * @param   int $courseId   The course ID (course.id)
  * @param   int $exerciseId The quiz ID (c_quiz.id)
  * @param   int $answer     The answer status (0 = incorrect, 1 = correct, 2 = both)
  * @param   array   $options    An array of options you can pass to the query (limit, where and order)
  * @return array An array with the data of exercise(s) progress
  */
 public static function get_exercise_progress($sessionId = 0, $courseId = 0, $exerciseId = 0, $date_from = null, $date_to = null, $options = array())
 {
     $sessionId = intval($sessionId);
     $courseId = intval($courseId);
     $exerciseId = intval($exerciseId);
     $date_from = Database::escape_string($date_from);
     $date_to = Database::escape_string($date_to);
     /*
      * This method gets the data by blocks, as previous attempts at one single
      * query made it take ages. The logic of query division is described below
      */
     // Get tables names
     $tuser = Database::get_main_table(TABLE_MAIN_USER);
     $tquiz = Database::get_course_table(TABLE_QUIZ_TEST);
     $tquiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $tquiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $tquiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $ttrack_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $ttrack_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $sessions = array();
     $courses = array();
     // if session ID is defined but course ID is empty, get all the courses
     // from that session
     if (!empty($sessionId) && empty($courseId)) {
         // $courses is an array of course int id as index and course details hash as value
         $courses = SessionManager::get_course_list_by_session_id($sessionId);
         $sessions[$sessionId] = api_get_session_info($sessionId);
     } elseif (empty($sessionId) && !empty($courseId)) {
         // if, to the contrary, course is defined but not sessions, get the sessions that include this course
         // $sessions is an array like: [0] => ('id' => 3, 'name' => 'Session 35'), [1] => () etc;
         $course = api_get_course_info_by_id($courseId);
         $sessionsTemp = SessionManager::get_session_by_course($courseId);
         $courses[$courseId] = $course;
         foreach ($sessionsTemp as $sessionItem) {
             $sessions[$sessionItem['id']] = $sessionItem;
         }
     } elseif (!empty($courseId) && !empty($sessionId)) {
         //none is empty
         $course = api_get_course_info_by_id($courseId);
         $courses[$courseId] = array($course['code']);
         $courses[$courseId]['code'] = $course['code'];
         $sessions[$sessionId] = api_get_session_info($sessionId);
     } else {
         //both are empty, not enough data, return an empty array
         return array();
     }
     // Now we have two arrays of courses and sessions with enough data to proceed
     // If no course could be found, we shouldn't return anything.
     // Sessions can be empty (then we only return the pure-course-context results)
     if (count($courses) < 1) {
         return array();
     }
     $data = array();
     // The following loop is less expensive than what it seems:
     // - if a course was defined, then we only loop through sessions
     // - if a session was defined, then we only loop through courses
     // - if a session and a course were defined, then we only loop once
     foreach ($courses as $courseIdx => $courseData) {
         $where = '';
         $whereParams = array();
         $whereSessionParams = '';
         if (count($sessions > 0)) {
             foreach ($sessions as $sessionIdx => $sessionData) {
                 if (!empty($sessionIdx)) {
                     $whereSessionParams .= $sessionIdx . ',';
                 }
             }
             $whereSessionParams = substr($whereSessionParams, 0, -1);
         }
         if (!empty($exerciseId)) {
             $exerciseId = intval($exerciseId);
             $where .= ' AND q.id = %d ';
             $whereParams[] = $exerciseId;
         }
         /*
          * This feature has been disabled for now, to avoid having to
          * join two very large tables
         //2 = show all questions (wrong and correct answered)
         if ($answer != 2) {
             $answer = intval($answer);
             //$where .= ' AND qa.correct = %d';
             //$whereParams[] = $answer;
         }
         */
         $limit = '';
         if (!empty($options['limit'])) {
             $limit = " LIMIT " . $options['limit'];
         }
         if (!empty($options['where'])) {
             $where .= ' AND ' . Database::escape_string($options['where']);
         }
//.........这里部分代码省略.........
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:tracking.lib.php

示例2: array

        ',',
        false
    );
}

if (!empty($teacherList)) {
    echo Display::page_subheader2(get_lang('Teachers'));
    echo $teacherList;
}

if (!empty($coaches)) {
    echo Display::page_subheader2(get_lang('Coaches'));
    echo $coaches;
}

$sessionList = SessionManager::get_session_by_course($courseInfo['code']);
if (!empty($sessionList)) {
    echo Display::page_subheader2(get_lang('SessionList'));
    $sessionToShow = array();
    foreach ($sessionList as $session) {
        $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'].'&cidReq='.$courseInfo['code'];
        $sessionToShow[] = Display::url($session['name'], $url);
    }
    echo implode(', ', $sessionToShow);
}

echo Display::page_subheader2(get_lang('StudentList'));

// PERSON_NAME_DATA_EXPORT is buggy
$is_western_name_order = api_is_western_name_order();
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:30,代码来源:courseLog.php

示例3: updateVisibilityFromAllSessions

 /**
  * @param array $courseInfo
  * @param int $id doc id
  * @param string $visibility visible/invisible
  * @param int $userId
  */
 public static function updateVisibilityFromAllSessions($courseInfo, $id, $visibility, $userId)
 {
     $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
     if (!empty($sessionList)) {
         foreach ($sessionList as $session) {
             $sessionId = $session['id'];
             api_item_property_update($courseInfo, TOOL_DOCUMENT, $id, $visibility, $userId, null, null, null, null, $sessionId);
         }
     }
 }
开发者ID:daffef,项目名称:chamilo-lms,代码行数:16,代码来源:document.lib.php

示例4: get_lang

    $table->set_header(0, get_lang('OfficialCode'), true);
    if ($is_western_name_order) {
        $table->set_header(1, get_lang('FirstName'), true);
        $table->set_header(2, get_lang('LastName'), true);
    } else {
        $table->set_header(1, get_lang('LastName'), true);
        $table->set_header(2, get_lang('FirstName'), true);
    }
    $table->set_header(3, get_lang('Email'), true);
    $table->set_header(4, get_lang('Status'), true);
    $table->set_header(5, '', false);
    $table->display();
} else {
    echo get_lang('NoUsersInCourse');
}
$session_list = SessionManager::get_session_by_course($course->code);
$url = api_get_path(WEB_CODE_PATH);
if (!empty($session_list)) {
    foreach ($session_list as &$session) {
        $session[0] = Display::url($session[0], $url . 'admin/resume_session.php?id_session=' . $session['id']);
        unset($session[1]);
    }
    echo Display::page_header(get_lang('Sessions'));
    $table = new SortableTableFromArray($session_list, 0, 20, 'user_table');
    $table->display();
}
/*$group = new UserGroup();
$usegroups = $group->get_usergroup_by_course($course->id);*/
/*@todo This should be dissapear classes are a deprecated feature*/
/*
//Show all classes subscribed in this course
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:course_information.php

示例5: updateTeachers

 /**
  * @param int $courseId
  * @param array $teachers
  * @param bool $deleteTeachersNotInList
  * @param bool $editTeacherInSessions
  * @param bool $deleteSessionTeacherNotInList
  * @return bool
  */
 public static function updateTeachers($courseId, $teachers, $deleteTeachersNotInList = true, $editTeacherInSessions = false, $deleteSessionTeacherNotInList = false, $teacherBackup = array())
 {
     if (empty($teachers)) {
         return false;
     }
     if (!is_array($teachers)) {
         $teachers = array($teachers);
     }
     $courseId = intval($courseId);
     $courseInfo = api_get_course_info_by_id($courseId);
     $course_code = $courseInfo['code'];
     $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $alreadyAddedTeachers = CourseManager::getTeacherListFromCourse($course_code);
     if ($deleteTeachersNotInList) {
         // Delete only teacher relations that doesn't match the selected teachers
         $cond = null;
         if (count($teachers) > 0) {
             foreach ($teachers as $key) {
                 $key = Database::escape_string($key);
                 $cond .= " AND user_id <> '" . $key . "'";
             }
         }
         $sql = 'DELETE FROM ' . $course_user_table . '
                 WHERE c_id ="' . $courseId . '" AND status="1" AND relation_type = 0 ' . $cond;
         Database::query($sql);
     }
     if (count($teachers) > 0) {
         foreach ($teachers as $userId) {
             $userId = intval($userId);
             // We check if the teacher is already subscribed in this course
             $sql = 'SELECT 1 FROM ' . $course_user_table . '
                     WHERE user_id = "' . $userId . '" AND c_id = "' . $courseId . '" ';
             $result = Database::query($sql);
             if (Database::num_rows($result)) {
                 $sql = 'UPDATE ' . $course_user_table . ' SET status = "1"
                         WHERE c_id = "' . $courseId . '" AND user_id = "' . $userId . '"  ';
             } else {
                 $userCourseCategory = '0';
                 if (isset($teacherBackup[$userId]) && isset($teacherBackup[$userId][$course_code])) {
                     $courseUserData = $teacherBackup[$userId][$course_code];
                     $userCourseCategory = $courseUserData['user_course_cat'];
                 }
                 $sql = "INSERT INTO " . $course_user_table . " SET\n                            c_id = " . $courseId . ",\n                            user_id = " . $userId . ",\n                            status = '1',\n                            is_tutor = '0',\n                            sort = '0',\n                            relation_type = '0',\n                            user_course_cat = '{$userCourseCategory}'\n                    ";
             }
             Database::query($sql);
         }
     }
     if ($editTeacherInSessions) {
         $sessions = SessionManager::get_session_by_course($courseId);
         if (!empty($sessions)) {
             foreach ($sessions as $session) {
                 // Remove old and add new
                 if ($deleteSessionTeacherNotInList) {
                     foreach ($teachers as $userId) {
                         SessionManager::set_coach_to_course_session($userId, $session['id'], $courseId);
                     }
                     $teachersToDelete = array();
                     if (!empty($alreadyAddedTeachers)) {
                         $teachersToDelete = array_diff(array_keys($alreadyAddedTeachers), $teachers);
                     }
                     if (!empty($teachersToDelete)) {
                         foreach ($teachersToDelete as $userId) {
                             SessionManager::set_coach_to_course_session($userId, $session['id'], $courseId, true);
                         }
                     }
                 } else {
                     // Add new teachers only
                     foreach ($teachers as $userId) {
                         SessionManager::set_coach_to_course_session($userId, $session['id'], $courseId);
                     }
                 }
             }
         }
     }
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:83,代码来源:course.lib.php

示例6: get_lang

$tool_name = get_lang('DocumentQuota');
$interbreadcrumb[] = array('url' => 'document.php', 'name' => get_lang('Documents'));
$htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.js');
$htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.pieRenderer.js');
$htmlHeadXtra[] = api_get_js('jqplot/plugins/jqplot.donutRenderer.js');
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH) . 'javascript/jqplot/jquery.jqplot.css');
$course_code = api_get_course_id();
$course_id = api_get_course_int_id();
$session_id = api_get_session_id();
$group_id = api_get_group_id();
$user_id = api_get_user_id();
$user_info = api_get_user_info($user_id);
$session = array();
$user_name = $user_info['complete_name'];
$course_list = SessionManager::get_course_list_by_session_id($session_id);
$session_list = SessionManager::get_session_by_course($course_id);
$total_quota_bytes = DocumentManager::get_course_quota();
$quota_bytes = DocumentManager::documents_total_space($course_id, 0, 0);
$quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
$session[] = array(get_lang('Course') . ' (' . format_file_size($quota_bytes) . ')', $quota_percentage);
$used_quota_bytes = $quota_bytes;
if (!empty($session_list)) {
    foreach ($session_list as $session_data) {
        $quota_percentage = 0;
        $quota_bytes = intval(DocumentManager::documents_total_space($course_id, null, $session_data['id']));
        if (!empty($quota_bytes)) {
            $quota_percentage = round($quota_bytes / $total_quota_bytes, 2) * 100;
        }
        if ($session_id == $session_data['id']) {
            $session_data['name'] = $session_data['name'] . ' * ';
        }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:31,代码来源:document_quota.php

示例7: get_lang

$form->addText('title', get_lang('Title'), true);
$form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
// Code
$element = $form->addElement('text', 'real_code', array(get_lang('CourseCode'), get_lang('ThisValueCantBeChanged')));
$element->freeze();
// Visual code
$form->addText('visual_code', array(get_lang('VisualCode'), get_lang('OnlyLettersAndNumbers'), get_lang('ThisValueIsUsedInTheCourseURL')), true, ['maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')]);
$form->applyFilter('visual_code', 'strtoupper');
$form->applyFilter('visual_code', 'html_filter');
$form->addElement('advmultiselect', 'course_teachers', get_lang('CourseTeachers'), $allTeachers);
$courseInfo['course_teachers'] = $course_teachers;
if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
    $form->addElement('checkbox', 'add_teachers_to_sessions_courses', null, get_lang('TeachersWillBeAddedAsCoachInAllCourseSessions'));
}
$coursesInSession = SessionManager::get_session_by_course($courseInfo['real_id']);
if (!empty($coursesInSession)) {
    foreach ($coursesInSession as $session) {
        $sessionId = $session['id'];
        $coaches = SessionManager::getCoachesByCourseSession($sessionId, $courseInfo['real_id']);
        $teachers = $allTeachers;
        $sessionTeachers = array();
        foreach ($coaches as $coachId) {
            $userInfo = api_get_user_info($coachId);
            $sessionTeachers[] = $coachId;
            if (isset($teachers[$coachId])) {
                unset($teachers[$coachId]);
            }
        }
        $groupName = 'session_coaches[' . $sessionId . ']';
        $platformTeacherId = 'platform_teachers_by_session_' . $sessionId;
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:31,代码来源:course_edit.php

示例8: send

 /**
  * Send emails to users.
  * @param bool $sendToUsersInSession
  * @param bool $sendToDrhUsers send a copy of the message to the DRH users
  * related to the main user
  */
 public function send($sendToUsersInSession = false, $sendToDrhUsers = false)
 {
     $sender = $this->sender();
     $subject = $this->subject();
     // Send email one by one to avoid antispam
     $users = $this->sent_to();
     foreach ($users as $user) {
         $message = $this->message($user['user_id']);
         MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id'], $sendToDrhUsers, true);
     }
     if ($sendToUsersInSession) {
         $sessionList = SessionManager::get_session_by_course($this->course['real_id']);
         if (!empty($sessionList)) {
             foreach ($sessionList as $sessionInfo) {
                 $sessionId = $sessionInfo['id'];
                 $message = $this->message(null, $sessionId);
                 $userList = CourseManager::get_user_list_from_course_code($this->course['code'], $sessionId);
                 if (!empty($userList)) {
                     foreach ($userList as $user) {
                         MessageManager::send_message_simple($user['user_id'], $subject, $message, $sender['user_id'], false, true);
                     }
                 }
             }
         }
     }
     $this->log_mail_sent();
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:33,代码来源:AnnouncementEmail.php

示例9: get_lang

}
$withFilter = false;
$reportTitle = get_lang('TimeReportIncludingAllCoursesAndSessionsByTeacher');
$reportSubTitle = sprintf(get_lang('TimeSpentBetweenXAndY'), $selectedFrom, $selectedUntil);
$timeReport = new TeacherTimeReport();
if (!empty($selectedCourse)) {
    $withFilter = true;
    $course = api_get_course_info($selectedCourse);
    $reportTitle = sprintf(get_lang('TimeReportForCourseX'), $course['title']);
    $teachers = CourseManager::getTeacherListFromCourse($course['real_id']);
    foreach ($teachers as $teacher) {
        $totalTime = UserManager::getTimeSpentInCourses($teacher['user_id'], $course['real_id'], 0, $selectedFrom, $selectedUntil);
        $formattedTime = api_format_time($totalTime);
        $timeReport->data[] = array('session' => null, 'course' => array('id' => $course['real_id'], 'name' => $course['title']), 'coach' => array('userId' => $teacher['user_id'], 'lastname' => $teacher['lastname'], 'firstname' => $teacher['firstname'], 'username' => $teacher['username'], 'completeName' => api_get_person_name($teacher['firstname'], $teacher['lastname'])), 'totalTime' => $formattedTime);
    }
    $sessionsByCourse = SessionManager::get_session_by_course($course['real_id']);
    foreach ($sessionsByCourse as $session) {
        $coaches = CourseManager::get_coachs_from_course($session['id'], $course['real_id']);
        if ($coaches) {
            foreach ($coaches as $coach) {
                $totalTime = UserManager::getTimeSpentInCourses($coach['user_id'], $course['real_id'], $session['id'], $selectedFrom, $selectedUntil);
                $formattedTime = api_format_time($totalTime);
                $timeReport->data[] = array('session' => array('id' => $session['id'], 'name' => $session['name']), 'course' => array('id' => $course['real_id'], 'name' => $course['title']), 'coach' => array('userId' => $coach['user_id'], 'lastname' => $coach['lastname'], 'firstname' => $coach['firstname'], 'username' => $coach['username'], 'completeName' => api_get_person_name($coach['firstname'], $coach['lastname'])), 'totalTime' => $formattedTime);
            }
        }
    }
}
if (!empty($selectedSession)) {
    $withFilter = true;
    $session = api_get_session_info($selectedSession);
    $sessionData = array('id' => $session['id'], 'name' => $session['name']);
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:31,代码来源:teacher_time_report.php

示例10: get_lang

\t\t<div class="controls">
\t\t\t<table cellpadding="0" cellspacing="0">
\t\t\t\t<tr>
\t\t\t\t\t<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->\t<td>{element}</td>
\t\t\t\t</tr>
\t\t\t</table>
\t\t</div>
\t</div>
EOT;
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate($element_template, 'group');
$form->addGroup($group, 'group', get_lang('CourseTeachers'), '</td><td width="80" align="center">' . '<input class="arrowr" style="width:30px;height:30px;padding-right:12px" type="button" onclick="moveItem(document.getElementById(\'platform_teachers\'), document.getElementById(\'course_teachers\'))"><br><br>' . '<input class="arrowl" style="width:30px;height:30px;padding-left:13px" type="button" onclick="moveItem(document.getElementById(\'course_teachers\'), document.getElementById(\'platform_teachers\'))"></td><td>');
if (array_key_exists('add_teachers_to_sessions_courses', $course)) {
    $form->addElement('checkbox', 'add_teachers_to_sessions_courses', null, get_lang('TeachersWillBeAddedAsCoachInAllCourseSessions'));
}
$coursesInSession = SessionManager::get_session_by_course($course['code']);
if (!empty($coursesInSession)) {
    foreach ($coursesInSession as $session) {
        $sessionId = $session['id'];
        $coaches = SessionManager::getCoachesByCourseSession($sessionId, $course['code']);
        $teachers = $allTeachers;
        $sessionTeachers = array();
        foreach ($coaches as $coachId) {
            $userInfo = api_get_user_info($coachId);
            $sessionTeachers[$coachId] = $userInfo['complete_name'];
            if (isset($teachers[$coachId])) {
                unset($teachers[$coachId]);
            }
        }
        $groupName = 'session_coaches[' . $sessionId . ']';
        $platformTeacherId = 'platform_teachers_by_session_' . $sessionId;
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:course_edit.php

示例11: addAnnouncementToAllUsersInSessions

 /**
  * @param int $announcementId
  */
 public static function addAnnouncementToAllUsersInSessions($announcementId)
 {
     $courseCode = api_get_course_id();
     $_course = api_get_course_info();
     $sessionList = SessionManager::get_session_by_course(api_get_course_int_id());
     if (!empty($sessionList)) {
         foreach ($sessionList as $sessionInfo) {
             $sessionId = $sessionInfo['id'];
             $userList = CourseManager::get_user_list_from_course_code($courseCode, $sessionId);
             if (!empty($userList)) {
                 foreach ($userList as $user) {
                     api_item_property_update($_course, TOOL_ANNOUNCEMENT, $announcementId, "AnnouncementUpdated", api_get_user_id(), 0, $user['user_id'], 0, 0, $sessionId);
                 }
             }
         }
     }
 }
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:20,代码来源:AnnouncementManager.php

示例12: get_lang

    $table->set_header(0, get_lang('OfficialCode'), true);
    if ($is_western_name_order) {
        $table->set_header(1, get_lang('FirstName'), true);
        $table->set_header(2, get_lang('LastName'), true);
    } else {
        $table->set_header(1, get_lang('LastName'), true);
        $table->set_header(2, get_lang('FirstName'), true);
    }
    $table->set_header(3, get_lang('Email'), true);
    $table->set_header(4, get_lang('Status'), true);
    $table->set_header(5, '', false);
    $table->display();
} else {
    echo Display::display_warning_message(get_lang('NoUsersInCourse'));
}
$session_list = SessionManager::get_session_by_course($course_info['real_id']);
$url = api_get_path(WEB_CODE_PATH);
if (!empty($session_list)) {
    foreach ($session_list as &$session) {
        $session[0] = Display::url($session[0], $url . 'admin/resume_session.php?id_session=' . $session['id']);
        unset($session[1]);
    }
    echo Display::page_subheader(get_lang('Sessions'));
    $table = new SortableTableFromArray($session_list, 0, 20, 'user_table');
    $table->display();
}
$extra_field = new ExtraField('course');
$extra_fields = $extra_field->get_all();
if (!empty($extra_fields)) {
    echo Display::page_subheader(get_lang('ExtraFields'));
    echo '<table class="data_table">';
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:31,代码来源:course_information.php

示例13: updateTeachers

 /**
  * @param string $course_code
  * @param array $teachers
  * @param bool $deleteTeachersNotInList
  * @param bool $editTeacherInSessions
  * @param bool $deleteSessionTeacherNotInList
  * @return bool
  */
 public static function updateTeachers($course_code, $teachers, $deleteTeachersNotInList = true, $editTeacherInSessions = false, $deleteSessionTeacherNotInList = false)
 {
     if (empty($teachers)) {
         return false;
     }
     if (!is_array($teachers)) {
         $teachers = array($teachers);
     }
     $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $alreadyAddedTeachers = CourseManager::get_teacher_list_from_course_code($course_code);
     if ($deleteTeachersNotInList) {
         // Delete only teacher relations that doesn't match the selected teachers
         $cond = null;
         if (count($teachers) > 0) {
             foreach ($teachers as $key) {
                 $key = Database::escape_string($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);
     }
     if (count($teachers) > 0) {
         foreach ($teachers as $userId) {
             $userId = intval($userId);
             // We check if the teacher is already subscribed in this course
             $sql = 'SELECT 1 FROM ' . $course_user_table . '
                     HERE user_id = "' . $userId . '" AND course_code = "' . $course_code . '" ';
             $result = Database::query($sql);
             if (Database::num_rows($result)) {
                 $sql = 'UPDATE ' . $course_user_table . ' SET status = "1"
                         WHERE course_code = "' . $course_code . '" AND user_id = "' . $userId . '"  ';
             } else {
                 $sql = "INSERT INTO " . $course_user_table . " SET\n                        course_code = '" . Database::escape_string($course_code) . "',\n                        user_id = '" . $userId . "',\n                        status = '1',\n                        role = '',\n                        tutor_id = '0',\n                        sort = '0',\n                        user_course_cat='0'";
             }
             Database::query($sql);
         }
     }
     if ($editTeacherInSessions) {
         $sessions = SessionManager::get_session_by_course($course_code);
         if (!empty($sessions)) {
             foreach ($sessions as $session) {
                 // Remove old and add new
                 if ($deleteSessionTeacherNotInList) {
                     foreach ($teachers as $userId) {
                         SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
                     }
                     $teachersToDelete = array();
                     if (!empty($alreadyAddedTeachers)) {
                         $teachersToDelete = array_diff(array_keys($alreadyAddedTeachers), $teachers);
                     }
                     if (!empty($teachersToDelete)) {
                         foreach ($teachersToDelete as $userId) {
                             SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code, true);
                         }
                     }
                 } else {
                     // Add new teachers only
                     foreach ($teachers as $userId) {
                         SessionManager::set_coach_to_course_session($userId, $session['id'], $course_code);
                     }
                 }
             }
         }
     }
 }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:75,代码来源:course.lib.php


注:本文中的SessionManager::get_session_by_course方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。