Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 86.65 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Artsofte\MainBundle\Model\om;
  4.  
  5. use \BaseObject;
  6. use \BasePeer;
  7. use \Criteria;
  8. use \Exception;
  9. use \NestedSetRecursiveIterator;
  10. use \PDO;
  11. use \Persistent;
  12. use \Propel;
  13. use \PropelCollection;
  14. use \PropelException;
  15. use \PropelObjectCollection;
  16. use \PropelPDO;
  17. use Artsofte\MainBundle\Model\Article;
  18. use Artsofte\MainBundle\Model\ArticleI18n;
  19. use Artsofte\MainBundle\Model\ArticleI18nQuery;
  20. use Artsofte\MainBundle\Model\ArticlePeer;
  21. use Artsofte\MainBundle\Model\ArticleQuery;
  22. use Artsofte\MainBundle\Model\SiteModule;
  23. use Artsofte\MainBundle\Model\SiteModuleQuery;
  24.  
  25. abstract class BaseArticle extends BaseObject implements Persistent
  26. {
  27. /**
  28. * Peer class name
  29. */
  30. const PEER = 'Artsofte\\MainBundle\\Model\\ArticlePeer';
  31.  
  32. /**
  33. * The Peer class.
  34. * Instance provides a convenient way of calling static methods on a class
  35. * that calling code may not be able to identify.
  36. * @var ArticlePeer
  37. */
  38. protected static $peer;
  39.  
  40. /**
  41. * The flag var to prevent infinite loop in deep copy
  42. * @var boolean
  43. */
  44. protected $startCopy = false;
  45.  
  46. /**
  47. * The value for the id field.
  48. * @var string
  49. */
  50. protected $id;
  51.  
  52. /**
  53. * The value for the active field.
  54. * @var boolean
  55. */
  56. protected $active;
  57.  
  58. /**
  59. * The value for the alias field.
  60. * @var string
  61. */
  62. protected $alias;
  63.  
  64. /**
  65. * The value for the site_module_id field.
  66. * @var int
  67. */
  68. protected $site_module_id;
  69.  
  70. /**
  71. * The value for the tree_left field.
  72. * @var int
  73. */
  74. protected $tree_left;
  75.  
  76. /**
  77. * The value for the tree_right field.
  78. * @var int
  79. */
  80. protected $tree_right;
  81.  
  82. /**
  83. * The value for the tree_level field.
  84. * @var int
  85. */
  86. protected $tree_level;
  87.  
  88. /**
  89. * @var SiteModule
  90. */
  91. protected $aSiteModule;
  92.  
  93. /**
  94. * @var PropelObjectCollection|ArticleI18n[] Collection to store aggregation of ArticleI18n objects.
  95. */
  96. protected $collArticleI18ns;
  97. protected $collArticleI18nsPartial;
  98.  
  99. /**
  100. * Flag to prevent endless save loop, if this object is referenced
  101. * by another object which falls in this transaction.
  102. * @var boolean
  103. */
  104. protected $alreadyInSave = false;
  105.  
  106. /**
  107. * Flag to prevent endless validation loop, if this object is referenced
  108. * by another object which falls in this transaction.
  109. * @var boolean
  110. */
  111. protected $alreadyInValidation = false;
  112.  
  113. /**
  114. * Flag to prevent endless clearAllReferences($deep=true) loop, if this object is referenced
  115. * @var boolean
  116. */
  117. protected $alreadyInClearAllReferencesDeep = false;
  118.  
  119. // nested_set behavior
  120.  
  121. /**
  122. * Queries to be executed in the save transaction
  123. * @var array
  124. */
  125. protected $nestedSetQueries = array();
  126.  
  127. /**
  128. * Internal cache for children nodes
  129. * @var null|PropelObjectCollection
  130. */
  131. protected $collNestedSetChildren = null;
  132.  
  133. /**
  134. * Internal cache for parent node
  135. * @var null|Article
  136. */
  137. protected $aNestedSetParent = null;
  138.  
  139.  
  140. // i18n behavior
  141.  
  142. /**
  143. * Current locale
  144. * @var string
  145. */
  146. protected $currentLocale = 'en_US';
  147.  
  148. /**
  149. * Current translation objects
  150. * @var array[ArticleI18n]
  151. */
  152. protected $currentTranslations;
  153.  
  154. /**
  155. * An array of objects scheduled for deletion.
  156. * @var PropelObjectCollection
  157. */
  158. protected $articleI18nsScheduledForDeletion = null;
  159.  
  160. /**
  161. * Get the [id] column value.
  162. *
  163. * @return string
  164. */
  165. public function getId()
  166. {
  167.  
  168. return $this->id;
  169. }
  170.  
  171. /**
  172. * Get the [active] column value.
  173. *
  174. * @return boolean
  175. */
  176. public function getActive()
  177. {
  178.  
  179. return $this->active;
  180. }
  181.  
  182. /**
  183. * Get the [alias] column value.
  184. *
  185. * @return string
  186. */
  187. public function getAlias()
  188. {
  189.  
  190. return $this->alias;
  191. }
  192.  
  193. /**
  194. * Get the [site_module_id] column value.
  195. *
  196. * @return int
  197. */
  198. public function getSiteModuleId()
  199. {
  200.  
  201. return $this->site_module_id;
  202. }
  203.  
  204. /**
  205. * Get the [tree_left] column value.
  206. *
  207. * @return int
  208. */
  209. public function getTreeLeft()
  210. {
  211.  
  212. return $this->tree_left;
  213. }
  214.  
  215. /**
  216. * Get the [tree_right] column value.
  217. *
  218. * @return int
  219. */
  220. public function getTreeRight()
  221. {
  222.  
  223. return $this->tree_right;
  224. }
  225.  
  226. /**
  227. * Get the [tree_level] column value.
  228. *
  229. * @return int
  230. */
  231. public function getTreeLevel()
  232. {
  233.  
  234. return $this->tree_level;
  235. }
  236.  
  237. /**
  238. * Set the value of [id] column.
  239. *
  240. * @param string $v new value
  241. * @return Article The current object (for fluent API support)
  242. */
  243. public function setId($v)
  244. {
  245. if ($v !== null && is_numeric($v)) {
  246. $v = (string) $v;
  247. }
  248.  
  249. if ($this->id !== $v) {
  250. $this->id = $v;
  251. $this->modifiedColumns[] = ArticlePeer::ID;
  252. }
  253.  
  254.  
  255. return $this;
  256. } // setId()
  257.  
  258. /**
  259. * Sets the value of the [active] column.
  260. * Non-boolean arguments are converted using the following rules:
  261. * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
  262. * * 0, '0', 'false', 'off', and 'no' are converted to boolean false
  263. * Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
  264. *
  265. * @param boolean|integer|string $v The new value
  266. * @return Article The current object (for fluent API support)
  267. */
  268. public function setActive($v)
  269. {
  270. if ($v !== null) {
  271. if (is_string($v)) {
  272. $v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
  273. } else {
  274. $v = (boolean) $v;
  275. }
  276. }
  277.  
  278. if ($this->active !== $v) {
  279. $this->active = $v;
  280. $this->modifiedColumns[] = ArticlePeer::ACTIVE;
  281. }
  282.  
  283.  
  284. return $this;
  285. } // setActive()
  286.  
  287. /**
  288. * Set the value of [alias] column.
  289. *
  290. * @param string $v new value
  291. * @return Article The current object (for fluent API support)
  292. */
  293. public function setAlias($v)
  294. {
  295. if ($v !== null) {
  296. $v = (string) $v;
  297. }
  298.  
  299. if ($this->alias !== $v) {
  300. $this->alias = $v;
  301. $this->modifiedColumns[] = ArticlePeer::ALIAS;
  302. }
  303.  
  304.  
  305. return $this;
  306. } // setAlias()
  307.  
  308. /**
  309. * Set the value of [site_module_id] column.
  310. *
  311. * @param int $v new value
  312. * @return Article The current object (for fluent API support)
  313. */
  314. public function setSiteModuleId($v)
  315. {
  316. if ($v !== null && is_numeric($v)) {
  317. $v = (int) $v;
  318. }
  319.  
  320. if ($this->site_module_id !== $v) {
  321. $this->site_module_id = $v;
  322. $this->modifiedColumns[] = ArticlePeer::SITE_MODULE_ID;
  323. }
  324.  
  325. if ($this->aSiteModule !== null && $this->aSiteModule->getId() !== $v) {
  326. $this->aSiteModule = null;
  327. }
  328.  
  329.  
  330. return $this;
  331. } // setSiteModuleId()
  332.  
  333. /**
  334. * Set the value of [tree_left] column.
  335. *
  336. * @param int $v new value
  337. * @return Article The current object (for fluent API support)
  338. */
  339. public function setTreeLeft($v)
  340. {
  341. if ($v !== null && is_numeric($v)) {
  342. $v = (int) $v;
  343. }
  344.  
  345. if ($this->tree_left !== $v) {
  346. $this->tree_left = $v;
  347. $this->modifiedColumns[] = ArticlePeer::TREE_LEFT;
  348. }
  349.  
  350.  
  351. return $this;
  352. } // setTreeLeft()
  353.  
  354. /**
  355. * Set the value of [tree_right] column.
  356. *
  357. * @param int $v new value
  358. * @return Article The current object (for fluent API support)
  359. */
  360. public function setTreeRight($v)
  361. {
  362. if ($v !== null && is_numeric($v)) {
  363. $v = (int) $v;
  364. }
  365.  
  366. if ($this->tree_right !== $v) {
  367. $this->tree_right = $v;
  368. $this->modifiedColumns[] = ArticlePeer::TREE_RIGHT;
  369. }
  370.  
  371.  
  372. return $this;
  373. } // setTreeRight()
  374.  
  375. /**
  376. * Set the value of [tree_level] column.
  377. *
  378. * @param int $v new value
  379. * @return Article The current object (for fluent API support)
  380. */
  381. public function setTreeLevel($v)
  382. {
  383. if ($v !== null && is_numeric($v)) {
  384. $v = (int) $v;
  385. }
  386.  
  387. if ($this->tree_level !== $v) {
  388. $this->tree_level = $v;
  389. $this->modifiedColumns[] = ArticlePeer::TREE_LEVEL;
  390. }
  391.  
  392.  
  393. return $this;
  394. } // setTreeLevel()
  395.  
  396. /**
  397. * Indicates whether the columns in this object are only set to default values.
  398. *
  399. * This method can be used in conjunction with isModified() to indicate whether an object is both
  400. * modified _and_ has some values set which are non-default.
  401. *
  402. * @return boolean Whether the columns in this object are only been set with default values.
  403. */
  404. public function hasOnlyDefaultValues()
  405. {
  406. // otherwise, everything was equal, so return true
  407. return true;
  408. } // hasOnlyDefaultValues()
  409.  
  410. /**
  411. * Hydrates (populates) the object variables with values from the database resultset.
  412. *
  413. * An offset (0-based "start column") is specified so that objects can be hydrated
  414. * with a subset of the columns in the resultset rows. This is needed, for example,
  415. * for results of JOIN queries where the resultset row includes columns from two or
  416. * more tables.
  417. *
  418. * @param array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM)
  419. * @param int $startcol 0-based offset column which indicates which resultset column to start with.
  420. * @param boolean $rehydrate Whether this object is being re-hydrated from the database.
  421. * @return int next starting column
  422. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  423. */
  424. public function hydrate($row, $startcol = 0, $rehydrate = false)
  425. {
  426. try {
  427.  
  428. $this->id = ($row[$startcol + 0] !== null) ? (string) $row[$startcol + 0] : null;
  429. $this->active = ($row[$startcol + 1] !== null) ? (boolean) $row[$startcol + 1] : null;
  430. $this->alias = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
  431. $this->site_module_id = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
  432. $this->tree_left = ($row[$startcol + 4] !== null) ? (int) $row[$startcol + 4] : null;
  433. $this->tree_right = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
  434. $this->tree_level = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
  435. $this->resetModified();
  436.  
  437. $this->setNew(false);
  438.  
  439. if ($rehydrate) {
  440. $this->ensureConsistency();
  441. }
  442. $this->postHydrate($row, $startcol, $rehydrate);
  443.  
  444. return $startcol + 7; // 7 = ArticlePeer::NUM_HYDRATE_COLUMNS.
  445.  
  446. } catch (Exception $e) {
  447. throw new PropelException("Error populating Article object", $e);
  448. }
  449. }
  450.  
  451. /**
  452. * Checks and repairs the internal consistency of the object.
  453. *
  454. * This method is executed after an already-instantiated object is re-hydrated
  455. * from the database. It exists to check any foreign keys to make sure that
  456. * the objects related to the current object are correct based on foreign key.
  457. *
  458. * You can override this method in the stub class, but you should always invoke
  459. * the base method from the overridden method (i.e. parent::ensureConsistency()),
  460. * in case your model changes.
  461. *
  462. * @throws PropelException
  463. */
  464. public function ensureConsistency()
  465. {
  466.  
  467. if ($this->aSiteModule !== null && $this->site_module_id !== $this->aSiteModule->getId()) {
  468. $this->aSiteModule = null;
  469. }
  470. } // ensureConsistency
  471.  
  472. /**
  473. * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.
  474. *
  475. * This will only work if the object has been saved and has a valid primary key set.
  476. *
  477. * @param boolean $deep (optional) Whether to also de-associated any related objects.
  478. * @param PropelPDO $con (optional) The PropelPDO connection to use.
  479. * @return void
  480. * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db
  481. */
  482. public function reload($deep = false, PropelPDO $con = null)
  483. {
  484. if ($this->isDeleted()) {
  485. throw new PropelException("Cannot reload a deleted object.");
  486. }
  487.  
  488. if ($this->isNew()) {
  489. throw new PropelException("Cannot reload an unsaved object.");
  490. }
  491.  
  492. if ($con === null) {
  493. $con = Propel::getConnection(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_READ);
  494. }
  495.  
  496. // We don't need to alter the object instance pool; we're just modifying this instance
  497. // already in the pool.
  498.  
  499. $stmt = ArticlePeer::doSelectStmt($this->buildPkeyCriteria(), $con);
  500. $row = $stmt->fetch(PDO::FETCH_NUM);
  501. $stmt->closeCursor();
  502. if (!$row) {
  503. throw new PropelException('Cannot find matching row in the database to reload object values.');
  504. }
  505. $this->hydrate($row, 0, true); // rehydrate
  506.  
  507. if ($deep) { // also de-associate any related objects?
  508.  
  509. $this->aSiteModule = null;
  510. $this->collArticleI18ns = null;
  511.  
  512. } // if (deep)
  513. }
  514.  
  515. /**
  516. * Removes this object from datastore and sets delete attribute.
  517. *
  518. * @param PropelPDO $con
  519. * @return void
  520. * @throws PropelException
  521. * @throws Exception
  522. * @see BaseObject::setDeleted()
  523. * @see BaseObject::isDeleted()
  524. */
  525. public function delete(PropelPDO $con = null)
  526. {
  527. if ($this->isDeleted()) {
  528. throw new PropelException("This object has already been deleted.");
  529. }
  530.  
  531. if ($con === null) {
  532. $con = Propel::getConnection(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  533. }
  534.  
  535. $con->beginTransaction();
  536. try {
  537. $deleteQuery = ArticleQuery::create()
  538. ->filterByPrimaryKey($this->getPrimaryKey());
  539. $ret = $this->preDelete($con);
  540. // nested_set behavior
  541. if ($this->isRoot()) {
  542. throw new PropelException('Deletion of a root node is disabled for nested sets. Use ArticlePeer::deleteTree() instead to delete an entire tree');
  543. }
  544.  
  545. if ($this->isInTree()) {
  546. $this->deleteDescendants($con);
  547. }
  548.  
  549. if ($ret) {
  550. $deleteQuery->delete($con);
  551. $this->postDelete($con);
  552. // nested_set behavior
  553. if ($this->isInTree()) {
  554. // fill up the room that was used by the node
  555. ArticlePeer::shiftRLValues(-2, $this->getRightValue() + 1, null, $con);
  556. }
  557.  
  558. $con->commit();
  559. $this->setDeleted(true);
  560. } else {
  561. $con->commit();
  562. }
  563. } catch (Exception $e) {
  564. $con->rollBack();
  565. throw $e;
  566. }
  567. }
  568.  
  569. /**
  570. * Persists this object to the database.
  571. *
  572. * If the object is new, it inserts it; otherwise an update is performed.
  573. * All modified related objects will also be persisted in the doSave()
  574. * method. This method wraps all precipitate database operations in a
  575. * single transaction.
  576. *
  577. * @param PropelPDO $con
  578. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  579. * @throws PropelException
  580. * @throws Exception
  581. * @see doSave()
  582. */
  583. public function save(PropelPDO $con = null)
  584. {
  585. if ($this->isDeleted()) {
  586. throw new PropelException("You cannot save an object that has been deleted.");
  587. }
  588.  
  589. if ($con === null) {
  590. $con = Propel::getConnection(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  591. }
  592.  
  593. $con->beginTransaction();
  594. $isInsert = $this->isNew();
  595. try {
  596. $ret = $this->preSave($con);
  597. // nested_set behavior
  598. if ($this->isNew() && $this->isRoot()) {
  599. // check if no other root exist in, the tree
  600. $nbRoots = ArticleQuery::create()
  601. ->addUsingAlias(ArticlePeer::LEFT_COL, 1, Criteria::EQUAL)
  602. ->count($con);
  603. if ($nbRoots > 0) {
  604. throw new PropelException('A root node already exists in this tree. To allow multiple root nodes, add the `use_scope` parameter in the nested_set behavior tag.');
  605. }
  606. }
  607. $this->processNestedSetQueries($con);
  608. if ($isInsert) {
  609. $ret = $ret && $this->preInsert($con);
  610. } else {
  611. $ret = $ret && $this->preUpdate($con);
  612. }
  613. if ($ret) {
  614. $affectedRows = $this->doSave($con);
  615. if ($isInsert) {
  616. $this->postInsert($con);
  617. } else {
  618. $this->postUpdate($con);
  619. }
  620. $this->postSave($con);
  621. ArticlePeer::addInstanceToPool($this);
  622. } else {
  623. $affectedRows = 0;
  624. }
  625. $con->commit();
  626.  
  627. return $affectedRows;
  628. } catch (Exception $e) {
  629. $con->rollBack();
  630. throw $e;
  631. }
  632. }
  633.  
  634. /**
  635. * Performs the work of inserting or updating the row in the database.
  636. *
  637. * If the object is new, it inserts it; otherwise an update is performed.
  638. * All related objects are also updated in this method.
  639. *
  640. * @param PropelPDO $con
  641. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  642. * @throws PropelException
  643. * @see save()
  644. */
  645. protected function doSave(PropelPDO $con)
  646. {
  647. $affectedRows = 0; // initialize var to track total num of affected rows
  648. if (!$this->alreadyInSave) {
  649. $this->alreadyInSave = true;
  650.  
  651. // We call the save method on the following object(s) if they
  652. // were passed to this object by their corresponding set
  653. // method. This object relates to these object(s) by a
  654. // foreign key reference.
  655.  
  656. if ($this->aSiteModule !== null) {
  657. if ($this->aSiteModule->isModified() || $this->aSiteModule->isNew()) {
  658. $affectedRows += $this->aSiteModule->save($con);
  659. }
  660. $this->setSiteModule($this->aSiteModule);
  661. }
  662.  
  663. if ($this->isNew() || $this->isModified()) {
  664. // persist changes
  665. if ($this->isNew()) {
  666. $this->doInsert($con);
  667. } else {
  668. $this->doUpdate($con);
  669. }
  670. $affectedRows += 1;
  671. $this->resetModified();
  672. }
  673.  
  674. if ($this->articleI18nsScheduledForDeletion !== null) {
  675. if (!$this->articleI18nsScheduledForDeletion->isEmpty()) {
  676. ArticleI18nQuery::create()
  677. ->filterByPrimaryKeys($this->articleI18nsScheduledForDeletion->getPrimaryKeys(false))
  678. ->delete($con);
  679. $this->articleI18nsScheduledForDeletion = null;
  680. }
  681. }
  682.  
  683. if ($this->collArticleI18ns !== null) {
  684. foreach ($this->collArticleI18ns as $referrerFK) {
  685. if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
  686. $affectedRows += $referrerFK->save($con);
  687. }
  688. }
  689. }
  690.  
  691. $this->alreadyInSave = false;
  692.  
  693. }
  694.  
  695. return $affectedRows;
  696. } // doSave()
  697.  
  698. /**
  699. * Insert the row in the database.
  700. *
  701. * @param PropelPDO $con
  702. *
  703. * @throws PropelException
  704. * @see doSave()
  705. */
  706. protected function doInsert(PropelPDO $con)
  707. {
  708. $modifiedColumns = array();
  709. $index = 0;
  710.  
  711. $this->modifiedColumns[] = ArticlePeer::ID;
  712. if (null !== $this->id) {
  713. throw new PropelException('Cannot insert a value for auto-increment primary key (' . ArticlePeer::ID . ')');
  714. }
  715.  
  716. // check the columns in natural order for more readable SQL queries
  717. if ($this->isColumnModified(ArticlePeer::ID)) {
  718. $modifiedColumns[':p' . $index++] = '`id`';
  719. }
  720. if ($this->isColumnModified(ArticlePeer::ACTIVE)) {
  721. $modifiedColumns[':p' . $index++] = '`active`';
  722. }
  723. if ($this->isColumnModified(ArticlePeer::ALIAS)) {
  724. $modifiedColumns[':p' . $index++] = '`alias`';
  725. }
  726. if ($this->isColumnModified(ArticlePeer::SITE_MODULE_ID)) {
  727. $modifiedColumns[':p' . $index++] = '`site_module_id`';
  728. }
  729. if ($this->isColumnModified(ArticlePeer::TREE_LEFT)) {
  730. $modifiedColumns[':p' . $index++] = '`tree_left`';
  731. }
  732. if ($this->isColumnModified(ArticlePeer::TREE_RIGHT)) {
  733. $modifiedColumns[':p' . $index++] = '`tree_right`';
  734. }
  735. if ($this->isColumnModified(ArticlePeer::TREE_LEVEL)) {
  736. $modifiedColumns[':p' . $index++] = '`tree_level`';
  737. }
  738.  
  739. $sql = sprintf(
  740. 'INSERT INTO `article` (%s) VALUES (%s)',
  741. implode(', ', $modifiedColumns),
  742. implode(', ', array_keys($modifiedColumns))
  743. );
  744.  
  745. try {
  746. $stmt = $con->prepare($sql);
  747. foreach ($modifiedColumns as $identifier => $columnName) {
  748. switch ($columnName) {
  749. case '`id`':
  750. $stmt->bindValue($identifier, $this->id, PDO::PARAM_STR);
  751. break;
  752. case '`active`':
  753. $stmt->bindValue($identifier, (int) $this->active, PDO::PARAM_INT);
  754. break;
  755. case '`alias`':
  756. $stmt->bindValue($identifier, $this->alias, PDO::PARAM_STR);
  757. break;
  758. case '`site_module_id`':
  759. $stmt->bindValue($identifier, $this->site_module_id, PDO::PARAM_INT);
  760. break;
  761. case '`tree_left`':
  762. $stmt->bindValue($identifier, $this->tree_left, PDO::PARAM_INT);
  763. break;
  764. case '`tree_right`':
  765. $stmt->bindValue($identifier, $this->tree_right, PDO::PARAM_INT);
  766. break;
  767. case '`tree_level`':
  768. $stmt->bindValue($identifier, $this->tree_level, PDO::PARAM_INT);
  769. break;
  770. }
  771. }
  772. $stmt->execute();
  773. } catch (Exception $e) {
  774. Propel::log($e->getMessage(), Propel::LOG_ERR);
  775. throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e);
  776. }
  777.  
  778. try {
  779. $pk = $con->lastInsertId();
  780. } catch (Exception $e) {
  781. throw new PropelException('Unable to get autoincrement id.', $e);
  782. }
  783. $this->setId($pk);
  784.  
  785. $this->setNew(false);
  786. }
  787.  
  788. /**
  789. * Update the row in the database.
  790. *
  791. * @param PropelPDO $con
  792. *
  793. * @see doSave()
  794. */
  795. protected function doUpdate(PropelPDO $con)
  796. {
  797. $selectCriteria = $this->buildPkeyCriteria();
  798. $valuesCriteria = $this->buildCriteria();
  799. BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con);
  800. }
  801.  
  802. /**
  803. * Array of ValidationFailed objects.
  804. * @var array ValidationFailed[]
  805. */
  806. protected $validationFailures = array();
  807.  
  808. /**
  809. * Gets any ValidationFailed objects that resulted from last call to validate().
  810. *
  811. *
  812. * @return array ValidationFailed[]
  813. * @see validate()
  814. */
  815. public function getValidationFailures()
  816. {
  817. return $this->validationFailures;
  818. }
  819.  
  820. /**
  821. * Validates the objects modified field values and all objects related to this table.
  822. *
  823. * If $columns is either a column name or an array of column names
  824. * only those columns are validated.
  825. *
  826. * @param mixed $columns Column name or an array of column names.
  827. * @return boolean Whether all columns pass validation.
  828. * @see doValidate()
  829. * @see getValidationFailures()
  830. */
  831. public function validate($columns = null)
  832. {
  833. $res = $this->doValidate($columns);
  834. if ($res === true) {
  835. $this->validationFailures = array();
  836.  
  837. return true;
  838. }
  839.  
  840. $this->validationFailures = $res;
  841.  
  842. return false;
  843. }
  844.  
  845. /**
  846. * This function performs the validation work for complex object models.
  847. *
  848. * In addition to checking the current object, all related objects will
  849. * also be validated. If all pass then <code>true</code> is returned; otherwise
  850. * an aggregated array of ValidationFailed objects will be returned.
  851. *
  852. * @param array $columns Array of column names to validate.
  853. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise.
  854. */
  855. protected function doValidate($columns = null)
  856. {
  857. if (!$this->alreadyInValidation) {
  858. $this->alreadyInValidation = true;
  859. $retval = null;
  860.  
  861. $failureMap = array();
  862.  
  863.  
  864. // We call the validate method on the following object(s) if they
  865. // were passed to this object by their corresponding set
  866. // method. This object relates to these object(s) by a
  867. // foreign key reference.
  868.  
  869. if ($this->aSiteModule !== null) {
  870. if (!$this->aSiteModule->validate($columns)) {
  871. $failureMap = array_merge($failureMap, $this->aSiteModule->getValidationFailures());
  872. }
  873. }
  874.  
  875.  
  876. if (($retval = ArticlePeer::doValidate($this, $columns)) !== true) {
  877. $failureMap = array_merge($failureMap, $retval);
  878. }
  879.  
  880.  
  881. if ($this->collArticleI18ns !== null) {
  882. foreach ($this->collArticleI18ns as $referrerFK) {
  883. if (!$referrerFK->validate($columns)) {
  884. $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
  885. }
  886. }
  887. }
  888.  
  889.  
  890. $this->alreadyInValidation = false;
  891. }
  892.  
  893. return (!empty($failureMap) ? $failureMap : true);
  894. }
  895.  
  896. /**
  897. * Retrieves a field from the object by name passed in as a string.
  898. *
  899. * @param string $name name
  900. * @param string $type The type of fieldname the $name is of:
  901. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  902. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  903. * Defaults to BasePeer::TYPE_PHPNAME
  904. * @return mixed Value of field.
  905. */
  906. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  907. {
  908. $pos = ArticlePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  909. $field = $this->getByPosition($pos);
  910.  
  911. return $field;
  912. }
  913.  
  914. /**
  915. * Retrieves a field from the object by Position as specified in the xml schema.
  916. * Zero-based.
  917. *
  918. * @param int $pos position in xml schema
  919. * @return mixed Value of field at $pos
  920. */
  921. public function getByPosition($pos)
  922. {
  923. switch ($pos) {
  924. case 0:
  925. return $this->getId();
  926. break;
  927. case 1:
  928. return $this->getActive();
  929. break;
  930. case 2:
  931. return $this->getAlias();
  932. break;
  933. case 3:
  934. return $this->getSiteModuleId();
  935. break;
  936. case 4:
  937. return $this->getTreeLeft();
  938. break;
  939. case 5:
  940. return $this->getTreeRight();
  941. break;
  942. case 6:
  943. return $this->getTreeLevel();
  944. break;
  945. default:
  946. return null;
  947. break;
  948. } // switch()
  949. }
  950.  
  951. /**
  952. * Exports the object as an array.
  953. *
  954. * You can specify the key type of the array by passing one of the class
  955. * type constants.
  956. *
  957. * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  958. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  959. * Defaults to BasePeer::TYPE_PHPNAME.
  960. * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
  961. * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
  962. * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  963. *
  964. * @return array an associative array containing the field names (as keys) and field values
  965. */
  966. public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
  967. {
  968. if (isset($alreadyDumpedObjects['Article'][$this->getPrimaryKey()])) {
  969. return '*RECURSION*';
  970. }
  971. $alreadyDumpedObjects['Article'][$this->getPrimaryKey()] = true;
  972. $keys = ArticlePeer::getFieldNames($keyType);
  973. $result = array(
  974. $keys[0] => $this->getId(),
  975. $keys[1] => $this->getActive(),
  976. $keys[2] => $this->getAlias(),
  977. $keys[3] => $this->getSiteModuleId(),
  978. $keys[4] => $this->getTreeLeft(),
  979. $keys[5] => $this->getTreeRight(),
  980. $keys[6] => $this->getTreeLevel(),
  981. );
  982. $virtualColumns = $this->virtualColumns;
  983. foreach ($virtualColumns as $key => $virtualColumn) {
  984. $result[$key] = $virtualColumn;
  985. }
  986.  
  987. if ($includeForeignObjects) {
  988. if (null !== $this->aSiteModule) {
  989. $result['SiteModule'] = $this->aSiteModule->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
  990. }
  991. if (null !== $this->collArticleI18ns) {
  992. $result['ArticleI18ns'] = $this->collArticleI18ns->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
  993. }
  994. }
  995.  
  996. return $result;
  997. }
  998.  
  999. /**
  1000. * Sets a field from the object by name passed in as a string.
  1001. *
  1002. * @param string $name peer name
  1003. * @param mixed $value field value
  1004. * @param string $type The type of fieldname the $name is of:
  1005. * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  1006. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  1007. * Defaults to BasePeer::TYPE_PHPNAME
  1008. * @return void
  1009. */
  1010. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  1011. {
  1012. $pos = ArticlePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  1013.  
  1014. $this->setByPosition($pos, $value);
  1015. }
  1016.  
  1017. /**
  1018. * Sets a field from the object by Position as specified in the xml schema.
  1019. * Zero-based.
  1020. *
  1021. * @param int $pos position in xml schema
  1022. * @param mixed $value field value
  1023. * @return void
  1024. */
  1025. public function setByPosition($pos, $value)
  1026. {
  1027. switch ($pos) {
  1028. case 0:
  1029. $this->setId($value);
  1030. break;
  1031. case 1:
  1032. $this->setActive($value);
  1033. break;
  1034. case 2:
  1035. $this->setAlias($value);
  1036. break;
  1037. case 3:
  1038. $this->setSiteModuleId($value);
  1039. break;
  1040. case 4:
  1041. $this->setTreeLeft($value);
  1042. break;
  1043. case 5:
  1044. $this->setTreeRight($value);
  1045. break;
  1046. case 6:
  1047. $this->setTreeLevel($value);
  1048. break;
  1049. } // switch()
  1050. }
  1051.  
  1052. /**
  1053. * Populates the object using an array.
  1054. *
  1055. * This is particularly useful when populating an object from one of the
  1056. * request arrays (e.g. $_POST). This method goes through the column
  1057. * names, checking to see whether a matching key exists in populated
  1058. * array. If so the setByName() method is called for that column.
  1059. *
  1060. * You can specify the key type of the array by additionally passing one
  1061. * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  1062. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  1063. * The default key type is the column's BasePeer::TYPE_PHPNAME
  1064. *
  1065. * @param array $arr An array to populate the object from.
  1066. * @param string $keyType The type of keys the array uses.
  1067. * @return void
  1068. */
  1069. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  1070. {
  1071. $keys = ArticlePeer::getFieldNames($keyType);
  1072.  
  1073. if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
  1074. if (array_key_exists($keys[1], $arr)) $this->setActive($arr[$keys[1]]);
  1075. if (array_key_exists($keys[2], $arr)) $this->setAlias($arr[$keys[2]]);
  1076. if (array_key_exists($keys[3], $arr)) $this->setSiteModuleId($arr[$keys[3]]);
  1077. if (array_key_exists($keys[4], $arr)) $this->setTreeLeft($arr[$keys[4]]);
  1078. if (array_key_exists($keys[5], $arr)) $this->setTreeRight($arr[$keys[5]]);
  1079. if (array_key_exists($keys[6], $arr)) $this->setTreeLevel($arr[$keys[6]]);
  1080. }
  1081.  
  1082. /**
  1083. * Build a Criteria object containing the values of all modified columns in this object.
  1084. *
  1085. * @return Criteria The Criteria object containing all modified values.
  1086. */
  1087. public function buildCriteria()
  1088. {
  1089. $criteria = new Criteria(ArticlePeer::DATABASE_NAME);
  1090.  
  1091. if ($this->isColumnModified(ArticlePeer::ID)) $criteria->add(ArticlePeer::ID, $this->id);
  1092. if ($this->isColumnModified(ArticlePeer::ACTIVE)) $criteria->add(ArticlePeer::ACTIVE, $this->active);
  1093. if ($this->isColumnModified(ArticlePeer::ALIAS)) $criteria->add(ArticlePeer::ALIAS, $this->alias);
  1094. if ($this->isColumnModified(ArticlePeer::SITE_MODULE_ID)) $criteria->add(ArticlePeer::SITE_MODULE_ID, $this->site_module_id);
  1095. if ($this->isColumnModified(ArticlePeer::TREE_LEFT)) $criteria->add(ArticlePeer::TREE_LEFT, $this->tree_left);
  1096. if ($this->isColumnModified(ArticlePeer::TREE_RIGHT)) $criteria->add(ArticlePeer::TREE_RIGHT, $this->tree_right);
  1097. if ($this->isColumnModified(ArticlePeer::TREE_LEVEL)) $criteria->add(ArticlePeer::TREE_LEVEL, $this->tree_level);
  1098.  
  1099. return $criteria;
  1100. }
  1101.  
  1102. /**
  1103. * Builds a Criteria object containing the primary key for this object.
  1104. *
  1105. * Unlike buildCriteria() this method includes the primary key values regardless
  1106. * of whether or not they have been modified.
  1107. *
  1108. * @return Criteria The Criteria object containing value(s) for primary key(s).
  1109. */
  1110. public function buildPkeyCriteria()
  1111. {
  1112. $criteria = new Criteria(ArticlePeer::DATABASE_NAME);
  1113. $criteria->add(ArticlePeer::ID, $this->id);
  1114.  
  1115. return $criteria;
  1116. }
  1117.  
  1118. /**
  1119. * Returns the primary key for this object (row).
  1120. * @return string
  1121. */
  1122. public function getPrimaryKey()
  1123. {
  1124. return $this->getId();
  1125. }
  1126.  
  1127. /**
  1128. * Generic method to set the primary key (id column).
  1129. *
  1130. * @param string $key Primary key.
  1131. * @return void
  1132. */
  1133. public function setPrimaryKey($key)
  1134. {
  1135. $this->setId($key);
  1136. }
  1137.  
  1138. /**
  1139. * Returns true if the primary key for this object is null.
  1140. * @return boolean
  1141. */
  1142. public function isPrimaryKeyNull()
  1143. {
  1144.  
  1145. return null === $this->getId();
  1146. }
  1147.  
  1148. /**
  1149. * Sets contents of passed object to values from current object.
  1150. *
  1151. * If desired, this method can also make copies of all associated (fkey referrers)
  1152. * objects.
  1153. *
  1154. * @param object $copyObj An object of Article (or compatible) type.
  1155. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  1156. * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new.
  1157. * @throws PropelException
  1158. */
  1159. public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
  1160. {
  1161. $copyObj->setActive($this->getActive());
  1162. $copyObj->setAlias($this->getAlias());
  1163. $copyObj->setSiteModuleId($this->getSiteModuleId());
  1164. $copyObj->setTreeLeft($this->getTreeLeft());
  1165. $copyObj->setTreeRight($this->getTreeRight());
  1166. $copyObj->setTreeLevel($this->getTreeLevel());
  1167.  
  1168. if ($deepCopy && !$this->startCopy) {
  1169. // important: temporarily setNew(false) because this affects the behavior of
  1170. // the getter/setter methods for fkey referrer objects.
  1171. $copyObj->setNew(false);
  1172. // store object hash to prevent cycle
  1173. $this->startCopy = true;
  1174.  
  1175. foreach ($this->getArticleI18ns() as $relObj) {
  1176. if ($relObj !== $this) { // ensure that we don't try to copy a reference to ourselves
  1177. $copyObj->addArticleI18n($relObj->copy($deepCopy));
  1178. }
  1179. }
  1180.  
  1181. //unflag object copy
  1182. $this->startCopy = false;
  1183. } // if ($deepCopy)
  1184.  
  1185. if ($makeNew) {
  1186. $copyObj->setNew(true);
  1187. $copyObj->setId(NULL); // this is a auto-increment column, so set to default value
  1188. }
  1189. }
  1190.  
  1191. /**
  1192. * Makes a copy of this object that will be inserted as a new row in table when saved.
  1193. * It creates a new object filling in the simple attributes, but skipping any primary
  1194. * keys that are defined for the table.
  1195. *
  1196. * If desired, this method can also make copies of all associated (fkey referrers)
  1197. * objects.
  1198. *
  1199. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  1200. * @return Article Clone of current object.
  1201. * @throws PropelException
  1202. */
  1203. public function copy($deepCopy = false)
  1204. {
  1205. // we use get_class(), because this might be a subclass
  1206. $clazz = get_class($this);
  1207. $copyObj = new $clazz();
  1208. $this->copyInto($copyObj, $deepCopy);
  1209.  
  1210. return $copyObj;
  1211. }
  1212.  
  1213. /**
  1214. * Returns a peer instance associated with this om.
  1215. *
  1216. * Since Peer classes are not to have any instance attributes, this method returns the
  1217. * same instance for all member of this class. The method could therefore
  1218. * be static, but this would prevent one from overriding the behavior.
  1219. *
  1220. * @return ArticlePeer
  1221. */
  1222. public function getPeer()
  1223. {
  1224. if (self::$peer === null) {
  1225. self::$peer = new ArticlePeer();
  1226. }
  1227.  
  1228. return self::$peer;
  1229. }
  1230.  
  1231. /**
  1232. * Declares an association between this object and a SiteModule object.
  1233. *
  1234. * @param SiteModule $v
  1235. * @return Article The current object (for fluent API support)
  1236. * @throws PropelException
  1237. */
  1238. public function setSiteModule(SiteModule $v = null)
  1239. {
  1240. if ($v === null) {
  1241. $this->setSiteModuleId(NULL);
  1242. } else {
  1243. $this->setSiteModuleId($v->getId());
  1244. }
  1245.  
  1246. $this->aSiteModule = $v;
  1247.  
  1248. // Add binding for other direction of this n:n relationship.
  1249. // If this object has already been added to the SiteModule object, it will not be re-added.
  1250. if ($v !== null) {
  1251. $v->addArticle($this);
  1252. }
  1253.  
  1254.  
  1255. return $this;
  1256. }
  1257.  
  1258.  
  1259. /**
  1260. * Get the associated SiteModule object
  1261. *
  1262. * @param PropelPDO $con Optional Connection object.
  1263. * @param $doQuery Executes a query to get the object if required
  1264. * @return SiteModule The associated SiteModule object.
  1265. * @throws PropelException
  1266. */
  1267. public function getSiteModule(PropelPDO $con = null, $doQuery = true)
  1268. {
  1269. if ($this->aSiteModule === null && ($this->site_module_id !== null) && $doQuery) {
  1270. $this->aSiteModule = SiteModuleQuery::create()->findPk($this->site_module_id, $con);
  1271. /* The following can be used additionally to
  1272. guarantee the related object contains a reference
  1273. to this object. This level of coupling may, however, be
  1274. undesirable since it could result in an only partially populated collection
  1275. in the referenced object.
  1276. $this->aSiteModule->addArticles($this);
  1277. */
  1278. }
  1279.  
  1280. return $this->aSiteModule;
  1281. }
  1282.  
  1283.  
  1284. /**
  1285. * Initializes a collection based on the name of a relation.
  1286. * Avoids crafting an 'init[$relationName]s' method name
  1287. * that wouldn't work when StandardEnglishPluralizer is used.
  1288. *
  1289. * @param string $relationName The name of the relation to initialize
  1290. * @return void
  1291. */
  1292. public function initRelation($relationName)
  1293. {
  1294. if ('ArticleI18n' == $relationName) {
  1295. $this->initArticleI18ns();
  1296. }
  1297. }
  1298.  
  1299. /**
  1300. * Clears out the collArticleI18ns collection
  1301. *
  1302. * This does not modify the database; however, it will remove any associated objects, causing
  1303. * them to be refetched by subsequent calls to accessor method.
  1304. *
  1305. * @return Article The current object (for fluent API support)
  1306. * @see addArticleI18ns()
  1307. */
  1308. public function clearArticleI18ns()
  1309. {
  1310. $this->collArticleI18ns = null; // important to set this to null since that means it is uninitialized
  1311. $this->collArticleI18nsPartial = null;
  1312.  
  1313. return $this;
  1314. }
  1315.  
  1316. /**
  1317. * reset is the collArticleI18ns collection loaded partially
  1318. *
  1319. * @return void
  1320. */
  1321. public function resetPartialArticleI18ns($v = true)
  1322. {
  1323. $this->collArticleI18nsPartial = $v;
  1324. }
  1325.  
  1326. /**
  1327. * Initializes the collArticleI18ns collection.
  1328. *
  1329. * By default this just sets the collArticleI18ns collection to an empty array (like clearcollArticleI18ns());
  1330. * however, you may wish to override this method in your stub class to provide setting appropriate
  1331. * to your application -- for example, setting the initial array to the values stored in database.
  1332. *
  1333. * @param boolean $overrideExisting If set to true, the method call initializes
  1334. * the collection even if it is not empty
  1335. *
  1336. * @return void
  1337. */
  1338. public function initArticleI18ns($overrideExisting = true)
  1339. {
  1340. if (null !== $this->collArticleI18ns && !$overrideExisting) {
  1341. return;
  1342. }
  1343. $this->collArticleI18ns = new PropelObjectCollection();
  1344. $this->collArticleI18ns->setModel('ArticleI18n');
  1345. }
  1346.  
  1347. /**
  1348. * Gets an array of ArticleI18n objects which contain a foreign key that references this object.
  1349. *
  1350. * If the $criteria is not null, it is used to always fetch the results from the database.
  1351. * Otherwise the results are fetched from the database the first time, then cached.
  1352. * Next time the same method is called without $criteria, the cached collection is returned.
  1353. * If this Article is new, it will return
  1354. * an empty collection or the current collection; the criteria is ignored on a new object.
  1355. *
  1356. * @param Criteria $criteria optional Criteria object to narrow the query
  1357. * @param PropelPDO $con optional connection object
  1358. * @return PropelObjectCollection|ArticleI18n[] List of ArticleI18n objects
  1359. * @throws PropelException
  1360. */
  1361. public function getArticleI18ns($criteria = null, PropelPDO $con = null)
  1362. {
  1363. $partial = $this->collArticleI18nsPartial && !$this->isNew();
  1364. if (null === $this->collArticleI18ns || null !== $criteria || $partial) {
  1365. if ($this->isNew() && null === $this->collArticleI18ns) {
  1366. // return empty collection
  1367. $this->initArticleI18ns();
  1368. } else {
  1369. $collArticleI18ns = ArticleI18nQuery::create(null, $criteria)
  1370. ->filterByArticle($this)
  1371. ->find($con);
  1372. if (null !== $criteria) {
  1373. if (false !== $this->collArticleI18nsPartial && count($collArticleI18ns)) {
  1374. $this->initArticleI18ns(false);
  1375.  
  1376. foreach ($collArticleI18ns as $obj) {
  1377. if (false == $this->collArticleI18ns->contains($obj)) {
  1378. $this->collArticleI18ns->append($obj);
  1379. }
  1380. }
  1381.  
  1382. $this->collArticleI18nsPartial = true;
  1383. }
  1384.  
  1385. $collArticleI18ns->getInternalIterator()->rewind();
  1386.  
  1387. return $collArticleI18ns;
  1388. }
  1389.  
  1390. if ($partial && $this->collArticleI18ns) {
  1391. foreach ($this->collArticleI18ns as $obj) {
  1392. if ($obj->isNew()) {
  1393. $collArticleI18ns[] = $obj;
  1394. }
  1395. }
  1396. }
  1397.  
  1398. $this->collArticleI18ns = $collArticleI18ns;
  1399. $this->collArticleI18nsPartial = false;
  1400. }
  1401. }
  1402.  
  1403. return $this->collArticleI18ns;
  1404. }
  1405.  
  1406. /**
  1407. * Sets a collection of ArticleI18n objects related by a one-to-many relationship
  1408. * to the current object.
  1409. * It will also schedule objects for deletion based on a diff between old objects (aka persisted)
  1410. * and new objects from the given Propel collection.
  1411. *
  1412. * @param PropelCollection $articleI18ns A Propel collection.
  1413. * @param PropelPDO $con Optional connection object
  1414. * @return Article The current object (for fluent API support)
  1415. */
  1416. public function setArticleI18ns(PropelCollection $articleI18ns, PropelPDO $con = null)
  1417. {
  1418. $articleI18nsToDelete = $this->getArticleI18ns(new Criteria(), $con)->diff($articleI18ns);
  1419.  
  1420.  
  1421. //since at least one column in the foreign key is at the same time a PK
  1422. //we can not just set a PK to NULL in the lines below. We have to store
  1423. //a backup of all values, so we are able to manipulate these items based on the onDelete value later.
  1424. $this->articleI18nsScheduledForDeletion = clone $articleI18nsToDelete;
  1425.  
  1426. foreach ($articleI18nsToDelete as $articleI18nRemoved) {
  1427. $articleI18nRemoved->setArticle(null);
  1428. }
  1429.  
  1430. $this->collArticleI18ns = null;
  1431. foreach ($articleI18ns as $articleI18n) {
  1432. $this->addArticleI18n($articleI18n);
  1433. }
  1434.  
  1435. $this->collArticleI18ns = $articleI18ns;
  1436. $this->collArticleI18nsPartial = false;
  1437.  
  1438. return $this;
  1439. }
  1440.  
  1441. /**
  1442. * Returns the number of related ArticleI18n objects.
  1443. *
  1444. * @param Criteria $criteria
  1445. * @param boolean $distinct
  1446. * @param PropelPDO $con
  1447. * @return int Count of related ArticleI18n objects.
  1448. * @throws PropelException
  1449. */
  1450. public function countArticleI18ns(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
  1451. {
  1452. $partial = $this->collArticleI18nsPartial && !$this->isNew();
  1453. if (null === $this->collArticleI18ns || null !== $criteria || $partial) {
  1454. if ($this->isNew() && null === $this->collArticleI18ns) {
  1455. return 0;
  1456. }
  1457.  
  1458. if ($partial && !$criteria) {
  1459. return count($this->getArticleI18ns());
  1460. }
  1461. $query = ArticleI18nQuery::create(null, $criteria);
  1462. if ($distinct) {
  1463. $query->distinct();
  1464. }
  1465.  
  1466. return $query
  1467. ->filterByArticle($this)
  1468. ->count($con);
  1469. }
  1470.  
  1471. return count($this->collArticleI18ns);
  1472. }
  1473.  
  1474. /**
  1475. * Method called to associate a ArticleI18n object to this object
  1476. * through the ArticleI18n foreign key attribute.
  1477. *
  1478. * @param ArticleI18n $l ArticleI18n
  1479. * @return Article The current object (for fluent API support)
  1480. */
  1481. public function addArticleI18n(ArticleI18n $l)
  1482. {
  1483. if ($l && $locale = $l->getLocale()) {
  1484. $this->setLocale($locale);
  1485. $this->currentTranslations[$locale] = $l;
  1486. }
  1487. if ($this->collArticleI18ns === null) {
  1488. $this->initArticleI18ns();
  1489. $this->collArticleI18nsPartial = true;
  1490. }
  1491.  
  1492. if (!in_array($l, $this->collArticleI18ns->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
  1493. $this->doAddArticleI18n($l);
  1494.  
  1495. if ($this->articleI18nsScheduledForDeletion and $this->articleI18nsScheduledForDeletion->contains($l)) {
  1496. $this->articleI18nsScheduledForDeletion->remove($this->articleI18nsScheduledForDeletion->search($l));
  1497. }
  1498. }
  1499.  
  1500. return $this;
  1501. }
  1502.  
  1503. /**
  1504. * @param ArticleI18n $articleI18n The articleI18n object to add.
  1505. */
  1506. protected function doAddArticleI18n($articleI18n)
  1507. {
  1508. $this->collArticleI18ns[]= $articleI18n;
  1509. $articleI18n->setArticle($this);
  1510. }
  1511.  
  1512. /**
  1513. * @param ArticleI18n $articleI18n The articleI18n object to remove.
  1514. * @return Article The current object (for fluent API support)
  1515. */
  1516. public function removeArticleI18n($articleI18n)
  1517. {
  1518. if ($this->getArticleI18ns()->contains($articleI18n)) {
  1519. $this->collArticleI18ns->remove($this->collArticleI18ns->search($articleI18n));
  1520. if (null === $this->articleI18nsScheduledForDeletion) {
  1521. $this->articleI18nsScheduledForDeletion = clone $this->collArticleI18ns;
  1522. $this->articleI18nsScheduledForDeletion->clear();
  1523. }
  1524. $this->articleI18nsScheduledForDeletion[]= clone $articleI18n;
  1525. $articleI18n->setArticle(null);
  1526. }
  1527.  
  1528. return $this;
  1529. }
  1530.  
  1531. /**
  1532. * Clears the current object and sets all attributes to their default values
  1533. */
  1534. public function clear()
  1535. {
  1536. $this->id = null;
  1537. $this->active = null;
  1538. $this->alias = null;
  1539. $this->site_module_id = null;
  1540. $this->tree_left = null;
  1541. $this->tree_right = null;
  1542. $this->tree_level = null;
  1543. $this->alreadyInSave = false;
  1544. $this->alreadyInValidation = false;
  1545. $this->alreadyInClearAllReferencesDeep = false;
  1546. $this->clearAllReferences();
  1547. $this->resetModified();
  1548. $this->setNew(true);
  1549. $this->setDeleted(false);
  1550. }
  1551.  
  1552. /**
  1553. * Resets all references to other model objects or collections of model objects.
  1554. *
  1555. * This method is a user-space workaround for PHP's inability to garbage collect
  1556. * objects with circular references (even in PHP 5.3). This is currently necessary
  1557. * when using Propel in certain daemon or large-volume/high-memory operations.
  1558. *
  1559. * @param boolean $deep Whether to also clear the references on all referrer objects.
  1560. */
  1561. public function clearAllReferences($deep = false)
  1562. {
  1563. if ($deep && !$this->alreadyInClearAllReferencesDeep) {
  1564. $this->alreadyInClearAllReferencesDeep = true;
  1565. if ($this->collArticleI18ns) {
  1566. foreach ($this->collArticleI18ns as $o) {
  1567. $o->clearAllReferences($deep);
  1568. }
  1569. }
  1570. if ($this->aSiteModule instanceof Persistent) {
  1571. $this->aSiteModule->clearAllReferences($deep);
  1572. }
  1573.  
  1574. $this->alreadyInClearAllReferencesDeep = false;
  1575. } // if ($deep)
  1576.  
  1577. // nested_set behavior
  1578. $this->collNestedSetChildren = null;
  1579. $this->aNestedSetParent = null;
  1580. // i18n behavior
  1581. $this->currentLocale = 'en_US';
  1582. $this->currentTranslations = null;
  1583.  
  1584. if ($this->collArticleI18ns instanceof PropelCollection) {
  1585. $this->collArticleI18ns->clearIterator();
  1586. }
  1587. $this->collArticleI18ns = null;
  1588. $this->aSiteModule = null;
  1589. }
  1590.  
  1591. /**
  1592. * return the string representation of this object
  1593. *
  1594. * @return string
  1595. */
  1596. public function __toString()
  1597. {
  1598. return (string) $this->exportTo(ArticlePeer::DEFAULT_STRING_FORMAT);
  1599. }
  1600.  
  1601. /**
  1602. * return true is the object is in saving state
  1603. *
  1604. * @return boolean
  1605. */
  1606. public function isAlreadyInSave()
  1607. {
  1608. return $this->alreadyInSave;
  1609. }
  1610.  
  1611. // nested_set behavior
  1612.  
  1613. /**
  1614. * Execute queries that were saved to be run inside the save transaction
  1615. */
  1616. protected function processNestedSetQueries($con)
  1617. {
  1618. foreach ($this->nestedSetQueries as $query) {
  1619. $query['arguments'][]= $con;
  1620. call_user_func_array($query['callable'], $query['arguments']);
  1621. }
  1622. $this->nestedSetQueries = array();
  1623. }
  1624.  
  1625. /**
  1626. * Proxy getter method for the left value of the nested set model.
  1627. * It provides a generic way to get the value, whatever the actual column name is.
  1628. *
  1629. * @return int The nested set left value
  1630. */
  1631. public function getLeftValue()
  1632. {
  1633. return $this->tree_left;
  1634. }
  1635.  
  1636. /**
  1637. * Proxy getter method for the right value of the nested set model.
  1638. * It provides a generic way to get the value, whatever the actual column name is.
  1639. *
  1640. * @return int The nested set right value
  1641. */
  1642. public function getRightValue()
  1643. {
  1644. return $this->tree_right;
  1645. }
  1646.  
  1647. /**
  1648. * Proxy getter method for the level value of the nested set model.
  1649. * It provides a generic way to get the value, whatever the actual column name is.
  1650. *
  1651. * @return int The nested set level value
  1652. */
  1653. public function getLevel()
  1654. {
  1655. return $this->tree_level;
  1656. }
  1657.  
  1658. /**
  1659. * Proxy setter method for the left value of the nested set model.
  1660. * It provides a generic way to set the value, whatever the actual column name is.
  1661. *
  1662. * @param int $v The nested set left value
  1663. * @return Article The current object (for fluent API support)
  1664. */
  1665. public function setLeftValue($v)
  1666. {
  1667. return $this->setTreeLeft($v);
  1668. }
  1669.  
  1670. /**
  1671. * Proxy setter method for the right value of the nested set model.
  1672. * It provides a generic way to set the value, whatever the actual column name is.
  1673. *
  1674. * @param int $v The nested set right value
  1675. * @return Article The current object (for fluent API support)
  1676. */
  1677. public function setRightValue($v)
  1678. {
  1679. return $this->setTreeRight($v);
  1680. }
  1681.  
  1682. /**
  1683. * Proxy setter method for the level value of the nested set model.
  1684. * It provides a generic way to set the value, whatever the actual column name is.
  1685. *
  1686. * @param int $v The nested set level value
  1687. * @return Article The current object (for fluent API support)
  1688. */
  1689. public function setLevel($v)
  1690. {
  1691. return $this->setTreeLevel($v);
  1692. }
  1693.  
  1694. /**
  1695. * Creates the supplied node as the root node.
  1696. *
  1697. * @return Article The current object (for fluent API support)
  1698. * @throws PropelException
  1699. */
  1700. public function makeRoot()
  1701. {
  1702. if ($this->getLeftValue() || $this->getRightValue()) {
  1703. throw new PropelException('Cannot turn an existing node into a root node.');
  1704. }
  1705.  
  1706. $this->setLeftValue(1);
  1707. $this->setRightValue(2);
  1708. $this->setLevel(0);
  1709.  
  1710. return $this;
  1711. }
  1712.  
  1713. /**
  1714. * Tests if onbject is a node, i.e. if it is inserted in the tree
  1715. *
  1716. * @return bool
  1717. */
  1718. public function isInTree()
  1719. {
  1720. return $this->getLeftValue() > 0 && $this->getRightValue() > $this->getLeftValue();
  1721. }
  1722.  
  1723. /**
  1724. * Tests if node is a root
  1725. *
  1726. * @return bool
  1727. */
  1728. public function isRoot()
  1729. {
  1730. return $this->isInTree() && $this->getLeftValue() == 1;
  1731. }
  1732.  
  1733. /**
  1734. * Tests if node is a leaf
  1735. *
  1736. * @return bool
  1737. */
  1738. public function isLeaf()
  1739. {
  1740. return $this->isInTree() && ($this->getRightValue() - $this->getLeftValue()) == 1;
  1741. }
  1742.  
  1743. /**
  1744. * Tests if node is a descendant of another node
  1745. *
  1746. * @param Article $node Propel node object
  1747. * @return bool
  1748. */
  1749. public function isDescendantOf($parent)
  1750. {
  1751.  
  1752. return $this->isInTree() && $this->getLeftValue() > $parent->getLeftValue() && $this->getRightValue() < $parent->getRightValue();
  1753. }
  1754.  
  1755. /**
  1756. * Tests if node is a ancestor of another node
  1757. *
  1758. * @param Article $node Propel node object
  1759. * @return bool
  1760. */
  1761. public function isAncestorOf($child)
  1762. {
  1763. return $child->isDescendantOf($this);
  1764. }
  1765.  
  1766. /**
  1767. * Tests if object has an ancestor
  1768. *
  1769. * @param PropelPDO $con Connection to use.
  1770. * @return bool
  1771. */
  1772. public function hasParent(PropelPDO $con = null)
  1773. {
  1774. return $this->getLevel() > 0;
  1775. }
  1776.  
  1777. /**
  1778. * Sets the cache for parent node of the current object.
  1779. * Warning: this does not move the current object in the tree.
  1780. * Use moveTofirstChildOf() or moveToLastChildOf() for that purpose
  1781. *
  1782. * @param Article $parent
  1783. * @return Article The current object, for fluid interface
  1784. */
  1785. public function setParent($parent = null)
  1786. {
  1787. $this->aNestedSetParent = $parent;
  1788.  
  1789. return $this;
  1790. }
  1791.  
  1792. /**
  1793. * Gets parent node for the current object if it exists
  1794. * The result is cached so further calls to the same method don't issue any queries
  1795. *
  1796. * @param PropelPDO $con Connection to use.
  1797. * @return mixed Propel object if exists else false
  1798. */
  1799. public function getParent(PropelPDO $con = null)
  1800. {
  1801. if ($this->aNestedSetParent === null && $this->hasParent()) {
  1802. $this->aNestedSetParent = ArticleQuery::create()
  1803. ->ancestorsOf($this)
  1804. ->orderByLevel(true)
  1805. ->findOne($con);
  1806. }
  1807.  
  1808. return $this->aNestedSetParent;
  1809. }
  1810.  
  1811. /**
  1812. * Determines if the node has previous sibling
  1813. *
  1814. * @param PropelPDO $con Connection to use.
  1815. * @return bool
  1816. */
  1817. public function hasPrevSibling(PropelPDO $con = null)
  1818. {
  1819. if (!ArticlePeer::isValid($this)) {
  1820. return false;
  1821. }
  1822.  
  1823. return ArticleQuery::create()
  1824. ->filterByTreeRight($this->getLeftValue() - 1)
  1825. ->count($con) > 0;
  1826. }
  1827.  
  1828. /**
  1829. * Gets previous sibling for the given node if it exists
  1830. *
  1831. * @param PropelPDO $con Connection to use.
  1832. * @return mixed Propel object if exists else false
  1833. */
  1834. public function getPrevSibling(PropelPDO $con = null)
  1835. {
  1836. return ArticleQuery::create()
  1837. ->filterByTreeRight($this->getLeftValue() - 1)
  1838. ->findOne($con);
  1839. }
  1840.  
  1841. /**
  1842. * Determines if the node has next sibling
  1843. *
  1844. * @param PropelPDO $con Connection to use.
  1845. * @return bool
  1846. */
  1847. public function hasNextSibling(PropelPDO $con = null)
  1848. {
  1849. if (!ArticlePeer::isValid($this)) {
  1850. return false;
  1851. }
  1852.  
  1853. return ArticleQuery::create()
  1854. ->filterByTreeLeft($this->getRightValue() + 1)
  1855. ->count($con) > 0;
  1856. }
  1857.  
  1858. /**
  1859. * Gets next sibling for the given node if it exists
  1860. *
  1861. * @param PropelPDO $con Connection to use.
  1862. * @return mixed Propel object if exists else false
  1863. */
  1864. public function getNextSibling(PropelPDO $con = null)
  1865. {
  1866. return ArticleQuery::create()
  1867. ->filterByTreeLeft($this->getRightValue() + 1)
  1868. ->findOne($con);
  1869. }
  1870.  
  1871. /**
  1872. * Clears out the $collNestedSetChildren collection
  1873. *
  1874. * This does not modify the database; however, it will remove any associated objects, causing
  1875. * them to be refetched by subsequent calls to accessor method.
  1876. *
  1877. * @return void
  1878. */
  1879. public function clearNestedSetChildren()
  1880. {
  1881. $this->collNestedSetChildren = null;
  1882. }
  1883.  
  1884. /**
  1885. * Initializes the $collNestedSetChildren collection.
  1886. *
  1887. * @return void
  1888. */
  1889. public function initNestedSetChildren()
  1890. {
  1891. $this->collNestedSetChildren = new PropelObjectCollection();
  1892. $this->collNestedSetChildren->setModel('Article');
  1893. }
  1894.  
  1895. /**
  1896. * Adds an element to the internal $collNestedSetChildren collection.
  1897. * Beware that this doesn't insert a node in the tree.
  1898. * This method is only used to facilitate children hydration.
  1899. *
  1900. * @param Article $article
  1901. *
  1902. * @return void
  1903. */
  1904. public function addNestedSetChild($article)
  1905. {
  1906. if ($this->collNestedSetChildren === null) {
  1907. $this->initNestedSetChildren();
  1908. }
  1909. if (!in_array($article, $this->collNestedSetChildren->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
  1910. $this->collNestedSetChildren[]= $article;
  1911. $article->setParent($this);
  1912. }
  1913. }
  1914.  
  1915. /**
  1916. * Tests if node has children
  1917. *
  1918. * @return bool
  1919. */
  1920. public function hasChildren()
  1921. {
  1922. return ($this->getRightValue() - $this->getLeftValue()) > 1;
  1923. }
  1924.  
  1925. /**
  1926. * Gets the children of the given node
  1927. *
  1928. * @param Criteria $criteria Criteria to filter results.
  1929. * @param PropelPDO $con Connection to use.
  1930. * @return array List of Article objects
  1931. */
  1932. public function getChildren($criteria = null, PropelPDO $con = null)
  1933. {
  1934. if (null === $this->collNestedSetChildren || null !== $criteria) {
  1935. if ($this->isLeaf() || ($this->isNew() && null === $this->collNestedSetChildren)) {
  1936. // return empty collection
  1937. $this->initNestedSetChildren();
  1938. } else {
  1939. $collNestedSetChildren = ArticleQuery::create(null, $criteria)
  1940. ->childrenOf($this)
  1941. ->orderByBranch()
  1942. ->find($con);
  1943. if (null !== $criteria) {
  1944. return $collNestedSetChildren;
  1945. }
  1946. $this->collNestedSetChildren = $collNestedSetChildren;
  1947. }
  1948. }
  1949.  
  1950. return $this->collNestedSetChildren;
  1951. }
  1952.  
  1953. /**
  1954. * Gets number of children for the given node
  1955. *
  1956. * @param Criteria $criteria Criteria to filter results.
  1957. * @param PropelPDO $con Connection to use.
  1958. * @return int Number of children
  1959. */
  1960. public function countChildren($criteria = null, PropelPDO $con = null)
  1961. {
  1962. if (null === $this->collNestedSetChildren || null !== $criteria) {
  1963. if ($this->isLeaf() || ($this->isNew() && null === $this->collNestedSetChildren)) {
  1964. return 0;
  1965. } else {
  1966. return ArticleQuery::create(null, $criteria)
  1967. ->childrenOf($this)
  1968. ->count($con);
  1969. }
  1970. } else {
  1971. return count($this->collNestedSetChildren);
  1972. }
  1973. }
  1974.  
  1975. /**
  1976. * Gets the first child of the given node
  1977. *
  1978. * @param Criteria $query Criteria to filter results.
  1979. * @param PropelPDO $con Connection to use.
  1980. * @return array List of Article objects
  1981. */
  1982. public function getFirstChild($query = null, PropelPDO $con = null)
  1983. {
  1984. if ($this->isLeaf()) {
  1985. return array();
  1986. } else {
  1987. return ArticleQuery::create(null, $query)
  1988. ->childrenOf($this)
  1989. ->orderByBranch()
  1990. ->findOne($con);
  1991. }
  1992. }
  1993.  
  1994. /**
  1995. * Gets the last child of the given node
  1996. *
  1997. * @param Criteria $query Criteria to filter results.
  1998. * @param PropelPDO $con Connection to use.
  1999. * @return array List of Article objects
  2000. */
  2001. public function getLastChild($query = null, PropelPDO $con = null)
  2002. {
  2003. if ($this->isLeaf()) {
  2004. return array();
  2005. } else {
  2006. return ArticleQuery::create(null, $query)
  2007. ->childrenOf($this)
  2008. ->orderByBranch(true)
  2009. ->findOne($con);
  2010. }
  2011. }
  2012.  
  2013. /**
  2014. * Gets the siblings of the given node
  2015. *
  2016. * @param bool $includeNode Whether to include the current node or not
  2017. * @param Criteria $query Criteria to filter results.
  2018. * @param PropelPDO $con Connection to use.
  2019. *
  2020. * @return array List of Article objects
  2021. */
  2022. public function getSiblings($includeNode = false, $query = null, PropelPDO $con = null)
  2023. {
  2024. if ($this->isRoot()) {
  2025. return array();
  2026. } else {
  2027. $query = ArticleQuery::create(null, $query)
  2028. ->childrenOf($this->getParent($con))
  2029. ->orderByBranch();
  2030. if (!$includeNode) {
  2031. $query->prune($this);
  2032. }
  2033.  
  2034. return $query->find($con);
  2035. }
  2036. }
  2037.  
  2038. /**
  2039. * Gets descendants for the given node
  2040. *
  2041. * @param Criteria $query Criteria to filter results.
  2042. * @param PropelPDO $con Connection to use.
  2043. * @return array List of Article objects
  2044. */
  2045. public function getDescendants($query = null, PropelPDO $con = null)
  2046. {
  2047. if ($this->isLeaf()) {
  2048. return array();
  2049. } else {
  2050. return ArticleQuery::create(null, $query)
  2051. ->descendantsOf($this)
  2052. ->orderByBranch()
  2053. ->find($con);
  2054. }
  2055. }
  2056.  
  2057. /**
  2058. * Gets number of descendants for the given node
  2059. *
  2060. * @param Criteria $query Criteria to filter results.
  2061. * @param PropelPDO $con Connection to use.
  2062. * @return int Number of descendants
  2063. */
  2064. public function countDescendants($query = null, PropelPDO $con = null)
  2065. {
  2066. if ($this->isLeaf()) {
  2067. // save one query
  2068. return 0;
  2069. } else {
  2070. return ArticleQuery::create(null, $query)
  2071. ->descendantsOf($this)
  2072. ->count($con);
  2073. }
  2074. }
  2075.  
  2076. /**
  2077. * Gets descendants for the given node, plus the current node
  2078. *
  2079. * @param Criteria $query Criteria to filter results.
  2080. * @param PropelPDO $con Connection to use.
  2081. * @return array List of Article objects
  2082. */
  2083. public function getBranch($query = null, PropelPDO $con = null)
  2084. {
  2085. return ArticleQuery::create(null, $query)
  2086. ->branchOf($this)
  2087. ->orderByBranch()
  2088. ->find($con);
  2089. }
  2090.  
  2091. /**
  2092. * Gets ancestors for the given node, starting with the root node
  2093. * Use it for breadcrumb paths for instance
  2094. *
  2095. * @param Criteria $query Criteria to filter results.
  2096. * @param PropelPDO $con Connection to use.
  2097. * @return array List of Article objects
  2098. */
  2099. public function getAncestors($query = null, PropelPDO $con = null)
  2100. {
  2101. if ($this->isRoot()) {
  2102. // save one query
  2103. return array();
  2104. } else {
  2105. return ArticleQuery::create(null, $query)
  2106. ->ancestorsOf($this)
  2107. ->orderByBranch()
  2108. ->find($con);
  2109. }
  2110. }
  2111.  
  2112. /**
  2113. * Inserts the given $child node as first child of current
  2114. * The modifications in the current object and the tree
  2115. * are not persisted until the child object is saved.
  2116. *
  2117. * @param Article $child Propel object for child node
  2118. *
  2119. * @return Article The current Propel object
  2120. */
  2121. public function addChild(Article $child)
  2122. {
  2123. if ($this->isNew()) {
  2124. throw new PropelException('A Article object must not be new to accept children.');
  2125. }
  2126. $child->insertAsFirstChildOf($this);
  2127.  
  2128. return $this;
  2129. }
  2130.  
  2131. /**
  2132. * Inserts the current node as first child of given $parent node
  2133. * The modifications in the current object and the tree
  2134. * are not persisted until the current object is saved.
  2135. *
  2136. * @param Article $parent Propel object for parent node
  2137. *
  2138. * @return Article The current Propel object
  2139. */
  2140. public function insertAsFirstChildOf($parent)
  2141. {
  2142. if ($this->isInTree()) {
  2143. throw new PropelException('A Article object must not already be in the tree to be inserted. Use the moveToFirstChildOf() instead.');
  2144. }
  2145. $left = $parent->getLeftValue() + 1;
  2146. // Update node properties
  2147. $this->setLeftValue($left);
  2148. $this->setRightValue($left + 1);
  2149. $this->setLevel($parent->getLevel() + 1);
  2150. // update the children collection of the parent
  2151. $parent->addNestedSetChild($this);
  2152.  
  2153. // Keep the tree modification query for the save() transaction
  2154. $this->nestedSetQueries []= array(
  2155. 'callable' => array('\\Artsofte\MainBundle\Model\\ArticlePeer', 'makeRoomForLeaf'),
  2156. 'arguments' => array($left, $this->isNew() ? null : $this)
  2157. );
  2158.  
  2159. return $this;
  2160. }
  2161.  
  2162. /**
  2163. * Inserts the current node as last child of given $parent node
  2164. * The modifications in the current object and the tree
  2165. * are not persisted until the current object is saved.
  2166. *
  2167. * @param Article $parent Propel object for parent node
  2168. *
  2169. * @return Article The current Propel object
  2170. */
  2171. public function insertAsLastChildOf($parent)
  2172. {
  2173. if ($this->isInTree()) {
  2174. throw new PropelException('A Article object must not already be in the tree to be inserted. Use the moveToLastChildOf() instead.');
  2175. }
  2176. $left = $parent->getRightValue();
  2177. // Update node properties
  2178. $this->setLeftValue($left);
  2179. $this->setRightValue($left + 1);
  2180. $this->setLevel($parent->getLevel() + 1);
  2181. // update the children collection of the parent
  2182. $parent->addNestedSetChild($this);
  2183.  
  2184. // Keep the tree modification query for the save() transaction
  2185. $this->nestedSetQueries []= array(
  2186. 'callable' => array('\\Artsofte\MainBundle\Model\\ArticlePeer', 'makeRoomForLeaf'),
  2187. 'arguments' => array($left, $this->isNew() ? null : $this)
  2188. );
  2189.  
  2190. return $this;
  2191. }
  2192.  
  2193. /**
  2194. * Inserts the current node as prev sibling given $sibling node
  2195. * The modifications in the current object and the tree
  2196. * are not persisted until the current object is saved.
  2197. *
  2198. * @param Article $sibling Propel object for parent node
  2199. *
  2200. * @return Article The current Propel object
  2201. */
  2202. public function insertAsPrevSiblingOf($sibling)
  2203. {
  2204. if ($this->isInTree()) {
  2205. throw new PropelException('A Article object must not already be in the tree to be inserted. Use the moveToPrevSiblingOf() instead.');
  2206. }
  2207. $left = $sibling->getLeftValue();
  2208. // Update node properties
  2209. $this->setLeftValue($left);
  2210. $this->setRightValue($left + 1);
  2211. $this->setLevel($sibling->getLevel());
  2212. // Keep the tree modification query for the save() transaction
  2213. $this->nestedSetQueries []= array(
  2214. 'callable' => array('\\Artsofte\MainBundle\Model\\ArticlePeer', 'makeRoomForLeaf'),
  2215. 'arguments' => array($left, $this->isNew() ? null : $this)
  2216. );
  2217.  
  2218. return $this;
  2219. }
  2220.  
  2221. /**
  2222. * Inserts the current node as next sibling given $sibling node
  2223. * The modifications in the current object and the tree
  2224. * are not persisted until the current object is saved.
  2225. *
  2226. * @param Article $sibling Propel object for parent node
  2227. *
  2228. * @return Article The current Propel object
  2229. */
  2230. public function insertAsNextSiblingOf($sibling)
  2231. {
  2232. if ($this->isInTree()) {
  2233. throw new PropelException('A Article object must not already be in the tree to be inserted. Use the moveToNextSiblingOf() instead.');
  2234. }
  2235. $left = $sibling->getRightValue() + 1;
  2236. // Update node properties
  2237. $this->setLeftValue($left);
  2238. $this->setRightValue($left + 1);
  2239. $this->setLevel($sibling->getLevel());
  2240. // Keep the tree modification query for the save() transaction
  2241. $this->nestedSetQueries []= array(
  2242. 'callable' => array('\\Artsofte\MainBundle\Model\\ArticlePeer', 'makeRoomForLeaf'),
  2243. 'arguments' => array($left, $this->isNew() ? null : $this)
  2244. );
  2245.  
  2246. return $this;
  2247. }
  2248.  
  2249. /**
  2250. * Moves current node and its subtree to be the first child of $parent
  2251. * The modifications in the current object and the tree are immediate
  2252. *
  2253. * @param Article $parent Propel object for parent node
  2254. * @param PropelPDO $con Connection to use.
  2255. *
  2256. * @return Article The current Propel object
  2257. */
  2258. public function moveToFirstChildOf($parent, PropelPDO $con = null)
  2259. {
  2260. if (!$this->isInTree()) {
  2261. throw new PropelException('A Article object must be already in the tree to be moved. Use the insertAsFirstChildOf() instead.');
  2262. }
  2263. if ($parent->isDescendantOf($this)) {
  2264. throw new PropelException('Cannot move a node as child of one of its subtree nodes.');
  2265. }
  2266.  
  2267. $this->moveSubtreeTo($parent->getLeftValue() + 1, $parent->getLevel() - $this->getLevel() + 1, $con);
  2268.  
  2269. return $this;
  2270. }
  2271.  
  2272. /**
  2273. * Moves current node and its subtree to be the last child of $parent
  2274. * The modifications in the current object and the tree are immediate
  2275. *
  2276. * @param Article $parent Propel object for parent node
  2277. * @param PropelPDO $con Connection to use.
  2278. *
  2279. * @return Article The current Propel object
  2280. */
  2281. public function moveToLastChildOf($parent, PropelPDO $con = null)
  2282. {
  2283. if (!$this->isInTree()) {
  2284. throw new PropelException('A Article object must be already in the tree to be moved. Use the insertAsLastChildOf() instead.');
  2285. }
  2286. if ($parent->isDescendantOf($this)) {
  2287. throw new PropelException('Cannot move a node as child of one of its subtree nodes.');
  2288. }
  2289.  
  2290. $this->moveSubtreeTo($parent->getRightValue(), $parent->getLevel() - $this->getLevel() + 1, $con);
  2291.  
  2292. return $this;
  2293. }
  2294.  
  2295. /**
  2296. * Moves current node and its subtree to be the previous sibling of $sibling
  2297. * The modifications in the current object and the tree are immediate
  2298. *
  2299. * @param Article $sibling Propel object for sibling node
  2300. * @param PropelPDO $con Connection to use.
  2301. *
  2302. * @return Article The current Propel object
  2303. */
  2304. public function moveToPrevSiblingOf($sibling, PropelPDO $con = null)
  2305. {
  2306. if (!$this->isInTree()) {
  2307. throw new PropelException('A Article object must be already in the tree to be moved. Use the insertAsPrevSiblingOf() instead.');
  2308. }
  2309. if ($sibling->isRoot()) {
  2310. throw new PropelException('Cannot move to previous sibling of a root node.');
  2311. }
  2312. if ($sibling->isDescendantOf($this)) {
  2313. throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.');
  2314. }
  2315.  
  2316. $this->moveSubtreeTo($sibling->getLeftValue(), $sibling->getLevel() - $this->getLevel(), $con);
  2317.  
  2318. return $this;
  2319. }
  2320.  
  2321. /**
  2322. * Moves current node and its subtree to be the next sibling of $sibling
  2323. * The modifications in the current object and the tree are immediate
  2324. *
  2325. * @param Article $sibling Propel object for sibling node
  2326. * @param PropelPDO $con Connection to use.
  2327. *
  2328. * @return Article The current Propel object
  2329. */
  2330. public function moveToNextSiblingOf($sibling, PropelPDO $con = null)
  2331. {
  2332. if (!$this->isInTree()) {
  2333. throw new PropelException('A Article object must be already in the tree to be moved. Use the insertAsNextSiblingOf() instead.');
  2334. }
  2335. if ($sibling->isRoot()) {
  2336. throw new PropelException('Cannot move to next sibling of a root node.');
  2337. }
  2338. if ($sibling->isDescendantOf($this)) {
  2339. throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.');
  2340. }
  2341.  
  2342. $this->moveSubtreeTo($sibling->getRightValue() + 1, $sibling->getLevel() - $this->getLevel(), $con);
  2343.  
  2344. return $this;
  2345. }
  2346.  
  2347. /**
  2348. * Move current node and its children to location $destLeft and updates rest of tree
  2349. *
  2350. * @param int $destLeft Destination left value
  2351. * @param int $levelDelta Delta to add to the levels
  2352. * @param PropelPDO $con Connection to use.
  2353. */
  2354. protected function moveSubtreeTo($destLeft, $levelDelta, PropelPDO $con = null)
  2355. {
  2356. $preventDefault = false;
  2357. $left = $this->getLeftValue();
  2358. $right = $this->getRightValue();
  2359.  
  2360.  
  2361. $treeSize = $right - $left +1;
  2362.  
  2363. if ($con === null) {
  2364. $con = Propel::getConnection(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  2365. }
  2366.  
  2367. $con->beginTransaction();
  2368. try {
  2369.  
  2370. // make room next to the target for the subtree
  2371. ArticlePeer::shiftRLValues($treeSize, $destLeft, null, $con);
  2372.  
  2373.  
  2374.  
  2375. if (!$preventDefault) {
  2376.  
  2377.  
  2378. if ($left >= $destLeft) { // src was shifted too?
  2379. $left += $treeSize;
  2380. $right += $treeSize;
  2381. }
  2382.  
  2383. if ($levelDelta) {
  2384. // update the levels of the subtree
  2385. ArticlePeer::shiftLevel($levelDelta, $left, $right, $con);
  2386. }
  2387.  
  2388. // move the subtree to the target
  2389. ArticlePeer::shiftRLValues($destLeft - $left, $left, $right, $con);
  2390. }
  2391.  
  2392. // remove the empty room at the previous location of the subtree
  2393. ArticlePeer::shiftRLValues(-$treeSize, $right + 1, null, $con);
  2394.  
  2395. // update all loaded nodes
  2396. ArticlePeer::updateLoadedNodes(null, $con);
  2397.  
  2398. $con->commit();
  2399. } catch (Exception $e) {
  2400. $con->rollback();
  2401. throw $e;
  2402. }
  2403. }
  2404.  
  2405. /**
  2406. * Deletes all descendants for the given node
  2407. * Instance pooling is wiped out by this command,
  2408. * so existing Article instances are probably invalid (except for the current one)
  2409. *
  2410. * @param PropelPDO $con Connection to use.
  2411. *
  2412. * @return int number of deleted nodes
  2413. */
  2414. public function deleteDescendants(PropelPDO $con = null)
  2415. {
  2416. if ($this->isLeaf()) {
  2417. // save one query
  2418. return;
  2419. }
  2420. if ($con === null) {
  2421. $con = Propel::getConnection(ArticlePeer::DATABASE_NAME, Propel::CONNECTION_READ);
  2422. }
  2423. $left = $this->getLeftValue();
  2424. $right = $this->getRightValue();
  2425. $con->beginTransaction();
  2426. try {
  2427. // delete descendant nodes (will empty the instance pool)
  2428. $ret = ArticleQuery::create()
  2429. ->descendantsOf($this)
  2430. ->delete($con);
  2431.  
  2432. // fill up the room that was used by descendants
  2433. ArticlePeer::shiftRLValues($left - $right + 1, $right, null, $con);
  2434.  
  2435. // fix the right value for the current node, which is now a leaf
  2436. $this->setRightValue($left + 1);
  2437.  
  2438. $con->commit();
  2439. } catch (Exception $e) {
  2440. $con->rollback();
  2441. throw $e;
  2442. }
  2443.  
  2444. return $ret;
  2445. }
  2446.  
  2447. /**
  2448. * Returns a pre-order iterator for this node and its children.
  2449. *
  2450. * @return RecursiveIterator
  2451. */
  2452. public function getIterator()
  2453. {
  2454. return new NestedSetRecursiveIterator($this);
  2455. }
  2456.  
  2457. // i18n behavior
  2458.  
  2459. /**
  2460. * Sets the locale for translations
  2461. *
  2462. * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
  2463. *
  2464. * @return Article The current object (for fluent API support)
  2465. */
  2466. public function setLocale($locale = 'en_US')
  2467. {
  2468. $this->currentLocale = $locale;
  2469.  
  2470. return $this;
  2471. }
  2472.  
  2473. /**
  2474. * Gets the locale for translations
  2475. *
  2476. * @return string $locale Locale to use for the translation, e.g. 'fr_FR'
  2477. */
  2478. public function getLocale()
  2479. {
  2480. return $this->currentLocale;
  2481. }
  2482.  
  2483. /**
  2484. * Returns the current translation for a given locale
  2485. *
  2486. * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
  2487. * @param PropelPDO $con an optional connection object
  2488. *
  2489. * @return ArticleI18n */
  2490. public function getTranslation($locale = 'en_US', PropelPDO $con = null)
  2491. {
  2492. if (!isset($this->currentTranslations[$locale])) {
  2493. if (null !== $this->collArticleI18ns) {
  2494. foreach ($this->collArticleI18ns as $translation) {
  2495. if ($translation->getLocale() == $locale) {
  2496. $this->currentTranslations[$locale] = $translation;
  2497.  
  2498. return $translation;
  2499. }
  2500. }
  2501. }
  2502. if ($this->isNew()) {
  2503. $translation = new ArticleI18n();
  2504. $translation->setLocale($locale);
  2505. } else {
  2506. $translation = ArticleI18nQuery::create()
  2507. ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
  2508. ->findOneOrCreate($con);
  2509. $this->currentTranslations[$locale] = $translation;
  2510. }
  2511. $this->addArticleI18n($translation);
  2512. }
  2513.  
  2514. return $this->currentTranslations[$locale];
  2515. }
  2516.  
  2517. /**
  2518. * Remove the translation for a given locale
  2519. *
  2520. * @param string $locale Locale to use for the translation, e.g. 'fr_FR'
  2521. * @param PropelPDO $con an optional connection object
  2522. *
  2523. * @return Article The current object (for fluent API support)
  2524. */
  2525. public function removeTranslation($locale = 'en_US', PropelPDO $con = null)
  2526. {
  2527. if (!$this->isNew()) {
  2528. ArticleI18nQuery::create()
  2529. ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
  2530. ->delete($con);
  2531. }
  2532. if (isset($this->currentTranslations[$locale])) {
  2533. unset($this->currentTranslations[$locale]);
  2534. }
  2535. foreach ($this->collArticleI18ns as $key => $translation) {
  2536. if ($translation->getLocale() == $locale) {
  2537. unset($this->collArticleI18ns[$key]);
  2538. break;
  2539. }
  2540. }
  2541.  
  2542. return $this;
  2543. }
  2544.  
  2545. /**
  2546. * Returns the current translation
  2547. *
  2548. * @param PropelPDO $con an optional connection object
  2549. *
  2550. * @return ArticleI18n */
  2551. public function getCurrentTranslation(PropelPDO $con = null)
  2552. {
  2553. return $this->getTranslation($this->getLocale(), $con);
  2554. }
  2555.  
  2556.  
  2557. /**
  2558. * Get the [title] column value.
  2559. *
  2560. * @return string
  2561. */
  2562. public function getTitle()
  2563. {
  2564. return $this->getCurrentTranslation()->getTitle();
  2565. }
  2566.  
  2567.  
  2568. /**
  2569. * Set the value of [title] column.
  2570. *
  2571. * @param string $v new value
  2572. * @return ArticleI18n The current object (for fluent API support)
  2573. */
  2574. public function setTitle($v)
  2575. { $this->getCurrentTranslation()->setTitle($v);
  2576.  
  2577. return $this;
  2578. }
  2579.  
  2580.  
  2581. /**
  2582. * Get the [body] column value.
  2583. *
  2584. * @return string
  2585. */
  2586. public function getBody()
  2587. {
  2588. return $this->getCurrentTranslation()->getBody();
  2589. }
  2590.  
  2591.  
  2592. /**
  2593. * Set the value of [body] column.
  2594. *
  2595. * @param string $v new value
  2596. * @return ArticleI18n The current object (for fluent API support)
  2597. */
  2598. public function setBody($v)
  2599. { $this->getCurrentTranslation()->setBody($v);
  2600.  
  2601. return $this;
  2602. }
  2603.  
  2604. // artsofte_cms behavior
  2605.  
  2606. /**
  2607. * Опубликовать/распубликовать объект
  2608. *
  2609. */
  2610. public function rePublic(PropelPDO $con = null)
  2611. {
  2612. $this->setActive(!$this->getActive());
  2613. return $this->save($con);
  2614. }
  2615.  
  2616. /**
  2617. * Имя класса Peer
  2618. *
  2619. */
  2620. public function getClassPeer(PropelPDO $con = null)
  2621. {
  2622. return get_class($this->getPeer());
  2623. }
  2624.  
  2625. /**
  2626. * Изменение порядка сортировки. Поднять вверх
  2627. */
  2628. public function treeUp(PropelPDO $con = null)
  2629. {
  2630. if($this->getParent()){
  2631. $prev = $this->getPrevSibling();
  2632. $this->moveToPrevSiblingOf($prev);
  2633. $this->save();
  2634. return true;
  2635. }
  2636. return false;
  2637. }
  2638.  
  2639. /**
  2640. * Изменение порядка сортировки. Опустить вниз
  2641. */
  2642. public function treeDown(PropelPDO $con = null)
  2643. {
  2644. if($this->getParent()){
  2645. $next = $this->getNextSibling();
  2646. $this->moveToNextSiblingOf($next);
  2647. $this->save();
  2648. return true;
  2649. }
  2650. return false;
  2651. }
  2652.  
  2653. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement