當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。