Example #1
0
<?php

require "../bcause-core2.php";
$con = new Connection();
$id = $_GET['id'];
$event = new Event($con);
$event_data = $event->getEvent($id);
$json_output = $event->getEventChildrenJSON($con, 1, 0);
print $json_output;
 public function getEventChildrenJSON($con, $max_degree, $child)
 {
     $name = $this->name;
     $id = $this->id;
     $event_children = $this->getEventChildren($id);
     $degree = 0;
     $json_output = '';
     if (isset($name)) {
         # montando o metadata
         foreach ($event_children as $ec) {
             if ($ec->quote == '') {
                 $ec->quote = "(no quote yet)";
             }
             $metadata[$ec->event_id] = "'{$ec->quote}' - <a href='{$ec->report_link}'>{$ec->report_news_source}</a>";
             if (isset($metadata_insert[$ec->event_id])) {
                 $metadata_insert[$ec->event_id] = $metadata_insert[$ec->event_id] . "</br>" . $metadata[$ec->event_id];
             } else {
                 $metadata_insert[$ec->event_id] = $metadata[$ec->event_id];
             }
         }
         $run = 0;
         $ids_done = array();
         $printed_once = 0;
         foreach ($event_children as $ecc) {
             if ($printed_once == 0 && $child == 0) {
                 $json_output = "{\n\"name\": \"{$name}\",\n\"quote\": \"\",\n\"children\": [";
                 $printed_once = 1;
             }
             //print_r($ecc);
             if (!in_array($ecc->event_id, $ids_done)) {
                 if ($ecc->quote == '') {
                     $ecc->quote = "(no quote yet)";
                 }
                 if ($run > 0) {
                     $json_output .= ",";
                 }
                 $mt = $metadata_insert[$ecc->event_id];
                 $json_output .= "{\n                \"name\": \"{$ecc->event_name}\",\n                \"url\": \"node.php?id={$ecc->event_id}\",\n                \"news_url\": \"{$ecc->report_link}\",\n                \"quote\": \"{$ecc->quote}\",\n                \"metadata\": \"{$mt}\",\n                \"children\": [";
                 # Running sub-children
                 $children_output = '';
                 if ($degree < $max_degree) {
                     $event2 = new Event($con);
                     $event2_data = $event2->getEvent($ecc->event_id);
                     # Passando o filho tb: se for filho, nao ha necessidade de printar de novo
                     $children_output = $event2->getEventChildrenJSON($con, $max_degree--, 1);
                     //print "AAA: $ecc->event_id\n $children_output\n\n\n";
                 }
                 $json_output .= $children_output;
                 # Continuando com o parent
                 $json_output .= "]\n                    }";
                 $run++;
                 $ids_done[] = $ecc->event_id;
             }
         }
         if ($printed_once == 1) {
             $json_output .= "]\n            }";
         }
     } else {
         $json_output = '';
     }
     return $json_output;
 }