PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/generator/lib/builder/om/PHP5NestedSetBuilder.php

https://github.com/1989gaurav/Propel
PHP | 1136 lines | 676 code | 102 blank | 358 comment | 31 complexity | b3420e8d5cee4dce0509b8c94f6012bd 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. require_once dirname(__FILE__) . '/ObjectBuilder.php';
  10. /**
  11. * Generates a PHP5 tree node Object class for user object model (OM) using Nested Set way.
  12. *
  13. * This class produces the base tree node object class (e.g. BaseMyTableNestedSet) which contains all
  14. * the custom-built accessor and setter methods.
  15. *
  16. * @author Heltem <heltem@o2php.com>
  17. * @package propel.generator.builder.om
  18. */
  19. class PHP5NestedSetBuilder extends ObjectBuilder
  20. {
  21. /**
  22. * Gets the package for the [base] object classes.
  23. * @return string
  24. */
  25. public function getPackage()
  26. {
  27. return parent::getPackage() . ".om";
  28. }
  29. /**
  30. * Returns the name of the current class being built.
  31. * @return string
  32. */
  33. public function getUnprefixedClassname()
  34. {
  35. return $this->getBuildProperty('basePrefix') . $this->getStubObjectBuilder()->getUnprefixedClassname() . 'NestedSet';
  36. }
  37. /**
  38. * Adds the include() statements for files that this class depends on or utilizes.
  39. * @param string &$script The script will be modified in this method.
  40. */
  41. protected function addIncludes(&$script)
  42. {
  43. $script .="
  44. require '".$this->getObjectBuilder()->getClassFilePath()."';
  45. ";
  46. } // addIncludes()
  47. /**
  48. * Adds class phpdoc comment and openning of class.
  49. * @param string &$script The script will be modified in this method.
  50. */
  51. protected function addClassOpen(&$script)
  52. {
  53. $table = $this->getTable();
  54. $tableName = $table->getName();
  55. $tableDesc = $table->getDescription();
  56. $script .= "
  57. /**
  58. * Base class that represents a row from the '$tableName' table.
  59. *
  60. * $tableDesc
  61. *";
  62. if ($this->getBuildProperty('addTimeStamp')) {
  63. $now = strftime('%c');
  64. $script .= "
  65. * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
  66. *
  67. * $now
  68. *";
  69. }
  70. $script .= "
  71. * @deprecated Since Propel 1.5. Use the nested_set behavior instead of the NestedSet treeMode
  72. * @package propel.generator.".$this->getPackage()."
  73. */
  74. abstract class ".$this->getClassname()." extends ".$this->getObjectBuilder()->getClassname()." implements NodeObject {
  75. ";
  76. }
  77. /**
  78. * Specifies the methods that are added as part of the basic OM class.
  79. * This can be overridden by subclasses that wish to add more methods.
  80. * @see ObjectBuilder::addClassBody()
  81. */
  82. protected function addClassBody(&$script)
  83. {
  84. $table = $this->getTable();
  85. $this->addAttributes($script);
  86. $this->addGetIterator($script);
  87. $this->addSave($script);
  88. $this->addDelete($script);
  89. $this->addMakeRoot($script);
  90. $this->addGetLevel($script);
  91. $this->addGetPath($script);
  92. $this->addGetNumberOfChildren($script);
  93. $this->addGetNumberOfDescendants($script);
  94. $this->addGetChildren($script);
  95. $this->addGetDescendants($script);
  96. $this->addSetLevel($script);
  97. $this->addSetChildren($script);
  98. $this->addSetParentNode($script);
  99. $this->addSetPrevSibling($script);
  100. $this->addSetNextSibling($script);
  101. $this->addIsRoot($script);
  102. $this->addIsLeaf($script);
  103. $this->addIsEqualTo($script);
  104. $this->addHasParent($script);
  105. $this->addHasChildren($script);
  106. $this->addHasPrevSibling($script);
  107. $this->addHasNextSibling($script);
  108. $this->addRetrieveParent($script);
  109. $this->addRetrieveFirstChild($script);
  110. $this->addRetrieveLastChild($script);
  111. $this->addRetrievePrevSibling($script);
  112. $this->addRetrieveNextSibling($script);
  113. $this->addInsertAsFirstChildOf($script);
  114. $this->addInsertAsLastChildOf($script);
  115. $this->addInsertAsPrevSiblingOf($script);
  116. $this->addInsertAsNextSiblingOf($script);
  117. $this->addMoveToFirstChildOf($script);
  118. $this->addMoveToLastChildOf($script);
  119. $this->addMoveToPrevSiblingOf($script);
  120. $this->addMoveToNextSiblingOf($script);
  121. $this->addInsertAsParentOf($script);
  122. $this->addGetLeft($script);
  123. $this->addGetRight($script);
  124. $this->addGetScopeId($script);
  125. $this->addSetLeft($script);
  126. $this->addSetRight($script);
  127. $this->addSetScopeId($script);
  128. }
  129. /**
  130. * Closes class.
  131. * @param string &$script The script will be modified in this method.
  132. */
  133. protected function addClassClose(&$script)
  134. {
  135. $script .= "
  136. } // " . $this->getClassname() . "
  137. ";
  138. }
  139. /**
  140. * Adds class attributes.
  141. * @param string &$script The script will be modified in this method.
  142. */
  143. protected function addAttributes(&$script)
  144. {
  145. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  146. $script .= "
  147. /**
  148. * Store level of node
  149. * @var int
  150. */
  151. protected \$level = null;
  152. /**
  153. * Store if node has prev sibling
  154. * @var bool
  155. */
  156. protected \$hasPrevSibling = null;
  157. /**
  158. * Store node if has prev sibling
  159. * @var $objectClassName
  160. */
  161. protected \$prevSibling = null;
  162. /**
  163. * Store if node has next sibling
  164. * @var bool
  165. */
  166. protected \$hasNextSibling = null;
  167. /**
  168. * Store node if has next sibling
  169. * @var $objectClassName
  170. */
  171. protected \$nextSibling = null;
  172. /**
  173. * Store if node has parent node
  174. * @var bool
  175. */
  176. protected \$hasParentNode = null;
  177. /**
  178. * The parent node for this node.
  179. * @var $objectClassName
  180. */
  181. protected \$parentNode = null;
  182. /**
  183. * Store children of the node
  184. * @var array
  185. */
  186. protected \$_children = null;
  187. ";
  188. }
  189. protected function addGetIterator(&$script)
  190. {
  191. $script .= "
  192. /**
  193. * Returns a pre-order iterator for this node and its children.
  194. *
  195. * @return NodeIterator
  196. */
  197. public function getIterator()
  198. {
  199. return new NestedSetRecursiveIterator(\$this);
  200. }
  201. ";
  202. }
  203. protected function addSave(&$script)
  204. {
  205. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  206. $script .= "
  207. /**
  208. * Saves modified object data to the datastore.
  209. * If object is saved without left/right values, set them as undefined (0)
  210. *
  211. * @param PropelPDO Connection to use.
  212. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  213. * May be unreliable with parent/children/brother changes
  214. * @throws PropelException
  215. */
  216. public function save(PropelPDO \$con = null)
  217. {
  218. \$left = \$this->getLeftValue();
  219. \$right = \$this->getRightValue();
  220. if (empty(\$left) || empty(\$right)) {
  221. \$root = $peerClassname::retrieveRoot(\$this->getScopeIdValue(), \$con);
  222. $peerClassname::insertAsLastChildOf(\$this, \$root, \$con);
  223. }
  224. return parent::save(\$con);
  225. }
  226. ";
  227. }
  228. protected function addDelete(&$script)
  229. {
  230. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  231. $script .= "
  232. /**
  233. * Removes this object and all descendants from datastore.
  234. *
  235. * @param PropelPDO Connection to use.
  236. * @return void
  237. * @throws PropelException
  238. */
  239. public function delete(PropelPDO \$con = null)
  240. {
  241. // delete node first
  242. parent::delete(\$con);
  243. // delete descendants and then shift tree
  244. $peerClassname::deleteDescendants(\$this, \$con);
  245. }
  246. ";
  247. }
  248. protected function addMakeRoot(&$script)
  249. {
  250. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  251. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  252. $script .= "
  253. /**
  254. * Sets node properties to make it a root node.
  255. *
  256. * @return $objectClassName The current object (for fluent API support)
  257. * @throws PropelException
  258. */
  259. public function makeRoot()
  260. {
  261. $peerClassname::createRoot(\$this);
  262. return \$this;
  263. }
  264. ";
  265. }
  266. protected function addGetLevel(&$script)
  267. {
  268. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  269. $script .= "
  270. /**
  271. * Gets the level if set, otherwise calculates this and returns it
  272. *
  273. * @param PropelPDO Connection to use.
  274. * @return int
  275. */
  276. public function getLevel(PropelPDO \$con = null)
  277. {
  278. if (null === \$this->level) {
  279. \$this->level = $peerClassname::getLevel(\$this, \$con);
  280. }
  281. return \$this->level;
  282. }
  283. ";
  284. }
  285. protected function addSetLevel(&$script)
  286. {
  287. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  288. $script .= "
  289. /**
  290. * Sets the level of the node in the tree
  291. *
  292. * @param int \$v new value
  293. * @return $objectClassName The current object (for fluent API support)
  294. */
  295. public function setLevel(\$level)
  296. {
  297. \$this->level = \$level;
  298. return \$this;
  299. }
  300. ";
  301. }
  302. protected function addSetChildren(&$script)
  303. {
  304. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  305. $script .= "
  306. /**
  307. * Sets the children array of the node in the tree
  308. *
  309. * @param array of $objectClassName \$children array of Propel node object
  310. * @return $objectClassName The current object (for fluent API support)
  311. */
  312. public function setChildren(array \$children)
  313. {
  314. \$this->_children = \$children;
  315. return \$this;
  316. }
  317. ";
  318. }
  319. protected function addSetParentNode(&$script)
  320. {
  321. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  322. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  323. $script .= "
  324. /**
  325. * Sets the parentNode of the node in the tree
  326. *
  327. * @param $objectClassName \$parent Propel node object
  328. * @return $objectClassName The current object (for fluent API support)
  329. */
  330. public function setParentNode(NodeObject \$parent = null)
  331. {
  332. \$this->parentNode = (true === (\$this->hasParentNode = $peerClassname::isValid(\$parent))) ? \$parent : null;
  333. return \$this;
  334. }
  335. ";
  336. }
  337. protected function addSetPrevSibling(&$script)
  338. {
  339. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  340. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  341. $script .= "
  342. /**
  343. * Sets the previous sibling of the node in the tree
  344. *
  345. * @param $objectClassName \$node Propel node object
  346. * @return $objectClassName The current object (for fluent API support)
  347. */
  348. public function setPrevSibling(NodeObject \$node = null)
  349. {
  350. \$this->prevSibling = \$node;
  351. \$this->hasPrevSibling = $peerClassname::isValid(\$node);
  352. return \$this;
  353. }
  354. ";
  355. }
  356. protected function addSetNextSibling(&$script)
  357. {
  358. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  359. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  360. $script .= "
  361. /**
  362. * Sets the next sibling of the node in the tree
  363. *
  364. * @param $objectClassName \$node Propel node object
  365. * @return $objectClassName The current object (for fluent API support)
  366. */
  367. public function setNextSibling(NodeObject \$node = null)
  368. {
  369. \$this->nextSibling = \$node;
  370. \$this->hasNextSibling = $peerClassname::isValid(\$node);
  371. return \$this;
  372. }
  373. ";
  374. }
  375. protected function addGetPath(&$script)
  376. {
  377. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  378. $script .= "
  379. /**
  380. * Get the path to the node in the tree
  381. *
  382. * @param PropelPDO Connection to use.
  383. * @return array
  384. */
  385. public function getPath(PropelPDO \$con = null)
  386. {
  387. return $peerClassname::getPath(\$this, \$con);
  388. }
  389. ";
  390. }
  391. protected function addGetNumberOfChildren(&$script)
  392. {
  393. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  394. $script .= "
  395. /**
  396. * Gets the number of children for the node (direct descendants)
  397. *
  398. * @param PropelPDO Connection to use.
  399. * @return int
  400. */
  401. public function getNumberOfChildren(PropelPDO \$con = null)
  402. {
  403. return $peerClassname::getNumberOfChildren(\$this, \$con);
  404. }
  405. ";
  406. }
  407. protected function addGetNumberOfDescendants(&$script)
  408. {
  409. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  410. $script .= "
  411. /**
  412. * Gets the total number of descendants for the node
  413. *
  414. * @param PropelPDO Connection to use.
  415. * @return int
  416. */
  417. public function getNumberOfDescendants(PropelPDO \$con = null)
  418. {
  419. return $peerClassname::getNumberOfDescendants(\$this, \$con);
  420. }
  421. ";
  422. }
  423. protected function addGetChildren(&$script)
  424. {
  425. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  426. $script .= "
  427. /**
  428. * Gets the children for the node
  429. *
  430. * @param PropelPDO Connection to use.
  431. * @return array
  432. */
  433. public function getChildren(PropelPDO \$con = null)
  434. {
  435. \$this->getLevel();
  436. if (is_array(\$this->_children)) {
  437. return \$this->_children;
  438. }
  439. return $peerClassname::retrieveChildren(\$this, \$con);
  440. }
  441. ";
  442. }
  443. protected function addGetDescendants(&$script)
  444. {
  445. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  446. $script .= "
  447. /**
  448. * Gets the descendants for the node
  449. *
  450. * @param PropelPDO Connection to use.
  451. * @return array
  452. */
  453. public function getDescendants(PropelPDO \$con = null)
  454. {
  455. \$this->getLevel();
  456. return $peerClassname::retrieveDescendants(\$this, \$con);
  457. }
  458. ";
  459. }
  460. protected function addIsRoot(&$script)
  461. {
  462. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  463. $script .= "
  464. /**
  465. * Returns true if node is the root node of the tree.
  466. *
  467. * @return bool
  468. */
  469. public function isRoot()
  470. {
  471. return $peerClassname::isRoot(\$this);
  472. }
  473. ";
  474. }
  475. protected function addIsLeaf(&$script)
  476. {
  477. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  478. $script .= "
  479. /**
  480. * Return true if the node is a leaf node
  481. *
  482. * @return bool
  483. */
  484. public function isLeaf()
  485. {
  486. return $peerClassname::isLeaf(\$this);
  487. }
  488. ";
  489. }
  490. protected function addIsEqualTo(&$script)
  491. {
  492. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  493. $script .= "
  494. /**
  495. * Tests if object is equal to \$node
  496. *
  497. * @param object \$node Propel object for node to compare to
  498. * @return bool
  499. */
  500. public function isEqualTo(NodeObject \$node)
  501. {
  502. return $peerClassname::isEqualTo(\$this, \$node);
  503. }
  504. ";
  505. }
  506. protected function addHasParent(&$script)
  507. {
  508. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  509. $script .= "
  510. /**
  511. * Tests if object has an ancestor
  512. *
  513. * @param PropelPDO \$con Connection to use.
  514. * @return bool
  515. */
  516. public function hasParent(PropelPDO \$con = null)
  517. {
  518. if (null === \$this->hasParentNode) {
  519. $peerClassname::hasParent(\$this, \$con);
  520. }
  521. return \$this->hasParentNode;
  522. }
  523. ";
  524. }
  525. protected function addHasChildren(&$script)
  526. {
  527. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  528. $script .= "
  529. /**
  530. * Determines if the node has children / descendants
  531. *
  532. * @return bool
  533. */
  534. public function hasChildren()
  535. {
  536. return $peerClassname::hasChildren(\$this);
  537. }
  538. ";
  539. }
  540. protected function addHasPrevSibling(&$script)
  541. {
  542. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  543. $script .= "
  544. /**
  545. * Determines if the node has previous sibling
  546. *
  547. * @param PropelPDO \$con Connection to use.
  548. * @return bool
  549. */
  550. public function hasPrevSibling(PropelPDO \$con = null)
  551. {
  552. if (null === \$this->hasPrevSibling) {
  553. $peerClassname::hasPrevSibling(\$this, \$con);
  554. }
  555. return \$this->hasPrevSibling;
  556. }
  557. ";
  558. }
  559. protected function addHasNextSibling(&$script)
  560. {
  561. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  562. $script .= "
  563. /**
  564. * Determines if the node has next sibling
  565. *
  566. * @param PropelPDO \$con Connection to use.
  567. * @return bool
  568. */
  569. public function hasNextSibling(PropelPDO \$con = null)
  570. {
  571. if (null === \$this->hasNextSibling) {
  572. $peerClassname::hasNextSibling(\$this, \$con);
  573. }
  574. return \$this->hasNextSibling;
  575. }
  576. ";
  577. }
  578. protected function addRetrieveParent(&$script)
  579. {
  580. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  581. $script .= "
  582. /**
  583. * Gets ancestor for the given node if it exists
  584. *
  585. * @param PropelPDO \$con Connection to use.
  586. * @return mixed Propel object if exists else false
  587. */
  588. public function retrieveParent(PropelPDO \$con = null)
  589. {
  590. if (null === \$this->hasParentNode) {
  591. \$this->parentNode = $peerClassname::retrieveParent(\$this, \$con);
  592. \$this->hasParentNode = $peerClassname::isValid(\$this->parentNode);
  593. }
  594. return \$this->parentNode;
  595. }
  596. ";
  597. }
  598. protected function addRetrieveFirstChild(&$script)
  599. {
  600. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  601. $script .= "
  602. /**
  603. * Gets first child if it exists
  604. *
  605. * @param PropelPDO \$con Connection to use.
  606. * @return mixed Propel object if exists else false
  607. */
  608. public function retrieveFirstChild(PropelPDO \$con = null)
  609. {
  610. if (\$this->hasChildren(\$con)) {
  611. if (is_array(\$this->_children)) {
  612. return \$this->_children[0];
  613. }
  614. return $peerClassname::retrieveFirstChild(\$this, \$con);
  615. }
  616. return false;
  617. }
  618. ";
  619. }
  620. protected function addRetrieveLastChild(&$script)
  621. {
  622. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  623. $script .= "
  624. /**
  625. * Gets last child if it exists
  626. *
  627. * @param PropelPDO \$con Connection to use.
  628. * @return mixed Propel object if exists else false
  629. */
  630. public function retrieveLastChild(PropelPDO \$con = null)
  631. {
  632. if (\$this->hasChildren(\$con)) {
  633. if (is_array(\$this->_children)) {
  634. \$last = count(\$this->_children) - 1;
  635. return \$this->_children[\$last];
  636. }
  637. return $peerClassname::retrieveLastChild(\$this, \$con);
  638. }
  639. return false;
  640. }
  641. ";
  642. }
  643. protected function addRetrievePrevSibling(&$script)
  644. {
  645. $script .= "
  646. /**
  647. * Gets prev sibling for the given node if it exists
  648. *
  649. * @param PropelPDO \$con Connection to use.
  650. * @return mixed Propel object if exists else false
  651. */
  652. public function retrievePrevSibling(PropelPDO \$con = null)
  653. {
  654. if (\$this->hasPrevSibling(\$con)) {
  655. return \$this->prevSibling;
  656. }
  657. return \$this->hasPrevSibling;
  658. }
  659. ";
  660. }
  661. protected function addRetrieveNextSibling(&$script)
  662. {
  663. $script .= "
  664. /**
  665. * Gets next sibling for the given node if it exists
  666. *
  667. * @param PropelPDO \$con Connection to use.
  668. * @return mixed Propel object if exists else false
  669. */
  670. public function retrieveNextSibling(PropelPDO \$con = null)
  671. {
  672. if (\$this->hasNextSibling(\$con)) {
  673. return \$this->nextSibling;
  674. }
  675. return \$this->hasNextSibling;
  676. }
  677. ";
  678. }
  679. protected function addInsertAsFirstChildOf(&$script)
  680. {
  681. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  682. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  683. $script .= "
  684. /**
  685. * Inserts as first child of given destination node \$parent
  686. *
  687. * @param $objectClassName \$parent Propel object for destination node
  688. * @param PropelPDO \$con Connection to use.
  689. * @return $objectClassName The current object (for fluent API support)
  690. * @throws PropelException - if this object already exists
  691. */
  692. public function insertAsFirstChildOf(NodeObject \$parent, PropelPDO \$con = null)
  693. {
  694. if (!\$this->isNew())
  695. {
  696. throw new PropelException(\"$objectClassName must be new.\");
  697. }
  698. $peerClassname::insertAsFirstChildOf(\$this, \$parent, \$con);
  699. return \$this;
  700. }
  701. ";
  702. }
  703. protected function addInsertAsLastChildOf(&$script)
  704. {
  705. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  706. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  707. $script .= "
  708. /**
  709. * Inserts as last child of given destination node \$parent
  710. *
  711. * @param $objectClassName \$parent Propel object for destination node
  712. * @param PropelPDO \$con Connection to use.
  713. * @return $objectClassName The current object (for fluent API support)
  714. * @throws PropelException - if this object already exists
  715. */
  716. public function insertAsLastChildOf(NodeObject \$parent, PropelPDO \$con = null)
  717. {
  718. if (!\$this->isNew())
  719. {
  720. throw new PropelException(\"$objectClassName must be new.\");
  721. }
  722. $peerClassname::insertAsLastChildOf(\$this, \$parent, \$con);
  723. return \$this;
  724. }
  725. ";
  726. }
  727. protected function addInsertAsPrevSiblingOf(&$script)
  728. {
  729. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  730. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  731. $script .= "
  732. /**
  733. * Inserts \$node as previous sibling to given destination node \$dest
  734. *
  735. * @param $objectClassName \$dest Propel object for destination node
  736. * @param PropelPDO \$con Connection to use.
  737. * @return $objectClassName The current object (for fluent API support)
  738. * @throws PropelException - if this object already exists
  739. */
  740. public function insertAsPrevSiblingOf(NodeObject \$dest, PropelPDO \$con = null)
  741. {
  742. if (!\$this->isNew())
  743. {
  744. throw new PropelException(\"$objectClassName must be new.\");
  745. }
  746. $peerClassname::insertAsPrevSiblingOf(\$this, \$dest, \$con);
  747. return \$this;
  748. }
  749. ";
  750. }
  751. protected function addInsertAsNextSiblingOf(&$script)
  752. {
  753. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  754. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  755. $script .= "
  756. /**
  757. * Inserts \$node as next sibling to given destination node \$dest
  758. *
  759. * @param $objectClassName \$dest Propel object for destination node
  760. * @param PropelPDO \$con Connection to use.
  761. * @return $objectClassName The current object (for fluent API support)
  762. * @throws PropelException - if this object already exists
  763. */
  764. public function insertAsNextSiblingOf(NodeObject \$dest, PropelPDO \$con = null)
  765. {
  766. if (!\$this->isNew())
  767. {
  768. throw new PropelException(\"$objectClassName must be new.\");
  769. }
  770. $peerClassname::insertAsNextSiblingOf(\$this, \$dest, \$con);
  771. return \$this;
  772. }
  773. ";
  774. }
  775. protected function addMoveToFirstChildOf(&$script)
  776. {
  777. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  778. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  779. $script .= "
  780. /**
  781. * Moves node to be first child of \$parent
  782. *
  783. * @param $objectClassName \$parent Propel object for destination node
  784. * @param PropelPDO \$con Connection to use.
  785. * @return $objectClassName The current object (for fluent API support)
  786. */
  787. public function moveToFirstChildOf(NodeObject \$parent, PropelPDO \$con = null)
  788. {
  789. if (\$this->isNew())
  790. {
  791. throw new PropelException(\"$objectClassName must exist in tree.\");
  792. }
  793. $peerClassname::moveToFirstChildOf(\$parent, \$this, \$con);
  794. return \$this;
  795. }
  796. ";
  797. }
  798. protected function addMoveToLastChildOf(&$script)
  799. {
  800. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  801. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  802. $script .= "
  803. /**
  804. * Moves node to be last child of \$parent
  805. *
  806. * @param $objectClassName \$parent Propel object for destination node
  807. * @param PropelPDO \$con Connection to use.
  808. * @return $objectClassName The current object (for fluent API support)
  809. */
  810. public function moveToLastChildOf(NodeObject \$parent, PropelPDO \$con = null)
  811. {
  812. if (\$this->isNew())
  813. {
  814. throw new PropelException(\"$objectClassName must exist in tree.\");
  815. }
  816. $peerClassname::moveToLastChildOf(\$parent, \$this, \$con);
  817. return \$this;
  818. }
  819. ";
  820. }
  821. protected function addMoveToPrevSiblingOf(&$script)
  822. {
  823. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  824. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  825. $script .= "
  826. /**
  827. * Moves node to be prev sibling to \$dest
  828. *
  829. * @param $objectClassName \$dest Propel object for destination node
  830. * @param PropelPDO \$con Connection to use.
  831. * @return $objectClassName The current object (for fluent API support)
  832. */
  833. public function moveToPrevSiblingOf(NodeObject \$dest, PropelPDO \$con = null)
  834. {
  835. if (\$this->isNew())
  836. {
  837. throw new PropelException(\"$objectClassName must exist in tree.\");
  838. }
  839. $peerClassname::moveToPrevSiblingOf(\$dest, \$this, \$con);
  840. return \$this;
  841. }
  842. ";
  843. }
  844. protected function addMoveToNextSiblingOf(&$script)
  845. {
  846. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  847. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  848. $script .= "
  849. /**
  850. * Moves node to be next sibling to \$dest
  851. *
  852. * @param $objectClassName \$dest Propel object for destination node
  853. * @param PropelPDO \$con Connection to use.
  854. * @return $objectClassName The current object (for fluent API support)
  855. */
  856. public function moveToNextSiblingOf(NodeObject \$dest, PropelPDO \$con = null)
  857. {
  858. if (\$this->isNew())
  859. {
  860. throw new PropelException(\"$objectClassName must exist in tree.\");
  861. }
  862. $peerClassname::moveToNextSiblingOf(\$dest, \$this, \$con);
  863. return \$this;
  864. }
  865. ";
  866. }
  867. protected function addInsertAsParentOf(&$script)
  868. {
  869. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  870. $peerClassname = $this->getStubPeerBuilder()->getClassname();
  871. $script .= "
  872. /**
  873. * Inserts node as parent of given node.
  874. *
  875. * @param $objectClassName \$node Propel object for destination node
  876. * @param PropelPDO \$con Connection to use.
  877. * @return $objectClassName The current object (for fluent API support)
  878. */
  879. public function insertAsParentOf(NodeObject \$node, PropelPDO \$con = null)
  880. {
  881. $peerClassname::insertAsParentOf(\$this, \$node, \$con);
  882. return \$this;
  883. }
  884. ";
  885. }
  886. protected function addGetLeft(&$script)
  887. {
  888. $table = $this->getTable();
  889. foreach ($table->getColumns() as $col) {
  890. if ($col->isNestedSetLeftKey()) {
  891. $left_col_getter_name = 'get'.$col->getPhpName();
  892. break;
  893. }
  894. }
  895. $script .= "
  896. /**
  897. * Wraps the getter for the left value
  898. *
  899. * @return int
  900. */
  901. public function getLeftValue()
  902. {
  903. return \$this->$left_col_getter_name();
  904. }
  905. ";
  906. }
  907. protected function addGetRight(&$script)
  908. {
  909. $table = $this->getTable();
  910. foreach ($table->getColumns() as $col) {
  911. if ($col->isNestedSetRightKey()) {
  912. $right_col_getter_name = 'get'.$col->getPhpName();
  913. break;
  914. }
  915. }
  916. $script .= "
  917. /**
  918. * Wraps the getter for the right value
  919. *
  920. * @return int
  921. */
  922. public function getRightValue()
  923. {
  924. return \$this->$right_col_getter_name();
  925. }
  926. ";
  927. }
  928. protected function addGetScopeId(&$script)
  929. {
  930. $table = $this->getTable();
  931. $scope_col_getter_name = null;
  932. foreach ($table->getColumns() as $col) {
  933. if ($col->isTreeScopeKey()) {
  934. $scope_col_getter_name = 'get'.$col->getPhpName();
  935. break;
  936. }
  937. }
  938. $script .= "
  939. /**
  940. * Wraps the getter for the scope value
  941. *
  942. * @return int or null if scope is disabled
  943. */
  944. public function getScopeIdValue()
  945. {";
  946. if ($scope_col_getter_name) {
  947. $script .= "
  948. return \$this->$scope_col_getter_name();";
  949. } else {
  950. $script .= "
  951. return null;";
  952. }
  953. $script .= "
  954. }
  955. ";
  956. }
  957. protected function addSetLeft(&$script)
  958. {
  959. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  960. $table = $this->getTable();
  961. foreach ($table->getColumns() as $col) {
  962. if ($col->isNestedSetLeftKey()) {
  963. $left_col_setter_name = 'set'.$col->getPhpName();
  964. break;
  965. }
  966. }
  967. $script .= "
  968. /**
  969. * Set the value left column
  970. *
  971. * @param int \$v new value
  972. * @return $objectClassName The current object (for fluent API support)
  973. */
  974. public function setLeftValue(\$v)
  975. {
  976. \$this->$left_col_setter_name(\$v);
  977. return \$this;
  978. }
  979. ";
  980. }
  981. protected function addSetRight(&$script)
  982. {
  983. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  984. $table = $this->getTable();
  985. foreach ($table->getColumns() as $col) {
  986. if ($col->isNestedSetRightKey()) {
  987. $right_col_setter_name = 'set'.$col->getPhpName();
  988. break;
  989. }
  990. }
  991. $script .= "
  992. /**
  993. * Set the value of right column
  994. *
  995. * @param int \$v new value
  996. * @return $objectClassName The current object (for fluent API support)
  997. */
  998. public function setRightValue(\$v)
  999. {
  1000. \$this->$right_col_setter_name(\$v);
  1001. return \$this;
  1002. }
  1003. ";
  1004. }
  1005. protected function addSetScopeId(&$script)
  1006. {
  1007. $objectClassName = $this->getStubObjectBuilder()->getClassname();
  1008. $table = $this->getTable();
  1009. $scope_col_setter_name = null;
  1010. foreach ($table->getColumns() as $col) {
  1011. if ($col->isTreeScopeKey()) {
  1012. $scope_col_setter_name = 'set'.$col->getPhpName();
  1013. break;
  1014. }
  1015. }
  1016. $script .= "
  1017. /**
  1018. * Set the value of scope column
  1019. *
  1020. * @param int \$v new value
  1021. * @return $objectClassName The current object (for fluent API support)
  1022. */
  1023. public function setScopeIdValue(\$v)
  1024. {";
  1025. if ($scope_col_setter_name) {
  1026. $script .= "
  1027. \$this->$scope_col_setter_name(\$v);";
  1028. }
  1029. $script .= "
  1030. return \$this;
  1031. }
  1032. ";
  1033. }
  1034. } // PHP5NestedSetBuilder