/** * 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); } }
/** * Push GCm Messages * * This gets called automatically by _fetchMessages. This is what actually deliveres the message. * * @access public */ public function push() { $device = new Push_Model_Android_Device(); $devices = $device->findAll(); foreach ($devices as $device) { try { $this->sendMessage($device); } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); } } }
protected function _getDeviceUid() { $id = null; if ($device_uid = $this->getRequest()->getParam('device_uid')) { if (!empty($device_uid)) { if (strlen($device_uid) == 36) { $device = new Push_Model_Iphone_Device(); $device->find($device_uid, 'device_uid'); $id = $device->getDeviceUid(); } else { $device = new Push_Model_Android_Device(); $device->find($device_uid, 'registration_id'); $id = $device->getRegistrationId(); } } } return $id; }
/** * Update position of device and send pending messages for this zone * @return type */ public function updatepositionAction() { if ($params = $this->getRequest()->getParams()) { if (empty($params['latitude']) or empty($params['longitude']) or empty($params['registration_id'])) { return; } $device = new Push_Model_Android_Device(); $device->findByRegistrationId($params['registration_id']); $messages = $device->findNotReceivedMessages(true); if ($messages->count() > 0) { foreach ($messages as $message) { $instance = $message->getInstance('android'); $instance->setMessage($message); $instance->sendMessage(array($device->getRegistrationId())); } } die; } }