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