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