BaseCcPermsPeer.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. <?php
  2. /**
  3. * Base static class for performing query and update operations on the 'cc_perms' table.
  4. *
  5. *
  6. *
  7. * @package propel.generator.airtime.om
  8. */
  9. abstract class BaseCcPermsPeer {
  10. /** the default database name for this class */
  11. const DATABASE_NAME = 'airtime';
  12. /** the table name for this class */
  13. const TABLE_NAME = 'cc_perms';
  14. /** the related Propel class for this table */
  15. const OM_CLASS = 'CcPerms';
  16. /** A class that can be returned by this peer. */
  17. const CLASS_DEFAULT = 'airtime.CcPerms';
  18. /** the related TableMap class for this table */
  19. const TM_CLASS = 'CcPermsTableMap';
  20. /** The total number of columns. */
  21. const NUM_COLUMNS = 5;
  22. /** The number of lazy-loaded columns. */
  23. const NUM_LAZY_LOAD_COLUMNS = 0;
  24. /** the column name for the PERMID field */
  25. const PERMID = 'cc_perms.PERMID';
  26. /** the column name for the SUBJ field */
  27. const SUBJ = 'cc_perms.SUBJ';
  28. /** the column name for the ACTION field */
  29. const ACTION = 'cc_perms.ACTION';
  30. /** the column name for the OBJ field */
  31. const OBJ = 'cc_perms.OBJ';
  32. /** the column name for the TYPE field */
  33. const TYPE = 'cc_perms.TYPE';
  34. /**
  35. * An identiy map to hold any loaded instances of CcPerms objects.
  36. * This must be public so that other peer classes can access this when hydrating from JOIN
  37. * queries.
  38. * @var array CcPerms[]
  39. */
  40. public static $instances = array();
  41. /**
  42. * holds an array of fieldnames
  43. *
  44. * first dimension keys are the type constants
  45. * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
  46. */
  47. private static $fieldNames = array (
  48. BasePeer::TYPE_PHPNAME => array ('Permid', 'Subj', 'Action', 'Obj', 'Type', ),
  49. BasePeer::TYPE_STUDLYPHPNAME => array ('permid', 'subj', 'action', 'obj', 'type', ),
  50. BasePeer::TYPE_COLNAME => array (self::PERMID, self::SUBJ, self::ACTION, self::OBJ, self::TYPE, ),
  51. BasePeer::TYPE_RAW_COLNAME => array ('PERMID', 'SUBJ', 'ACTION', 'OBJ', 'TYPE', ),
  52. BasePeer::TYPE_FIELDNAME => array ('permid', 'subj', 'action', 'obj', 'type', ),
  53. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
  54. );
  55. /**
  56. * holds an array of keys for quick access to the fieldnames array
  57. *
  58. * first dimension keys are the type constants
  59. * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
  60. */
  61. private static $fieldKeys = array (
  62. BasePeer::TYPE_PHPNAME => array ('Permid' => 0, 'Subj' => 1, 'Action' => 2, 'Obj' => 3, 'Type' => 4, ),
  63. BasePeer::TYPE_STUDLYPHPNAME => array ('permid' => 0, 'subj' => 1, 'action' => 2, 'obj' => 3, 'type' => 4, ),
  64. BasePeer::TYPE_COLNAME => array (self::PERMID => 0, self::SUBJ => 1, self::ACTION => 2, self::OBJ => 3, self::TYPE => 4, ),
  65. BasePeer::TYPE_RAW_COLNAME => array ('PERMID' => 0, 'SUBJ' => 1, 'ACTION' => 2, 'OBJ' => 3, 'TYPE' => 4, ),
  66. BasePeer::TYPE_FIELDNAME => array ('permid' => 0, 'subj' => 1, 'action' => 2, 'obj' => 3, 'type' => 4, ),
  67. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
  68. );
  69. /**
  70. * Translates a fieldname to another type
  71. *
  72. * @param string $name field name
  73. * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  74. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  75. * @param string $toType One of the class type constants
  76. * @return string translated name of the field.
  77. * @throws PropelException - if the specified name could not be found in the fieldname mappings.
  78. */
  79. static public function translateFieldName($name, $fromType, $toType)
  80. {
  81. $toNames = self::getFieldNames($toType);
  82. $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
  83. if ($key === null) {
  84. throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
  85. }
  86. return $toNames[$key];
  87. }
  88. /**
  89. * Returns an array of field names.
  90. *
  91. * @param string $type The type of fieldnames to return:
  92. * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  93. * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  94. * @return array A list of field names
  95. */
  96. static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
  97. {
  98. if (!array_key_exists($type, self::$fieldNames)) {
  99. throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
  100. }
  101. return self::$fieldNames[$type];
  102. }
  103. /**
  104. * Convenience method which changes table.column to alias.column.
  105. *
  106. * Using this method you can maintain SQL abstraction while using column aliases.
  107. * <code>
  108. * $c->addAlias("alias1", TablePeer::TABLE_NAME);
  109. * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
  110. * </code>
  111. * @param string $alias The alias for the current table.
  112. * @param string $column The column name for current table. (i.e. CcPermsPeer::COLUMN_NAME).
  113. * @return string
  114. */
  115. public static function alias($alias, $column)
  116. {
  117. return str_replace(CcPermsPeer::TABLE_NAME.'.', $alias.'.', $column);
  118. }
  119. /**
  120. * Add all the columns needed to create a new object.
  121. *
  122. * Note: any columns that were marked with lazyLoad="true" in the
  123. * XML schema will not be added to the select list and only loaded
  124. * on demand.
  125. *
  126. * @param Criteria $criteria object containing the columns to add.
  127. * @param string $alias optional table alias
  128. * @throws PropelException Any exceptions caught during processing will be
  129. * rethrown wrapped into a PropelException.
  130. */
  131. public static function addSelectColumns(Criteria $criteria, $alias = null)
  132. {
  133. if (null === $alias) {
  134. $criteria->addSelectColumn(CcPermsPeer::PERMID);
  135. $criteria->addSelectColumn(CcPermsPeer::SUBJ);
  136. $criteria->addSelectColumn(CcPermsPeer::ACTION);
  137. $criteria->addSelectColumn(CcPermsPeer::OBJ);
  138. $criteria->addSelectColumn(CcPermsPeer::TYPE);
  139. } else {
  140. $criteria->addSelectColumn($alias . '.PERMID');
  141. $criteria->addSelectColumn($alias . '.SUBJ');
  142. $criteria->addSelectColumn($alias . '.ACTION');
  143. $criteria->addSelectColumn($alias . '.OBJ');
  144. $criteria->addSelectColumn($alias . '.TYPE');
  145. }
  146. }
  147. /**
  148. * Returns the number of rows matching criteria.
  149. *
  150. * @param Criteria $criteria
  151. * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
  152. * @param PropelPDO $con
  153. * @return int Number of matching rows.
  154. */
  155. public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
  156. {
  157. // we may modify criteria, so copy it first
  158. $criteria = clone $criteria;
  159. // We need to set the primary table name, since in the case that there are no WHERE columns
  160. // it will be impossible for the BasePeer::createSelectSql() method to determine which
  161. // tables go into the FROM clause.
  162. $criteria->setPrimaryTableName(CcPermsPeer::TABLE_NAME);
  163. if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  164. $criteria->setDistinct();
  165. }
  166. if (!$criteria->hasSelectClause()) {
  167. CcPermsPeer::addSelectColumns($criteria);
  168. }
  169. $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
  170. $criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName
  171. if ($con === null) {
  172. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  173. }
  174. // BasePeer returns a PDOStatement
  175. $stmt = BasePeer::doCount($criteria, $con);
  176. if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  177. $count = (int) $row[0];
  178. } else {
  179. $count = 0; // no rows returned; we infer that means 0 matches.
  180. }
  181. $stmt->closeCursor();
  182. return $count;
  183. }
  184. /**
  185. * Method to select one object from the DB.
  186. *
  187. * @param Criteria $criteria object used to create the SELECT statement.
  188. * @param PropelPDO $con
  189. * @return CcPerms
  190. * @throws PropelException Any exceptions caught during processing will be
  191. * rethrown wrapped into a PropelException.
  192. */
  193. public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
  194. {
  195. $critcopy = clone $criteria;
  196. $critcopy->setLimit(1);
  197. $objects = CcPermsPeer::doSelect($critcopy, $con);
  198. if ($objects) {
  199. return $objects[0];
  200. }
  201. return null;
  202. }
  203. /**
  204. * Method to do selects.
  205. *
  206. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  207. * @param PropelPDO $con
  208. * @return array Array of selected Objects
  209. * @throws PropelException Any exceptions caught during processing will be
  210. * rethrown wrapped into a PropelException.
  211. */
  212. public static function doSelect(Criteria $criteria, PropelPDO $con = null)
  213. {
  214. return CcPermsPeer::populateObjects(CcPermsPeer::doSelectStmt($criteria, $con));
  215. }
  216. /**
  217. * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
  218. *
  219. * Use this method directly if you want to work with an executed statement durirectly (for example
  220. * to perform your own object hydration).
  221. *
  222. * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  223. * @param PropelPDO $con The connection to use
  224. * @throws PropelException Any exceptions caught during processing will be
  225. * rethrown wrapped into a PropelException.
  226. * @return PDOStatement The executed PDOStatement object.
  227. * @see BasePeer::doSelect()
  228. */
  229. public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
  230. {
  231. if ($con === null) {
  232. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  233. }
  234. if (!$criteria->hasSelectClause()) {
  235. $criteria = clone $criteria;
  236. CcPermsPeer::addSelectColumns($criteria);
  237. }
  238. // Set the correct dbName
  239. $criteria->setDbName(self::DATABASE_NAME);
  240. // BasePeer returns a PDOStatement
  241. return BasePeer::doSelect($criteria, $con);
  242. }
  243. /**
  244. * Adds an object to the instance pool.
  245. *
  246. * Propel keeps cached copies of objects in an instance pool when they are retrieved
  247. * from the database. In some cases -- especially when you override doSelect*()
  248. * methods in your stub classes -- you may need to explicitly add objects
  249. * to the cache in order to ensure that the same objects are always returned by doSelect*()
  250. * and retrieveByPK*() calls.
  251. *
  252. * @param CcPerms $value A CcPerms object.
  253. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  254. */
  255. public static function addInstanceToPool(CcPerms $obj, $key = null)
  256. {
  257. if (Propel::isInstancePoolingEnabled()) {
  258. if ($key === null) {
  259. $key = (string) $obj->getPermid();
  260. } // if key === null
  261. self::$instances[$key] = $obj;
  262. }
  263. }
  264. /**
  265. * Removes an object from the instance pool.
  266. *
  267. * Propel keeps cached copies of objects in an instance pool when they are retrieved
  268. * from the database. In some cases -- especially when you override doDelete
  269. * methods in your stub classes -- you may need to explicitly remove objects
  270. * from the cache in order to prevent returning objects that no longer exist.
  271. *
  272. * @param mixed $value A CcPerms object or a primary key value.
  273. */
  274. public static function removeInstanceFromPool($value)
  275. {
  276. if (Propel::isInstancePoolingEnabled() && $value !== null) {
  277. if (is_object($value) && $value instanceof CcPerms) {
  278. $key = (string) $value->getPermid();
  279. } elseif (is_scalar($value)) {
  280. // assume we've been passed a primary key
  281. $key = (string) $value;
  282. } else {
  283. $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or CcPerms object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
  284. throw $e;
  285. }
  286. unset(self::$instances[$key]);
  287. }
  288. } // removeInstanceFromPool()
  289. /**
  290. * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
  291. *
  292. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  293. * a multi-column primary key, a serialize()d version of the primary key will be returned.
  294. *
  295. * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
  296. * @return CcPerms Found object or NULL if 1) no instance exists for specified key or 2) instance pooling has been disabled.
  297. * @see getPrimaryKeyHash()
  298. */
  299. public static function getInstanceFromPool($key)
  300. {
  301. if (Propel::isInstancePoolingEnabled()) {
  302. if (isset(self::$instances[$key])) {
  303. return self::$instances[$key];
  304. }
  305. }
  306. return null; // just to be explicit
  307. }
  308. /**
  309. * Clear the instance pool.
  310. *
  311. * @return void
  312. */
  313. public static function clearInstancePool()
  314. {
  315. self::$instances = array();
  316. }
  317. /**
  318. * Method to invalidate the instance pool of all tables related to cc_perms
  319. * by a foreign key with ON DELETE CASCADE
  320. */
  321. public static function clearRelatedInstancePool()
  322. {
  323. }
  324. /**
  325. * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
  326. *
  327. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  328. * a multi-column primary key, a serialize()d version of the primary key will be returned.
  329. *
  330. * @param array $row PropelPDO resultset row.
  331. * @param int $startcol The 0-based offset for reading from the resultset row.
  332. * @return string A string version of PK or NULL if the components of primary key in result array are all null.
  333. */
  334. public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
  335. {
  336. // If the PK cannot be derived from the row, return NULL.
  337. if ($row[$startcol] === null) {
  338. return null;
  339. }
  340. return (string) $row[$startcol];
  341. }
  342. /**
  343. * Retrieves the primary key from the DB resultset row
  344. * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
  345. * a multi-column primary key, an array of the primary key columns will be returned.
  346. *
  347. * @param array $row PropelPDO resultset row.
  348. * @param int $startcol The 0-based offset for reading from the resultset row.
  349. * @return mixed The primary key of the row
  350. */
  351. public static function getPrimaryKeyFromRow($row, $startcol = 0)
  352. {
  353. return (int) $row[$startcol];
  354. }
  355. /**
  356. * The returned array will contain objects of the default type or
  357. * objects that inherit from the default.
  358. *
  359. * @throws PropelException Any exceptions caught during processing will be
  360. * rethrown wrapped into a PropelException.
  361. */
  362. public static function populateObjects(PDOStatement $stmt)
  363. {
  364. $results = array();
  365. // set the class once to avoid overhead in the loop
  366. $cls = CcPermsPeer::getOMClass(false);
  367. // populate the object(s)
  368. while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  369. $key = CcPermsPeer::getPrimaryKeyHashFromRow($row, 0);
  370. if (null !== ($obj = CcPermsPeer::getInstanceFromPool($key))) {
  371. // We no longer rehydrate the object, since this can cause data loss.
  372. // See http://www.propelorm.org/ticket/509
  373. // $obj->hydrate($row, 0, true); // rehydrate
  374. $results[] = $obj;
  375. } else {
  376. $obj = new $cls();
  377. $obj->hydrate($row);
  378. $results[] = $obj;
  379. CcPermsPeer::addInstanceToPool($obj, $key);
  380. } // if key exists
  381. }
  382. $stmt->closeCursor();
  383. return $results;
  384. }
  385. /**
  386. * Populates an object of the default type or an object that inherit from the default.
  387. *
  388. * @param array $row PropelPDO resultset row.
  389. * @param int $startcol The 0-based offset for reading from the resultset row.
  390. * @throws PropelException Any exceptions caught during processing will be
  391. * rethrown wrapped into a PropelException.
  392. * @return array (CcPerms object, last column rank)
  393. */
  394. public static function populateObject($row, $startcol = 0)
  395. {
  396. $key = CcPermsPeer::getPrimaryKeyHashFromRow($row, $startcol);
  397. if (null !== ($obj = CcPermsPeer::getInstanceFromPool($key))) {
  398. // We no longer rehydrate the object, since this can cause data loss.
  399. // See http://www.propelorm.org/ticket/509
  400. // $obj->hydrate($row, $startcol, true); // rehydrate
  401. $col = $startcol + CcPermsPeer::NUM_COLUMNS;
  402. } else {
  403. $cls = CcPermsPeer::OM_CLASS;
  404. $obj = new $cls();
  405. $col = $obj->hydrate($row, $startcol);
  406. CcPermsPeer::addInstanceToPool($obj, $key);
  407. }
  408. return array($obj, $col);
  409. }
  410. /**
  411. * Returns the number of rows matching criteria, joining the related CcSubjs table
  412. *
  413. * @param Criteria $criteria
  414. * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
  415. * @param PropelPDO $con
  416. * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  417. * @return int Number of matching rows.
  418. */
  419. public static function doCountJoinCcSubjs(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
  420. {
  421. // we're going to modify criteria, so copy it first
  422. $criteria = clone $criteria;
  423. // We need to set the primary table name, since in the case that there are no WHERE columns
  424. // it will be impossible for the BasePeer::createSelectSql() method to determine which
  425. // tables go into the FROM clause.
  426. $criteria->setPrimaryTableName(CcPermsPeer::TABLE_NAME);
  427. if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  428. $criteria->setDistinct();
  429. }
  430. if (!$criteria->hasSelectClause()) {
  431. CcPermsPeer::addSelectColumns($criteria);
  432. }
  433. $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
  434. // Set the correct dbName
  435. $criteria->setDbName(self::DATABASE_NAME);
  436. if ($con === null) {
  437. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  438. }
  439. $criteria->addJoin(CcPermsPeer::SUBJ, CcSubjsPeer::ID, $join_behavior);
  440. $stmt = BasePeer::doCount($criteria, $con);
  441. if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  442. $count = (int) $row[0];
  443. } else {
  444. $count = 0; // no rows returned; we infer that means 0 matches.
  445. }
  446. $stmt->closeCursor();
  447. return $count;
  448. }
  449. /**
  450. * Selects a collection of CcPerms objects pre-filled with their CcSubjs objects.
  451. * @param Criteria $criteria
  452. * @param PropelPDO $con
  453. * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  454. * @return array Array of CcPerms objects.
  455. * @throws PropelException Any exceptions caught during processing will be
  456. * rethrown wrapped into a PropelException.
  457. */
  458. public static function doSelectJoinCcSubjs(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
  459. {
  460. $criteria = clone $criteria;
  461. // Set the correct dbName if it has not been overridden
  462. if ($criteria->getDbName() == Propel::getDefaultDB()) {
  463. $criteria->setDbName(self::DATABASE_NAME);
  464. }
  465. CcPermsPeer::addSelectColumns($criteria);
  466. $startcol = (CcPermsPeer::NUM_COLUMNS - CcPermsPeer::NUM_LAZY_LOAD_COLUMNS);
  467. CcSubjsPeer::addSelectColumns($criteria);
  468. $criteria->addJoin(CcPermsPeer::SUBJ, CcSubjsPeer::ID, $join_behavior);
  469. $stmt = BasePeer::doSelect($criteria, $con);
  470. $results = array();
  471. while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  472. $key1 = CcPermsPeer::getPrimaryKeyHashFromRow($row, 0);
  473. if (null !== ($obj1 = CcPermsPeer::getInstanceFromPool($key1))) {
  474. // We no longer rehydrate the object, since this can cause data loss.
  475. // See http://www.propelorm.org/ticket/509
  476. // $obj1->hydrate($row, 0, true); // rehydrate
  477. } else {
  478. $cls = CcPermsPeer::getOMClass(false);
  479. $obj1 = new $cls();
  480. $obj1->hydrate($row);
  481. CcPermsPeer::addInstanceToPool($obj1, $key1);
  482. } // if $obj1 already loaded
  483. $key2 = CcSubjsPeer::getPrimaryKeyHashFromRow($row, $startcol);
  484. if ($key2 !== null) {
  485. $obj2 = CcSubjsPeer::getInstanceFromPool($key2);
  486. if (!$obj2) {
  487. $cls = CcSubjsPeer::getOMClass(false);
  488. $obj2 = new $cls();
  489. $obj2->hydrate($row, $startcol);
  490. CcSubjsPeer::addInstanceToPool($obj2, $key2);
  491. } // if obj2 already loaded
  492. // Add the $obj1 (CcPerms) to $obj2 (CcSubjs)
  493. $obj2->addCcPerms($obj1);
  494. } // if joined row was not null
  495. $results[] = $obj1;
  496. }
  497. $stmt->closeCursor();
  498. return $results;
  499. }
  500. /**
  501. * Returns the number of rows matching criteria, joining all related tables
  502. *
  503. * @param Criteria $criteria
  504. * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
  505. * @param PropelPDO $con
  506. * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  507. * @return int Number of matching rows.
  508. */
  509. public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
  510. {
  511. // we're going to modify criteria, so copy it first
  512. $criteria = clone $criteria;
  513. // We need to set the primary table name, since in the case that there are no WHERE columns
  514. // it will be impossible for the BasePeer::createSelectSql() method to determine which
  515. // tables go into the FROM clause.
  516. $criteria->setPrimaryTableName(CcPermsPeer::TABLE_NAME);
  517. if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  518. $criteria->setDistinct();
  519. }
  520. if (!$criteria->hasSelectClause()) {
  521. CcPermsPeer::addSelectColumns($criteria);
  522. }
  523. $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
  524. // Set the correct dbName
  525. $criteria->setDbName(self::DATABASE_NAME);
  526. if ($con === null) {
  527. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  528. }
  529. $criteria->addJoin(CcPermsPeer::SUBJ, CcSubjsPeer::ID, $join_behavior);
  530. $stmt = BasePeer::doCount($criteria, $con);
  531. if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  532. $count = (int) $row[0];
  533. } else {
  534. $count = 0; // no rows returned; we infer that means 0 matches.
  535. }
  536. $stmt->closeCursor();
  537. return $count;
  538. }
  539. /**
  540. * Selects a collection of CcPerms objects pre-filled with all related objects.
  541. *
  542. * @param Criteria $criteria
  543. * @param PropelPDO $con
  544. * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  545. * @return array Array of CcPerms objects.
  546. * @throws PropelException Any exceptions caught during processing will be
  547. * rethrown wrapped into a PropelException.
  548. */
  549. public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
  550. {
  551. $criteria = clone $criteria;
  552. // Set the correct dbName if it has not been overridden
  553. if ($criteria->getDbName() == Propel::getDefaultDB()) {
  554. $criteria->setDbName(self::DATABASE_NAME);
  555. }
  556. CcPermsPeer::addSelectColumns($criteria);
  557. $startcol2 = (CcPermsPeer::NUM_COLUMNS - CcPermsPeer::NUM_LAZY_LOAD_COLUMNS);
  558. CcSubjsPeer::addSelectColumns($criteria);
  559. $startcol3 = $startcol2 + (CcSubjsPeer::NUM_COLUMNS - CcSubjsPeer::NUM_LAZY_LOAD_COLUMNS);
  560. $criteria->addJoin(CcPermsPeer::SUBJ, CcSubjsPeer::ID, $join_behavior);
  561. $stmt = BasePeer::doSelect($criteria, $con);
  562. $results = array();
  563. while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
  564. $key1 = CcPermsPeer::getPrimaryKeyHashFromRow($row, 0);
  565. if (null !== ($obj1 = CcPermsPeer::getInstanceFromPool($key1))) {
  566. // We no longer rehydrate the object, since this can cause data loss.
  567. // See http://www.propelorm.org/ticket/509
  568. // $obj1->hydrate($row, 0, true); // rehydrate
  569. } else {
  570. $cls = CcPermsPeer::getOMClass(false);
  571. $obj1 = new $cls();
  572. $obj1->hydrate($row);
  573. CcPermsPeer::addInstanceToPool($obj1, $key1);
  574. } // if obj1 already loaded
  575. // Add objects for joined CcSubjs rows
  576. $key2 = CcSubjsPeer::getPrimaryKeyHashFromRow($row, $startcol2);
  577. if ($key2 !== null) {
  578. $obj2 = CcSubjsPeer::getInstanceFromPool($key2);
  579. if (!$obj2) {
  580. $cls = CcSubjsPeer::getOMClass(false);
  581. $obj2 = new $cls();
  582. $obj2->hydrate($row, $startcol2);
  583. CcSubjsPeer::addInstanceToPool($obj2, $key2);
  584. } // if obj2 loaded
  585. // Add the $obj1 (CcPerms) to the collection in $obj2 (CcSubjs)
  586. $obj2->addCcPerms($obj1);
  587. } // if joined row not null
  588. $results[] = $obj1;
  589. }
  590. $stmt->closeCursor();
  591. return $results;
  592. }
  593. /**
  594. * Returns the TableMap related to this peer.
  595. * This method is not needed for general use but a specific application could have a need.
  596. * @return TableMap
  597. * @throws PropelException Any exceptions caught during processing will be
  598. * rethrown wrapped into a PropelException.
  599. */
  600. public static function getTableMap()
  601. {
  602. return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
  603. }
  604. /**
  605. * Add a TableMap instance to the database for this peer class.
  606. */
  607. public static function buildTableMap()
  608. {
  609. $dbMap = Propel::getDatabaseMap(BaseCcPermsPeer::DATABASE_NAME);
  610. if (!$dbMap->hasTable(BaseCcPermsPeer::TABLE_NAME))
  611. {
  612. $dbMap->addTableObject(new CcPermsTableMap());
  613. }
  614. }
  615. /**
  616. * The class that the Peer will make instances of.
  617. *
  618. * If $withPrefix is true, the returned path
  619. * uses a dot-path notation which is tranalted into a path
  620. * relative to a location on the PHP include_path.
  621. * (e.g. path.to.MyClass -> 'path/to/MyClass.php')
  622. *
  623. * @param boolean $withPrefix Whether or not to return the path with the class name
  624. * @return string path.to.ClassName
  625. */
  626. public static function getOMClass($withPrefix = true)
  627. {
  628. return $withPrefix ? CcPermsPeer::CLASS_DEFAULT : CcPermsPeer::OM_CLASS;
  629. }
  630. /**
  631. * Method perform an INSERT on the database, given a CcPerms or Criteria object.
  632. *
  633. * @param mixed $values Criteria or CcPerms object containing data that is used to create the INSERT statement.
  634. * @param PropelPDO $con the PropelPDO connection to use
  635. * @return mixed The new primary key.
  636. * @throws PropelException Any exceptions caught during processing will be
  637. * rethrown wrapped into a PropelException.
  638. */
  639. public static function doInsert($values, PropelPDO $con = null)
  640. {
  641. if ($con === null) {
  642. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  643. }
  644. if ($values instanceof Criteria) {
  645. $criteria = clone $values; // rename for clarity
  646. } else {
  647. $criteria = $values->buildCriteria(); // build Criteria from CcPerms object
  648. }
  649. // Set the correct dbName
  650. $criteria->setDbName(self::DATABASE_NAME);
  651. try {
  652. // use transaction because $criteria could contain info
  653. // for more than one table (I guess, conceivably)
  654. $con->beginTransaction();
  655. $pk = BasePeer::doInsert($criteria, $con);
  656. $con->commit();
  657. } catch(PropelException $e) {
  658. $con->rollBack();
  659. throw $e;
  660. }
  661. return $pk;
  662. }
  663. /**
  664. * Method perform an UPDATE on the database, given a CcPerms or Criteria object.
  665. *
  666. * @param mixed $values Criteria or CcPerms object containing data that is used to create the UPDATE statement.
  667. * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
  668. * @return int The number of affected rows (if supported by underlying database driver).
  669. * @throws PropelException Any exceptions caught during processing will be
  670. * rethrown wrapped into a PropelException.
  671. */
  672. public static function doUpdate($values, PropelPDO $con = null)
  673. {
  674. if ($con === null) {
  675. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  676. }
  677. $selectCriteria = new Criteria(self::DATABASE_NAME);
  678. if ($values instanceof Criteria) {
  679. $criteria = clone $values; // rename for clarity
  680. $comparison = $criteria->getComparison(CcPermsPeer::PERMID);
  681. $value = $criteria->remove(CcPermsPeer::PERMID);
  682. if ($value) {
  683. $selectCriteria->add(CcPermsPeer::PERMID, $value, $comparison);
  684. } else {
  685. $selectCriteria->setPrimaryTableName(CcPermsPeer::TABLE_NAME);
  686. }
  687. } else { // $values is CcPerms object
  688. $criteria = $values->buildCriteria(); // gets full criteria
  689. $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
  690. }
  691. // set the correct dbName
  692. $criteria->setDbName(self::DATABASE_NAME);
  693. return BasePeer::doUpdate($selectCriteria, $criteria, $con);
  694. }
  695. /**
  696. * Method to DELETE all rows from the cc_perms table.
  697. *
  698. * @return int The number of affected rows (if supported by underlying database driver).
  699. */
  700. public static function doDeleteAll($con = null)
  701. {
  702. if ($con === null) {
  703. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  704. }
  705. $affectedRows = 0; // initialize var to track total num of affected rows
  706. try {
  707. // use transaction because $criteria could contain info
  708. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  709. $con->beginTransaction();
  710. $affectedRows += BasePeer::doDeleteAll(CcPermsPeer::TABLE_NAME, $con, CcPermsPeer::DATABASE_NAME);
  711. // Because this db requires some delete cascade/set null emulation, we have to
  712. // clear the cached instance *after* the emulation has happened (since
  713. // instances get re-added by the select statement contained therein).
  714. CcPermsPeer::clearInstancePool();
  715. CcPermsPeer::clearRelatedInstancePool();
  716. $con->commit();
  717. return $affectedRows;
  718. } catch (PropelException $e) {
  719. $con->rollBack();
  720. throw $e;
  721. }
  722. }
  723. /**
  724. * Method perform a DELETE on the database, given a CcPerms or Criteria object OR a primary key value.
  725. *
  726. * @param mixed $values Criteria or CcPerms object or primary key or array of primary keys
  727. * which is used to create the DELETE statement
  728. * @param PropelPDO $con the connection to use
  729. * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
  730. * if supported by native driver or if emulated using Propel.
  731. * @throws PropelException Any exceptions caught during processing will be
  732. * rethrown wrapped into a PropelException.
  733. */
  734. public static function doDelete($values, PropelPDO $con = null)
  735. {
  736. if ($con === null) {
  737. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
  738. }
  739. if ($values instanceof Criteria) {
  740. // invalidate the cache for all objects of this type, since we have no
  741. // way of knowing (without running a query) what objects should be invalidated
  742. // from the cache based on this Criteria.
  743. CcPermsPeer::clearInstancePool();
  744. // rename for clarity
  745. $criteria = clone $values;
  746. } elseif ($values instanceof CcPerms) { // it's a model object
  747. // invalidate the cache for this single object
  748. CcPermsPeer::removeInstanceFromPool($values);
  749. // create criteria based on pk values
  750. $criteria = $values->buildPkeyCriteria();
  751. } else { // it's a primary key, or an array of pks
  752. $criteria = new Criteria(self::DATABASE_NAME);
  753. $criteria->add(CcPermsPeer::PERMID, (array) $values, Criteria::IN);
  754. // invalidate the cache for this object(s)
  755. foreach ((array) $values as $singleval) {
  756. CcPermsPeer::removeInstanceFromPool($singleval);
  757. }
  758. }
  759. // Set the correct dbName
  760. $criteria->setDbName(self::DATABASE_NAME);
  761. $affectedRows = 0; // initialize var to track total num of affected rows
  762. try {
  763. // use transaction because $criteria could contain info
  764. // for more than one table or we could emulating ON DELETE CASCADE, etc.
  765. $con->beginTransaction();
  766. $affectedRows += BasePeer::doDelete($criteria, $con);
  767. CcPermsPeer::clearRelatedInstancePool();
  768. $con->commit();
  769. return $affectedRows;
  770. } catch (PropelException $e) {
  771. $con->rollBack();
  772. throw $e;
  773. }
  774. }
  775. /**
  776. * Validates all modified columns of given CcPerms object.
  777. * If parameter $columns is either a single column name or an array of column names
  778. * than only those columns are validated.
  779. *
  780. * NOTICE: This does not apply to primary or foreign keys for now.
  781. *
  782. * @param CcPerms $obj The object to validate.
  783. * @param mixed $cols Column name or array of column names.
  784. *
  785. * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
  786. */
  787. public static function doValidate(CcPerms $obj, $cols = null)
  788. {
  789. $columns = array();
  790. if ($cols) {
  791. $dbMap = Propel::getDatabaseMap(CcPermsPeer::DATABASE_NAME);
  792. $tableMap = $dbMap->getTable(CcPermsPeer::TABLE_NAME);
  793. if (! is_array($cols)) {
  794. $cols = array($cols);
  795. }
  796. foreach ($cols as $colName) {
  797. if ($tableMap->containsColumn($colName)) {
  798. $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
  799. $columns[$colName] = $obj->$get();
  800. }
  801. }
  802. } else {
  803. }
  804. return BasePeer::doValidate(CcPermsPeer::DATABASE_NAME, CcPermsPeer::TABLE_NAME, $columns);
  805. }
  806. /**
  807. * Retrieve a single object by pkey.
  808. *
  809. * @param int $pk the primary key.
  810. * @param PropelPDO $con the connection to use
  811. * @return CcPerms
  812. */
  813. public static function retrieveByPK($pk, PropelPDO $con = null)
  814. {
  815. if (null !== ($obj = CcPermsPeer::getInstanceFromPool((string) $pk))) {
  816. return $obj;
  817. }
  818. if ($con === null) {
  819. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  820. }
  821. $criteria = new Criteria(CcPermsPeer::DATABASE_NAME);
  822. $criteria->add(CcPermsPeer::PERMID, $pk);
  823. $v = CcPermsPeer::doSelect($criteria, $con);
  824. return !empty($v) > 0 ? $v[0] : null;
  825. }
  826. /**
  827. * Retrieve multiple objects by pkey.
  828. *
  829. * @param array $pks List of primary keys
  830. * @param PropelPDO $con the connection to use
  831. * @throws PropelException Any exceptions caught during processing will be
  832. * rethrown wrapped into a PropelException.
  833. */
  834. public static function retrieveByPKs($pks, PropelPDO $con = null)
  835. {
  836. if ($con === null) {
  837. $con = Propel::getConnection(CcPermsPeer::DATABASE_NAME, Propel::CONNECTION_READ);
  838. }
  839. $objs = null;
  840. if (empty($pks)) {
  841. $objs = array();
  842. } else {
  843. $criteria = new Criteria(CcPermsPeer::DATABASE_NAME);
  844. $criteria->add(CcPermsPeer::PERMID, $pks, Criteria::IN);
  845. $objs = CcPermsPeer::doSelect($criteria, $con);
  846. }
  847. return $objs;
  848. }
  849. } // BaseCcPermsPeer
  850. // This is the static code needed to register the TableMap for this table with the main Propel class.
  851. //
  852. BaseCcPermsPeer::buildTableMap();