<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(0);
require_once '../cms/includes/inicio.php';

$categorias = Categoria::listar('', null, 'nome');
if ($categorias) {
    foreach($categorias as $c) {        
        $categoriaId = $c->id;
        $categoria = $c->nome;
        $exames = Exames::listar('cp_categoria.id = '.$categoriaId, null, 'cp_categoria.nome, cp_exames.nome');
        $examesArr = null;
        if ($exames) {
            foreach($exames as $e) {
                $examesArr[] = array("title" => $e->nome,
                                     "description" => $e->descricao);         
            }
        }
        $arr[] = array("title" => $categoria,
                       "exames" => $examesArr);

    }
}
//echo "<pre>"; print_r($arr);
$retorno = $arr;

header('Content-Type: application/json; charset=utf-8');
echo html_entity_decode(json_encode($retorno));

// $arr = array();
// $arr[0]['title'] = 'Sangue';
// $arr[0]['exames'][0]['title'] = 'Colesterol';
// $arr[0]['exames'][0]['description'] = 'Description 01';
// $arr[0]['exames'][0]['url'] = '#';
// $arr[0]['exames'][1]['title'] = 'Creatinina';
// $arr[0]['exames'][1]['description'] = 'Description 02';
// $arr[0]['exames'][1]['url'] = '#';

// $arr[1]['title'] = 'Ocular';
// $arr[1]['exames'][0]['title'] = 'Exame de olho direito';
// $arr[1]['exames'][0]['description'] = 'Description 01';
// $arr[1]['exames'][0]['url'] = '#';
// $arr[1]['exames'][1]['title'] = 'Exame de olho esquerdo';
// $arr[1]['exames'][1]['description'] = 'Description 02';
// $arr[1]['exames'][1]['url'] = '#';

// $json = json_encode($arr);

// echo $json;


?>

