Changeset 136 for trunk/lib/Hierarchy.inc.php
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Hierarchy.inc.php
r111 r136 2 2 /** 3 3 * Hierarchy.inc.php 4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information 5 */ 6 7 /** 4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information 5 * 8 6 * Objective: This class provides the tools to organize pieces of data into a 9 7 * hierarchy of nodes. Any form of data (article, product, image) can be … … 97 95 function toStringID($child_type=null, $child_id=null) 98 96 { 99 if (!isset($child_type) || !isset($child_id)) { 100 if ($this->node_init) { 101 $child_type =& $this->child_type; 102 $child_id =& $this->child_id; 103 } else { 104 App::logMsg(_("toStringID failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 97 $app =& App::getInstance(); 98 99 if (!isset($child_type) || !isset($child_id)) { 100 if ($this->node_init) { 101 $child_type =& $this->child_type; 102 $child_id =& $this->child_id; 103 } else { 104 $app->logMsg(_("toStringID failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 105 105 return false; 106 106 } … … 129 129 function toArrayID(&$node) 130 130 { 131 if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) { 131 $app =& App::getInstance(); 132 133 if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) { 132 134 return array('node_type' => $node_parts[1], 'node_id' => $node_parts[2]); 133 135 } else { 134 App::logMsg(_("Cannot parse node identifier, not formated correctly."), LOG_ERR, __FILE__, __LINE__);136 $app->logMsg(_("Cannot parse node identifier, not formated correctly."), LOG_ERR, __FILE__, __LINE__); 135 137 return false; 136 138 } … … 147 149 function insertNode($parents, $child_type=null, $child_id=null, $relationship_type=null, $title='') 148 150 { 151 $app =& App::getInstance(); 152 $db =& DB::getInstance(); 153 149 154 if (!isset($child_type) || !isset($child_id)) { 150 155 if ($this->node_init) { … … 152 157 $child_id =& $this->child_id; 153 158 } else { 154 App::logMsg(_("insertNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);159 $app->logMsg(_("insertNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 155 160 return false; 156 161 } … … 159 164 // Make sure this is not empty and an array, even if it has only one value. 160 165 if ('' == $parents) { 161 App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);162 App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);166 $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__); 167 $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__); 163 168 return false; 164 169 } else if (!is_array($parents)) { … … 174 179 $parent = $this->toArrayID($parent_string); 175 180 if ($this->nodeExists($child_type, $child_id, $parent['node_type'], $parent['node_id'], $relationship_type)) { 176 App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);177 App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);181 $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__); 182 $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__); 178 183 return false; 179 184 } 180 185 if (!$this->nodeExists($parent['node_type'], $parent['node_id'])) { 181 App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);182 App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);186 $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__); 187 $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__); 183 188 return false; 184 189 } … … 188 193 foreach ($parents as $parent_string) { 189 194 $parent = $this->toArrayID($parent_string); 190 DB::query("195 $db->query(" 191 196 INSERT INTO node_tbl ( 192 197 parent_type, … … 197 202 title 198 203 ) VALUES ( 199 '" . DB::escapeString($parent['node_type']) . "',200 '" . DB::escapeString($parent['node_id']) . "',201 '" . DB::escapeString($child_type) . "',202 '" . DB::escapeString($child_id) . "',203 " . (is_null($relationship_type) ? "NULL" : "'" . DB::escapeString($relationship_type) . "'") . ",204 '" . DB::escapeString($title) . "'204 '" . $db->escapeString($parent['node_type']) . "', 205 '" . $db->escapeString($parent['node_id']) . "', 206 '" . $db->escapeString($child_type) . "', 207 '" . $db->escapeString($child_id) . "', 208 " . (is_null($relationship_type) ? "NULL" : "'" . $db->escapeString($relationship_type) . "'") . ", 209 '" . $db->escapeString($title) . "' 205 210 ) 206 211 "); 207 App::logMsg(sprintf('insertNode: Added node %s %s with parent %s %s.', $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_DEBUG, __FILE__, __LINE__);212 $app->logMsg(sprintf('insertNode: Added node %s %s with parent %s %s.', $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_DEBUG, __FILE__, __LINE__); 208 213 } 209 214 return true; … … 223 228 function deleteNode($child_type=null, $child_id=null) 224 229 { 230 $app =& App::getInstance(); 231 $db =& DB::getInstance(); 232 225 233 if (!isset($child_type) || !isset($child_id)) { 226 234 if ($this->node_init) { … … 228 236 $child_id =& $this->child_id; 229 237 } else { 230 App::logMsg(_("deleteNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);238 $app->logMsg(_("deleteNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 231 239 return false; 232 240 } … … 243 251 } 244 252 245 DB::query("253 $db->query(" 246 254 DELETE FROM node_tbl 247 WHERE child_type = '" . DB::escapeString($child_type) . "'248 AND child_id = '" . DB::escapeString($child_id) . "'255 WHERE child_type = '" . $db->escapeString($child_type) . "' 256 AND child_id = '" . $db->escapeString($child_id) . "' 249 257 "); 250 App::logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);258 $app->logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__); 251 259 252 260 return true; … … 270 278 function moveNode($new_parents=null, $child_type=null, $child_id=null, $relationship_type=null, $title='') 271 279 { 272 if (!isset($child_type) || !isset($child_id)) { 273 if ($this->node_init) { 274 $child_type =& $this->child_type; 275 $child_id =& $this->child_id; 276 } else { 277 App::logMsg(_("moveNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 280 $app =& App::getInstance(); 281 $db =& DB::getInstance(); 282 283 if (!isset($child_type) || !isset($child_id)) { 284 if ($this->node_init) { 285 $child_type =& $this->child_type; 286 $child_id =& $this->child_id; 287 } else { 288 $app->logMsg(_("moveNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 278 289 return false; 279 290 } … … 282 293 // Make sure this is not empty and an array, even if it has only one value. 283 294 if (empty($new_parents)) { 284 App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);285 App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);295 $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__); 296 $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__); 286 297 return false; 287 298 } else if (!is_array($new_parents)) { … … 296 307 $parent = $this->toArrayID($parent_string); 297 308 if (!$this->nodeExists($parent['node_type'], $parent['node_id'])) { 298 App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);299 App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);309 $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__); 310 $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__); 300 311 return false; 301 312 } 302 313 if ($this->isAncestor($child_type, $child_id, $parent['node_type'], $parent['node_id'])) { 303 App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);304 App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);314 $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__); 315 $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__); 305 316 return false; 306 317 } … … 309 320 if (empty($title)) { 310 321 // Select the title of the node we are moving, so we can add it again with the same info. 311 $qid = DB::query("322 $qid = $db->query(" 312 323 SELECT title FROM node_tbl 313 WHERE child_type = '" . DB::escapeString($child_type) . "'314 AND child_id = '" . DB::escapeString($child_id) . "'315 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "324 WHERE child_type = '" . $db->escapeString($child_type) . "' 325 AND child_id = '" . $db->escapeString($child_id) . "' 326 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . " 316 327 "); 317 328 list($title) = mysql_fetch_row($qid); … … 319 330 320 331 // Delete the nodes with the old parents. 321 DB::query("332 $db->query(" 322 333 DELETE FROM node_tbl 323 WHERE child_type = '" . DB::escapeString($child_type) . "'324 AND child_id = '" . DB::escapeString($child_id) . "'325 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "334 WHERE child_type = '" . $db->escapeString($child_type) . "' 335 AND child_id = '" . $db->escapeString($child_id) . "' 336 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . " 326 337 "); 327 App::logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);338 $app->logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__); 328 339 329 340 // Insert new nodes with the new parents. … … 344 355 function getParents($child_type=null, $child_id=null, $type_constraint=null, $order='') 345 356 { 357 $app =& App::getInstance(); 358 $db =& DB::getInstance(); 359 346 360 if (!isset($child_type) || !isset($child_id)) { 347 361 if ($this->node_init) { … … 349 363 $child_id =& $this->child_id; 350 364 } else { 351 App::logMsg(_("getParents failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);365 $app->logMsg(_("getParents failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 352 366 return false; 353 367 } … … 359 373 $type_constraint = array($type_constraint); 360 374 } 361 $in_clause = "AND parent_type IN ('" . join("','", array_map(array( 'DB', 'escapeString'), $type_constraint)) . "')";362 } 363 364 $qid = DB::query("375 $in_clause = "AND parent_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')"; 376 } 377 378 $qid = $db->query(" 365 379 SELECT parent_type, parent_id 366 380 FROM node_tbl 367 WHERE child_type = '" . DB::escapeString($child_type) . "'368 AND child_id = '" . DB::escapeString($child_id) . "'381 WHERE child_type = '" . $db->escapeString($child_type) . "' 382 AND child_id = '" . $db->escapeString($child_id) . "' 369 383 $in_clause 370 " . DB::escapeString($order) . "384 " . $db->escapeString($order) . " 371 385 "); 372 386 … … 392 406 function getNode($child_type=null, $child_id=null) 393 407 { 408 $app =& App::getInstance(); 409 $db =& DB::getInstance(); 410 394 411 if (!isset($child_type) || !isset($child_id)) { 395 412 if ($this->node_init) { … … 397 414 $child_id =& $this->child_id; 398 415 } else { 399 App::logMsg(_("getNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);400 return false; 401 } 402 } 403 404 $qid = DB::query("416 $app->logMsg(_("getNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 417 return false; 418 } 419 } 420 421 $qid = $db->query(" 405 422 SELECT child_type, child_id, title, subnode_quantity 406 423 FROM node_tbl 407 WHERE child_type = '" . DB::escapeString($child_type) . "'408 AND child_id = '" . DB::escapeString($child_id) . "'424 WHERE child_type = '" . $db->escapeString($child_type) . "' 425 AND child_id = '" . $db->escapeString($child_id) . "' 409 426 "); 410 427 … … 433 450 function getChildren($child_type=null, $child_id=null, $type_constraint=null, $order='') 434 451 { 452 $app =& App::getInstance(); 453 $db =& DB::getInstance(); 454 435 455 if (!isset($child_type) || !isset($child_id)) { 436 456 if ($this->node_init) { … … 438 458 $child_id =& $this->child_id; 439 459 } else { 440 App::logMsg(_("getChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);460 $app->logMsg(_("getChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 441 461 return false; 442 462 } … … 448 468 $type_constraint = array($type_constraint); 449 469 } 450 $in_clause = "AND child_type IN ('" . join("','", array_map(array( 'DB', 'escapeString'), $type_constraint)) . "')";451 } 452 453 $qid = DB::query("470 $in_clause = "AND child_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')"; 471 } 472 473 $qid = $db->query(" 454 474 SELECT * 455 475 FROM node_tbl 456 WHERE parent_type = '" . DB::escapeString($child_type) . "'457 AND parent_id = '" . DB::escapeString($child_id) . "'476 WHERE parent_type = '" . $db->escapeString($child_type) . "' 477 AND parent_id = '" . $db->escapeString($child_id) . "' 458 478 $in_clause 459 " . DB::escapeString($order) . "479 " . $db->escapeString($order) . " 460 480 "); 461 481 … … 482 502 function getNumberChildren($child_type=null, $child_id=null, $type_constraint=null) 483 503 { 504 $app =& App::getInstance(); 505 $db =& DB::getInstance(); 506 484 507 if (!isset($child_type) || !isset($child_id)) { 485 508 if ($this->node_init) { … … 487 510 $child_id =& $this->child_id; 488 511 } else { 489 App::logMsg(_("getNumberChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);512 $app->logMsg(_("getNumberChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 490 513 return false; 491 514 } … … 497 520 $type_constraint = array($type_constraint); 498 521 } 499 $in_clause = "AND child_type IN ('" . join("','", array_map(array( 'DB', 'escapeString'), $type_constraint)) . "')";500 } 501 502 $qid = DB::query("522 $in_clause = "AND child_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')"; 523 } 524 525 $qid = $db->query(" 503 526 SELECT COUNT(*) 504 527 FROM node_tbl 505 WHERE parent_type = '" . DB::escapeString($child_type) . "'506 AND parent_id = '" . DB::escapeString($child_id) . "'528 WHERE parent_type = '" . $db->escapeString($child_type) . "' 529 AND parent_id = '" . $db->escapeString($child_id) . "' 507 530 $in_clause 508 531 "); … … 520 543 function isLeaf($child_type=null, $child_id=null) 521 544 { 545 $app =& App::getInstance(); 546 522 547 if (!isset($child_type) || !isset($child_id)) { 523 548 if ($this->node_init) { … … 525 550 $child_id =& $this->child_id; 526 551 } else { 527 App::logMsg(_("isLeaf failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);552 $app->logMsg(_("isLeaf failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 528 553 return false; 529 554 } … … 579 604 function getAllAncestors($child_type, $child_id, $go_linear=false, $_return_flag=true) 580 605 { 606 $db =& DB::getInstance(); 607 581 608 static $output = array(); 582 609 static $return_flag; 583 610 584 $qid = DB::query("611 $qid = $db->query(" 585 612 SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity 586 613 FROM node_tbl 587 WHERE child_type = '" . DB::escapeString($child_type) . "'588 AND child_id = '" . DB::escapeString($child_id) . "'614 WHERE child_type = '" . $db->escapeString($child_type) . "' 615 AND child_id = '" . $db->escapeString($child_id) . "' 589 616 "); 590 617 while ($row = mysql_fetch_assoc($qid)) { … … 631 658 function nodeExists($child_type=null, $child_id=null, $parent_type=null, $parent_id=null, $relationship_type=null) 632 659 { 660 $app =& App::getInstance(); 661 $db =& DB::getInstance(); 662 633 663 if (!isset($child_type) || !isset($child_id)) { 634 664 if ($this->node_init) { … … 636 666 $child_id =& $this->child_id; 637 667 } else { 638 App::logMsg(_("nodeExists failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);668 $app->logMsg(_("nodeExists failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 639 669 return false; 640 670 } … … 642 672 643 673 if (isset($parent_type) && isset($parent_id)) { 644 $qid = DB::query("674 $qid = $db->query(" 645 675 SELECT 1 FROM node_tbl 646 WHERE parent_type = '" . DB::escapeString($parent_type) . "'647 AND parent_id = '" . DB::escapeString($parent_id) . "'648 AND child_type = '" . DB::escapeString($child_type) . "'649 AND child_id = '" . DB::escapeString($child_id) . "'650 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "676 WHERE parent_type = '" . $db->escapeString($parent_type) . "' 677 AND parent_id = '" . $db->escapeString($parent_id) . "' 678 AND child_type = '" . $db->escapeString($child_type) . "' 679 AND child_id = '" . $db->escapeString($child_id) . "' 680 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . " 651 681 "); 652 682 } else { 653 $qid = DB::query("683 $qid = $db->query(" 654 684 SELECT 1 FROM node_tbl 655 WHERE child_type = '" . DB::escapeString($child_type) . "'656 AND child_id = '" . DB::escapeString($child_id) . "'685 WHERE child_type = '" . $db->escapeString($child_type) . "' 686 AND child_id = '" . $db->escapeString($child_id) . "' 657 687 "); 658 688 } … … 680 710 function &getNodeList($preselected=null, $child_type=null, $child_id=null, $type_constraint=null, $include_curr=false, $order='', $_indent=0, $_return_flag=true) 681 711 { 712 $app =& App::getInstance(); 713 682 714 static $output = array(); 683 715 static $is_a_leaf = array(); … … 688 720 $child_id =& $this->child_id; 689 721 } else { 690 App::logMsg(_("getNodeList failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);722 $app->logMsg(_("getNodeList failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__); 691 723 return false; 692 724 } … … 709 741 // Preventing circular references. 710 742 if ($my_children[$i]['child_type'] == $child_type && $my_children[$i]['child_id'] == $child_id && !($_return_flag && $include_curr)) { 711 App::logMsg(sprintf(_("Circular reference detected: %s has itself as a parent."), $this->toStringID($my_children[$i]['child_type'], $my_children[$i]['child_id'])), LOG_ERR, __FILE__, __LINE__);743 $app->logMsg(sprintf(_("Circular reference detected: %s has itself as a parent."), $this->toStringID($my_children[$i]['child_type'], $my_children[$i]['child_id'])), LOG_ERR, __FILE__, __LINE__); 712 744 continue; 713 745 } … … 751 783 function rebuildSubnodeQty($type_constraint=null) 752 784 { 785 $db =& DB::getInstance(); 786 753 787 // Reset all the category counters to zero. 754 DB::query("UPDATE node_tbl SET subnode_quantity = 0");788 $db->query("UPDATE node_tbl SET subnode_quantity = 0"); 755 789 756 790 // Get all the nodes. 757 $qid = DB::query("SELECT DISTINCT child_type, child_id FROM node_tbl");791 $qid = $db->query("SELECT DISTINCT child_type, child_id FROM node_tbl"); 758 792 759 793 // For each node count the number of children... … … 773 807 function setSubnodeQtyToParents($child_type, $child_id, $num_children) 774 808 { 775 DB::query(" 809 $db =& DB::getInstance(); 810 811 $db->query(" 776 812 UPDATE node_tbl 777 SET subnode_quantity = subnode_quantity + '" . DB::escapeString($num_children) . "'778 WHERE child_type = '" . DB::escapeString($child_type) . "'779 AND child_id = '" . DB::escapeString($child_id) . "'813 SET subnode_quantity = subnode_quantity + '" . $db->escapeString($num_children) . "' 814 WHERE child_type = '" . $db->escapeString($child_type) . "' 815 AND child_id = '" . $db->escapeString($child_id) . "' 780 816 ",false); 781 $qid = DB::query("817 $qid = $db->query(" 782 818 SELECT parent_type, parent_id 783 819 FROM node_tbl 784 WHERE child_type = '" . DB::escapeString($child_type) . "'785 AND child_id = '" . DB::escapeString($child_id) . "'820 WHERE child_type = '" . $db->escapeString($child_type) . "' 821 AND child_id = '" . $db->escapeString($child_id) . "' 786 822 ",false); 787 823 while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
Note: See TracChangeset
for help on using the changeset viewer.