/**
  * Loads the contest model this keyword is using.
  * Plays the contest.
  * 
  * @access public
  * @return void
  */
 public function handle()
 {
     // message that was sent by the subscriber
     $this->_message = $this->_inbound->message;
     // Make sure our keyword loaded
     if ($this->_keyword instanceof Application_Model_Keyword) {
         $this->_writeLog('Keyword: ', print_r($this->_keyword, 1));
         // Get the contest attached to this keyword
         $this->_contest = new Application_Model_Contest($this->_keyword->contestid);
         // Make sure our contest loaded
         if ($this->_contest instanceof Application_Model_Contest && $this->_contest->getId()) {
             $this->_writeLog('Contest: ' . print_r($this->_contest, 1));
             // Check if there is a contest action on the keyword and, if
             // there is, handle that
             if ($this->_keyword->hasContestAction()) {
                 $action = $this->_keyword->getContestAction();
                 if (is_numeric($action)) {
                     //Pick some winners
                     $winners = $this->_contest->pickWinners($action);
                     if ($winners) {
                         $this->_keyword->response = null;
                         $first = true;
                         foreach ($winners as $winner) {
                             if ($first) {
                                 $message = new Application_Model_Message(new Application_Model_User($winner->userid));
                                 $message->body = $winner->response;
                                 $message->keywordid = $winner->keywordid;
                                 $message->folderid = $winner->folderid;
                             }
                             $message->recipients[$winner->id] = $winner->phonenumber;
                         }
                         if (isset($message) && $message instanceof Application_Model_Message) {
                             $out = new Application_Model_Smsoutbound($message);
                             return $out->sendNow();
                         }
                     }
                 } else {
                     // Either start or stop
                     if ($action == 'start') {
                         if ($this->_contest->startContest()) {
                             $this->_setResponse(str_replace('{{KEYWORD}}', $this->_keyword->keyword, $this->_getActionKeywordReplyText('conteststarted')));
                         } else {
                             $this->_setResponse($this->_contest->error);
                         }
                     } else {
                         if ($this->_contest->endContest()) {
                             $this->_setResponse(str_replace('{{KEYWORD}}', $this->_keyword->keyword, $this->_getActionKeywordReplyText('contestended')));
                         } else {
                             $this->_setResponse($this->_contest->error);
                         }
                     }
                 }
             } else {
                 // Not going to user the standard autoresponder
                 $this->_keyword->usecustomresponse = true;
                 // Default the standard autoresponder
                 $this->_keyword->response = null;
                 // See if this mobile number has already played the contest
                 // Returns a subscriber object or false
                 $this->subscriber = $this->_keyword->hasSubscriberPhone($this->_inbound->device_address);
                 // If we don't have a subscriber id for this mobile number, create one
                 if ($this->subscriber == false) {
                     $this->_keyword->addSubscriber($this->_inbound->device_address);
                     // Now get the newly created subscriber object
                     $this->subscriber = $this->_keyword->hasSubscriberPhone($this->_inbound->device_address);
                 }
                 // Play the contest
                 $result = $this->_contest->play($this->subscriber->id, $this->_keyword->id);
                 // Play method will handle autoresponse, we are all done!
                 $this->_setResponse($result);
                 $this->_writeLog('Contest Response is: ' . $result);
             }
         } else {
             $this->_writeLog('Could not load contest model for contest: ' . $this->_keyword->contestid . ', Keyword: ' . $this->_keyword->id);
         }
     }
 }
$raffles = $contest->getAllAutoRaffles();
// Loop and work
if ($raffles && is_array($raffles)) {
    foreach ($raffles as $raffle) {
        // See if there are winners to pick for this raffle(contest id)
        $picks = $contest->hasWinnersToPick($raffle->id);
        if ($picks) {
            // ACtually select our winners now, and send them their message
            $winners = $contest->pickWinners($picks, $raffle->id);
            if ($winners) {
                $first = true;
                foreach ($winners as $winner) {
                    if ($first) {
                        $message = new Application_Model_Message(new Application_Model_User($winner->userid));
                        $message->body = $winner->response;
                        $message->keywordid = $winner->keywordid;
                        $message->folderid = $winner->folderid;
                    }
                    $message->recipients[$winner->id] = $winner->phonenumber;
                }
                // Send them their message
                if (isset($message) && $message instanceof Application_Model_Message) {
                    $out = new Application_Model_Smsoutbound($message);
                    $out->sendNow();
                }
            }
        }
    }
}
// Clean up
exit(0);
Exemple #3
0
 /**
  * Sends a message to a collection of recipients (or one recipient)
  *
  * @access public
  * @param string $message The message to send
  * @param array $recipients An array of recipients to send to
  * @return boolean
  */
 public function sendNow($body, $recipients, $sc)
 {
     $this->body = $body;
     $this->recipients = (array) $recipients;
     // Build the reporting keys, used for cross referencing DRs
     $this->reportingkey1 = time();
     $this->reportingkey2 = md5(uniqid() . serialize($this->recipients));
     $this->shortcode = $sc;
     // Send this message to the outbound sms class to be sent.
     $sender = new Application_Model_Smsoutbound($this);
     //		$sender = new Application_Model_Synsmsoutbound($this);
     if (($return = $sender->sendNow()) === false) {
         $this->setError($sender->error, true);
     }
     return $return;
 }