$apppath = realpath(dirname(__FILE__) . '/..');
// Add the application path to the include path
set_include_path(get_include_path() . PATH_SEPARATOR . $apppath);
// Get the Zend Framework loader setup
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// Setup routing of model autoloaders
$loader = new Zend_Loader_Autoloader_Resource(array('basePath' => $apppath . '/application/', 'namespace' => 'Application'));
// Name, path, namepsace
$loader->addResourceType('model', 'models', 'Model');
// Get our config file
$config = new Zend_Config_Ini($apppath . '/application/configs/application.ini');
Zend_Registry::set('config', $config->production);
// Because our models need it this way
// Build up the contest model
$contest = new Application_Model_Contest();
// Get our active auto raffles
$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));
 /**
  * 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);
         }
     }
 }
Exemple #3
0
 /**
  * Gets a collection of contest models for this user
  * 
  * Sorted by name
  * 
  * @access public
  * @return Array
  */
 public function getContests()
 {
     $return = array();
     if ($this->id) {
         $sql = "CALL user_get_contests({$this->id})";
         $rs = $this->query($sql);
         if ($rs && $rs->num_rows) {
             while ($row = $rs->fetchArray()) {
                 $contest = new Application_Model_Contest();
                 $contest->loadFromArray($row);
                 if (isset($return[$contest->name])) {
                     $ix = 0;
                     $index = $contest->name . $ix;
                     while (isset($return[$index])) {
                         $ix++;
                         $index = $contest->name . $ix;
                     }
                     $return[$index] = $contest;
                 } else {
                     $return[$contest->name] = $contest;
                 }
             }
         }
     }
     ksort($return);
     return $return;
 }
 public function contestprizeAction()
 {
     // No rendering of views or layouts
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     // Set up the reply
     $reply = array('success' => 0, 'message' => '');
     // Handle the request
     if ($this->_request->isPost()) {
         $contestid = $this->_request->getPost('contestid');
         if ($contestid) {
             // Only build a contest model if we have a contest id
             $contest = new Application_Model_Contest($contestid);
             $prizeid = $this->_request->getPost('prizeid');
             // Now we can work
             $name = $this->_request->getPost('name');
             $action = $this->_request->getPost('action');
             $response = $this->_request->getPost('response');
             $odds = $this->_request->getPost('odds');
             $winner = $this->_request->getPost('winner');
             $expiredays = $this->_request->getPost('expire_days');
             $expiredate = $this->_request->getPost('expire_date');
             if ($action == 'add') {
                 if ($contest->addPrize($name, $response, $odds, $winner, null, $expiredays, $expiredate)) {
                     // Response with success
                     $reply['success'] = 1;
                 } else {
                     // Response with success = 0, message = $contest->error
                     $reply['message'] = $contest->error;
                 }
             } else {
                 if ($action == 'edit') {
                     if ($prizeid) {
                         if ($contest->editPrize($prizeid, $name, $response, $odds, $winner, null, $expiredays, $expiredate)) {
                             // Response with success
                             $reply['success'] = 1;
                         } else {
                             // Response with success = 0, message = $contest->error
                             $reply['message'] = $contest->error;
                         }
                     } else {
                         $reply['message'] = 'Missing prize id for editing';
                     }
                 } else {
                     if ($action == 'delete') {
                         //
                     } else {
                         $reply['message'] = 'Incorrect request type';
                     }
                 }
             }
         } else {
             $reply['message'] = 'No contest selected';
         }
     } else {
         $reply['message'] = 'Improper or malformed request';
     }
     echo json_encode($reply);
 }