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