本文整理汇总了PHP中CourseManager::add_user_to_course方法的典型用法代码示例。如果您正苦于以下问题:PHP CourseManager::add_user_to_course方法的具体用法?PHP CourseManager::add_user_to_course怎么用?PHP CourseManager::add_user_to_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CourseManager
的用法示例。
在下文中一共展示了CourseManager::add_user_to_course方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subscribe_user
/**
* Subscribe the user to a given course
* @param string Course code
* @return string Message about results
*/
public function subscribe_user($course_code)
{
$user_id = api_get_user_id();
$all_course_information = CourseManager::get_course_information($course_code);
if ($all_course_information['registration_code'] == '' || $_POST['course_registration_code'] == $all_course_information['registration_code']) {
if (api_is_platform_admin()) {
$status_user_in_new_course = COURSEMANAGER;
} else {
$status_user_in_new_course = null;
}
if (CourseManager::add_user_to_course($user_id, $course_code, $status_user_in_new_course)) {
$send = api_get_course_setting('email_alert_to_teacher_on_new_user_in_course', $course_code);
if ($send == 1) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = false);
} else {
if ($send == 2) {
CourseManager::email_to_tutor($user_id, $course_code, $send_to_tutor_also = true);
}
}
$url = Display::url($all_course_information['title'], api_get_course_url($course_code));
$message = sprintf(get_lang('EnrollToCourseXSuccessful'), $url);
} else {
$message = get_lang('ErrorContactPlatformAdmin');
}
return array('message' => $message);
} else {
if (isset($_POST['course_registration_code']) && $_POST['course_registration_code'] != $all_course_information['registration_code']) {
return false;
}
$message = get_lang('CourseRequiresPassword') . '<br />';
$message .= $all_course_information['title'] . ' (' . $all_course_information['visual_code'] . ') ';
$action = api_get_path(WEB_CODE_PATH) . "auth/courses.php?action=subscribe_user_with_password&sec_token=" . $_SESSION['sec_token'];
$form = new FormValidator('subscribe_user_with_password', 'post', $action);
$form->addElement('hidden', 'sec_token', $_SESSION['sec_token']);
$form->addElement('hidden', 'subscribe_user_with_password', $all_course_information['code']);
$form->addElement('text', 'course_registration_code');
$form->addButton(get_lang('SubmitRegistrationCode'));
$content = $form->returnForm();
return array('message' => $message, 'content' => $content);
}
}
示例2: WSSubscribeUserToCourseSimple
function WSSubscribeUserToCourseSimple($params)
{
global $debug;
if ($debug) {
error_log('WSSubscribeUserToCourseSimple');
}
if ($debug) {
error_log('Params ' . print_r($params, 1));
}
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
$result = array();
$course_code = $params['course'];
//Course code
$user_id = $params['user_id'];
//chamilo user id
$status = STUDENT;
// Get user id
$user_data = api_get_user_info($user_id);
if (empty($user_data)) {
// If user was not found, there was a problem
$result = "User {$user_id} does not exist";
if ($debug) {
error_log($result);
}
return $result;
}
if (!empty($course_code)) {
$course_data = CourseManager::get_course_information($course_code);
if (empty($course_data)) {
// Course was not found
$result = "Course {$course_code} does not exist in the platform ";
if ($debug) {
error_log($result);
}
} else {
if ($debug) {
error_log('Try to register: user_id= ' . $user_id . ' to course: ' . $course_data['code']);
}
if (!CourseManager::add_user_to_course($user_id, $course_data['code'], $status)) {
$result = 'User was not registered possible reasons: User already registered to the course, Course visibility doesnt allow user subscriptions ';
if ($debug) {
error_log($result);
}
} else {
if ($debug) {
error_log('User registered to the course: ' . $course_data['code']);
}
$result = 1;
}
}
}
return $result;
}
示例3: subscribe_user
/**
* Subscribe a user to a course. No checks are performed here to see if
* course subscription is allowed.
* @param int User ID
* @param string Course code
* @param int Status (STUDENT, COURSEMANAGER, COURSE_ADMIN, NORMAL_COURSE_MEMBER)
* @return bool True on success, false on failure
* @see add_user_to_course
* @assert ('', '') === false
*/
public static function subscribe_user($user_id, $course_code, $status = STUDENT, $session_id = 0, $userCourseCategoryId = 0)
{
if ($user_id != strval(intval($user_id))) {
return false;
//detected possible SQL injection
}
$course_code = Database::escape_string($course_code);
$courseInfo = api_get_course_info($course_code);
$courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
$userCourseCategoryId = intval($userCourseCategoryId);
if (empty($user_id) || empty($course_code)) {
return false;
}
if (!empty($session_id)) {
$session_id = intval($session_id);
} else {
$session_id = api_get_session_id();
}
$status = $status == STUDENT || $status == COURSEMANAGER ? $status : STUDENT;
//$role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;
// A preliminary check whether the user has bben already registered on the platform.
if (Database::num_rows(Database::query("SELECT status FROM " . Database::get_main_table(TABLE_MAIN_USER) . "\n WHERE user_id = '{$user_id}' ")) == 0) {
return false;
// The user has not been registered to the platform.
}
// Check whether the user has not been already subscribed to the course.
if (empty($session_id)) {
if (Database::num_rows(Database::query("\n SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "\n WHERE user_id = '{$user_id}' AND relation_type<>" . COURSE_RELATION_TYPE_RRHH . " AND c_id = '{$courseId}'")) > 0) {
// The user has been already subscribed to the course.
return false;
}
}
if (!empty($session_id)) {
SessionManager::subscribe_users_to_session_course(array($user_id), $session_id, $courseCode);
} else {
CourseManager::add_user_to_course($user_id, $courseCode, $status);
// Add event to the system log
Event::addEvent(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_COURSE_CODE, $course_code, api_get_utc_datetime(), api_get_user_id());
$user_info = api_get_user_info($user_id);
Event::addEvent(LOG_SUBSCRIBE_USER_TO_COURSE, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), api_get_user_id());
}
return true;
}
示例4: subscribe_user
/**
* Regiser a user to a course.
* Returns true on success, false otherwise.
*
* @param string $course_code
* @param string $registration_code
* @param int $user_id
* @return bool
*/
function subscribe_user($course_code, $registration_code = '', $user_id = null)
{
$course = $this->retrieve_course($course_code);
$course_regisration_code = $course['registration_code'];
if (!empty($course_regisration_code) && $registration_code != $course_regisration_code) {
return false;
}
if (empty($user_id)) {
global $_user;
$user_id = $_user['user_id'];
}
return (bool) CourseManager::add_user_to_course($user_id, $course_code);
}
示例5: save_data
/**
* Saves imported data.
*/
function save_data($users_courses)
{
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$csv_data = array();
foreach ($users_courses as $user_course) {
$csv_data[$user_course['UserName']][$user_course['CourseCode']] = $user_course['Status'];
}
foreach ($csv_data as $username => $csv_subscriptions) {
$sql = "SELECT * FROM {$user_table} u WHERE u.username = '" . Database::escape_string($username) . "'";
$res = Database::query($sql);
$obj = Database::fetch_object($res);
$user_id = $obj->user_id;
$sql = "SELECT * FROM {$course_user_table} cu\n\t\t WHERE cu.user_id = {$user_id} AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . " ";
$res = Database::query($sql);
$db_subscriptions = array();
while ($obj = Database::fetch_object($res)) {
$db_subscriptions[$obj->c_id] = $obj->status;
}
$csvCourseList = array();
foreach ($csv_subscriptions as $courseCode => $status) {
$courseInfo = api_get_course_info($courseCode);
if ($courseInfo) {
$csvCourseList[$courseInfo['real_id']] = $status;
}
}
$to_subscribe = array_diff(array_keys($csvCourseList), array_keys($db_subscriptions));
$to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csvCourseList));
global $inserted_in_course;
if (!isset($inserted_in_course)) {
$inserted_in_course = array();
}
if (isset($_POST['subscribe']) && $_POST['subscribe']) {
foreach ($to_subscribe as $courseId) {
CourseManager::add_user_to_course($user_id, $courseId, $csvCourseList[$courseId]);
$course_info = api_get_course_info_by_id($courseId);
$inserted_in_course[$courseId] = $course_info['title'];
}
}
if (isset($_POST['unsubscribe']) && $_POST['unsubscribe']) {
foreach ($to_unsubscribe as $courseId) {
CourseManager::unsubscribe_user($user_id, $courseId);
$course_info = api_get_course_info_by_id($courseId);
$inserted_in_course[$courseId] = $course_info['title'];
}
}
}
}
示例6: save_data
/**
* Saves imported data.
* @param array List of courses
*/
function save_data($courses)
{
global $purification_option_for_usernames;
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$msg = '';
foreach ($courses as $index => $course) {
$course_language = api_get_valid_language($course['Language']);
$username = '';
$teachers = getTeacherListInArray($course['Teacher']);
$teacherList = array();
$creatorId = api_get_user_id();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacherInfo = api_get_user_info_from_username($teacher);
if (!empty($teacherInfo)) {
$teacherList[] = $teacherInfo;
}
}
}
$params = array();
$params['title'] = $course['Title'];
$params['wanted_code'] = $course['Code'];
$params['tutor_name'] = null;
$params['course_category'] = $course['CourseCategory'];
$params['course_language'] = $course_language;
$params['user_id'] = $creatorId;
$course_info = CourseManager::create_course($params);
if (!empty($course_info)) {
if (!empty($teacherList)) {
foreach ($teacherList as $teacher) {
CourseManager::add_user_to_course($teacher['user_id'], $course_info['code'], COURSEMANAGER);
}
}
$msg .= '<a href="' . api_get_path(WEB_COURSE_PATH) . $course_info['directory'] . '/">
' . $course_info['title'] . '</a> ' . get_lang('Created') . '<br />';
}
}
if (!empty($msg)) {
Display::display_normal_message($msg, false);
}
}
示例7: save_data
/**
* Saves imported data.
* @param array $courses List of courses
*/
function save_data($courses)
{
$msg = '';
foreach ($courses as $course) {
$course_language = $course['Language'];
$teachers = getTeacherListInArray($course['Teacher']);
$teacherList = array();
$creatorId = api_get_user_id();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacherInfo = api_get_user_info_from_username($teacher);
if (!empty($teacherInfo)) {
$teacherList[] = $teacherInfo;
}
}
}
$params = array();
$params['title'] = $course['Title'];
$params['wanted_code'] = $course['Code'];
$params['tutor_name'] = null;
$params['course_category'] = $course['CourseCategory'];
$params['course_language'] = $course_language;
$params['user_id'] = $creatorId;
$addMeAsTeacher = isset($_POST['add_me_as_teacher']) ? $_POST['add_me_as_teacher'] : false;
$params['add_user_as_teacher'] = $addMeAsTeacher;
$courseInfo = CourseManager::create_course($params);
if (!empty($courseInfo)) {
if (!empty($teacherList)) {
foreach ($teacherList as $teacher) {
CourseManager::add_user_to_course($teacher['user_id'], $courseInfo['code'], COURSEMANAGER);
}
}
$msg .= '<a href="' . api_get_path(WEB_COURSE_PATH) . $courseInfo['directory'] . '/">
' . $courseInfo['title'] . '</a> ' . get_lang('Created') . '<br />';
}
}
if (!empty($msg)) {
Display::display_normal_message($msg, false);
}
}
示例8: get_lang
}
echo '<br /><br />';
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">' . get_lang('BackToNewSearch') . '</a>';
echo '<br /><br />';
echo '</div>';
} elseif (!empty($annee) && !empty($course) && $_POST['confirmed'] == 'yes') {
$id = $_POST['username_form'];
$UserList = array();
$userid_match_login = array();
foreach ($id as $form_index => $user_id) {
if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes']))) {
$tmp = ldap_add_user($user_id);
$UserList[] = $tmp;
$userid_match_login[$tmp] = $user_id;
}
}
if (!empty($_POST['course'])) {
foreach ($UserList as $user_id) {
CourseManager::add_user_to_course($user_id, $_POST['course']);
}
header('Location: course_information.php?code=' . Security::remove_XSS($_POST['course']));
} else {
Display::display_header($tool_name);
$message = get_lang('NoUserAdded');
Display::display_normal_message($message, false);
}
echo '<br /><br />';
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">' . get_lang('BackToNewSearch') . '</a>';
echo '<br /><br />';
}
Display::display_footer();
示例9: get_lang
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">' . get_lang('BackToNewSearch') . '</a>';
echo '<br /><br />';
echo '</div>';
} elseif (!empty($annee) && !empty($course) && $_POST['confirmed'] == 'yes') {
$id = $_POST['username_form'];
$UserList = array();
$userid_match_login = array();
foreach ($id as $form_index => $user_id) {
if (is_array($_POST['checkboxes']) && in_array($form_index, array_values($_POST['checkboxes']))) {
$tmp = ldap_add_user($user_id);
$UserList[] = $tmp;
$userid_match_login[$tmp] = $user_id;
}
}
$courseInfo = api_get_course_info($_POST['course']);
if (!empty($courseInfo)) {
foreach ($UserList as $user_id) {
CourseManager::add_user_to_course($user_id, $courseInfo['real_id']);
}
header('Location: course_information.php?code=' . Security::remove_XSS($_POST['course']));
exit;
} else {
Display::display_header($tool_name);
$message = get_lang('NoUserAdded');
Display::display_normal_message($message, false);
}
echo '<br /><br />';
echo '<a href="ldap_import_students.php?annee=&composante=&etape=">' . get_lang('BackToNewSearch') . '</a>';
echo '<br /><br />';
}
Display::display_footer();