Example #1
0
/**
 * Receives a message event object from moodletxt+
 * and sens an SMS to the destination user as per their
 * preferences
 * @param object $messageObject Message event object
 * @version 2012062401
 * @since 2012062401
 */
function send_moodletxt_plus_message($messageObject)
{
    $accountDAO = new TxttoolsAccountDAO();
    $userDAO = new MoodletxtMoodleUserDAO();
    $messageDAO = new TxttoolsSentMessageDAO();
    // moodletxt requires a ConnectTxt account to be specified
    // for this message to transition via
    $defaultAccountId = (int) get_config('moodletxt', 'Event_Messaging_Account');
    if ($defaultAccountId > 0) {
        $connectTxtAccount = $accountDAO->getTxttoolsAccountById($defaultAccountId);
        // Check that the specified account has outbound enabled
        if ($connectTxtAccount->isOutboundEnabled()) {
            $sender = $userDAO->getUserById($messageObject->from_id);
            $recipient = $userDAO->getUserById($messageObject->to_id);
            $message = new MoodletxtOutboundMessage($connectTxtAccount, $sender, $messageObject->smallmessage, time(), MoodletxtOutboundMessage::$MESSAGE_CHARGE_TYPE_BULK);
            $message->addMessageRecipient($recipient);
            $message->setEventCreated(true);
            // Send message to ConnectTxt
            try {
                $connector = MoodletxtOutboundControllerFactory::getOutboundController(MoodletxtOutboundControllerFactory::$CONTROLLER_TYPE_XML);
                $message->setSentSMSMessages($connector->sendMessage($message));
                $messageDAO->saveSentMessage($message);
            } catch (MoodletxtRemoteProcessingException $ex) {
                // Die silently, for now
            }
        }
    }
}
Example #2
0
     $destinations += $userDAO->getUsersById($moodleUsers, 'phone');
 }
 // If there are valid destinations, send the message
 if (count($destinations) > 0) {
     $txttoolsAccount = $accountDAO->getTxttoolsAccountById($formData->txttoolsaccount);
     $thisUser = new MoodletxtBiteSizedUser($USER->id, $USER->username, $USER->firstname, $USER->lastname);
     if ($formData->schedule == 'schedule') {
         $scheduletime = usertime(gmmktime($formData->scheduletime['H'], $formData->scheduletime['i'], 0, $formData->scheduletime['M'], $formData->scheduletime['d'], $formData->scheduletime['Y']));
     } else {
         $scheduletime = time();
     }
     $outboundMessage = new MoodletxtOutboundMessage($txttoolsAccount, $thisUser, $formData->messageText, time(), MoodletxtOutboundMessage::$MESSAGE_CHARGE_TYPE_BULK, $scheduletime, $formData->suppressUnicode);
     $outboundMessage->setMessageRecipients($destinations);
     try {
         $connector = MoodletxtOutboundControllerFactory::getOutboundController(MoodletxtOutboundControllerFactory::$CONTROLLER_TYPE_XML);
         $outboundMessage->setSentSMSMessages($connector->sendMessage($outboundMessage));
         $messageDAO->saveSentMessage($outboundMessage);
         $statsDAO->incrementUserOutboundStatsById($txttoolsAccount->getId(), $USER->id, 1);
         // Stub for later expansion
         $sentPageUrl = new moodle_url('/blocks/moodletxt/sent.php', array('course' => $courseId, 'instance' => $instanceId));
         redirect($sentPageUrl, get_string('redirectmessagesent', 'block_moodletxt'));
     } catch (MoodletxtRemoteProcessingException $ex) {
         // Uh-oh, couldn't send! Display error, please
         if (has_capability('block/moodletxt:adminsettings', $blockcontext, $USER->id)) {
             $notifications = $output->notification(get_string('errorconnadmin', 'block_moodletxt'), 'notifyproblem');
             $notifications .= $output->notification($ex->getMessage(), 'notifyproblem');
         } else {
             $notifications .= $output->notification(get_string('errorconndefault', 'block_moodletxt'), 'notifyproblem');
         }
     }
 }