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