/** * Converts a basic SMS object from the database to a useful * full-fat data object * @param object $stdObject DB object to upgrade * @return MoodletxtOutboundSMS Full data object with children * @version 2013081501 * @since 2012031901 */ private function convertSMSStandardClassToBeans($stdObject) { $sms = new MoodletxtOutboundSMS($stdObject->messageid, $stdObject->ticketnumber, $stdObject->messagetext); $sms->setId($stdObject->id); // Build recipient if (isset($stdObject->contactfirst) || isset($stdObject->contactlast) || isset($stdObject->company)) { $sms->setRecipientObject(new MoodletxtAddressbookRecipient(new MoodletxtPhoneNumber($stdObject->destination), $stdObject->contactfirst, $stdObject->contactlast, $stdObject->company, $stdObject->contactid)); } else { if (isset($stdObject->userfirst) || isset($stdObject->userlast)) { $sms->setRecipientObject(new MoodletxtBiteSizedUser($stdObject->userid, $stdObject->username, $stdObject->userfirst, $stdObject->userlast, new MoodletxtPhoneNumber($stdObject->destination))); } else { $sms->setRecipientObject(new MoodletxtAdditionalRecipient(new MoodletxtPhoneNumber($stdObject->destination), $stdObject->sendfirstname, $stdObject->sendlastname)); } } // Optionally drop in statuses, if they were retrieved if (isset($stdObject->status) && $stdObject->status != null) { $sms->setStatusUpdates(array(new MoodletxtOutboundSMSStatus($stdObject->ticketnumber, $stdObject->status, $stdObject->statusmessage, $stdObject->updatetime, $stdObject->statusid))); } return $sms; }
/** * Builds message and status objects from parsed XML * @param SimpleXMLElement $node The node collection to create the object from * @return mixed[] Sent messages built from the XML * @see SentMessageStatus * @version 2012031501 * @since 2011033101 */ private function buildStatusMessage($node) { $returnObjects = array(); // Check that all required children for message object // build exist within passed data if (isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_MESSAGE_TEXT}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_PHONE}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_TICKET}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_UNIQUE_ID})) { // Build object and shove it onto the parsed objects array $sentMessageObject = new MoodletxtOutboundSMS($this->outboundMessageObject->getId(), (int) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_TICKET}, (string) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_MESSAGE_TEXT}); $sentMessageObject->setRecipientObject($this->outboundMessageObject->getMessageRecipientByKey((string) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_UNIQUE_ID})); } // Check if required children for status object exist if (isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_TICKET}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_CODE}) && isset($node->{MoodletxtXMLConstants::$RESPONSE_STATUS_MESSAGE})) { // Build status object and shove onto array $statusObject = new MoodletxtOutboundSMSStatus((int) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_TICKET}, (int) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_CODE}, (string) $node->{MoodletxtXMLConstants::$RESPONSE_STATUS_MESSAGE}, time()); if (isset($sentMessageObject)) { $sentMessageObject->addStatusUpdate($statusObject); } else { if ($this->getExistingSentMessageByTicketNumber($statusObject->getTicketNumber()) != null) { $this->getExistingSentMessageByTicketNumber($statusObject->getTicketNumber())->addStatusUpdate($statusObject); } else { array_push($returnObjects, $statusObject); } } } if (isset($sentMessageObject)) { array_push($returnObjects, $sentMessageObject); } return $returnObjects; }