/** * @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'); } $oToken = AM_Model_Db_Table_Abstract::factory('device_token')->findOneBy(array('token' => $sDeviceToken, 'application_id' => $iApplicationId)); $aSenderTaskOptions = array('message' => $sMessage, 'badge' => $iBadge, 'application_id' => $iApplicationId); $aSenderTaskOptions['tokens_apple'] = array(); $aSenderTaskOptions['tokens_android'] = array(); if ($oToken->type_os == 'ios') { $aSenderTaskOptions['tokens_apple'] = array($sDeviceToken); } else { $aSenderTaskOptions['tokens_android'] = array($sDeviceToken); } $oTaskSender = new AM_Task_Worker_Notification_Sender_Boxcar(); $oTaskSender->setOptions($aSenderTaskOptions); $oTaskSender->create(); }
/** * @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'); } $oTokensApple = AM_Model_Db_Table_Abstract::factory('device_token')->getTokens($iApplicationId, AM_Model_Pns_Type::PLATFORM_IOS); $oTokensAndroid = AM_Model_Db_Table_Abstract::factory('device_token')->getTokens($iApplicationId, AM_Model_Pns_Type::PLATFORM_ANDROID); if (0 === $oTokensApple->count() && 0 === $oTokensAndroid->count()) { $this->finish(); $this->getLogger()->debug('There are not tokens to notificate'); return; } $aSenderTaskOptions = array('message' => $sMessage, 'badge' => $iBadge, 'application_id' => $iApplicationId); $aTokensApple = array_chunk($oTokensApple->toArray(), 100); $aTokensAndroid = array_chunk($oTokensAndroid->toArray(), 100); $iMoreTokenSliceCount = count($aTokensApple) > count($aTokensAndroid) ? count($aTokensApple) : count($aTokensAndroid); for ($i = 0; $i < $iMoreTokenSliceCount; $i++) { $aTokensAndroidPrepared = array(); $aTokensApplePrepared = array(); if (!empty($aTokensAndroid[$i]) && is_array($aTokensAndroid[$i])) { foreach ($aTokensAndroid[$i] as $aTokenAndroid) { $this->getLogger()->debug(sprintf('Preparing message for token android \'%s\'', $aTokenAndroid['token'])); $aTokensAndroidPrepared[] = $aTokenAndroid['token']; } } if (!empty($aTokensApple[$i]) && is_array($aTokensApple[$i])) { foreach ($aTokensApple[$i] as $aTokenApple) { $this->getLogger()->debug(sprintf('Preparing message for token apple \'%s\'', $aTokenApple['token'])); $aTokensApplePrepared[] = $aTokenApple['token']; } } $aSenderTaskOptions['tokens_apple'] = $aTokensApplePrepared; $aSenderTaskOptions['tokens_android'] = $aTokensAndroidPrepared; $oTaskSender = new AM_Task_Worker_Notification_Sender_Boxcar(); $oTaskSender->setOptions($aSenderTaskOptions); $oTaskSender->create(); } }