예제 #1
0
 /**
  * @see AM_Task_Worker_Abstract::_fire()
  * @throws AM_Task_Worker_Exception
  * @return void
  */
 protected function _fire()
 {
     $iIssueId = intval($this->getOption('issue_id'));
     $sMessage = $this->getOption('message');
     $iBadge = intval($this->getOption('badge'));
     $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $iIssueId);
     /* @var $oIssue AM_Model_Db_Issue */
     if (is_null($oIssue)) {
         throw new AM_Task_Worker_Exception('Issue not found');
     }
     $iApplicationId = $oIssue->getApplication()->id;
     if (empty($iApplicationId)) {
         throw new AM_Task_Worker_Exception('Wrong parameters were given');
     }
     $oTokensRow = AM_Model_Db_Table_Abstract::factory('device_token')->getTokens($iApplicationId, AM_Model_Pns_Type::PLATFORM_IOS);
     if (0 === $oTokensRow->count()) {
         $this->finish();
         $this->getLogger()->debug('There are not tokens to notificate');
         return;
     }
     $aSenderTaskOptions = array('message' => $sMessage, 'badge' => $iBadge, 'application_id' => $iApplicationId);
     $aTokensGroups = array_chunk($oTokensRow->toArray(), 100);
     foreach ($aTokensGroups as $aTokensGroup) {
         $aTokens = array();
         foreach ($aTokensGroup as $aToken) {
             $this->getLogger()->debug(sprintf('Preparing message for token apple \'%s\'', $aToken["token"]));
             $aTokens[] = $aToken['token'];
         }
         $aSenderTaskOptions['tokens'] = $aTokens;
         $oTaskSender = new AM_Task_Worker_Notification_Sender_Apple();
         $oTaskSender->setOptions($aSenderTaskOptions);
         $oTaskSender->create();
     }
 }
예제 #2
0
 /**
  * @see AM_Task_Worker_Abstract::_fire()
  * @throws AM_Task_Worker_Exception
  * @return void
  */
 protected function _fire()
 {
     $iIssueId = intval($this->getOption('issue_id'));
     $sMessage = $this->getOption('message');
     $iBadge = intval($this->getOption('badge'));
     $sDeviceToken = $this->getOption('token');
     $this->getLogger()->debug('Token value %s', $sDeviceToken);
     $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $iIssueId);
     /* @var $oIssue AM_Model_Db_Issue */
     if (is_null($oIssue)) {
         throw new AM_Task_Worker_Exception('Issue not found');
     }
     $iApplicationId = $oIssue->getApplication()->id;
     if (empty($iApplicationId)) {
         throw new AM_Task_Worker_Exception('Wrong parameters were given');
     }
     $aSenderTaskOptions = array('message' => $sMessage, 'badge' => $iBadge, 'application_id' => $iApplicationId, 'tokens' => array($sDeviceToken));
     $oTaskSender = new AM_Task_Worker_Notification_Sender_Apple();
     $oTaskSender->setOptions($aSenderTaskOptions);
     $oTaskSender->create();
 }