本文整理汇总了PHP中api_get_user_info_from_username函数的典型用法代码示例。如果您正苦于以下问题:PHP api_get_user_info_from_username函数的具体用法?PHP api_get_user_info_from_username怎么用?PHP api_get_user_info_from_username使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_get_user_info_from_username函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_data
/**
* Save imported class data to database
*
* @param $classes
*
* @return int
*/
function save_data($classes)
{
$count = 0;
$usergroup = new UserGroup();
foreach ($classes as $index => $class) {
$usersToAdd = isset($class['users']) ? $class['users'] : null;
unset($class['users']);
$id = $usergroup->save($class);
if ($id) {
if (!empty($usersToAdd)) {
$usersToAddList = explode(',', $usersToAdd);
$userIdList = array();
foreach ($usersToAddList as $username) {
$userInfo = api_get_user_info_from_username($username);
$userIdList[] = $userInfo['user_id'];
}
if (!empty($userIdList)) {
$usergroup->subscribe_users_to_usergroup($id, $userIdList, false);
}
}
$count++;
}
}
return $count;
}
示例2: WSEventsList
/**
* Get a list of events between two dates for the given username
* Function registered as service. Returns strings in UTF-8.
* @param string Username
* @param string User's API key (the user's API key)
* @param int Start date, in YYYYMMDD format
* @param int End date, in YYYYMMDD format
* @return array Events list
*/
function WSEventsList($username, $signature, $datestart = 0, $dateend = 0)
{
if (empty($username) or empty($signature)) {
return -1;
}
global $_configuration;
$info = api_get_user_info_from_username($username);
$user_id = $info['user_id'];
$list = UserManager::get_api_keys($user_id, 'dokeos');
$key = '';
foreach ($list as $key) {
break;
}
$local_key = $username . $key;
if (!api_is_valid_secret_key($signature, $local_key)) {
return -1;
// The secret key is incorrect.
}
$events_list = array();
$user_id = UserManager::get_user_id_from_username($username);
if ($user_id === false) {
return $events_list;
}
// Error in user id recovery.
$ds = substr($datestart, 0, 4) . '-' . substr($datestart, 4, 2) . '-' . substr($datestart, 6, 2) . ' 00:00:00';
$de = substr($dateend, 0, 4) . '-' . substr($dateend, 4, 2) . '-' . substr($dateend, 6, 2) . ' 00:00:00';
$events_list = Agenda::get_personal_agenda_items_between_dates($user_id, $ds, $de);
return $events_list;
}
示例3: getNewMessages
/**
* Get the list of new messages for a user
* @param string $username The username
* @param int $lastId The id of the last received message
* @return array the new message list
*/
public function getNewMessages($username, $lastId = 0)
{
$messages = array();
$userInfo = api_get_user_info_from_username($username);
$userId = $userInfo['user_id'];
$lastMessages = MessageManager::getMessagesFromLastReceivedMessage($userId, $lastId);
foreach ($lastMessages as $message) {
$hasAttachments = MessageManager::hasAttachments($message['id']);
$messages[] = array('id' => $message['id'], 'title' => $message['title'], 'sender' => array('id' => $message['user_id'], 'lastname' => $message['lastname'], 'firstname' => $message['firstname'], 'completeName' => api_get_person_name($message['firstname'], $message['lastname'])), 'sendDate' => $message['send_date'], 'content' => $message['content'], 'hasAttachments' => $hasAttachments, 'platform' => array('website' => api_get_path(WEB_PATH), 'messagingTool' => api_get_path(WEB_PATH) . 'main/messages/inbox.php'));
}
return $messages;
}
示例4: facebook_connect
/**
* This function connect to facebook and retrieves the user info
* If user does not exist in chamilo, it creates it and logs in
* If user already exists, it updates his info
* */
function facebook_connect()
{
global $facebook;
// See if there is a user from a cookie
$user = $facebook->getUser();
if ($user) {
try {
//Gets facebook user info
$fu = $facebook->api('/me');
$username = $fu['username'];
if (api_get_setting('login_is_email') == 'true' || empty($fu['username'])) {
$username = change_to_valid_chamilo_login($fu['email']);
}
//Checks if user already exists in chamilo
$u = array('firstname' => $fu['first_name'], 'lastname' => $fu['last_name'], 'status' => STUDENT, 'email' => $fu['email'], 'username' => $username, 'language' => 'french', 'password' => DEFAULT_PASSWORD, 'auth_source' => 'facebook', 'extra' => array());
$cu = api_get_user_info_from_username($username);
$chamilo_uinfo = api_get_user_info_from_username($username);
if ($chamilo_uinfo === false) {
//we have to create the user
$chamilo_uid = external_add_user($u);
if ($chamilo_uid !== false) {
$_user['user_id'] = $chamilo_uid;
$_user['uidReset'] = true;
$_SESSION['_user'] = $_user;
header('Location:' . api_get_path(WEB_PATH));
exit;
} else {
return false;
}
} else {
//User already exists, update info and login
$chamilo_uid = $chamilo_uinfo['user_id'];
$u['user_id'] = $chamilo_uid;
external_update_user($u);
$_user['user_id'] = $chamilo_uid;
$_user['uidReset'] = true;
$_SESSION['_user'] = $_user;
header('Location:' . api_get_path(WEB_PATH));
exit;
}
} catch (FacebookApiException $e) {
echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
$user = null;
}
}
}
示例5: WSCourseList
/**
* Get a list of courses (code, url, title, teacher, language) and return to caller
* Function registered as service. Returns strings in UTF-8.
* @param string User name in Chamilo
* @param string Signature (composed of the sha1(username+apikey)
* @param mixed Array or string. Type of visibility of course (public, public-registered, private, closed)
* @return array Courses list (code=>[title=>'title',url='http://...',teacher=>'...',language=>''],code=>[...],...)
*/
function WSCourseList($username, $signature, $visibilities = 'public') {
if (empty($username) or empty($signature)) { return -1; }
global $_configuration;
$info = api_get_user_info_from_username($username);
$user_id = $info['user_id'];
if (!UserManager::is_admin($user_id)) { return -1; }
$list = UserManager::get_api_keys($user_id, 'dokeos');
$key = '';
foreach ($list as $key) {
break;
}
$local_key = $username.$key;
if (!api_is_valid_secret_key($signature, $local_key) && !api_is_valid_secret_key($signature, $username.$_configuration['security_key'])) {
return -1; // The secret key is incorrect.
}
//public-registered = open
$vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
$courses_list = array();
if (!is_array($visibilities)) {
$visibilities = split(',', $visibilities);
}
foreach ($visibilities as $visibility) {
if (!in_array($visibility, array_keys($vis))) {
return array('error_msg' => 'Security check failed');
}
$courses_list_tmp = CourseManager::get_courses_list(null, null, null, null, $vis[$visibility]);
foreach ($courses_list_tmp as $index => $course) {
$course_info = CourseManager::get_course_information($course['code']);
$courses_list[] = array('code' => $course['code'], 'title' => api_utf8_encode($course_info['title']), 'url' => api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/', 'teacher' => api_utf8_encode($course_info['tutor_name']), 'language' => $course_info['course_language']);
}
}
return $courses_list;
}
示例6: WSUpdateUserApiKey
function WSUpdateUserApiKey($params)
{
if (!WSHelperVerifyKey($params)) {
return return_error(WS_ERROR_SECRET_KEY);
}
$user_id = UserManager::get_user_id_from_original_id($params['original_user_id_value'], $params['original_user_id_name']);
if (!$user_id) {
if (!empty($params['chamilo_username'])) {
$info = api_get_user_info_from_username($params['chamilo_username']);
$user_id = $info['user_id'];
// Save new fieldlabel into user_field table.
$field_id = UserManager::create_extra_field($params['original_user_id_name'], 1, $params['original_user_id_name'], '');
// Save the external system's id into user_field_value table.
$res = UserManager::update_extra_field_value($user_id, $params['original_user_id_name'], $params['original_user_id_value']);
} else {
return 0;
}
}
$list = UserManager::get_api_keys($user_id);
$key_id = UserManager::get_api_key_id($user_id, 'dokeos');
if (isset($list[$key_id])) {
$apikey = $list[$key_id];
} else {
$lastid = UserManager::update_api_key($user_id, 'dokeos');
if ($lastid) {
$apikeys = UserManager::get_api_keys($user_id);
$apikey = $apikeys[$lastid];
}
}
return $apikey;
}
示例7: updateUsers
/**
* Update users from the imported data
* @param array $users List of users
* @return void
* @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
*/
function updateUsers($users)
{
global $insertedIn_course;
// Not all scripts declare the $inserted_in_course array (although they should).
if (!isset($inserted_in_course)) {
$inserted_in_course = array();
}
$usergroup = new UserGroup();
$send_mail = $_POST['sendMail'] ? true : false;
if (is_array($users)) {
foreach ($users as $user) {
$user = complete_missing_data($user);
$user['Status'] = api_status_key($user['Status']);
$userName = $user['UserName'];
$userInfo = api_get_user_info_from_username($userName);
$user_id = $userInfo['user_id'];
if ($user_id == 0) {
return false;
}
$firstName = isset($user['FirstName']) ? $user['FirstName'] : $userInfo['firstname'];
$lastName = isset($user['LastName']) ? $user['LastName'] : $userInfo['lastname'];
$userName = isset($user['NewUserName']) ? $user['NewUserName'] : $userInfo['username'];
$password = isset($user['Password']) ? $user['Password'] : $userInfo['password'];
$authSource = isset($user['AuthSource']) ? $user['AuthSource'] : $userInfo['auth_source'];
$email = isset($user['Email']) ? $user['Email'] : $userInfo['email'];
$status = isset($user['Status']) ? $user['Status'] : $userInfo['status'];
$officialCode = isset($user['OfficialCode']) ? $user['OfficialCode'] : $userInfo['official_code'];
$phone = isset($user['PhoneNumber']) ? $user['PhoneNumber'] : $userInfo['phone'];
$pictureUrl = isset($user['PictureUri']) ? $user['PictureUri'] : $userInfo['picture_uri'];
$expirationDate = isset($user['ExpiryDate']) ? $user['ExpiryDate'] : $userInfo['expiration_date'];
$active = isset($user['Active']) ? $user['Active'] : $userInfo['active'];
$creatorId = $userInfo['creator_id'];
$hrDeptId = $userInfo['hr_dept_id'];
$language = isset($user['Language']) ? $user['Language'] : $userInfo['language'];
$sendEmail = isset($user['SendEmail']) ? $user['SendEmail'] : $userInfo['language'];
$userUpdated = UserManager::update_user($user_id, $firstName, $lastName, $userName, $password, $authSource, $email, $status, $officialCode, $phone, $pictureUrl, $expirationDate, $active, $creatorId, $hrDeptId, null, $language, '', '', '');
if (!is_array($user['Courses']) && !empty($user['Courses'])) {
$user['Courses'] = array($user['Courses']);
}
if (is_array($user['Courses'])) {
foreach ($user['Courses'] as $course) {
if (CourseManager::course_exists($course)) {
CourseManager::subscribe_user($user_id, $course, $user['Status']);
$course_info = CourseManager::get_course_information($course);
$inserted_in_course[$course] = $course_info['title'];
}
}
}
if (!empty($user['ClassId'])) {
$classId = explode('|', trim($user['ClassId']));
foreach ($classId as $id) {
$usergroup->subscribe_users_to_usergroup($id, array($user_id), false);
}
}
// Saving extra fields.
global $extra_fields;
// We are sure that the extra field exists.
foreach ($extra_fields as $extras) {
if (isset($user[$extras[1]])) {
$key = $extras[1];
$value = $user[$extras[1]];
UserManager::update_extra_field_value($user_id, $key, $value);
}
}
}
}
}
示例8: importSessionsStatic
/**
* Updates the session synchronize with the csv file.
* @param string $file
*/
private function importSessionsStatic($file)
{
$content = file($file);
$sessions = array();
if (!api_strstr($content[0], ';')) {
$error_message = get_lang('NotCSV');
} else {
$tag_names = array();
foreach ($content as $key => $enreg) {
$enreg = explode(';', trim($enreg));
if ($key) {
foreach ($tag_names as $tag_key => $tag_name) {
$sessions[$key - 1][$tag_name] = $enreg[$tag_key];
}
} else {
foreach ($enreg as $tag_name) {
$tag_names[] = api_preg_replace('/[^a-zA-Z0-9_\\-]/', '', $tag_name);
}
if (!in_array('SessionName', $tag_names) || !in_array('DateStart', $tag_names) || !in_array('DateEnd', $tag_names)) {
$error_message = get_lang('NoNeededData');
break;
}
}
}
}
if (!empty($sessions)) {
// Looping the sessions.
foreach ($sessions as $session) {
if (!empty($session['SessionID'])) {
$sessionId = SessionManager::get_session_id_from_original_id($session['SessionID'], $this->extraFieldIdNameList['session']);
$coachUserName = isset($session['Coach']) ? $session['Coach'] : null;
$categoryId = isset($session['category_id']) ? $session['category_id'] : null;
// 2014-06-30
$dateStart = explode('/', $session['DateStart']);
$dateEnd = explode('/', $session['DateEnd']);
$visibility = $this->defaultSessionVisibility;
$coachId = null;
if (!empty($coachUserName)) {
$coachInfo = api_get_user_info_from_username($coachUserName);
$coachId = $coachInfo['user_id'];
}
if (empty($sessionId)) {
$result = SessionManager::create_session($session['SessionName'], $dateStart[0], $dateStart[1], $dateStart[2], $dateEnd[0], $dateEnd[1], $dateEnd[2], $this->daysCoachAccessBeforeBeginning, $this->daysCoachAccessAfterBeginning, null, $coachUserName, $categoryId, $visibility, 1);
if (is_numeric($result)) {
$sessionId = $result;
SessionManager::update_session_extra_field_value($sessionId, $this->extraFieldIdNameList['session'], $session['SessionID']);
}
} else {
$sessionInfo = api_get_session_info($sessionId);
$accessBefore = null;
$accessAfter = null;
if (empty($sessionInfo['nb_days_access_before_beginning']) || !empty($sessionInfo['nb_days_access_before_beginning']) && $sessionInfo['nb_days_access_before_beginning'] < $this->daysCoachAccessBeforeBeginning) {
$accessBefore = intval($this->daysCoachAccessBeforeBeginning);
}
$accessAfter = null;
if (empty($sessionInfo['nb_days_access_after_end']) || !empty($sessionInfo['nb_days_access_after_end']) && $sessionInfo['nb_days_access_after_end'] < $this->daysCoachAccessAfterBeginning) {
$accessAfter = intval($this->daysCoachAccessAfterBeginning);
}
$showDescription = isset($sessionInfo['show_description']) ? $sessionInfo['show_description'] : 1;
$result = SessionManager::edit_session($sessionId, $session['SessionName'], $dateStart[0], $dateStart[1], $dateStart[2], $dateEnd[0], $dateEnd[1], $dateEnd[2], $accessBefore, $accessAfter, null, $coachId, $categoryId, $visibility, true, true, null, $showDescription);
if (is_numeric($result)) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$params = array('description' => $session['SessionDescription']);
Database::update($tbl_session, $params, array('id = ?' => $sessionId));
}
}
// Courses
$courses = explode('|', $session['Courses']);
$courseList = array();
foreach ($courses as $course) {
$courseArray = bracketsToArray($course);
$courseCode = $courseArray[0];
if (CourseManager::course_exists($courseCode)) {
$courseList[] = $courseCode;
}
}
SessionManager::add_courses_to_session($sessionId, $courseList, true);
if (!empty($sessionId)) {
$courses = explode('|', $session['Courses']);
foreach ($courses as $course) {
$courseArray = bracketsToArray($course);
$courseCode = $courseArray[0];
if (CourseManager::course_exists($courseCode)) {
// Coaches
$courseCoaches = isset($courseArray[1]) ? $courseArray[1] : null;
$courseCoaches = explode(',', $courseCoaches);
if (!empty($courseCoaches)) {
$coachList = array();
foreach ($courseCoaches as $courseCoach) {
$courseCoachId = UserManager::get_user_id_from_username($courseCoach);
if ($courseCoachId !== false) {
// Just insert new coaches
$coachList[] = $courseCoachId;
}
}
SessionManager::updateCoaches($sessionId, $courseCode, $coachList, true);
//.........这里部分代码省略.........
示例9: importCategoriesAndGroupsFromArray
/**
* @param array $groupData
* @param bool $deleteNotInArray
* @return array
*/
public static function importCategoriesAndGroupsFromArray($groupData, $deleteNotInArray = false)
{
$result = array();
$elementsFound = array('categories' => array(), 'groups' => array());
$groupCategories = GroupManager::get_categories();
if (empty($groupCategories)) {
$result['error'][] = get_lang('CreateACategory');
return $result;
}
foreach ($groupData as $data) {
$isCategory = empty($data['group']) ? true : false;
if ($isCategory) {
$categoryInfo = self::getCategoryByTitle($data['category']);
$categoryId = $categoryInfo['id'];
if (!empty($categoryInfo)) {
// Update
self::update_category($categoryId, $data['category'], $data['description'], $data['doc_state'], $data['work_state'], $data['calendar_state'], $data['announcements_state'], $data['forum_state'], $data['wiki_state'], $data['chat_state'], $data['self_reg_allowed'], $data['self_unreg_allowed'], $data['max_student'], $data['groups_per_user']);
$data['category_id'] = $categoryId;
$result['updated']['category'][] = $data;
} else {
// Add
$categoryId = self::create_category($data['category'], $data['description'], $data['doc_state'], $data['work_state'], $data['calendar_state'], $data['announcements_state'], $data['forum_state'], $data['wiki_state'], $data['chat_state'], $data['self_reg_allowed'], $data['self_unreg_allowed'], $data['max_student'], $data['groups_per_user']);
if ($categoryId) {
$data['category_id'] = $categoryId;
$result['added']['category'][] = $data;
}
}
$elementsFound['categories'][] = $categoryId;
} else {
$groupInfo = self::getGroupByName($data['group']);
$categoryInfo = self::getCategoryByTitle($data['category']);
$categoryId = null;
if (!empty($categoryInfo)) {
$categoryId = $categoryInfo['id'];
} else {
if (!empty($groupCategories) && isset($groupCategories[0])) {
$defaultGroupCategory = $groupCategories[0];
$categoryId = $defaultGroupCategory['id'];
}
}
if (empty($groupInfo)) {
// Add
$groupId = self::create_group($data['group'], $categoryId, null, $data['max_students']);
if ($groupId) {
self::set_group_properties($groupId, $data['group'], $data['description'], $data['max_students'], $data['doc_state'], $data['work_state'], $data['calendar_state'], $data['announcements_state'], $data['forum_state'], $data['wiki_state'], $data['chat_state'], $data['self_reg_allowed'], $data['self_unreg_allowed'], $categoryId);
$data['group_id'] = $groupId;
$result['added']['group'][] = $data;
}
} else {
// Update
$groupId = $groupInfo['id'];
self::set_group_properties($groupId, $data['group'], $data['description'], $data['max_students'], $data['doc_state'], $data['work_state'], $data['calendar_state'], $data['announcements_state'], $data['forum_state'], $data['wiki_state'], $data['chat_state'], $data['self_reg_allowed'], $data['self_unreg_allowed'], $categoryId);
$data['group_id'] = $groupId;
$result['updated']['group'][] = $data;
}
$students = isset($data['students']) ? explode(',', $data['students']) : null;
if (!empty($students)) {
$studentUserIdList = array();
foreach ($students as $student) {
$userInfo = api_get_user_info_from_username($student);
$studentUserIdList[] = $userInfo['user_id'];
}
self::subscribe_users($studentUserIdList, $groupId);
}
$tutors = isset($data['tutors']) ? explode(',', $data['tutors']) : null;
if (!empty($tutors)) {
$tutorIdList = array();
foreach ($tutors as $tutor) {
$userInfo = api_get_user_info_from_username($tutor);
$tutorIdList[] = $userInfo['user_id'];
}
self::subscribe_tutors($tutorIdList, $groupId);
}
$elementsFound['groups'][] = $groupId;
}
}
if ($deleteNotInArray) {
// Check categories
$categories = GroupManager::get_categories();
foreach ($categories as $category) {
if (!in_array($category['id'], $elementsFound['categories'])) {
GroupManager::delete_category($category['id']);
$category['category'] = $category['title'];
$result['deleted']['category'][] = $category;
}
}
$groups = GroupManager::get_groups();
foreach ($groups as $group) {
if (!in_array($group['id'], $elementsFound['groups'])) {
GroupManager::delete_groups(array($group['id']));
$group['group'] = $group['name'];
$result['deleted']['group'][] = $group;
}
}
}
//.........这里部分代码省略.........
示例10: api_get_user_blocked_by_captcha
/**
* @param string $username
* @return bool
*/
function api_get_user_blocked_by_captcha($username)
{
$userInfo = api_get_user_info_from_username($username);
if (empty($userInfo)) {
return false;
}
$data = UserManager::get_extra_user_data_by_field($userInfo['user_id'], 'captcha_blocked_until_date');
if (isset($data) && isset($data['captcha_blocked_until_date'])) {
return $data['captcha_blocked_until_date'];
}
return false;
}
示例11: importSessionDrhCSV
/**
* @param string $file
* @param bool $sendEmail
* @param bool $removeOldRelationShips
*/
public static function importSessionDrhCSV($file, $sendEmail, $removeOldRelationShips)
{
$list = Import::csv_reader($file);
if (!empty($list)) {
$userSessionList = array();
foreach ($list as $data) {
$userInfo = api_get_user_info_from_username($data['Username']);
$sessionInfo = self::get_session_by_name($data['SessionName']);
if (!empty($userInfo) && !empty($sessionInfo)) {
$userSessionList[$userInfo['user_id']]['session_list'][] = array('session_id' => $sessionInfo['id'], 'session_info' => $sessionInfo);
$userSessionList[$userInfo['user_id']]['user_info'] = $userInfo;
}
}
self::subscribeDrhToSessionList($userSessionList, $sendEmail, $removeOldRelationShips);
return self::checkSubscribeDrhToSessionList($userSessionList);
}
}
示例12: ldap_get_values_len
$outab[] = $info[$key]["edupersonprimaryaffiliation"][0];
// Ici "student"
$val = ldap_get_values_len($ds, $sr, "userPassword");
$password = $val[0];
// Pour faciliter la gestion on ajoute le code "etape-annee"
$official_code = $etape . "-" . $annee;
$auth_source = "ldap";
// Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP)
$expiration_date = '0000-00-00 00:00:00';
$active = 1;
// Ajout de l'utilisateur
if (UserManager::is_username_available($username)) {
$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('language.platform_language'), $phone, $picture_uri, $auth_source, $expiration_date, $active);
$UserAdd[] = $user_id;
} else {
$user = api_get_user_info_from_username($username);
$user_id = $user['user_id'];
UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
$UserUpdate[] = $user_id;
}
$UserList[] = $user_id;
}
//}
}
if (isset($included) && $included) {
$message .= "> {$name_session}: " . count($UserAdd) . " " . get_lang('Added') . ' ' . get_lang('And') . ' ' . count($UserUpdate) . ' ' . get_lang('Modified') . '<br/>';
} else {
print "> {$name_session}: " . count($UserAdd) . get_lang('Added') . ' ' . get_lang('And') . ' ' . count($UserUpdate) . ' ' . get_lang('Modified') . "\n";
}
// Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter la session
$result = Database::query("SELECT c_id FROM {$tbl_session_rel_course} WHERE session_id='{$id_session}'");
示例13: cleanCourseRow
/**
* @param array $row
* @return array
*/
private function cleanCourseRow($row)
{
$row['title'] = $row['Title'];
$row['course_code'] = $row['Code'];
$row['course_category'] = $row['CourseCategory'];
$row['email'] = $row['Teacher'];
$row['language'] = $row['Language'];
$row['teachers'] = array();
if (isset($row['Teacher']) && !empty($row['Teacher'])) {
$teachers = explode(',', $row['Teacher']);
if (!empty($teachers)) {
foreach ($teachers as $teacherUserName) {
$teacherUserName = trim($teacherUserName);
$userInfo = api_get_user_info_from_username($teacherUserName);
if (!empty($userInfo)) {
$row['teachers'][] = $userInfo['user_id'];
}
}
}
}
if (isset($row['CourseID'])) {
$row['extra_' . $this->extraFieldIdNameList['course']] = $row['CourseID'];
}
return $row;
}
示例14: 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);
}
}
示例15: 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);
}
}