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