PageRenderTime 97ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

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

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