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