BaseNodePage.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. /**
  3. * Base class that represents a row from the 'node_page' table.
  4. *
  5. *
  6. *
  7. * @package lib.model.om
  8. */
  9. abstract class BaseNodePage extends BaseObject implements Persistent {
  10. /**
  11. * The Peer class.
  12. * Instance provides a convenient way of calling static methods on a class
  13. * that calling code may not be able to identify.
  14. * @var NodePagePeer
  15. */
  16. protected static $peer;
  17. /**
  18. * The value for the id field.
  19. * @var int
  20. */
  21. protected $id;
  22. /**
  23. * The value for the node_id field.
  24. * @var int
  25. */
  26. protected $node_id;
  27. /**
  28. * The value for the content field.
  29. * @var string
  30. */
  31. protected $content;
  32. /**
  33. * @var Node
  34. */
  35. protected $aNode;
  36. /**
  37. * Flag to prevent endless save loop, if this object is referenced
  38. * by another object which falls in this transaction.
  39. * @var boolean
  40. */
  41. protected $alreadyInSave = false;
  42. /**
  43. * Flag to prevent endless validation loop, if this object is referenced
  44. * by another object which falls in this transaction.
  45. * @var boolean
  46. */
  47. protected $alreadyInValidation = false;
  48. /**
  49. * Get the [id] column value.
  50. *
  51. * @return int
  52. */
  53. public function getId()
  54. {
  55. return $this->id;
  56. }
  57. /**
  58. * Get the [node_id] column value.
  59. *
  60. * @return int
  61. */
  62. public function getNodeId()
  63. {
  64. return $this->node_id;
  65. }
  66. /**
  67. * Get the [content] column value.
  68. *
  69. * @return string
  70. */
  71. public function getContent()
  72. {
  73. return $this->content;
  74. }
  75. /**
  76. * Set the value of [id] column.
  77. *
  78. * @param int $v new value
  79. * @return void
  80. */
  81. public function setId($v)
  82. {
  83. // Since the native PHP type for this column is integer,
  84. // we will cast the input value to an int (if it is not).
  85. if ($v !== null && !is_int($v) && is_numeric($v)) {
  86. $v = (int) $v;
  87. }
  88. if ($this->id !== $v) {
  89. $this->id = $v;
  90. $this->modifiedColumns[] = NodePagePeer::ID;
  91. }
  92. } // setId()
  93. /**
  94. * Set the value of [node_id] column.
  95. *
  96. * @param int $v new value
  97. * @return void
  98. */
  99. public function setNodeId($v)
  100. {
  101. // Since the native PHP type for this column is integer,
  102. // we will cast the input value to an int (if it is not).
  103. if ($v !== null && !is_int($v) && is_numeric($v)) {
  104. $v = (int) $v;
  105. }
  106. if ($this->node_id !== $v) {
  107. $this->node_id = $v;
  108. $this->modifiedColumns[] = NodePagePeer::NODE_ID;
  109. }
  110. if ($this->aNode !== null && $this->aNode->getId() !== $v) {
  111. $this->aNode = null;
  112. }
  113. } // setNodeId()
  114. /**
  115. * Set the value of [content] column.
  116. *
  117. * @param string $v new value
  118. * @return void
  119. */
  120. public function setContent($v)
  121. {
  122. // Since the native PHP type for this column is string,
  123. // we will cast the input to a string (if it is not).
  124. if ($v !== null && !is_string($v)) {
  125. $v = (string) $v;
  126. }
  127. if ($this->content !== $v) {
  128. $this->content = $v;
  129. $this->modifiedColumns[] = NodePagePeer::CONTENT;
  130. }
  131. } // setContent()
  132. /**
  133. * Hydrates (populates) the object variables with values from the database resultset.
  134. *
  135. * An offset (1-based "start column") is specified so that objects can be hydrated
  136. * with a subset of the columns in the resultset rows. This is needed, for example,
  137. * for results of JOIN queries where the resultset row includes columns from two or
  138. * more tables.
  139. *
  140. * @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos.
  141. * @param int $startcol 1-based offset column which indicates which restultset column to start with.
  142. * @return int next starting column
  143. * @throws PropelException - Any caught Exception will be rewrapped as a PropelException.
  144. */
  145. public function hydrate(ResultSet $rs, $startcol = 1)
  146. {
  147. try {
  148. $this->id = $rs->getInt($startcol + 0);
  149. $this->node_id = $rs->getInt($startcol + 1);
  150. $this->content = $rs->getString($startcol + 2);
  151. $this->resetModified();
  152. $this->setNew(false);
  153. // FIXME - using NUM_COLUMNS may be clearer.
  154. return $startcol + 3; // 3 = NodePagePeer::NUM_COLUMNS - NodePagePeer::NUM_LAZY_LOAD_COLUMNS).
  155. } catch (Exception $e) {
  156. throw new PropelException("Error populating NodePage object", $e);
  157. }
  158. }
  159. /**
  160. * Removes this object from datastore and sets delete attribute.
  161. *
  162. * @param Connection $con
  163. * @return void
  164. * @throws PropelException
  165. * @see BaseObject::setDeleted()
  166. * @see BaseObject::isDeleted()
  167. */
  168. public function delete($con = null)
  169. {
  170. foreach (sfMixer::getCallables('BaseNodePage:delete:pre') as $callable)
  171. {
  172. $ret = call_user_func($callable, $this, $con);
  173. if ($ret)
  174. {
  175. return;
  176. }
  177. }
  178. if ($this->isDeleted()) {
  179. throw new PropelException("This object has already been deleted.");
  180. }
  181. if ($con === null) {
  182. $con = Propel::getConnection(NodePagePeer::DATABASE_NAME);
  183. }
  184. try {
  185. $con->begin();
  186. NodePagePeer::doDelete($this, $con);
  187. $this->setDeleted(true);
  188. $con->commit();
  189. } catch (PropelException $e) {
  190. $con->rollback();
  191. throw $e;
  192. }
  193. foreach (sfMixer::getCallables('BaseNodePage:delete:post') as $callable)
  194. {
  195. call_user_func($callable, $this, $con);
  196. }
  197. }
  198. /**
  199. * Stores the object in the database. If the object is new,
  200. * it inserts it; otherwise an update is performed. This method
  201. * wraps the doSave() worker method in a transaction.
  202. *
  203. * @param Connection $con
  204. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  205. * @throws PropelException
  206. * @see doSave()
  207. */
  208. public function save($con = null)
  209. {
  210. foreach (sfMixer::getCallables('BaseNodePage:save:pre') as $callable)
  211. {
  212. $affectedRows = call_user_func($callable, $this, $con);
  213. if (is_int($affectedRows))
  214. {
  215. return $affectedRows;
  216. }
  217. }
  218. if ($this->isDeleted()) {
  219. throw new PropelException("You cannot save an object that has been deleted.");
  220. }
  221. if ($con === null) {
  222. $con = Propel::getConnection(NodePagePeer::DATABASE_NAME);
  223. }
  224. try {
  225. $con->begin();
  226. $affectedRows = $this->doSave($con);
  227. $con->commit();
  228. foreach (sfMixer::getCallables('BaseNodePage:save:post') as $callable)
  229. {
  230. call_user_func($callable, $this, $con, $affectedRows);
  231. }
  232. return $affectedRows;
  233. } catch (PropelException $e) {
  234. $con->rollback();
  235. throw $e;
  236. }
  237. }
  238. /**
  239. * Stores the object in the database.
  240. *
  241. * If the object is new, it inserts it; otherwise an update is performed.
  242. * All related objects are also updated in this method.
  243. *
  244. * @param Connection $con
  245. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  246. * @throws PropelException
  247. * @see save()
  248. */
  249. protected function doSave($con)
  250. {
  251. $affectedRows = 0; // initialize var to track total num of affected rows
  252. if (!$this->alreadyInSave) {
  253. $this->alreadyInSave = true;
  254. // We call the save method on the following object(s) if they
  255. // were passed to this object by their coresponding set
  256. // method. This object relates to these object(s) by a
  257. // foreign key reference.
  258. if ($this->aNode !== null) {
  259. if ($this->aNode->isModified() || ($this->aNode->getCulture() && $this->aNode->getCurrentNodeI18n()->isModified())) {
  260. $affectedRows += $this->aNode->save($con);
  261. }
  262. $this->setNode($this->aNode);
  263. }
  264. // If this object has been modified, then save it to the database.
  265. if ($this->isModified()) {
  266. if ($this->isNew()) {
  267. $pk = NodePagePeer::doInsert($this, $con);
  268. $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which
  269. // should always be true here (even though technically
  270. // BasePeer::doInsert() can insert multiple rows).
  271. $this->setId($pk); //[IMV] update autoincrement primary key
  272. $this->setNew(false);
  273. } else {
  274. $affectedRows += NodePagePeer::doUpdate($this, $con);
  275. }
  276. $this->resetModified(); // [HL] After being saved an object is no longer 'modified'
  277. }
  278. $this->alreadyInSave = false;
  279. }
  280. return $affectedRows;
  281. } // doSave()
  282. /**
  283. * Array of ValidationFailed objects.
  284. * @var array ValidationFailed[]
  285. */
  286. protected $validationFailures = array();
  287. /**
  288. * Gets any ValidationFailed objects that resulted from last call to validate().
  289. *
  290. *
  291. * @return array ValidationFailed[]
  292. * @see validate()
  293. */
  294. public function getValidationFailures()
  295. {
  296. return $this->validationFailures;
  297. }
  298. /**
  299. * Validates the objects modified field values and all objects related to this table.
  300. *
  301. * If $columns is either a column name or an array of column names
  302. * only those columns are validated.
  303. *
  304. * @param mixed $columns Column name or an array of column names.
  305. * @return boolean Whether all columns pass validation.
  306. * @see doValidate()
  307. * @see getValidationFailures()
  308. */
  309. public function validate($columns = null)
  310. {
  311. $res = $this->doValidate($columns);
  312. if ($res === true) {
  313. $this->validationFailures = array();
  314. return true;
  315. } else {
  316. $this->validationFailures = $res;
  317. return false;
  318. }
  319. }
  320. /**
  321. * This function performs the validation work for complex object models.
  322. *
  323. * In addition to checking the current object, all related objects will
  324. * also be validated. If all pass then <code>true</code> is returned; otherwise
  325. * an aggreagated array of ValidationFailed objects will be returned.
  326. *
  327. * @param array $columns Array of column names to validate.
  328. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  329. */
  330. protected function doValidate($columns = null)
  331. {
  332. if (!$this->alreadyInValidation) {
  333. $this->alreadyInValidation = true;
  334. $retval = null;
  335. $failureMap = array();
  336. // We call the validate method on the following object(s) if they
  337. // were passed to this object by their coresponding set
  338. // method. This object relates to these object(s) by a
  339. // foreign key reference.
  340. if ($this->aNode !== null) {
  341. if (!$this->aNode->validate($columns)) {
  342. $failureMap = array_merge($failureMap, $this->aNode->getValidationFailures());
  343. }
  344. }
  345. if (($retval = NodePagePeer::doValidate($this, $columns)) !== true) {
  346. $failureMap = array_merge($failureMap, $retval);
  347. }
  348. $this->alreadyInValidation = false;
  349. }
  350. return (!empty($failureMap) ? $failureMap : true);
  351. }
  352. /**
  353. * Retrieves a field from the object by name passed in as a string.
  354. *
  355. * @param string $name name
  356. * @param string $type The type of fieldname the $name is of:
  357. * one of the class type constants TYPE_PHPNAME,
  358. * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
  359. * @return mixed Value of field.
  360. */
  361. public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
  362. {
  363. $pos = NodePagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  364. return $this->getByPosition($pos);
  365. }
  366. /**
  367. * Retrieves a field from the object by Position as specified in the xml schema.
  368. * Zero-based.
  369. *
  370. * @param int $pos position in xml schema
  371. * @return mixed Value of field at $pos
  372. */
  373. public function getByPosition($pos)
  374. {
  375. switch($pos) {
  376. case 0:
  377. return $this->getId();
  378. break;
  379. case 1:
  380. return $this->getNodeId();
  381. break;
  382. case 2:
  383. return $this->getContent();
  384. break;
  385. default:
  386. return null;
  387. break;
  388. } // switch()
  389. }
  390. /**
  391. * Exports the object as an array.
  392. *
  393. * You can specify the key type of the array by passing one of the class
  394. * type constants.
  395. *
  396. * @param string $keyType One of the class type constants TYPE_PHPNAME,
  397. * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
  398. * @return an associative array containing the field names (as keys) and field values
  399. */
  400. public function toArray($keyType = BasePeer::TYPE_PHPNAME)
  401. {
  402. $keys = NodePagePeer::getFieldNames($keyType);
  403. $result = array(
  404. $keys[0] => $this->getId(),
  405. $keys[1] => $this->getNodeId(),
  406. $keys[2] => $this->getContent(),
  407. );
  408. return $result;
  409. }
  410. /**
  411. * Sets a field from the object by name passed in as a string.
  412. *
  413. * @param string $name peer name
  414. * @param mixed $value field value
  415. * @param string $type The type of fieldname the $name is of:
  416. * one of the class type constants TYPE_PHPNAME,
  417. * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
  418. * @return void
  419. */
  420. public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
  421. {
  422. $pos = NodePagePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
  423. return $this->setByPosition($pos, $value);
  424. }
  425. /**
  426. * Sets a field from the object by Position as specified in the xml schema.
  427. * Zero-based.
  428. *
  429. * @param int $pos position in xml schema
  430. * @param mixed $value field value
  431. * @return void
  432. */
  433. public function setByPosition($pos, $value)
  434. {
  435. switch($pos) {
  436. case 0:
  437. $this->setId($value);
  438. break;
  439. case 1:
  440. $this->setNodeId($value);
  441. break;
  442. case 2:
  443. $this->setContent($value);
  444. break;
  445. } // switch()
  446. }
  447. /**
  448. * Populates the object using an array.
  449. *
  450. * This is particularly useful when populating an object from one of the
  451. * request arrays (e.g. $_POST). This method goes through the column
  452. * names, checking to see whether a matching key exists in populated
  453. * array. If so the setByName() method is called for that column.
  454. *
  455. * You can specify the key type of the array by additionally passing one
  456. * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  457. * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  458. *
  459. * @param array $arr An array to populate the object from.
  460. * @param string $keyType The type of keys the array uses.
  461. * @return void
  462. */
  463. public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
  464. {
  465. $keys = NodePagePeer::getFieldNames($keyType);
  466. if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
  467. if (array_key_exists($keys[1], $arr)) $this->setNodeId($arr[$keys[1]]);
  468. if (array_key_exists($keys[2], $arr)) $this->setContent($arr[$keys[2]]);
  469. }
  470. /**
  471. * Build a Criteria object containing the values of all modified columns in this object.
  472. *
  473. * @return Criteria The Criteria object containing all modified values.
  474. */
  475. public function buildCriteria()
  476. {
  477. $criteria = new Criteria(NodePagePeer::DATABASE_NAME);
  478. if ($this->isColumnModified(NodePagePeer::ID)) $criteria->add(NodePagePeer::ID, $this->id);
  479. if ($this->isColumnModified(NodePagePeer::NODE_ID)) $criteria->add(NodePagePeer::NODE_ID, $this->node_id);
  480. if ($this->isColumnModified(NodePagePeer::CONTENT)) $criteria->add(NodePagePeer::CONTENT, $this->content);
  481. return $criteria;
  482. }
  483. /**
  484. * Builds a Criteria object containing the primary key for this object.
  485. *
  486. * Unlike buildCriteria() this method includes the primary key values regardless
  487. * of whether or not they have been modified.
  488. *
  489. * @return Criteria The Criteria object containing value(s) for primary key(s).
  490. */
  491. public function buildPkeyCriteria()
  492. {
  493. $criteria = new Criteria(NodePagePeer::DATABASE_NAME);
  494. $criteria->add(NodePagePeer::ID, $this->id);
  495. return $criteria;
  496. }
  497. /**
  498. * Returns the primary key for this object (row).
  499. * @return int
  500. */
  501. public function getPrimaryKey()
  502. {
  503. return $this->getId();
  504. }
  505. /**
  506. * Generic method to set the primary key (id column).
  507. *
  508. * @param int $key Primary key.
  509. * @return void
  510. */
  511. public function setPrimaryKey($key)
  512. {
  513. $this->setId($key);
  514. }
  515. /**
  516. * Sets contents of passed object to values from current object.
  517. *
  518. * If desired, this method can also make copies of all associated (fkey referrers)
  519. * objects.
  520. *
  521. * @param object $copyObj An object of NodePage (or compatible) type.
  522. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  523. * @throws PropelException
  524. */
  525. public function copyInto($copyObj, $deepCopy = false)
  526. {
  527. $copyObj->setNodeId($this->node_id);
  528. $copyObj->setContent($this->content);
  529. $copyObj->setNew(true);
  530. $copyObj->setId(NULL); // this is a pkey column, so set to default value
  531. }
  532. /**
  533. * Makes a copy of this object that will be inserted as a new row in table when saved.
  534. * It creates a new object filling in the simple attributes, but skipping any primary
  535. * keys that are defined for the table.
  536. *
  537. * If desired, this method can also make copies of all associated (fkey referrers)
  538. * objects.
  539. *
  540. * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row.
  541. * @return NodePage Clone of current object.
  542. * @throws PropelException
  543. */
  544. public function copy($deepCopy = false)
  545. {
  546. // we use get_class(), because this might be a subclass
  547. $clazz = get_class($this);
  548. $copyObj = new $clazz();
  549. $this->copyInto($copyObj, $deepCopy);
  550. return $copyObj;
  551. }
  552. /**
  553. * Returns a peer instance associated with this om.
  554. *
  555. * Since Peer classes are not to have any instance attributes, this method returns the
  556. * same instance for all member of this class. The method could therefore
  557. * be static, but this would prevent one from overriding the behavior.
  558. *
  559. * @return NodePagePeer
  560. */
  561. public function getPeer()
  562. {
  563. if (self::$peer === null) {
  564. self::$peer = new NodePagePeer();
  565. }
  566. return self::$peer;
  567. }
  568. /**
  569. * Declares an association between this object and a Node object.
  570. *
  571. * @param Node $v
  572. * @return void
  573. * @throws PropelException
  574. */
  575. public function setNode($v)
  576. {
  577. if ($v === null) {
  578. $this->setNodeId(NULL);
  579. } else {
  580. $this->setNodeId($v->getId());
  581. }
  582. $this->aNode = $v;
  583. }
  584. /**
  585. * Get the associated Node object
  586. *
  587. * @param Connection Optional Connection object.
  588. * @return Node The associated Node object.
  589. * @throws PropelException
  590. */
  591. public function getNode($con = null)
  592. {
  593. if ($this->aNode === null && ($this->node_id !== null)) {
  594. // include the related Peer class
  595. $this->aNode = NodePeer::retrieveByPK($this->node_id, $con);
  596. /* The following can be used instead of the line above to
  597. guarantee the related object contains a reference
  598. to this object, but this level of coupling
  599. may be undesirable in many circumstances.
  600. As it can lead to a db query with many results that may
  601. never be used.
  602. $obj = NodePeer::retrieveByPK($this->node_id, $con);
  603. $obj->addNodes($this);
  604. */
  605. }
  606. return $this->aNode;
  607. }
  608. public function __call($method, $arguments)
  609. {
  610. if (!$callable = sfMixer::getCallable('BaseNodePage:'.$method))
  611. {
  612. throw new sfException(sprintf('Call to undefined method BaseNodePage::%s', $method));
  613. }
  614. array_unshift($arguments, $this);
  615. return call_user_func_array($callable, $arguments);
  616. }
  617. } // BaseNodePage