BaseNodeHome.php 20 KB

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