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


PHP UserManager::purify_username方法代码示例

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


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

示例1: save_data

/**
 * Saves imported data.
 */
function save_data($users_classes)
{
    global $purification_option_for_usernames;
    // Table definitions.
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $class_user_table = Database::get_main_table(TABLE_MAIN_CLASS_USER);
    $class_table = Database::get_main_table(TABLE_MAIN_CLASS);
    // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
    $csv_data = array();
    foreach ($users_classes as $index => $user_class) {
        $sql1 = "SELECT user_id FROM {$user_table} WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'";
        $res1 = Database::query($sql1);
        $obj1 = Database::fetch_object($res1);
        $sql2 = "SELECT id FROM {$class_table} WHERE name = '" . Database::escape_string(trim($user_class['ClassName'])) . "'";
        $res2 = Database::query($sql2);
        $obj2 = Database::fetch_object($res2);
        if ($obj1 && $obj2) {
            $csv_data[$obj1->user_id][$obj2->id] = 1;
        }
    }
    // Logic for processing the request (data + UI options).
    $db_subscriptions = array();
    foreach ($csv_data as $user_id => $csv_subscriptions) {
        $sql = "SELECT class_id FROM {$class_user_table} cu WHERE cu.user_id = {$user_id}";
        $res = Database::query($sql);
        while ($obj = Database::fetch_object($res)) {
            $db_subscriptions[$obj->class_id] = 1;
        }
        $to_subscribe = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
        $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
        // Subscriptions for new classes.
        if ($_POST['subscribe']) {
            foreach ($to_subscribe as $class_id) {
                ClassManager::add_user($user_id, $class_id);
            }
        }
        // Unsubscription from previous classes.
        if ($_POST['unsubscribe']) {
            foreach ($to_unsubscribe as $class_id) {
                ClassManager::unsubscribe_user($user_id, $class_id);
            }
        }
    }
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:47,代码来源:class_user_import.php

示例2: complete_missing_data

/**
 * Add missing user-information (which isn't required, like password, username etc).
 */
function complete_missing_data($user)
{
    global $purification_option_for_usernames;
    // 1. Create a username if necessary.
    if (UserManager::is_username_empty($user['UserName'])) {
        $user['UserName'] = UserManager::create_unique_username($user['FirstName'], $user['LastName']);
    } else {
        $user['UserName'] = UserManager::purify_username($user['UserName'], $purification_option_for_usernames);
    }
    // 2. Generate a password if necessary.
    if (empty($user['Password'])) {
        $user['Password'] = api_generate_password();
    }
    // 3. Set status if not allready set.
    if (empty($user['Status'])) {
        $user['Status'] = 'user';
    }
    // 4. Set authsource if not allready set.
    if (empty($user['AuthSource'])) {
        $user['AuthSource'] = PLATFORM_AUTH_SOURCE;
    }
    return $user;
}
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:26,代码来源:user_import.php

示例3: save_data

/**
 * Saves imported data.
 */
function save_data($users_classes, $deleteUsersNotInList = false)
{
    global $purification_option_for_usernames;
    // Table definitions.
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $usergroup = new UserGroup();
    // Data parsing: purification + conversion (UserName, ClassName) --> (user_is, class_id)
    $csv_data = array();
    if (!empty($users_classes)) {
        foreach ($users_classes as $user_class) {
            $sql1 = "SELECT user_id FROM {$user_table}\n                     WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'";
            $res1 = Database::query($sql1);
            $obj1 = Database::fetch_object($res1);
            $usergroup = new UserGroup();
            $id = $usergroup->get_id_by_name($user_class['ClassName']);
            if ($obj1 && $id) {
                $csv_data[$id]['user_list'][] = $obj1->user_id;
                $csv_data[$id]['user_list_name'][] = $user_class['UserName'];
                $csv_data[$id]['class_name'] = $user_class['ClassName'];
            }
        }
    }
    // Logic for processing the request (data + UI options).
    $message = null;
    if (!empty($csv_data)) {
        foreach ($csv_data as $class_id => $user_data) {
            $user_list = $user_data['user_list'];
            $class_name = $user_data['class_name'];
            $user_list_name = $user_data['user_list_name'];
            $usergroup->subscribe_users_to_usergroup($class_id, $user_list, $deleteUsersNotInList);
            $message .= Display::return_message(get_lang('Class') . ': ' . $class_name . '<br />', 'normal', false);
            $message .= Display::return_message(get_lang('Users') . ': ' . implode(', ', $user_list_name));
        }
    }
    return $message;
}
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:39,代码来源:usergroup_user_import.php

示例4: foreach

 // adding coachs to session course user
 foreach ($course_coaches as $course_coach) {
     $coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames);
     $coach_id = UserManager::get_user_id_from_username($course_coach);
     if ($coach_id !== false) {
         $sql = "INSERT IGNORE INTO {$tbl_session_course_user} SET\n                                                        id_user='{$coach_id}',\n                                                        course_code='{$vcourse['code']}',\n                                                        id_session = '{$session_id}',\n                                                        status = 2 ";
         $rs_coachs = Database::query($sql);
     } else {
         $error_message .= get_lang('UserDoesNotExist') . ' : ' . $user . '<br />';
     }
 }
 // adding users
 $course_counter++;
 $users_in_course_counter = 0;
 foreach ($node_course->User as $node_user) {
     $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
     $user_id = UserManager::get_user_id_from_username($username);
     if ($user_id !== false) {
         // Adding to session_rel_user table.
         $sql = "INSERT IGNORE INTO {$tbl_session_user} SET\n                                                        id_user='{$user_id}',\n                                                        id_session = '{$session_id}'";
         $rs_user = Database::query($sql);
         $user_counter++;
         // Adding to session_rel_user_rel_course table.
         $sql = "INSERT IGNORE INTO {$tbl_session_course_user} SET\n                                                        id_user='{$user_id}',\n                                                        course_code='{$vcourse['code']}',\n                                                        id_session = '{$session_id}'";
         $rs_users = Database::query($sql);
         $users_in_course_counter++;
     } else {
         $error_message .= get_lang('UserDoesNotExist') . ' : ' . $username . '<br />';
     }
 }
 $update_session_course = "UPDATE {$tbl_session_course} SET nbr_users='{$users_in_course_counter}' WHERE course_code='{$course_code}'";
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:31,代码来源:session_import.php

示例5: element_end

 /**
  * XML-parser: the handler at the end of element.
  */
 function element_end($parser, $data)
 {
     $data = api_utf8_decode($data);
     global $user;
     global $users;
     global $current_value;
     global $purification_option_for_usernames;
     $user[$data] = $current_value;
     switch ($data) {
         case 'Contact':
             $user['UserName'] = UserManager::purify_username($user['UserName'], $purification_option_for_usernames);
             $users[] = $user;
             break;
         default:
             $user[$data] = $current_value;
             break;
     }
 }
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:21,代码来源:myspace.lib.php

示例6: create_user

 /**
  * Manage the user creation, including checking if the user hasn't been
  * created previously
  * @param array User data
  * @param object List of migrated things
  * @return array User info (from Chamilo DB)
  */
 static function create_user($data, &$omigrate = null)
 {
     //error_log('In create_user, receiving '.print_r($data,1));
     if (empty($data['uidIdPersona'])) {
         error_log('User does not have a uidIdPersona');
         error_log(print_r($data, 1));
         return false;
         //exit;
     }
     $data['uidIdPersona'] = strtoupper($data['uidIdPersona']);
     $data['status'] = STUDENT;
     if (isset($data['uidIdEmpleado'])) {
         $data['status'] = COURSEMANAGER;
     }
     if (!isset($data['username']) || empty($data['username'])) {
         $data['firstname'] = (string) trim($data['firstname']);
         $data['lastname'] = (string) trim($data['lastname']);
         if (empty($data['firstname']) && empty($data['lastname'])) {
             $wanted_user_name = UserManager::purify_username($data['uidIdPersona']);
             //$wanted_user_name = UserManager::create_unique_username(null, null);
         } else {
             $wanted_user_name = UserManager::create_username($data['firstname'], $data['lastname']);
         }
         $extra_data = UserManager::get_extra_user_data_by_value('uidIdPersona', $data['uidIdPersona']);
         if ($extra_data) {
             $user_info = api_get_user_info($extra_data[0]);
             //print_r($extra_data);
             //error_log("User_already_added - {$user_info['user_id']}  - {$user_info['username']} - {$user_info['firstname']} - {$user_info['lastname']}");
             return $user_info;
         }
         if (UserManager::is_username_available($wanted_user_name)) {
             $data['username'] = $wanted_user_name;
             error_log("username available  {$wanted_user_name}");
         } else {
             //the user already exists?
             $user_info = UserManager::get_user_info_simple($wanted_user_name);
             $user_persona = UserManager::get_extra_user_data_by_field($user_info['user_id'], 'uidIdPersona');
             if (isset($user_persona['uidIdPersona']) && $data['uidIdPersona'] == $user_persona['uidIdPersona']) {
                 error_log("Skip user already added: {$user_info['username']}");
                 return $user_info;
             } else {
                 error_log("Homonym - wanted_username: {$wanted_user_name} - uidIdPersona: {$user_persona['uidIdPersona']} - username: {$user_info['username']}");
                 //print_r($data);
                 //The user has the same firstname and lastname but it has another uiIdPersona could by an homonym
                 $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);
                 error_log("homonym username created " . $data['username']);
             }
         }
         if (empty($data['username'])) {
             //Last chance to have a nice username
             if (empty($data['firstname']) && empty($data['lastname'])) {
                 $data['username'] = UserManager::create_unique_username(uniqid());
                 error_log("username empty 1" . $data['username']);
             } else {
                 $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);
                 error_log("username empty 2" . $data['username']);
             }
         }
     } else {
         if (UserManager::is_username_available($data['username'])) {
             //error_log("username available {$data['username']} ");
         } else {
             //the user already exists?
             $user_info = UserManager::get_user_info_simple($data['username']);
             $user_persona = UserManager::get_extra_user_data_by_field($user_info['user_id'], 'uidIdPersona');
             if (isset($user_persona['uidIdPersona']) && (string) $data['uidIdPersona'] == (string) $user_persona['uidIdPersona']) {
                 //error_log("2 Skip user already added: {$user_info['username']}");
                 return $user_info;
             } else {
                 //print_r($user_persona);
                 //error_log("2 homonym - wanted_username: {$data['username']} - uidIdPersona: {$user_persona['uidIdPersona']} - username: {$user_info['username']}");
                 //print_r($data);
                 //The user has the same firstname and lastname but it has another uiIdPersona could by an homonym
                 $data['username'] = UserManager::create_unique_username($data['firstname'], $data['lastname']);
                 //error_log("2 homonym username created ". $data['username']);
             }
         }
     }
     if (empty($data['username'])) {
         error_log('No Username provided');
         error_log(print_r($data, 1));
         return false;
         //exit;
     }
     $id_persona = $data['uidIdPersona'];
     unset($data['uidIdPersona']);
     unset($data['uidIdAlumno']);
     unset($data['uidIdEmpleado']);
     $data['encrypt_method'] = 'sha1';
     global $api_failureList;
     $api_failureList = array();
     //error_log(print_r($data, 1));
     $user_info = UserManager::add($data);
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:migration.custom.class.php


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