/** * 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; }
/** * Saves a top-level sent message to the database * @global moodle_database $DB Moodle database controller * @param MoodletxtOutboundMessage $outboundMessage Message sent out * @return MoodletxtOutboundMessage Message object (may have been modified with IDs, etc) * @version 2012041001 * @since 2012031501 */ public function saveSentMessage(MoodletxtOutboundMessage $outboundMessage) { global $DB; $action = $outboundMessage->getId() > 0 ? 'update' : 'insert'; if ($action == 'insert') { $insertClass = $this->convertBeanToStandardClass($outboundMessage); $outboundMessage->setId($DB->insert_record('block_moodletxt_outbox', $insertClass)); } else { $updateClass = $this->convertBeanToStandardClass($outboundMessage, $DB->get_record('block_moodletxt_outbox', array('id' => $outboundMessage->getId()))); $DB->update_record('block_moodletxt_outbox', $updateClass); } // That's the top level object saved - now to save individual SMS messages if (count($outboundMessage->getSentSMSMessages()) > 0) { $outboundMessage->setSentSMSMessages($this->saveMessagesSentViaSMS($outboundMessage->getSentSMSMessages())); } return $outboundMessage; }