public function SendAPNsFromNotification() { $notifications = DB::select("SELECT u.DeviceUDID AS Devices,u.IsIOSGeneralOn,\n u.IsIOSAnalystOn,u.IsIOSFundamentalOn,u.IsIOSEquityOn,u.IsIOSFutureOn,u.IsIOSCommodityOn,u.IsIOSBTSTOn,u.IsIOSChatOn,\n n.NotificationID, NotificationType,Message, `Key`, ImageUrl, IsPast\n FROM notifications n LEFT JOIN users u ON u.UserID = n.UserID and u.IsAndroid = 0 AND u.DeviceUDID IS NOT NULL WHERE issent = 0 AND IFNULL(u.DeviceUDID,'') != ''"); if ($notifications) { foreach ($notifications as $notification) { $notifications = DB::select("Update notifications SET IsSent=2 where NotificationID=?", array($notification->NotificationID)); if ($notification && $notification->Devices) { if ($notification->IsIOSGeneralOn && $notification->NotificationType == Constants::$NotificationType['General']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSAnalystOn && $notification->NotificationType == Constants::$NotificationType['Analyst']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSFundamentalOn && $notification->NotificationType == Constants::$NotificationType['Fundamental']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSEquityOn && $notification->NotificationType == Constants::$NotificationType['Equity']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSFutureOn && $notification->NotificationType == Constants::$NotificationType['Future']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSCommodityOn && $notification->NotificationType == Constants::$NotificationType['Commodity']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSBTSTOn && $notification->NotificationType == Constants::$NotificationType['BTST']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } else { if ($notification->IsIOSChatOn && $notification->NotificationType == Constants::$NotificationType['Chat']) { $notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); } } } } } } } } /*else{ $notificationEntity = DB::table('notifications')->where("NotificationID", $notification->NotificationID)->update(array("IsSent" => 1,"SentDate" => date(Constants::$DefaultDateTimeFormat))); }*/ //$notificationResponse = Common::SendIOSCloudMessage($notification->Devices, Common::GetIOSCloudMessage($notification->Message, $notification->NotificationType, $notification->Key, $notification->NotificationID, $notification->ImageUrl, $notification->IsPast)); if ($notificationResponse) { $notificationEntity = DB::table('notifications')->where("NotificationID", $notification->NotificationID)->update(array("IsSent" => 1, "SentDate" => date(Constants::$DefaultDateTimeFormat))); } else { $notificationEntity = DB::table('notifications')->where("NotificationID", $notification->NotificationID)->update(array("IsSent" => 3, "SentDate" => date(Constants::$DefaultDateTimeFormat))); } } $notifications = DB::select("Update notifications SET IsSent=0 where NotificationID=? and IsSent=2", array($notification->NotificationID)); } } }