Exemplo n.º 1
0
 /**
  * Converts an outbound message down to a basic object for writing to the DB
  * @param MoodletxtOutboundMessage $bean Object to convert
  * @param object $existingRecord Existing DB record, if one exists
  * @return object Object for writing to the database
  * @version 2012062401
  * @since 2011081101
  */
 private function convertBeanToStandardClass(MoodletxtOutboundMessage $bean, object $existingRecord = null)
 {
     if ($existingRecord == null) {
         $existingRecord = new object();
     }
     $existingRecord->userid = $bean->getUser()->getId();
     $existingRecord->txttoolsaccount = $bean->getTxttoolsAccount()->getId();
     $existingRecord->messagetext = $bean->getMessageText();
     $existingRecord->timesent = $bean->getTimeSent();
     $existingRecord->scheduledfor = $bean->getScheduledTime();
     $existingRecord->type = $bean->getType();
     $existingRecord->fromevent = $bean->isEventCreated() ? 1 : 0;
     return $existingRecord;
 }
Exemplo n.º 2
0
 /**
  * Build text message blocks.
  * Method builds the individual <Message> blocks to be included in the message being built.
  * These blocks are cached into an array, then compiled into <Request> blocks later on.
  * @param MoodletxtOutboundMessage $message The message object to base the block on
  * @version 2013080801
  * @since 2010090101
  */
 private function buildTextMessageBlocks(MoodletxtOutboundMessage $message)
 {
     $messageRecipients = $message->getMessageRecipients();
     // Loop over recipients and create message blocks
     foreach ($messageRecipients as $recipientKey => $recipient) {
         if (!$recipient->getRecipientNumber() instanceof MoodletxtPhoneNumber) {
             continue;
         }
         $messageText = trim(stripslashes($message->getMessageText()));
         $messageText = MoodletxtStringHelper::mergeTagsIntoMessageText($messageText, $recipient);
         // Chunk message text into blocks of 160 chars
         $messagechunks = str_split($messageText, 160);
         // Build message blocks
         foreach ($messagechunks as $chunk) {
             // Code written this way so the output is all nice and formatted
             $messageBlock = '
 ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_BLOCK . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_TEXT . $chunk . MoodletxtXMLConstants::$_REQUEST_MESSAGE_TEXT . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_PHONE . $recipient->getRecipientNumber()->getPhoneNumber() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_PHONE . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_TYPE . $message->getType() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_TYPE . '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_UNIQUE_ID . $recipientKey . MoodletxtXMLConstants::$_REQUEST_MESSAGE_UNIQUE_ID;
             // Add scheduled send time if specified
             $messageBlock .= $message->getScheduledTime() > $message->getTimeSent() ? '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_SCHEDULE_DATE . $message->getScheduledTime() . MoodletxtXMLConstants::$_REQUEST_MESSAGE_SCHEDULE_DATE : '';
             // Add UTF-8 suppression if specified
             $messageBlock .= $message->isSuppressUnicode() ? '
     ' . MoodletxtXMLConstants::$REQUEST_MESSAGE_SUPPRESS_UNICODE : '';
             $messageBlock .= '
 ' . MoodletxtXMLConstants::$_REQUEST_MESSAGE_BLOCK;
             $this->addRequestBlock($messageBlock);
         }
     }
 }