Created
January 26, 2015 21:33
-
-
Save pcave/5572e561f61fd9d11c3c to your computer and use it in GitHub Desktop.
Message Grinder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes a set of messages and converts them to target messages | |
* based on how many deliverable targets were resolved. | |
* | |
* @param array $alert | |
* An array of messages from target resolution or direct API call. | |
*/ | |
function grindMessages($alert) { | |
$target_messages = array(); | |
// Loop over each message. | |
foreach ($alert->messages as $message_id => $message) { | |
// Each message could have 0 to N targets after resolution takes place. | |
foreach ($message->deliverable as $target) { | |
// Create a target message for each one. | |
$target_message = new stdClass(); | |
$target_message->alert_id = $alert->alert_id; | |
$target_message->contact = $alert->contact; | |
$target_message->message = $message->message; // same message, different target | |
$target_message->target = $target; | |
$target_messages[] = $target_message; | |
} | |
} | |
return $target_messages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment