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


PHP user_created::create方法代码示例

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


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

示例1: user_create_user

/**
 * Creates a user
 *
 * @param stdClass $user user to create
 * @param bool $updatepassword if true, authentication plugin will update password.
 * @return int id of the newly created user
 */
function user_create_user($user, $updatepassword = true)
{
    global $CFG, $DB;
    // Set the timecreate field to the current time.
    if (!is_object($user)) {
        $user = (object) $user;
    }
    // Check username.
    if ($user->username !== core_text::strtolower($user->username)) {
        throw new moodle_exception('usernamelowercase');
    } else {
        if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
            throw new moodle_exception('invalidusername');
        }
    }
    // Save the password in a temp value for later.
    if ($updatepassword && isset($user->password)) {
        // Check password toward the password policy.
        if (!check_password_policy($user->password, $errmsg)) {
            throw new moodle_exception($errmsg);
        }
        $userpassword = $user->password;
        unset($user->password);
    }
    // Make sure calendartype, if set, is valid.
    if (!empty($user->calendartype)) {
        $availablecalendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
        if (empty($availablecalendartypes[$user->calendartype])) {
            $user->calendartype = $CFG->calendartype;
        }
    } else {
        $user->calendartype = $CFG->calendartype;
    }
    $user->timecreated = time();
    $user->timemodified = $user->timecreated;
    // Insert the user into the database.
    $newuserid = $DB->insert_record('user', $user);
    // Create USER context for this user.
    $usercontext = context_user::instance($newuserid);
    // Update user password if necessary.
    if (isset($userpassword)) {
        // Get full database user row, in case auth is default.
        $newuser = $DB->get_record('user', array('id' => $newuserid));
        $authplugin = get_auth_plugin($newuser->auth);
        $authplugin->user_update_password($newuser, $userpassword);
    }
    // Trigger event.
    $event = \core\event\user_created::create(array('objectid' => $newuserid, 'context' => $usercontext));
    $event->trigger();
    return $newuserid;
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:58,代码来源:lib.php

示例2: local_ltiprovider_cron


//.........这里部分代码省略.........
                                    $grades = grade_get_grades($cm->course, 'mod', $cm->modname, $cm->instance, $user->userid);
                                    if (empty($grades->items[0]->grades)) {
                                        $grade = false;
                                    } else {
                                        $grade = reset($grades->items[0]->grades);
                                        if (!empty($grade->item)) {
                                            $grademax = floatval($grade->item->grademax);
                                        } else {
                                            $grademax = floatval($grades->items[0]->grademax);
                                        }
                                        $grade = $grade->grade;
                                    }
                                }
                            }
                            if ($grade === false || $grade === NULL || strlen($grade) < 1) {
                                mtrace("   Invalid grade {$grade}");
                                continue;
                            }
                            // No need to be dividing by zero
                            if ($grademax == 0.0) {
                                $grademax = 100.0;
                            }
                            // TODO: Make lastgrade should be float or string - but it is integer so we truncate
                            // TODO: Then remove those intval() calls
                            // Don't double send
                            if (intval($grade) == $user->lastgrade) {
                                mtrace("   Skipping, last grade send is equal to current grade");
                                continue;
                            }
                            // We sync with the external system only when the new grade differs with the previous one
                            // TODO - Global setting for check this
                            if ($grade >= 0 and $grade <= $grademax) {
                                $float_grade = $grade / $grademax;
                                $body = local_ltiprovider_create_service_body($user->sourceid, $float_grade);
                                try {
                                    $response = ltiprovider\sendOAuthBodyPOST('POST', $user->serviceurl, $user->consumerkey, $user->consumersecret, 'application/xml', $body);
                                } catch (Exception $e) {
                                    mtrace(" " . $e->getMessage());
                                    $error_count = $error_count + 1;
                                    continue;
                                }
                                // TODO - Check for errors in $retval in a correct way (parsing xml)
                                if (strpos(strtolower($response), 'success') !== false) {
                                    $DB->set_field('local_ltiprovider_user', 'lastsync', $timenow, array('id' => $user->id));
                                    $DB->set_field('local_ltiprovider_user', 'lastgrade', intval($grade), array('id' => $user->id));
                                    mtrace(" User grade sent to remote system. userid: {$user->userid} grade: {$float_grade}");
                                    $send_count = $send_count + 1;
                                } else {
                                    mtrace(" User grade send failed. userid: {$user->userid} grade: {$float_grade}: " . $response);
                                    $error_count = $error_count + 1;
                                }
                            } else {
                                mtrace(" User grade for user {$user->userid} out of range: grade = " . $grade);
                                $error_count = $error_count + 1;
                            }
                        } else {
                            mtrace(" Invalid context: contextid = " . $tool->contextid);
                        }
                    }
                }
                mtrace(" Completed sync tool id {$tool->id} course id {$tool->courseid} users={$user_count} sent={$send_count} errors={$error_count}");
                $DB->set_field('local_ltiprovider', 'lastsync', $timenow, array('id' => $tool->id));
            }
        }
    }
    $timenow = time();
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:67,代码来源:lib.php

示例3: stdClass

     $user = new stdClass();
     // clean_param , email username text
     $auth = get_config('local_ltiprovider', 'defaultauthmethod');
     if ($auth) {
         $user->auth = $auth;
     } else {
         $user->auth = 'nologin';
     }
     $user->username = $username;
     $user->password = md5(uniqid(rand(), 1));
     local_ltiprovider_populate($user, $context, $tool);
     $user->id = $DB->insert_record('user', $user);
     // Reload full user
     $user = $DB->get_record('user', array('id' => $user->id));
     // Trigger event.
     $event = \core\event\user_created::create(array('objectid' => $user->id, 'relateduserid' => $user->id, 'context' => context_user::instance($user->id)));
     $event->trigger();
 } else {
     $user = new stdClass();
     local_ltiprovider_populate($user, $context, $tool);
     if (local_ltiprovider_user_match($user, $dbuser)) {
         $user = $dbuser;
     } else {
         $user = $dbuser;
         $userprofileupdate = get_config('local_ltiprovider', 'userprofileupdate');
         if ($userprofileupdate == -1) {
             // Check the tool setting.
             $userprofileupdate = $tool->userprofileupdate;
         }
         if ($userprofileupdate) {
             local_ltiprovider_populate($user, $context, $tool);
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:31,代码来源:tool.php


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