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


PHP uu_increment_username函数代码示例

本文整理汇总了PHP中uu_increment_username函数的典型用法代码示例。如果您正苦于以下问题:PHP uu_increment_username函数的具体用法?PHP uu_increment_username怎么用?PHP uu_increment_username使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: uu_increment_username

/**
 * Increments username - increments trailing number or adds it if not present.
 * Varifies that the new username does not exist yet
 * @param string $username
 * @return incremented username which does not exist yet
 */
function uu_increment_username($username)
{
    global $DB, $CFG;
    if (!preg_match_all('/(.*?)([0-9]+)$/', $username, $matches)) {
        $username = $username . '2';
    } else {
        $username = $matches[1][0] . ($matches[2][0] + 1);
    }
    if ($DB->record_exists('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
        return uu_increment_username($username);
    } else {
        return $username;
    }
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:20,代码来源:locallib.php

示例2: get_string

     $upt->track('username', $errorstr, 'error');
     $userserrors++;
     continue;
 } else {
     if ($user->username === 'guest') {
         $upt->track('status', get_string('guestnoeditprofileother', 'error'), 'error');
         $userserrors++;
         continue;
     }
 }
 if ($existinguser = $DB->get_record('user', array('username' => $user->username, 'mnethostid' => $CFG->mnet_localhost_id))) {
     $upt->track('id', $existinguser->id, 'normal', false);
 }
 // find out in username incrementing required
 if ($existinguser and $optype == UU_USER_ADDINC) {
     $user->username = uu_increment_username($user->username);
     $existinguser = false;
 }
 // notify about nay username changes
 if ($originalusername !== $user->username) {
     $upt->track('username', '', 'normal', false);
     // clear previous
     $upt->track('username', s($originalusername) . '-->' . s($user->username), 'info');
 } else {
     $upt->track('username', s($user->username), 'normal', false);
 }
 // add default values for remaining fields
 $formdefaults = array();
 foreach ($STD_FIELDS as $field) {
     if (isset($user->{$field})) {
         continue;
开发者ID:richheath,项目名称:moodle,代码行数:31,代码来源:uploaduser.php

示例3: prepare


//.........这里部分代码省略.........
         if ($this->importoptions['standardise']) {
             $oldusername = clean_param($oldusername, PARAM_USERNAME);
         }
         $this->existing = $this->exists($oldusername);
         if (!$this->can_update()) {
             $this->error('usernotupdatederror', new lang_string('usernotupdatederror', 'error'));
             return false;
         } else {
             if (!$this->existing) {
                 $this->error('usernotrenamedmissing', new lang_string('usernotrenamedmissing', 'error'));
                 return false;
             } else {
                 if (!$this->can_rename()) {
                     $this->error('usernotrenamedoff', new lang_string('usernotrenamedoff', 'error'));
                     return false;
                 }
             }
         }
         $this->do = self::DO_UPDATE;
         $this->set_status('userrenamed', new lang_string('userrenamed', 'tool_uploadusercli', array('from' => $oldusername, 'to' => $finaldata->username)));
     }
     // Do not update admin and guest account through the csv.
     if ($this->existing) {
         if (is_siteadmin($this->existing)) {
             $this->error('usernotupdatedadmin', new lang_string('usernotupdatedadmin', 'error'));
             return false;
         } else {
             if ($this->existing->username === 'guest') {
                 $this->error('guestnoeditprofileother', new lang_string('guestnoeditprofileother', 'error'));
                 return false;
             }
         }
     }
     // If exists, but we only want to create users, increment the username.
     if ($this->existing && $this->mode === tool_uploadusercli_processor::MODE_CREATE_ALL) {
         $original = $finaldata->username;
         $finaldata->username = uu_increment_username($finaldata->username);
         // We are creating a new user.
         $this->existing = NULL;
         if ($finaldata->username !== $original) {
             $this->set_status('userrenamed', new lang_string('userrenamed', 'tool_uploadusercli', array('from' => $original, 'to' => $this->name)));
         }
     }
     // Ultimate check mode vs. existence.
     switch ($this->mode) {
         case tool_uploadusercli_processor::MODE_CREATE_NEW:
             if ($this->existing) {
                 $this->error('usernotaddedregistered', new lang_string('usernotaddedregistered', 'error'));
                 return false;
             }
             break;
         case tool_uploadusercli_processor::MODE_CREATE_ALL:
             // This should not happen, we set existing to NULL when we increment.
             if ($this->existing) {
                 $this->error('usernotaddederror', new lang_string('usernotaddederror', 'error'));
                 return false;
             }
             break;
         case tool_uploadusercli_processor::MODE_UPDATE_ONLY:
             if (!$this->existing) {
                 $this->error('usernotcreatedoff', new lang_string('usernotcreatedoff', 'tool_uploadusercli'));
                 return false;
             }
             break;
         case tool_uploadusercli_processor::MODE_CREATE_OR_UPDATE:
             if ($this->existing) {
                 if ($this->updatemode === tool_uploadusercli_processor::UPDATE_NOTHING) {
                     $this->error('updatemodedoessettonothing', new lang_string('updatemodedoessettonothing', 'tool_uploadusercli'));
                     return false;
                 }
             }
             break;
         default:
             // O_o Huh?! This should really never happen here!
             $this->error('unknownuploadmode', new lang_string('unknownuploadmode', 'tool_uploadusercli'));
             return false;
     }
     // Get final data.
     if ($this->existing) {
         $missingonly = $this->updatemode === tool_uploadusercli_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAULTS;
         $finaldata = $this->get_final_update_data($finaldata, $this->existing, $UUC_DEFAULTS, $missingonly);
         if (!$finaldata) {
             $this->error('usernotupdatederror', new lang_string('usernotupdatederror', 'error'));
             return false;
         } else {
             $this->do = self::DO_UPDATE;
         }
     } else {
         $finaldata = $this->get_final_create_data($finaldata);
         if (!$finaldata) {
             $this->error('usernotaddederror', new lang_string('usernotaddederror', 'error'));
             return false;
         } else {
             $this->do = self::DO_CREATE;
         }
     }
     // Saving data.
     $this->finaldata = $finaldata;
     return true;
 }
开发者ID:alexandru-elisei,项目名称:moodle-tool_uploadusercli,代码行数:101,代码来源:user.php


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