1. matteosister
  2. sfPropelORMRatableBehaviorPlugin

Source

sfPropelORMRatableBehaviorPlugin / lib / model / om / BasesfRatableQuery.php

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<?php


/**
 * Base class that represents a query for the 'sf_ratable' table.
 *
 * 
 *
 * This class was autogenerated by Propel 1.5.3-dev on:
 *
 * Tue Jul 13 14:46:38 2010
 *
 * @method     sfRatableQuery orderById($order = Criteria::ASC) Order by the id column
 * @method     sfRatableQuery orderByRatableModel($order = Criteria::ASC) Order by the ratable_model column
 * @method     sfRatableQuery orderByRatableId($order = Criteria::ASC) Order by the ratable_id column
 * @method     sfRatableQuery orderByUserId($order = Criteria::ASC) Order by the user_id column
 * @method     sfRatableQuery orderByRating($order = Criteria::ASC) Order by the rating column
 * @method     sfRatableQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
 * @method     sfRatableQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
 *
 * @method     sfRatableQuery groupById() Group by the id column
 * @method     sfRatableQuery groupByRatableModel() Group by the ratable_model column
 * @method     sfRatableQuery groupByRatableId() Group by the ratable_id column
 * @method     sfRatableQuery groupByUserId() Group by the user_id column
 * @method     sfRatableQuery groupByRating() Group by the rating column
 * @method     sfRatableQuery groupByCreatedAt() Group by the created_at column
 * @method     sfRatableQuery groupByUpdatedAt() Group by the updated_at column
 *
 * @method     sfRatableQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method     sfRatableQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method     sfRatableQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method     sfRatable findOne(PropelPDO $con = null) Return the first sfRatable matching the query
 * @method     sfRatable findOneOrCreate(PropelPDO $con = null) Return the first sfRatable matching the query, or a new sfRatable object populated from the query conditions when no match is found
 *
 * @method     sfRatable findOneById(int $id) Return the first sfRatable filtered by the id column
 * @method     sfRatable findOneByRatableModel(string $ratable_model) Return the first sfRatable filtered by the ratable_model column
 * @method     sfRatable findOneByRatableId(int $ratable_id) Return the first sfRatable filtered by the ratable_id column
 * @method     sfRatable findOneByUserId(int $user_id) Return the first sfRatable filtered by the user_id column
 * @method     sfRatable findOneByRating(int $rating) Return the first sfRatable filtered by the rating column
 * @method     sfRatable findOneByCreatedAt(string $created_at) Return the first sfRatable filtered by the created_at column
 * @method     sfRatable findOneByUpdatedAt(string $updated_at) Return the first sfRatable filtered by the updated_at column
 *
 * @method     array findById(int $id) Return sfRatable objects filtered by the id column
 * @method     array findByRatableModel(string $ratable_model) Return sfRatable objects filtered by the ratable_model column
 * @method     array findByRatableId(int $ratable_id) Return sfRatable objects filtered by the ratable_id column
 * @method     array findByUserId(int $user_id) Return sfRatable objects filtered by the user_id column
 * @method     array findByRating(int $rating) Return sfRatable objects filtered by the rating column
 * @method     array findByCreatedAt(string $created_at) Return sfRatable objects filtered by the created_at column
 * @method     array findByUpdatedAt(string $updated_at) Return sfRatable objects filtered by the updated_at column
 *
 * @package    propel.generator.plugins.sfPropel15RatableBehaviorPlugin.lib.model.om
 */
abstract class BasesfRatableQuery extends ModelCriteria
{

	/**
	 * Initializes internal state of BasesfRatableQuery object.
	 *
	 * @param     string $dbName The dabase name
	 * @param     string $modelName The phpName of a model, e.g. 'Book'
	 * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
	 */
	public function __construct($dbName = 'propel', $modelName = 'sfRatable', $modelAlias = null)
	{
		parent::__construct($dbName, $modelName, $modelAlias);
	}

	/**
	 * Returns a new sfRatableQuery object.
	 *
	 * @param     string $modelAlias The alias of a model in the query
	 * @param     Criteria $criteria Optional Criteria to build the query from
	 *
	 * @return    sfRatableQuery
	 */
	public static function create($modelAlias = null, $criteria = null)
	{
		if ($criteria instanceof sfRatableQuery) {
			return $criteria;
		}
		$query = new sfRatableQuery();
		if (null !== $modelAlias) {
			$query->setModelAlias($modelAlias);
		}
		if ($criteria instanceof Criteria) {
			$query->mergeWith($criteria);
		}
		return $query;
	}

	/**
	 * Find object by primary key
	 * Use instance pooling to avoid a database query if the object exists
	 * <code>
	 * $obj  = $c->findPk(12, $con);
	 * </code>
	 * @param     mixed $key Primary key to use for the query
	 * @param     PropelPDO $con an optional connection object
	 *
	 * @return    sfRatable|array|mixed the result, formatted by the current formatter
	 */
	public function findPk($key, $con = null)
	{
		if ((null !== ($obj = sfRatablePeer::getInstanceFromPool((string) $key))) && $this->getFormatter()->isObjectFormatter()) {
			// the object is alredy in the instance pool
			return $obj;
		} else {
			// the object has not been requested yet, or the formatter is not an object formatter
			$criteria = $this->isKeepQuery() ? clone $this : $this;
			$stmt = $criteria
				->filterByPrimaryKey($key)
				->getSelectStatement($con);
			return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
		}
	}

	/**
	 * Find objects by primary key
	 * <code>
	 * $objs = $c->findPks(array(12, 56, 832), $con);
	 * </code>
	 * @param     array $keys Primary keys to use for the query
	 * @param     PropelPDO $con an optional connection object
	 *
	 * @return    PropelObjectCollection|array|mixed the list of results, formatted by the current formatter
	 */
	public function findPks($keys, $con = null)
	{	
		$criteria = $this->isKeepQuery() ? clone $this : $this;
		return $this
			->filterByPrimaryKeys($keys)
			->find($con);
	}

	/**
	 * Filter the query by primary key
	 *
	 * @param     mixed $key Primary key to use for the query
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByPrimaryKey($key)
	{
		return $this->addUsingAlias(sfRatablePeer::ID, $key, Criteria::EQUAL);
	}

	/**
	 * Filter the query by a list of primary keys
	 *
	 * @param     array $keys The list of primary key to use for the query
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByPrimaryKeys($keys)
	{
		return $this->addUsingAlias(sfRatablePeer::ID, $keys, Criteria::IN);
	}

	/**
	 * Filter the query on the id column
	 * 
	 * @param     int|array $id The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterById($id = null, $comparison = null)
	{
		if (is_array($id) && null === $comparison) {
			$comparison = Criteria::IN;
		}
		return $this->addUsingAlias(sfRatablePeer::ID, $id, $comparison);
	}

	/**
	 * Filter the query on the ratable_model column
	 * 
	 * @param     string $ratableModel The value to use as filter.
	 *            Accepts wildcards (* and % trigger a LIKE)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByRatableModel($ratableModel = null, $comparison = null)
	{
		if (null === $comparison) {
			if (is_array($ratableModel)) {
				$comparison = Criteria::IN;
			} elseif (preg_match('/[\%\*]/', $ratableModel)) {
				$ratableModel = str_replace('*', '%', $ratableModel);
				$comparison = Criteria::LIKE;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::RATABLE_MODEL, $ratableModel, $comparison);
	}

	/**
	 * Filter the query on the ratable_id column
	 * 
	 * @param     int|array $ratableId The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByRatableId($ratableId = null, $comparison = null)
	{
		if (is_array($ratableId)) {
			$useMinMax = false;
			if (isset($ratableId['min'])) {
				$this->addUsingAlias(sfRatablePeer::RATABLE_ID, $ratableId['min'], Criteria::GREATER_EQUAL);
				$useMinMax = true;
			}
			if (isset($ratableId['max'])) {
				$this->addUsingAlias(sfRatablePeer::RATABLE_ID, $ratableId['max'], Criteria::LESS_EQUAL);
				$useMinMax = true;
			}
			if ($useMinMax) {
				return $this;
			}
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::RATABLE_ID, $ratableId, $comparison);
	}

	/**
	 * Filter the query on the user_id column
	 * 
	 * @param     int|array $userId The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByUserId($userId = null, $comparison = null)
	{
		if (is_array($userId)) {
			$useMinMax = false;
			if (isset($userId['min'])) {
				$this->addUsingAlias(sfRatablePeer::USER_ID, $userId['min'], Criteria::GREATER_EQUAL);
				$useMinMax = true;
			}
			if (isset($userId['max'])) {
				$this->addUsingAlias(sfRatablePeer::USER_ID, $userId['max'], Criteria::LESS_EQUAL);
				$useMinMax = true;
			}
			if ($useMinMax) {
				return $this;
			}
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::USER_ID, $userId, $comparison);
	}

	/**
	 * Filter the query on the rating column
	 * 
	 * @param     int|array $rating The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByRating($rating = null, $comparison = null)
	{
		if (is_array($rating)) {
			$useMinMax = false;
			if (isset($rating['min'])) {
				$this->addUsingAlias(sfRatablePeer::RATING, $rating['min'], Criteria::GREATER_EQUAL);
				$useMinMax = true;
			}
			if (isset($rating['max'])) {
				$this->addUsingAlias(sfRatablePeer::RATING, $rating['max'], Criteria::LESS_EQUAL);
				$useMinMax = true;
			}
			if ($useMinMax) {
				return $this;
			}
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::RATING, $rating, $comparison);
	}

	/**
	 * Filter the query on the created_at column
	 * 
	 * @param     string|array $createdAt The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByCreatedAt($createdAt = null, $comparison = null)
	{
		if (is_array($createdAt)) {
			$useMinMax = false;
			if (isset($createdAt['min'])) {
				$this->addUsingAlias(sfRatablePeer::CREATED_AT, $createdAt['min'], Criteria::GREATER_EQUAL);
				$useMinMax = true;
			}
			if (isset($createdAt['max'])) {
				$this->addUsingAlias(sfRatablePeer::CREATED_AT, $createdAt['max'], Criteria::LESS_EQUAL);
				$useMinMax = true;
			}
			if ($useMinMax) {
				return $this;
			}
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::CREATED_AT, $createdAt, $comparison);
	}

	/**
	 * Filter the query on the updated_at column
	 * 
	 * @param     string|array $updatedAt The value to use as filter.
	 *            Accepts an associative array('min' => $minValue, 'max' => $maxValue)
	 * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function filterByUpdatedAt($updatedAt = null, $comparison = null)
	{
		if (is_array($updatedAt)) {
			$useMinMax = false;
			if (isset($updatedAt['min'])) {
				$this->addUsingAlias(sfRatablePeer::UPDATED_AT, $updatedAt['min'], Criteria::GREATER_EQUAL);
				$useMinMax = true;
			}
			if (isset($updatedAt['max'])) {
				$this->addUsingAlias(sfRatablePeer::UPDATED_AT, $updatedAt['max'], Criteria::LESS_EQUAL);
				$useMinMax = true;
			}
			if ($useMinMax) {
				return $this;
			}
			if (null === $comparison) {
				$comparison = Criteria::IN;
			}
		}
		return $this->addUsingAlias(sfRatablePeer::UPDATED_AT, $updatedAt, $comparison);
	}

	/**
	 * Exclude object from result
	 *
	 * @param     sfRatable $sfRatable Object to remove from the list of results
	 *
	 * @return    sfRatableQuery The current query, for fluid interface
	 */
	public function prune($sfRatable = null)
	{
		if ($sfRatable) {
			$this->addUsingAlias(sfRatablePeer::ID, $sfRatable->getId(), Criteria::NOT_EQUAL);
	  }
	  
		return $this;
	}

	// timestampable behavior
	
	/**
	 * Filter by the latest updated
	 *
	 * @param      int $nbDays Maximum age of the latest update in days
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function recentlyUpdated($nbDays = 7)
	{
		return $this->addUsingAlias(sfRatablePeer::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
	}
	
	/**
	 * Filter by the latest created
	 *
	 * @param      int $nbDays Maximum age of in days
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function recentlyCreated($nbDays = 7)
	{
		return $this->addUsingAlias(sfRatablePeer::CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
	}
	
	/**
	 * Order by update date desc
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function lastUpdatedFirst()
	{
		return $this->addDescendingOrderByColumn(sfRatablePeer::UPDATED_AT);
	}
	
	/**
	 * Order by update date asc
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function firstUpdatedFirst()
	{
		return $this->addAscendingOrderByColumn(sfRatablePeer::UPDATED_AT);
	}
	
	/**
	 * Order by create date desc
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function lastCreatedFirst()
	{
		return $this->addDescendingOrderByColumn(sfRatablePeer::CREATED_AT);
	}
	
	/**
	 * Order by create date asc
	 *
	 * @return     sfRatableQuery The current query, for fuid interface
	 */
	public function firstCreatedFirst()
	{
		return $this->addAscendingOrderByColumn(sfRatablePeer::CREATED_AT);
	}

} // BasesfRatableQuery