/** * Builds InboundMessage objects from parsed XML * @param SimpleXMLElement $node The captured elements to build from * @return MoodletxtInboundMessage[] Inbound messages built from the XML * @version 2012101001 * @since 2011033101 */ private function buildInboundMessage($node) { $receivedMessages = array(); // Check that required children exist for object build if (isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_MESSAGE_TEXT}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_PHONE}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DELIVERY_DATE}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_TICKET}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DESTINATION})) { try { // Create object and shove onto array $messageObject = new MoodletxtInboundMessage((string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_TICKET}, (string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_MESSAGE_TEXT}, new MoodletxtPhoneNumber((string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_PHONE}), (string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DELIVERY_DATE}, false); $messageObject->setDestinationNumber(new MoodletxtPhoneNumber((string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DESTINATION})); // If this field exists, we're parsing a pushed inbound message, // rather than one retrieved manually if (isset($node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DESTINATION_ACC})) { $messageObject->setDestinationAccountUsername((string) $node->{MoodletxtXMLConstants::$RESPONSE_INBOUND_DESTINATION_ACC}); } else { $messageObject->setDestinationAccountId($this->getTxttoolsAccountObject()->getId()); $messageObject->setDestinationAccountUsername($this->getTxttoolsAccountObject()->getUsername()); } } catch (InvalidPhoneNumberException $ex) { // Invalid message content - ignore and continue } array_push($receivedMessages, $messageObject); } return $receivedMessages; }