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