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

      1: <?php
      2:
      3: namespace Thelia\Model\om;
      4:
      5: use \Criteria;
      6: use \Exception;
      7: use \ModelCriteria;
      8: use \ModelJoin;
      9: use \PDO;
     10: use \Propel;
     11: use \PropelCollection;
     12: use \PropelException;
     13: use \PropelObjectCollection;
     14: use \PropelPDO;
     15: use Thelia\Model\Combination;
     16: use Thelia\Model\Product;
     17: use Thelia\Model\Stock;
     18: use Thelia\Model\StockPeer;
     19: use Thelia\Model\StockQuery;
     20:
     21: /**
     22:  * Base class that represents a query for the 'stock' table.
     23:  *
     24:  *
     25:  *
     26:  * @method StockQuery orderById($order = Criteria::ASC) Order by the id column
     27:  * @method StockQuery orderByCombinationId($order = Criteria::ASC) Order by the combination_id column
     28:  * @method StockQuery orderByProductId($order = Criteria::ASC) Order by the product_id column
     29:  * @method StockQuery orderByIncrease($order = Criteria::ASC) Order by the increase column
     30:  * @method StockQuery orderByValue($order = Criteria::ASC) Order by the value column
     31:  * @method StockQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
     32:  * @method StockQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
     33:  *
     34:  * @method StockQuery groupById() Group by the id column
     35:  * @method StockQuery groupByCombinationId() Group by the combination_id column
     36:  * @method StockQuery groupByProductId() Group by the product_id column
     37:  * @method StockQuery groupByIncrease() Group by the increase column
     38:  * @method StockQuery groupByValue() Group by the value column
     39:  * @method StockQuery groupByCreatedAt() Group by the created_at column
     40:  * @method StockQuery groupByUpdatedAt() Group by the updated_at column
     41:  *
     42:  * @method StockQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
     43:  * @method StockQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
     44:  * @method StockQuery innerJoin($relation) Adds a INNER JOIN clause to the query
     45:  *
     46:  * @method StockQuery leftJoinCombination($relationAlias = null) Adds a LEFT JOIN clause to the query using the Combination relation
     47:  * @method StockQuery rightJoinCombination($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Combination relation
     48:  * @method StockQuery innerJoinCombination($relationAlias = null) Adds a INNER JOIN clause to the query using the Combination relation
     49:  *
     50:  * @method StockQuery leftJoinProduct($relationAlias = null) Adds a LEFT JOIN clause to the query using the Product relation
     51:  * @method StockQuery rightJoinProduct($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Product relation
     52:  * @method StockQuery innerJoinProduct($relationAlias = null) Adds a INNER JOIN clause to the query using the Product relation
     53:  *
     54:  * @method Stock findOne(PropelPDO $con = null) Return the first Stock matching the query
     55:  * @method Stock findOneOrCreate(PropelPDO $con = null) Return the first Stock matching the query, or a new Stock object populated from the query conditions when no match is found
     56:  *
     57:  * @method Stock findOneById(int $id) Return the first Stock filtered by the id column
     58:  * @method Stock findOneByCombinationId(int $combination_id) Return the first Stock filtered by the combination_id column
     59:  * @method Stock findOneByProductId(int $product_id) Return the first Stock filtered by the product_id column
     60:  * @method Stock findOneByIncrease(double $increase) Return the first Stock filtered by the increase column
     61:  * @method Stock findOneByValue(double $value) Return the first Stock filtered by the value column
     62:  * @method Stock findOneByCreatedAt(string $created_at) Return the first Stock filtered by the created_at column
     63:  * @method Stock findOneByUpdatedAt(string $updated_at) Return the first Stock filtered by the updated_at column
     64:  *
     65:  * @method array findById(int $id) Return Stock objects filtered by the id column
     66:  * @method array findByCombinationId(int $combination_id) Return Stock objects filtered by the combination_id column
     67:  * @method array findByProductId(int $product_id) Return Stock objects filtered by the product_id column
     68:  * @method array findByIncrease(double $increase) Return Stock objects filtered by the increase column
     69:  * @method array findByValue(double $value) Return Stock objects filtered by the value column
     70:  * @method array findByCreatedAt(string $created_at) Return Stock objects filtered by the created_at column
     71:  * @method array findByUpdatedAt(string $updated_at) Return Stock objects filtered by the updated_at column
     72:  *
     73:  * @package    propel.generator.Thelia.Model.om
     74:  */
     75: abstract class BaseStockQuery extends ModelCriteria
     76: {
     77:     /**
     78:      * Initializes internal state of BaseStockQuery object.
     79:      *
     80:      * @param     string $dbName The dabase name
     81:      * @param     string $modelName The phpName of a model, e.g. 'Book'
     82:      * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     83:      */
     84:     public function __construct($dbName = 'thelia', $modelName = 'Thelia\\Model\\Stock', $modelAlias = null)
     85:     {
     86:         parent::__construct($dbName, $modelName, $modelAlias);
     87:     }
     88:
     89:     /**
     90:      * Returns a new StockQuery object.
     91:      *
     92:      * @param     string $modelAlias The alias of a model in the query
     93:      * @param     StockQuery|Criteria $criteria Optional Criteria to build the query from
     94:      *
     95:      * @return StockQuery
     96:      */
     97:     public static function create($modelAlias = null, $criteria = null)
     98:     {
     99:         if ($criteria instanceof StockQuery) {
    100:             return $criteria;
    101:         }
    102:         $query = new StockQuery();
    103:         if (null !== $modelAlias) {
    104:             $query->setModelAlias($modelAlias);
    105:         }
    106:         if ($criteria instanceof Criteria) {
    107:             $query->mergeWith($criteria);
    108:         }
    109:
    110:         return $query;
    111:     }
    112:
    113:     /**
    114:      * Find object by primary key.
    115:      * Propel uses the instance pool to skip the database if the object exists.
    116:      * Go fast if the query is untouched.
    117:      *
    118:      * <code>
    119:      * $obj  = $c->findPk(12, $con);
    120:      * </code>
    121:      *
    122:      * @param mixed $key Primary key to use for the query
    123:      * @param     PropelPDO $con an optional connection object
    124:      *
    125:      * @return   Stock|Stock[]|mixed the result, formatted by the current formatter
    126:      */
    127:     public function findPk($key, $con = null)
    128:     {
    129:         if ($key === null) {
    130:             return null;
    131:         }
    132:         if ((null !== ($obj = StockPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
    133:             // the object is alredy in the instance pool
    134:             return $obj;
    135:         }
    136:         if ($con === null) {
    137:             $con = Propel::getConnection(StockPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    138:         }
    139:         $this->basePreSelect($con);
    140:         if ($this->formatter || $this->modelAlias || $this->with || $this->select
    141:          || $this->selectColumns || $this->asColumns || $this->selectModifiers
    142:          || $this->map || $this->having || $this->joins) {
    143:             return $this->findPkComplex($key, $con);
    144:         } else {
    145:             return $this->findPkSimple($key, $con);
    146:         }
    147:     }
    148:
    149:     /**
    150:      * Find object by primary key using raw SQL to go fast.
    151:      * Bypass doSelect() and the object formatter by using generated code.
    152:      *
    153:      * @param     mixed $key Primary key to use for the query
    154:      * @param     PropelPDO $con A connection object
    155:      *
    156:      * @return   Stock A model object, or null if the key is not found
    157:      * @throws   PropelException
    158:      */
    159:     protected function findPkSimple($key, $con)
    160:     {
    161:         $sql = 'SELECT `ID`, `COMBINATION_ID`, `PRODUCT_ID`, `INCREASE`, `VALUE`, `CREATED_AT`, `UPDATED_AT` FROM `stock` WHERE `ID` = :p0';
    162:         try {
    163:             $stmt = $con->prepare($sql);
    164:             $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
    165:             $stmt->execute();
    166:         } catch (Exception $e) {
    167:             Propel::log($e->getMessage(), Propel::LOG_ERR);
    168:             throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
    169:         }
    170:         $obj = null;
    171:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    172:             $obj = new Stock();
    173:             $obj->hydrate($row);
    174:             StockPeer::addInstanceToPool($obj, (string) $key);
    175:         }
    176:         $stmt->closeCursor();
    177:
    178:         return $obj;
    179:     }
    180:
    181:     /**
    182:      * Find object by primary key.
    183:      *
    184:      * @param     mixed $key Primary key to use for the query
    185:      * @param     PropelPDO $con A connection object
    186:      *
    187:      * @return Stock|Stock[]|mixed the result, formatted by the current formatter
    188:      */
    189:     protected function findPkComplex($key, $con)
    190:     {
    191:         // As the query uses a PK condition, no limit(1) is necessary.
    192:         $criteria = $this->isKeepQuery() ? clone $this : $this;
    193:         $stmt = $criteria
    194:             ->filterByPrimaryKey($key)
    195:             ->doSelect($con);
    196:
    197:         return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    198:     }
    199:
    200:     /**
    201:      * Find objects by primary key
    202:      * <code>
    203:      * $objs = $c->findPks(array(12, 56, 832), $con);
    204:      * </code>
    205:      * @param     array $keys Primary keys to use for the query
    206:      * @param     PropelPDO $con an optional connection object
    207:      *
    208:      * @return PropelObjectCollection|Stock[]|mixed the list of results, formatted by the current formatter
    209:      */
    210:     public function findPks($keys, $con = null)
    211:     {
    212:         if ($con === null) {
    213:             $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
    214:         }
    215:         $this->basePreSelect($con);
    216:         $criteria = $this->isKeepQuery() ? clone $this : $this;
    217:         $stmt = $criteria
    218:             ->filterByPrimaryKeys($keys)
    219:             ->doSelect($con);
    220:
    221:         return $criteria->getFormatter()->init($criteria)->format($stmt);
    222:     }
    223:
    224:     /**
    225:      * Filter the query by primary key
    226:      *
    227:      * @param     mixed $key Primary key to use for the query
    228:      *
    229:      * @return StockQuery The current query, for fluid interface
    230:      */
    231:     public function filterByPrimaryKey($key)
    232:     {
    233:
    234:         return $this->addUsingAlias(StockPeer::ID, $key, Criteria::EQUAL);
    235:     }
    236:
    237:     /**
    238:      * Filter the query by a list of primary keys
    239:      *
    240:      * @param     array $keys The list of primary key to use for the query
    241:      *
    242:      * @return StockQuery The current query, for fluid interface
    243:      */
    244:     public function filterByPrimaryKeys($keys)
    245:     {
    246:
    247:         return $this->addUsingAlias(StockPeer::ID, $keys, Criteria::IN);
    248:     }
    249:
    250:     /**
    251:      * Filter the query on the id column
    252:      *
    253:      * Example usage:
    254:      * <code>
    255:      * $query->filterById(1234); // WHERE id = 1234
    256:      * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
    257:      * $query->filterById(array('min' => 12)); // WHERE id > 12
    258:      * </code>
    259:      *
    260:      * @param     mixed $id The value to use as filter.
    261:      *              Use scalar values for equality.
    262:      *              Use array values for in_array() equivalent.
    263:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    264:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    265:      *
    266:      * @return StockQuery The current query, for fluid interface
    267:      */
    268:     public function filterById($id = null, $comparison = null)
    269:     {
    270:         if (is_array($id) && null === $comparison) {
    271:             $comparison = Criteria::IN;
    272:         }
    273:
    274:         return $this->addUsingAlias(StockPeer::ID, $id, $comparison);
    275:     }
    276:
    277:     /**
    278:      * Filter the query on the combination_id column
    279:      *
    280:      * Example usage:
    281:      * <code>
    282:      * $query->filterByCombinationId(1234); // WHERE combination_id = 1234
    283:      * $query->filterByCombinationId(array(12, 34)); // WHERE combination_id IN (12, 34)
    284:      * $query->filterByCombinationId(array('min' => 12)); // WHERE combination_id > 12
    285:      * </code>
    286:      *
    287:      * @see       filterByCombination()
    288:      *
    289:      * @param     mixed $combinationId The value to use as filter.
    290:      *              Use scalar values for equality.
    291:      *              Use array values for in_array() equivalent.
    292:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    293:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    294:      *
    295:      * @return StockQuery The current query, for fluid interface
    296:      */
    297:     public function filterByCombinationId($combinationId = null, $comparison = null)
    298:     {
    299:         if (is_array($combinationId)) {
    300:             $useMinMax = false;
    301:             if (isset($combinationId['min'])) {
    302:                 $this->addUsingAlias(StockPeer::COMBINATION_ID, $combinationId['min'], Criteria::GREATER_EQUAL);
    303:                 $useMinMax = true;
    304:             }
    305:             if (isset($combinationId['max'])) {
    306:                 $this->addUsingAlias(StockPeer::COMBINATION_ID, $combinationId['max'], Criteria::LESS_EQUAL);
    307:                 $useMinMax = true;
    308:             }
    309:             if ($useMinMax) {
    310:                 return $this;
    311:             }
    312:             if (null === $comparison) {
    313:                 $comparison = Criteria::IN;
    314:             }
    315:         }
    316:
    317:         return $this->addUsingAlias(StockPeer::COMBINATION_ID, $combinationId, $comparison);
    318:     }
    319:
    320:     /**
    321:      * Filter the query on the product_id column
    322:      *
    323:      * Example usage:
    324:      * <code>
    325:      * $query->filterByProductId(1234); // WHERE product_id = 1234
    326:      * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34)
    327:      * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12
    328:      * </code>
    329:      *
    330:      * @see       filterByProduct()
    331:      *
    332:      * @param     mixed $productId The value to use as filter.
    333:      *              Use scalar values for equality.
    334:      *              Use array values for in_array() equivalent.
    335:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    336:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    337:      *
    338:      * @return StockQuery The current query, for fluid interface
    339:      */
    340:     public function filterByProductId($productId = null, $comparison = null)
    341:     {
    342:         if (is_array($productId)) {
    343:             $useMinMax = false;
    344:             if (isset($productId['min'])) {
    345:                 $this->addUsingAlias(StockPeer::PRODUCT_ID, $productId['min'], Criteria::GREATER_EQUAL);
    346:                 $useMinMax = true;
    347:             }
    348:             if (isset($productId['max'])) {
    349:                 $this->addUsingAlias(StockPeer::PRODUCT_ID, $productId['max'], Criteria::LESS_EQUAL);
    350:                 $useMinMax = true;
    351:             }
    352:             if ($useMinMax) {
    353:                 return $this;
    354:             }
    355:             if (null === $comparison) {
    356:                 $comparison = Criteria::IN;
    357:             }
    358:         }
    359:
    360:         return $this->addUsingAlias(StockPeer::PRODUCT_ID, $productId, $comparison);
    361:     }
    362:
    363:     /**
    364:      * Filter the query on the increase column
    365:      *
    366:      * Example usage:
    367:      * <code>
    368:      * $query->filterByIncrease(1234); // WHERE increase = 1234
    369:      * $query->filterByIncrease(array(12, 34)); // WHERE increase IN (12, 34)
    370:      * $query->filterByIncrease(array('min' => 12)); // WHERE increase > 12
    371:      * </code>
    372:      *
    373:      * @param     mixed $increase The value to use as filter.
    374:      *              Use scalar values for equality.
    375:      *              Use array values for in_array() equivalent.
    376:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    377:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    378:      *
    379:      * @return StockQuery The current query, for fluid interface
    380:      */
    381:     public function filterByIncrease($increase = null, $comparison = null)
    382:     {
    383:         if (is_array($increase)) {
    384:             $useMinMax = false;
    385:             if (isset($increase['min'])) {
    386:                 $this->addUsingAlias(StockPeer::INCREASE, $increase['min'], Criteria::GREATER_EQUAL);
    387:                 $useMinMax = true;
    388:             }
    389:             if (isset($increase['max'])) {
    390:                 $this->addUsingAlias(StockPeer::INCREASE, $increase['max'], Criteria::LESS_EQUAL);
    391:                 $useMinMax = true;
    392:             }
    393:             if ($useMinMax) {
    394:                 return $this;
    395:             }
    396:             if (null === $comparison) {
    397:                 $comparison = Criteria::IN;
    398:             }
    399:         }
    400:
    401:         return $this->addUsingAlias(StockPeer::INCREASE, $increase, $comparison);
    402:     }
    403:
    404:     /**
    405:      * Filter the query on the value column
    406:      *
    407:      * Example usage:
    408:      * <code>
    409:      * $query->filterByValue(1234); // WHERE value = 1234
    410:      * $query->filterByValue(array(12, 34)); // WHERE value IN (12, 34)
    411:      * $query->filterByValue(array('min' => 12)); // WHERE value > 12
    412:      * </code>
    413:      *
    414:      * @param     mixed $value The value to use as filter.
    415:      *              Use scalar values for equality.
    416:      *              Use array values for in_array() equivalent.
    417:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    418:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    419:      *
    420:      * @return StockQuery The current query, for fluid interface
    421:      */
    422:     public function filterByValue($value = null, $comparison = null)
    423:     {
    424:         if (is_array($value)) {
    425:             $useMinMax = false;
    426:             if (isset($value['min'])) {
    427:                 $this->addUsingAlias(StockPeer::VALUE, $value['min'], Criteria::GREATER_EQUAL);
    428:                 $useMinMax = true;
    429:             }
    430:             if (isset($value['max'])) {
    431:                 $this->addUsingAlias(StockPeer::VALUE, $value['max'], Criteria::LESS_EQUAL);
    432:                 $useMinMax = true;
    433:             }
    434:             if ($useMinMax) {
    435:                 return $this;
    436:             }
    437:             if (null === $comparison) {
    438:                 $comparison = Criteria::IN;
    439:             }
    440:         }
    441:
    442:         return $this->addUsingAlias(StockPeer::VALUE, $value, $comparison);
    443:     }
    444:
    445:     /**
    446:      * Filter the query on the created_at column
    447:      *
    448:      * Example usage:
    449:      * <code>
    450:      * $query->filterByCreatedAt('2011-03-14'); // WHERE created_at = '2011-03-14'
    451:      * $query->filterByCreatedAt('now'); // WHERE created_at = '2011-03-14'
    452:      * $query->filterByCreatedAt(array('max' => 'yesterday')); // WHERE created_at > '2011-03-13'
    453:      * </code>
    454:      *
    455:      * @param     mixed $createdAt The value to use as filter.
    456:      *              Values can be integers (unix timestamps), DateTime objects, or strings.
    457:      *              Empty strings are treated as NULL.
    458:      *              Use scalar values for equality.
    459:      *              Use array values for in_array() equivalent.
    460:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    461:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    462:      *
    463:      * @return StockQuery The current query, for fluid interface
    464:      */
    465:     public function filterByCreatedAt($createdAt = null, $comparison = null)
    466:     {
    467:         if (is_array($createdAt)) {
    468:             $useMinMax = false;
    469:             if (isset($createdAt['min'])) {
    470:                 $this->addUsingAlias(StockPeer::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
    471:                 $useMinMax = true;
    472:             }
    473:             if (isset($createdAt['max'])) {
    474:                 $this->addUsingAlias(StockPeer::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
    475:                 $useMinMax = true;
    476:             }
    477:             if ($useMinMax) {
    478:                 return $this;
    479:             }
    480:             if (null === $comparison) {
    481:                 $comparison = Criteria::IN;
    482:             }
    483:         }
    484:
    485:         return $this->addUsingAlias(StockPeer::CREATED_AT, $createdAt, $comparison);
    486:     }
    487:
    488:     /**
    489:      * Filter the query on the updated_at column
    490:      *
    491:      * Example usage:
    492:      * <code>
    493:      * $query->filterByUpdatedAt('2011-03-14'); // WHERE updated_at = '2011-03-14'
    494:      * $query->filterByUpdatedAt('now'); // WHERE updated_at = '2011-03-14'
    495:      * $query->filterByUpdatedAt(array('max' => 'yesterday')); // WHERE updated_at > '2011-03-13'
    496:      * </code>
    497:      *
    498:      * @param     mixed $updatedAt The value to use as filter.
    499:      *              Values can be integers (unix timestamps), DateTime objects, or strings.
    500:      *              Empty strings are treated as NULL.
    501:      *              Use scalar values for equality.
    502:      *              Use array values for in_array() equivalent.
    503:      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
    504:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    505:      *
    506:      * @return StockQuery The current query, for fluid interface
    507:      */
    508:     public function filterByUpdatedAt($updatedAt = null, $comparison = null)
    509:     {
    510:         if (is_array($updatedAt)) {
    511:             $useMinMax = false;
    512:             if (isset($updatedAt['min'])) {
    513:                 $this->addUsingAlias(StockPeer::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
    514:                 $useMinMax = true;
    515:             }
    516:             if (isset($updatedAt['max'])) {
    517:                 $this->addUsingAlias(StockPeer::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
    518:                 $useMinMax = true;
    519:             }
    520:             if ($useMinMax) {
    521:                 return $this;
    522:             }
    523:             if (null === $comparison) {
    524:                 $comparison = Criteria::IN;
    525:             }
    526:         }
    527:
    528:         return $this->addUsingAlias(StockPeer::UPDATED_AT, $updatedAt, $comparison);
    529:     }
    530:
    531:     /**
    532:      * Filter the query by a related Combination object
    533:      *
    534:      * @param   Combination|PropelObjectCollection $combination The related object(s) to use as filter
    535:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    536:      *
    537:      * @return   StockQuery The current query, for fluid interface
    538:      * @throws   PropelException - if the provided filter is invalid.
    539:      */
    540:     public function filterByCombination($combination, $comparison = null)
    541:     {
    542:         if ($combination instanceof Combination) {
    543:             return $this
    544:                 ->addUsingAlias(StockPeer::COMBINATION_ID, $combination->getId(), $comparison);
    545:         } elseif ($combination instanceof PropelObjectCollection) {
    546:             if (null === $comparison) {
    547:                 $comparison = Criteria::IN;
    548:             }
    549:
    550:             return $this
    551:                 ->addUsingAlias(StockPeer::COMBINATION_ID, $combination->toKeyValue('PrimaryKey', 'Id'), $comparison);
    552:         } else {
    553:             throw new PropelException('filterByCombination() only accepts arguments of type Combination or PropelCollection');
    554:         }
    555:     }
    556:
    557:     /**
    558:      * Adds a JOIN clause to the query using the Combination relation
    559:      *
    560:      * @param     string $relationAlias optional alias for the relation
    561:      * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
    562:      *
    563:      * @return StockQuery The current query, for fluid interface
    564:      */
    565:     public function joinCombination($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    566:     {
    567:         $tableMap = $this->getTableMap();
    568:         $relationMap = $tableMap->getRelation('Combination');
    569:
    570:         // create a ModelJoin object for this join
    571:         $join = new ModelJoin();
    572:         $join->setJoinType($joinType);
    573:         $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
    574:         if ($previousJoin = $this->getPreviousJoin()) {
    575:             $join->setPreviousJoin($previousJoin);
    576:         }
    577:
    578:         // add the ModelJoin to the current object
    579:         if ($relationAlias) {
    580:             $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
    581:             $this->addJoinObject($join, $relationAlias);
    582:         } else {
    583:             $this->addJoinObject($join, 'Combination');
    584:         }
    585:
    586:         return $this;
    587:     }
    588:
    589:     /**
    590:      * Use the Combination relation Combination object
    591:      *
    592:      * @see       useQuery()
    593:      *
    594:      * @param     string $relationAlias optional alias for the relation,
    595:      *                                   to be used as main alias in the secondary query
    596:      * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
    597:      *
    598:      * @return   \Thelia\Model\CombinationQuery A secondary query class using the current class as primary query
    599:      */
    600:     public function useCombinationQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN)
    601:     {
    602:         return $this
    603:             ->joinCombination($relationAlias, $joinType)
    604:             ->useQuery($relationAlias ? $relationAlias : 'Combination', '\Thelia\Model\CombinationQuery');
    605:     }
    606:
    607:     /**
    608:      * Filter the query by a related Product object
    609:      *
    610:      * @param   Product|PropelObjectCollection $product The related object(s) to use as filter
    611:      * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
    612:      *
    613:      * @return   StockQuery The current query, for fluid interface
    614:      * @throws   PropelException - if the provided filter is invalid.
    615:      */
    616:     public function filterByProduct($product, $comparison = null)
    617:     {
    618:         if ($product instanceof Product) {
    619:             return $this
    620:                 ->addUsingAlias(StockPeer::PRODUCT_ID, $product->getId(), $comparison);
    621:         } elseif ($product instanceof PropelObjectCollection) {
    622:             if (null === $comparison) {
    623:                 $comparison = Criteria::IN;
    624:             }
    625:
    626:             return $this
    627:                 ->addUsingAlias(StockPeer::PRODUCT_ID, $product->toKeyValue('PrimaryKey', 'Id'), $comparison);
    628:         } else {
    629:             throw new PropelException('filterByProduct() only accepts arguments of type Product or PropelCollection');
    630:         }
    631:     }
    632:
    633:     /**
    634:      * Adds a JOIN clause to the query using the Product relation
    635:      *
    636:      * @param     string $relationAlias optional alias for the relation
    637:      * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
    638:      *
    639:      * @return StockQuery The current query, for fluid interface
    640:      */
    641:     public function joinProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    642:     {
    643:         $tableMap = $this->getTableMap();
    644:         $relationMap = $tableMap->getRelation('Product');
    645:
    646:         // create a ModelJoin object for this join
    647:         $join = new ModelJoin();
    648:         $join->setJoinType($joinType);
    649:         $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
    650:         if ($previousJoin = $this->getPreviousJoin()) {
    651:             $join->setPreviousJoin($previousJoin);
    652:         }
    653:
    654:         // add the ModelJoin to the current object
    655:         if ($relationAlias) {
    656:             $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
    657:             $this->addJoinObject($join, $relationAlias);
    658:         } else {
    659:             $this->addJoinObject($join, 'Product');
    660:         }
    661:
    662:         return $this;
    663:     }
    664:
    665:     /**
    666:      * Use the Product relation Product object
    667:      *
    668:      * @see       useQuery()
    669:      *
    670:      * @param     string $relationAlias optional alias for the relation,
    671:      *                                   to be used as main alias in the secondary query
    672:      * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
    673:      *
    674:      * @return   \Thelia\Model\ProductQuery A secondary query class using the current class as primary query
    675:      */
    676:     public function useProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    677:     {
    678:         return $this
    679:             ->joinProduct($relationAlias, $joinType)
    680:             ->useQuery($relationAlias ? $relationAlias : 'Product', '\Thelia\Model\ProductQuery');
    681:     }
    682:
    683:     /**
    684:      * Exclude object from result
    685:      *
    686:      * @param   Stock $stock Object to remove from the list of results
    687:      *
    688:      * @return StockQuery The current query, for fluid interface
    689:      */
    690:     public function prune($stock = null)
    691:     {
    692:         if ($stock) {
    693:             $this->addUsingAlias(StockPeer::ID, $stock->getId(), Criteria::NOT_EQUAL);
    694:         }
    695:
    696:         return $this;
    697:     }
    698:
    699:     // timestampable behavior
    700:
    701:     /**
    702:      * Filter by the latest updated
    703:      *
    704:      * @param      int $nbDays Maximum age of the latest update in days
    705:      *
    706:      * @return     StockQuery The current query, for fluid interface
    707:      */
    708:     public function recentlyUpdated($nbDays = 7)
    709:     {
    710:         return $this->addUsingAlias(StockPeer::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
    711:     }
    712:
    713:     /**
    714:      * Order by update date desc
    715:      *
    716:      * @return     StockQuery The current query, for fluid interface
    717:      */
    718:     public function lastUpdatedFirst()
    719:     {
    720:         return $this->addDescendingOrderByColumn(StockPeer::UPDATED_AT);
    721:     }
    722:
    723:     /**
    724:      * Order by update date asc
    725:      *
    726:      * @return     StockQuery The current query, for fluid interface
    727:      */
    728:     public function firstUpdatedFirst()
    729:     {
    730:         return $this->addAscendingOrderByColumn(StockPeer::UPDATED_AT);
    731:     }
    732:
    733:     /**
    734:      * Filter by the latest created
    735:      *
    736:      * @param      int $nbDays Maximum age of in days
    737:      *
    738:      * @return     StockQuery The current query, for fluid interface
    739:      */
    740:     public function recentlyCreated($nbDays = 7)
    741:     {
    742:         return $this->addUsingAlias(StockPeer::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
    743:     }
    744:
    745:     /**
    746:      * Order by create date desc
    747:      *
    748:      * @return     StockQuery The current query, for fluid interface
    749:      */
    750:     public function lastCreatedFirst()
    751:     {
    752:         return $this->addDescendingOrderByColumn(StockPeer::CREATED_AT);
    753:     }
    754:
    755:     /**
    756:      * Order by create date asc
    757:      *
    758:      * @return     StockQuery The current query, for fluid interface
    759:      */
    760:     public function firstCreatedFirst()
    761:     {
    762:         return $this->addAscendingOrderByColumn(StockPeer::CREATED_AT);
    763:     }
    764: }
    765: