/** * Function to be run periodically according to the moodle cron * Finds all facetoface notifications that have yet to be mailed out, and mails them. */ function facetoface_cron($testing = false) { global $DB; // Find "instant" manual notifications that haven't yet been sent if (!$testing) { mtrace('Checking for instant Face-to-face notifications'); } $manual = $DB->get_records_select( 'facetoface_notification', 'type = ? AND issent <> ? AND status = 1', array(MDL_F2F_NOTIFICATION_MANUAL, MDL_F2F_NOTIFICATION_STATE_FULLY_SENT)); if ($manual) { foreach ($manual as $notif) { $notification = new facetoface_notification((array)$notif, false); $notification->send_to_users(); } } // Find scheduled notifications that haven't yet been sent if (!$testing) { mtrace('Checking for scheduled Face-to-face notifications'); } $sched = $DB->get_records_select( 'facetoface_notification', 'scheduletime IS NOT NULL AND issent <> ? AND status = 1', array(MDL_F2F_NOTIFICATION_STATE_FULLY_SENT)); if ($sched) { foreach ($sched as $notif) { $notification = new facetoface_notification((array)$notif, false); $notification->send_scheduled(); } } return true; }