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


PHP user_updated::create方法代码示例

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


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

示例1: user_update_user

/**
 * Update a user with a user object (will compare against the ID)
 *
 * @param stdClass $user the user to update
 * @param bool $updatepassword if true, authentication plugin will update password.
 */
function user_update_user($user, $updatepassword = true)
{
    global $DB;
    // set the timecreate field to the current time
    if (!is_object($user)) {
        $user = (object) $user;
    }
    //check username
    if (isset($user->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');
            }
        }
    }
    // Unset password here, for updating later, if password update is required.
    if ($updatepassword && isset($user->password)) {
        //check password toward the password policy
        if (!check_password_policy($user->password, $errmsg)) {
            throw new moodle_exception($errmsg);
        }
        $passwd = $user->password;
        unset($user->password);
    }
    $user->timemodified = time();
    $DB->update_record('user', $user);
    if ($updatepassword) {
        // Get full user record.
        $updateduser = $DB->get_record('user', array('id' => $user->id));
        // if password was set, then update its hash
        if (isset($passwd)) {
            $authplugin = get_auth_plugin($updateduser->auth);
            if ($authplugin->can_change_password()) {
                $authplugin->user_update_password($updateduser, $passwd);
            }
        }
    }
    // Trigger event.
    $event = \core\event\user_updated::create(array('objectid' => $user->id, 'context' => context_user::instance($user->id)));
    $event->trigger();
}
开发者ID:helenagarcia90,项目名称:moodle,代码行数:49,代码来源:lib.php

示例2: setnew_password_and_mail

/**
 * Sets specified user's password and send the new password to the user via email.
 *
 * @param stdClass $user A {@link $USER} object
 * @param bool $fasthash If true, use a low cost factor when generating the hash for speed.
 * @return bool|string Returns "true" if mail was sent OK and "false" if there was an error
 */
function setnew_password_and_mail($user, $fasthash = false)
{
    global $CFG, $DB;
    // We try to send the mail in language the user understands,
    // unfortunately the filter_string() does not support alternative langs yet
    // so multilang will not work properly for site->fullname.
    $lang = empty($user->lang) ? $CFG->lang : $user->lang;
    $site = get_site();
    $supportuser = core_user::get_support_user();
    $newpassword = generate_password();
    $hashedpassword = hash_internal_user_password($newpassword, $fasthash);
    $DB->set_field('user', 'password', $hashedpassword, array('id' => $user->id));
    $user->password = $hashedpassword;
    // Trigger event.
    $event = \core\event\user_updated::create(array('objectid' => $user->id, 'context' => context_user::instance($user->id)));
    $event->add_record_snapshot('user', $user);
    $event->trigger();
    $a = new stdClass();
    $a->firstname = fullname($user, true);
    $a->sitename = format_string($site->fullname);
    $a->username = $user->username;
    $a->newpassword = $newpassword;
    $a->link = $CFG->wwwroot . '/login/';
    $a->signoff = generate_email_signoff();
    $message = (string) new lang_string('newusernewpasswordtext', '', $a, $lang);
    $subject = format_string($site->fullname) . ': ' . (string) new lang_string('newusernewpasswordsubj', '', $a, $lang);
    // Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
    return email_to_user($user, $supportuser, $subject, $message);
}
开发者ID:eamador,项目名称:moodle-course-custom-fields,代码行数:36,代码来源:moodlelib.php

示例3: user_update_user

/**
 * Update a user with a user object (will compare against the ID)
 *
 * @param stdClass $user the user to update
 * @param bool $updatepassword if true, authentication plugin will update password.
 */
function user_update_user($user, $updatepassword = true)
{
    global $DB;
    // set the timecreate field to the current time
    if (!is_object($user)) {
        $user = (object) $user;
    }
    //check username
    if (isset($user->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');
            }
        }
    }
    // Unset password here, for updating later, if password update is required.
    if ($updatepassword && isset($user->password)) {
        //check password toward the password policy
        if (!check_password_policy($user->password, $errmsg)) {
            throw new moodle_exception($errmsg);
        }
        $passwd = $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 it doesn't exist, then unset this value, we do not want to update the user's value.
        if (empty($availablecalendartypes[$user->calendartype])) {
            unset($user->calendartype);
        }
    } else {
        // Unset this variable, must be an empty string, which we do not want to update the calendartype to.
        unset($user->calendartype);
    }
    $user->timemodified = time();
    $DB->update_record('user', $user);
    if ($updatepassword) {
        // Get full user record.
        $updateduser = $DB->get_record('user', array('id' => $user->id));
        // if password was set, then update its hash
        if (isset($passwd)) {
            $authplugin = get_auth_plugin($updateduser->auth);
            if ($authplugin->can_change_password()) {
                $authplugin->user_update_password($updateduser, $passwd);
            }
        }
    }
    // Trigger event.
    $event = \core\event\user_updated::create(array('objectid' => $user->id, 'context' => context_user::instance($user->id)));
    $event->trigger();
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:60,代码来源:lib.php

示例4: 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

示例5: isset

         $title = isset($usernew->usertitle) ? $usernew->usertitle : 0;
         assign_department_and_title_to_user($companyid, $department, $title, $usernew->id);
     }
 }
 // Reload from db.
 $usernew = $DB->get_record('user', array('id' => $usernew->id));
 // Trigger events.
 if ($usercreated) {
     // Set default message preferences.
     if (!message_set_default_message_preferences($usernew)) {
         print_error('cannotsavemessageprefs', 'message');
     }
     $event = \core\event\user_created::create_from_userid($usernew->id);
     $event->trigger();
 } else {
     $event = \core\event\user_updated::create(array('context' => $systemcontext, 'userid' => $usernew->id, 'relateduserid' => $USER->id));
     $event->trigger();
 }
 if ($user->id == $USER->id) {
     // Override old $USER session variable.
     foreach ((array) $usernew as $variable => $value) {
         $USER->{$variable} = $value;
     }
     if (!empty($USER->newadminuser)) {
         unset($USER->newadminuser);
         // Apply defaults again - some of them might depend on admin user info, backup, roles, etc..
         admin_apply_default_settings(null, false);
         // Redirect to admin/ to continue with installation.
         redirect("{$CFG->wwwroot}/{$CFG->admin}/");
     } else {
         redirect("{$CFG->wwwroot}/user/view.php?id={$USER->id}&course={$course->id}");
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:editadvanced.php

示例6: set_user_preference

         if ($isinternalauth && $updatepasswords) {
             if (empty($existinguser->password)) {
                 set_user_preference('create_password', 1, $existinguser->id);
                 set_user_preference('auth_forcepasswordchange', 1, $existinguser->id);
                 $upt->track('password', get_string('new'));
             } else {
                 if ($forcechangepassword) {
                     set_user_preference('auth_forcepasswordchange', 1, $existinguser->id);
                 }
             }
         }
         $upt->track('status', $struserupdated);
         $usersupdated++;
         // Save custom profile fields data from csv file.
         profile_save_data($existinguser);
         \core\event\user_updated::create(array('context' => $systemcontext, 'relateduserid' => $USER->id, 'userid' => $existinguser->id))->trigger();
     }
     if ($bulk == 2 or $bulk == 3) {
         if (!in_array($user->id, $SESSION->bulk_users)) {
             $SESSION->bulk_users[] = $user->id;
         }
     }
 } else {
     // Save the user to the database.
     $user->confirmed = 1;
     $user->timemodified = time();
     $user->timecreated = time();
     if (isset($user->auth) && empty($user->auth)) {
         $user->auth = 'manual';
     }
     $auth = get_auth_plugin($user->auth);
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:uploaduser.php

示例7: stdClass

     $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);
             $DB->update_record('user', $user);
             // Trigger event.
             $event = \core\event\user_updated::create(array('objectid' => $user->id, 'relateduserid' => $user->id, 'context' => context_user::instance($user->id)));
             $event->trigger();
         }
     }
 }
 // Update user image.
 if (!empty($context->info['user_image']) or !empty($context->info['custom_user_image'])) {
     $userimageurl = !empty($context->info['user_image']) ? $context->info['user_image'] : $context->info['custom_user_image'];
     local_ltiprovider_update_user_profile_image($user->id, $userimageurl);
 }
 // Enrol user in course and activity if needed
 if (!($moodlecontext = $DB->get_record('context', array('id' => $tool->contextid)))) {
     print_error("invalidcontext");
 }
 if ($moodlecontext->contextlevel == CONTEXT_COURSE) {
     $courseid = $moodlecontext->instanceid;
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:31,代码来源:tool.php


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