本文整理汇总了PHP中SMS::notify方法的典型用法代码示例。如果您正苦于以下问题:PHP SMS::notify方法的具体用法?PHP SMS::notify怎么用?PHP SMS::notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMS
的用法示例。
在下文中一共展示了SMS::notify方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cron
function cron()
{
global $CFG;
echo "\n\n****** moodle_notifications :: begin ******";
$User = new User();
// clean deleted users data
$User->collect_garbage();
$Course = new Course();
// clean deleted courses data
$Course->collect_garbage();
// get the list of courses that are using this block
$courses = $Course->get_all_courses_using_moodle_notifications_block();
// if no courses are using this block exit
if (!is_array($courses) or count($courses) < 1) {
echo "\n--> None course is using moodle_notifications plugin.";
echo "\n****** moodle_notifications :: end ******\n\n";
return;
}
foreach ($courses as $course) {
// if course is not visible then skip
if ($course->visible == 0) {
continue;
}
// if the course has not been registered so far then register
echo "\n--> Processing course: {$course->fullname}";
if (!$Course->is_registered($course->id)) {
$Course->register($course->id, time());
}
// check notification frequency for this course
$course_registration = $Course->get_registration($course->id);
// initialize user preferences and check for new enrolled users in this course
$enrolled_users = $User->get_all_users_enrolled_in_the_course($course->id);
foreach ($enrolled_users as $user) {
// check if the user has preferences
$user_preferences = $User->get_preferences($user->id, $course->id);
// if the user has not preferences than set the default
if (is_null($user_preferences)) {
$user_preferences = new Object();
$user_preferences->user_id = $user->id;
$user_preferences->course_id = $course->id;
$user_preferences->notify_by_email = $course_registration->email_notification_preset;
$user_preferences->notify_by_sms = $course_registration->sms_notification_preset;
$User->initialize_preferences($user_preferences->user_id, $user_preferences->course_id, $user_preferences->notify_by_email, $user_preferences->notify_by_sms);
}
}
// if course log entry does not exist
// or the last notification time is older than two days
// then reinitialize course log
if (!$Course->log_exists($course->id) or $course_registration->last_notification_time + 48 * 3600 < time()) {
$Course->initialize_log($course);
}
// check notification frequency for the course and skip to next cron cycle if neccessary
if ($course_registration->last_notification_time + $course_registration->notification_frequency > time()) {
echo " - Skipping to next cron cycle.";
continue;
}
$Course->update_log($course);
// check if the course has something new or not
$changelist = $Course->get_recent_activities($course->id);
// update the last notification time
$Course->update_last_notification_time($course->id, time());
if (empty($changelist)) {
continue;
}
// check the next course. No new items in this one.
foreach ($enrolled_users as $user) {
// get user preferences
$user_preferences = $User->get_preferences($user->id, $course->id);
// if the email notification is enabled in the course
// and if the user has set the emailing notification in preferences
// then send a notification by email
if ($CFG->block_moodle_notifications_email_channel == 1 and $course_registration->notify_by_email == 1 and $user_preferences->notify_by_email == 1) {
$eMail = new eMail();
$eMail->notify($changelist, $user, $course);
}
// if the sms notification is enabled in the course
// and if the user has set the sms notification in preferences
// and if the user has set the mobile phone number
// then send a notification by sms
if (class_exists('SMS') and $CFG->block_moodle_notifications_sms_channel == 1 and $course_registration->notify_by_sms == 1 and $user_preferences->notify_by_sms == 1 and !empty($user->phone2)) {
$sms = new SMS();
$sms->notify($changelist, $user, $course);
}
}
}
echo "\n****** moodle_notifications :: end ******\n\n";
return;
}