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