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