本文整理汇总了PHP中core_user类的典型用法代码示例。如果您正苦于以下问题:PHP core_user类的具体用法?PHP core_user怎么用?PHP core_user使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了core_user类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_all_data
/**
* Reset contents of all database tables to initial values, reset caches, etc.
*
* Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
*
* @static
* @param bool $detectchanges
* true - changes in global state and database are reported as errors
* false - no errors reported
* null - only critical problems are reported as errors
* @return void
*/
public static function reset_all_data($detectchanges = false)
{
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
// Stop any message redirection.
phpunit_util::stop_message_redirection();
// Stop any message redirection.
phpunit_util::stop_phpmailer_redirection();
// Stop any message redirection.
phpunit_util::stop_event_redirection();
// We used to call gc_collect_cycles here to ensure desctructors were called between tests.
// This accounted for 25% of the total time running phpunit - so we removed it.
// Show any unhandled debugging messages, the runbare() could already reset it.
self::display_debugging_messages();
self::reset_debugging();
// reset global $DB in case somebody mocked it
$DB = self::get_global_backup('DB');
if ($DB->is_transaction_started()) {
// we can not reset inside transaction
$DB->force_transaction_rollback();
}
$resetdb = self::reset_database();
$warnings = array();
if ($detectchanges === true) {
if ($resetdb) {
$warnings[] = 'Warning: unexpected database modification, resetting DB state';
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
if ($detectchanges !== false) {
$warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
}
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$_GET = array();
$_POST = array();
$_FILES = array();
$_REQUEST = array();
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
// Empty sessison and set fresh new not-logged-in user.
\core\session\manager::init_empty_session();
// reset all static caches
\core\event\manager::phpunit_reset();
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches(true);
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
filter_manager::reset_caches();
// Reset internal users.
core_user::reset_internal_users();
//TODO MDL-25290: add more resets here and probably refactor them to new core function
//.........这里部分代码省略.........
示例2: local_sandbox_inform_admin
/**
* Helper function for sending notification mails
*
* @param string $message The message
* @param int $level Notification level
* @return
*/
function local_sandbox_inform_admin($message, $level = SANDBOX_LEVEL_NOTICE)
{
// Get recipients
$recipients = get_users_from_config(get_config('local_sandbox', 'notifyonerrors'), 'moodle/site:config');
// If there are no recipients, don't execute.
if (!is_array($recipients) || count($recipients) <= 0) {
return false;
}
// If message level is below configured notice level, don't execute
if ($level < get_config('local_sandbox', 'notifylevel')) {
return false;
}
// Get subject
if ($level > SANDBOX_LEVEL_WARNING) {
$subject = get_string('emailsubjecterror', 'local_sandbox');
} else {
if ($level > SANDBOX_LEVEL_NOTICE) {
$subject = get_string('emailsubjectwarning', 'local_sandbox');
} else {
$subject = get_string('emailsubjectnotice', 'local_sandbox');
}
}
// Send mail
foreach ($recipients as $r) {
// Email the admin directly rather than putting these through the messaging system
email_to_user($r, core_user::get_support_user(), $subject, $message);
}
}
示例3: generate_message
/**
* Generates the message object for a give subscription and event.
*
* @param int $subscriptionid Subscription instance
* @param \stdClass $eventobj Event data
*
* @return false|\stdClass message object
*/
protected function generate_message($subscriptionid, \stdClass $eventobj)
{
try {
$subscription = subscription_manager::get_subscription($subscriptionid);
} catch (\dml_exception $e) {
// Race condition, someone deleted the subscription.
return false;
}
$user = \core_user::get_user($subscription->userid);
$context = \context_user::instance($user->id, IGNORE_MISSING);
if ($context === false) {
// User context doesn't exist. Should never happen, nothing to do return.
return false;
}
$template = $subscription->template;
$template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
$msgdata = new \stdClass();
$msgdata->component = 'tool_monitor';
// Your component name.
$msgdata->name = 'notification';
// This is the message name from messages.php.
$msgdata->userfrom = \core_user::get_noreply_user();
$msgdata->userto = $user;
$msgdata->subject = $subscription->get_name($context);
$msgdata->fullmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->fullmessageformat = $subscription->templateformat;
$msgdata->fullmessagehtml = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata->smallmessage = '';
$msgdata->notification = 1;
// This is only set to 0 for personal messages between users.
return $msgdata;
}
示例4: definition
/**
* Define the form.
*/
public function definition()
{
global $CFG, $COURSE;
$mform = $this->_form;
$choices = array();
$choices['0'] = get_string('emaildigestoff');
$choices['1'] = get_string('emaildigestcomplete');
$choices['2'] = get_string('emaildigestsubjects');
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
$mform->setDefault('maildigest', core_user::get_property_default('maildigest'));
$mform->addHelpButton('maildigest', 'emaildigest');
$choices = array();
$choices['1'] = get_string('autosubscribeyes');
$choices['0'] = get_string('autosubscribeno');
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', core_user::get_property_default('autosubscribe'));
if (!empty($CFG->forum_trackreadposts)) {
$choices = array();
$choices['0'] = get_string('trackforumsno');
$choices['1'] = get_string('trackforumsyes');
$mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
$mform->setDefault('trackforums', core_user::get_property_default('trackforums'));
}
// Add some extra hidden fields.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'course', $COURSE->id);
$mform->setType('course', PARAM_INT);
$this->add_action_buttons(true, get_string('savechanges'));
}
示例5: export_for_template
public function export_for_template(\renderer_base $output)
{
$data = new \stdClass();
$data->contacts = array();
$userids = array();
foreach ($this->contacts as $contact) {
$contact = new contact($contact);
$contactdata = $contact->export_for_template($output);
$userids[$contactdata->userid] = $contactdata->userid;
// Check if the contact was selected.
if ($this->contactuserid == $contactdata->userid) {
$contactdata->selected = true;
}
$data->contacts[] = $contactdata;
}
// Check if the other user is not part of the contacts. We may be sending a message to someone
// we have not had a conversation with, so we want to add a new item to the contacts array.
if ($this->contactuserid && !isset($userids[$this->contactuserid])) {
$user = \core_user::get_user($this->contactuserid);
// Set an empty message so that we know we are messaging the user, and not viewing their profile.
$user->smallmessage = '';
$user->useridfrom = $user->id;
$contact = \core_message\helper::create_contact($user);
$contact = new contact($contact);
$contactdata = $contact->export_for_template($output);
$contactdata->selected = true;
// Put the contact at the front.
array_unshift($data->contacts, $contactdata);
}
return $data;
}
示例6: get_popup_notifications
/**
* Get popup notifications for the specified users. Nothing is returned if notifications are disabled.
*
* @param int $useridto the user id who received the notification
* @param string $sort the column name to order by including optionally direction
* @param int $limit limit the number of result returned
* @param int $offset offset the result set by this amount
* @return array notification records
* @throws \moodle_exception
* @since 3.2
*/
public static function get_popup_notifications($useridto = 0, $sort = 'DESC', $limit = 0, $offset = 0)
{
global $DB, $USER;
$sort = strtoupper($sort);
if ($sort != 'DESC' && $sort != 'ASC') {
throw new \moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"');
}
if (empty($useridto)) {
$useridto = $USER->id;
}
$params = ['useridto1' => $useridto, 'useridto2' => $useridto];
// Is notification enabled ?
if ($useridto == $USER->id) {
$disabled = $USER->emailstop;
} else {
$user = \core_user::get_user($useridto, "emailstop", MUST_EXIST);
$disabled = $user->emailstop;
}
if ($disabled) {
// Notifications are disabled, no need to run giant queries.
return array();
}
$sql = "SELECT * FROM (\n SELECT concat('r', r.id) as uniqueid, r.id, r.useridfrom, r.useridto,\n r.subject, r.fullmessage, r.fullmessageformat,\n r.fullmessagehtml, r.smallmessage, r.notification, r.contexturl,\n r.contexturlname, r.timecreated, r.timeuserfromdeleted, r.timeusertodeleted,\n r.component, r.eventtype, r.timeread\n FROM {message_read} r\n WHERE r.notification = 1\n AND r.id IN (SELECT messageid FROM {message_popup} WHERE isread = 1)\n AND r.useridto = :useridto1\n UNION ALL\n SELECT concat('u', u.id) as uniqueid, u.id, u.useridfrom, u.useridto,\n u.subject, u.fullmessage, u.fullmessageformat,\n u.fullmessagehtml, u.smallmessage, u.notification, u.contexturl,\n u.contexturlname, u.timecreated, u.timeuserfromdeleted, u.timeusertodeleted,\n u.component, u.eventtype, 0 as timeread\n FROM {message} u\n WHERE u.notification = 1\n AND u.id IN (SELECT messageid FROM {message_popup} WHERE isread = 0)\n AND u.useridto = :useridto2\n ) f ORDER BY timecreated {$sort}, timeread {$sort}, id {$sort}";
return array_values($DB->get_records_sql($sql, $params, $offset, $limit));
}
示例7: __construct
/**
* Constructor.
*
* @param int $currentuserid The current user we are wanting to view messages for
* @param int $otheruserid The other user we are wanting to view messages for
* @param array $messages
*/
public function __construct($currentuserid, $otheruserid, $messages)
{
$ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess';
$this->currentuserid = $currentuserid;
if ($otheruserid) {
$this->otheruserid = $otheruserid;
$this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST);
}
$this->messages = $messages;
}
示例8: definition_after_data
/**
* Extend the form definition after the data has been parsed.
*/
public function definition_after_data()
{
global $CFG, $DB, $OUTPUT;
$mform = $this->_form;
// If language does not exist, use site default lang.
if ($langsel = $mform->getElementValue('lang')) {
$lang = reset($langsel);
// Check lang exists.
if (!get_string_manager()->translation_exists($lang, false)) {
$langel =& $mform->getElement('lang');
$langel->setValue(core_user::get_property_default('lang'));
}
}
}
示例9: test_create_user
public function test_create_user()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/user/lib.php';
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$count = $DB->count_records('user');
$this->setCurrentTimeStart();
$user = $generator->create_user();
$this->assertEquals($count + 1, $DB->count_records('user'));
$this->assertSame($user->username, core_user::clean_field($user->username, 'username'));
$this->assertSame($user->email, core_user::clean_field($user->email, 'email'));
$this->assertSame(AUTH_PASSWORD_NOT_CACHED, $user->password);
$this->assertNotEmpty($user->firstnamephonetic);
$this->assertNotEmpty($user->lastnamephonetic);
$this->assertNotEmpty($user->alternatename);
$this->assertNotEmpty($user->middlename);
$this->assertSame('manual', $user->auth);
$this->assertSame('en', $user->lang);
$this->assertSame('1', $user->confirmed);
$this->assertSame('0', $user->deleted);
$this->assertTimeCurrent($user->timecreated);
$this->assertSame($user->timecreated, $user->timemodified);
$this->assertSame('0.0.0.0', $user->lastip);
$record = array('auth' => 'email', 'firstname' => 'Žluťoučký', 'lastname' => 'Koníček', 'firstnamephonetic' => 'Zhlutyoucky', 'lastnamephonetic' => 'Koniiczek', 'middlename' => 'Hopper', 'alternatename' => 'horse', 'idnumber' => 'abc1', 'mnethostid' => (string) $CFG->mnet_localhost_id, 'username' => 'konic666', 'password' => 'password1', 'email' => 'email@example.com', 'confirmed' => '1', 'lang' => 'cs', 'maildisplay' => '1', 'mailformat' => '0', 'maildigest' => '1', 'autosubscribe' => '0', 'trackforums' => '0', 'deleted' => '0', 'timecreated' => '666');
$user = $generator->create_user($record);
$this->assertEquals($count + 2, $DB->count_records('user'));
foreach ($record as $k => $v) {
if ($k === 'password') {
$this->assertTrue(password_verify($v, $user->password));
} else {
$this->assertSame($v, $user->{$k});
}
}
$record = array('firstname' => 'Some', 'lastname' => 'User', 'idnumber' => 'def', 'username' => 'user666', 'email' => 'email666@example.com', 'deleted' => '1');
$user = $generator->create_user($record);
$this->assertEquals($count + 3, $DB->count_records('user'));
$this->assertSame('', $user->idnumber);
$this->assertSame(md5($record['username']), $user->email);
$this->assertFalse(context_user::instance($user->id, IGNORE_MISSING));
// Test generating user with interests.
$user = $generator->create_user(array('interests' => 'Cats, Dogs'));
$userdetails = user_get_user_details($user);
$this->assertSame('Cats, Dogs', $userdetails['interests']);
}
示例10: send_message
/**
* Send non-submitters message to students.
*
* @param string $message
* @return void
*/
public function send_message($userid, $subject, $message)
{
$eventdata = new stdClass();
$eventdata->component = 'mod_turnitintooltwo';
//your component name
$eventdata->name = 'nonsubmitters';
//this is the message name from messages.php
$eventdata->userfrom = \core_user::get_noreply_user();
$eventdata->userto = $userid;
$eventdata->subject = $subject;
$eventdata->fullmessage = $message;
$eventdata->fullmessageformat = FORMAT_HTML;
$eventdata->fullmessagehtml = $message;
$eventdata->smallmessage = '';
$eventdata->notification = 1;
//this is only set to 0 for personal messages between users
message_send($eventdata);
}
示例11: report_log_print_graph
/**
* This function is used to generate and display the log activity graph
*
* @global stdClass $CFG
* @param stdClass $course course instance
* @param int|stdClass $user id/object of the user whose logs are needed
* @param string $typeormode type of logs graph needed (usercourse.png/userday.png) or the mode (today, all).
* @param int $date timestamp in GMT (seconds since epoch)
* @param string $logreader Log reader.
* @return void
*/
function report_log_print_graph($course, $user, $typeormode, $date = 0, $logreader = '')
{
global $CFG, $OUTPUT;
if (!is_object($user)) {
$user = core_user::get_user($user);
}
$logmanager = get_log_manager();
$readers = $logmanager->get_readers();
if (empty($logreader)) {
$reader = reset($readers);
} else {
$reader = $readers[$logreader];
}
// If reader is not a sql_internal_table_reader and not legacy store then don't show graph.
if (!$reader instanceof \core\log\sql_internal_table_reader && !$reader instanceof logstore_legacy\log\store) {
return array();
}
$coursecontext = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->shortname, true, array('context' => $coursecontext));
$a->username = fullname($user, true);
if ($typeormode == 'today' || $typeormode == 'userday.png') {
$logs = report_log_usertoday_data($course, $user, $date, $logreader);
$title = get_string("hitsoncoursetoday", "", $a);
} else {
if ($typeormode == 'all' || $typeormode == 'usercourse.png') {
$logs = report_log_userall_data($course, $user, $logreader);
$title = get_string("hitsoncourse", "", $a);
}
}
if (!empty($CFG->preferlinegraphs)) {
$chart = new \core\chart_line();
} else {
$chart = new \core\chart_bar();
}
$series = new \core\chart_series(get_string("hits"), $logs['series']);
$chart->add_series($series);
$chart->set_title($title);
$chart->set_labels($logs['labels']);
$yaxis = $chart->get_yaxis(0, true);
$yaxis->set_label(get_string("hits"));
$yaxis->set_stepsize(max(1, round(max($logs['series']) / 10)));
echo $OUTPUT->render($chart);
}
示例12: get_user_badges
/**
* Returns the list of badges awarded to a user.
*
* @param int $userid user id
* @param int $courseid course id
* @param int $page page of records to return
* @param int $perpage number of records to return per page
* @param string $search a simple string to search for
* @param bool $onlypublic whether to return only public badges
* @return array array containing warnings and the awarded badges
* @since Moodle 3.1
* @throws moodle_exception
*/
public static function get_user_badges($userid = 0, $courseid = 0, $page = 0, $perpage = 0, $search = '', $onlypublic = false)
{
global $CFG, $USER;
$warnings = array();
$params = array('userid' => $userid, 'courseid' => $courseid, 'page' => $page, 'perpage' => $perpage, 'search' => $search, 'onlypublic' => $onlypublic);
$params = self::validate_parameters(self::get_user_badges_parameters(), $params);
if (empty($CFG->enablebadges)) {
throw new moodle_exception('badgesdisabled', 'badges');
}
if (empty($CFG->badges_allowcoursebadges) && $params['courseid'] != 0) {
throw new moodle_exception('coursebadgesdisabled', 'badges');
}
// Default value for userid.
if (empty($params['userid'])) {
$params['userid'] = $USER->id;
}
// Validate the user.
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
$usercontext = context_user::instance($user->id);
self::validate_context($usercontext);
if ($USER->id != $user->id) {
require_capability('moodle/badges:viewotherbadges', $usercontext);
// We are looking other user's badges, we must retrieve only public badges.
$params['onlypublic'] = true;
}
$userbadges = badges_get_user_badges($user->id, $params['courseid'], $params['page'], $params['perpage'], $params['search'], $params['onlypublic']);
$result = array();
$result['badges'] = array();
$result['warnings'] = $warnings;
foreach ($userbadges as $badge) {
$context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid);
$badge->badgeurl = moodle_url::make_webservice_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1')->out(false);
// Return all the information if we are requesting our own badges.
// Or, if we have permissions for configuring badges in the badge context.
if ($USER->id == $user->id or has_capability('moodle/badges:configuredetails', $context)) {
$result['badges'][] = (array) $badge;
} else {
$result['badges'][] = array('name' => $badge->name, 'description' => $badge->description, 'badgeurl' => $badge->badgeurl, 'issuername' => $badge->issuername, 'issuerurl' => $badge->issuerurl, 'issuercontact' => $badge->issuercontact, 'uniquehash' => $badge->uniquehash, 'dateissued' => $badge->dateissued, 'dateexpire' => $badge->dateexpire);
}
}
return $result;
}
示例13: test_get_user
public function test_get_user()
{
global $CFG;
$this->resetAfterTest(true);
// Create user and try fetach it with api.
$user = $this->getDataGenerator()->create_user();
$this->assertEquals($user, core_user::get_user($user->id, '*', MUST_EXIST));
// Test noreply user.
$CFG->noreplyuserid = null;
$noreplyuser = core_user::get_noreply_user();
$this->assertEquals(1, $noreplyuser->emailstop);
$this->assertFalse(core_user::is_real_user($noreplyuser->id));
$this->assertEquals($CFG->noreplyaddress, $noreplyuser->email);
$this->assertEquals(get_string('noreplyname'), $noreplyuser->firstname);
// Set user as noreply user and make sure noreply propery is set.
core_user::reset_internal_users();
$CFG->noreplyuserid = $user->id;
$noreplyuser = core_user::get_noreply_user();
$this->assertEquals(1, $noreplyuser->emailstop);
$this->assertTrue(core_user::is_real_user($noreplyuser->id));
// Test support user.
core_user::reset_internal_users();
$CFG->supportemail = null;
$CFG->noreplyuserid = null;
$supportuser = core_user::get_support_user();
$adminuser = get_admin();
$this->assertEquals($adminuser, $supportuser);
$this->assertTrue(core_user::is_real_user($supportuser->id));
// When supportemail is set.
core_user::reset_internal_users();
$CFG->supportemail = 'test@support.moodle.test';
$supportuser = core_user::get_support_user();
$this->assertEquals(core_user::SUPPORT_USER, $supportuser->id);
$this->assertFalse(core_user::is_real_user($supportuser->id));
// Set user as support user and make sure noreply propery is set.
core_user::reset_internal_users();
$CFG->supportuserid = $user->id;
$supportuser = core_user::get_support_user();
$this->assertEquals($user, $supportuser);
$this->assertTrue(core_user::is_real_user($supportuser->id));
}
示例14: activenotification
function activenotification($id){
global $DB, $USER, $CFG,$COURSE,$PAGE,$OUTPUT;
//Batch Name
$batchname=$DB->get_field('facetoface','name',array('id'=>$id));
//getting batch users
$batch_users=$DB->get_records_sql("select * from {local_batch_users} where f2fid=$id");
//getting session details
$session_details=$DB->get_records_sql("select * from {facetoface_sessions} where facetoface=$id");
$sessionsingle="<table border='1' style='text-align:center;'><tr><th>Serial</th><th>Startdate</th><th>Enddate</th><th>Classroom</th></tr>";
$n=1;
foreach($session_details as $session_detail){
//session dates
$startdateunix=$DB->get_field('facetoface_sessions_dates','timestart',array('sessionid'=>$session_detail->id));
$enddateuinx=$DB->get_field('facetoface_sessions_dates','timefinish',array('sessionid'=>$session_detail->id));
//converting dates
$statrtdate=date('d M Y H:i:s',$startdateunix);
$enddate=date('d M Y H:i:s',$enddateuinx);
//session room
$sessionroom=$DB->get_field('facetoface_room','name',array('id'=>$session_detail->roomid));
$sessionsingle .="<tr><td>$n</td><td>$statrtdate</td><td>$enddate</td><td>$sessionroom</td></tr>";
$n++;
}
// sending email to each users
foreach($batch_users as $batch_user){
$user_active_details=$DB->get_record_sql("select * from {user} where id=$batch_user->userid");
// Course Name
$coursename=$DB->get_field('course','fullname',array('id'=>$batch_user->courseid));
$from = core_user::get_support_user();
$subject =get_string('activenotification', 'facetoface');
$usermail=new stdClass();
$usermail->fullname=fullname($batch_user->userid);
$usermail->batchname=$batchname;
$usermail->coursename=$coursename;
$usermail->session=$sessionsingle;
$messagetext=get_string('activenotificationmsg', 'facetoface',$usermail);
$email=email_to_user($user_active_details,$from,$subject,$messagetext);
//print_object(email_to_user($user_active_details,$from,$subject,$messagetext));
}
}
示例15: execute
/**
* Run the deletion task.
*
* @throws \coding_exception if the module could not be removed.
*/
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/course/lib.php';
// Set the proper user.
if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
$realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST);
cron_setup_user($realuser);
\core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
} else {
$user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST);
cron_setup_user($user);
}
$cms = $this->get_custom_data()->cms;
foreach ($cms as $cm) {
try {
course_delete_module($cm->id);
} catch (\Exception $e) {
throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}");
}
}
}