NeuralMesh
  • Class
  • Tree

Classes

  • AbstractNetwork
  • Controller
  • layer
  • ManagedNetwork
  • Model
  • mysql
  • Navigation
  • network
  • NeuralMesh
  • neuron
  • nmesh
  • synapse
  • train
  • UnmanagedNetwork
  • users
  • validation
  1 <?php
  2 class Navigation {
  3 
  4     private $struct;
  5     private $output = "";
  6     private $active = "";
  7     private $found = false;
  8 
  9     function __construct() {
 10         $this->struct = simplexml_load_file(Controller::$root."data/navigation.xml");
 11     }
 12     
 13     /**
 14     * Based on the navigation xml, build the nav
 15     * @param active The link to show as active
 16     * @param struct Document/structure to build
 17     * @param level Level of depth currently building
 18     */
 19     function build($active=null,$struct=NULL,$level=0) {
 20     
 21         if(is_null($struct)) $struct = $this->struct;
 22         if(is_null($active)) $active = $this->getActive();
 23         $build_flag = false;
 24         
 25         $this->output .= "<ul id='lvl$level'>\n";
 26         foreach($struct as $child) {
 27             //if the href tag does not exist, find the first child that does
 28             $href = isset($child['href']) ? $child['href'] : $this->firstChild($child); 
 29             //if the href is an immediate child, set active class
 30             $active_class = ($active == $href) ? " class='active'" : "";
 31             
 32             $this->find($active,$child); //look for href in current children
 33 
 34             if($this->found) { //if found flag is raised
 35                 $build_flag = $child;
 36                 $active_class = " class='active'";
 37                 $this->found = false; //reset
 38             }
 39             $qs = $this->addVars($child); //generate query string           
 40             $this->output .= "\t<li><a href='{$href}{$qs}'{$active_class}>".$child['name']."</a></li>\n";
 41             
 42         }
 43         $this->output .= "</ul>\n";
 44         if($build_flag) $this->build($active,$build_flag,$level+1); //build next level
 45     }
 46 
 47     /**
 48     * Returns the first child of a node
 49     * @param struct The document/structure to search for
 50     */
 51     private function firstChild($struct) {
 52         if($struct->page[0]['href']) {
 53             return $struct->page[0]['href'];
 54         }
 55         return $this->firstChild($struct->page[0]);
 56     }
 57 
 58     /**
 59      * Search for a HREF within a structs children
 60      * @param href The page link to find
 61      * @param struct The document/structure to search in
 62      */
 63     private function find($href,$struct) {
 64 
 65         foreach($struct as $child) {
 66             if(isset($child['href']) && $child['href'] == $href) {
 67                 $this->found = true;
 68             } else {
 69                 $this->find($href,$child);
 70             }
 71         }
 72     }
 73     
 74     public function asList() {
 75         $this->build();
 76         return $this->output;
 77     }
 78     
 79     /**
 80     * Get the active page
 81     * @return the filename
 82     */
 83     private function getActive() {
 84         $path = $_SERVER['SCRIPT_NAME'];
 85         return substr($path,strrpos($path,"/")+1,strlen($path));
 86     }
 87     
 88     private function addVars($page) {
 89         if(isset($page['var'])) {
 90             $vars = explode(",",$page['var']);
 91             $data = array(); //assoc array
 92             foreach($vars as $var) {
 93                 if(isset($_GET[$var])) //check if the var exists in url
 94                     $data[$var] = $_GET[$var];
 95             }
 96             return "?".http_build_query($data);
 97         }
 98         return "";
 99     }
100 }
101 ?>
102 
NeuralMesh API documentation generated by ApiGen