PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/generator/lib/behavior/nestedset/NestedSetBehaviorObjectBuilderModifier.php

https://github.com/1989gaurav/Propel
PHP | 1591 lines | 1025 code | 122 blank | 444 comment | 115 complexity | 994927bbe12844d2ba63a130c937e388 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * Behavior to adds nested set tree structure columns and abilities
  11. *
  12. * @author François Zaninotto
  13. * @author heltem <heltem@o2php.com>
  14. * @package propel.generator.behavior.nestedset
  15. */
  16. class NestedSetBehaviorObjectBuilderModifier
  17. {
  18. protected $behavior, $table, $builder, $objectClassname, $peerClassname;
  19. public function __construct($behavior)
  20. {
  21. $this->behavior = $behavior;
  22. $this->table = $behavior->getTable();
  23. }
  24. protected function getParameter($key)
  25. {
  26. return $this->behavior->getParameter($key);
  27. }
  28. protected function getColumnAttribute($name)
  29. {
  30. return strtolower($this->behavior->getColumnForParameter($name)->getName());
  31. }
  32. protected function getColumnPhpName($name)
  33. {
  34. return $this->behavior->getColumnForParameter($name)->getPhpName();
  35. }
  36. protected function setBuilder($builder)
  37. {
  38. $this->builder = $builder;
  39. $this->objectClassname = $builder->getStubObjectBuilder()->getClassname();
  40. $this->queryClassname = $builder->getStubQueryBuilder()->getClassname();
  41. $this->peerClassname = $builder->getStubPeerBuilder()->getClassname();
  42. }
  43. /*
  44. public function objectFilter(&$script, $builder)
  45. {
  46. $script = str_replace('implements Persistent', 'implements Persistent, NodeObject', $script);
  47. }
  48. */
  49. public function objectAttributes($builder)
  50. {
  51. $objectClassname = $builder->getStubObjectBuilder()->getClassname();
  52. return "
  53. /**
  54. * Queries to be executed in the save transaction
  55. * @var array
  56. */
  57. protected \$nestedSetQueries = array();
  58. /**
  59. * Internal cache for children nodes
  60. * @var null|PropelObjectCollection
  61. */
  62. protected \$collNestedSetChildren = null;
  63. /**
  64. * Internal cache for parent node
  65. * @var null|$objectClassname
  66. */
  67. protected \$aNestedSetParent = null;
  68. ";
  69. }
  70. public function preSave($builder)
  71. {
  72. $peerClassname = $builder->getStubPeerBuilder()->getClassname();
  73. $queryClassname = $builder->getStubQueryBuilder()->getClassname();
  74. $script = "if (\$this->isNew() && \$this->isRoot()) {
  75. // check if no other root exist in, the tree
  76. \$nbRoots = $queryClassname::create()
  77. ->addUsingAlias($peerClassname::LEFT_COL, 1, Criteria::EQUAL)";
  78. if ($this->behavior->useScope()) {
  79. $script .= "
  80. ->addUsingAlias($peerClassname::SCOPE_COL, \$this->getScopeValue(), Criteria::EQUAL)";
  81. }
  82. $script .= "
  83. ->count(\$con);
  84. if (\$nbRoots > 0) {
  85. throw new PropelException(";
  86. if ($this->behavior->useScope()) {
  87. $script .= "sprintf('A root node already exists in this tree with scope \"%s\".', \$this->getScopeValue())";
  88. } else {
  89. $script .= "'A root node already exists in this tree. To allow multiple root nodes, add the `use_scope` parameter in the nested_set behavior tag.'";
  90. }
  91. $script .= ");
  92. }
  93. }
  94. \$this->processNestedSetQueries(\$con);";
  95. return $script;
  96. }
  97. public function preDelete($builder)
  98. {
  99. $peerClassname = $builder->getStubPeerBuilder()->getClassname();
  100. return "if (\$this->isRoot()) {
  101. throw new PropelException('Deletion of a root node is disabled for nested sets. Use $peerClassname::deleteTree(" . ($this->behavior->useScope() ? '$scope' : '') . ") instead to delete an entire tree');
  102. }
  103. if (\$this->isInTree()) {
  104. \$this->deleteDescendants(\$con);
  105. }
  106. ";
  107. }
  108. public function postDelete($builder)
  109. {
  110. $peerClassname = $builder->getStubPeerBuilder()->getClassname();
  111. return "if (\$this->isInTree()) {
  112. // fill up the room that was used by the node
  113. $peerClassname::shiftRLValues(-2, \$this->getRightValue() + 1, null" . ($this->behavior->useScope() ? ", \$this->getScopeValue()" : "") . ", \$con);
  114. }
  115. ";
  116. }
  117. public function objectClearReferences($builder)
  118. {
  119. return "\$this->collNestedSetChildren = null;
  120. \$this->aNestedSetParent = null;";
  121. }
  122. public function objectMethods($builder)
  123. {
  124. $this->setBuilder($builder);
  125. $script = '';
  126. $this->addProcessNestedSetQueries($script);
  127. if ($this->getColumnPhpName('left_column') != 'LeftValue') {
  128. $this->addGetLeft($script);
  129. }
  130. if ($this->getColumnPhpName('right_column') != 'RightValue') {
  131. $this->addGetRight($script);
  132. }
  133. if ($this->getColumnPhpName('level_column') != 'Level') {
  134. $this->addGetLevel($script);
  135. }
  136. if ($this->getParameter('use_scope') == 'true'
  137. && $this->getColumnPhpName('scope_column') != 'ScopeValue') {
  138. $this->addGetScope($script);
  139. }
  140. if ($this->getColumnPhpName('left_column') != 'LeftValue') {
  141. $this->addSetLeft($script);
  142. }
  143. if ($this->getColumnPhpName('right_column') != 'RightValue') {
  144. $this->addSetRight($script);
  145. }
  146. if ($this->getColumnPhpName('level_column') != 'Level') {
  147. $this->addSetLevel($script);
  148. }
  149. if ($this->getParameter('use_scope') == 'true'
  150. && $this->getColumnPhpName('scope_column') != 'ScopeValue') {
  151. $this->addSetScope($script);
  152. }
  153. $this->addMakeRoot($script);
  154. $this->addIsInTree($script);
  155. $this->addIsRoot($script);
  156. $this->addIsLeaf($script);
  157. $this->addIsDescendantOf($script);
  158. $this->addIsAncestorOf($script);
  159. $this->addHasParent($script);
  160. $this->addSetParent($script);
  161. $this->addGetParent($script);
  162. $this->addHasPrevSibling($script);
  163. $this->addGetPrevSibling($script);
  164. $this->addHasNextSibling($script);
  165. $this->addGetNextSibling($script);
  166. $this->addNestedSetChildrenClear($script);
  167. $this->addNestedSetChildrenInit($script);
  168. $this->addNestedSetChildAdd($script);
  169. $this->addHasChildren($script);
  170. $this->addGetChildren($script);
  171. $this->addCountChildren($script);
  172. $this->addGetFirstChild($script);
  173. $this->addGetLastChild($script);
  174. $this->addGetSiblings($script);
  175. $this->addGetDescendants($script);
  176. $this->addCountDescendants($script);
  177. $this->addGetBranch($script);
  178. $this->addGetAncestors($script);
  179. $this->addAddChild($script);
  180. $this->addInsertAsFirstChildOf($script);
  181. $this->addInsertAsLastChildOf($script);
  182. $this->addInsertAsPrevSiblingOf($script);
  183. $this->addInsertAsNextSiblingOf($script);
  184. $this->addMoveToFirstChildOf($script);
  185. $this->addMoveToLastChildOf($script);
  186. $this->addMoveToPrevSiblingOf($script);
  187. $this->addMoveToNextSiblingOf($script);
  188. $this->addMoveSubtreeTo($script);
  189. $this->addDeleteDescendants($script);
  190. $this->addGetIterator($script);
  191. if ($this->getParameter('method_proxies') == 'true')
  192. {
  193. $this->addCompatibilityProxies($script);
  194. }
  195. return $script;
  196. }
  197. protected function addProcessNestedSetQueries(&$script)
  198. {
  199. $script .= "
  200. /**
  201. * Execute queries that were saved to be run inside the save transaction
  202. */
  203. protected function processNestedSetQueries(\$con)
  204. {
  205. foreach (\$this->nestedSetQueries as \$query) {
  206. \$query['arguments'][]= \$con;
  207. call_user_func_array(\$query['callable'], \$query['arguments']);
  208. }
  209. \$this->nestedSetQueries = array();
  210. }
  211. ";
  212. }
  213. protected function addGetLeft(&$script)
  214. {
  215. $script .= "
  216. /**
  217. * Proxy getter method for the left value of the nested set model.
  218. * It provides a generic way to get the value, whatever the actual column name is.
  219. *
  220. * @return int The nested set left value
  221. */
  222. public function getLeftValue()
  223. {
  224. return \$this->{$this->getColumnAttribute('left_column')};
  225. }
  226. ";
  227. }
  228. protected function addGetRight(&$script)
  229. {
  230. $script .= "
  231. /**
  232. * Proxy getter method for the right value of the nested set model.
  233. * It provides a generic way to get the value, whatever the actual column name is.
  234. *
  235. * @return int The nested set right value
  236. */
  237. public function getRightValue()
  238. {
  239. return \$this->{$this->getColumnAttribute('right_column')};
  240. }
  241. ";
  242. }
  243. protected function addGetLevel(&$script)
  244. {
  245. $script .= "
  246. /**
  247. * Proxy getter method for the level value of the nested set model.
  248. * It provides a generic way to get the value, whatever the actual column name is.
  249. *
  250. * @return int The nested set level value
  251. */
  252. public function getLevel()
  253. {
  254. return \$this->{$this->getColumnAttribute('level_column')};
  255. }
  256. ";
  257. }
  258. protected function addGetScope(&$script)
  259. {
  260. $script .= "
  261. /**
  262. * Proxy getter method for the scope value of the nested set model.
  263. * It provides a generic way to get the value, whatever the actual column name is.
  264. *
  265. * @return int The nested set scope value
  266. */
  267. public function getScopeValue()
  268. {
  269. return \$this->{$this->getColumnAttribute('scope_column')};
  270. }
  271. ";
  272. }
  273. protected function addSetLeft(&$script)
  274. {
  275. $script .= "
  276. /**
  277. * Proxy setter method for the left value of the nested set model.
  278. * It provides a generic way to set the value, whatever the actual column name is.
  279. *
  280. * @param int \$v The nested set left value
  281. * @return {$this->objectClassname} The current object (for fluent API support)
  282. */
  283. public function setLeftValue(\$v)
  284. {
  285. return \$this->set{$this->getColumnPhpName('left_column')}(\$v);
  286. }
  287. ";
  288. }
  289. protected function addSetRight(&$script)
  290. {
  291. $script .= "
  292. /**
  293. * Proxy setter method for the right value of the nested set model.
  294. * It provides a generic way to set the value, whatever the actual column name is.
  295. *
  296. * @param int \$v The nested set right value
  297. * @return {$this->objectClassname} The current object (for fluent API support)
  298. */
  299. public function setRightValue(\$v)
  300. {
  301. return \$this->set{$this->getColumnPhpName('right_column')}(\$v);
  302. }
  303. ";
  304. }
  305. protected function addSetLevel(&$script)
  306. {
  307. $script .= "
  308. /**
  309. * Proxy setter method for the level value of the nested set model.
  310. * It provides a generic way to set the value, whatever the actual column name is.
  311. *
  312. * @param int \$v The nested set level value
  313. * @return {$this->objectClassname} The current object (for fluent API support)
  314. */
  315. public function setLevel(\$v)
  316. {
  317. return \$this->set{$this->getColumnPhpName('level_column')}(\$v);
  318. }
  319. ";
  320. }
  321. protected function addSetScope(&$script)
  322. {
  323. $script .= "
  324. /**
  325. * Proxy setter method for the scope value of the nested set model.
  326. * It provides a generic way to set the value, whatever the actual column name is.
  327. *
  328. * @param int \$v The nested set scope value
  329. * @return {$this->objectClassname} The current object (for fluent API support)
  330. */
  331. public function setScopeValue(\$v)
  332. {
  333. return \$this->set{$this->getColumnPhpName('scope_column')}(\$v);
  334. }
  335. ";
  336. }
  337. protected function addMakeRoot(&$script)
  338. {
  339. $script .= "
  340. /**
  341. * Creates the supplied node as the root node.
  342. *
  343. * @return {$this->objectClassname} The current object (for fluent API support)
  344. * @throws PropelException
  345. */
  346. public function makeRoot()
  347. {
  348. if (\$this->getLeftValue() || \$this->getRightValue()) {
  349. throw new PropelException('Cannot turn an existing node into a root node.');
  350. }
  351. \$this->setLeftValue(1);
  352. \$this->setRightValue(2);
  353. \$this->setLevel(0);
  354. return \$this;
  355. }
  356. ";
  357. }
  358. protected function addIsInTree(&$script)
  359. {
  360. $script .= "
  361. /**
  362. * Tests if onbject is a node, i.e. if it is inserted in the tree
  363. *
  364. * @return bool
  365. */
  366. public function isInTree()
  367. {
  368. return \$this->getLeftValue() > 0 && \$this->getRightValue() > \$this->getLeftValue();
  369. }
  370. ";
  371. }
  372. protected function addIsRoot(&$script)
  373. {
  374. $script .= "
  375. /**
  376. * Tests if node is a root
  377. *
  378. * @return bool
  379. */
  380. public function isRoot()
  381. {
  382. return \$this->isInTree() && \$this->getLeftValue() == 1;
  383. }
  384. ";
  385. }
  386. protected function addIsLeaf(&$script)
  387. {
  388. $script .= "
  389. /**
  390. * Tests if node is a leaf
  391. *
  392. * @return bool
  393. */
  394. public function isLeaf()
  395. {
  396. return \$this->isInTree() && (\$this->getRightValue() - \$this->getLeftValue()) == 1;
  397. }
  398. ";
  399. }
  400. protected function addIsDescendantOf(&$script)
  401. {
  402. $objectClassname = $this->objectClassname;
  403. $script .= "
  404. /**
  405. * Tests if node is a descendant of another node
  406. *
  407. * @param $objectClassname \$node Propel node object
  408. * @return bool
  409. */
  410. public function isDescendantOf(\$parent)
  411. {";
  412. if ($this->behavior->useScope()) {
  413. $script .= "
  414. if (\$this->getScopeValue() !== \$parent->getScopeValue()) {
  415. throw new PropelException('Comparing two nodes of different trees');
  416. }";
  417. }
  418. $script .= "
  419. return \$this->isInTree() && \$this->getLeftValue() > \$parent->getLeftValue() && \$this->getRightValue() < \$parent->getRightValue();
  420. }
  421. ";
  422. }
  423. protected function addIsAncestorOf(&$script)
  424. {
  425. $objectClassname = $this->objectClassname;
  426. $script .= "
  427. /**
  428. * Tests if node is a ancestor of another node
  429. *
  430. * @param $objectClassname \$node Propel node object
  431. * @return bool
  432. */
  433. public function isAncestorOf(\$child)
  434. {
  435. return \$child->isDescendantOf(\$this);
  436. }
  437. ";
  438. }
  439. protected function addHasParent(&$script)
  440. {
  441. $script .= "
  442. /**
  443. * Tests if object has an ancestor
  444. *
  445. * @param PropelPDO \$con Connection to use.
  446. * @return bool
  447. */
  448. public function hasParent(PropelPDO \$con = null)
  449. {
  450. return \$this->getLevel() > 0;
  451. }
  452. ";
  453. }
  454. protected function addSetParent(&$script)
  455. {
  456. $objectClassname = $this->objectClassname;
  457. $script .= "
  458. /**
  459. * Sets the cache for parent node of the current object.
  460. * Warning: this does not move the current object in the tree.
  461. * Use moveTofirstChildOf() or moveToLastChildOf() for that purpose
  462. *
  463. * @param $objectClassname \$parent
  464. * @return $objectClassname The current object, for fluid interface
  465. */
  466. public function setParent(\$parent = null)
  467. {
  468. \$this->aNestedSetParent = \$parent;
  469. return \$this;
  470. }
  471. ";
  472. }
  473. protected function addGetParent(&$script)
  474. {
  475. $script .= "
  476. /**
  477. * Gets parent node for the current object if it exists
  478. * The result is cached so further calls to the same method don't issue any queries
  479. *
  480. * @param PropelPDO \$con Connection to use.
  481. * @return mixed Propel object if exists else false
  482. */
  483. public function getParent(PropelPDO \$con = null)
  484. {
  485. if (\$this->aNestedSetParent === null && \$this->hasParent()) {
  486. \$this->aNestedSetParent = {$this->queryClassname}::create()
  487. ->ancestorsOf(\$this)
  488. ->orderByLevel(true)
  489. ->findOne(\$con);
  490. }
  491. return \$this->aNestedSetParent;
  492. }
  493. ";
  494. }
  495. protected function addHasPrevSibling(&$script)
  496. {
  497. $peerClassname = $this->peerClassname;
  498. $queryClassname = $this->queryClassname;
  499. $script .= "
  500. /**
  501. * Determines if the node has previous sibling
  502. *
  503. * @param PropelPDO \$con Connection to use.
  504. * @return bool
  505. */
  506. public function hasPrevSibling(PropelPDO \$con = null)
  507. {
  508. if (!{$this->peerClassname}::isValid(\$this)) {
  509. return false;
  510. }
  511. return $queryClassname::create()
  512. ->filterBy" . $this->getColumnPhpName('right_column') . "(\$this->getLeftValue() - 1)";
  513. if ($this->behavior->useScope()) {
  514. $script .= "
  515. ->inTree(\$this->getScopeValue())";
  516. }
  517. $script .= "
  518. ->count(\$con) > 0;
  519. }
  520. ";
  521. }
  522. protected function addGetPrevSibling(&$script)
  523. {
  524. $queryClassname = $this->queryClassname;
  525. $script .= "
  526. /**
  527. * Gets previous sibling for the given node if it exists
  528. *
  529. * @param PropelPDO \$con Connection to use.
  530. * @return mixed Propel object if exists else false
  531. */
  532. public function getPrevSibling(PropelPDO \$con = null)
  533. {
  534. return $queryClassname::create()
  535. ->filterBy" . $this->getColumnPhpName('right_column') . "(\$this->getLeftValue() - 1)";
  536. if ($this->behavior->useScope()) {
  537. $script .= "
  538. ->inTree(\$this->getScopeValue())";
  539. }
  540. $script .= "
  541. ->findOne(\$con);
  542. }
  543. ";
  544. }
  545. protected function addHasNextSibling(&$script)
  546. {
  547. $peerClassname = $this->peerClassname;
  548. $queryClassname = $this->queryClassname;
  549. $script .= "
  550. /**
  551. * Determines if the node has next sibling
  552. *
  553. * @param PropelPDO \$con Connection to use.
  554. * @return bool
  555. */
  556. public function hasNextSibling(PropelPDO \$con = null)
  557. {
  558. if (!{$this->peerClassname}::isValid(\$this)) {
  559. return false;
  560. }
  561. return $queryClassname::create()
  562. ->filterBy" . $this->getColumnPhpName('left_column') . "(\$this->getRightValue() + 1)";
  563. if ($this->behavior->useScope()) {
  564. $script .= "
  565. ->inTree(\$this->getScopeValue())";
  566. }
  567. $script .= "
  568. ->count(\$con) > 0;
  569. }
  570. ";
  571. }
  572. protected function addGetNextSibling(&$script)
  573. {
  574. $queryClassname = $this->queryClassname;
  575. $script .= "
  576. /**
  577. * Gets next sibling for the given node if it exists
  578. *
  579. * @param PropelPDO \$con Connection to use.
  580. * @return mixed Propel object if exists else false
  581. */
  582. public function getNextSibling(PropelPDO \$con = null)
  583. {
  584. return $queryClassname::create()
  585. ->filterBy" . $this->getColumnPhpName('left_column') . "(\$this->getRightValue() + 1)";
  586. if ($this->behavior->useScope()) {
  587. $script .= "
  588. ->inTree(\$this->getScopeValue())";
  589. }
  590. $script .= "
  591. ->findOne(\$con);
  592. }
  593. ";
  594. }
  595. protected function addNestedSetChildrenClear(&$script)
  596. {
  597. $script .= "
  598. /**
  599. * Clears out the \$collNestedSetChildren collection
  600. *
  601. * This does not modify the database; however, it will remove any associated objects, causing
  602. * them to be refetched by subsequent calls to accessor method.
  603. *
  604. * @return void
  605. */
  606. public function clearNestedSetChildren()
  607. {
  608. \$this->collNestedSetChildren = null;
  609. }
  610. ";
  611. }
  612. protected function addNestedSetChildrenInit(&$script)
  613. {
  614. $script .= "
  615. /**
  616. * Initializes the \$collNestedSetChildren collection.
  617. *
  618. * @return void
  619. */
  620. public function initNestedSetChildren()
  621. {
  622. \$this->collNestedSetChildren = new PropelObjectCollection();
  623. \$this->collNestedSetChildren->setModel('" . $this->builder->getNewStubObjectBuilder($this->table)->getClassname() . "');
  624. }
  625. ";
  626. }
  627. protected function addNestedSetChildAdd(&$script)
  628. {
  629. $objectClassname = $this->objectClassname;
  630. $objectName = '$' . $this->table->getStudlyPhpName();
  631. $script .= "
  632. /**
  633. * Adds an element to the internal \$collNestedSetChildren collection.
  634. * Beware that this doesn't insert a node in the tree.
  635. * This method is only used to facilitate children hydration.
  636. *
  637. * @param $objectClassname $objectName
  638. *
  639. * @return void
  640. */
  641. public function addNestedSetChild($objectName)
  642. {
  643. if (\$this->collNestedSetChildren === null) {
  644. \$this->initNestedSetChildren();
  645. }
  646. if (!\$this->collNestedSetChildren->contains($objectName)) { // only add it if the **same** object is not already associated
  647. \$this->collNestedSetChildren[]= $objectName;
  648. {$objectName}->setParent(\$this);
  649. }
  650. }
  651. ";
  652. }
  653. protected function addHasChildren(&$script)
  654. {
  655. $script .= "
  656. /**
  657. * Tests if node has children
  658. *
  659. * @return bool
  660. */
  661. public function hasChildren()
  662. {
  663. return (\$this->getRightValue() - \$this->getLeftValue()) > 1;
  664. }
  665. ";
  666. }
  667. protected function addGetChildren(&$script)
  668. {
  669. $objectClassname = $this->objectClassname;
  670. $queryClassname = $this->queryClassname;
  671. $script .= "
  672. /**
  673. * Gets the children of the given node
  674. *
  675. * @param Criteria \$criteria Criteria to filter results.
  676. * @param PropelPDO \$con Connection to use.
  677. * @return array List of $objectClassname objects
  678. */
  679. public function getChildren(\$criteria = null, PropelPDO \$con = null)
  680. {
  681. if(null === \$this->collNestedSetChildren || null !== \$criteria) {
  682. if (\$this->isLeaf() || (\$this->isNew() && null === \$this->collNestedSetChildren)) {
  683. // return empty collection
  684. \$this->initNestedSetChildren();
  685. } else {
  686. \$collNestedSetChildren = $queryClassname::create(null, \$criteria)
  687. ->childrenOf(\$this)
  688. ->orderByBranch()
  689. ->find(\$con);
  690. if (null !== \$criteria) {
  691. return \$collNestedSetChildren;
  692. }
  693. \$this->collNestedSetChildren = \$collNestedSetChildren;
  694. }
  695. }
  696. return \$this->collNestedSetChildren;
  697. }
  698. ";
  699. }
  700. protected function addCountChildren(&$script)
  701. {
  702. $objectClassname = $this->objectClassname;
  703. $queryClassname = $this->queryClassname;
  704. $script .= "
  705. /**
  706. * Gets number of children for the given node
  707. *
  708. * @param Criteria \$criteria Criteria to filter results.
  709. * @param PropelPDO \$con Connection to use.
  710. * @return int Number of children
  711. */
  712. public function countChildren(\$criteria = null, PropelPDO \$con = null)
  713. {
  714. if(null === \$this->collNestedSetChildren || null !== \$criteria) {
  715. if (\$this->isLeaf() || (\$this->isNew() && null === \$this->collNestedSetChildren)) {
  716. return 0;
  717. } else {
  718. return $queryClassname::create(null, \$criteria)
  719. ->childrenOf(\$this)
  720. ->count(\$con);
  721. }
  722. } else {
  723. return count(\$this->collNestedSetChildren);
  724. }
  725. }
  726. ";
  727. }
  728. protected function addGetFirstChild(&$script)
  729. {
  730. $objectClassname = $this->objectClassname;
  731. $queryClassname = $this->queryClassname;
  732. $script .= "
  733. /**
  734. * Gets the first child of the given node
  735. *
  736. * @param Criteria \$query Criteria to filter results.
  737. * @param PropelPDO \$con Connection to use.
  738. * @return array List of $objectClassname objects
  739. */
  740. public function getFirstChild(\$query = null, PropelPDO \$con = null)
  741. {
  742. if(\$this->isLeaf()) {
  743. return array();
  744. } else {
  745. return $queryClassname::create(null, \$query)
  746. ->childrenOf(\$this)
  747. ->orderByBranch()
  748. ->findOne(\$con);
  749. }
  750. }
  751. ";
  752. }
  753. protected function addGetLastChild(&$script)
  754. {
  755. $objectClassname = $this->objectClassname;
  756. $queryClassname = $this->queryClassname;
  757. $script .= "
  758. /**
  759. * Gets the last child of the given node
  760. *
  761. * @param Criteria \$query Criteria to filter results.
  762. * @param PropelPDO \$con Connection to use.
  763. * @return array List of $objectClassname objects
  764. */
  765. public function getLastChild(\$query = null, PropelPDO \$con = null)
  766. {
  767. if(\$this->isLeaf()) {
  768. return array();
  769. } else {
  770. return $queryClassname::create(null, \$query)
  771. ->childrenOf(\$this)
  772. ->orderByBranch(true)
  773. ->findOne(\$con);
  774. }
  775. }
  776. ";
  777. }
  778. protected function addGetSiblings(&$script)
  779. {
  780. $objectClassname = $this->objectClassname;
  781. $queryClassname = $this->queryClassname;
  782. $script .= "
  783. /**
  784. * Gets the siblings of the given node
  785. *
  786. * @param bool \$includeNode Whether to include the current node or not
  787. * @param Criteria \$query Criteria to filter results.
  788. * @param PropelPDO \$con Connection to use.
  789. *
  790. * @return array List of $objectClassname objects
  791. */
  792. public function getSiblings(\$includeNode = false, \$query = null, PropelPDO \$con = null)
  793. {
  794. if(\$this->isRoot()) {
  795. return array();
  796. } else {
  797. \$query = $queryClassname::create(null, \$query)
  798. ->childrenOf(\$this->getParent(\$con))
  799. ->orderByBranch();
  800. if (!\$includeNode) {
  801. \$query->prune(\$this);
  802. }
  803. return \$query->find(\$con);
  804. }
  805. }
  806. ";
  807. }
  808. protected function addGetDescendants(&$script)
  809. {
  810. $objectClassname = $this->objectClassname;
  811. $queryClassname = $this->queryClassname;
  812. $script .= "
  813. /**
  814. * Gets descendants for the given node
  815. *
  816. * @param Criteria \$query Criteria to filter results.
  817. * @param PropelPDO \$con Connection to use.
  818. * @return array List of $objectClassname objects
  819. */
  820. public function getDescendants(\$query = null, PropelPDO \$con = null)
  821. {
  822. if(\$this->isLeaf()) {
  823. return array();
  824. } else {
  825. return $queryClassname::create(null, \$query)
  826. ->descendantsOf(\$this)
  827. ->orderByBranch()
  828. ->find(\$con);
  829. }
  830. }
  831. ";
  832. }
  833. protected function addCountDescendants(&$script)
  834. {
  835. $objectClassname = $this->objectClassname;
  836. $queryClassname = $this->queryClassname;
  837. $script .= "
  838. /**
  839. * Gets number of descendants for the given node
  840. *
  841. * @param Criteria \$query Criteria to filter results.
  842. * @param PropelPDO \$con Connection to use.
  843. * @return int Number of descendants
  844. */
  845. public function countDescendants(\$query = null, PropelPDO \$con = null)
  846. {
  847. if(\$this->isLeaf()) {
  848. // save one query
  849. return 0;
  850. } else {
  851. return $queryClassname::create(null, \$query)
  852. ->descendantsOf(\$this)
  853. ->count(\$con);
  854. }
  855. }
  856. ";
  857. }
  858. protected function addGetBranch(&$script)
  859. {
  860. $objectClassname = $this->objectClassname;
  861. $queryClassname = $this->queryClassname;
  862. $script .= "
  863. /**
  864. * Gets descendants for the given node, plus the current node
  865. *
  866. * @param Criteria \$query Criteria to filter results.
  867. * @param PropelPDO \$con Connection to use.
  868. * @return array List of $objectClassname objects
  869. */
  870. public function getBranch(\$query = null, PropelPDO \$con = null)
  871. {
  872. return $queryClassname::create(null, \$query)
  873. ->branchOf(\$this)
  874. ->orderByBranch()
  875. ->find(\$con);
  876. }
  877. ";
  878. }
  879. protected function addGetAncestors(&$script)
  880. {
  881. $objectClassname = $this->objectClassname;
  882. $queryClassname = $this->queryClassname;
  883. $script .= "
  884. /**
  885. * Gets ancestors for the given node, starting with the root node
  886. * Use it for breadcrumb paths for instance
  887. *
  888. * @param Criteria \$query Criteria to filter results.
  889. * @param PropelPDO \$con Connection to use.
  890. * @return array List of $objectClassname objects
  891. */
  892. public function getAncestors(\$query = null, PropelPDO \$con = null)
  893. {
  894. if(\$this->isRoot()) {
  895. // save one query
  896. return array();
  897. } else {
  898. return $queryClassname::create(null, \$query)
  899. ->ancestorsOf(\$this)
  900. ->orderByBranch()
  901. ->find(\$con);
  902. }
  903. }
  904. ";
  905. }
  906. protected function addAddChild(&$script)
  907. {
  908. $objectClassname = $this->objectClassname;
  909. $useScope = $this->behavior->useScope();
  910. $script .= "
  911. /**
  912. * Inserts the given \$child node as first child of current
  913. * The modifications in the current object and the tree
  914. * are not persisted until the child object is saved.
  915. *
  916. * @param $objectClassname \$child Propel object for child node
  917. *
  918. * @return $objectClassname The current Propel object
  919. */
  920. public function addChild($objectClassname \$child)
  921. {
  922. if (\$this->isNew()) {
  923. throw new PropelException('A $objectClassname object must not be new to accept children.');
  924. }
  925. \$child->insertAsFirstChildOf(\$this);
  926. return \$this;
  927. }
  928. ";
  929. }
  930. protected function getPeerClassNameWithNamespace()
  931. {
  932. $peerClassname = $this->peerClassname;
  933. if ($namespace = $this->builder->getStubPeerBuilder()->getNamespace()) {
  934. $peerClassname = '\\\\' . $namespace . '\\\\' . $peerClassname;
  935. }
  936. return $peerClassname;
  937. }
  938. protected function addInsertAsFirstChildOf(&$script)
  939. {
  940. $objectClassname = $this->objectClassname;
  941. $peerClassname = $this->getPeerClassNameWithNamespace();
  942. $useScope = $this->behavior->useScope();
  943. $script .= "
  944. /**
  945. * Inserts the current node as first child of given \$parent node
  946. * The modifications in the current object and the tree
  947. * are not persisted until the current object is saved.
  948. *
  949. * @param $objectClassname \$parent Propel object for parent node
  950. *
  951. * @return $objectClassname The current Propel object
  952. */
  953. public function insertAsFirstChildOf(\$parent)
  954. {
  955. if (\$this->isInTree()) {
  956. throw new PropelException('A $objectClassname object must not already be in the tree to be inserted. Use the moveToFirstChildOf() instead.');
  957. }
  958. \$left = \$parent->getLeftValue() + 1;
  959. // Update node properties
  960. \$this->setLeftValue(\$left);
  961. \$this->setRightValue(\$left + 1);
  962. \$this->setLevel(\$parent->getLevel() + 1);";
  963. if ($useScope)
  964. {
  965. $script .= "
  966. \$scope = \$parent->getScopeValue();
  967. \$this->setScopeValue(\$scope);";
  968. }
  969. $script .= "
  970. // update the children collection of the parent
  971. \$parent->addNestedSetChild(\$this);
  972. // Keep the tree modification query for the save() transaction
  973. \$this->nestedSetQueries []= array(
  974. 'callable' => array('$peerClassname', 'makeRoomForLeaf'),
  975. 'arguments' => array(\$left" . ($useScope ? ", \$scope" : "") . ", \$this->isNew() ? null : \$this)
  976. );
  977. return \$this;
  978. }
  979. ";
  980. }
  981. protected function addInsertAsLastChildOf(&$script)
  982. {
  983. $objectClassname = $this->objectClassname;
  984. $peerClassname = $this->getPeerClassNameWithNamespace();
  985. $useScope = $this->behavior->useScope();
  986. $script .= "
  987. /**
  988. * Inserts the current node as last child of given \$parent node
  989. * The modifications in the current object and the tree
  990. * are not persisted until the current object is saved.
  991. *
  992. * @param $objectClassname \$parent Propel object for parent node
  993. *
  994. * @return $objectClassname The current Propel object
  995. */
  996. public function insertAsLastChildOf(\$parent)
  997. {
  998. if (\$this->isInTree()) {
  999. throw new PropelException('A $objectClassname object must not already be in the tree to be inserted. Use the moveToLastChildOf() instead.');
  1000. }
  1001. \$left = \$parent->getRightValue();
  1002. // Update node properties
  1003. \$this->setLeftValue(\$left);
  1004. \$this->setRightValue(\$left + 1);
  1005. \$this->setLevel(\$parent->getLevel() + 1);";
  1006. if ($useScope)
  1007. {
  1008. $script .= "
  1009. \$scope = \$parent->getScopeValue();
  1010. \$this->setScopeValue(\$scope);";
  1011. }
  1012. $script .= "
  1013. // update the children collection of the parent
  1014. \$parent->addNestedSetChild(\$this);
  1015. // Keep the tree modification query for the save() transaction
  1016. \$this->nestedSetQueries []= array(
  1017. 'callable' => array('$peerClassname', 'makeRoomForLeaf'),
  1018. 'arguments' => array(\$left" . ($useScope ? ", \$scope" : "") . ", \$this->isNew() ? null : \$this)
  1019. );
  1020. return \$this;
  1021. }
  1022. ";
  1023. }
  1024. protected function addInsertAsPrevSiblingOf(&$script)
  1025. {
  1026. $objectClassname = $this->objectClassname;
  1027. $peerClassname = $this->getPeerClassNameWithNamespace();
  1028. $useScope = $this->behavior->useScope();
  1029. $script .= "
  1030. /**
  1031. * Inserts the current node as prev sibling given \$sibling node
  1032. * The modifications in the current object and the tree
  1033. * are not persisted until the current object is saved.
  1034. *
  1035. * @param $objectClassname \$sibling Propel object for parent node
  1036. *
  1037. * @return $objectClassname The current Propel object
  1038. */
  1039. public function insertAsPrevSiblingOf(\$sibling)
  1040. {
  1041. if (\$this->isInTree()) {
  1042. throw new PropelException('A $objectClassname object must not already be in the tree to be inserted. Use the moveToPrevSiblingOf() instead.');
  1043. }
  1044. \$left = \$sibling->getLeftValue();
  1045. // Update node properties
  1046. \$this->setLeftValue(\$left);
  1047. \$this->setRightValue(\$left + 1);
  1048. \$this->setLevel(\$sibling->getLevel());";
  1049. if ($useScope)
  1050. {
  1051. $script .= "
  1052. \$scope = \$sibling->getScopeValue();
  1053. \$this->setScopeValue(\$scope);";
  1054. }
  1055. $script .= "
  1056. // Keep the tree modification query for the save() transaction
  1057. \$this->nestedSetQueries []= array(
  1058. 'callable' => array('$peerClassname', 'makeRoomForLeaf'),
  1059. 'arguments' => array(\$left" . ($useScope ? ", \$scope" : "") . ", \$this->isNew() ? null : \$this)
  1060. );
  1061. return \$this;
  1062. }
  1063. ";
  1064. }
  1065. protected function addInsertAsNextSiblingOf(&$script)
  1066. {
  1067. $objectClassname = $this->objectClassname;
  1068. $peerClassname = $this->getPeerClassNameWithNamespace();
  1069. $useScope = $this->behavior->useScope();
  1070. $script .= "
  1071. /**
  1072. * Inserts the current node as next sibling given \$sibling node
  1073. * The modifications in the current object and the tree
  1074. * are not persisted until the current object is saved.
  1075. *
  1076. * @param $objectClassname \$sibling Propel object for parent node
  1077. *
  1078. * @return $objectClassname The current Propel object
  1079. */
  1080. public function insertAsNextSiblingOf(\$sibling)
  1081. {
  1082. if (\$this->isInTree()) {
  1083. throw new PropelException('A $objectClassname object must not already be in the tree to be inserted. Use the moveToNextSiblingOf() instead.');
  1084. }
  1085. \$left = \$sibling->getRightValue() + 1;
  1086. // Update node properties
  1087. \$this->setLeftValue(\$left);
  1088. \$this->setRightValue(\$left + 1);
  1089. \$this->setLevel(\$sibling->getLevel());";
  1090. if ($useScope)
  1091. {
  1092. $script .= "
  1093. \$scope = \$sibling->getScopeValue();
  1094. \$this->setScopeValue(\$scope);";
  1095. }
  1096. $script .= "
  1097. // Keep the tree modification query for the save() transaction
  1098. \$this->nestedSetQueries []= array(
  1099. 'callable' => array('$peerClassname', 'makeRoomForLeaf'),
  1100. 'arguments' => array(\$left" . ($useScope ? ", \$scope" : "") . ", \$this->isNew() ? null : \$this)
  1101. );
  1102. return \$this;
  1103. }
  1104. ";
  1105. }
  1106. protected function addMoveToFirstChildOf(&$script)
  1107. {
  1108. $objectClassname = $this->objectClassname;
  1109. $script .= "
  1110. /**
  1111. * Moves current node and its subtree to be the first child of \$parent
  1112. * The modifications in the current object and the tree are immediate
  1113. *
  1114. * @param $objectClassname \$parent Propel object for parent node
  1115. * @param PropelPDO \$con Connection to use.
  1116. *
  1117. * @return $objectClassname The current Propel object
  1118. */
  1119. public function moveToFirstChildOf(\$parent, PropelPDO \$con = null)
  1120. {
  1121. if (!\$this->isInTree()) {
  1122. throw new PropelException('A $objectClassname object must be already in the tree to be moved. Use the insertAsFirstChildOf() instead.');
  1123. }";
  1124. if ($this->behavior->useScope()) {
  1125. $script .= "
  1126. if (\$parent->getScopeValue() != \$this->getScopeValue()) {
  1127. throw new PropelException('Moving nodes across trees is not supported');
  1128. }";
  1129. }
  1130. $script .= "
  1131. if (\$parent->isDescendantOf(\$this)) {
  1132. throw new PropelException('Cannot move a node as child of one of its subtree nodes.');
  1133. }
  1134. \$this->moveSubtreeTo(\$parent->getLeftValue() + 1, \$parent->getLevel() - \$this->getLevel() + 1, \$con);
  1135. return \$this;
  1136. }
  1137. ";
  1138. }
  1139. protected function addMoveToLastChildOf(&$script)
  1140. {
  1141. $objectClassname = $this->objectClassname;
  1142. $script .= "
  1143. /**
  1144. * Moves current node and its subtree to be the last child of \$parent
  1145. * The modifications in the current object and the tree are immediate
  1146. *
  1147. * @param $objectClassname \$parent Propel object for parent node
  1148. * @param PropelPDO \$con Connection to use.
  1149. *
  1150. * @return $objectClassname The current Propel object
  1151. */
  1152. public function moveToLastChildOf(\$parent, PropelPDO \$con = null)
  1153. {
  1154. if (!\$this->isInTree()) {
  1155. throw new PropelException('A $objectClassname object must be already in the tree to be moved. Use the insertAsLastChildOf() instead.');
  1156. }";
  1157. if ($this->behavior->useScope()) {
  1158. $script .= "
  1159. if (\$parent->getScopeValue() != \$this->getScopeValue()) {
  1160. throw new PropelException('Moving nodes across trees is not supported');
  1161. }";
  1162. }
  1163. $script .= "
  1164. if (\$parent->isDescendantOf(\$this)) {
  1165. throw new PropelException('Cannot move a node as child of one of its subtree nodes.');
  1166. }
  1167. \$this->moveSubtreeTo(\$parent->getRightValue(), \$parent->getLevel() - \$this->getLevel() + 1, \$con);
  1168. return \$this;
  1169. }
  1170. ";
  1171. }
  1172. protected function addMoveToPrevSiblingOf(&$script)
  1173. {
  1174. $objectClassname = $this->objectClassname;
  1175. $script .= "
  1176. /**
  1177. * Moves current node and its subtree to be the previous sibling of \$sibling
  1178. * The modifications in the current object and the tree are immediate
  1179. *
  1180. * @param $objectClassname \$sibling Propel object for sibling node
  1181. * @param PropelPDO \$con Connection to use.
  1182. *
  1183. * @return $objectClassname The current Propel object
  1184. */
  1185. public function moveToPrevSiblingOf(\$sibling, PropelPDO \$con = null)
  1186. {
  1187. if (!\$this->isInTree()) {
  1188. throw new PropelException('A $objectClassname object must be already in the tree to be moved. Use the insertAsPrevSiblingOf() instead.');
  1189. }
  1190. if (\$sibling->isRoot()) {
  1191. throw new PropelException('Cannot move to previous sibling of a root node.');
  1192. }";
  1193. if ($this->behavior->useScope()) {
  1194. $script .= "
  1195. if (\$sibling->getScopeValue() != \$this->getScopeValue()) {
  1196. throw new PropelException('Moving nodes across trees is not supported');
  1197. }";
  1198. }
  1199. $script .= "
  1200. if (\$sibling->isDescendantOf(\$this)) {
  1201. throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.');
  1202. }
  1203. \$this->moveSubtreeTo(\$sibling->getLeftValue(), \$sibling->getLevel() - \$this->getLevel(), \$con);
  1204. return \$this;
  1205. }
  1206. ";
  1207. }
  1208. protected function addMoveToNextSiblingOf(&$script)
  1209. {
  1210. $objectClassname = $this->objectClassname;
  1211. $script .= "
  1212. /**
  1213. * Moves current node and its subtree to be the next sibling of \$sibling
  1214. * The modifications in the current object and the tree are immediate
  1215. *
  1216. * @param $objectClassname \$sibling Propel object for sibling node
  1217. * @param PropelPDO \$con Connection to use.
  1218. *
  1219. * @return $objectClassname The current Propel object
  1220. */
  1221. public function moveToNextSiblingOf(\$sibling, PropelPDO \$con = null)
  1222. {
  1223. if (!\$this->isInTree()) {
  1224. throw new PropelException('A $objectClassname object must be already in the tree to be moved. Use the insertAsNextSiblingOf() instead.');
  1225. }
  1226. if (\$sibling->isRoot()) {
  1227. throw new PropelException('Cannot move to next sibling of a root node.');
  1228. }";
  1229. if ($this->behavior->useScope()) {
  1230. $script .= "
  1231. if (\$sibling->getScopeValue() != \$this->getScopeValue()) {
  1232. throw new PropelException('Moving nodes across trees is not supported');
  1233. }";
  1234. }
  1235. $script .= "
  1236. if (\$sibling->isDescendantOf(\$this)) {
  1237. throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.');
  1238. }
  1239. \$this->moveSubtreeTo(\$sibling->getRightValue() + 1, \$sibling->getLevel() - \$this->getLevel(), \$con);
  1240. return \$this;
  1241. }
  1242. ";
  1243. }
  1244. protected function addMoveSubtreeTo(&$script)
  1245. {
  1246. $objectClassname = $this->objectClassname;
  1247. $peerClassname = $this->peerClassname;
  1248. $useScope = $this->behavior->useScope();
  1249. $script .= "
  1250. /**
  1251. * Move current node and its children to location \$destLeft and updates rest of tree
  1252. *
  1253. * @param int \$destLeft Destination left value
  1254. * @param int \$levelDelta Delta to add to the levels
  1255. * @param PropelPDO \$con Connection to use.
  1256. */
  1257. protected function moveSubtreeTo(\$destLeft, \$levelDelta, PropelPDO \$con = null)
  1258. {
  1259. \$left = \$this->getLeftValue();
  1260. \$right = \$this->getRightValue();";
  1261. if ($useScope) {
  1262. $script .= "
  1263. \$scope = \$this->getScopeValue();";
  1264. }
  1265. $script .= "
  1266. \$treeSize = \$right - \$left +1;
  1267. if (\$con === null) {
  1268. \$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_WRITE);
  1269. }
  1270. \$con->beginTransaction();
  1271. try {
  1272. // make room next to the target for the subtree
  1273. $peerClassname::shiftRLValues(\$treeSize, \$destLeft, null" . ($useScope ? ", \$scope" : "") . ", \$con);
  1274. if (\$left >= \$destLeft) { // src was shifted too?
  1275. \$left += \$treeSize;
  1276. \$right += \$treeSize;
  1277. }
  1278. if (\$levelDelta) {
  1279. // update the levels of the subtree
  1280. $peerClassname::shiftLevel(\$levelDelta, \$left, \$right" . ($useScope ? ", \$scope" : "") . ", \$con);
  1281. }
  1282. // move the subtree to the target
  1283. $peerClassname::shiftRLValues(\$destLeft - \$left, \$left, \$right" . ($useScope ? ", \$scope" : "") . ", \$con);
  1284. // remove the empty room at the previous location of the subtree
  1285. $peerClassname::shiftRLValues(-\$treeSize, \$right + 1, null" . ($useScope ? ", \$scope" : "") . ", \$con);
  1286. // update all loaded nodes
  1287. $peerClassname::updateLoadedNodes(null, \$con);
  1288. \$con->commit();
  1289. } catch (PropelException \$e) {
  1290. \$con->rollback();
  1291. throw \$e;
  1292. }
  1293. }
  1294. ";
  1295. }
  1296. protected function addDeleteDescendants(&$script)
  1297. {
  1298. $objectClassname = $this->objectClassname;
  1299. $peerClassname = $this->peerClassname;
  1300. $queryClassname = $this->queryClassname;
  1301. $useScope = $this->behavior->useScope();
  1302. $script .= "
  1303. /**
  1304. * Deletes all descendants for the given node
  1305. * Instance pooling is wiped out by this command,
  1306. * so existing $objectClassname instances are probably invalid (except for the current one)
  1307. *
  1308. * @param PropelPDO \$con Connection to use.
  1309. *
  1310. * @return int number of deleted nodes
  1311. */
  1312. public function deleteDescendants(PropelPDO \$con = null)
  1313. {
  1314. if(\$this->isLeaf()) {
  1315. // save one query
  1316. return;
  1317. }
  1318. if (\$con === null) {
  1319. \$con = Propel::getConnection($peerClassname::DATABASE_NAME, Propel::CONNECTION_READ);
  1320. }
  1321. \$left = \$this->getLeftValue();
  1322. \$right = \$this->getRightValue();";
  1323. if ($useScope) {
  1324. $script .= "
  1325. \$scope = \$this->getScopeValue();";
  1326. }
  1327. $script .= "
  1328. \$con->beginTransaction();
  1329. try {
  1330. // delete descendant nodes (will empty the instance pool)
  1331. \$ret = $queryClassname::create()
  1332. ->descendantsOf(\$this)
  1333. ->delete(\$con);
  1334. // fill up the room that was used by descendants
  1335. $peerClassname::shiftRLValues(\$left - \$right + 1, \$right, null" . ($useScope ? ", \$scope" : "") . ", \$con);
  1336. // fix the right value for the current node, which is now a leaf
  1337. \$this->setRightValue(\$left + 1);
  1338. \$con->commit();
  1339. } catch (Exception \$e) {
  1340. \$con->rollback();
  1341. throw \$e;
  1342. }
  1343. return \$ret;
  1344. }
  1345. ";
  1346. }
  1347. protected function addGetIterator(&$script)
  1348. {
  1349. $script .= "
  1350. /**
  1351. * Returns a pre-order iterator for this node and its children.
  1352. *
  1353. * @return RecursiveIterator
  1354. */
  1355. public function getIterator()
  1356. {
  1357. return new NestedSetRecursiveIterator(\$this);
  1358. }
  1359. ";
  1360. }
  1361. protected function addCompatibilityProxies(&$script)
  1362. {
  1363. $objectClassname = $this->objectClassname;
  1364. $script .= "
  1365. /**
  1366. * Alias for makeRoot(), for BC with Propel 1.4 nested sets
  1367. *
  1368. * @deprecated since 1.5
  1369. * @see makeRoot
  1370. */
  1371. public function createRoot()
  1372. {
  1373. return \$this->makeRoot();
  1374. }
  1375. /**
  1376. * Alias for getParent(), for BC with Propel 1.4 nested sets
  1377. *
  1378. * @deprecated since 1.5
  1379. * @see getParent
  1380. */
  1381. public function retrieveParent(PropelPDO \$con = null)
  1382. {
  1383. return \$this->getParent(\$con);
  1384. }
  1385. /**
  1386. * Alias for setParent(), for BC with Propel 1.4 nested sets
  1387. *
  1388. * @deprecated since 1.5
  1389. * @see setParent
  1390. */
  1391. public function setParentNode(\$parent = null)
  1392. {
  1393. return \$this->setParent(\$parent);
  1394. }
  1395. /**
  1396. * Alias for countDecendants(), for BC with Propel 1.4 nested sets
  1397. *
  1398. * @deprecated since 1.5
  1399. * @see setParent
  1400. */
  1401. public function getNumberOfDescendants(PropelPDO \$con = null)
  1402. {
  1403. return \$this->countDescendants(null, \$con);
  1404. }
  1405. /**
  1406. * Alias for countChildren(), for BC with Propel 1.4 nested sets
  1407. *
  1408. * @deprecated since 1.5
  1409. * @see setParent
  1410. */
  1411. public function getNumberOfChildren(PropelPDO \$con = null)
  1412. {
  1413. return \$this->countChildren(null, \$con);
  1414. }
  1415. /**
  1416. * Alias for getPrevSibling(), for BC with Propel 1.4 nested sets
  1417. *
  1418. * @deprecated since 1.5
  1419. * @see getParent
  1420. */
  1421. public function retrievePrevSibling(PropelPDO \$con = null)
  1422. {
  1423. return \$this->getPrevSibling(\$con);
  1424. }
  1425. /**
  1426. * Alias for getNextSibling(), for BC with Propel 1.4 nested sets
  1427. *
  1428. * @deprecated since 1.5
  1429. * @see getParent
  1430. */
  1431. public function retrieveNextSibling(PropelPDO \$con = null)
  1432. {
  1433. return \$this->getNextSibling(\$con);
  1434. }
  1435. /**
  1436. * Alias for getFirstChild(), for BC with Propel 1.4 nested sets
  1437. *
  1438. * @deprecated since 1.5
  1439. * @see getParent
  1440. */
  1441. public function retrieveFirstChild(PropelPDO \$con = null)
  1442. {
  1443. return \$this->getFirstChild(null, \$con);
  1444. }
  1445. /**
  1446. * Alias for getLastChild(), for BC with Propel 1.4 nested sets
  1447. *
  1448. * @deprecated since 1.5
  1449. * @see getParent
  1450. */
  1451. public function retrieveLastChild(PropelPDO \$con = null)
  1452. {
  1453. return \$this->getLastChild(null, \$con);
  1454. }
  1455. /**
  1456. * Alias for getAncestors(), for BC with Propel 1.4 nested sets
  1457. *
  1458. * @deprecated since 1.5
  1459. * @see getAncestors
  1460. */
  1461. public function getPath(PropelPDO \$con = null)
  1462. {
  1463. \$path = \$this->getAncestors(null, \$con);
  1464. \$path []= \$this;
  1465. return \$path;
  1466. }
  1467. ";
  1468. }
  1469. }