BaseNodeNews.php 23 KB

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