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


PHP core_user::get_noreply_user方法代码示例

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


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

示例1: 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;
 }
开发者ID:HuiChangZhai,项目名称:moodle,代码行数:40,代码来源:notification_task.php

示例2: 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);
 }
开发者ID:uofr,项目名称:moodle-mod_turnitintooltwo,代码行数:24,代码来源:nonsubmitters_message.php

示例3: 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));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:41,代码来源:user_test.php

示例4: send_instructor_message

 /**
  * Send instructor message to instructors on course.
  *
  * @param array $instructors
  * @param string $message
  * @return void
  */
 public function send_instructor_message($instructors, $message)
 {
     $subject = get_string('receipt_instructor_copy_subject', 'turnitintooltwo');
     $eventdata = new stdClass();
     $eventdata->component = 'mod_turnitintooltwo';
     //your component name
     $eventdata->name = 'submission';
     //this is the message name from messages.php
     $eventdata->userfrom = \core_user::get_noreply_user();
     $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
     foreach ($instructors as $instructor) {
         $eventdata->userto = $instructor->id;
         message_send($eventdata);
     }
     unset($instructor);
 }
开发者ID:unikent,项目名称:moodle-mod_turnitintooltwo,代码行数:29,代码来源:instructor_message.php

示例5: mod_assignment_pending_upgrades_notification

/**
 * Inform admins about assignments that still need upgrading.
 */
function mod_assignment_pending_upgrades_notification($count)
{
    $admins = get_admins();
    if (empty($admins)) {
        return;
    }
    $a = new stdClass();
    $a->count = $count;
    $a->docsurl = get_docs_url('Assignment_upgrade_tool');
    foreach ($admins as $admin) {
        $message = new stdClass();
        $message->component = 'moodle';
        $message->name = 'notices';
        $message->userfrom = \core_user::get_noreply_user();
        $message->userto = $admin;
        $message->smallmessage = get_string('pendingupgrades_message_small', 'mod_assignment');
        $message->subject = get_string('pendingupgrades_message_subject', 'mod_assignment');
        $message->fullmessage = get_string('pendingupgrades_message_content', 'mod_assignment', $a);
        $message->fullmessagehtml = get_string('pendingupgrades_message_content', 'mod_assignment', $a);
        $message->fullmessageformat = FORMAT_PLAIN;
        $message->notification = 1;
        message_send($message);
    }
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:27,代码来源:upgradelib.php

示例6: handle_verification_failure

 /**
  * Handle failure of sender verification.
  *
  * This will send a notification to the user identified in the Inbound Message address informing them that a message has been
  * stored. The message includes a verification link and reply-to address which is handled by the
  * invalid_recipient_handler.
  *
  * @param \Horde_Imap_Client_Ids $messageids
  * @param string $recipient The message recipient
  * @return bool
  */
 private function handle_verification_failure(\Horde_Imap_Client_Ids $messageids, $recipient)
 {
     global $DB, $USER;
     if (!($messageid = $this->currentmessagedata->messageid)) {
         mtrace("---> Warning: Unable to determine the Message-ID of the message.");
         return false;
     }
     // Move the message into a new mailbox.
     $this->client->copy(self::MAILBOX, $this->get_confirmation_folder(), array('create' => true, 'ids' => $messageids, 'move' => true));
     // Store the data from the failed message in the associated table.
     $record = new \stdClass();
     $record->messageid = $messageid;
     $record->userid = $USER->id;
     $record->address = $recipient;
     $record->timecreated = time();
     $record->id = $DB->insert_record('messageinbound_messagelist', $record);
     // Setup the Inbound Message generator for the invalid recipient handler.
     $addressmanager = new \core\message\inbound\address_manager();
     $addressmanager->set_handler('\\tool_messageinbound\\message\\inbound\\invalid_recipient_handler');
     $addressmanager->set_data($record->id);
     $eventdata = new \core\message\message();
     $eventdata->component = 'tool_messageinbound';
     $eventdata->name = 'invalidrecipienthandler';
     $userfrom = clone $USER;
     $userfrom->customheaders = array();
     // Adding the In-Reply-To header ensures that it is seen as a reply.
     $userfrom->customheaders[] = 'In-Reply-To: ' . $messageid;
     // The message will be sent from the intended user.
     $eventdata->courseid = SITEID;
     $eventdata->userfrom = \core_user::get_noreply_user();
     $eventdata->userto = $USER;
     $eventdata->subject = $this->get_reply_subject($this->currentmessagedata->envelope->subject);
     $eventdata->fullmessage = get_string('invalidrecipientdescription', 'tool_messageinbound', $this->currentmessagedata);
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = get_string('invalidrecipientdescriptionhtml', 'tool_messageinbound', $this->currentmessagedata);
     $eventdata->smallmessage = $eventdata->fullmessage;
     $eventdata->notification = 1;
     $eventdata->replyto = $addressmanager->generate($USER->id);
     mtrace("--> Sending a message to the user to report an verification failure.");
     if (!message_send($eventdata)) {
         mtrace("---> Warning: Message could not be sent.");
         return false;
     }
     return true;
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:56,代码来源:manager.php

示例7: quiz_send_overdue_message

/**
 * Send the notification message when a quiz attempt becomes overdue.
 *
 * @param object $course the course
 * @param object $quiz the quiz
 * @param object $attempt this attempt just finished
 * @param object $context the quiz context
 * @param object $cm the coursemodule for this quiz
 */
function quiz_send_overdue_message($course, $quiz, $attempt, $context, $cm) {
    global $CFG, $DB;

    // Do nothing if required objects not present.
    if (empty($course) or empty($quiz) or empty($attempt) or empty($context)) {
        throw new coding_exception('$course, $quiz, $attempt, $context and $cm must all be set.');
    }

    $submitter = $DB->get_record('user', array('id' => $attempt->userid), '*', MUST_EXIST);

    if (!has_capability('mod/quiz:emailwarnoverdue', $context, $submitter, false)) {
        return; // Message not required.
    }

    // Prepare lots of useful information that admins might want to include in
    // the email message.
    $quizname = format_string($quiz->name);

    $deadlines = array();
    if ($quiz->timelimit) {
        $deadlines[] = $attempt->timestart + $quiz->timelimit;
    }
    if ($quiz->timeclose) {
        $deadlines[] = $quiz->timeclose;
    }
    $duedate = min($deadlines);
    $graceend = $duedate + $quiz->graceperiod;

    $a = new stdClass();
    // Course info.
    $a->coursename         = $course->fullname;
    $a->courseshortname    = $course->shortname;
    // Quiz info.
    $a->quizname           = $quizname;
    $a->quizurl            = $CFG->wwwroot . '/mod/quiz/view.php?id=' . $cm->id;
    $a->quizlink           = '<a href="' . $a->quizurl . '">' . $quizname . '</a>';
    // Attempt info.
    $a->attemptduedate    = userdate($duedate);
    $a->attemptgraceend    = userdate($graceend);
    $a->attemptsummaryurl  = $CFG->wwwroot . '/mod/quiz/summary.php?attempt=' . $attempt->id;
    $a->attemptsummarylink = '<a href="' . $a->attemptsummaryurl . '">' . $quizname . ' review</a>';
    // Student's info.
    $a->studentidnumber    = $submitter->idnumber;
    $a->studentname        = fullname($submitter);
    $a->studentusername    = $submitter->username;

    // Prepare the message.
    $eventdata = new stdClass();
    $eventdata->component         = 'mod_quiz';
    $eventdata->name              = 'attempt_overdue';
    $eventdata->notification      = 1;

    $eventdata->userfrom          = core_user::get_noreply_user();
    $eventdata->userto            = $submitter;
    $eventdata->subject           = get_string('emailoverduesubject', 'quiz', $a);
    $eventdata->fullmessage       = get_string('emailoverduebody', 'quiz', $a);
    $eventdata->fullmessageformat = FORMAT_PLAIN;
    $eventdata->fullmessagehtml   = '';

    $eventdata->smallmessage      = get_string('emailoverduesmall', 'quiz', $a);
    $eventdata->contexturl        = $a->quizurl;
    $eventdata->contexturlname    = $a->quizname;

    // Send the message.
    return message_send($eventdata);
}
开发者ID:rwijaya,项目名称:moodle,代码行数:75,代码来源:locallib.php

示例8: format_string

     $teacher = false;
 }
 $mailstudents = $plugin->get_config('mailstudents');
 $mailteachers = $plugin->get_config('mailteachers');
 $mailadmins = $plugin->get_config('mailadmins');
 $shortname = format_string($course->shortname, true, array('context' => $context));
 if (!empty($mailstudents)) {
     $a = new stdClass();
     $a->coursename = format_string($course->fullname, true, array('context' => $coursecontext));
     $a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}";
     $eventdata = new \core\message\message();
     $eventdata->courseid = $course->id;
     $eventdata->modulename = 'moodle';
     $eventdata->component = 'enrol_paypal';
     $eventdata->name = 'paypal_enrolment';
     $eventdata->userfrom = empty($teacher) ? core_user::get_noreply_user() : $teacher;
     $eventdata->userto = $user;
     $eventdata->subject = get_string("enrolmentnew", 'enrol', $shortname);
     $eventdata->fullmessage = get_string('welcometocoursetext', '', $a);
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '';
     $eventdata->smallmessage = '';
     message_send($eventdata);
 }
 if (!empty($mailteachers) && !empty($teacher)) {
     $a->course = format_string($course->fullname, true, array('context' => $coursecontext));
     $a->user = fullname($user);
     $eventdata = new \core\message\message();
     $eventdata->courseid = $course->id;
     $eventdata->modulename = 'moodle';
     $eventdata->component = 'enrol_paypal';
开发者ID:lucaboesch,项目名称:moodle,代码行数:31,代码来源:ipn.php

示例9: notify_student_submission_receipt

 /**
  * Notify student upon successful submission.
  *
  * @param stdClass $submission
  * @return void
  */
 protected function notify_student_submission_receipt(stdClass $submission)
 {
     global $DB, $USER;
     $adminconfig = $this->get_admin_config();
     if (empty($adminconfig->submissionreceipts)) {
         // No need to do anything.
         return;
     }
     if ($submission->userid) {
         $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
     } else {
         $user = $USER;
     }
     if ($submission->userid == $USER->id) {
         $this->send_notification(core_user::get_noreply_user(), $user, 'submissionreceipt', 'assign_notification', $submission->timemodified);
     } else {
         $this->send_notification($USER, $user, 'submissionreceiptother', 'assign_notification', $submission->timemodified);
     }
 }
开发者ID:mercysmart,项目名称:naikelas,代码行数:25,代码来源:locallib.php

示例10: forum_cron


//.........这里部分代码省略.........
                        }
                        if (!isset($userfrom->groups[$forum->id])) {
                            if (!isset($userfrom->groups)) {
                                $userfrom->groups = array();
                                if (isset($users[$userfrom->id])) {
                                    $users[$userfrom->id]->groups = array();
                                }
                            }
                            $userfrom->groups[$forum->id] = groups_get_all_groups($course->id, $userfrom->id, $cm->groupingid);
                            if (isset($users[$userfrom->id])) {
                                $users[$userfrom->id]->groups[$forum->id] = $userfrom->groups[$forum->id];
                            }
                        }
                        // Headers to help prevent auto-responders.
                        $userfrom->customheaders = array("Precedence: Bulk", 'X-Auto-Response-Suppress: All', 'Auto-Submitted: auto-generated');
                        $maildigest = forum_get_user_maildigest_bulk($digests, $userto, $forum->id);
                        if (!isset($userto->canpost[$discussion->id])) {
                            $canreply = forum_user_can_post($forum, $discussion, $userto, $cm, $course, $modcontext);
                        } else {
                            $canreply = $userto->canpost[$discussion->id];
                        }
                        $data = new \mod_forum\output\forum_post_email($course, $cm, $forum, $discussion, $post, $userfrom, $userto, $canreply);
                        if (!isset($userto->viewfullnames[$forum->id])) {
                            $data->viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
                        } else {
                            $data->viewfullnames = $userto->viewfullnames[$forum->id];
                        }
                        if ($maildigest == 2) {
                            // Subjects and link only.
                            $posttext .= $textdigestbasicout->render($data);
                            $posthtml .= $htmldigestbasicout->render($data);
                        } else {
                            // The full treatment.
                            $posttext .= $textdigestfullout->render($data);
                            $posthtml .= $htmldigestfullout->render($data);
                            // Create an array of postid's for this user to mark as read.
                            if (!$CFG->forum_usermarksread) {
                                $userto->markposts[$post->id] = $post->id;
                            }
                        }
                        $sentcount++;
                    }
                    $footerlinks = array();
                    if ($canunsubscribe) {
                        $footerlinks[] = "<a href=\"{$CFG->wwwroot}/mod/forum/subscribe.php?id={$forum->id}\">" . get_string("unsubscribe", "forum") . "</a>";
                    } else {
                        $footerlinks[] = get_string("everyoneissubscribed", "forum");
                    }
                    $footerlinks[] = "<a href='{$CFG->wwwroot}/mod/forum/index.php?id={$forum->course}'>" . get_string("digestmailpost", "forum") . '</a>';
                    $posthtml .= "\n<div class='mdl-right'><font size=\"1\">" . implode('&nbsp;', $footerlinks) . '</font></div>';
                    $posthtml .= '<hr size="1" noshade="noshade" /></p>';
                }
                if (empty($userto->mailformat) || $userto->mailformat != 1) {
                    // This user DOESN'T want to receive HTML
                    $posthtml = '';
                }
                $eventdata = new \core\message\message();
                $eventdata->courseid = SITEID;
                $eventdata->component = 'mod_forum';
                $eventdata->name = 'digests';
                $eventdata->userfrom = core_user::get_noreply_user();
                $eventdata->userto = $userto;
                $eventdata->subject = $postsubject;
                $eventdata->fullmessage = $posttext;
                $eventdata->fullmessageformat = FORMAT_PLAIN;
                $eventdata->fullmessagehtml = $posthtml;
                $eventdata->notification = 1;
                $eventdata->smallmessage = get_string('smallmessagedigest', 'forum', $sentcount);
                $mailresult = message_send($eventdata);
                if (!$mailresult) {
                    mtrace("ERROR: mod/forum/cron.php: Could not send out digest mail to user {$userto->id} " . "({$userto->email})... not trying again.");
                } else {
                    mtrace("success.");
                    $usermailcount++;
                    // Mark post as read if forum_usermarksread is set off
                    if (get_user_preferences('forum_markasreadonnotification', 1, $userto->id) == 1) {
                        forum_tp_mark_posts_read($userto, $userto->markposts);
                    }
                }
            }
        }
        /// We have finishied all digest emails, update $CFG->digestmailtimelast
        set_config('digestmailtimelast', $timenow);
    }
    cron_setup_user();
    if (!empty($usermailcount)) {
        mtrace(get_string('digestsentusers', 'forum', $usermailcount));
    }
    if (!empty($CFG->forum_lastreadclean)) {
        $timenow = time();
        if ($CFG->forum_lastreadclean + 24 * 3600 < $timenow) {
            set_config('forum_lastreadclean', $timenow);
            mtrace('Removing old forum read tracking info...');
            forum_tp_clean_read_records();
        }
    } else {
        set_config('forum_lastreadclean', time());
    }
    return true;
}
开发者ID:rezaies,项目名称:moodle,代码行数:101,代码来源:lib.php

示例11: test_comment_add_plan

 /**
  * Commenting on a plan.
  */
 public function test_comment_add_plan()
 {
     $this->resetAfterTest();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $u3 = $dg->create_user();
     $userroleid = $dg->create_role();
     $reviewerroleid = $dg->create_role();
     assign_capability('moodle/competency:planviewowndraft', CAP_ALLOW, $userroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planviewown', CAP_ALLOW, $userroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planviewdraft', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planmanage', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:plancomment', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     $dg->role_assign($userroleid, $u1->id, context_user::instance($u1->id));
     $dg->role_assign($reviewerroleid, $u2->id, context_user::instance($u1->id));
     $dg->role_assign($reviewerroleid, $u3->id, context_system::instance());
     accesslib_clear_all_caches_for_unit_testing();
     $p1 = $lpg->create_plan(array('userid' => $u1->id));
     // Post a comment in own plan, no reviewer. Nobody is messaged.
     $this->setUser($u1);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(0, $messages);
     // Post a comment in plan as someone else, no reviewer. The owner is messages.
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u1->id, $message->useridto);
     // Post a comment in a plan with reviewer. The reviewer is messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u1);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u2->id, $message->useridto);
     // Post a comment as reviewer in a plan being reviewed. The owner is messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u2);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u1->id, $message->useridto);
     // Post a comment as someone else in a plan being reviewed. The owner and reviewer are messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(2, $messages);
     $message1 = array_shift($messages);
     $message2 = array_shift($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message1->useridfrom);
     $this->assertEquals($u1->id, $message1->useridto);
     $this->assertEquals(core_user::get_noreply_user()->id, $message2->useridfrom);
     $this->assertEquals($u2->id, $message2->useridto);
     $p1->set_reviewerid(null);
     $p1->update();
     // Test message content.
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $expectedurlname = $p1->get_name();
     $expectedurl = url::plan($p1->get_id());
     $this->assertTrue(strpos($message->fullmessage, 'Hello world!') !== false);
     $this->assertTrue(strpos($message->fullmessagehtml, 'Hello world!') !== false);
     $this->assertEquals(FORMAT_MOODLE, $message->fullmessageformat);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:lib_test.php

示例12: test_require_active_user

 /**
  * Test require_active_user
  */
 public function test_require_active_user()
 {
     global $DB;
     // Create a default user for the test.
     $userexpected = $this->getDataGenerator()->create_user();
     // Simple case, all good.
     core_user::require_active_user($userexpected, true, true);
     // Set user not confirmed.
     $DB->set_field('user', 'confirmed', 0, array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected);
     } catch (moodle_exception $e) {
         $this->assertEquals('usernotconfirmed', $e->errorcode);
     }
     $DB->set_field('user', 'confirmed', 1, array('id' => $userexpected->id));
     // Set nologin auth method.
     $DB->set_field('user', 'auth', 'nologin', array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected, false, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('suspended', $e->errorcode);
     }
     // Check no exceptions are thrown if we don't specify to check suspended.
     core_user::require_active_user($userexpected);
     $DB->set_field('user', 'auth', 'manual', array('id' => $userexpected->id));
     // Set user suspended.
     $DB->set_field('user', 'suspended', 1, array('id' => $userexpected->id));
     try {
         core_user::require_active_user($userexpected, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('suspended', $e->errorcode);
     }
     // Check no exceptions are thrown if we don't specify to check suspended.
     core_user::require_active_user($userexpected);
     // Delete user.
     delete_user($userexpected);
     try {
         core_user::require_active_user($userexpected);
     } catch (moodle_exception $e) {
         $this->assertEquals('userdeleted', $e->errorcode);
     }
     // Use a not real user.
     $noreplyuser = core_user::get_noreply_user();
     try {
         core_user::require_active_user($noreplyuser, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('invaliduser', $e->errorcode);
     }
     // Get the guest user.
     $guestuser = $DB->get_record('user', array('username' => 'guest'));
     try {
         core_user::require_active_user($guestuser, true);
     } catch (moodle_exception $e) {
         $this->assertEquals('guestsarenotallowed', $e->errorcode);
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:59,代码来源:user_test.php

示例13: local_uai_send_notifications

function local_uai_send_notifications($cron = true, $debug = false, $debugsend = false, $course = 0)
{
    global $DB, $USER;
    // Get the notifications configured
    if ($course) {
        $quiznotifications = $DB->get_records('local_uai_quiz_notifications', array('course' => $course));
    } else {
        $quiznotifications = $DB->get_records('local_uai_quiz_notifications');
    }
    $numnotifications = count($quiznotifications);
    // If there are any
    if ($numnotifications > 0) {
        // Process each course separatedly
        foreach ($quiznotifications as $quiznotification) {
            if (!($course = $DB->get_record('course', array('id' => $quiznotification->course)))) {
                $msg = 'Invalid course id ' . $quiznotification->course;
                if ($cron) {
                    mtrace($msg);
                } else {
                    if ($debug) {
                        echo $msg;
                    }
                }
                continue;
            }
            $msg = 'Processing notifications for course ' . $course->fullname;
            if ($cron) {
                mtrace($msg);
            } else {
                if ($debug) {
                    echo $msg;
                }
            }
            // Get the attempts
            $attemptsSemester = local_uai_get_quiz_attempts($course->id, -365);
            // Calculate stats for the attempts
            list($studentinfoSemester, $coursestatsSemester) = local_uai_get_stats_from_attempts($attemptsSemester);
            // Get the attempts
            $attempts = local_uai_get_quiz_attempts($course->id, -7);
            $userfrom = \core_user::get_noreply_user();
            $userfrom->maildisplay = true;
            $totalmessages = 1;
            foreach ($attempts as $studentinfo) {
                // The user to be notified
                if ($debugsend) {
                    $userto = $DB->get_record('user', array('id' => $USER->id));
                } else {
                    $userto = $DB->get_record('user', array('id' => $studentinfo->uid));
                }
                // Email subject
                $subject = 'Informe de tu trabajo on-line';
                $message = '<html>';
                $message .= '<p><strong>Estimado(a) ' . $studentinfo->firstname . ' ' . $studentinfo->lastname . '</strong>,</p>';
                $message .= '<p>Quiero que notes que respecto de tu trabajo con los ejercicios de wiris:</p>';
                $message .= '<p>Esta semana realizaste  ' . $studentinfo->finished . '  intentos';
                if ($studentinfo->correct > 0) {
                    $message .= ', de los cuales contestaste adecuadamente ' . $studentinfo->correct;
                }
                $message .= '.<br/>';
                $message .= 'Desde el inicio del curso hasta ahora llevas acumulado un trabajo de ' . $studentinfoSemester[$studentinfo->uid]->finished . ' intentos y en promedio un ';
                $message .= 'alumno del curso ha trabajado ' . $coursestatsSemester->avgfinished . ',  con un máximo de ' . $coursestatsSemester->maxfinished . ' intentos.</p><br/><br/>';
                $message .= 'Quedo en espera de tus dudas.';
                $message .= '</html>';
                $eventdata = new stdClass();
                $eventdata->component = 'local_uai';
                $eventdata->name = 'quizzes_notification';
                $eventdata->userto = $userto;
                $eventdata->userfrom = $userfrom;
                $eventdata->subject = $subject;
                $eventdata->fullmessage = format_text_email($message, FORMAT_HTML);
                $eventdata->fullmessageformat = FORMAT_HTML;
                $eventdata->fullmessagehtml = $message;
                $eventdata->smallmessage = $subject;
                $eventdata->notification = 1;
                // this is only set to 0 for personal messages between users
                if ($userto) {
                    if (!$debug || $debugsend) {
                        $send = message_send($eventdata);
                    }
                    if ($debug) {
                        echo '<hr>';
                        echo 'Subject: ' . $subject . '<br/>';
                        echo "To: {$userto->firstname} {$userto->lastname} &lt;{$userto->email}&gt;<br/>";
                        echo $message;
                    }
                    $totalmessages++;
                } else {
                    if ($cron) {
                        mtrace("Error sending message to {$userto}");
                    }
                }
                if ($debugsend) {
                    break;
                }
            }
        }
    }
    return array($totalmessages, $numnotifications);
}
开发者ID:jorgecabane93,项目名称:uai,代码行数:99,代码来源:locallib.php

示例14: unregister_from_agrp


//.........这里部分代码省略.........
                     if (!empty($this->grouptool->immediate_reg)) {
                         groups_add_member($groupdata->id, $newrecord->userid);
                     }
                     $allowm = $this->grouptool->allow_multiple;
                     $usrregcnt = $this->get_user_reg_count(0, $newrecord->userid);
                     $max = $this->grouptool->choose_max;
                     if ($allowm && $usrregcnt >= $max || !$allowm) {
                         $agrps = $this->get_active_groups(false, false, 0, 0, 0, false);
                         $agrpids = array_keys($agrps);
                         list($sql, $params) = $DB->get_in_or_equal($agrpids);
                         $records = $DB->get_records_sql("SELECT queued.*, agrp.groupid\n                                                               FROM {grouptool_queued} queued\n                                                               JOIN {grouptool_agrps} agrp ON queued.agrpid = agrp.id\n                                                              WHERE userid = ? AND agrpid " . $sql, array_merge(array($newrecord->userid), $params));
                         $DB->delete_records_select('grouptool_queued', ' userid = ? AND agrpid ' . $sql, array_merge(array($newrecord->userid), $params));
                         foreach ($records as $cur) {
                             // Trigger the event!
                             \mod_grouptool\event\queue_entry_deleted::create_limit_violation($this->cm, $cur)->trigger();
                         }
                     }
                     $strgrouptools = get_string("modulenameplural", "grouptool");
                     $strgrouptool = get_string("modulename", "grouptool");
                     $postsubject = $this->course->shortname . ': ' . $strgrouptools . ': ' . format_string($this->grouptool->name, true);
                     $posttext = $this->course->shortname . ' -> ' . $strgrouptools . ' -> ' . format_string($this->grouptool->name, true) . "\n";
                     $posttext .= "----------------------------------------------------------\n";
                     $posttext .= get_string("register_you_in_group_successmail", "grouptool", $message) . "\n";
                     $posttext .= "----------------------------------------------------------\n";
                     $usermailformat = $DB->get_field('user', 'mailformat', array('id' => $newrecord->userid));
                     if ($usermailformat == 1) {
                         // HTML!
                         $posthtml = "<p><font face=\"sans-serif\">";
                         $posthtml = "<a href=\"" . $CFG->wwwroot . "/course/view.php?id=" . $this->course->id . "\">" . $this->course->shortname . "</a> ->";
                         $posthtml = "<a href=\"" . $CFG->wwwroot . "/mod/grouptool/index.php?id=" . $this->course->id . "\">" . $strgrouptools . "</a> ->";
                         $posthtml = "<a href=\"" . $CFG->wwwroot . "/mod/grouptool/view.php?id=" . $this->cm->id . "\">" . format_string($this->grouptool->name, true) . "</a></font></p>";
                         $posthtml .= "<hr /><font face=\"sans-serif\">";
                         $posthtml .= "<p>" . get_string("register_you_in_group_successmailhtml", "grouptool", $message) . "</p>";
                         $posthtml .= "</font><hr />";
                     } else {
                         $posthtml = "";
                     }
                     $messageuser = $DB->get_record('user', array('id' => $newrecord->userid));
                     $eventdata = new stdClass();
                     $eventdata->modulename = 'grouptool';
                     $userfrom = core_user::get_noreply_user();
                     $eventdata->userfrom = $userfrom;
                     $eventdata->userto = $messageuser;
                     $eventdata->subject = $postsubject;
                     $eventdata->fullmessage = $posttext;
                     $eventdata->fullmessageformat = FORMAT_PLAIN;
                     $eventdata->fullmessagehtml = $posthtml;
                     $eventdata->smallmessage = get_string('register_you_in_group_success', 'grouptool', $message);
                     $eventdata->name = 'grouptool_moveupreg';
                     $eventdata->component = 'mod_grouptool';
                     $eventdata->notification = 1;
                     $eventdata->contexturl = $CFG->wwwroot . '/mod/grouptool/view.php?id=' . $this->cm->id;
                     $eventdata->contexturlname = $this->grouptool->name;
                     message_send($eventdata);
                     $DB->delete_records('grouptool_queued', array('id' => $record->id));
                     // Trigger the event!
                     // We fetched groupid above in SQL.
                     \mod_grouptool\event\user_moved::promotion_from_queue($this->cm, $record, $newrecord)->trigger();
                 }
                 if ($userid == $USER->id) {
                     return array(false, get_string('unreg_you_from_group_success', 'grouptool', $message));
                 } else {
                     return array(false, get_string('unreg_from_group_success', 'grouptool', $message));
                 }
             }
         } else {
             if ($this->get_rank_in_queue($groupdata->queued, $userid) != false) {
                 // He is queued!
                 if ($previewonly) {
                     if ($userid == $USER->id) {
                         return array(false, get_string('unqueue_you_from_group', 'grouptool', $message));
                     } else {
                         return array(false, get_string('unqueue_from_group', 'grouptool', $message));
                     }
                 } else {
                     $records = $DB->get_records('grouptool_queued', array('agrpid' => $agrpid, 'userid' => $userid));
                     $DB->delete_records('grouptool_queued', array('agrpid' => $agrpid, 'userid' => $userid));
                     foreach ($records as $cur) {
                         // Trigger the Event!
                         $cur->groupid = $groupdata->id;
                         \mod_grouptool\event\queue_entry_deleted::create_direct($this->cm, $cur)->trigger();
                     }
                     if ($userid == $USER->id) {
                         return array(false, get_string('unqueue_you_from_group_success', 'grouptool', $message));
                     } else {
                         return array(false, get_string('unqueue_from_group_success', 'grouptool', $message));
                     }
                 }
             } else {
                 if ($userid == $USER->id) {
                     return array(true, get_string('you_are_not_in_queue_or_registered', 'grouptool', $message));
                 } else {
                     return array(true, get_string('not_in_queue_or_registered', 'grouptool', $message));
                 }
             }
         }
     } else {
         return array(true, get_string('error_getting_data', 'grouptool'));
     }
 }
开发者ID:rimacher,项目名称:moodle-mod_grouptool,代码行数:101,代码来源:locallib.php

示例15: sendemail

 /**
  * Sends an email to each owner
  *
  * @param object $obj user array with courses attached
  * @return array of courses that match the search
  */
 protected function sendemail($obj)
 {
     global $CFG, $DB;
     if (empty($CFG->siteadmins)) {
         // Should not happen on an ordinary site.
         return false;
     } else {
         $admin = get_admin();
     }
     $config = get_config('tool_coursearchiver');
     switch ($this->mode) {
         case self::MODE_HIDEEMAIL:
             $subject = get_string('hidewarningsubject', 'tool_coursearchiver');
             $message = $config->hidewarningemailsetting;
             break;
         case self::MODE_ARCHIVEEMAIL:
             $subject = get_string('archivewarningsubject', 'tool_coursearchiver');
             $message = $config->archivewarningemailsetting;
             break;
         default:
             $this->errors[] = get_string('invalidmode', 'tool_coursearchiver');
             return false;
     }
     $courses = $this->get_email_courses($obj, $admin);
     if (!empty($courses)) {
         $c = "";
         foreach ($courses as $coursetext) {
             $c .= $coursetext;
         }
         // Make sure both the %to variable and the %courses variable exist in the message template.
         if (!strstr($message, '%to')) {
             $this->errors[] = get_string('errormissingto', 'tool_coursearchiver');
             return 0;
         }
         if (!strstr($message, '%courses')) {
             $this->errors[] = get_string('errormissingcourses', 'tool_coursearchiver');
             return 0;
         }
         $vars = array('%to' => $obj["user"]->firstname . ' ' . $obj["user"]->lastname, '%courses' => $c);
         $message = strtr(nl2br($message), $vars);
         $event = new \core\message\message();
         $event->component = 'tool_coursearchiver';
         $event->name = 'courseowner';
         $event->userfrom = core_user::get_noreply_user();
         $event->userto = $obj["user"];
         $event->subject = $subject;
         $event->fullmessage = '';
         $event->fullmessageformat = FORMAT_MARKDOWN;
         $event->fullmessagehtml = $message;
         $event->smallmessage = $subject;
         $event->notification = '1';
         $event->contexturl = $CFG->wwwroot;
         $event->contexturlname = 'Course Archiver';
         $event->replyto = $admin->email;
         try {
             $messageid = message_send($event);
         } catch (Exception $e) {
             $this->errors[] = get_string('errorsendingemail', 'tool_coursearchiver', $obj["user"]);
             return false;
         }
         return count($courses);
     } else {
         return 0;
     }
 }
开发者ID:pennedav,项目名称:moodle-tool_coursearchiver,代码行数:71,代码来源:processor.php


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