Changeset 1436

Show
Ignore:
Timestamp:
12/17/09 17:02:31 (4 years ago)
Author:
gbastien
Message:
Location:
trunk/wifidog-auth
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1435 r1436  
    11# $Id$ 
     2 
     32009-12-17 
     4 * Code refactoring: Network, NodeGroup, Node inherit from HotspotGraphElement (#677) 
     5 
    262009-12-08 
    37 * Added the concept of node group and hierarchy (in a not too clean way to start with, I will refactor the code before adding new functionalities to nodes and groups) (#246) 
  • trunk/wifidog-auth/wifidog/classes/Content/ContentGroup/ContentGroupElement.php

    r1421 r1436  
    332332        /* content_group_element_has_allowed_nodes */ 
    333333        $html .= "<li class='admin_element_item_container'>\n"; 
    334         $html .= "<div class='admin_element_label'>" . _("Only display at node(s):") . "</div>\n"; 
     334        $html .= "<div class='admin_element_label'>" . _("Only display at node(s):") . _(" (DEPRECATED should use NodeGroups instead)") . "</div>\n"; 
    335335        $html .= "<ul class='admin_element_list'>\n"; 
    336336 
  • trunk/wifidog-auth/wifidog/classes/HotspotGraph.php

    r1435 r1436  
    6767        $db = AbstractDb :: getObject(); 
    6868        $allparents = array(); 
    69         $allparents[] = $object->getId(); 
     69        $hgeid = $object->getHgeId(); 
     70        $allparents[] = $hgeid; 
    7071        $newchildren = array(); 
    71         $newchildren[] = "'{$db->escapeString($object->getId())}'";       
    72          
    73         while (!empty($newchildren)) { 
    74             $parentswhere = implode(', ', $newchildren); 
    75             $parents_sql = "SELECT hg.parent_element_id FROM hotspot_graph hg 
    76                 where hg.child_element_id in ({$parentswhere})";  
    77              
    78             $parent_rows = null; 
    79             $db->execSql($parents_sql, $parent_rows, false); 
    80             $newchildren = array(); 
    81              
    82             if ($parent_rows) { 
    83                 foreach ($parent_rows as $parent_row) { 
    84                     if (!in_array($parent_row['parent_element_id'], $allparents)) { 
    85                         $allparents[] = $parent_row['parent_element_id']; 
    86                         $newchildren[] = "'{$db->escapeString($parent_row['parent_element_id'])}'"; 
     72        $newchildren[] = "{$db->escapeString($hgeid)}";       
     73         
     74        while (!empty($newchildren)) {      
     75            $notvisited = array(); 
     76            foreach ($newchildren as $child) { 
     77                $next_level = HotspotGraph::getParents($child); 
     78                if ($next_level) { 
     79                    foreach ($next_level as $next_row) { 
     80                        if (!in_array($next_row['next_element_id'], $allparents)) { 
     81                            $allparents[] = $next_row['next_element_id']; 
     82                            $notvisited[] =  $next_row['next_element_id']; 
     83                        } 
    8784                    } 
    8885                } 
    8986            } 
    90         } 
     87            $newchildren = $notvisited; 
     88        } 
     89         
    9190        return $allparents; 
    9291    } 
     
    109108        // Init values 
    110109        $html = ""; 
    111         $object_id = $graph_element->getId(); 
     110        $object_id = $db->escapeString($graph_element->getHgeId()); 
    112111         
    113112         
     
    116115             
    117116            $_title = _("Parents :"); 
    118             $parents_sql = "SELECT hg.parent_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
    119                 inner join hotspot_graph_elements hge on hg.parent_element_id = hge.hotspot_graph_element_id 
    120                 left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
    121                 left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
    122                 left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
    123                 where hg.child_element_id = '{$db->escapeString($graph_element->getId())}'";  
    124              
    125             $parent_rows = null; 
    126             $db->execSql($parents_sql, $parent_rows, false); 
     117            $parent_rows = HotspotGraph::getParents($object_id); 
    127118            $listData = ""; 
    128119             
     
    130121                foreach ($parent_rows as $parent_row) { 
    131122                    $classname = $parent_row['element_type']; 
    132                     $element = HotspotGraphElement::getChildObject($classname, $parent_row['element_id']); 
     123                    $element = HotspotGraphElement::getObject($parent_row['element_id'], $classname); 
    133124                    $parentStr = htmlspecialchars($parent_row['name']) . " (".htmlspecialchars($parent_row['element_type']) .")  "; 
    134                     $name = $object_id . "_parent_" . $parent_row['parent_element_id'] . "_remove"; 
     125                    $name = $object_id . "_parent_" . $parent_row['next_element_id'] . "_remove"; 
    135126                    $listDataContents = InterfaceElements::generateAdminSection("", $parentStr, InterfaceElements::generateInputSubmit($name, _("Remove from"))); 
    136127                    $listData .= "<li class='admin_element_item_container node_owner_list'>".$listDataContents."</li>\n"; 
     
    139130             
    140131            $listData .= "<li class='admin_element_item_container'>"; 
    141             $listData .= HotspotGraphElement::getSelectGraphElementUI($object_id . "_parent_add_element", array('additionalWhere' => " AND element_type in ('Network', 'NodeGroup') AND hotspot_graph_element_id != '{$db->escapeString($graph_element->getId())}'")); 
     132            $listData .= HotspotGraphElement::getSelectGraphElementUI($object_id . "_parent_add_element", array('additionalWhere' => " AND element_type in ('Network', 'NodeGroup') AND hotspot_graph_element_id != '{$db->escapeString($graph_element->getHgeId())}'")); 
    142133            $listData .= InterfaceElements::generateInputSubmit($object_id . "_parent_add", _("Add")); 
    143134            $listData .= "<br class='clearbr' /></li>\n"; 
     
    154145             
    155146            $_title = _("Children :"); 
    156             $children_sql = "SELECT hg.child_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
    157                 inner join hotspot_graph_elements hge on hg.child_element_id = hge.hotspot_graph_element_id 
    158                 left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
    159                 left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
    160                 left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
    161                 where hg.parent_element_id = '{$db->escapeString($graph_element->getId())}'";  
    162              
    163             $children_rows = null; 
    164             $db->execSql($children_sql, $children_rows, false); 
     147            $children_rows = HotspotGraph::getChildren($object_id); 
    165148            $listData = ""; 
    166149             
     
    168151                foreach ($children_rows as $child_row) { 
    169152                    $classname = $child_row['element_type']; 
    170                     $element = HotspotGraphElement::getChildObject($classname, $child_row['element_id']); 
     153                    $element = HotspotGraphElement::getObject($child_row['element_id'], $classname); 
    171154                    $childStr = htmlspecialchars($child_row['name']) . " (".htmlspecialchars($child_row['element_type']) .")  ";; 
    172                     $name = $object_id . "_child_" . $child_row['child_element_id'] . "_remove"; 
     155                    $name = $object_id . "_child_" . $child_row['next_element_id'] . "_remove"; 
    173156                    $listDataContents = InterfaceElements::generateAdminSection("", $childStr, InterfaceElements::generateInputSubmit($name, _("Remove from"))); 
    174157                    $listData .= "<li class='admin_element_item_container node_owner_list'>".$listDataContents."</li>\n"; 
     
    177160             
    178161            $listData .= "<li class='admin_element_item_container'>"; 
    179             $listData .= HotspotGraphElement::getSelectGraphElementUI($object_id . "_child_add_element", array('additionalWhere' => " AND element_type in ('Node', 'NodeGroup') AND hotspot_graph_element_id != '{$db->escapeString($graph_element->getId())}'")); 
     162            $listData .= HotspotGraphElement::getSelectGraphElementUI($object_id . "_child_add_element", array('additionalWhere' => " AND element_type in ('Node', 'NodeGroup') AND hotspot_graph_element_id != '{$db->escapeString($graph_element->getHgeId())}'")); 
    180163            $listData .= InterfaceElements::generateInputSubmit($object_id . "_child_add", _("Add")); 
    181164            $listData .= "<br class='clearbr' /></li>\n"; 
     
    201184    { 
    202185        $db = AbstractDb::getObject(); 
    203         $object_id = $db->escapeString($graph_element->getId()); 
     186        $object_id = $db->escapeString($graph_element->getHgeId()); 
    204187        $allparents = array(); 
    205188         
    206189        // Process the parents 
    207190        // Process any remove element command 
    208         $parents_sql = "SELECT hg.parent_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
    209                 inner join hotspot_graph_elements hge on hg.parent_element_id = hge.hotspot_graph_element_id 
    210                 left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
    211                 left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
    212                 left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
    213                 where hg.child_element_id = '{$object_id}'";  
    214              
    215         $parent_rows = null; 
    216         $db->execSql($parents_sql, $parent_rows, false); 
     191        $parent_rows = HotspotGraph::getParents($object_id); 
    217192        $allparents = array(); 
    218193         
    219194        if($parent_rows) { 
    220195            foreach ($parent_rows as $parent_row) { 
    221                 $allparents[$parent_row['parent_element_id']] = $parent_row['name']; 
    222                 $name = $object_id . "_parent_" . $parent_row['parent_element_id'] . "_remove"; 
     196                $allparents[$parent_row['next_element_id']] = $parent_row['name']; 
     197                $name = $object_id . "_parent_" . $parent_row['next_element_id'] . "_remove"; 
    223198                if(!empty($_REQUEST[$name])) { 
    224                     $parentIdStr = $db->escapeString($parent_row['parent_element_id']); 
     199                    $parentIdStr = $db->escapeString($parent_row['next_element_id']); 
    225200                    $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='$parentIdStr' AND child_element_id='$object_id';"; 
    226201                    $db->execSqlUpdate($sql, false); 
     
    235210            if ($element) { 
    236211                //The user and role exist 
    237                 if(isset($allparents[$element->getId()])) { 
    238                     $errMsg .= sprintf(_("Element %s is already a parent of this object"), $allparents[$element->getId()]); 
     212                if(isset($allparents[$element->getHgeId()])) { 
     213                    $errMsg .= sprintf(_("Element %s is already a parent of this object"), $allparents[$element->getHgeId()]); 
     214                } elseif (HotspotGraph::detectCycle($graph_element, $element->getHgeId(), false)) { 
     215                    $errMsg .= sprintf(_("Cycle detected while adding element '%s' as a parent of this object: this element is already among the children of this object."), $element->__toString()); 
    239216                } 
    240217                else {// the user doesn't already have that role 
    241                     $sql = "INSERT INTO hotspot_graph (parent_element_id, child_element_id) VALUES ('{$element->getId()}', '{$object_id}');"; 
     218                    $sql = "INSERT INTO hotspot_graph (parent_element_id, child_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');"; 
    242219                    $db->execSqlUpdate($sql, false); 
    243220     
     
    248225        // Process the children 
    249226        // Process any remove element command 
    250         $children_sql = "SELECT hg.child_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
    251                 inner join hotspot_graph_elements hge on hg.child_element_id = hge.hotspot_graph_element_id 
    252                 left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
    253                 left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
    254                 left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
    255                 where hg.parent_element_id = '{$object_id}'";  
    256              
    257         $children_rows = null; 
    258         $db->execSql($children_sql, $children_rows, false); 
     227        $children_rows = HotspotGraph::getChildren($object_id); 
     228         
    259229        $allchildren = array(); 
    260230         
    261231        if($children_rows) { 
    262232            foreach ($children_rows as $child_row) { 
    263                 $allchildren[$child_row['child_element_id']] = $child_row['name']; 
    264                 $name = $object_id . "_child_" . $child_row['child_element_id'] . "_remove"; 
     233                $allchildren[$child_row['next_element_id']] = $child_row['name']; 
     234                $name = $object_id . "_child_" . $child_row['next_element_id'] . "_remove"; 
    265235                if(!empty($_REQUEST[$name])) { 
    266                     $childIdStr = $db->escapeString($child_row['child_element_id']); 
     236                    $childIdStr = $db->escapeString($child_row['next_element_id']); 
    267237                    $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='$object_id' AND child_element_id='$childIdStr';"; 
    268238                    $db->execSqlUpdate($sql, false); 
     
    277247            if ($element) { 
    278248                //The user and role exist 
    279                 if(isset($allchildren[$element->getId()])) { 
    280                     $errMsg .= sprintf(_("Element '%s' is already a child of this object"), $allchildren[$element->getId()]); 
    281                 } 
    282                 elseif (isset($allparents[$element->getId()])) { 
    283                     $errMsg .= sprintf(_("Element '%s' is a parent of this object and therefore cannot be a child as well"), $allparents[$element->getId()]); 
     249                if(isset($allchildren[$element->getHgeId()])) { 
     250                    $errMsg .= sprintf(_("Element '%s' is already a child of this object"), $allchildren[$element->getHgeId()]); 
     251                } 
     252                elseif (HotspotGraph::detectCycle($graph_element, $element->getHgeId(), true)) { 
     253                    $errMsg .= sprintf(_("Cycle detected while adding element '%s' as a child of this object: this element is already among the parents of this object."), $element->__toString()); 
    284254                } 
    285255                else {// the user doesn't already have that role 
    286                     $sql = "INSERT INTO hotspot_graph (child_element_id, parent_element_id) VALUES ('{$element->getId()}', '{$object_id}');"; 
     256                    $sql = "INSERT INTO hotspot_graph (child_element_id, parent_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');"; 
    287257                    $db->execSqlUpdate($sql, false); 
    288258     
     
    291261        } 
    292262        return null; 
     263    } 
     264     
     265    /** 
     266     * Returns an array of rows containing information on the children of this node 
     267     * @param string $element the db-escaped hotspot_graph_element_id 
     268     * @return array 
     269     */ 
     270    public static function getChildren($object_id) { 
     271        $db = AbstractDb::getObject(); 
     272         
     273        $children_sql = "SELECT hg.child_element_id as next_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
     274                inner join hotspot_graph_elements hge on hg.child_element_id = hge.hotspot_graph_element_id 
     275                left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
     276                left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
     277                left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
     278                where hg.parent_element_id = '{$object_id}'";  
     279             
     280        $children_rows = null; 
     281        $db->execSql($children_sql, $children_rows, false); 
     282        return $children_rows; 
     283    }     
     284     
     285    /** 
     286     * Returns an array of rows containing information on the parents of this node 
     287     * @param string $element the db-escaped hotspot_graph_element_id 
     288     * @return array 
     289     */ 
     290    public static function getParents($object_id) { 
     291        $db = AbstractDb::getObject(); 
     292         
     293        $parents_sql = "SELECT hg.parent_element_id as next_element_id, hge.element_id, hge.element_type, coalesce(n.name, ng.name, no.name) as name FROM hotspot_graph hg 
     294                inner join hotspot_graph_elements hge on hg.parent_element_id = hge.hotspot_graph_element_id 
     295                left join networks n on hge.element_id = n.network_id AND hge.element_type='Network'  
     296                left join node_groups ng on hge.element_id = ng.node_group_id AND hge.element_type = 'NodeGroup' 
     297                left join nodes no on hge.element_id = no.node_id AND hge.element_type = 'Node' 
     298                where hg.child_element_id = '{$object_id}'";  
     299             
     300        $parent_rows = null; 
     301        $db->execSql($parents_sql, $parent_rows, false); 
     302        return $parent_rows; 
     303         
     304    } 
     305     
     306    /** 
     307     * Detect if the addition of element with id $object_id as either parent or child would cause the graph to have a cycle 
     308     * @param HotspotGraphElement $start_element The element to start cycle detection with 
     309     * @param string $object_id The object_id of the element to add to the graph from $start_elelemtn 
     310     * @param boolean $child if the element to add to the graph is a child of the start_element or a parent 
     311     * @return boolean (true if cycle detected) 
     312     */ 
     313    protected static function detectCycle($start_element, $object_id, $child = true) { 
     314        // If the element is a child, we check for its presence in the parents and vice versa 
     315        if ($child) { 
     316            $function = 'getParents'; 
     317        } else { 
     318            $function = 'getChildren'; 
     319        } 
     320        $db = AbstractDb::getObject(); 
     321        $start_object_id = $db->escapeString($start_element->getHgeId()); 
     322        return HotspotGraph::isCycle($start_object_id, $function, $object_id); 
     323    } 
     324     
     325    /** 
     326     *  
     327     * @param string $start_object_id The id of the object to start the search from 
     328     * @param string $function the function to get the next level of elements 
     329     * @param string $object_id the object id to searhc for 
     330     * @param array $visited the array of visited element 
     331     * @return boolean true if cycle 
     332     */ 
     333    protected static function isCycle($start_object_id, $function, $object_id, &$visited = array()) { 
     334        
     335        if ($start_object_id == $object_id) 
     336            return true; 
     337        $visited[] = $start_object_id; 
     338        $cycle = false; 
     339        $next_level = HotspotGraph::$function($start_object_id); 
     340        if ($next_level) { 
     341            foreach ($next_level as $next_row) { 
     342                if (!in_array($next_row['next_element_id'], $visited)) 
     343                    $cycle = $cycle || HotspotGraph::isCycle($next_row['next_element_id'], $function, $object_id, $visited); 
     344                if ($cycle) 
     345                    break; 
     346            } 
     347        } 
     348        return $cycle; 
    293349    } 
    294350 
  • trunk/wifidog-auth/wifidog/classes/HotspotGraphElement.php

    r1435 r1436  
    4747require_once('classes/Content.php'); 
    4848require_once('classes/User.php'); 
    49 require_once('classes/Node.php'); 
    50 require_once('classes/Network.php'); 
    51 require_once('classes/NodeGroup.php'); 
    5249require_once('classes/HotspotGraph.php'); 
    5350 
     
    6057 * @package    WiFiDogAuthServer 
    6158 * @author     Geneviève Bastien <gbastien@versatic.net> 
    62  * @todo                 Logically, Network, Node and NodeGroup should inherit from HotspotGraphElement, the base class, but one change 
    63  *             at a time.  First we'll add the possibility to group nodes easily and add contents to those groups. 
    64  *             For this purpose at this point, Hotspot graph element will be rather considered as a part of the child instead of its parent. 
    65  *             If reactions are good to those additions, the logic of the interface will be changed to make the graph more central and have 
    66  *             Networks, nodes and nodeGroups just elements types. 
    6759 */ 
    68 class HotspotGraphElement extends GenericDataObject 
     60abstract class HotspotGraphElement extends GenericDataObject 
    6961{ 
    7062    /** Object cache for the object factory (getObject())*/ 
    7163    protected static $instanceArray = array('Network' => array(), 'Node' => array(), 'NodeGroup' => array()); 
    72     protected static $possibleTypes = array('Network', 'Node', 'NodeGroup'); 
     64    protected $_hgeid; 
     65    protected $_hgerow; 
    7366 
    7467    /** 
     
    8881    public static function &getObject($id, $type = 'Node') 
    8982    { 
     83        if (!(class_exists($type) && (get_parent_class($type) == 'HotspotGraphElement'))) 
     84            throw new Exception(_("HotspotGraphElement::getObject, parameter type has a wrong value.  Should be the name of a child class.")); 
    9085        if(!isset(self::$instanceArray[$type][$id])) 
    9186        { 
    92             self::$instanceArray[$type][$id] = new self($type, $id); 
     87            self::$instanceArray[$type][$id] = new $type($id); 
    9388        } 
    9489        return self::$instanceArray[$type][$id]; 
    95     } 
    96      
    97                 /** 
    98      * Get an instance of the child object of this graph element (the element represented by this) 
    99      * 
    100      *  
    101      * @param string $id The object id 
    102      * @param string $type The type of graph element: Node, Network or NodeGroup 
    103      * 
    104      * @return mixed An object of type Network, Node or NodeGroup 
    105      * 
    106      * @see GenericObject 
    107      * @static 
    108      * @access public 
    109      */ 
    110     public static function &getChildObject($id, $type = 'Node') 
    111     { 
    112         $object = null; 
    113         switch($type) { 
    114             case 'Network': $object = Network::getObject($id); 
    115                 break; 
    116             case 'NodeGroup': $object = NodeGroup::getObject($id); 
    117                 break; 
    118             case 'Node': $object = Node::getObject($id); 
    119                 break; 
    120  
    121         } 
    122         return $object; 
    123     } 
    124      
    125                 /** 
    126      * Get an instance of this class for a child object 
    127      * 
    128      *  
    129      * @param object $object The object id 
    130      * @param string $type The type of graph element: Node, Network or NodeGroup 
    131      * 
    132      * @return mixed An object of type Network, Node or NodeGroup 
    133      * 
    134      * @see GenericObject 
    135      * @static 
    136      * @access public 
    137      */ 
    138     public static function &getObjectFor($object) 
    139     { 
    140         $object_id = $object->getId(); 
    141         if ($object instanceof Network) { 
    142             return self::getObject($object_id, 'Network'); 
    143         } 
    144         elseif ($object instanceof NodeGroup) { 
    145             return self::getObject($object_id, 'NodeGroup'); 
    146         } 
    147         elseif ($object instanceof Node) { 
    148             return self::getObject($object_id, 'Node'); 
    149         } 
    150         else { 
    151             throw new Exception(_('HotspotGraphElement: getObjectFor an object of a wrong class')); 
    152         } 
    153         return null; 
    15490    } 
    15591 
     
    15894     * Thanks and so long for all the ram. 
    15995     */ 
    160     public static function freeObject($id) 
    161     { 
    162         if(isset(self::$instanceArray[$id])) 
     96    public static function freeObject($id, $type) 
     97    { 
     98        if (!(class_exists($type) && (get_parent_class($type) == 'HotspotGraphElement'))) 
     99            throw new Exception(_("HotspotGraphElement::freeObject, parameter type has a wrong value.  Should be the name of a child class.")); 
     100        if(isset(self::$instanceArray[$type][$id])) 
    163101        { 
    164             unset(self::$instanceArray[$id]); 
     102            unset(self::$instanceArray[$type][$id]); 
    165103        } 
    166104    } 
     
    183121        $graph_element_id = get_guid(); 
    184122         
    185         if (!in_array($element_type, self::$possibleTypes)) 
     123         if (!(class_exists($element_type) && (get_parent_class($element_type) == 'HotspotGraphElement'))) 
    186124            throw new Exception(_('Cannot add element to hotspot graph. Wrong type specified: ').$element_type); 
    187125        
     
    189127 
    190128        if (!$db->execSqlUpdate($sql, false)) { 
    191             throw new Exception(_('Unable to insert the new network in the database!')); 
     129            throw new Exception(_('Unable to insert the new element in the database!')); 
    192130        } 
    193131        $object = self::getObject($element_id, $element_type); 
     
    364302     * @access private 
    365303     */ 
    366     private function __construct($type, $id) 
     304    protected function __construct($id, $type) 
    367305    { 
    368306        $db = AbstractDb::getObject(); 
     
    375313            throw new Exception("The element of type $type with id $element_id_str could not be found in the database"); 
    376314        } 
    377         $this->_row = $row; 
    378         $this->_id = $row['hotspot_graph_element_id']; 
    379     } 
    380  
    381     public function __toString() 
    382     { 
    383         return $this->getId(); 
    384     } 
     315        $this->_hgerow = $row; 
     316        $this->_hgeid = $row['hotspot_graph_element_id']; 
     317    } 
     318 
     319    public function getHgeId() { 
     320        return $this->_hgeid; 
     321    } 
     322     
     323    public abstract function __toString(); 
    385324 
    386325    /** 
     
    389328     * @return string 
    390329     */ 
    391     protected function getType() { 
    392         return $this->_row['element_type']; 
    393     } 
     330    protected abstract function getType(); 
    394331   
    395332    /** 
     
    397334     * @return boolean 
    398335     */ 
    399     public function isRoot() { 
    400         return ($this->getType() == 'Network'); 
    401     } 
     336    public abstract function isRoot() ; 
    402337     
    403338                /** 
     
    405340     * @return boolean 
    406341     */ 
    407     public function isLeaf() { 
    408         return ($this->getType() == 'Node'); 
    409     } 
     342    public abstract function isLeaf(); 
    410343 
    411344    /** 
     
    421354        require_once('classes/Stakeholder.php'); 
    422355         
    423         $hge_id = $this->getId(); 
    424          
     356        $hge_id = $this->getHgeId(); 
     357 
    425358        $_html_content = array(); 
    426359        $_title = _("Node content"); 
    427         $_data = Content::getLinkedContentUI("hge_" . $hge_id . "_content", "hotspot_graph_element_has_content", "hotspot_graph_element_id", $this->_id, "portal"); 
     360        $_data = Content::getLinkedContentUI("hge_" . $hge_id . "_content", "hotspot_graph_element_has_content", "hotspot_graph_element_id", $hge_id, "portal"); 
    428361        $html .= InterfaceElements::generateAdminSectionContainer("node_content", $_title, $_data); 
    429362         
     
    441374    public function processContentAdminUI() 
    442375    { 
    443         $hge_id = $this->getId(); 
     376        $hge_id = $this->getHgeId(); 
    444377         
    445378        $name = "hge_{$hge_id}_content"; 
    446         Content::processLinkedContentUI($name, 'hotspot_graph_element_has_content', 'hotspot_graph_element_id', $this->_id); 
     379        Content::processLinkedContentUI($name, 'hotspot_graph_element_has_content', 'hotspot_graph_element_id', $hge_id); 
    447380         
    448381    } 
     
    464397        // Group section 
    465398        if (is_null($network) || Security::hasPermission(Permission::P('NETWORK_PERM_ALLOW_GROUP_NODE'), $network)) { 
    466             $hge_id = $this->getId(); 
     399            $hge_id = $this->getHgeId(); 
    467400         
    468401            $_html_content = array(); 
     
    484417    public function processGraphAdminUI(&$errMsg, $network = null) 
    485418    { 
    486         $hge_id = $this->getId(); 
     419        $hge_id = $this->getHgeId(); 
    487420         
    488421        if (is_null($network) || Security::hasPermission(Permission::P('NETWORK_PERM_ALLOW_GROUP_NODE'), $network)) { 
     
    580513        $db = AbstractDb::getObject(); 
    581514 
    582         $content_id = $db->escapeString($content->getId()); 
    583         $sql = "INSERT INTO hotspot_graph_element_has_content (hotspot_graph_element_id, content_id) VALUES ('$this->_id','$content_id')"; 
     515        $content_id = $db->escapeString($content->getHgeId()); 
     516        $sql = "INSERT INTO hotspot_graph_element_has_content (hotspot_graph_element_id, content_id) VALUES ('$this->_hgeid','$content_id')"; 
    584517        $db->execSqlUpdate($sql, false); 
    585518    } 
     
    598531        $db = AbstractDb::getObject(); 
    599532 
    600         $content_id = $db->escapeString($content->getId()); 
    601         $sql = "DELETE FROM hotspot_graph_element_has_content WHERE hotspot_graph_element_id='$this->_id' AND content_id='$content_id'"; 
     533        $content_id = $db->escapeString($content->getHgeId()); 
     534        $sql = "DELETE FROM hotspot_graph_element_has_content WHERE hotspot_graph_element_id='$this->_hgeid' AND content_id='$content_id'"; 
    602535        $db->execSqlUpdate($sql, false); 
    603536    } 
    604  
    605     /** 
    606      * Delete this Object form the it's storage mechanism 
    607      * 
    608      * @param string &$errmsg Returns an explanation of the error on failure 
    609      * 
    610      * @return bool true on success, false on failure or access denied 
    611      * 
    612      * @access public 
    613      */ 
    614     public function delete(& $errmsg) 
     537     
     538     
     539    /** Delete this Object form it's storage mechanism 
     540     * @param &$errmsg Appends an explanation of the error on failure 
     541     * @return true on success, false on failure or access denied */ 
     542    public function delete(& $errmsg) { 
     543        $errmsg .= sprintf(_("Delete not supported on class %s"),get_class($this)); 
     544        return false; 
     545    } 
     546 
     547    /** 
     548     * Function called by the children of this class to delete the parent element form the graph 
     549     * @param unknown_type $errmsg 
     550     * @return unknown_type 
     551     */ 
     552    protected function _delete(& $errmsg) 
    615553    { 
    616554        // Init values 
    617555        $retval = false; 
    618         if ($this->isDefaultNetwork() === true) { 
    619             $errmsg = _('Cannot delete default network, create another one and select it before you remove this one.'); 
     556         
     557        $db = AbstractDb::getObject(); 
     558        $id = $db->escapeString($this->getHgeId()); 
     559        if (!$db->execSqlUpdate("DELETE FROM hotspot_graph_elements WHERE hotspot_graph_element_id='{$id}'", false)) { 
     560            $errmsg = _('Could not delete graph element!'); 
    620561        } else { 
    621             $db = AbstractDb::getObject(); 
    622             $id = $db->escapeString($this->getId()); 
    623             if (!$db->execSqlUpdate("DELETE FROM hotspot_graph_elements WHERE hotspot_graph_element_id='{$id}'", false)) { 
    624                 $errmsg = _('Could not delete graph element!'); 
    625             } else { 
    626                 $retval = true; 
    627             } 
    628         } 
    629  
     562            $retval = true; 
     563        } 
    630564 
    631565        return $retval; 
     
    644578        //$this->__construct($this->_id); 
    645579    } 
     580     
     581 
    646582 
    647583    /** Menu hook function */ 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1435 r1436  
    4747 * Load required classes 
    4848 */ 
    49 require_once('classes/GenericDataObject.php'); 
    5049require_once('classes/Content.php'); 
    5150require_once('classes/User.php'); 
    5251require_once('classes/Node.php'); 
     52require_once('classes/NodeGroup.php'); 
    5353require_once('classes/GisPoint.php'); 
    5454require_once('classes/Cache.php'); 
     
    6868 * @copyright  2006 Max Horváth, Horvath Web Consulting 
    6969 */ 
    70 class Network extends GenericDataObject 
     70class Network extends HotspotGraphElement 
    7171{ 
    7272    /** Object cache for the object factory (getObject())*/ 
    73     private static $instanceArray = array(); 
    74     protected $_hotspotGraphElement; 
    7573 
    7674    /** 
     
    8886    public static function &getObject($id) 
    8987    { 
    90         if(!isset(self::$instanceArray[$id])) 
    91         { 
    92             self::$instanceArray[$id] = new self($id); 
    93         } 
    94         return self::$instanceArray[$id]; 
     88        return HotspotGraphElement::getObject($id, 'Network'); 
    9589    } 
    9690 
     
    10195    public static function freeObject($id) 
    10296    { 
    103         if(isset(self::$instanceArray[$id])) 
    104         { 
    105             unset(self::$instanceArray[$id]); 
    106         } 
     97        HotspotGraphElement::freeObject($id, 'Network'); 
    10798    } 
    10899 
     
    192183    public static function createNewObject($network_id = null) 
    193184    { 
     185         
    194186        $db = AbstractDb::getObject(); 
    195187        if (empty ($network_id)) { 
     
    380372     * @access private 
    381373     */ 
    382     private function __construct($p_network_id) 
     374    protected function __construct($p_network_id) 
    383375    { 
    384376        $db = AbstractDb::getObject(); 
     
    395387        $this->_row = $row; 
    396388        $this->_id = $p_network_id; 
    397         $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->_id,'Network'); 
     389        parent::__construct($this->_id, 'Network'); 
    398390    } 
    399391 
     
    17061698        $data = Content::getLinkedContentUI($name, "network_has_content", "network_id", $this->_id, $display_page = "portal"); 
    17071699        $html .= InterfaceElements::generateAdminSectionContainer("network_content", $title, $data);*/ 
    1708         if (!is_null($this->_hotspotGraphElement)) 
    1709             $html .= $this->_hotspotGraphElement->getContentAdminUI(); 
     1700         
     1701        $html .= parent::getContentAdminUI(); 
    17101702 
    17111703        /* 
     
    19371929         
    19381930        // objects hierarchy 
    1939         if (!is_null($this->_hotspotGraphElement)) 
    1940             $html .= $this->_hotspotGraphElement->getGraphAdminUI($this); 
     1931        $html .= parent::getGraphAdminUI($this); 
    19411932 
    19421933        $html .= "</ul>\n"; 
     
    19581949 
    19591950        // Content management 
    1960         if (!is_null($this->_hotspotGraphElement)) 
    1961             $this->_hotspotGraphElement->processContentAdminUI(); 
     1951        parent::processContentAdminUI(); 
    19621952        /* $name = "network_".$this->_id."_content"; 
    19631953        Content :: processLinkedContentUI($name, 'network_has_content', 'network_id', $this->_id);*/ 
     
    20792069        ProfileTemplate :: processLinkedProfileTemplateUI($name, 'network_has_profile_templates', 'network_id', $this->_id); 
    20802070         
    2081         if (!is_null($this->_hotspotGraphElement)) 
    2082             $this->_hotspotGraphElement->processGraphAdminUI($errMsg, $this); 
     2071        parent::processGraphAdminUI($errMsg, $this); 
    20832072        if(!empty($errMsg)) { 
    20842073            echo $errMsg; 
     
    21032092     * @access public 
    21042093     */ 
    2105     public function addContent(Content $content) 
     2094 /*   public function addContent(Content $content) 
    21062095    { 
    21072096        $db = AbstractDb::getObject(); 
     
    21102099        $sql = "INSERT INTO network_has_content (network_id, content_id) VALUES ('$this->_id','$content_id')"; 
    21112100        $db->execSqlUpdate($sql, false); 
    2112     } 
     2101    }*/ 
    21132102 
    21142103    /** 
     
    21212110     * @access public 
    21222111     */ 
    2123     public function removeContent(Content $content) 
     2112 /*   public function removeContent(Content $content) 
    21242113    { 
    21252114        $db = AbstractDb::getObject(); 
     
    21282117        $sql = "DELETE FROM network_has_content WHERE network_id='$this->_id' AND content_id='$content_id'"; 
    21292118        $db->execSqlUpdate($sql, false); 
    2130     } 
     2119    }*/ 
    21312120 
    21322121 
     
    22052194                $errmsg = _('Could not delete network!'); 
    22062195            } else { 
     2196                parent::_delete($errmsg); 
    22072197                $retval = true; 
    22082198            } 
     
    22742264        $smarty->assign('networkNumNonMonitoredNodes', $net ? $net->getNumOnlineNodes(true) : 0); 
    22752265    } 
     2266     
     2267/** 
     2268     * Get the type of graph element (read-only for now) 
     2269     *  
     2270     * @return string 
     2271     */ 
     2272    protected function getType() { 
     2273        return 'Network'; 
     2274    } 
     2275   
     2276    /** 
     2277     * Return whether this element is a root or has parent (Network is root) 
     2278     * @return boolean 
     2279     */ 
     2280    public function isRoot(){ 
     2281        return true; 
     2282    } 
     2283     
     2284                /** 
     2285     * Return whether this element is a leaf or has children (Node is leaf) 
     2286     * @return boolean 
     2287     */ 
     2288    public function isLeaf() { 
     2289        return false; 
     2290    } 
    22762291} 
    22772292 
  • trunk/wifidog-auth/wifidog/classes/Node.php

    r1435 r1436  
    6262 * @copyright  2005 Benoit Grégoire, Technologies Coeus inc. 
    6363 */ 
    64 class Node implements GenericObject 
     64class Node extends HotspotGraphElement 
    6565{ 
    6666    /** Object cache for the object factory (getObject())*/ 
    67     private static $instanceArray = array(); 
    68     private $_row; 
    69     private $mdB; /**< An AbstractDb instance */ 
    70     private $id; 
    71     private static $currentNode = null; 
    72     protected $_hotspotGraphElement; 
     67    protected $_row; 
     68    protected $mdB; /**< An AbstractDb instance */ 
     69    protected $id; 
     70    protected static $currentNode = null; 
    7371 
    7472    /** 
     
    7876     * @access private 
    7977     */ 
    80     private $_deploymentStatuses = array(); 
     78    protected $_deploymentStatuses = array(); 
    8179 
    8280    /** 
     
    8785     * @access private 
    8886     */ 
    89     private $_warningMessage; 
     87    protected $_warningMessage; 
    9088 
    9189    /** Instantiate a node object 
     
    9593    public static function &getObject($id) 
    9694    { 
    97         if(!isset(self::$instanceArray[$id])) 
    98         { 
    99             self::$instanceArray[$id] = new self($id); 
    100         } 
    101         return self::$instanceArray[$id]; 
     95        return HotspotGraphElement::getObject($id, 'Node'); 
    10296    } 
    10397 
     
    108102    public static function freeObject($id) 
    109103    { 
    110         if(isset(self::$instanceArray[$id])) 
    111         { 
    112             unset(self::$instanceArray[$id]); 
    113         } 
     104        HotspotGraphElement::freeObject($id, 'Node'); 
    114105    } 
    115106 
     
    226217            else 
    227218            { 
     219                parent::_delete($errmsg); 
    228220                $retval = true; 
    229221            } 
     
    663655    /** @param $id The id of the node 
    664656     * @param $idType 'NODE_ID' or 'GATEWAY_ID'*/ 
    665     private function __construct($id, $idType='NODE_ID') 
     657    protected function __construct($id, $idType='NODE_ID') 
    666658    { 
    667659        $db = AbstractDb::getObject(); 
     
    698690        $this->id = $row['node_id']; 
    699691         
    700         $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->id, 'Node'); 
     692        parent::__construct($this->id, 'Node'); 
    701693    } 
    702694 
     
    11971189        $_data = Content::getLinkedContentUI("node_" . $node_id . "_content", "node_has_content", "node_id", $this->id, "portal"); 
    11981190        $html .= InterfaceElements::generateAdminSectionContainer("node_content", $_title, $_data);*/ 
    1199         if (!is_null($this->_hotspotGraphElement)) 
    1200             $html .= $this->_hotspotGraphElement->getContentAdminUI(); 
     1191        $html .= parent::getContentAdminUI(); 
    12011192             
    12021193        // Name 
     
    13721363         
    13731364        //Node hierarchy 
    1374         if (!is_null($this->_hotspotGraphElement)) 
    1375             $html .= $this->_hotspotGraphElement->getGraphAdminUI($network); 
     1365        $html .= parent::getGraphAdminUI($network); 
    13761366 
    13771367        $html .= "</ul>\n"; 
     
    14161406        } 
    14171407        // Content processing 
    1418         if (!is_null($this->_hotspotGraphElement)) 
    1419             $this->_hotspotGraphElement->processContentAdminUI(); 
     1408        parent::processContentAdminUI(); 
    14201409        /*$name = "node_{$node_id}_content"; 
    14211410        Content::processLinkedContentUI($name, 'node_has_content', 'node_id', $this->id);*/ 
     
    15811570        // End Node configuration section 
    15821571         
    1583         if (!is_null($this->_hotspotGraphElement)) 
    1584             $this->_hotspotGraphElement->processGraphAdminUI($errMsg, $network); 
     1572        parent::processGraphAdminUI($errMsg, $network); 
    15851573        if(!empty($errMsg)) { 
    15861574            echo $errMsg; 
     
    16021590 
    16031591    /** Add content to this node */ 
    1604     public function addContent(Content $content) 
     1592   /* public function addContent(Content $content) 
    16051593    { 
    16061594        $db = AbstractDb::getObject(); 
     
    16091597        $db->execSqlUpdate($sql, false); 
    16101598        exit; 
    1611     } 
     1599    }*/ 
    16121600 
    16131601    /** Remove content from this node */ 
    1614     public function removeContent(Content $content) 
     1602   /* public function removeContent(Content $content) 
    16151603    { 
    16161604        $db = AbstractDb::getObject(); 
     
    16181606        $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; 
    16191607        $db->execSqlUpdate($sql, false); 
    1620     } 
     1608    }*/ 
    16211609 
    16221610    /** 
     
    18321820        $smarty->assign('realNodeLastHeartbeatIP', $node ? $node->getLastHeartbeatIP() : ''); 
    18331821    } 
     1822     
     1823    /** 
     1824     * Get the type of graph element (read-only for now) 
     1825     *  
     1826     * @return string 
     1827     */ 
     1828    protected function getType() { 
     1829        return 'Node'; 
     1830    } 
     1831   
     1832    /** 
     1833     * Return whether this element is a root or has parent (Network is root) 
     1834     * @return boolean 
     1835     */ 
     1836    public function isRoot(){ 
     1837        return false; 
     1838    } 
     1839     
     1840                /** 
     1841     * Return whether this element is a leaf or has children (Node is leaf) 
     1842     * @return boolean 
     1843     */ 
     1844    public function isLeaf() { 
     1845        return true; 
     1846    } 
     1847     
    18341848} 
    18351849 
  • trunk/wifidog-auth/wifidog/classes/NodeGroup.php

    r1435 r1436  
    5858 * @copyright  2005 Benoit Grégoire, Technologies Coeus inc. 
    5959 */ 
    60 class NodeGroup implements GenericObject 
     60class NodeGroup extends HotspotGraphElement 
    6161{ 
    6262    /** Object cache for the object factory (getObject())*/ 
    63     private static $instanceArray = array(); 
    64     private $_row; 
    65     private $mdB; /**< An AbstractDb instance */ 
    66     private $id; 
    67     protected $_hotspotGraphElement; 
     63    protected $_row; 
     64    protected $mdB; /**< An AbstractDb instance */ 
     65    protected $id; 
    6866     
    6967    /** 
     
    7472     * @access private 
    7573     */ 
    76     private $_warningMessage; 
     74    protected $_warningMessage; 
    7775 
    7876    /** Instantiate a nodeGroup object 
     
    8280    public static function &getObject($id) 
    8381    { 
    84         if(!isset(self::$instanceArray[$id])) 
    85         { 
    86             self::$instanceArray[$id] = new self($id); 
    87         } 
    88         return self::$instanceArray[$id]; 
     82        return HotspotGraphElement::getObject($id, 'NodeGroup'); 
    8983    } 
    9084 
     
    9589    public static function freeObject($id) 
    9690    { 
    97         if(isset(self::$instanceArray[$id])) 
    98         { 
    99             unset(self::$instanceArray[$id]); 
    100         } 
     91        HotspotGraphElement::freeObject($id, 'NodeGroup'); 
    10192    } 
    10293     
     
    316307    /** @param $id The id of the node group 
    317308     * @param $idType 'GROUP_ID' or 'NAME'*/ 
    318     private function __construct($id, $idType='GROUP_ID') 
     309    protected function __construct($id, $idType='GROUP_ID') 
    319310    { 
    320311        $db = AbstractDb::getObject(); 
     
    342333        $this->id = $row['node_group_id']; 
    343334         
    344         $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->id, 'NodeGroup'); 
     335        parent::__construct($this->id, 'NodeGroup'); 
    345336    } 
    346337 
     
    464455 
    465456        //Node content 
    466         if (!is_null($this->_hotspotGraphElement)) 
    467             $html .= $this->_hotspotGraphElement->getContentAdminUI(); 
     457        $html .= parent::getContentAdminUI(); 
    468458             
    469459        //Node hierarchy 
    470         if (!is_null($this->_hotspotGraphElement)) 
    471             $html .= $this->_hotspotGraphElement->getGraphAdminUI(); 
     460        $html .= parent::getGraphAdminUI(); 
    472461             
    473462        // Build section 
     
    515504 
    516505        // Content processing 
    517         if (!is_null($this->_hotspotGraphElement)) 
    518             $this->_hotspotGraphElement->processContentAdminUI(); 
     506        parent::processContentAdminUI(); 
    519507 
    520508        // Name 
     
    535523        $this->setDescription($_REQUEST[$name]); 
    536524 
    537         if (!is_null($this->_hotspotGraphElement)) 
    538             $this->_hotspotGraphElement->processGraphAdminUI($errMsg); 
     525        parent::processGraphAdminUI($errMsg); 
    539526        if(!empty($errMsg)) { 
    540527            echo $errMsg; 
     
    552539 
    553540    /** Add content to this node */ 
    554     public function addContent(Content $content) 
     541   /* public function addContent(Content $content) 
    555542    { 
    556543        $db = AbstractDb::getObject(); 
     
    559546        $db->execSqlUpdate($sql, false); 
    560547        exit; 
    561     } 
     548    }*/ 
    562549 
    563550    /** Remove content from this node */ 
    564     public function removeContent(Content $content) 
     551  /*  public function removeContent(Content $content) 
    565552    { 
    566553        $db = AbstractDb::getObject(); 
     
    568555        $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; 
    569556        $db->execSqlUpdate($sql, false); 
    570     } 
     557    }*/ 
    571558 
    572559 
     
    634621        $smarty->assign('realNodeLastHeartbeatIP', $node ? $node->getLastHeartbeatIP() : ''); 
    635622    } 
     623     
     624        /** 
     625     * Get the type of graph element (read-only for now) 
     626     *  
     627     * @return string 
     628     */ 
     629    protected function getType() { 
     630        return 'NodeGroup'; 
     631    } 
     632   
     633    /** 
     634     * Return whether this element is a root or has parent (Network is root) 
     635     * @return boolean 
     636     */ 
     637    public function isRoot(){ 
     638        return false; 
     639    } 
     640     
     641                /** 
     642     * Return whether this element is a leaf or has children (Node is leaf) 
     643     * @return boolean 
     644     */ 
     645    public function isLeaf() { 
     646        return false; 
     647    } 
    636648} 
    637649 
  • trunk/wifidog-auth/wifidog/portal/index.php

    r1435 r1436  
    167167 
    168168// Get all the parent objects of the node 
    169 $parents = HotspotGraph::getAllParents(HotspotGraphElement::getObjectFor($node)); 
     169$parents = HotspotGraph::getAllParents($node); 
    170170 
    171171// Get the contents for all elements parents of and including the node, but exclude user subscribed content if user is known