BaseNodeHomePeer.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. <?php
  2. /**
  3. * Base static class for performing query and update operations on the 'node_home' table.
  4. *
  5. *
  6. *
  7. * @package lib.model.om
  8. */
  9. abstract class BaseNodeHomePeer {
  10. /** the default database name for this class */
  11. const DATABASE_NAME = 'propel';
  12. /** the table name for this class */
  13. const TABLE_NAME = 'node_home';
  14. /** A class that can be returned by this peer. */
  15. const CLASS_DEFAULT = 'lib.model.NodeHome';
  16. /** The total number of columns. */
  17. const NUM_COLUMNS = 4;
  18. /** The number of lazy-loaded columns. */
  19. const NUM_LAZY_LOAD_COLUMNS = 0;
  20. /** the column name for the ID field */
  21. const ID = 'node_home.ID';
  22. /** the column name for the NODE_ID field */
  23. const NODE_ID = 'node_home.NODE_ID';
  24. /** the column name for the EDITO_TITLE field */
  25. const EDITO_TITLE = 'node_home.EDITO_TITLE';
  26. /** the column name for the EDITO_CONTENT field */
  27. const EDITO_CONTENT = 'node_home.EDITO_CONTENT';
  28. /** The PHP to DB Name Mapping */
  29. private static $phpNameMap = null;
  30. /**
  31. * holds an array of fieldnames
  32. *
  33. * first dimension keys are the type constants
  34. * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
  35. */
  36. private static $fieldNames = array (
  37. BasePeer::TYPE_PHPNAME => array ('Id', 'NodeId', 'EditoTitle', 'EditoContent', ),
  38. BasePeer::TYPE_COLNAME => array (NodeHomePeer::ID, NodeHomePeer::NODE_ID, NodeHomePeer::EDITO_TITLE, NodeHomePeer::EDITO_CONTENT, ),
  39. BasePeer::TYPE_FIELDNAME => array ('id', 'node_id', 'edito_title', 'edito_content', ),
  40. BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
  41. );
  42. /**
  43. * holds an array of keys for quick access to the fieldnames array
  44. *
  45. * first dimension keys are the type constants
  46. * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
  47. */
  48. private static $fieldKeys = array (
  49. BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'NodeId' => 1, 'EditoTitle' => 2, 'EditoContent' => 3, ),
  50. BasePeer::TYPE_COLNAME => array (NodeHomePeer::ID => 0, NodeHomePeer::NODE_ID => 1, NodeHomePeer::EDITO_TITLE => 2, NodeHomePeer::EDITO_CONTENT => 3, ),
  51. BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'node_id' => 1, 'edito_title' => 2, 'edito_content' => 3, ),
  52. BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
  53. );
  54. /**
  55. * @return MapBuilder the map builder for this peer
  56. * @throws PropelException Any exceptions caught during processing will be
  57. * rethrown wrapped into a PropelException.
  58. */
  59. public static function getMapBuilder()
  60. {
  61. return BasePeer::getMapBuilder('lib.model.map.NodeHomeMapBuilder');
  62. }
  63. /**
  64. * Gets a map (hash) of PHP names to DB column names.
  65. *
  66. * @return array The PHP to DB name map for this peer
  67. * @throws PropelException Any exceptions caught during processing will be
  68. * rethrown wrapped into a PropelException.
  69. * @deprecated Use the getFieldNames() and translateFieldName() methods instead of this.
  70. */
  71. public static function getPhpNameMap()
  72. {
  73. if (self::$phpNameMap === null) {
  74. $map = NodeHomePeer::getTableMap();
  75. $columns = $map->getColumns();
  76. $nameMap = array();
  77. foreach ($columns as $column) {
  78. $nameMap[$column->getPhpName()] = $column->getColumnName();
  79. }
  80. self::$phpNameMap = $nameMap;
  81. }
  82. return self::$phpNameMap;
  83. }
  84. /**
  85. * Translates a fieldname to another type
  86. *
  87. * @param string $name field name
  88. * @param string $fromType One of the class type constants TYPE_PHPNAME,
  89. * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
  90. * @param string $toType One of the class type constants
  91. * @return string translated name of the field.
  92. */
  93. static public function translateFieldName($name, $fromType, $toType)
  94. {
  95. $toNames = self::getFieldNames($toType);
  96. $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
  97. if ($key === null) {
  98. throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
  99. }
  100. return $toNames[$key];
  101. }
  102. /**
  103. * Returns an array of of field names.
  104. *
  105. * @param string $type The type of fieldnames to return:
  106. * One of the class type constants TYPE_PHPNAME,
  107. * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM
  108. * @return array A list of field names
  109. */
  110. static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
  111. {
  112. if (!array_key_exists($type, self::$fieldNames)) {
  113. throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
  114. }
  115. return self::$fieldNames[$type];
  116. }
  117. /**
  118. * Convenience method which changes table.column to alias.column.
  119. *
  120. * Using this method you can maintain SQL abstraction while using column aliases.
  121. * <code>
  122. * $c->addAlias("alias1", TablePeer::TABLE_NAME);
  123. * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
  124. * </code>
  125. * @param string $alias The alias for the current table.
  126. * @param string $column The column name for current table. (i.e. NodeHomePeer::COLUMN_NAME).
  127. * @return string
  128. */
  129. public static function alias($alias, $column)
  130. {
  131. return str_replace(NodeHomePeer::TABLE_NAME.'.', $alias.'.', $column);
  132. }
  133. /**
  134. * Add all the columns needed to create a new object.
  135. *
  136. * Note: any columns that were marked with lazyLoad="true" in the
  137. * XML schema will not be added to the select list and only loaded
  138. * on demand.
  139. *
  140. * @param criteria object containing the columns to add.
  141. * @throws PropelException Any exceptions caught during processing will be
  142. * rethrown wrapped into a PropelException.
  143. */
  144. public static function addSelectColumns(Criteria $criteria)
  145. {
  146. $criteria->addSelectColumn(NodeHomePeer::ID);
  147. $criteria->addSelectColumn(NodeHomePeer::NODE_ID);
  148. $criteria->addSelectColumn(NodeHomePeer::EDITO_TITLE);
  149. $criteria->addSelectColumn(NodeHomePeer::EDITO_CONTENT);
  150. }
  151. const COUNT = 'COUNT(node_home.ID)';
  152. const COUNT_DISTINCT = 'COUNT(DISTINCT node_home.ID)';
  153. /**
  154. * Returns the number of rows matching criteria.
  155. *
  156. * @param Criteria $criteria
  157. * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
  158. * @param Connection $con
  159. * @return int Number of matching rows.
  160. */
  161. public static function doCount(Criteria $criteria, $distinct = false, $con = null)
  162. {
  163. // we're going to modify criteria, so copy it first
  164. $criteria = clone $criteria;
  165. // clear out anything that might confuse the ORDER BY clause
  166. $criteria->clearSelectColumns()->clearOrderByColumns();
  167. if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  168. $criteria->addSelectColumn(NodeHomePeer::COUNT_DISTINCT);
  169. } else {
  170. $criteria->addSelectColumn(NodeHomePeer::COUNT);
  171. }
  172. // just in case we're grouping: add those columns to the select statement
  173. foreach($criteria->getGroupByColumns() as $column)
  174. {
  175. $criteria->addSelectColumn($column);
  176. }
  177. $rs = NodeHomePeer::doSelectRS($criteria, $con);
  178. if ($rs->next()) {
  179. return $rs->getInt(1);
  180. } else {
  181. // no rows returned; we infer that means 0 matches.
  182. return 0;
  183. }
  184. }
  185. /**
  186. * Method to select one object from the DB.
  187. *
  188. * @param Criteria $criteria object used to create the SELECT statement.
  189. * @param Connection $con
  190. * @return NodeHome
  191. * @throws PropelException Any exceptions caught during processing will be
  192. * rethrown wrapped into a PropelException.
  193. */
  194. public static function doSelectOne(Criteria $criteria, $con = null)
  195. {
  196. $critcopy = clone $criteria;
  197. $critcopy->setLimit(1);
  198. $objects = NodeHomePeer::doSelect($critcopy, $con);
  199. if ($objects) {
  200. return $objects[0];
  201. }
  202. return null;
  203. }
  204. /**
  205. * Method to do selects.
  206. *
  207. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  208. * @param Connection $con
  209. * @return array Array of selected Objects
  210. * @throws PropelException Any exceptions caught during processing will be
  211. * rethrown wrapped into a PropelException.
  212. */
  213. public static function doSelect(Criteria $criteria, $con = null)
  214. {
  215. return NodeHomePeer::populateObjects(NodeHomePeer::doSelectRS($criteria, $con));
  216. }
  217. /**
  218. * Prepares the Criteria object and uses the parent doSelect()
  219. * method to get a ResultSet.
  220. *
  221. * Use this method directly if you want to just get the resultset
  222. * (instead of an array of objects).
  223. *
  224. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  225. * @param Connection $con the connection to use
  226. * @throws PropelException Any exceptions caught during processing will be
  227. * rethrown wrapped into a PropelException.
  228. * @return ResultSet The resultset object with numerically-indexed fields.
  229. * @see BasePeer::doSelect()
  230. */
  231. public static function doSelectRS(Criteria $criteria, $con = null)
  232. {
  233. foreach (sfMixer::getCallables('BaseNodeHomePeer:doSelectRS:doSelectRS') as $callable)
  234. {
  235. call_user_func($callable, 'BaseNodeHomePeer', $criteria, $con);
  236. }
  237. if ($con === null) {
  238. $con = Propel::getConnection(self::DATABASE_NAME);
  239. }
  240. if (!$criteria->getSelectColumns()) {
  241. $criteria = clone $criteria;
  242. NodeHomePeer::addSelectColumns($criteria);
  243. }
  244. // Set the correct dbName
  245. $criteria->setDbName(self::DATABASE_NAME);
  246. // BasePeer returns a Creole ResultSet, set to return
  247. // rows indexed numerically.
  248. return BasePeer::doSelect($criteria, $con);
  249. }
  250. /**
  251. * The returned array will contain objects of the default type or
  252. * objects that inherit from the default.
  253. *
  254. * @throws PropelException Any exceptions caught during processing will be
  255. * rethrown wrapped into a PropelException.
  256. */
  257. public static function populateObjects(ResultSet $rs)
  258. {
  259. $results = array();
  260. // set the class once to avoid overhead in the loop
  261. $cls = NodeHomePeer::getOMClass();
  262. $cls = sfPropel::import($cls);
  263. // populate the object(s)
  264. while($rs->next()) {
  265. $obj = new $cls();
  266. $obj->hydrate($rs);
  267. $results[] = $obj;
  268. }
  269. return $results;
  270. }
  271. /**
  272. * Returns the number of rows matching criteria, joining the related Node table
  273. *
  274. * @param Criteria $c
  275. * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
  276. * @param Connection $con
  277. * @return int Number of matching rows.
  278. */
  279. public static function doCountJoinNode(Criteria $criteria, $distinct = false, $con = null)
  280. {
  281. // we're going to modify criteria, so copy it first
  282. $criteria = clone $criteria;
  283. // clear out anything that might confuse the ORDER BY clause
  284. $criteria->clearSelectColumns()->clearOrderByColumns();
  285. if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  286. $criteria->addSelectColumn(NodeHomePeer::COUNT_DISTINCT);
  287. } else {
  288. $criteria->addSelectColumn(NodeHomePeer::COUNT);
  289. }
  290. // just in case we're grouping: add those columns to the select statement
  291. foreach($criteria->getGroupByColumns() as $column)
  292. {
  293. $criteria->addSelectColumn($column);
  294. }
  295. $criteria->addJoin(NodeHomePeer::NODE_ID, NodePeer::ID);
  296. $rs = NodeHomePeer::doSelectRS($criteria, $con);
  297. if ($rs->next()) {
  298. return $rs->getInt(1);
  299. } else {
  300. // no rows returned; we infer that means 0 matches.
  301. return 0;
  302. }
  303. }
  304. /**
  305. * Selects a collection of NodeHome objects pre-filled with their Node objects.
  306. *
  307. * @return array Array of NodeHome objects.
  308. * @throws PropelException Any exceptions caught during processing will be
  309. * rethrown wrapped into a PropelException.
  310. */
  311. public static function doSelectJoinNode(Criteria $c, $con = null)
  312. {
  313. foreach (sfMixer::getCallables('BaseNodeHomePeer:doSelectJoin:doSelectJoin') as $callable)
  314. {
  315. call_user_func($callable, 'BaseNodeHomePeer', $c, $con);
  316. }
  317. $c = clone $c;
  318. // Set the correct dbName if it has not been overridden
  319. if ($c->getDbName() == Propel::getDefaultDB()) {
  320. $c->setDbName(self::DATABASE_NAME);
  321. }
  322. NodeHomePeer::addSelectColumns($c);
  323. $startcol = (NodeHomePeer::NUM_COLUMNS - NodeHomePeer::NUM_LAZY_LOAD_COLUMNS) + 1;
  324. NodePeer::addSelectColumns($c);
  325. $c->addJoin(NodeHomePeer::NODE_ID, NodePeer::ID);
  326. $rs = BasePeer::doSelect($c, $con);
  327. $results = array();
  328. while($rs->next()) {
  329. $omClass = NodeHomePeer::getOMClass();
  330. $cls = sfPropel::import($omClass);
  331. $obj1 = new $cls();
  332. $obj1->hydrate($rs);
  333. $omClass = NodePeer::getOMClass();
  334. $cls = sfPropel::import($omClass);
  335. $obj2 = new $cls();
  336. $obj2->hydrate($rs, $startcol);
  337. $newObject = true;
  338. foreach($results as $temp_obj1) {
  339. $temp_obj2 = $temp_obj1->getNode(); //CHECKME
  340. if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
  341. $newObject = false;
  342. // e.g. $author->addBookRelatedByBookId()
  343. $temp_obj2->addNodeHome($obj1); //CHECKME
  344. break;
  345. }
  346. }
  347. if ($newObject) {
  348. $obj2->initNodeHomes();
  349. $obj2->addNodeHome($obj1); //CHECKME
  350. }
  351. $results[] = $obj1;
  352. }
  353. return $results;
  354. }
  355. /**
  356. * Returns the number of rows matching criteria, joining all related tables
  357. *
  358. * @param Criteria $c
  359. * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria).
  360. * @param Connection $con
  361. * @return int Number of matching rows.
  362. */
  363. public static function doCountJoinAll(Criteria $criteria, $distinct = false, $con = null)
  364. {
  365. $criteria = clone $criteria;
  366. // clear out anything that might confuse the ORDER BY clause
  367. $criteria->clearSelectColumns()->clearOrderByColumns();
  368. if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  369. $criteria->addSelectColumn(NodeHomePeer::COUNT_DISTINCT);
  370. } else {
  371. $criteria->addSelectColumn(NodeHomePeer::COUNT);
  372. }
  373. // just in case we're grouping: add those columns to the select statement
  374. foreach($criteria->getGroupByColumns() as $column)
  375. {
  376. $criteria->addSelectColumn($column);
  377. }
  378. $criteria->addJoin(NodeHomePeer::NODE_ID, NodePeer::ID);
  379. $rs = NodeHomePeer::doSelectRS($criteria, $con);
  380. if ($rs->next()) {
  381. return $rs->getInt(1);
  382. } else {
  383. // no rows returned; we infer that means 0 matches.
  384. return 0;
  385. }
  386. }
  387. /**
  388. * Selects a collection of NodeHome objects pre-filled with all related objects.
  389. *
  390. * @return array Array of NodeHome objects.
  391. * @throws PropelException Any exceptions caught during processing will be
  392. * rethrown wrapped into a PropelException.
  393. */
  394. public static function doSelectJoinAll(Criteria $c, $con = null)
  395. {
  396. foreach (sfMixer::getCallables('BaseNodeHomePeer:doSelectJoinAll:doSelectJoinAll') as $callable)
  397. {
  398. call_user_func($callable, 'BaseNodeHomePeer', $c, $con);
  399. }
  400. $c = clone $c;
  401. // Set the correct dbName if it has not been overridden
  402. if ($c->getDbName() == Propel::getDefaultDB()) {
  403. $c->setDbName(self::DATABASE_NAME);
  404. }
  405. NodeHomePeer::addSelectColumns($c);
  406. $startcol2 = (NodeHomePeer::NUM_COLUMNS - NodeHomePeer::NUM_LAZY_LOAD_COLUMNS) + 1;
  407. NodePeer::addSelectColumns($c);
  408. $startcol3 = $startcol2 + NodePeer::NUM_COLUMNS;
  409. $c->addJoin(NodeHomePeer::NODE_ID, NodePeer::ID);
  410. $rs = BasePeer::doSelect($c, $con);
  411. $results = array();
  412. while($rs->next()) {
  413. $omClass = NodeHomePeer::getOMClass();
  414. $cls = sfPropel::import($omClass);
  415. $obj1 = new $cls();
  416. $obj1->hydrate($rs);
  417. // Add objects for joined Node rows
  418. $omClass = NodePeer::getOMClass();
  419. $cls = sfPropel::import($omClass);
  420. $obj2 = new $cls();
  421. $obj2->hydrate($rs, $startcol2);
  422. $newObject = true;
  423. for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
  424. $temp_obj1 = $results[$j];
  425. $temp_obj2 = $temp_obj1->getNode(); // CHECKME
  426. if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
  427. $newObject = false;
  428. $temp_obj2->addNodeHome($obj1); // CHECKME
  429. break;
  430. }
  431. }
  432. if ($newObject) {
  433. $obj2->initNodeHomes();
  434. $obj2->addNodeHome($obj1);
  435. }
  436. $results[] = $obj1;
  437. }
  438. return $results;
  439. }
  440. static public function getUniqueColumnNames()
  441. {
  442. return array();
  443. }
  444. /**
  445. * Returns the TableMap related to this peer.
  446. * This method is not needed for general use but a specific application could have a need.
  447. * @return TableMap
  448. * @throws PropelException Any exceptions caught during processing will be
  449. * rethrown wrapped into a PropelException.
  450. */
  451. public static function getTableMap()
  452. {
  453. return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
  454. }
  455. /**
  456. * The class that the Peer will make instances of.
  457. *
  458. * This uses a dot-path notation which is tranalted into a path
  459. * relative to a location on the PHP include_path.
  460. * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
  461. *
  462. * @return string path.to.ClassName
  463. */
  464. public static function getOMClass()
  465. {
  466. return NodeHomePeer::CLASS_DEFAULT;
  467. }
  468. /**
  469. * Method perform an INSERT on the database, given a NodeHome or Criteria object.
  470. *
  471. * @param mixed $values Criteria or NodeHome object containing data that is used to create the INSERT statement.
  472. * @param Connection $con the connection to use
  473. * @return mixed The new primary key.
  474. * @throws PropelException Any exceptions caught during processing will be
  475. * rethrown wrapped into a PropelException.
  476. */
  477. public static function doInsert($values, $con = null)
  478. {
  479. foreach (sfMixer::getCallables('BaseNodeHomePeer:doInsert:pre') as $callable)
  480. {
  481. $ret = call_user_func($callable, 'BaseNodeHomePeer', $values, $con);
  482. if (false !== $ret)
  483. {
  484. return $ret;
  485. }
  486. }
  487. if ($con === null) {
  488. $con = Propel::getConnection(self::DATABASE_NAME);
  489. }
  490. if ($values instanceof Criteria) {
  491. $criteria = clone $values; // rename for clarity
  492. } else {
  493. $criteria = $values->buildCriteria(); // build Criteria from NodeHome object
  494. }
  495. $criteria->remove(NodeHomePeer::ID); // remove pkey col since this table uses auto-increment
  496. // Set the correct dbName
  497. $criteria->setDbName(self::DATABASE_NAME);
  498. try {
  499. // use transaction because $criteria could contain info
  500. // for more than one table (I guess, conceivably)
  501. $con->begin();
  502. $pk = BasePeer::doInsert($criteria, $con);
  503. $con->commit();
  504. } catch(PropelException $e) {
  505. $con->rollback();
  506. throw $e;
  507. }
  508. foreach (sfMixer::getCallables('BaseNodeHomePeer:doInsert:post') as $callable)
  509. {
  510. call_user_func($callable, 'BaseNodeHomePeer', $values, $con, $pk);
  511. }
  512. return $pk;
  513. }
  514. /**
  515. * Method perform an UPDATE on the database, given a NodeHome or Criteria object.
  516. *
  517. * @param mixed $values Criteria or NodeHome object containing data that is used to create the UPDATE statement.
  518. * @param Connection $con The connection to use (specify Connection object to exert more control over transactions).
  519. * @return int The number of affected rows (if supported by underlying database driver).
  520. * @throws PropelException Any exceptions caught during processing will be
  521. * rethrown wrapped into a PropelException.
  522. */
  523. public static function doUpdate($values, $con = null)
  524. {
  525. foreach (sfMixer::getCallables('BaseNodeHomePeer:doUpdate:pre') as $callable)
  526. {
  527. $ret = call_user_func($callable, 'BaseNodeHomePeer', $values, $con);
  528. if (false !== $ret)
  529. {
  530. return $ret;
  531. }
  532. }
  533. if ($con === null) {
  534. $con = Propel::getConnection(self::DATABASE_NAME);
  535. }
  536. $selectCriteria = new Criteria(self::DATABASE_NAME);
  537. if ($values instanceof Criteria) {
  538. $criteria = clone $values; // rename for clarity
  539. $comparison = $criteria->getComparison(NodeHomePeer::ID);
  540. $selectCriteria->add(NodeHomePeer::ID, $criteria->remove(NodeHomePeer::ID), $comparison);
  541. } else { // $values is NodeHome object
  542. $criteria = $values->buildCriteria(); // gets full criteria
  543. $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
  544. }
  545. // set the correct dbName
  546. $criteria->setDbName(self::DATABASE_NAME);
  547. $ret = BasePeer::doUpdate($selectCriteria, $criteria, $con);
  548. foreach (sfMixer::getCallables('BaseNodeHomePeer:doUpdate:post') as $callable)
  549. {
  550. call_user_func($callable, 'BaseNodeHomePeer', $values, $con, $ret);
  551. }
  552. return $ret;
  553. }
  554. /**
  555. * Method to DELETE all rows from the node_home table.
  556. *
  557. * @return int The number of affected rows (if supported by underlying database driver).
  558. */
  559. public static function doDeleteAll($con = null)
  560. {
  561. if ($con === null) {
  562. $con = Propel::getConnection(self::DATABASE_NAME);
  563. }
  564. $affectedRows = 0; // initialize var to track total num of affected rows
  565. try {
  566. // use transaction because $criteria could contain info
  567. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  568. $con->begin();
  569. $affectedRows += BasePeer::doDeleteAll(NodeHomePeer::TABLE_NAME, $con);
  570. $con->commit();
  571. return $affectedRows;
  572. } catch (PropelException $e) {
  573. $con->rollback();
  574. throw $e;
  575. }
  576. }
  577. /**
  578. * Method perform a DELETE on the database, given a NodeHome or Criteria object OR a primary key value.
  579. *
  580. * @param mixed $values Criteria or NodeHome object or primary key or array of primary keys
  581. * which is used to create the DELETE statement
  582. * @param Connection $con the connection to use
  583. * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
  584. * if supported by native driver or if emulated using Propel.
  585. * @throws PropelException Any exceptions caught during processing will be
  586. * rethrown wrapped into a PropelException.
  587. */
  588. public static function doDelete($values, $con = null)
  589. {
  590. if ($con === null) {
  591. $con = Propel::getConnection(NodeHomePeer::DATABASE_NAME);
  592. }
  593. if ($values instanceof Criteria) {
  594. $criteria = clone $values; // rename for clarity
  595. } elseif ($values instanceof NodeHome) {
  596. $criteria = $values->buildPkeyCriteria();
  597. } else {
  598. // it must be the primary key
  599. $criteria = new Criteria(self::DATABASE_NAME);
  600. $criteria->add(NodeHomePeer::ID, (array) $values, Criteria::IN);
  601. }
  602. // Set the correct dbName
  603. $criteria->setDbName(self::DATABASE_NAME);
  604. $affectedRows = 0; // initialize var to track total num of affected rows
  605. try {
  606. // use transaction because $criteria could contain info
  607. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  608. $con->begin();
  609. $affectedRows += BasePeer::doDelete($criteria, $con);
  610. $con->commit();
  611. return $affectedRows;
  612. } catch (PropelException $e) {
  613. $con->rollback();
  614. throw $e;
  615. }
  616. }
  617. /**
  618. * Validates all modified columns of given NodeHome object.
  619. * If parameter $columns is either a single column name or an array of column names
  620. * than only those columns are validated.
  621. *
  622. * NOTICE: This does not apply to primary or foreign keys for now.
  623. *
  624. * @param NodeHome $obj The object to validate.
  625. * @param mixed $cols Column name or array of column names.
  626. *
  627. * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
  628. */
  629. public static function doValidate(NodeHome $obj, $cols = null)
  630. {
  631. $columns = array();
  632. if ($cols) {
  633. $dbMap = Propel::getDatabaseMap(NodeHomePeer::DATABASE_NAME);
  634. $tableMap = $dbMap->getTable(NodeHomePeer::TABLE_NAME);
  635. if (! is_array($cols)) {
  636. $cols = array($cols);
  637. }
  638. foreach($cols as $colName) {
  639. if ($tableMap->containsColumn($colName)) {
  640. $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
  641. $columns[$colName] = $obj->$get();
  642. }
  643. }
  644. } else {
  645. }
  646. $res = BasePeer::doValidate(NodeHomePeer::DATABASE_NAME, NodeHomePeer::TABLE_NAME, $columns);
  647. if ($res !== true) {
  648. $request = sfContext::getInstance()->getRequest();
  649. foreach ($res as $failed) {
  650. $col = NodeHomePeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
  651. $request->setError($col, $failed->getMessage());
  652. }
  653. }
  654. return $res;
  655. }
  656. /**
  657. * Retrieve a single object by pkey.
  658. *
  659. * @param mixed $pk the primary key.
  660. * @param Connection $con the connection to use
  661. * @return NodeHome
  662. */
  663. public static function retrieveByPK($pk, $con = null)
  664. {
  665. if ($con === null) {
  666. $con = Propel::getConnection(self::DATABASE_NAME);
  667. }
  668. $criteria = new Criteria(NodeHomePeer::DATABASE_NAME);
  669. $criteria->add(NodeHomePeer::ID, $pk);
  670. $v = NodeHomePeer::doSelect($criteria, $con);
  671. return !empty($v) > 0 ? $v[0] : null;
  672. }
  673. /**
  674. * Retrieve multiple objects by pkey.
  675. *
  676. * @param array $pks List of primary keys
  677. * @param Connection $con the connection to use
  678. * @throws PropelException Any exceptions caught during processing will be
  679. * rethrown wrapped into a PropelException.
  680. */
  681. public static function retrieveByPKs($pks, $con = null)
  682. {
  683. if ($con === null) {
  684. $con = Propel::getConnection(self::DATABASE_NAME);
  685. }
  686. $objs = null;
  687. if (empty($pks)) {
  688. $objs = array();
  689. } else {
  690. $criteria = new Criteria();
  691. $criteria->add(NodeHomePeer::ID, $pks, Criteria::IN);
  692. $objs = NodeHomePeer::doSelect($criteria, $con);
  693. }
  694. return $objs;
  695. }
  696. } // BaseNodeHomePeer
  697. // static code to register the map builder for this Peer with the main Propel class
  698. if (Propel::isInit()) {
  699. // the MapBuilder classes register themselves with Propel during initialization
  700. // so we need to load them here.
  701. try {
  702. BaseNodeHomePeer::getMapBuilder();
  703. } catch (Exception $e) {
  704. Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
  705. }
  706. } else {
  707. // even if Propel is not yet initialized, the map builder class can be registered
  708. // now and then it will be loaded when Propel initializes.
  709. Propel::registerMapBuilder('lib.model.map.NodeHomeMapBuilder');
  710. }