[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 // Template for creating base node class on tree table. 4 // 5 // $Id: Node.tpl,v 1.6 2005/04/04 10:48:33 dlawson_mi Exp $ 6 7 8 require_once 'propel/engine/builder/om/ClassTools.php'; 9 10 $db = $table->getDatabase(); 11 if($table->getPackage()) { 12 $package = $table->getPackage(); 13 } else { 14 $package = $targetPackage; 15 } 16 17 echo '<' . '?' . 'php'; 18 19 ?> 20 21 22 require_once '<?php echo ClassTools::getFilePath($package, $table->getPhpName() . 'NodePeer') ?>'; 23 24 /** 25 * Base tree node class for manipulating a tree of <?php echo $table->getPhpName() ?> objects. 26 * This class will wrap these objects within a "node" interface. It provides a 27 * method overload mechanism which allows you to use a <?php echo $table->getPhpName() ?>Node 28 * object just like a <?php $table->getPhpName() ?> object. 29 * 30 * To avoid tree corruption, you should always use this class to make changes to 31 * the tree and objects within it rather than using the <?php echo $table->getPhpName() ?> 32 * class directly. 33 * 34 <?php if (isset($addTimeStamp)) { ?> 35 * This class was autogenerated by Propel on: 36 * 37 * [<?php echo $now ?>] 38 * 39 <?php } ?> 40 * @package <?php echo $package ?> 41 * 42 */ 43 class <?php echo $basePrefix . $table->getPhpName() ?>Node implements IteratorAggregate 44 { 45 /** 46 * @var <?php echo $table->getPhpName() ?> Object wrapped by this node. 47 */ 48 protected $obj = null; 49 50 /** 51 * The parent node for this node. 52 * @var <?php echo $table->getPhpName() ?>Node 53 */ 54 protected $parentNode = null; 55 56 /** 57 * Array of child nodes for this node. Nodes indexes are one-based. 58 * @var array 59 */ 60 protected $childNodes = array(); 61 62 /** 63 * Constructor. 64 * 65 * @param <?php echo $table->getPhpName() ?> Object wrapped by this node. 66 */ 67 public function __construct($obj = null) 68 { 69 if ($obj !== null) 70 { 71 $this->obj = $obj; 72 } 73 else 74 { 75 $setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME; 76 $this->obj = new <?php echo $table->getPhpName() ?>(); 77 $this->obj->$setNodePath('0'); 78 } 79 } 80 81 /** 82 * Convenience overload for wrapped object methods. 83 * 84 * @param string Method name to call on wrapped object. 85 * @param mixed Parameter accepted by wrapped object set method. 86 * @return mixed Return value of wrapped object method. 87 * @throws PropelException Fails if method is not defined for wrapped object. 88 */ 89 public function __call($name, $parms) 90 { 91 if (method_exists($this->obj, $name)) 92 return call_user_func_array(array($this->obj, $name), $parms); 93 else 94 throw new PropelException("get method not defined: $name"); 95 } 96 97 /** 98 * Sets the default options for iterators created from this object. 99 * The options are specified in map format. The following options 100 * are supported by all iterators. Some iterators may support other 101 * options: 102 * 103 * "querydb" - True if nodes should be retrieved from database. 104 * "con" - Connection to use if retrieving from database. 105 * 106 * @param string Type of iterator to use ("pre", "post", "level"). 107 * @param array Map of option name => value. 108 * @return void 109 * @todo Implement other iterator types (i.e. post-order, level, etc.) 110 */ 111 public function setIteratorOptions($type, $opts) 112 { 113 $this->itType = $type; 114 $this->itOpts = $opts; 115 } 116 117 /** 118 * Returns a pre-order iterator for this node and its children. 119 * 120 * @param string Type of iterator to use ("pre", "post", "level") 121 * @param array Map of option name => value. 122 * @return NodeIterator 123 */ 124 public function getIterator($type = null, $opts = null) 125 { 126 if ($type === null) 127 $type = (isset($this->itType) ? $this->itType : 'Pre'); 128 129 if ($opts === null) 130 $opts = (isset($this->itOpts) ? $this->itOpts : array()); 131 132 $itclass = ucfirst(strtolower($type)) . 'OrderNodeIterator'; 133 134 require_once('propel/om/' . $itclass . '.php'); 135 return new $itclass($this, $opts); 136 } 137 138 /** 139 * Returns the object wrapped by this class. 140 * @return <?php echo $table->getPhpName() . "\n" ?> 141 */ 142 public function getNodeObj() 143 { 144 return $this->obj; 145 } 146 147 /** 148 * Convenience method for retrieving nodepath. 149 * @return string 150 */ 151 public function getNodePath() 152 { 153 $getNodePath = 'get' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME; 154 return $this->obj->$getNodePath(); 155 } 156 157 /** 158 * Returns one-based node index among siblings. 159 * @return int 160 */ 161 public function getNodeIndex() 162 { 163 $npath =& $this->getNodePath(); 164 $sep = strrpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP); 165 return (int) ($sep !== false ? substr($npath, $sep+1) : $npath); 166 } 167 168 /** 169 * Returns one-based node level within tree (root node is level 1). 170 * @return int 171 */ 172 public function getNodeLevel() 173 { 174 return (substr_count($this->getNodePath(), <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP) + 1); 175 } 176 177 /** 178 * Returns true if specified node is a child of this node. If recurse is 179 * true, checks if specified node is a descendant of this node. 180 * 181 * @param <?php echo $table->getPhpName() ?>Node Node to look for. 182 * @param boolean True if strict comparison should be used. 183 * @param boolean True if all descendants should be checked. 184 * @return boolean 185 */ 186 public function hasChildNode($node, $strict = false, $recurse = false) 187 { 188 foreach ($this->childNodes as $childNode) 189 { 190 if ($childNode->equals($node, $strict)) 191 return true; 192 193 if ($recurse && $childNode->hasChildNode($node, $recurse)) 194 return true; 195 } 196 197 return false; 198 } 199 200 /** 201 * Returns child node at one-based index. Retrieves from database if not 202 * loaded yet. 203 * 204 * @param int One-based child node index. 205 * @param boolean True if child should be retrieved from database. 206 * @param Connection Connection to use if retrieving from database. 207 * @return <?php echo $table->getPhpName() ?>Node 208 */ 209 public function getChildNodeAt($i, $querydb = false, $con = null) 210 { 211 if ($querydb && 212 !$this->obj->isNew() && 213 !$this->obj->isDeleted() && 214 !isset($this->childNodes[$i])) 215 { 216 $criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 217 $criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i, Criteria::EQUAL); 218 219 if ($childObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con)) 220 $this->attachChildNode(new <?php echo $table->getPhpName() ?>Node($childObj)); 221 } 222 223 return (isset($this->childNodes[$i]) ? $this->childNodes[$i] : null); 224 } 225 226 /** 227 * Returns first child node (if any). Retrieves from database if not loaded yet. 228 * 229 * @param boolean True if child should be retrieved from database. 230 * @param Connection Connection to use if retrieving from database. 231 * @return <?php echo $table->getPhpName() ?>Node 232 */ 233 public function getFirstChildNode($querydb = false, $con = null) 234 { 235 return $this->getChildNodeAt(1, $querydb, $con); 236 } 237 238 /** 239 * Returns last child node (if any). 240 * 241 * @param boolean True if child should be retrieved from database. 242 * @param Connection Connection to use if retrieving from database. 243 */ 244 public function getLastChildNode($querydb = false, $con = null) 245 { 246 $lastNode = null; 247 248 if ($this->obj->isNew() || $this->obj->isDeleted()) 249 { 250 end($this->childNodes); 251 $lastNode = (count($this->childNodes) ? current($this->childNodes) : null); 252 } 253 else if ($querydb) 254 { 255 $db = Propel::getDb(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 256 $criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 257 $criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%', Criteria::LIKE); 258 $criteria->addAnd(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%' . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . '%', Criteria::NOT_LIKE); 259 $criteria->addAsColumn('npathlen', $db->strLength(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME)); 260 $criteria->addDescendingOrderByColumn('npathlen'); 261 $criteria->addDescendingOrderByColumn(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME); 262 263 $lastObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con); 264 265 if ($lastObj !== null) 266 { 267 $lastNode = new <?php echo $table->getPhpName() ?>Node($lastObj); 268 269 end($this->childNodes); 270 $endNode = (count($this->childNodes) ? current($this->childNodes) : null); 271 272 if ($endNode) 273 { 274 if ($endNode->getNodePath() > $lastNode->getNodePath()) 275 throw new PropelException('Cached child node inconsistent with database.'); 276 else if ($endNode->getNodePath() == $lastNode->getNodePath()) 277 $lastNode = $endNode; 278 else 279 $this->attachChildNode($lastNode); 280 } 281 else 282 { 283 $this->attachChildNode($lastNode); 284 } 285 } 286 } 287 288 return $lastNode; 289 } 290 291 /** 292 * Returns next (or previous) sibling node or null. Retrieves from database if 293 * not loaded yet. 294 * 295 * @param boolean True if previous sibling should be returned. 296 * @param boolean True if sibling should be retrieved from database. 297 * @param Connection Connection to use if retrieving from database. 298 * @return <?php echo $table->getPhpName() ?>Node 299 */ 300 public function getSiblingNode($prev = false, $querydb = false, $con = null) 301 { 302 $nidx = $this->getNodeIndex(); 303 304 if ($this->isRootNode()) 305 { 306 return null; 307 } 308 else if ($prev) 309 { 310 if ($nidx > 1 && ($parentNode = $this->getParentNode($querydb, $con))) 311 return $parentNode->getChildNodeAt($nidx-1, $querydb, $con); 312 else 313 return null; 314 } 315 else 316 { 317 if ($parentNode = $this->getParentNode($querydb, $con)) 318 return $parentNode->getChildNodeAt($nidx+1, $querydb, $con); 319 else 320 return null; 321 } 322 } 323 324 /** 325 * Returns parent node. Loads from database if not cached yet. 326 * 327 * @param boolean True if parent should be retrieved from database. 328 * @param Connection Connection to use if retrieving from database. 329 * @return <?php echo $table->getPhpName() ?>Node 330 */ 331 public function getParentNode($querydb = true, $con = null) 332 { 333 if ($querydb && 334 $this->parentNode === null && 335 !$this->isRootNode() && 336 !$this->obj->isNew() && 337 !$this->obj->isDeleted()) 338 { 339 $npath =& $this->getNodePath(); 340 $sep = strrpos($npath, <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP); 341 $ppath = substr($npath, 0, $sep); 342 343 $criteria = new Criteria(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 344 $criteria->add(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME, $ppath, Criteria::EQUAL); 345 346 if ($parentObj = <?php echo $table->getPhpName() ?>Peer::doSelectOne($criteria, $con)) 347 { 348 $parentNode = new <?php echo $table->getPhpName() ?>Node($parentObj); 349 $parentNode->attachChildNode($this); 350 } 351 } 352 353 return $this->parentNode; 354 } 355 356 /** 357 * Returns an array of all ancestor nodes, starting with the root node 358 * first. 359 * 360 * @param boolean True if ancestors should be retrieved from database. 361 * @param Connection Connection to use if retrieving from database. 362 * @return array 363 */ 364 public function getAncestors($querydb = false, $con = null) 365 { 366 $ancestors = array(); 367 $parentNode = $this; 368 369 while ($parentNode = $parentNode->getParentNode($querydb, $con)) 370 array_unshift($ancestors, $parentNode); 371 372 return $ancestors; 373 } 374 375 /** 376 * Returns true if node is the root node of the tree. 377 * @return boolean 378 */ 379 public function isRootNode() 380 { 381 return ($this->getNodePath() === '1'); 382 } 383 384 /** 385 * Changes the state of the object and its descendants to 'new'. 386 * Also changes the node path to '0' to indicate that it is not a 387 * stored node. 388 * 389 * @param boolean 390 * @return void 391 */ 392 public function setNew($b) 393 { 394 $this->adjustStatus('new', $b); 395 $this->adjustNodePath($this->getNodePath(), '0'); 396 } 397 398 /** 399 * Changes the state of the object and its descendants to 'deleted'. 400 * 401 * @param boolean 402 * @return void 403 */ 404 public function setDeleted($b) 405 { 406 $this->adjustStatus('deleted', $b); 407 } 408 409 /** 410 * Adds the specified node (and its children) as a child to this node. If a 411 * valid $beforeNode is specified, the node will be inserted in front of 412 * $beforeNode. If $beforeNode is not specified the node will be appended to 413 * the end of the child nodes. 414 * 415 * @param <?php echo $table->getPhpName() ?>Node Node to add. 416 * @param <?php echo $table->getPhpName() ?>Node Node to insert before. 417 * @param Connection Connection to use. 418 */ 419 public function addChildNode($node, $beforeNode = null, $con = null) 420 { 421 if ($this->obj->isNew() && !$node->obj->isNew()) 422 throw new PropelException('Cannot add stored nodes to a new node.'); 423 424 if ($this->obj->isDeleted() || $node->obj->isDeleted()) 425 throw new PropelException('Cannot add children in a deleted state.'); 426 427 if ($this->hasChildNode($node)) 428 throw new PropelException('Node is already a child of this node.'); 429 430 if ($beforeNode && !$this->hasChildNode($beforeNode)) 431 throw new PropelException('Invalid beforeNode.'); 432 433 if ($con === null) 434 $con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 435 436 try { 437 438 if (!$this->obj->isNew()) $con->begin(); 439 440 if ($beforeNode) 441 { 442 // Inserting before a node. 443 $childIdx = $beforeNode->getNodeIndex(); 444 $this->shiftChildNodes(1, $beforeNode->getNodeIndex(), $con); 445 } 446 else 447 { 448 // Appending child node. 449 if ($lastNode = $this->getLastChildNode(true, $con)) 450 $childIdx = $lastNode->getNodeIndex()+1; 451 else 452 $childIdx = 1; 453 } 454 455 // Add the child (and its children) at the specified index. 456 457 if (!$this->obj->isNew() && $node->obj->isNew()) 458 { 459 $this->insertNewChildNode($node, $childIdx, $con); 460 } 461 else 462 { 463 // $this->isNew() && $node->isNew() || 464 // !$this->isNew() && !node->isNew() 465 466 $srcPath = $node->getNodePath(); 467 $dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $childIdx; 468 469 if (!$node->obj->isNew()) 470 { 471 <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, $con); 472 $parentNode = $node->getParentNode(true, $con); 473 } 474 else 475 { 476 $parentNode = $node->getParentNode(); 477 } 478 479 if ($parentNode) 480 { 481 $parentNode->detachChildNode($node); 482 $parentNode->shiftChildNodes(-1, $node->getNodeIndex()+1, $con); 483 } 484 485 $node->adjustNodePath($srcPath, $dstPath); 486 } 487 488 if (!$this->obj->isNew()) $con->commit(); 489 490 $this->attachChildNode($node); 491 492 } catch (SQLException $e) { 493 if (!$this->obj->isNew()) $con->rollback(); 494 throw new PropelException($e); 495 } 496 } 497 498 /** 499 * Moves the specified child node in the specified direction. 500 * 501 * @param <?php $table->getPhpName() ?>Node Node to move. 502 * @param int Number of spaces to move among siblings (may be negative). 503 * @param Connection Connection to use. 504 * @throws PropelException 505 */ 506 public function moveChildNode($node, $direction, $con = null) 507 { 508 throw new PropelException('moveChildNode() not implemented yet.'); 509 } 510 511 /** 512 * Saves modified object data to the datastore. 513 * 514 * @param boolean If true, descendants will be saved as well. 515 * @param Connection Connection to use. 516 */ 517 public function save($recurse = false, $con = null) 518 { 519 if ($this->obj->isDeleted()) 520 throw new PropelException('Cannot save deleted node.'); 521 522 if (substr($this->getNodePath(), 0, 1) == '0') 523 throw new PropelException('Cannot save unattached node.'); 524 525 if ($this->obj->isColumnModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME)) 526 throw new PropelException('Cannot save manually modified node path.'); 527 528 $this->obj->save($con); 529 530 if ($recurse) 531 { 532 foreach ($this->childNodes as $childNode) 533 $childNode->save($recurse, $con); 534 } 535 } 536 537 /** 538 * Removes this object and all descendants from datastore. 539 * 540 * @param Connection Connection to use. 541 * @return void 542 * @throws PropelException 543 */ 544 public function delete($con = null) 545 { 546 if ($this->obj->isDeleted()) 547 throw new PropelException('This node has already been deleted.'); 548 549 if (!$this->obj->isNew()) 550 { 551 <?php echo $table->getPhpName() ?>NodePeer::deleteNodeSubTree($this->getNodePath(), $con); 552 } 553 554 if ($parentNode = $this->getParentNode(true, $con)) 555 { 556 $parentNode->detachChildNode($this); 557 $parentNode->shiftChildNodes(-1, $this->getNodeIndex()+1, $con); 558 } 559 560 $this->setDeleted(true); 561 } 562 563 /** 564 * Compares the object wrapped by this node with that of another node. Use 565 * this instead of equality operators to prevent recursive dependency 566 * errors. 567 * 568 * @param <?php echo $table->getPhpName() ?>Node Node to compare. 569 * @param boolean True if strict comparison should be used. 570 * @return boolean 571 */ 572 public function equals($node, $strict = false) 573 { 574 if ($strict) 575 return ($this->obj === $node->obj); 576 else 577 return ($this->obj == $node->obj); 578 } 579 580 /** 581 * This method is used internally when constructing the tree structure 582 * from the database. To set the parent of a node, you should call 583 * addChildNode() on the parent. 584 * 585 * @param <?php echo $table->getPhpName() ?>Node Parent node to attach. 586 * @return void 587 * @throws PropelException 588 */ 589 public function attachParentNode($node) 590 { 591 if (!$node->hasChildNode($this, true)) 592 throw new PropelException('Failed to attach parent node for non-child.'); 593 594 $this->parentNode = $node; 595 } 596 597 /** 598 * This method is used internally when constructing the tree structure 599 * from the database. To add a child to a node you should call the 600 * addChildNode() method instead. 601 * 602 * @param <?php echo $table->getPhpName() ?>Node Child node to attach. 603 * @return void 604 * @throws PropelException 605 */ 606 public function attachChildNode($node) 607 { 608 if ($this->hasChildNode($node)) 609 throw new PropelException('Failed to attach child node. Node already exists.'); 610 611 if ($this->obj->isDeleted() || $node->obj->isDeleted()) 612 throw new PropelException('Failed to attach node in deleted state.'); 613 614 if ($this->obj->isNew() && !$node->obj->isNew()) 615 throw new PropelException('Failed to attach non-new child to new node.'); 616 617 if (!$this->obj->isNew() && $node->obj->isNew()) 618 throw new PropelException('Failed to attach new child to non-new node.'); 619 620 if ($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $node->getNodeIndex() != $node->getNodePath()) 621 throw new PropelException('Failed to attach child node. Node path mismatch.'); 622 623 $this->childNodes[$node->getNodeIndex()] = $node; 624 ksort($this->childNodes); 625 626 $node->attachParentNode($this); 627 } 628 629 /** 630 * This method is used internally when deleting nodes. It is used to break 631 * the link to this node's parent. 632 * @param <?php echo $table->getPhpName() ?>Node Parent node to detach from. 633 * @return void 634 * @throws PropelException 635 */ 636 public function detachParentNode($node) 637 { 638 if (!$node->hasChildNode($this, true)) 639 throw new PropelException('Failed to detach parent node from non-child.'); 640 641 unset($node->childNodes[$this->getNodeIndex()]); 642 $this->parentNode = null; 643 } 644 645 /** 646 * This method is used internally when deleting nodes. It is used to break 647 * the link to this between this node and the specified child. 648 * @param <?php echo $table->getPhpName() ?>Node Child node to detach. 649 * @return void 650 * @throws PropelException 651 */ 652 public function detachChildNode($node) 653 { 654 if (!$this->hasChildNode($node, true)) 655 throw new PropelException('Failed to detach non-existent child node.'); 656 657 unset($this->childNodes[$node->getNodeIndex()]); 658 $node->parentNode = null; 659 } 660 661 /** 662 * Shifts child nodes in the specified direction and offset index. This 663 * method assumes that there is already space available in the 664 * direction/offset indicated. 665 * 666 * @param int Direction/# spaces to shift. 1=leftshift, 1=rightshift 667 * @param int Node index to start shift at. 668 * @param Connection The connection to be used. 669 * @return void 670 * @throws PropelException 671 */ 672 protected function shiftChildNodes($direction, $offsetIdx, $con) 673 { 674 if ($this->obj->isDeleted()) 675 throw new PropelException('Cannot shift nodes for deleted object'); 676 677 $lastNode = $this->getLastChildNode(true, $con); 678 $lastIdx = ($lastNode !== null ? $lastNode->getNodeIndex() : 0); 679 680 if ($lastNode === null || $offsetIdx > $lastIdx) 681 return; 682 683 if ($con === null) 684 $con = Propel::getConnection(<?php echo $table->getPhpName() ?>Peer::DATABASE_NAME); 685 686 if (!$this->obj->isNew()) 687 { 688 // Shift nodes in database. 689 690 try { 691 692 $con->begin(); 693 694 $n = $lastIdx - $offsetIdx + 1; 695 $i = $direction < 1 ? $offsetIdx : $lastIdx; 696 697 while ($n--) 698 { 699 $srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i; // 1.2.2 700 $dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . ($i+$direction); // 1.2.3 701 702 <?php echo $table->getPhpName() ?>NodePeer::moveNodeSubTree($srcPath, $dstPath, $con); 703 704 $i -= $direction; 705 } 706 707 $con->commit(); 708 709 } catch (SQLException $e) { 710 $con->rollback(); 711 throw new PropelException($e); 712 } 713 } 714 715 // Shift the in-memory objects. 716 717 $n = $lastIdx - $offsetIdx + 1; 718 $i = $direction < 1 ? $offsetIdx : $lastIdx; 719 720 while ($n--) 721 { 722 if (isset($this->childNodes[$i])) 723 { 724 $srcPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $i; // 1.2.2 725 $dstPath = $this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . ($i+$direction); // 1.2.3 726 727 $this->childNodes[$i+$direction] = $this->childNodes[$i]; 728 $this->childNodes[$i+$direction]->adjustNodePath($srcPath, $dstPath); 729 730 unset($this->childNodes[$i]); 731 } 732 733 $i -= $direction; 734 } 735 736 ksort($this->childNodes); 737 } 738 739 /** 740 * Inserts the node and its children at the specified childIdx. 741 * 742 * @param <?php echo $table->getPhpName() ?>Node Node to insert. 743 * @param int One-based child index to insert at. 744 * @param Connection Connection to use. 745 * @param void 746 */ 747 protected function insertNewChildNode($node, $childIdx, $con) 748 { 749 if (!$node->obj->isNew()) 750 throw new PropelException('Failed to insert non-new node.'); 751 752 $setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME; 753 754 $node->obj->$setNodePath($this->getNodePath() . <?php echo $table->getPhpName() ?>NodePeer::NPATH_SEP . $childIdx); 755 $node->obj->save($con); 756 757 $i = 1; 758 foreach ($node->childNodes as $childNode) 759 $node->insertNewChildNode($childNode, $i++, $con); 760 } 761 762 /** 763 * Adjust new/deleted status of node and all children. 764 * 765 * @param string Status to change ('New' or 'Deleted') 766 * @param boolean Value for status. 767 * @return void 768 */ 769 protected function adjustStatus($status, $b) 770 { 771 $setStatus = 'set' . $status; 772 773 $this->obj->$setStatus($b); 774 775 foreach ($this->childNodes as $childNode) 776 $childNode->obj->$setStatus($b); 777 } 778 779 /** 780 * Adjust path of node and all children. This is used internally when 781 * inserting/moving nodes. 782 * 783 * @param string Section of old path to change. 784 * @param string New section to replace old path with. 785 * @return void 786 */ 787 protected function adjustNodePath($oldBasePath, $newBasePath) 788 { 789 $setNodePath = "set" . <?php echo $table->getPhpName() ?>NodePeer::NPATH_PHPNAME; 790 791 $this->obj->$setNodePath($newBasePath . 792 substr($this->getNodePath(), strlen($oldBasePath))); 793 $this->obj->resetModified(<?php echo $table->getPhpName() ?>NodePeer::NPATH_COLNAME); 794 795 foreach ($this->childNodes as $childNode) 796 $childNode->adjustNodePath($oldBasePath, $newBasePath); 797 } 798 799 } 800 801 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |