       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_US';
     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 directly (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($and_clear_all_references = false)
     460:     {
     461:       if ($and_clear_all_references)
     462:       {
     463:         foreach (ProductPeer::$instances as $instance)
     464:         {
     465:           $instance->clearAllReferences(true);
     466:         }
     467:       }
     468:         ProductPeer::$instances = array();
     469:     }
     470:
     471:     /**
     472:      * Method to invalidate the instance pool of all tables related to product
     473:      * by a foreign key with ON DELETE CASCADE
     474:      */
     475:     public static function clearRelatedInstancePool()
     476:     {
     477:         // Invalidate objects in ProductCategoryPeer instance pool,
     478:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     479:         ProductCategoryPeer::clearInstancePool();
     480:         // Invalidate objects in FeatureProdPeer instance pool,
     481:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     482:         FeatureProdPeer::clearInstancePool();
     483:         // Invalidate objects in StockPeer instance pool,
     484:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     485:         StockPeer::clearInstancePool();
     486:         // Invalidate objects in ContentAssocPeer instance pool,
     487:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     488:         ContentAssocPeer::clearInstancePool();
     489:         // Invalidate objects in ImagePeer instance pool,
     490:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     491:         ImagePeer::clearInstancePool();
     492:         // Invalidate objects in DocumentPeer instance pool,
     493:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     494:         DocumentPeer::clearInstancePool();
     495:         // Invalidate objects in AccessoryPeer instance pool,
     496:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     497:         AccessoryPeer::clearInstancePool();
     498:         // Invalidate objects in AccessoryPeer instance pool,
     499:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     500:         AccessoryPeer::clearInstancePool();
     501:         // Invalidate objects in RewritingPeer instance pool,
     502:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     503:         RewritingPeer::clearInstancePool();
     504:         // Invalidate objects in ProductI18nPeer instance pool,
     505:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     506:         ProductI18nPeer::clearInstancePool();
     507:         // Invalidate objects in ProductVersionPeer instance pool,
     508:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     509:         ProductVersionPeer::clearInstancePool();
     510:     }
     511:
     512:     /**
     513:      * 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.
     514:      *
     515:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     516:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     517:      *
     518:      * @param      array $row PropelPDO resultset row.
     519:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     520:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     521:      */
     522:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     523:     {
     524:         // If the PK cannot be derived from the row, return null.
     525:         if ($row[$startcol] === null) {
     526:             return null;
     527:         }
     528:
     529:         return (string) $row[$startcol];
     530:     }
     531:
     532:     /**
     533:      * Retrieves the primary key from the DB resultset row
     534:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     535:      * a multi-column primary key, an array of the primary key columns will be returned.
     536:      *
     537:      * @param      array $row PropelPDO resultset row.
     538:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     539:      * @return mixed The primary key of the row
     540:      */
     541:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     542:     {
     543:
     544:         return (int) $row[$startcol];
     545:     }
     546:
     547:     /**
     548:      * The returned array will contain objects of the default type or
     549:      * objects that inherit from the default.
     550:      *
     551:      * @throws PropelException Any exceptions caught during processing will be
     552:      *       rethrown wrapped into a PropelException.
     553:      */
     554:     public static function populateObjects(PDOStatement $stmt)
     555:     {
     556:         $results = array();
     557:
     558:         // set the class once to avoid overhead in the loop
     559:         $cls = ProductPeer::getOMClass();
     560:         // populate the object(s)
     561:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     562:             $key = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     563:             if (null !== ($obj = ProductPeer::getInstanceFromPool($key))) {
     564:                 // We no longer rehydrate the object, since this can cause data loss.
     565:                 // See http://www.propelorm.org/ticket/509
     566:                 // $obj->hydrate($row, 0, true); // rehydrate
     567:                 $results[] = $obj;
     568:             } else {
     569:                 $obj = new $cls();
     570:                 $obj->hydrate($row);
     571:                 $results[] = $obj;
     572:                 ProductPeer::addInstanceToPool($obj, $key);
     573:             } // if key exists
     574:         }
     575:         $stmt->closeCursor();
     576:
     577:         return $results;
     578:     }
     579:     /**
     580:      * Populates an object of the default type or an object that inherit from the default.
     581:      *
     582:      * @param      array $row PropelPDO resultset row.
     583:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     584:      * @throws PropelException Any exceptions caught during processing will be
     585:      *       rethrown wrapped into a PropelException.
     586:      * @return array (Product object, last column rank)
     587:      */
     588:     public static function populateObject($row, $startcol = 0)
     589:     {
     590:         $key = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol);
     591:         if (null !== ($obj = ProductPeer::getInstanceFromPool($key))) {
     592:             // We no longer rehydrate the object, since this can cause data loss.
     593:             // See http://www.propelorm.org/ticket/509
     594:             // $obj->hydrate($row, $startcol, true); // rehydrate
     595:             $col = $startcol + ProductPeer::NUM_HYDRATE_COLUMNS;
     596:         } else {
     597:             $cls = ProductPeer::OM_CLASS;
     598:             $obj = new $cls();
     599:             $col = $obj->hydrate($row, $startcol);
     600:             ProductPeer::addInstanceToPool($obj, $key);
     601:         }
     602:
     603:         return array($obj, $col);
     604:     }
     605:
     606:
     607:     /**
     608:      * Returns the number of rows matching criteria, joining the related TaxRule table
     609:      *
     610:      * @param      Criteria $criteria
     611:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     612:      * @param      PropelPDO $con
     613:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     614:      * @return int Number of matching rows.
     615:      */
     616:     public static function doCountJoinTaxRule(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     617:     {
     618:         // we're going to modify criteria, so copy it first
     619:         $criteria = clone $criteria;
     620:
     621:         // We need to set the primary table name, since in the case that there are no WHERE columns
     622:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     623:         // tables go into the FROM clause.
     624:         $criteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     625:
     626:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     627:             $criteria->setDistinct();
     628:         }
     629:
     630:         if (!$criteria->hasSelectClause()) {
     631:             ProductPeer::addSelectColumns($criteria);
     632:         }
     633:
     634:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     635:
     636:         // Set the correct dbName
     637:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     638:
     639:         if ($con === null) {
     640:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     641:         }
     642:
     643:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     644:
     645:         $stmt = BasePeer::doCount($criteria, $con);
     646:
     647:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     648:             $count = (int) $row[0];
     649:         } else {
     650:             $count = 0; // no rows returned; we infer that means 0 matches.
     651:         }
     652:         $stmt->closeCursor();
     653:
     654:         return $count;
     655:     }
     656:
     657:
     658:     /**
     659:      * Selects a collection of Product objects pre-filled with their TaxRule objects.
     660:      * @param      Criteria  $criteria
     661:      * @param      PropelPDO $con
     662:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     663:      * @return array           Array of Product objects.
     664:      * @throws PropelException Any exceptions caught during processing will be
     665:      *       rethrown wrapped into a PropelException.
     666:      */
     667:     public static function doSelectJoinTaxRule(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     668:     {
     669:         $criteria = clone $criteria;
     670:
     671:         // Set the correct dbName if it has not been overridden
     672:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     673:             $criteria->setDbName(ProductPeer::DATABASE_NAME);
     674:         }
     675:
     676:         ProductPeer::addSelectColumns($criteria);
     677:         $startcol = ProductPeer::NUM_HYDRATE_COLUMNS;
     678:         TaxRulePeer::addSelectColumns($criteria);
     679:
     680:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     681:
     682:         $stmt = BasePeer::doSelect($criteria, $con);
     683:         $results = array();
     684:
     685:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     686:             $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     687:             if (null !== ($obj1 = ProductPeer::getInstanceFromPool($key1))) {
     688:                 // We no longer rehydrate the object, since this can cause data loss.
     689:                 // See http://www.propelorm.org/ticket/509
     690:                 // $obj1->hydrate($row, 0, true); // rehydrate
     691:             } else {
     692:
     693:                 $cls = ProductPeer::getOMClass();
     694:
     695:                 $obj1 = new $cls();
     696:                 $obj1->hydrate($row);
     697:                 ProductPeer::addInstanceToPool($obj1, $key1);
     698:             } // if $obj1 already loaded
     699:
     700:             $key2 = TaxRulePeer::getPrimaryKeyHashFromRow($row, $startcol);
     701:             if ($key2 !== null) {
     702:                 $obj2 = TaxRulePeer::getInstanceFromPool($key2);
     703:                 if (!$obj2) {
     704:
     705:                     $cls = TaxRulePeer::getOMClass();
     706:
     707:                     $obj2 = new $cls();
     708:                     $obj2->hydrate($row, $startcol);
     709:                     TaxRulePeer::addInstanceToPool($obj2, $key2);
     710:                 } // if obj2 already loaded
     711:
     712:                 // Add the $obj1 (Product) to $obj2 (TaxRule)
     713:                 $obj2->addProduct($obj1);
     714:
     715:             } // if joined row was not null
     716:
     717:             $results[] = $obj1;
     718:         }
     719:         $stmt->closeCursor();
     720:
     721:         return $results;
     722:     }
     723:
     724:
     725:     /**
     726:      * Returns the number of rows matching criteria, joining all related tables
     727:      *
     728:      * @param      Criteria $criteria
     729:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     730:      * @param      PropelPDO $con
     731:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     732:      * @return int Number of matching rows.
     733:      */
     734:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     735:     {
     736:         // we're going to modify criteria, so copy it first
     737:         $criteria = clone $criteria;
     738:
     739:         // We need to set the primary table name, since in the case that there are no WHERE columns
     740:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     741:         // tables go into the FROM clause.
     742:         $criteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     743:
     744:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     745:             $criteria->setDistinct();
     746:         }
     747:
     748:         if (!$criteria->hasSelectClause()) {
     749:             ProductPeer::addSelectColumns($criteria);
     750:         }
     751:
     752:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     753:
     754:         // Set the correct dbName
     755:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     756:
     757:         if ($con === null) {
     758:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     759:         }
     760:
     761:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     762:
     763:         $stmt = BasePeer::doCount($criteria, $con);
     764:
     765:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     766:             $count = (int) $row[0];
     767:         } else {
     768:             $count = 0; // no rows returned; we infer that means 0 matches.
     769:         }
     770:         $stmt->closeCursor();
     771:
     772:         return $count;
     773:     }
     774:
     775:     /**
     776:      * Selects a collection of Product objects pre-filled with all related objects.
     777:      *
     778:      * @param      Criteria  $criteria
     779:      * @param      PropelPDO $con
     780:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     781:      * @return array           Array of Product objects.
     782:      * @throws PropelException Any exceptions caught during processing will be
     783:      *       rethrown wrapped into a PropelException.
     784:      */
     785:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     786:     {
     787:         $criteria = clone $criteria;
     788:
     789:         // Set the correct dbName if it has not been overridden
     790:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     791:             $criteria->setDbName(ProductPeer::DATABASE_NAME);
     792:         }
     793:
     794:         ProductPeer::addSelectColumns($criteria);
     795:         $startcol2 = ProductPeer::NUM_HYDRATE_COLUMNS;
     796:
     797:         TaxRulePeer::addSelectColumns($criteria);
     798:         $startcol3 = $startcol2 + TaxRulePeer::NUM_HYDRATE_COLUMNS;
     799:
     800:         $criteria->addJoin(ProductPeer::TAX_RULE_ID, TaxRulePeer::ID, $join_behavior);
     801:
     802:         $stmt = BasePeer::doSelect($criteria, $con);
     803:         $results = array();
     804:
     805:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     806:             $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
     807:             if (null !== ($obj1 = ProductPeer::getInstanceFromPool($key1))) {
     808:                 // We no longer rehydrate the object, since this can cause data loss.
     809:                 // See http://www.propelorm.org/ticket/509
     810:                 // $obj1->hydrate($row, 0, true); // rehydrate
     811:             } else {
     812:                 $cls = ProductPeer::getOMClass();
     813:
     814:                 $obj1 = new $cls();
     815:                 $obj1->hydrate($row);
     816:                 ProductPeer::addInstanceToPool($obj1, $key1);
     817:             } // if obj1 already loaded
     818:
     819:             // Add objects for joined TaxRule rows
     820:
     821:             $key2 = TaxRulePeer::getPrimaryKeyHashFromRow($row, $startcol2);
     822:             if ($key2 !== null) {
     823:                 $obj2 = TaxRulePeer::getInstanceFromPool($key2);
     824:                 if (!$obj2) {
     825:
     826:                     $cls = TaxRulePeer::getOMClass();
     827:
     828:                     $obj2 = new $cls();
     829:                     $obj2->hydrate($row, $startcol2);
     830:                     TaxRulePeer::addInstanceToPool($obj2, $key2);
     831:                 } // if obj2 loaded
     832:
     833:                 // Add the $obj1 (Product) to the collection in $obj2 (TaxRule)
     834:                 $obj2->addProduct($obj1);
     835:             } // if joined row not null
     836:
     837:             $results[] = $obj1;
     838:         }
     839:         $stmt->closeCursor();
     840:
     841:         return $results;
     842:     }
     843:
     844:     /**
     845:      * Returns the TableMap related to this peer.
     846:      * This method is not needed for general use but a specific application could have a need.
     847:      * @return TableMap
     848:      * @throws PropelException Any exceptions caught during processing will be
     849:      *       rethrown wrapped into a PropelException.
     850:      */
     851:     public static function getTableMap()
     852:     {
     853:         return Propel::getDatabaseMap(ProductPeer::DATABASE_NAME)->getTable(ProductPeer::TABLE_NAME);
     854:     }
     855:
     856:     /**
     857:      * Add a TableMap instance to the database for this peer class.
     858:      */
     859:     public static function buildTableMap()
     860:     {
     861:       $dbMap = Propel::getDatabaseMap(BaseProductPeer::DATABASE_NAME);
     862:       if (!$dbMap->hasTable(BaseProductPeer::TABLE_NAME)) {
     863:         $dbMap->addTableObject(new ProductTableMap());
     864:       }
     865:     }
     866:
     867:     /**
     868:      * The class that the Peer will make instances of.
     869:      *
     870:      *
     871:      * @return string ClassName
     872:      */
     873:     public static function getOMClass($row = 0, $colnum = 0)
     874:     {
     875:         return ProductPeer::OM_CLASS;
     876:     }
     877:
     878:     /**
     879:      * Performs an INSERT on the database, given a Product or Criteria object.
     880:      *
     881:      * @param      mixed $values Criteria or Product object containing data that is used to create the INSERT statement.
     882:      * @param      PropelPDO $con the PropelPDO connection to use
     883:      * @return mixed           The new primary key.
     884:      * @throws PropelException Any exceptions caught during processing will be
     885:      *       rethrown wrapped into a PropelException.
     886:      */
     887:     public static function doInsert($values, PropelPDO $con = null)
     888:     {
     889:         if ($con === null) {
     890:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     891:         }
     892:
     893:         if ($values instanceof Criteria) {
     894:             $criteria = clone $values; // rename for clarity
     895:         } else {
     896:             $criteria = $values->buildCriteria(); // build Criteria from Product object
     897:         }
     898:
     899:         if ($criteria->containsKey(ProductPeer::ID) && $criteria->keyContainsValue(ProductPeer::ID) ) {
     900:             throw new PropelException('Cannot insert a value for auto-increment primary key ('.ProductPeer::ID.')');
     901:         }
     902:
     903:
     904:         // Set the correct dbName
     905:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     906:
     907:         try {
     908:             // use transaction because $criteria could contain info
     909:             // for more than one table (I guess, conceivably)
     910:             $con->beginTransaction();
     911:             $pk = BasePeer::doInsert($criteria, $con);
     912:             $con->commit();
     913:         } catch (PropelException $e) {
     914:             $con->rollBack();
     915:             throw $e;
     916:         }
     917:
     918:         return $pk;
     919:     }
     920:
     921:     /**
     922:      * Performs an UPDATE on the database, given a Product or Criteria object.
     923:      *
     924:      * @param      mixed $values Criteria or Product object containing data that is used to create the UPDATE statement.
     925:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
     926:      * @return int             The number of affected rows (if supported by underlying database driver).
     927:      * @throws PropelException Any exceptions caught during processing will be
     928:      *       rethrown wrapped into a PropelException.
     929:      */
     930:     public static function doUpdate($values, PropelPDO $con = null)
     931:     {
     932:         if ($con === null) {
     933:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     934:         }
     935:
     936:         $selectCriteria = new Criteria(ProductPeer::DATABASE_NAME);
     937:
     938:         if ($values instanceof Criteria) {
     939:             $criteria = clone $values; // rename for clarity
     940:
     941:             $comparison = $criteria->getComparison(ProductPeer::ID);
     942:             $value = $criteria->remove(ProductPeer::ID);
     943:             if ($value) {
     944:                 $selectCriteria->add(ProductPeer::ID, $value, $comparison);
     945:             } else {
     946:                 $selectCriteria->setPrimaryTableName(ProductPeer::TABLE_NAME);
     947:             }
     948:
     949:         } else { // $values is Product object
     950:             $criteria = $values->buildCriteria(); // gets full criteria
     951:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
     952:         }
     953:
     954:         // set the correct dbName
     955:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     956:
     957:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
     958:     }
     959:
     960:     /**
     961:      * Deletes all rows from the product table.
     962:      *
     963:      * @param      PropelPDO $con the connection to use
     964:      * @return int             The number of affected rows (if supported by underlying database driver).
     965:      * @throws PropelException
     966:      */
     967:     public static function doDeleteAll(PropelPDO $con = null)
     968:     {
     969:         if ($con === null) {
     970:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     971:         }
     972:         $affectedRows = 0; // initialize var to track total num of affected rows
     973:         try {
     974:             // use transaction because $criteria could contain info
     975:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     976:             $con->beginTransaction();
     977:             $affectedRows += BasePeer::doDeleteAll(ProductPeer::TABLE_NAME, $con, ProductPeer::DATABASE_NAME);
     978:             // Because this db requires some delete cascade/set null emulation, we have to
     979:             // clear the cached instance *after* the emulation has happened (since
     980:             // instances get re-added by the select statement contained therein).
     981:             ProductPeer::clearInstancePool();
     982:             ProductPeer::clearRelatedInstancePool();
     983:             $con->commit();
     984:
     985:             return $affectedRows;
     986:         } catch (PropelException $e) {
     987:             $con->rollBack();
     988:             throw $e;
     989:         }
     990:     }
     991:
     992:     /**
     993:      * Performs a DELETE on the database, given a Product or Criteria object OR a primary key value.
     994:      *
     995:      * @param      mixed $values Criteria or Product object or primary key or array of primary keys
     996:      *              which is used to create the DELETE statement
     997:      * @param      PropelPDO $con the connection to use
     998:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
     999:      *              if supported by native driver or if emulated using Propel.
    1000:      * @throws PropelException Any exceptions caught during processing will be
    1001:      *       rethrown wrapped into a PropelException.
    1002:      */
    1003:      public static function doDelete($values, PropelPDO $con = null)
    1004:      {
    1005:         if ($con === null) {
    1006:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1007:         }
    1008:
    1009:         if ($values instanceof Criteria) {
    1010:             // invalidate the cache for all objects of this type, since we have no
    1011:             // way of knowing (without running a query) what objects should be invalidated
    1012:             // from the cache based on this Criteria.
    1013:             ProductPeer::clearInstancePool();
    1014:             // rename for clarity
    1015:             $criteria = clone $values;
    1016:         } elseif ($values instanceof Product) { // it's a model object
    1017:             // invalidate the cache for this single object
    1018:             ProductPeer::removeInstanceFromPool($values);
    1019:             // create criteria based on pk values
    1020:             $criteria = $values->buildPkeyCriteria();
    1021:         } else { // it's a primary key, or an array of pks
    1022:             $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1023:             $criteria->add(ProductPeer::ID, (array) $values, Criteria::IN);
    1024:             // invalidate the cache for this object(s)
    1025:             foreach ((array) $values as $singleval) {
    1026:                 ProductPeer::removeInstanceFromPool($singleval);
    1027:             }
    1028:         }
    1029:
    1030:         // Set the correct dbName
    1031:         $criteria->setDbName(ProductPeer::DATABASE_NAME);
    1032:
    1033:         $affectedRows = 0; // initialize var to track total num of affected rows
    1034:
    1035:         try {
    1036:             // use transaction because $criteria could contain info
    1037:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1038:             $con->beginTransaction();
    1039:
    1040:             $affectedRows += BasePeer::doDelete($criteria, $con);
    1041:             ProductPeer::clearRelatedInstancePool();
    1042:             $con->commit();
    1043:
    1044:             return $affectedRows;
    1045:         } catch (PropelException $e) {
    1046:             $con->rollBack();
    1047:             throw $e;
    1048:         }
    1049:     }
    1050:
    1051:     /**
    1052:      * Validates all modified columns of given Product object.
    1053:      * If parameter $columns is either a single column name or an array of column names
    1054:      * than only those columns are validated.
    1055:      *
    1056:      * NOTICE: This does not apply to primary or foreign keys for now.
    1057:      *
    1058:      * @param      Product $obj The object to validate.
    1059:      * @param      mixed $cols Column name or array of column names.
    1060:      *
    1061:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
    1062:      */
    1063:     public static function doValidate($obj, $cols = null)
    1064:     {
    1065:         $columns = array();
    1066:
    1067:         if ($cols) {
    1068:             $dbMap = Propel::getDatabaseMap(ProductPeer::DATABASE_NAME);
    1069:             $tableMap = $dbMap->getTable(ProductPeer::TABLE_NAME);
    1070:
    1071:             if (! is_array($cols)) {
    1072:                 $cols = array($cols);
    1073:             }
    1074:
    1075:             foreach ($cols as $colName) {
    1076:                 if ($tableMap->hasColumn($colName)) {
    1077:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
    1078:                     $columns[$colName] = $obj->$get();
    1079:                 }
    1080:             }
    1081:         } else {
    1082:
    1083:         }
    1084:
    1085:         return BasePeer::doValidate(ProductPeer::DATABASE_NAME, ProductPeer::TABLE_NAME, $columns);
    1086:     }
    1087:
    1088:     /**
    1089:      * Retrieve a single object by pkey.
    1090:      *
    1091:      * @param      int $pk the primary key.
    1092:      * @param      PropelPDO $con the connection to use
    1093:      * @return Product
    1094:      */
    1095:     public static function retrieveByPK($pk, PropelPDO $con = null)
    1096:     {
    1097:
    1098:         if (null !== ($obj = ProductPeer::getInstanceFromPool((string) $pk))) {
    1099:             return $obj;
    1100:         }
    1101:
    1102:         if ($con === null) {
    1103:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1104:         }
    1105:
    1106:         $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1107:         $criteria->add(ProductPeer::ID, $pk);
    1108:
    1109:         $v = ProductPeer::doSelect($criteria, $con);
    1110:
    1111:         return !empty($v) > 0 ? $v[0] : null;
    1112:     }
    1113:
    1114:     /**
    1115:      * Retrieve multiple objects by pkey.
    1116:      *
    1117:      * @param      array $pks List of primary keys
    1118:      * @param      PropelPDO $con the connection to use
    1119:      * @return Product[]
    1120:      * @throws PropelException Any exceptions caught during processing will be
    1121:      *       rethrown wrapped into a PropelException.
    1122:      */
    1123:     public static function retrieveByPKs($pks, PropelPDO $con = null)
    1124:     {
    1125:         if ($con === null) {
    1126:             $con = Propel::getConnection(ProductPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1127:         }
    1128:
    1129:         $objs = null;
    1130:         if (empty($pks)) {
    1131:             $objs = array();
    1132:         } else {
    1133:             $criteria = new Criteria(ProductPeer::DATABASE_NAME);
    1134:             $criteria->add(ProductPeer::ID, $pks, Criteria::IN);
    1135:             $objs = ProductPeer::doSelect($criteria, $con);
    1136:         }
    1137:
    1138:         return $objs;
    1139:     }
    1140:
    1141:     // versionable behavior
    1142:
    1143:     /**
    1144:      * Checks whether versioning is enabled
    1145:      *
    1146:      * @return boolean
    1147:      */
    1148:     public static function isVersioningEnabled()
    1149:     {
    1150:         return self::$isVersioningEnabled;
    1151:     }
    1152:
    1153:     /**
    1154:      * Enables versioning
    1155:      */
    1156:     public static function enableVersioning()
    1157:     {
    1158:         self::$isVersioningEnabled = true;
    1159:     }
    1160:
    1161:     /**
    1162:      * Disables versioning
    1163:      */
    1164:     public static function disableVersioning()
    1165:     {
    1166:         self::$isVersioningEnabled = false;
    1167:     }
    1168:
    1169: } // BaseProductPeer
    1170:
    1171: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1172: //
    1173: BaseProductPeer::buildTableMap();
    1174:
    1175: