コード例 #1
0
ファイル: Message.php プロジェクト: bklein01/siberian_cms_2
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: Message.php プロジェクト: bklein01/siberian_cms_2
 public function push()
 {
     if ($this->getErrors()) {
         return $this;
     }
     if (!$this->__certificate) {
         $this->setErrors(array($this->_("Please provide a certificate.")));
         return $this;
     }
     $this->createConnection();
     $device = new Push_Model_Iphone_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);
     $errors = array();
     $error = false;
     foreach ($devices as $device) {
         try {
             $this->sendMessage($device);
         } catch (Exception $e) {
             $errors[$device->getId()] = "Device {$device->getId()} -> {$e->getMessage()}";
         }
     }
     fclose($this->_stream_client);
     try {
         $this->_checkFeedback();
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     $this->setErrors($errors);
     return $this;
 }