Example #1
0
 /**
  * Push GCm Messages
  *
  * This gets called automatically by _fetchMessages.  This is what actually deliveres the message.
  *
  * @access public
  */
 public function push()
 {
     try {
         $device = new Push_Model_Android_Device();
         $app_id = $this->getMessage()->getAppId();
         if ($this->getMessage()->getSendToAll() == 0) {
             $category_message = new Topic_Model_Category_Message();
             $allowed_categories = $category_message->findCategoryByMessageId($this->getMessage()->getId());
         } else {
             $allowed_categories = null;
         }
         $devices = $device->findByAppId($app_id, $allowed_categories);
         $registration_ids = array();
         foreach ($devices as $device) {
             $registration_ids[] = $device->getRegistrationId();
         }
         if (!empty($registration_ids)) {
             $chunked_registration_ids = array_chunk($registration_ids, 999);
             foreach ($chunked_registration_ids as $registration_ids) {
                 $sent = $this->sendMessage($registration_ids);
                 if ($sent) {
                     foreach ($devices as $device) {
                         $this->getMessage()->createLog($device, 1, $device->getRegistrationId());
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $logger = Zend_Registry::get("logger");
         $logger->log(print_r($e, true), Zend_Log::DEBUG);
     }
 }