# File core/lib/Thelia/Model/om/BaseProductPeer.php | thelia

       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\AccessoryPeer;
      13: use Thelia\Model\ContentAssocPeer;
      14: use Thelia\Model\DocumentPeer;
      15: use Thelia\Model\FeatureProdPeer;
      16: use Thelia\Model\ImagePeer;
      17: use Thelia\Model\Product;
      18: use Thelia\Model\ProductCategoryPeer;
      19: use Thelia\Model\ProductI18nPeer;
      20: use Thelia\Model\ProductPeer;
      21: use Thelia\Model\ProductVersionPeer;
      22: use Thelia\Model\RewritingPeer;
      23: use Thelia\Model\StockPeer;
      24: use Thelia\Model\TaxRulePeer;
      25: use Thelia\Model\map\ProductTableMap;
      26:
      27: /**
      28:  * Base static class for performing query and update operations on the 'product' table.
      29:  *
      30:  *
      31:  *
      32:  * @package propel.generator.Thelia.Model.om
      33:  */
      34: abstract class BaseProductPeer
      35: {
      36:
      37:     /** the default database name for this class */
      38:     const DATABASE_NAME = 'thelia';
      39:
      40:     /** the table name for this class */
      41:     const TABLE_NAME = 'product';
      42:
      43:     /** the related Propel class for this table */
      44:     const OM_CLASS = 'Thelia\\Model\\Product';
      45:
      46:     /** the related TableMap class for this table */
      47:     const TM_CLASS = 'ProductTableMap';
      48:
      49:     /** The total number of columns. */
      50:     const NUM_COLUMNS = 17;
      51:
      52:     /** The number of lazy-loaded columns. */
      53:     const NUM_LAZY_LOAD_COLUMNS = 0;
      54:
      55:     /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
      56:     const NUM_HYDRATE_COLUMNS = 17;
      57:
      58:     /** the column name for the ID field */
      59:     const ID = 'product.ID';
      60:
      61:     /** the column name for the TAX_RULE_ID field */
      62:     const TAX_RULE_ID = 'product.TAX_RULE_ID';
      63:
      64:     /** the column name for the REF field */
      65:     const REF = 'product.REF';
      66:
      67:     /** the column name for the PRICE field */
      68:     const PRICE = 'product.PRICE';
      69:
      70:     /** the column name for the PRICE2 field */
      71:     const PRICE2 = 'product.PRICE2';
      72:
      73:     /** the column name for the ECOTAX field */
      74:     const ECOTAX = 'product.ECOTAX';
      75:
      76:     /** the column name for the NEWNESS field */
      77:     const NEWNESS = 'product.NEWNESS';
      78:
      79:     /** the column name for the PROMO field */
      80:     const PROMO = 'product.PROMO';
      81:
      82:     /** the column name for the STOCK field */
      83:     const STOCK = 'product.STOCK';
      84:
      85:     /** the column name for the VISIBLE field */
      86:     const VISIBLE = 'product.VISIBLE';
      87:
      88:     /** the column name for the WEIGHT field */
      89:     const WEIGHT = 'product.WEIGHT';
      90:
      91:     /** the column name for the POSITION field */
      92:     const POSITION = 'product.POSITION';
      93:
      94:     /** the column name for the CREATED_AT field */
      95:     const CREATED_AT = 'product.CREATED_AT';
      96:
      97:     /** the column name for the UPDATED_AT field */
      98:     const UPDATED_AT = 'product.UPDATED_AT';
      99:
     100:     /** the column name for the VERSION field */
     101:     const VERSION = 'product.VERSION';
     102:
     103:     /** the column name for the VERSION_CREATED_AT field */
     104:     const VERSION_CREATED_AT = 'product.VERSION_CREATED_AT';
     105:
     106:     /** the column name for the VERSION_CREATED_BY field */
     107:     const VERSION_CREATED_BY = 'product.VERSION_CREATED_BY';
     108:
     109:     /** The default string format for model objects of the related table **/
     110:     const DEFAULT_STRING_FORMAT = 'YAML';
     111:
     112:     /**
     113:      * An identiy map to hold any loaded instances of Product objects.
     114:      * This must be public so that other peer classes can access this when hydrating from JOIN
     115:      * queries.
     116:      * @var        array Product[]
     117:      */
     118:     public static $instances = array();
     119:
     120:
     121:     // i18n behavior
     122:
     123:     /**
     124:      * The default locale to use for translations
     125:      * @var        string
     126:      */
     127:     const DEFAULT_LOCALE = 'en_EN';
     128:     // versionable behavior
     129:
     130:     /**
     131:      * Whether the versioning is enabled
     132:      */
     133:     static $isVersioningEnabled = true;
     134:
     135:     /**
     136:      * holds an array of fieldnames
     137:      *
     138:      * first dimension keys are the type constants
     139:      * e.g. ProductPeer::$fieldNames[ProductPeer::TYPE_PHPNAME][0] = 'Id'
     140:      */
     141:     protected static $fieldNames = array (
     142:         BasePeer::TYPE_PHPNAME => array ('Id', 'TaxRuleId', 'Ref', 'Price', 'Price2', 'Ecotax', 'Newness', 'Promo', 'Stock', 'Visible', 'Weight', 'Position', 'CreatedAt', 'UpdatedAt', 'Version', 'VersionCreatedAt', 'VersionCreatedBy', ),
     143:         BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'taxRuleId', 'ref', 'price', 'price2', 'ecotax', 'newness', 'promo', 'stock', 'visible', 'weight', 'position', 'createdAt', 'updatedAt', 'version', 'versionCreatedAt', 'versionCreatedBy', ),
     144:         BasePeer::TYPE_COLNAME => array (ProductPeer::ID, ProductPeer::TAX_RULE_ID, ProductPeer::REF, ProductPeer::PRICE, ProductPeer::PRICE2, ProductPeer::ECOTAX, ProductPeer::NEWNESS, ProductPeer::PROMO, ProductPeer::STOCK, ProductPeer::VISIBLE, ProductPeer::WEIGHT, ProductPeer::POSITION, ProductPeer::CREATED_AT, ProductPeer::UPDATED_AT, ProductPeer::VERSION, ProductPeer::VERSION_CREATED_AT, ProductPeer::VERSION_CREATED_BY, ),
     145:         BasePeer::TYPE_RAW_COLNAME => array ('ID', 'TAX_RULE_ID', 'REF', 'PRICE', 'PRICE2', 'ECOTAX', 'NEWNESS', 'PROMO', 'STOCK', 'VISIBLE', 'WEIGHT', 'POSITION', 'CREATED_AT', 'UPDATED_AT', 'VERSION', 'VERSION_CREATED_AT', 'VERSION_CREATED_BY', ),
     146:         BasePeer::TYPE_FIELDNAME => array ('id', 'tax_rule_id', 'ref', 'price', 'price2', 'ecotax', 'newness', 'promo', 'stock', 'visible', 'weight', 'position', 'created_at', 'updated_at', 'version', 'version_created_at', 'version_created_by', ),
     147:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, )
     148:     );
     149:
     150:     /**
     151:      * holds an array of keys for quick access to the fieldnames array
     152:      *
     153:      * first dimension keys are the type constants
     154:      * e.g. ProductPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
     155:      */
     156:     protected static $fieldKeys = array (
     157:         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'TaxRuleId' => 1, 'Ref' => 2, 'Price' => 3, 'Price2' => 4, 'Ecotax' => 5, 'Newness' => 6, 'Promo' => 7, 'Stock' => 8, 'Visible' => 9, 'Weight' => 10, 'Position' => 11, 'CreatedAt' => 12, 'UpdatedAt' => 13, 'Version' => 14, 'VersionCreatedAt' => 15, 'VersionCreatedBy' => 16, ),
     158:         BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'taxRuleId' => 1, 'ref' => 2, 'price' => 3, 'price2' => 4, 'ecotax' => 5, 'newness' => 6, 'promo' => 7, 'stock' => 8, 'visible' => 9, 'weight' => 10, 'position' => 11, 'createdAt' => 12, 'updatedAt' => 13, 'version' => 14, 'versionCreatedAt' => 15, 'versionCreatedBy' => 16, ),
     159:         BasePeer::TYPE_COLNAME => array (ProductPeer::ID => 0, ProductPeer::TAX_RULE_ID => 1, ProductPeer::REF => 2, ProductPeer::PRICE => 3, ProductPeer::PRICE2 => 4, ProductPeer::ECOTAX => 5, ProductPeer::NEWNESS => 6, ProductPeer::PROMO => 7, ProductPeer::STOCK => 8, ProductPeer::VISIBLE => 9, ProductPeer::WEIGHT => 10, ProductPeer::POSITION => 11, ProductPeer::CREATED_AT => 12, ProductPeer::UPDATED_AT => 13, ProductPeer::VERSION => 14, ProductPeer::VERSION_CREATED_AT => 15, ProductPeer::VERSION_CREATED_BY => 16, ),
     160:         BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'TAX_RULE_ID' => 1, 'REF' => 2, 'PRICE' => 3, 'PRICE2' => 4, 'ECOTAX' => 5, 'NEWNESS' => 6, 'PROMO' => 7, 'STOCK' => 8, 'VISIBLE' => 9, 'WEIGHT' => 10, 'POSITION' => 11, 'CREATED_AT' => 12, 'UPDATED_AT' => 13, 'VERSION' => 14, 'VERSION_CREATED_AT' => 15, 'VERSION_CREATED_BY' => 16, ),
     161:         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'tax_rule_id' => 1, 'ref' => 2, 'price' => 3, 'price2' => 4, 'ecotax' => 5, 'newness' => 6, 'promo' => 7, 'stock' => 8, 'visible' => 9, 'weight' => 10, 'position' => 11, 'created_at' => 12, 'updated_at' => 13, 'version' => 14, 'version_created_at' => 15, 'version_created_by' => 16, ),
     162:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, )
     163:     );
     164:
     165:     /**
     166:      * Translates a fieldname to another type
     167:      *
     168:      * @param      string $name field name
     169:      * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     170:      *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     171:      * @param      string $toType   One of the class type constants
     172:      * @return string          translated name of the field.
     173:      * @throws PropelException - if the specified name could not be found in the fieldname mappings.
     174:      */
     175:     public static function translateFieldName($name, $fromType, $toType)
     176:     {
     177:         $toNames = ProductPeer::getFieldNames($toType);
     178:         $key = isset(ProductPeer::$fieldKeys[$fromType][$name]) ? ProductPeer::$fieldKeys[$fromType][$name] : null;
     179:         if ($key === null) {
     180:             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(ProductPeer::$fieldKeys[$fromType], true));
     181:         }
     182:
     183:         return $toNames[$key];
     184:     }
     185:
     186:     /**
     187:      * Returns an array of field names.
     188:      *
     189:      * @param      string $type The type of fieldnames to return:
     190:      *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     191:      *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     192:      * @return array           A list of field names
     193:      * @throws PropelException - if the type is not valid.
     194:      */
     195:     public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
     196:     {
     197:         if (!array_key_exists($type, ProductPeer::$fieldNames)) {
     198:             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.');
     199:         }
     200:
     201:         return ProductPeer::$fieldNames[$type];
     202:     }
     203:
     204:     /**
     205:      * Convenience method which changes table.column to alias.column.
     206:      *
     207:      * Using this method you can maintain SQL abstraction while using column aliases.
     208:      * <code>
     209:      *      $c->addAlias("alias1", TablePeer::TABLE_NAME);
     210:      *      $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
     211:      * </code>
     212:      * @param      string $alias The alias for the current table.
     213:      * @param      string $column The column name for current table. (i.e. ProductPeer::COLUMN_NAME).
     214:      * @return string
     215:      */
     216:     public static function alias($alias, $column)
     217:     {
     218:         return str_replace(ProductPeer::TABLE_NAME.'.', $alias.'.', $column);
     219:     }
     220:
     221:     /**
     222:      * Add all the columns needed to create a new object.
     223:      *
     224:      * Note: any columns that were marked with lazyLoad="true" in the
     225:      * XML schema will not be added to the select list and only loaded
     226:      * on demand.
     227:      *
     228:      * @param      Criteria $criteria object containing the columns to add.
     229:      * @param      string   $alias    optional table alias
     230:      * @throws PropelException Any exceptions caught during processing will be
     231:      *       rethrown wrapped into a PropelException.
     232:      */
     233:     public static function addSelectColumns(Criteria $criteria, $alias = null)
     234:     {
     235:         if (null === $alias) {
     236:             $criteria->addSelectColumn(ProductPeer::ID);
     237:             $criteria->addSelectColumn(ProductPeer::TAX_RULE_ID);
     238:             $criteria->addSelectColumn(ProductPeer::REF);
     239:             $criteria->addSelectColumn(ProductPeer::PRICE);
     240:             $criteria->addSelectColumn(ProductPeer::PRICE2);
     241:             $criteria->addSelectColumn(ProductPeer::ECOTAX);
     242:             $criteria->addSelectColumn(ProductPeer::NEWNESS);
     243:             $criteria->addSelectColumn(ProductPeer::PROMO);
     244:             $criteria->addSelectColumn(ProductPeer::STOCK);
     245:             $criteria->addSelectColumn(ProductPeer::VISIBLE);
     246:             $criteria->addSelectColumn(ProductPeer::WEIGHT);
     247:             $criteria->addSelectColumn(ProductPeer::POSITION);
     248:             $criteria->addSelectColumn(ProductPeer::CREATED_AT);
     249:             $criteria->addSelectColumn(ProductPeer::UPDATED_AT);
     250:             $criteria->addSelectColumn(ProductPeer::VERSION);
     251:             $criteria->addSelectColumn(ProductPeer::VERSION_CREATED_AT);
     252:             $criteria->addSelectColumn(ProductPeer::VERSION_CREATED_BY);
     253:         } else {
     254:             $criteria->addSelectColumn($alias . '.ID');
     255:             $criteria->addSelectColumn($alias . '.TAX_RULE_ID');
     256:             $criteria->addSelectColumn($alias . '.REF');
     257:             $criteria->addSelectColumn($alias . '.PRICE');
     258:             $criteria->addSelectColumn($alias . '.PRICE2');
     259:             $criteria->addSelectColumn($alias . '.ECOTAX');
     260:             $criteria->addSelectColumn($alias . '.NEWNESS');
     261:             $criteria->addSelectColumn($alias . '.PROMO');
     262:             $criteria->addSelectColumn($alias . '.STOCK');
     263:             $criteria->addSelectColumn($alias . '.VISIBLE');
     264:             $criteria->addSelectColumn($alias . '.WEIGHT');
     265:             $criteria->addSelectColumn($alias . '.POSITION');
     266:             $criteria->addSelectColumn($alias . '.CREATED_AT');
     267:             $criteria->addSelectColumn($alias . '.UPDATED_AT');
     268:             $criteria->addSelectColumn($alias . '.VERSION');
     269:             $criteria->addSelectColumn($alias . '.VERSION_CREATED_AT');
     270:             $criteria->addSelectColumn($alias . '.VERSION_CREATED_BY');
     271:         }
     272:     }
     273:
     274:     /**
     275:      * Returns the number of rows matching criteria.
     276:      *
     277:      * @param      Criteria $criteria
     278:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     279:      * @param      PropelPDO $con
     280:      * @return int Number of matching rows.
     281:      */
     282:     public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
     283:     {
     284:         // we may modify criteria, so copy it first
     285:         $criteria = clone $criteria;
     286:
     287:         // We need to set the primary table name, since in the case that there are no WHERE columns
     288:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     289:         // tables go into the FROM clause.
     290:         $criteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     291:
     292:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     293:             $criteria->setDistinct();
     294:         }
     295:
     296:         if (!$criteria->hasSelectClause()) {
     297:             ProductPeer::addSelectColumns($criteria);
     298:         }
     299:
     300:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     301:         $criteria->setDbName(ProductPeer::DATABASE_NAME); // Set the correct dbName
     302:
     303:         if ($con === null) {
     304:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     305:         }
     306:         // BasePeer returns a PDOStatement
     307:         $stmt = BasePeer::doCount($criteria, $con);
     308:
     309:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     310:             $count = (int) $row[0];
     311:         } else {
     312:             $count = 0; // no rows returned; we infer that means 0 matches.
     313:         }
     314:         $stmt->closeCursor();
     315:
     316:         return $count;
     317:     }
     318:     /**
     319:      * Selects one object from the DB.
     320:      *
     321:      * @param      Criteria $criteria object used to create the SELECT statement.
     322:      * @param      PropelPDO $con
     323:      * @return                 Product
     324:      * @throws PropelException Any exceptions caught during processing will be
     325:      *       rethrown wrapped into a PropelException.
     326:      */
     327:     public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
     328:     {
     329:         $critcopy = clone $criteria;
     330:         $critcopy->setLimit(1);
     331:         $objects = ProductPeer::doSelect($critcopy, $con);
     332:         if ($objects) {
     333:             return $objects[0];
     334:         }
     335:
     336:         return null;
     337:     }
     338:     /**
     339:      * Selects several row from the DB.
     340:      *
     341:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     342:      * @param      PropelPDO $con
     343:      * @return array           Array of selected Objects
     344:      * @throws PropelException Any exceptions caught during processing will be
     345:      *       rethrown wrapped into a PropelException.
     346:      */
     347:     public static function doSelect(Criteria $criteria, PropelPDO $con = null)
     348:     {
     349:         return ProductPeer::populateObjects(ProductPeer::doSelectStmt($criteria, $con));
     350:     }
     351:     /**
     352:      * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
     353:      *
     354:      * Use this method directly if you want to work with an executed statement durirectly (for example
     355:      * to perform your own object hydration).
     356:      *
     357:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     358:      * @param      PropelPDO $con The connection to use
     359:      * @throws PropelException Any exceptions caught during processing will be
     360:      *       rethrown wrapped into a PropelException.
     361:      * @return PDOStatement The executed PDOStatement object.
     362:      * @see        BasePeer::doSelect()
     363:      */
     364:     public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
     365:     {
     366:         if ($con === null) {
     367:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     368:         }
     369:
     370:         if (!$criteria->hasSelectClause()) {
     371:             $criteria = clone $criteria;
     372:             ProductPeer::addSelectColumns($criteria);
     373:         }
     374:
     375:         // Set the correct dbName
     376:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     377:
     378:         // BasePeer returns a PDOStatement
     379:         return BasePeer::doSelect($criteria, $con);
     380:     }
     381:     /**
     382:      * Adds an object to the instance pool.
     383:      *
     384:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     385:      * from the database.  In some cases -- especially when you override doSelect*()
     386:      * methods in your stub classes -- you may need to explicitly add objects
     387:      * to the cache in order to ensure that the same objects are always returned by doSelect*()
     388:      * and retrieveByPK*() calls.
     389:      *
     390:      * @param      Product $obj A Product object.
     391:      * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
     392:      */
     393:     public static function addInstanceToPool($obj, $key = null)
     394:     {
     395:         if (Propel::isInstancePoolingEnabled()) {
     396:             if ($key === null) {
     397:                 $key = (string) $obj->getId();
     398:             } // if key === null
     399:             ProductPeer::$instances[$key] = $obj;
     400:         }
     401:     }
     402:
     403:     /**
     404:      * Removes an object from the instance pool.
     405:      *
     406:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     407:      * from the database.  In some cases -- especially when you override doDelete
     408:      * methods in your stub classes -- you may need to explicitly remove objects
     409:      * from the cache in order to prevent returning objects that no longer exist.
     410:      *
     411:      * @param      mixed $value A Product object or a primary key value.
     412:      *
     413:      * @return void
     414:      * @throws PropelException - if the value is invalid.
     415:      */
     416:     public static function removeInstanceFromPool($value)
     417:     {
     418:         if (Propel::isInstancePoolingEnabled() && $value !== null) {
     419:             if (is_object($value) && $value instanceof Product) {
     420:                 $key = (string) $value->getId();
     421:             } elseif (is_scalar($value)) {
     422:                 // assume we've been passed a primary key
     423:                 $key = (string) $value;
     424:             } else {
     425:                 $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Product object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
     426:                 throw $e;
     427:             }
     428:
     429:             unset(ProductPeer::$instances[$key]);
     430:         }
     431:     } // removeInstanceFromPool()
     432:
     433:     /**
     434:      * 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.
     435:      *
     436:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     437:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     438:      *
     439:      * @param      string $key The key (@see getPrimaryKeyHash()) for this instance.
     440:      * @return   Product Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
     441:      * @see        getPrimaryKeyHash()
     442:      */
     443:     public static function getInstanceFromPool($key)
     444:     {
     445:         if (Propel::isInstancePoolingEnabled()) {
     446:             if (isset(ProductPeer::$instances[$key])) {
     447:                 return ProductPeer::$instances[$key];
     448:             }
     449:         }
     450:
     451:         return null; // just to be explicit
     452:     }
     453:
     454:     /**
     455:      * Clear the instance pool.
     456:      *
     457:      * @return void
     458:      */
     459:     public static function clearInstancePool()
     460:     {
     461:         ProductPeer::$instances = array();
     462:     }
     463:
     464:     /**
     465:      * Method to invalidate the instance pool of all tables related to product
     466:      * by a foreign key with ON DELETE CASCADE
     467:      */
     468:     public static function clearRelatedInstancePool()
     469:     {
     470:         // Invalidate objects in ProductCategoryPeer instance pool,
     471:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     472:         ProductCategoryPeer::clearInstancePool();
     473:         // Invalidate objects in FeatureProdPeer instance pool,
     474:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     475:         FeatureProdPeer::clearInstancePool();
     476:         // Invalidate objects in StockPeer instance pool,
     477:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     478:         StockPeer::clearInstancePool();
     479:         // Invalidate objects in ContentAssocPeer instance pool,
     480:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     481:         ContentAssocPeer::clearInstancePool();
     482:         // Invalidate objects in ImagePeer instance pool,
     483:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     484:         ImagePeer::clearInstancePool();
     485:         // Invalidate objects in DocumentPeer instance pool,
     486:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     487:         DocumentPeer::clearInstancePool();
     488:         // Invalidate objects in AccessoryPeer instance pool,
     489:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     490:         AccessoryPeer::clearInstancePool();
     491:         // Invalidate objects in AccessoryPeer instance pool,
     492:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     493:         AccessoryPeer::clearInstancePool();
     494:         // Invalidate objects in RewritingPeer instance pool,
     495:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     496:         RewritingPeer::clearInstancePool();
     497:         // Invalidate objects in ProductI18nPeer instance pool,
     498:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     499:         ProductI18nPeer::clearInstancePool();
     500:         // Invalidate objects in ProductVersionPeer instance pool,
     501:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     502:         ProductVersionPeer::clearInstancePool();
     503:     }
     504:
     505:     /**
     506:      * 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.
     507:      *
     508:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     509:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     510:      *
     511:      * @param      array $row PropelPDO resultset row.
     512:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     513:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     514:      */
     515:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     516:     {
     517:         // If the PK cannot be derived from the row, return null.
     518:         if ($row[$startcol] === null) {
     519:             return null;
     520:         }
     521:
     522:         return (string) $row[$startcol];
     523:     }
     524:
     525:     /**
     526:      * Retrieves the primary key from the DB resultset row
     527:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     528:      * a multi-column primary key, an array of the primary key columns will be returned.
     529:      *
     530:      * @param      array $row PropelPDO resultset row.
     531:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     532:      * @return mixed The primary key of the row
     533:      */
     534:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     535:     {
     536:
     537:         return (int) $row[$startcol];
     538:     }
     539:
     540:     /**
     541:      * The returned array will contain objects of the default type or
     542:      * objects that inherit from the default.
     543:      *
     544:      * @throws PropelException Any exceptions caught during processing will be
     545:      *       rethrown wrapped into a PropelException.
     546:      */
     547:     public static function populateObjects(PDOStatement $stmt)
     548:     {
     549:         $results = array();
     550:
     551:         // set the class once to avoid overhead in the loop
     552:         $cls = ProductPeer::getOMClass();
     553:         // populate the object(s)
     554:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     555:             $key = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     556:             if (null !== ($obj = ProductPeer::getInstanceFromPool($key))) {
     557:                 // We no longer rehydrate the object, since this can cause data loss.
     558:                 // See http://www.propelorm.org/ticket/509
     559:                 // $obj->hydrate($row, 0, true); // rehydrate
     560:                 $results[] = $obj;
     561:             } else {
     562:                 $obj = new $cls();
     563:                 $obj->hydrate($row);
     564:                 $results[] = $obj;
     565:                 ProductPeer::addInstanceToPool($obj, $key);
     566:             } // if key exists
     567:         }
     568:         $stmt->closeCursor();
     569:
     570:         return $results;
     571:     }
     572:     /**
     573:      * Populates an object of the default type or an object that inherit from the default.
     574:      *
     575:      * @param      array $row PropelPDO resultset row.
     576:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     577:      * @throws PropelException Any exceptions caught during processing will be
     578:      *       rethrown wrapped into a PropelException.
     579:      * @return array (Product object, last column rank)
     580:      */
     581:     public static function populateObject($row, $startcol = 0)
     582:     {
     583:         $key = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol);
     584:         if (null !== ($obj = ProductPeer::getInstanceFromPool($key))) {
     585:             // We no longer rehydrate the object, since this can cause data loss.
     586:             // See http://www.propelorm.org/ticket/509
     587:             // $obj->hydrate($row, $startcol, true); // rehydrate
     588:             $col = $startcol + ProductPeer::NUM_HYDRATE_COLUMNS;
     589:         } else {
     590:             $cls = ProductPeer::OM_CLASS;
     591:             $obj = new $cls();
     592:             $col = $obj->hydrate($row, $startcol);
     593:             ProductPeer::addInstanceToPool($obj, $key);
     594:         }
     595:
     596:         return array($obj, $col);
     597:     }
     598:
     599:
     600:     /**
     601:      * Returns the number of rows matching criteria, joining the related TaxRule table
     602:      *
     603:      * @param      Criteria $criteria
     604:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     605:      * @param      PropelPDO $con
     606:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     607:      * @return int Number of matching rows.
     608:      */
     609:     public static function doCountJoinTaxRule(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     610:     {
     611:         // we're going to modify criteria, so copy it first
     612:         $criteria = clone $criteria;
     613:
     614:         // We need to set the primary table name, since in the case that there are no WHERE columns
     615:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     616:         // tables go into the FROM clause.
     617:         $criteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     618:
     619:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     620:             $criteria->setDistinct();
     621:         }
     622:
     623:         if (!$criteria->hasSelectClause()) {
     624:             ProductPeer::addSelectColumns($criteria);
     625:         }
     626:
     627:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     628:
     629:         // Set the correct dbName
     630:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     631:
     632:         if ($con === null) {
     633:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     634:         }
     635:
     636:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     637:
     638:         $stmt = BasePeer::doCount($criteria, $con);
     639:
     640:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     641:             $count = (int) $row[0];
     642:         } else {
     643:             $count = 0; // no rows returned; we infer that means 0 matches.
     644:         }
     645:         $stmt->closeCursor();
     646:
     647:         return $count;
     648:     }
     649:
     650:
     651:     /**
     652:      * Selects a collection of Product objects pre-filled with their TaxRule objects.
     653:      * @param      Criteria  $criteria
     654:      * @param      PropelPDO $con
     655:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     656:      * @return array           Array of Product objects.
     657:      * @throws PropelException Any exceptions caught during processing will be
     658:      *       rethrown wrapped into a PropelException.
     659:      */
     660:     public static function doSelectJoinTaxRule(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     661:     {
     662:         $criteria = clone $criteria;
     663:
     664:         // Set the correct dbName if it has not been overridden
     665:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     666:             $criteria->setDbName(ProductPeer::DATABASE_NAME);
     667:         }
     668:
     669:         ProductPeer::addSelectColumns($criteria);
     670:         $startcol = ProductPeer::NUM_HYDRATE_COLUMNS;
     671:         TaxRulePeer::addSelectColumns($criteria);
     672:
     673:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     674:
     675:         $stmt = BasePeer::doSelect($criteria, $con);
     676:         $results = array();
     677:
     678:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     679:             $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     680:             if (null !== ($obj1 = ProductPeer::getInstanceFromPool($key1))) {
     681:                 // We no longer rehydrate the object, since this can cause data loss.
     682:                 // See http://www.propelorm.org/ticket/509
     683:                 // $obj1->hydrate($row, 0, true); // rehydrate
     684:             } else {
     685:
     686:                 $cls = ProductPeer::getOMClass();
     687:
     688:                 $obj1 = new $cls();
     689:                 $obj1->hydrate($row);
     690:                 ProductPeer::addInstanceToPool($obj1, $key1);
     691:             } // if $obj1 already loaded
     692:
     693:             $key2 = TaxRulePeer::getPrimaryKeyHashFromRow($row, $startcol);
     694:             if ($key2 !== null) {
     695:                 $obj2 = TaxRulePeer::getInstanceFromPool($key2);
     696:                 if (!$obj2) {
     697:
     698:                     $cls = TaxRulePeer::getOMClass();
     699:
     700:                     $obj2 = new $cls();
     701:                     $obj2->hydrate($row, $startcol);
     702:                     TaxRulePeer::addInstanceToPool($obj2, $key2);
     703:                 } // if obj2 already loaded
     704:
     705:                 // Add the $obj1 (Product) to $obj2 (TaxRule)
     706:                 $obj2->addProduct($obj1);
     707:
     708:             } // if joined row was not null
     709:
     710:             $results[] = $obj1;
     711:         }
     712:         $stmt->closeCursor();
     713:
     714:         return $results;
     715:     }
     716:
     717:
     718:     /**
     719:      * Returns the number of rows matching criteria, joining all related tables
     720:      *
     721:      * @param      Criteria $criteria
     722:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     723:      * @param      PropelPDO $con
     724:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     725:      * @return int Number of matching rows.
     726:      */
     727:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     728:     {
     729:         // we're going to modify criteria, so copy it first
     730:         $criteria = clone $criteria;
     731:
     732:         // We need to set the primary table name, since in the case that there are no WHERE columns
     733:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     734:         // tables go into the FROM clause.
     735:         $criteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     736:
     737:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     738:             $criteria->setDistinct();
     739:         }
     740:
     741:         if (!$criteria->hasSelectClause()) {
     742:             ProductPeer::addSelectColumns($criteria);
     743:         }
     744:
     745:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     746:
     747:         // Set the correct dbName
     748:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     749:
     750:         if ($con === null) {
     751:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     752:         }
     753:
     754:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     755:
     756:         $stmt = BasePeer::doCount($criteria, $con);
     757:
     758:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     759:             $count = (int) $row[0];
     760:         } else {
     761:             $count = 0; // no rows returned; we infer that means 0 matches.
     762:         }
     763:         $stmt->closeCursor();
     764:
     765:         return $count;
     766:     }
     767:
     768:     /**
     769:      * Selects a collection of Product objects pre-filled with all related objects.
     770:      *
     771:      * @param      Criteria  $criteria
     772:      * @param      PropelPDO $con
     773:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     774:      * @return array           Array of Product objects.
     775:      * @throws PropelException Any exceptions caught during processing will be
     776:      *       rethrown wrapped into a PropelException.
     777:      */
     778:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     779:     {
     780:         $criteria = clone $criteria;
     781:
     782:         // Set the correct dbName if it has not been overridden
     783:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     784:             $criteria->setDbName(ProductPeer::DATABASE_NAME);
     785:         }
     786:
     787:         ProductPeer::addSelectColumns($criteria);
     788:         $startcol2 = ProductPeer::NUM_HYDRATE_COLUMNS;
     789:
     790:         TaxRulePeer::addSelectColumns($criteria);
     791:         $startcol3 = $startcol2 + TaxRulePeer::NUM_HYDRATE_COLUMNS;
     792:
     793:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     794:
     795:         $stmt = BasePeer::doSelect($criteria, $con);
     796:         $results = array();
     797:
     798:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     799:             $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     800:             if (null !== ($obj1 = ProductPeer::getInstanceFromPool($key1))) {
     801:                 // We no longer rehydrate the object, since this can cause data loss.
     802:                 // See http://www.propelorm.org/ticket/509
     803:                 // $obj1->hydrate($row, 0, true); // rehydrate
     804:             } else {
     805:                 $cls = ProductPeer::getOMClass();
     806:
     807:                 $obj1 = new $cls();
     808:                 $obj1->hydrate($row);
     809:                 ProductPeer::addInstanceToPool($obj1, $key1);
     810:             } // if obj1 already loaded
     811:
     812:             // Add objects for joined TaxRule rows
     813:
     814:             $key2 = TaxRulePeer::getPrimaryKeyHashFromRow($row, $startcol2);
     815:             if ($key2 !== null) {
     816:                 $obj2 = TaxRulePeer::getInstanceFromPool($key2);
     817:                 if (!$obj2) {
     818:
     819:                     $cls = TaxRulePeer::getOMClass();
     820:
     821:                     $obj2 = new $cls();
     822:                     $obj2->hydrate($row, $startcol2);
     823:                     TaxRulePeer::addInstanceToPool($obj2, $key2);
     824:                 } // if obj2 loaded
     825:
     826:                 // Add the $obj1 (Product) to the collection in $obj2 (TaxRule)
     827:                 $obj2->addProduct($obj1);
     828:             } // if joined row not null
     829:
     830:             $results[] = $obj1;
     831:         }
     832:         $stmt->closeCursor();
     833:
     834:         return $results;
     835:     }
     836:
     837:     /**
     838:      * Returns the TableMap related to this peer.
     839:      * This method is not needed for general use but a specific application could have a need.
     840:      * @return TableMap
     841:      * @throws PropelException Any exceptions caught during processing will be
     842:      *       rethrown wrapped into a PropelException.
     843:      */
     844:     public static function getTableMap()
     845:     {
     846:         return Propel::getDatabaseMap(ProductPeer::DATABASE_NAME)->getTable(ProductPeer::TABLE_NAME);
     847:     }
     848:
     849:     /**
     850:      * Add a TableMap instance to the database for this peer class.
     851:      */
     852:     public static function buildTableMap()
     853:     {
     854:       $dbMap = Propel::getDatabaseMap(BaseProductPeer::DATABASE_NAME);
     855:       if (!$dbMap->hasTable(BaseProductPeer::TABLE_NAME)) {
     856:         $dbMap->addTableObject(new ProductTableMap());
     857:       }
     858:     }
     859:
     860:     /**
     861:      * The class that the Peer will make instances of.
     862:      *
     863:      *
     864:      * @return string ClassName
     865:      */
     866:     public static function getOMClass()
     867:     {
     868:         return ProductPeer::OM_CLASS;
     869:     }
     870:
     871:     /**
     872:      * Performs an INSERT on the database, given a Product or Criteria object.
     873:      *
     874:      * @param      mixed $values Criteria or Product object containing data that is used to create the INSERT statement.
     875:      * @param      PropelPDO $con the PropelPDO connection to use
     876:      * @return mixed           The new primary key.
     877:      * @throws PropelException Any exceptions caught during processing will be
     878:      *       rethrown wrapped into a PropelException.
     879:      */
     880:     public static function doInsert($values, PropelPDO $con = null)
     881:     {
     882:         if ($con === null) {
     883:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     884:         }
     885:
     886:         if ($values instanceof Criteria) {
     887:             $criteria = clone $values; // rename for clarity
     888:         } else {
     889:             $criteria = $values->buildCriteria(); // build Criteria from Product object
     890:         }
     891:
     892:         if ($criteria->containsKey(ProductPeer::ID) && $criteria->keyContainsValue(ProductPeer::ID) ) {
     893:             throw new PropelException('Cannot insert a value for auto-increment primary key ('.ProductPeer::ID.')');
     894:         }
     895:
     896:
     897:         // Set the correct dbName
     898:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     899:
     900:         try {
     901:             // use transaction because $criteria could contain info
     902:             // for more than one table (I guess, conceivably)
     903:             $con->beginTransaction();
     904:             $pk = BasePeer::doInsert($criteria, $con);
     905:             $con->commit();
     906:         } catch (PropelException $e) {
     907:             $con->rollBack();
     908:             throw $e;
     909:         }
     910:
     911:         return $pk;
     912:     }
     913:
     914:     /**
     915:      * Performs an UPDATE on the database, given a Product or Criteria object.
     916:      *
     917:      * @param      mixed $values Criteria or Product object containing data that is used to create the UPDATE statement.
     918:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
     919:      * @return int             The number of affected rows (if supported by underlying database driver).
     920:      * @throws PropelException Any exceptions caught during processing will be
     921:      *       rethrown wrapped into a PropelException.
     922:      */
     923:     public static function doUpdate($values, PropelPDO $con = null)
     924:     {
     925:         if ($con === null) {
     926:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     927:         }
     928:
     929:         $selectCriteria = new Criteria(ProductPeer::DATABASE_NAME);
     930:
     931:         if ($values instanceof Criteria) {
     932:             $criteria = clone $values; // rename for clarity
     933:
     934:             $comparison = $criteria->getComparison(ProductPeer::ID);
     935:             $value = $criteria->remove(ProductPeer::ID);
     936:             if ($value) {
     937:                 $selectCriteria->add(ProductPeer::ID, $value, $comparison);
     938:             } else {
     939:                 $selectCriteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     940:             }
     941:
     942:         } else { // $values is Product object
     943:             $criteria = $values->buildCriteria(); // gets full criteria
     944:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
     945:         }
     946:
     947:         // set the correct dbName
     948:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     949:
     950:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
     951:     }
     952:
     953:     /**
     954:      * Deletes all rows from the product table.
     955:      *
     956:      * @param      PropelPDO $con the connection to use
     957:      * @return int             The number of affected rows (if supported by underlying database driver).
     958:      * @throws PropelException
     959:      */
     960:     public static function doDeleteAll(PropelPDO $con = null)
     961:     {
     962:         if ($con === null) {
     963:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     964:         }
     965:         $affectedRows = 0; // initialize var to track total num of affected rows
     966:         try {
     967:             // use transaction because $criteria could contain info
     968:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     969:             $con->beginTransaction();
     970:             $affectedRows += BasePeer::doDeleteAll(ProductPeer::TABLE_NAME, $con, ProductPeer::DATABASE_NAME);
     971:             // Because this db requires some delete cascade/set null emulation, we have to
     972:             // clear the cached instance *after* the emulation has happened (since
     973:             // instances get re-added by the select statement contained therein).
     974:             ProductPeer::clearInstancePool();
     975:             ProductPeer::clearRelatedInstancePool();
     976:             $con->commit();
     977:
     978:             return $affectedRows;
     979:         } catch (PropelException $e) {
     980:             $con->rollBack();
     981:             throw $e;
     982:         }
     983:     }
     984:
     985:     /**
     986:      * Performs a DELETE on the database, given a Product or Criteria object OR a primary key value.
     987:      *
     988:      * @param      mixed $values Criteria or Product object or primary key or array of primary keys
     989:      *              which is used to create the DELETE statement
     990:      * @param      PropelPDO $con the connection to use
     991:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
     992:      *              if supported by native driver or if emulated using Propel.
     993:      * @throws PropelException Any exceptions caught during processing will be
     994:      *       rethrown wrapped into a PropelException.
     995:      */
     996:      public static function doDelete($values, PropelPDO $con = null)
     997:      {
     998:         if ($con === null) {
     999:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1000:         }
    1001:
    1002:         if ($values instanceof Criteria) {
    1003:             // invalidate the cache for all objects of this type, since we have no
    1004:             // way of knowing (without running a query) what objects should be invalidated
    1005:             // from the cache based on this Criteria.
    1006:             ProductPeer::clearInstancePool();
    1007:             // rename for clarity
    1008:             $criteria = clone $values;
    1009:         } elseif ($values instanceof Product) { // it's a model object
    1010:             // invalidate the cache for this single object
    1011:             ProductPeer::removeInstanceFromPool($values);
    1012:             // create criteria based on pk values
    1013:             $criteria = $values->buildPkeyCriteria();
    1014:         } else { // it's a primary key, or an array of pks
    1015:             $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1016:             $criteria->add(ProductPeer::ID, (array) $values, Criteria::IN);
    1017:             // invalidate the cache for this object(s)
    1018:             foreach ((array) $values as $singleval) {
    1019:                 ProductPeer::removeInstanceFromPool($singleval);
    1020:             }
    1021:         }
    1022:
    1023:         // Set the correct dbName
    1024:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
    1025:
    1026:         $affectedRows = 0; // initialize var to track total num of affected rows
    1027:
    1028:         try {
    1029:             // use transaction because $criteria could contain info
    1030:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1031:             $con->beginTransaction();
    1032:
    1033:             $affectedRows += BasePeer::doDelete($criteria, $con);
    1034:             ProductPeer::clearRelatedInstancePool();
    1035:             $con->commit();
    1036:
    1037:             return $affectedRows;
    1038:         } catch (PropelException $e) {
    1039:             $con->rollBack();
    1040:             throw $e;
    1041:         }
    1042:     }
    1043:
    1044:     /**
    1045:      * Validates all modified columns of given Product object.
    1046:      * If parameter $columns is either a single column name or an array of column names
    1047:      * than only those columns are validated.
    1048:      *
    1049:      * NOTICE: This does not apply to primary or foreign keys for now.
    1050:      *
    1051:      * @param      Product $obj The object to validate.
    1052:      * @param      mixed $cols Column name or array of column names.
    1053:      *
    1054:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
    1055:      */
    1056:     public static function doValidate($obj, $cols = null)
    1057:     {
    1058:         $columns = array();
    1059:
    1060:         if ($cols) {
    1061:             $dbMap = Propel::getDatabaseMap(ProductPeer::DATABASE_NAME);
    1062:             $tableMap = $dbMap->getTable(ProductPeer::TABLE_NAME);
    1063:
    1064:             if (! is_array($cols)) {
    1065:                 $cols = array($cols);
    1066:             }
    1067:
    1068:             foreach ($cols as $colName) {
    1069:                 if ($tableMap->hasColumn($colName)) {
    1070:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
    1071:                     $columns[$colName] = $obj->$get();
    1072:                 }
    1073:             }
    1074:         } else {
    1075:
    1076:         }
    1077:
    1078:         return BasePeer::doValidate(ProductPeer::DATABASE_NAME, ProductPeer::TABLE_NAME, $columns);
    1079:     }
    1080:
    1081:     /**
    1082:      * Retrieve a single object by pkey.
    1083:      *
    1084:      * @param      int $pk the primary key.
    1085:      * @param      PropelPDO $con the connection to use
    1086:      * @return Product
    1087:      */
    1088:     public static function retrieveByPK($pk, PropelPDO $con = null)
    1089:     {
    1090:
    1091:         if (null !== ($obj = ProductPeer::getInstanceFromPool((string) $pk))) {
    1092:             return $obj;
    1093:         }
    1094:
    1095:         if ($con === null) {
    1096:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1097:         }
    1098:
    1099:         $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1100:         $criteria->add(ProductPeer::ID, $pk);
    1101:
    1102:         $v = ProductPeer::doSelect($criteria, $con);
    1103:
    1104:         return !empty($v) > 0 ? $v[0] : null;
    1105:     }
    1106:
    1107:     /**
    1108:      * Retrieve multiple objects by pkey.
    1109:      *
    1110:      * @param      array $pks List of primary keys
    1111:      * @param      PropelPDO $con the connection to use
    1112:      * @return Product[]
    1113:      * @throws PropelException Any exceptions caught during processing will be
    1114:      *       rethrown wrapped into a PropelException.
    1115:      */
    1116:     public static function retrieveByPKs($pks, PropelPDO $con = null)
    1117:     {
    1118:         if ($con === null) {
    1119:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1120:         }
    1121:
    1122:         $objs = null;
    1123:         if (empty($pks)) {
    1124:             $objs = array();
    1125:         } else {
    1126:             $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1127:             $criteria->add(ProductPeer::ID, $pks, Criteria::IN);
    1128:             $objs = ProductPeer::doSelect($criteria, $con);
    1129:         }
    1130:
    1131:         return $objs;
    1132:     }
    1133:
    1134:     // versionable behavior
    1135:
    1136:     /**
    1137:      * Checks whether versioning is enabled
    1138:      *
    1139:      * @return boolean
    1140:      */
    1141:     public static function isVersioningEnabled()
    1142:     {
    1143:         return self::$isVersioningEnabled;
    1144:     }
    1145:
    1146:     /**
    1147:      * Enables versioning
    1148:      */
    1149:     public static function enableVersioning()
    1150:     {
    1151:         self::$isVersioningEnabled = true;
    1152:     }
    1153:
    1154:     /**
    1155:      * Disables versioning
    1156:      */
    1157:     public static function disableVersioning()
    1158:     {
    1159:         self::$isVersioningEnabled = false;
    1160:     }
    1161:
    1162: } // BaseProductPeer
    1163:
    1164: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1165: //
    1166: BaseProductPeer::buildTableMap();
    1167:
    1168: