<?php
/**
 * Created by PhpStorm.
 * User: Jure
 * Date: 16.4.2014
 * Time: 14:43
 */
require_once '../AutoLoader.php';
include_once('_dirinfo.php');
include_once(PATH_TO_ROOT . "init.php");
include_once(PATH_TO_ROOT . "config.php");

$autoloader = new Autoloader();

$start_time = time();
$aa = new NfieldInterviewersService();
while (true) {
    try {
        if ((time() - $start_time) > 10) {
            break; // timeout, function took longer than 10 seconds
        }
        $result = $aa->query();

        $samplePointsDecoded = json_decode($result, true);
        if (isset($samplePointsDecoded[0]['InterviewerId'])) {
            foreach($samplePointsDecoded as $interviewer){
                $interviewer['FirstNameLastName'] = $interviewer['FirstName'].' '.$interviewer['LastName'];
                $data[] = $interviewer;
             }
            break;
        }
        sleep(5);
    } catch (Exception $e) {

    }
}

?>
    {
    "success": "true",
    "results": "<?php echo sizeof($data); ?>",
    "rows": <?php echo json_encode($data); ?>
    }
<?php

