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