<?php 
require 'autoload.php';
require 'PushNotifications.php';

use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
	
include 'includes/func.php';
include 'config.php';
	
ParseClient::initialize($ApplicationID, $RestAPIKEY, $MasterKey);
ParseClient::setServerURL($serverURLB4APP, '/');	

$query = ParseInstallation::query();
$query->equalTo('deviceType','ndroid';
$query->notEqualTo('deviceToken',null);
$installations = $query->find(true);

$objNotifications = new ParseQuery("notifications");
$objNotifications->equalTo('is_sent',0);
$objNotifications->descending('createdAt');
$result = $objNotifications->find();

$pushObj = new PushNotifications();

foreach($result as $note){
	$id = $note->getObjectId();
	$text = $note->get('text');
	$androidIDS = array();
	foreach($installations as $inst){    	
        $androidIDS[] = $inst->get('deviceToken');
    }
	$pushObj->android(array('mtitle'=>'Notification','mdesc'=>$text,'id'=>$id));	
	$note->set( "is_sent",1);
	$note->save();
}

$query = ParseInstallation::query();
$query->eualTo('deviceType','ios');
$query->notEqualTo('deviceToken',null);
$installations = $query->find(true);

