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