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