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_US';
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 directly (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($and_clear_all_references = false)
394: {
395: if ($and_clear_all_references)
396: {
397: foreach (ModulePeer::$instances as $instance)
398: {
399: $instance->clearAllReferences(true);
400: }
401: }
402: ModulePeer::$instances = array();
403: }
404:
405: /**
406: * Method to invalidate the instance pool of all tables related to module
407: * by a foreign key with ON DELETE CASCADE
408: */
409: public static function clearRelatedInstancePool()
410: {
411: // Invalidate objects in GroupModulePeer instance pool,
412: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
413: GroupModulePeer::clearInstancePool();
414: // Invalidate objects in ModuleI18nPeer instance pool,
415: // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
416: ModuleI18nPeer::clearInstancePool();
417: }
418:
419: /**
420: * 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.
421: *
422: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
423: * a multi-column primary key, a serialize()d version of the primary key will be returned.
424: *
425: * @param array $row PropelPDO resultset row.
426: * @param int $startcol The 0-based offset for reading from the resultset row.
427: * @return string A string version of PK or null if the components of primary key in result array are all null.
428: */
429: public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
430: {
431: // If the PK cannot be derived from the row, return null.
432: if ($row[$startcol] === null) {
433: return null;
434: }
435:
436: return (string) $row[$startcol];
437: }
438:
439: /**
440: * Retrieves the primary key from the DB resultset row
441: * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
442: * a multi-column primary key, an array of the primary key columns will be returned.
443: *
444: * @param array $row PropelPDO resultset row.
445: * @param int $startcol The 0-based offset for reading from the resultset row.
446: * @return mixed The primary key of the row
447: */
448: public static function getPrimaryKeyFromRow($row, $startcol = 0)
449: {
450:
451: return (int) $row[$startcol];
452: }
453:
454: /**
455: * The returned array will contain objects of the default type or
456: * objects that inherit from the default.
457: *
458: * @throws PropelException Any exceptions caught during processing will be
459: * rethrown wrapped into a PropelException.
460: */
461: public static function populateObjects(PDOStatement $stmt)
462: {
463: $results = array();
464:
465: // set the class once to avoid overhead in the loop
466: $cls = ModulePeer::getOMClass();
467: // populate the object(s)
468: while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
469: $key = ModulePeer::getPrimaryKeyHashFromRow($row, 0);
470: if (null !== ($obj = ModulePeer::getInstanceFromPool($key))) {
471: // We no longer rehydrate the object, since this can cause data loss.
472: // See http://www.propelorm.org/ticket/509
473: // $obj->hydrate($row, 0, true); // rehydrate
474: $results[] = $obj;
475: } else {
476: $obj = new $cls();
477: $obj->hydrate($row);
478: $results[] = $obj;
479: ModulePeer::addInstanceToPool($obj, $key);
480: } // if key exists
481: }
482: $stmt->closeCursor();
483:
484: return $results;
485: }
486: /**
487: * Populates an object of the default type or an object that inherit from the default.
488: *
489: * @param array $row PropelPDO resultset row.
490: * @param int $startcol The 0-based offset for reading from the resultset row.
491: * @throws PropelException Any exceptions caught during processing will be
492: * rethrown wrapped into a PropelException.
493: * @return array (Module object, last column rank)
494: */
495: public static function populateObject($row, $startcol = 0)
496: {
497: $key = ModulePeer::getPrimaryKeyHashFromRow($row, $startcol);
498: if (null !== ($obj = ModulePeer::getInstanceFromPool($key))) {
499: // We no longer rehydrate the object, since this can cause data loss.
500: // See http://www.propelorm.org/ticket/509
501: // $obj->hydrate($row, $startcol, true); // rehydrate
502: $col = $startcol + ModulePeer::NUM_HYDRATE_COLUMNS;
503: } else {
504: $cls = ModulePeer::OM_CLASS;
505: $obj = new $cls();
506: $col = $obj->hydrate($row, $startcol);
507: ModulePeer::addInstanceToPool($obj, $key);
508: }
509:
510: return array($obj, $col);
511: }
512:
513: /**
514: * Returns the TableMap related to this peer.
515: * This method is not needed for general use but a specific application could have a need.
516: * @return TableMap
517: * @throws PropelException Any exceptions caught during processing will be
518: * rethrown wrapped into a PropelException.
519: */
520: public static function getTableMap()
521: {
522: return Propel::getDatabaseMap(ModulePeer::DATABASE_NAME)->getTable(ModulePeer::TABLE_NAME);
523: }
524:
525: /**
526: * Add a TableMap instance to the database for this peer class.
527: */
528: public static function buildTableMap()
529: {
530: $dbMap = Propel::getDatabaseMap(BaseModulePeer::DATABASE_NAME);
531: if (!$dbMap->hasTable(BaseModulePeer::TABLE_NAME)) {
532: $dbMap->addTableObject(new ModuleTableMap());
533: }
534: }
535:
536: /**
537: * The class that the Peer will make instances of.
538: *
539: *
540: * @return string ClassName
541: */
542: public static function getOMClass($row = 0, $colnum = 0)
543: {
544: return ModulePeer::OM_CLASS;
545: }
546:
547: /**
548: * Performs an INSERT on the database, given a Module or Criteria object.
549: *
550: * @param mixed $values Criteria or Module object containing data that is used to create the INSERT statement.
551: * @param PropelPDO $con the PropelPDO connection to use
552: * @return mixed The new primary key.
553: * @throws PropelException Any exceptions caught during processing will be
554: * rethrown wrapped into a PropelException.
555: */
556: public static function doInsert($values, PropelPDO $con = null)
557: {
558: if ($con === null) {
559: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
560: }
561:
562: if ($values instanceof Criteria) {
563: $criteria = clone $values; // rename for clarity
564: } else {
565: $criteria = $values->buildCriteria(); // build Criteria from Module object
566: }
567:
568: if ($criteria->containsKey(ModulePeer::ID) && $criteria->keyContainsValue(ModulePeer::ID) ) {
569: throw new PropelException('Cannot insert a value for auto-increment primary key ('.ModulePeer::ID.')');
570: }
571:
572:
573: // Set the correct dbName
574: $criteria->setDbName(ModulePeer::DATABASE_NAME);
575:
576: try {
577: // use transaction because $criteria could contain info
578: // for more than one table (I guess, conceivably)
579: $con->beginTransaction();
580: $pk = BasePeer::doInsert($criteria, $con);
581: $con->commit();
582: } catch (PropelException $e) {
583: $con->rollBack();
584: throw $e;
585: }
586:
587: return $pk;
588: }
589:
590: /**
591: * Performs an UPDATE on the database, given a Module or Criteria object.
592: *
593: * @param mixed $values Criteria or Module object containing data that is used to create the UPDATE statement.
594: * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
595: * @return int The number of affected rows (if supported by underlying database driver).
596: * @throws PropelException Any exceptions caught during processing will be
597: * rethrown wrapped into a PropelException.
598: */
599: public static function doUpdate($values, PropelPDO $con = null)
600: {
601: if ($con === null) {
602: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
603: }
604:
605: $selectCriteria = new Criteria(ModulePeer::DATABASE_NAME);
606:
607: if ($values instanceof Criteria) {
608: $criteria = clone $values; // rename for clarity
609:
610: $comparison = $criteria->getComparison(ModulePeer::ID);
611: $value = $criteria->remove(ModulePeer::ID);
612: if ($value) {
613: $selectCriteria->add(ModulePeer::ID, $value, $comparison);
614: } else {
615: $selectCriteria->setPrimaryTableName(ModulePeer::TABLE_NAME);
616: }
617:
618: } else { // $values is Module object
619: $criteria = $values->buildCriteria(); // gets full criteria
620: $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
621: }
622:
623: // set the correct dbName
624: $criteria->setDbName(ModulePeer::DATABASE_NAME);
625:
626: return BasePeer::doUpdate($selectCriteria, $criteria, $con);
627: }
628:
629: /**
630: * Deletes all rows from the module table.
631: *
632: * @param PropelPDO $con the connection to use
633: * @return int The number of affected rows (if supported by underlying database driver).
634: * @throws PropelException
635: */
636: public static function doDeleteAll(PropelPDO $con = null)
637: {
638: if ($con === null) {
639: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
640: }
641: $affectedRows = 0; // initialize var to track total num of affected rows
642: try {
643: // use transaction because $criteria could contain info
644: // for more than one table or we could emulating ON DELETE CASCADE, etc.
645: $con->beginTransaction();
646: $affectedRows += BasePeer::doDeleteAll(ModulePeer::TABLE_NAME, $con, ModulePeer::DATABASE_NAME);
647: // Because this db requires some delete cascade/set null emulation, we have to
648: // clear the cached instance *after* the emulation has happened (since
649: // instances get re-added by the select statement contained therein).
650: ModulePeer::clearInstancePool();
651: ModulePeer::clearRelatedInstancePool();
652: $con->commit();
653:
654: return $affectedRows;
655: } catch (PropelException $e) {
656: $con->rollBack();
657: throw $e;
658: }
659: }
660:
661: /**
662: * Performs a DELETE on the database, given a Module or Criteria object OR a primary key value.
663: *
664: * @param mixed $values Criteria or Module object or primary key or array of primary keys
665: * which is used to create the DELETE statement
666: * @param PropelPDO $con the connection to use
667: * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
668: * if supported by native driver or if emulated using Propel.
669: * @throws PropelException Any exceptions caught during processing will be
670: * rethrown wrapped into a PropelException.
671: */
672: public static function doDelete($values, PropelPDO $con = null)
673: {
674: if ($con === null) {
675: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
676: }
677:
678: if ($values instanceof Criteria) {
679: // invalidate the cache for all objects of this type, since we have no
680: // way of knowing (without running a query) what objects should be invalidated
681: // from the cache based on this Criteria.
682: ModulePeer::clearInstancePool();
683: // rename for clarity
684: $criteria = clone $values;
685: } elseif ($values instanceof Module) { // it's a model object
686: // invalidate the cache for this single object
687: ModulePeer::removeInstanceFromPool($values);
688: // create criteria based on pk values
689: $criteria = $values->buildPkeyCriteria();
690: } else { // it's a primary key, or an array of pks
691: $criteria = new Criteria(ModulePeer::DATABASE_NAME);
692: $criteria->add(ModulePeer::ID, (array) $values, Criteria::IN);
693: // invalidate the cache for this object(s)
694: foreach ((array) $values as $singleval) {
695: ModulePeer::removeInstanceFromPool($singleval);
696: }
697: }
698:
699: // Set the correct dbName
700: $criteria->setDbName(ModulePeer::DATABASE_NAME);
701:
702: $affectedRows = 0; // initialize var to track total num of affected rows
703:
704: try {
705: // use transaction because $criteria could contain info
706: // for more than one table or we could emulating ON DELETE CASCADE, etc.
707: $con->beginTransaction();
708:
709: $affectedRows += BasePeer::doDelete($criteria, $con);
710: ModulePeer::clearRelatedInstancePool();
711: $con->commit();
712:
713: return $affectedRows;
714: } catch (PropelException $e) {
715: $con->rollBack();
716: throw $e;
717: }
718: }
719:
720: /**
721: * Validates all modified columns of given Module object.
722: * If parameter $columns is either a single column name or an array of column names
723: * than only those columns are validated.
724: *
725: * NOTICE: This does not apply to primary or foreign keys for now.
726: *
727: * @param Module $obj The object to validate.
728: * @param mixed $cols Column name or array of column names.
729: *
730: * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
731: */
732: public static function doValidate($obj, $cols = null)
733: {
734: $columns = array();
735:
736: if ($cols) {
737: $dbMap = Propel::getDatabaseMap(ModulePeer::DATABASE_NAME);
738: $tableMap = $dbMap->getTable(ModulePeer::TABLE_NAME);
739:
740: if (! is_array($cols)) {
741: $cols = array($cols);
742: }
743:
744: foreach ($cols as $colName) {
745: if ($tableMap->hasColumn($colName)) {
746: $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
747: $columns[$colName] = $obj->$get();
748: }
749: }
750: } else {
751:
752: }
753:
754: return BasePeer::doValidate(ModulePeer::DATABASE_NAME, ModulePeer::TABLE_NAME, $columns);
755: }
756:
757: /**
758: * Retrieve a single object by pkey.
759: *
760: * @param int $pk the primary key.
761: * @param PropelPDO $con the connection to use
762: * @return Module
763: */
764: public static function retrieveByPK($pk, PropelPDO $con = null)
765: {
766:
767: if (null !== ($obj = ModulePeer::getInstanceFromPool((string) $pk))) {
768: return $obj;
769: }
770:
771: if ($con === null) {
772: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
773: }
774:
775: $criteria = new Criteria(ModulePeer::DATABASE_NAME);
776: $criteria->add(ModulePeer::ID, $pk);
777:
778: $v = ModulePeer::doSelect($criteria, $con);
779:
780: return !empty($v) > 0 ? $v[0] : null;
781: }
782:
783: /**
784: * Retrieve multiple objects by pkey.
785: *
786: * @param array $pks List of primary keys
787: * @param PropelPDO $con the connection to use
788: * @return Module[]
789: * @throws PropelException Any exceptions caught during processing will be
790: * rethrown wrapped into a PropelException.
791: */
792: public static function retrieveByPKs($pks, PropelPDO $con = null)
793: {
794: if ($con === null) {
795: $con = Propel::getConnection(ModulePeer::DATABASE_NAME, Propel::CONNECTION_READ);
796: }
797:
798: $objs = null;
799: if (empty($pks)) {
800: $objs = array();
801: } else {
802: $criteria = new Criteria(ModulePeer::DATABASE_NAME);
803: $criteria->add(ModulePeer::ID, $pks, Criteria::IN);
804: $objs = ModulePeer::doSelect($criteria, $con);
805: }
806:
807: return $objs;
808: }
809:
810: } // BaseModulePeer
811:
812: // This is the static code needed to register the TableMap for this table with the main Propel class.
813: //
814: BaseModulePeer::buildTableMap();
815:
816: