示例#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
            }
        }
    }
}
 /**
  * Globally toggle access to an account, either in or outbound
  * @param int $accountId ID of account to modify
  * @param string $direction Specify inbound/outbound access to update
  * @return string JSON response
  * @throws MoodletxtAJAXException
  * @version 2012101601
  * @since 2011061301
  */
 private function toggleAccountAccess($accountId, $direction = 'outbound')
 {
     $txttoolsAccount = $this->accountDAO->getTxttoolsAccountById($accountId);
     // Account must exist within system
     if (!is_object($txttoolsAccount)) {
         throw new MoodletxtAJAXException(get_string('errorinvalidaccountid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_ACCOUNT_ID, null, false, $accountId);
     }
     // Update account settings within DB
     if ($direction == self::$DIRECTION_IDENTIFIER_OUTBOUND) {
         $txttoolsAccount->setOutboundEnabled(!$txttoolsAccount->isOutboundEnabled());
     } else {
         if ($direction == self::$DIRECTION_IDENTIFIER_INBOUND) {
             $txttoolsAccount->setInboundEnabled(!$txttoolsAccount->isInboundEnabled());
         }
     }
     $this->accountDAO->saveTxttoolsAccount($txttoolsAccount);
     return $this->buildResponse($txttoolsAccount);
 }
示例#3
0
 }
 if (count($addressBookContacts) > 0) {
     $destinations += $addressbookDAO->getAddressbookContactsById($addressBookContacts, 'phone');
 }
 // Merge Moodle users last - higher priority in linking than other contact type
 if (count($moodleUserGroups) > 0) {
     foreach ($moodleUserGroups as $userGroup) {
         $destinations += $userDAO->getUsersInGroup($userGroup, 'phone');
     }
 }
 if (count($moodleUsers) > 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));