BaseNodeNetworkPeer.php 25 KB

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