Beispiel #1
0
 public function push()
 {
     if ($this->getErrors()) {
         return $this;
     }
     $device = new Push_Model_Iphone_Device();
     $devices = $device->findAll();
     //        Zend_Debug::dump($devices);
     //        die;
     //        $device_type = Push_Model_Iphone_Device::DEVICE_TYPE;
     //        $select = $this->select()
     //            ->from(array('pad' => $this->_name))
     //            ->joinLeft(array('_table_is_read' => 'push_delivered_message'), '_table_is_read.device_id = pad.device_id AND _table_is_read.status = 1 AND _table_is_read.is_read = 0', array('not_read' => new Zend_Db_Expr('COUNT(_table_is_read.deliver_id)')))
     //            ->where('pad.app_id = ?', $app_id)
     //            ->where('pad.status = ?', 'active')
     //            ->where('(pad.push_badge = "enabled" OR pad.push_alert = "enabled" OR pad.push_sound = "enabled")')
     //            ->group('pad.device_id')
     //            ->order('')
     //            ->setIntegrityCheck(false)
     //        ;
     //        return $this->fetchAll($select);
     $errors = array();
     $is_geolocated = $this->getMessage()->getLatitude() && $this->getMessage()->getLongitude() && $this->getMessage()->getRadius();
     $error = false;
     foreach ($devices as $device) {
         try {
             $canSendMessage = false;
             if ($is_geolocated) {
                 if ($device->getLastKnownLatitude() and $device->getLastKnownLongitude()) {
                     $canSendMessage = $this->isInsideRadius($device->getLastKnownLatitude(), $device->getLastKnownLongitude());
                 }
             } else {
                 $canSendMessage = true;
             }
             if ($canSendMessage) {
                 $this->sendMessage($device);
             }
         } catch (Exception $e) {
             $errors[$device->getId()] = $e;
         }
     }
     $this->setErrors($errors);
     return $this;
 }