Changeset 1436
- Timestamp:
- 12/17/09 17:02:31 (4 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 8 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/Content/ContentGroup/ContentGroupElement.php (modified) (1 diff)
-
wifidog/classes/HotspotGraph.php (modified) (13 diffs)
-
wifidog/classes/HotspotGraphElement.php (modified) (18 diffs)
-
wifidog/classes/Network.php (modified) (17 diffs)
-
wifidog/classes/Node.php (modified) (16 diffs)
-
wifidog/classes/NodeGroup.php (modified) (13 diffs)
-
wifidog/portal/index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1435 r1436 1 1 # $Id$ 2 3 2009-12-17 4 * Code refactoring: Network, NodeGroup, Node inherit from HotspotGraphElement (#677) 5 2 6 2009-12-08 3 7 * 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 332 332 /* content_group_element_has_allowed_nodes */ 333 333 $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"; 335 335 $html .= "<ul class='admin_element_list'>\n"; 336 336 -
trunk/wifidog-auth/wifidog/classes/HotspotGraph.php
r1435 r1436 67 67 $db = AbstractDb :: getObject(); 68 68 $allparents = array(); 69 $allparents[] = $object->getId(); 69 $hgeid = $object->getHgeId(); 70 $allparents[] = $hgeid; 70 71 $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 } 87 84 } 88 85 } 89 86 } 90 } 87 $newchildren = $notvisited; 88 } 89 91 90 return $allparents; 92 91 } … … 109 108 // Init values 110 109 $html = ""; 111 $object_id = $ graph_element->getId();110 $object_id = $db->escapeString($graph_element->getHgeId()); 112 111 113 112 … … 116 115 117 116 $_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); 127 118 $listData = ""; 128 119 … … 130 121 foreach ($parent_rows as $parent_row) { 131 122 $classname = $parent_row['element_type']; 132 $element = HotspotGraphElement::get ChildObject($classname, $parent_row['element_id']);123 $element = HotspotGraphElement::getObject($parent_row['element_id'], $classname); 133 124 $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"; 135 126 $listDataContents = InterfaceElements::generateAdminSection("", $parentStr, InterfaceElements::generateInputSubmit($name, _("Remove from"))); 136 127 $listData .= "<li class='admin_element_item_container node_owner_list'>".$listDataContents."</li>\n"; … … 139 130 140 131 $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->get Id())}'"));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())}'")); 142 133 $listData .= InterfaceElements::generateInputSubmit($object_id . "_parent_add", _("Add")); 143 134 $listData .= "<br class='clearbr' /></li>\n"; … … 154 145 155 146 $_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); 165 148 $listData = ""; 166 149 … … 168 151 foreach ($children_rows as $child_row) { 169 152 $classname = $child_row['element_type']; 170 $element = HotspotGraphElement::get ChildObject($classname, $child_row['element_id']);153 $element = HotspotGraphElement::getObject($child_row['element_id'], $classname); 171 154 $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"; 173 156 $listDataContents = InterfaceElements::generateAdminSection("", $childStr, InterfaceElements::generateInputSubmit($name, _("Remove from"))); 174 157 $listData .= "<li class='admin_element_item_container node_owner_list'>".$listDataContents."</li>\n"; … … 177 160 178 161 $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->get Id())}'"));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())}'")); 180 163 $listData .= InterfaceElements::generateInputSubmit($object_id . "_child_add", _("Add")); 181 164 $listData .= "<br class='clearbr' /></li>\n"; … … 201 184 { 202 185 $db = AbstractDb::getObject(); 203 $object_id = $db->escapeString($graph_element->get Id());186 $object_id = $db->escapeString($graph_element->getHgeId()); 204 187 $allparents = array(); 205 188 206 189 // Process the parents 207 190 // 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); 217 192 $allparents = array(); 218 193 219 194 if($parent_rows) { 220 195 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"; 223 198 if(!empty($_REQUEST[$name])) { 224 $parentIdStr = $db->escapeString($parent_row[' parent_element_id']);199 $parentIdStr = $db->escapeString($parent_row['next_element_id']); 225 200 $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='$parentIdStr' AND child_element_id='$object_id';"; 226 201 $db->execSqlUpdate($sql, false); … … 235 210 if ($element) { 236 211 //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()); 239 216 } 240 217 else {// the user doesn't already have that role 241 $sql = "INSERT INTO hotspot_graph (parent_element_id, child_element_id) VALUES ('{$element->get Id()}', '{$object_id}');";218 $sql = "INSERT INTO hotspot_graph (parent_element_id, child_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');"; 242 219 $db->execSqlUpdate($sql, false); 243 220 … … 248 225 // Process the children 249 226 // 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 259 229 $allchildren = array(); 260 230 261 231 if($children_rows) { 262 232 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"; 265 235 if(!empty($_REQUEST[$name])) { 266 $childIdStr = $db->escapeString($child_row[' child_element_id']);236 $childIdStr = $db->escapeString($child_row['next_element_id']); 267 237 $sql = "DELETE FROM hotspot_graph WHERE parent_element_id='$object_id' AND child_element_id='$childIdStr';"; 268 238 $db->execSqlUpdate($sql, false); … … 277 247 if ($element) { 278 248 //The user and role exist 279 if(isset($allchildren[$element->get Id()])) {280 $errMsg .= sprintf(_("Element '%s' is already a child of this object"), $allchildren[$element->get Id()]);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()); 284 254 } 285 255 else {// the user doesn't already have that role 286 $sql = "INSERT INTO hotspot_graph (child_element_id, parent_element_id) VALUES ('{$element->get Id()}', '{$object_id}');";256 $sql = "INSERT INTO hotspot_graph (child_element_id, parent_element_id) VALUES ('{$element->getHgeId()}', '{$object_id}');"; 287 257 $db->execSqlUpdate($sql, false); 288 258 … … 291 261 } 292 262 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; 293 349 } 294 350 -
trunk/wifidog-auth/wifidog/classes/HotspotGraphElement.php
r1435 r1436 47 47 require_once('classes/Content.php'); 48 48 require_once('classes/User.php'); 49 require_once('classes/Node.php');50 require_once('classes/Network.php');51 require_once('classes/NodeGroup.php');52 49 require_once('classes/HotspotGraph.php'); 53 50 … … 60 57 * @package WiFiDogAuthServer 61 58 * @author Geneviève Bastien <gbastien@versatic.net> 62 * @todo Logically, Network, Node and NodeGroup should inherit from HotspotGraphElement, the base class, but one change63 * 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 have66 * Networks, nodes and nodeGroups just elements types.67 59 */ 68 class HotspotGraphElement extends GenericDataObject60 abstract class HotspotGraphElement extends GenericDataObject 69 61 { 70 62 /** Object cache for the object factory (getObject())*/ 71 63 protected static $instanceArray = array('Network' => array(), 'Node' => array(), 'NodeGroup' => array()); 72 protected static $possibleTypes = array('Network', 'Node', 'NodeGroup'); 64 protected $_hgeid; 65 protected $_hgerow; 73 66 74 67 /** … … 88 81 public static function &getObject($id, $type = 'Node') 89 82 { 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.")); 90 85 if(!isset(self::$instanceArray[$type][$id])) 91 86 { 92 self::$instanceArray[$type][$id] = new self($type,$id);87 self::$instanceArray[$type][$id] = new $type($id); 93 88 } 94 89 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 id102 * @param string $type The type of graph element: Node, Network or NodeGroup103 *104 * @return mixed An object of type Network, Node or NodeGroup105 *106 * @see GenericObject107 * @static108 * @access public109 */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 object127 *128 *129 * @param object $object The object id130 * @param string $type The type of graph element: Node, Network or NodeGroup131 *132 * @return mixed An object of type Network, Node or NodeGroup133 *134 * @see GenericObject135 * @static136 * @access public137 */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;154 90 } 155 91 … … 158 94 * Thanks and so long for all the ram. 159 95 */ 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])) 163 101 { 164 unset(self::$instanceArray[$ id]);102 unset(self::$instanceArray[$type][$id]); 165 103 } 166 104 } … … 183 121 $graph_element_id = get_guid(); 184 122 185 if (!in_array($element_type, self::$possibleTypes))123 if (!(class_exists($element_type) && (get_parent_class($element_type) == 'HotspotGraphElement'))) 186 124 throw new Exception(_('Cannot add element to hotspot graph. Wrong type specified: ').$element_type); 187 125 … … 189 127 190 128 if (!$db->execSqlUpdate($sql, false)) { 191 throw new Exception(_('Unable to insert the new networkin the database!'));129 throw new Exception(_('Unable to insert the new element in the database!')); 192 130 } 193 131 $object = self::getObject($element_id, $element_type); … … 364 302 * @access private 365 303 */ 366 pr ivate function __construct($type, $id)304 protected function __construct($id, $type) 367 305 { 368 306 $db = AbstractDb::getObject(); … … 375 313 throw new Exception("The element of type $type with id $element_id_str could not be found in the database"); 376 314 } 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(); 385 324 386 325 /** … … 389 328 * @return string 390 329 */ 391 protected function getType() { 392 return $this->_row['element_type']; 393 } 330 protected abstract function getType(); 394 331 395 332 /** … … 397 334 * @return boolean 398 335 */ 399 public function isRoot() { 400 return ($this->getType() == 'Network'); 401 } 336 public abstract function isRoot() ; 402 337 403 338 /** … … 405 340 * @return boolean 406 341 */ 407 public function isLeaf() { 408 return ($this->getType() == 'Node'); 409 } 342 public abstract function isLeaf(); 410 343 411 344 /** … … 421 354 require_once('classes/Stakeholder.php'); 422 355 423 $hge_id = $this->get Id();424 356 $hge_id = $this->getHgeId(); 357 425 358 $_html_content = array(); 426 359 $_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"); 428 361 $html .= InterfaceElements::generateAdminSectionContainer("node_content", $_title, $_data); 429 362 … … 441 374 public function processContentAdminUI() 442 375 { 443 $hge_id = $this->get Id();376 $hge_id = $this->getHgeId(); 444 377 445 378 $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); 447 380 448 381 } … … 464 397 // Group section 465 398 if (is_null($network) || Security::hasPermission(Permission::P('NETWORK_PERM_ALLOW_GROUP_NODE'), $network)) { 466 $hge_id = $this->get Id();399 $hge_id = $this->getHgeId(); 467 400 468 401 $_html_content = array(); … … 484 417 public function processGraphAdminUI(&$errMsg, $network = null) 485 418 { 486 $hge_id = $this->get Id();419 $hge_id = $this->getHgeId(); 487 420 488 421 if (is_null($network) || Security::hasPermission(Permission::P('NETWORK_PERM_ALLOW_GROUP_NODE'), $network)) { … … 580 513 $db = AbstractDb::getObject(); 581 514 582 $content_id = $db->escapeString($content->get Id());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')"; 584 517 $db->execSqlUpdate($sql, false); 585 518 } … … 598 531 $db = AbstractDb::getObject(); 599 532 600 $content_id = $db->escapeString($content->get Id());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'"; 602 535 $db->execSqlUpdate($sql, false); 603 536 } 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) 615 553 { 616 554 // Init values 617 555 $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!'); 620 561 } 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 } 630 564 631 565 return $retval; … … 644 578 //$this->__construct($this->_id); 645 579 } 580 581 646 582 647 583 /** Menu hook function */ -
trunk/wifidog-auth/wifidog/classes/Network.php
r1435 r1436 47 47 * Load required classes 48 48 */ 49 require_once('classes/GenericDataObject.php');50 49 require_once('classes/Content.php'); 51 50 require_once('classes/User.php'); 52 51 require_once('classes/Node.php'); 52 require_once('classes/NodeGroup.php'); 53 53 require_once('classes/GisPoint.php'); 54 54 require_once('classes/Cache.php'); … … 68 68 * @copyright 2006 Max Horváth, Horvath Web Consulting 69 69 */ 70 class Network extends GenericDataObject70 class Network extends HotspotGraphElement 71 71 { 72 72 /** Object cache for the object factory (getObject())*/ 73 private static $instanceArray = array();74 protected $_hotspotGraphElement;75 73 76 74 /** … … 88 86 public static function &getObject($id) 89 87 { 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'); 95 89 } 96 90 … … 101 95 public static function freeObject($id) 102 96 { 103 if(isset(self::$instanceArray[$id])) 104 { 105 unset(self::$instanceArray[$id]); 106 } 97 HotspotGraphElement::freeObject($id, 'Network'); 107 98 } 108 99 … … 192 183 public static function createNewObject($network_id = null) 193 184 { 185 194 186 $db = AbstractDb::getObject(); 195 187 if (empty ($network_id)) { … … 380 372 * @access private 381 373 */ 382 pr ivatefunction __construct($p_network_id)374 protected function __construct($p_network_id) 383 375 { 384 376 $db = AbstractDb::getObject(); … … 395 387 $this->_row = $row; 396 388 $this->_id = $p_network_id; 397 $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->_id,'Network');389 parent::__construct($this->_id, 'Network'); 398 390 } 399 391 … … 1706 1698 $data = Content::getLinkedContentUI($name, "network_has_content", "network_id", $this->_id, $display_page = "portal"); 1707 1699 $html .= InterfaceElements::generateAdminSectionContainer("network_content", $title, $data);*/ 1708 if (!is_null($this->_hotspotGraphElement))1709 $html .= $this->_hotspotGraphElement->getContentAdminUI();1700 1701 $html .= parent::getContentAdminUI(); 1710 1702 1711 1703 /* … … 1937 1929 1938 1930 // objects hierarchy 1939 if (!is_null($this->_hotspotGraphElement)) 1940 $html .= $this->_hotspotGraphElement->getGraphAdminUI($this); 1931 $html .= parent::getGraphAdminUI($this); 1941 1932 1942 1933 $html .= "</ul>\n"; … … 1958 1949 1959 1950 // Content management 1960 if (!is_null($this->_hotspotGraphElement)) 1961 $this->_hotspotGraphElement->processContentAdminUI(); 1951 parent::processContentAdminUI(); 1962 1952 /* $name = "network_".$this->_id."_content"; 1963 1953 Content :: processLinkedContentUI($name, 'network_has_content', 'network_id', $this->_id);*/ … … 2079 2069 ProfileTemplate :: processLinkedProfileTemplateUI($name, 'network_has_profile_templates', 'network_id', $this->_id); 2080 2070 2081 if (!is_null($this->_hotspotGraphElement)) 2082 $this->_hotspotGraphElement->processGraphAdminUI($errMsg, $this); 2071 parent::processGraphAdminUI($errMsg, $this); 2083 2072 if(!empty($errMsg)) { 2084 2073 echo $errMsg; … … 2103 2092 * @access public 2104 2093 */ 2105 public function addContent(Content $content)2094 /* public function addContent(Content $content) 2106 2095 { 2107 2096 $db = AbstractDb::getObject(); … … 2110 2099 $sql = "INSERT INTO network_has_content (network_id, content_id) VALUES ('$this->_id','$content_id')"; 2111 2100 $db->execSqlUpdate($sql, false); 2112 } 2101 }*/ 2113 2102 2114 2103 /** … … 2121 2110 * @access public 2122 2111 */ 2123 public function removeContent(Content $content)2112 /* public function removeContent(Content $content) 2124 2113 { 2125 2114 $db = AbstractDb::getObject(); … … 2128 2117 $sql = "DELETE FROM network_has_content WHERE network_id='$this->_id' AND content_id='$content_id'"; 2129 2118 $db->execSqlUpdate($sql, false); 2130 } 2119 }*/ 2131 2120 2132 2121 … … 2205 2194 $errmsg = _('Could not delete network!'); 2206 2195 } else { 2196 parent::_delete($errmsg); 2207 2197 $retval = true; 2208 2198 } … … 2274 2264 $smarty->assign('networkNumNonMonitoredNodes', $net ? $net->getNumOnlineNodes(true) : 0); 2275 2265 } 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 } 2276 2291 } 2277 2292 -
trunk/wifidog-auth/wifidog/classes/Node.php
r1435 r1436 62 62 * @copyright 2005 Benoit Grégoire, Technologies Coeus inc. 63 63 */ 64 class Node implements GenericObject64 class Node extends HotspotGraphElement 65 65 { 66 66 /** 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; 73 71 74 72 /** … … 78 76 * @access private 79 77 */ 80 pr ivate$_deploymentStatuses = array();78 protected $_deploymentStatuses = array(); 81 79 82 80 /** … … 87 85 * @access private 88 86 */ 89 pr ivate$_warningMessage;87 protected $_warningMessage; 90 88 91 89 /** Instantiate a node object … … 95 93 public static function &getObject($id) 96 94 { 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'); 102 96 } 103 97 … … 108 102 public static function freeObject($id) 109 103 { 110 if(isset(self::$instanceArray[$id])) 111 { 112 unset(self::$instanceArray[$id]); 113 } 104 HotspotGraphElement::freeObject($id, 'Node'); 114 105 } 115 106 … … 226 217 else 227 218 { 219 parent::_delete($errmsg); 228 220 $retval = true; 229 221 } … … 663 655 /** @param $id The id of the node 664 656 * @param $idType 'NODE_ID' or 'GATEWAY_ID'*/ 665 pr ivatefunction __construct($id, $idType='NODE_ID')657 protected function __construct($id, $idType='NODE_ID') 666 658 { 667 659 $db = AbstractDb::getObject(); … … 698 690 $this->id = $row['node_id']; 699 691 700 $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->id, 'Node');692 parent::__construct($this->id, 'Node'); 701 693 } 702 694 … … 1197 1189 $_data = Content::getLinkedContentUI("node_" . $node_id . "_content", "node_has_content", "node_id", $this->id, "portal"); 1198 1190 $html .= InterfaceElements::generateAdminSectionContainer("node_content", $_title, $_data);*/ 1199 if (!is_null($this->_hotspotGraphElement)) 1200 $html .= $this->_hotspotGraphElement->getContentAdminUI(); 1191 $html .= parent::getContentAdminUI(); 1201 1192 1202 1193 // Name … … 1372 1363 1373 1364 //Node hierarchy 1374 if (!is_null($this->_hotspotGraphElement)) 1375 $html .= $this->_hotspotGraphElement->getGraphAdminUI($network); 1365 $html .= parent::getGraphAdminUI($network); 1376 1366 1377 1367 $html .= "</ul>\n"; … … 1416 1406 } 1417 1407 // Content processing 1418 if (!is_null($this->_hotspotGraphElement)) 1419 $this->_hotspotGraphElement->processContentAdminUI(); 1408 parent::processContentAdminUI(); 1420 1409 /*$name = "node_{$node_id}_content"; 1421 1410 Content::processLinkedContentUI($name, 'node_has_content', 'node_id', $this->id);*/ … … 1581 1570 // End Node configuration section 1582 1571 1583 if (!is_null($this->_hotspotGraphElement)) 1584 $this->_hotspotGraphElement->processGraphAdminUI($errMsg, $network); 1572 parent::processGraphAdminUI($errMsg, $network); 1585 1573 if(!empty($errMsg)) { 1586 1574 echo $errMsg; … … 1602 1590 1603 1591 /** Add content to this node */ 1604 public function addContent(Content $content)1592 /* public function addContent(Content $content) 1605 1593 { 1606 1594 $db = AbstractDb::getObject(); … … 1609 1597 $db->execSqlUpdate($sql, false); 1610 1598 exit; 1611 } 1599 }*/ 1612 1600 1613 1601 /** Remove content from this node */ 1614 public function removeContent(Content $content)1602 /* public function removeContent(Content $content) 1615 1603 { 1616 1604 $db = AbstractDb::getObject(); … … 1618 1606 $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; 1619 1607 $db->execSqlUpdate($sql, false); 1620 } 1608 }*/ 1621 1609 1622 1610 /** … … 1832 1820 $smarty->assign('realNodeLastHeartbeatIP', $node ? $node->getLastHeartbeatIP() : ''); 1833 1821 } 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 1834 1848 } 1835 1849 -
trunk/wifidog-auth/wifidog/classes/NodeGroup.php
r1435 r1436 58 58 * @copyright 2005 Benoit Grégoire, Technologies Coeus inc. 59 59 */ 60 class NodeGroup implements GenericObject60 class NodeGroup extends HotspotGraphElement 61 61 { 62 62 /** 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; 68 66 69 67 /** … … 74 72 * @access private 75 73 */ 76 pr ivate$_warningMessage;74 protected $_warningMessage; 77 75 78 76 /** Instantiate a nodeGroup object … … 82 80 public static function &getObject($id) 83 81 { 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'); 89 83 } 90 84 … … 95 89 public static function freeObject($id) 96 90 { 97 if(isset(self::$instanceArray[$id])) 98 { 99 unset(self::$instanceArray[$id]); 100 } 91 HotspotGraphElement::freeObject($id, 'NodeGroup'); 101 92 } 102 93 … … 316 307 /** @param $id The id of the node group 317 308 * @param $idType 'GROUP_ID' or 'NAME'*/ 318 pr ivatefunction __construct($id, $idType='GROUP_ID')309 protected function __construct($id, $idType='GROUP_ID') 319 310 { 320 311 $db = AbstractDb::getObject(); … … 342 333 $this->id = $row['node_group_id']; 343 334 344 $this->_hotspotGraphElement = HotspotGraphElement::getObject($this->id, 'NodeGroup');335 parent::__construct($this->id, 'NodeGroup'); 345 336 } 346 337 … … 464 455 465 456 //Node content 466 if (!is_null($this->_hotspotGraphElement)) 467 $html .= $this->_hotspotGraphElement->getContentAdminUI(); 457 $html .= parent::getContentAdminUI(); 468 458 469 459 //Node hierarchy 470 if (!is_null($this->_hotspotGraphElement)) 471 $html .= $this->_hotspotGraphElement->getGraphAdminUI(); 460 $html .= parent::getGraphAdminUI(); 472 461 473 462 // Build section … … 515 504 516 505 // Content processing 517 if (!is_null($this->_hotspotGraphElement)) 518 $this->_hotspotGraphElement->processContentAdminUI(); 506 parent::processContentAdminUI(); 519 507 520 508 // Name … … 535 523 $this->setDescription($_REQUEST[$name]); 536 524 537 if (!is_null($this->_hotspotGraphElement)) 538 $this->_hotspotGraphElement->processGraphAdminUI($errMsg); 525 parent::processGraphAdminUI($errMsg); 539 526 if(!empty($errMsg)) { 540 527 echo $errMsg; … … 552 539 553 540 /** Add content to this node */ 554 public function addContent(Content $content)541 /* public function addContent(Content $content) 555 542 { 556 543 $db = AbstractDb::getObject(); … … 559 546 $db->execSqlUpdate($sql, false); 560 547 exit; 561 } 548 }*/ 562 549 563 550 /** Remove content from this node */ 564 public function removeContent(Content $content)551 /* public function removeContent(Content $content) 565 552 { 566 553 $db = AbstractDb::getObject(); … … 568 555 $sql = "DELETE FROM node_has_content WHERE node_id='$this->id' AND content_id='$content_id'"; 569 556 $db->execSqlUpdate($sql, false); 570 } 557 }*/ 571 558 572 559 … … 634 621 $smarty->assign('realNodeLastHeartbeatIP', $node ? $node->getLastHeartbeatIP() : ''); 635 622 } 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 } 636 648 } 637 649 -
trunk/wifidog-auth/wifidog/portal/index.php
r1435 r1436 167 167 168 168 // Get all the parent objects of the node 169 $parents = HotspotGraph::getAllParents( HotspotGraphElement::getObjectFor($node));169 $parents = HotspotGraph::getAllParents($node); 170 170 171 171 // Get the contents for all elements parents of and including the node, but exclude user subscribed content if user is known
