From 0b01c52d980445e2ed0a6e5a17f96d6872f6c77f Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 4 Nov 2016 14:40:17 +0900 Subject: [PATCH] Implement delayed sending of SMS --- common/framework/drivers/sms/coolsms.php | 11 ++++++- common/framework/sms.php | 38 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/common/framework/drivers/sms/coolsms.php b/common/framework/drivers/sms/coolsms.php index 6dd7442e0..4b289ffc1 100644 --- a/common/framework/drivers/sms/coolsms.php +++ b/common/framework/drivers/sms/coolsms.php @@ -67,9 +67,18 @@ class CoolSMS extends Base implements \Rhymix\Framework\Drivers\SMSInterface $options->from = $message->getFrom(); $options->to = $recipient_number; $options->charset = 'utf8'; - $content_full = $message->getContent(); + + // Determine when to send this message. + if ($datetime = $message->getDelay()) + { + if ($datetime > time()) + { + $options->datetime = gmdate('YmdHis', $datetime + (3600 * 9)); + } + } // Determine the message type based on the length. + $content_full = $message->getContent(); $detected_type = $message->checkLength($content_full, $this->_maxlength_sms) ? 'SMS' : 'LMS'; $options->type = $detected_type; diff --git a/common/framework/sms.php b/common/framework/sms.php index 1396946d1..26ae2b8e0 100644 --- a/common/framework/sms.php +++ b/common/framework/sms.php @@ -17,6 +17,7 @@ class SMS protected $subject = ''; protected $content = ''; protected $attachments = array(); + protected $delay_timestamp = 0; protected $force_sms = false; protected $allow_split_sms = true; protected $allow_split_lms = true; @@ -313,6 +314,43 @@ class SMS return $this->attachments; } + /** + * Delay sending the message. + * + * Delays (in seconds) less than 1 year will be treated as relative to the + * current time. Greater values will be interpreted as a Unix timestamp. + * + * This feature may not be implemented by all drivers. + * + * @param int $when Unix timestamp + * @return bool + */ + public function setDelay($when) + { + if ($when <= (86400 * 365)) + { + $when = time() + $when; + } + + $this->delay_timestamp = intval($when); + return true; + } + + /** + * Get the Unix timestamp of when to send the message. + * + * This method always returns a Unix timestamp, even if the original value + * was given as a relative delay. + * + * This feature may not be implemented by all drivers. + * + * @return int + */ + public function getDelay() + { + return $this->delay_timestamp; + } + /** * Force this message to use SMS (not LMS or MMS). *