Criteria.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * This is a utility class for holding criteria information for a query.
  11. *
  12. * BasePeer constructs SQL statements based on the values in this class.
  13. *
  14. * @author Hans Lellelid <hans@xmpl.org> (Propel)
  15. * @author Kaspars Jaudzems <kaspars.jaudzems@inbox.lv> (Propel)
  16. * @author Frank Y. Kim <frank.kim@clearink.com> (Torque)
  17. * @author John D. McNally <jmcnally@collab.net> (Torque)
  18. * @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
  19. * @author Eric Dobbs <eric@dobbse.net> (Torque)
  20. * @author Henning P. Schmiedehausen <hps@intermeta.de> (Torque)
  21. * @author Sam Joseph <sam@neurogrid.com> (Torque)
  22. * @version $Revision: 1765 $
  23. * @package propel.runtime.query
  24. */
  25. class Criteria implements IteratorAggregate
  26. {
  27. /** Comparison type. */
  28. const EQUAL = "=";
  29. /** Comparison type. */
  30. const NOT_EQUAL = "<>";
  31. /** Comparison type. */
  32. const ALT_NOT_EQUAL = "!=";
  33. /** Comparison type. */
  34. const GREATER_THAN = ">";
  35. /** Comparison type. */
  36. const LESS_THAN = "<";
  37. /** Comparison type. */
  38. const GREATER_EQUAL = ">=";
  39. /** Comparison type. */
  40. const LESS_EQUAL = "<=";
  41. /** Comparison type. */
  42. const LIKE = " LIKE ";
  43. /** Comparison type. */
  44. const NOT_LIKE = " NOT LIKE ";
  45. /** PostgreSQL comparison type */
  46. const ILIKE = " ILIKE ";
  47. /** PostgreSQL comparison type */
  48. const NOT_ILIKE = " NOT ILIKE ";
  49. /** Comparison type. */
  50. const CUSTOM = "CUSTOM";
  51. /** Comparison type for update */
  52. const CUSTOM_EQUAL = "CUSTOM_EQUAL";
  53. /** Comparison type. */
  54. const DISTINCT = "DISTINCT";
  55. /** Comparison type. */
  56. const IN = " IN ";
  57. /** Comparison type. */
  58. const NOT_IN = " NOT IN ";
  59. /** Comparison type. */
  60. const ALL = "ALL";
  61. /** Comparison type. */
  62. const JOIN = "JOIN";
  63. /** Binary math operator: AND */
  64. const BINARY_AND = "&";
  65. /** Binary math operator: OR */
  66. const BINARY_OR = "|";
  67. /** "Order by" qualifier - ascending */
  68. const ASC = "ASC";
  69. /** "Order by" qualifier - descending */
  70. const DESC = "DESC";
  71. /** "IS NULL" null comparison */
  72. const ISNULL = " IS NULL ";
  73. /** "IS NOT NULL" null comparison */
  74. const ISNOTNULL = " IS NOT NULL ";
  75. /** "CURRENT_DATE" ANSI SQL function */
  76. const CURRENT_DATE = "CURRENT_DATE";
  77. /** "CURRENT_TIME" ANSI SQL function */
  78. const CURRENT_TIME = "CURRENT_TIME";
  79. /** "CURRENT_TIMESTAMP" ANSI SQL function */
  80. const CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
  81. /** "LEFT JOIN" SQL statement */
  82. const LEFT_JOIN = "LEFT JOIN";
  83. /** "RIGHT JOIN" SQL statement */
  84. const RIGHT_JOIN = "RIGHT JOIN";
  85. /** "INNER JOIN" SQL statement */
  86. const INNER_JOIN = "INNER JOIN";
  87. /** logical OR operator */
  88. const LOGICAL_OR = "OR";
  89. /** logical AND operator */
  90. const LOGICAL_AND = "AND";
  91. protected $ignoreCase = false;
  92. protected $singleRecord = false;
  93. /**
  94. * Storage of select data. Collection of column names.
  95. * @var array
  96. */
  97. protected $selectColumns = array();
  98. /**
  99. * Storage of aliased select data. Collection of column names.
  100. * @var array
  101. */
  102. protected $asColumns = array();
  103. /**
  104. * Storage of select modifiers data. Collection of modifier names.
  105. * @var array
  106. */
  107. protected $selectModifiers = array();
  108. /**
  109. * Storage of conditions data. Collection of Criterion objects.
  110. * @var array
  111. */
  112. protected $map = array();
  113. /**
  114. * Storage of ordering data. Collection of column names.
  115. * @var array
  116. */
  117. protected $orderByColumns = array();
  118. /**
  119. * Storage of grouping data. Collection of column names.
  120. * @var array
  121. */
  122. protected $groupByColumns = array();
  123. /**
  124. * Storage of having data.
  125. * @var Criterion
  126. */
  127. protected $having = null;
  128. /**
  129. * Storage of join data. colleciton of Join objects.
  130. * @var array
  131. */
  132. protected $joins = array();
  133. /**
  134. * The name of the database.
  135. * @var string
  136. */
  137. protected $dbName;
  138. /**
  139. * The primary table for this Criteria.
  140. * Useful in cases where there are no select or where
  141. * columns.
  142. * @var string
  143. */
  144. protected $primaryTableName;
  145. /** The name of the database as given in the contructor. */
  146. protected $originalDbName;
  147. /**
  148. * To limit the number of rows to return. <code>0</code> means return all
  149. * rows.
  150. */
  151. protected $limit = 0;
  152. /** To start the results at a row other than the first one. */
  153. protected $offset = 0;
  154. /**
  155. * Comment to add to the SQL query
  156. * @var string
  157. */
  158. protected $queryComment;
  159. // flag to note that the criteria involves a blob.
  160. protected $blobFlag = null;
  161. protected $aliases = array();
  162. protected $useTransaction = false;
  163. /**
  164. * Storage for Criterions expected to be combined
  165. * @var array
  166. */
  167. protected $namedCriterions = array();
  168. /**
  169. * Creates a new instance with the default capacity which corresponds to
  170. * the specified database.
  171. *
  172. * @param dbName The dabase name.
  173. */
  174. public function __construct($dbName = null)
  175. {
  176. $this->setDbName($dbName);
  177. $this->originalDbName = $dbName;
  178. }
  179. /**
  180. * Implementing SPL IteratorAggregate interface. This allows
  181. * you to foreach () over a Criteria object.
  182. */
  183. public function getIterator()
  184. {
  185. return new CriterionIterator($this);
  186. }
  187. /**
  188. * Get the criteria map, i.e. the array of Criterions
  189. * @return array
  190. */
  191. public function getMap()
  192. {
  193. return $this->map;
  194. }
  195. /**
  196. * Brings this criteria back to its initial state, so that it
  197. * can be reused as if it was new. Except if the criteria has grown in
  198. * capacity, it is left at the current capacity.
  199. * @return void
  200. */
  201. public function clear()
  202. {
  203. $this->map = array();
  204. $this->namedCriterions = array();
  205. $this->ignoreCase = false;
  206. $this->singleRecord = false;
  207. $this->selectModifiers = array();
  208. $this->selectColumns = array();
  209. $this->orderByColumns = array();
  210. $this->groupByColumns = array();
  211. $this->having = null;
  212. $this->asColumns = array();
  213. $this->joins = array();
  214. $this->dbName = $this->originalDbName;
  215. $this->offset = 0;
  216. $this->limit = -1;
  217. $this->blobFlag = null;
  218. $this->aliases = array();
  219. $this->useTransaction = false;
  220. }
  221. /**
  222. * Add an AS clause to the select columns. Usage:
  223. *
  224. * <code>
  225. * Criteria myCrit = new Criteria();
  226. * myCrit->addAsColumn("alias", "ALIAS(".MyPeer::ID.")");
  227. * </code>
  228. *
  229. * @param string $name Wanted Name of the column (alias).
  230. * @param string $clause SQL clause to select from the table
  231. *
  232. * If the name already exists, it is replaced by the new clause.
  233. *
  234. * @return Criteria A modified Criteria object.
  235. */
  236. public function addAsColumn($name, $clause)
  237. {
  238. $this->asColumns[$name] = $clause;
  239. return $this;
  240. }
  241. /**
  242. * Get the column aliases.
  243. *
  244. * @return array An assoc array which map the column alias names
  245. * to the alias clauses.
  246. */
  247. public function getAsColumns()
  248. {
  249. return $this->asColumns;
  250. }
  251. /**
  252. * Returns the column name associated with an alias (AS-column).
  253. *
  254. * @param string $alias
  255. * @return string $string
  256. */
  257. public function getColumnForAs($as)
  258. {
  259. if (isset($this->asColumns[$as])) {
  260. return $this->asColumns[$as];
  261. }
  262. }
  263. /**
  264. * Allows one to specify an alias for a table that can
  265. * be used in various parts of the SQL.
  266. *
  267. * @param string $alias
  268. * @param string $table
  269. *
  270. * @return Criteria A modified Criteria object.
  271. */
  272. public function addAlias($alias, $table)
  273. {
  274. $this->aliases[$alias] = $table;
  275. return $this;
  276. }
  277. /**
  278. * Remove an alias for a table (useful when merging Criterias).
  279. *
  280. * @param string $alias
  281. *
  282. * @return Criteria A modified Criteria object.
  283. */
  284. public function removeAlias($alias)
  285. {
  286. unset($this->aliases[$alias]);
  287. return $this;
  288. }
  289. /**
  290. * Returns the aliases for this Criteria
  291. *
  292. * @return array
  293. */
  294. public function getAliases()
  295. {
  296. return $this->aliases;
  297. }
  298. /**
  299. * Returns the table name associated with an alias.
  300. *
  301. * @param string $alias
  302. * @return string $string
  303. */
  304. public function getTableForAlias($alias)
  305. {
  306. if (isset($this->aliases[$alias])) {
  307. return $this->aliases[$alias];
  308. }
  309. }
  310. /**
  311. * Get the keys of the criteria map, i.e. the list of columns bearing a condition
  312. * <code>
  313. * print_r($c->keys());
  314. * => array('book.price', 'book.title', 'author.first_name')
  315. * </code>
  316. *
  317. * @return array
  318. */
  319. public function keys()
  320. {
  321. return array_keys($this->map);
  322. }
  323. /**
  324. * Does this Criteria object contain the specified key?
  325. *
  326. * @param string $column [table.]column
  327. * @return boolean True if this Criteria object contain the specified key.
  328. */
  329. public function containsKey($column)
  330. {
  331. // must use array_key_exists() because the key could
  332. // exist but have a NULL value (that'd be valid).
  333. return array_key_exists($column, $this->map);
  334. }
  335. /**
  336. * Does this Criteria object contain the specified key and does it have a value set for the key
  337. *
  338. * @param string $column [table.]column
  339. * @return boolean True if this Criteria object contain the specified key and a value for that key
  340. */
  341. public function keyContainsValue($column)
  342. {
  343. // must use array_key_exists() because the key could
  344. // exist but have a NULL value (that'd be valid).
  345. return (array_key_exists($column, $this->map) && ($this->map[$column]->getValue() !== null) );
  346. }
  347. /**
  348. * Whether this Criteria has any where columns.
  349. *
  350. * This counts conditions added with the add() method.
  351. *
  352. * @return boolean
  353. * @see add()
  354. */
  355. public function hasWhereClause()
  356. {
  357. return !empty($this->map);
  358. }
  359. /**
  360. * Will force the sql represented by this criteria to be executed within
  361. * a transaction. This is here primarily to support the oid type in
  362. * postgresql. Though it can be used to require any single sql statement
  363. * to use a transaction.
  364. * @return void
  365. */
  366. public function setUseTransaction($v)
  367. {
  368. $this->useTransaction = (boolean) $v;
  369. }
  370. /**
  371. * Whether the sql command specified by this criteria must be wrapped
  372. * in a transaction.
  373. *
  374. * @return boolean
  375. */
  376. public function isUseTransaction()
  377. {
  378. return $this->useTransaction;
  379. }
  380. /**
  381. * Method to return criteria related to columns in a table.
  382. *
  383. * Make sure you call containsKey($column) prior to calling this method,
  384. * since no check on the existence of the $column is made in this method.
  385. *
  386. * @param string $column Column name.
  387. * @return Criterion A Criterion object.
  388. */
  389. public function getCriterion($column)
  390. {
  391. return $this->map[$column];
  392. }
  393. /**
  394. * Method to return the latest Criterion in a table.
  395. *
  396. * @return Criterion A Criterion or null no Criterion is added.
  397. */
  398. public function getLastCriterion()
  399. {
  400. if($cnt = count($this->map)) {
  401. $map = array_values($this->map);
  402. return $map[$cnt - 1];
  403. }
  404. return null;
  405. }
  406. /**
  407. * Method to return criterion that is not added automatically
  408. * to this Criteria. This can be used to chain the
  409. * Criterions to form a more complex where clause.
  410. *
  411. * @param string $column Full name of column (for example TABLE.COLUMN).
  412. * @param mixed $value
  413. * @param string $comparison
  414. * @return Criterion
  415. */
  416. public function getNewCriterion($column, $value = null, $comparison = self::EQUAL)
  417. {
  418. return new Criterion($this, $column, $value, $comparison);
  419. }
  420. /**
  421. * Method to return a String table name.
  422. *
  423. * @param string $name Name of the key.
  424. * @return string The value of the object at key.
  425. */
  426. public function getColumnName($name)
  427. {
  428. if (isset($this->map[$name])) {
  429. return $this->map[$name]->getColumn();
  430. }
  431. return null;
  432. }
  433. /**
  434. * Shortcut method to get an array of columns indexed by table.
  435. * <code>
  436. * print_r($c->getTablesColumns());
  437. * => array(
  438. * 'book' => array('book.price', 'book.title'),
  439. * 'author' => array('author.first_name')
  440. * )
  441. * </code>
  442. *
  443. * @return array array(table => array(table.column1, table.column2))
  444. */
  445. public function getTablesColumns()
  446. {
  447. $tables = array();
  448. foreach ($this->keys() as $key) {
  449. $tableName = substr($key, 0, strrpos($key, '.' ));
  450. $tables[$tableName][] = $key;
  451. }
  452. return $tables;
  453. }
  454. /**
  455. * Method to return a comparison String.
  456. *
  457. * @param string $key String name of the key.
  458. * @return string A String with the value of the object at key.
  459. */
  460. public function getComparison($key)
  461. {
  462. if ( isset ( $this->map[$key] ) ) {
  463. return $this->map[$key]->getComparison();
  464. }
  465. return null;
  466. }
  467. /**
  468. * Get the Database(Map) name.
  469. *
  470. * @return string A String with the Database(Map) name.
  471. */
  472. public function getDbName()
  473. {
  474. return $this->dbName;
  475. }
  476. /**
  477. * Set the DatabaseMap name. If <code>null</code> is supplied, uses value
  478. * provided by <code>Propel::getDefaultDB()</code>.
  479. *
  480. * @param string $dbName The Database (Map) name.
  481. * @return void
  482. */
  483. public function setDbName($dbName = null)
  484. {
  485. $this->dbName = ($dbName === null ? Propel::getDefaultDB() : $dbName);
  486. }
  487. /**
  488. * Get the primary table for this Criteria.
  489. *
  490. * This is useful for cases where a Criteria may not contain
  491. * any SELECT columns or WHERE columns. This must be explicitly
  492. * set, of course, in order to be useful.
  493. *
  494. * @return string
  495. */
  496. public function getPrimaryTableName()
  497. {
  498. return $this->primaryTableName;
  499. }
  500. /**
  501. * Sets the primary table for this Criteria.
  502. *
  503. * This is useful for cases where a Criteria may not contain
  504. * any SELECT columns or WHERE columns. This must be explicitly
  505. * set, of course, in order to be useful.
  506. *
  507. * @param string $v
  508. */
  509. public function setPrimaryTableName($tableName)
  510. {
  511. $this->primaryTableName = $tableName;
  512. }
  513. /**
  514. * Method to return a String table name.
  515. *
  516. * @param string $name The name of the key.
  517. * @return string The value of table for criterion at key.
  518. */
  519. public function getTableName($name)
  520. {
  521. if (isset($this->map[$name])) {
  522. return $this->map[$name]->getTable();
  523. }
  524. return null;
  525. }
  526. /**
  527. * Method to return the value that was added to Criteria.
  528. *
  529. * @param string $name A String with the name of the key.
  530. * @return mixed The value of object at key.
  531. */
  532. public function getValue($name)
  533. {
  534. if (isset($this->map[$name])) {
  535. return $this->map[$name]->getValue();
  536. }
  537. return null;
  538. }
  539. /**
  540. * An alias to getValue() -- exposing a Hashtable-like interface.
  541. *
  542. * @param string $key An Object.
  543. * @return mixed The value within the Criterion (not the Criterion object).
  544. */
  545. public function get($key)
  546. {
  547. return $this->getValue($key);
  548. }
  549. /**
  550. * Overrides Hashtable put, so that this object is returned
  551. * instead of the value previously in the Criteria object.
  552. * The reason is so that it more closely matches the behavior
  553. * of the add() methods. If you want to get the previous value
  554. * then you should first Criteria.get() it yourself. Note, if
  555. * you attempt to pass in an Object that is not a String, it will
  556. * throw a NPE. The reason for this is that none of the add()
  557. * methods support adding anything other than a String as a key.
  558. *
  559. * @param string $key
  560. * @param mixed $value
  561. * @return Instance of self.
  562. */
  563. public function put($key, $value)
  564. {
  565. return $this->add($key, $value);
  566. }
  567. /**
  568. * Copies all of the mappings from the specified Map to this Criteria
  569. * These mappings will replace any mappings that this Criteria had for any
  570. * of the keys currently in the specified Map.
  571. *
  572. * if the map was another Criteria, its attributes are copied to this
  573. * Criteria, overwriting previous settings.
  574. *
  575. * @param mixed $t Mappings to be stored in this map.
  576. */
  577. public function putAll($t)
  578. {
  579. if (is_array($t)) {
  580. foreach ($t as $key=>$value) {
  581. if ($value instanceof Criterion) {
  582. $this->map[$key] = $value;
  583. } else {
  584. $this->put($key, $value);
  585. }
  586. }
  587. } elseif ($t instanceof Criteria) {
  588. $this->joins = $t->joins;
  589. }
  590. }
  591. /**
  592. * This method adds a new criterion to the list of criterias.
  593. * If a criterion for the requested column already exists, it is
  594. * replaced. If is used as follow:
  595. *
  596. * <code>
  597. * $crit = new Criteria();
  598. * $crit->add($column, $value, Criteria::GREATER_THAN);
  599. * </code>
  600. *
  601. * Any comparison can be used.
  602. *
  603. * The name of the table must be used implicitly in the column name,
  604. * so the Column name must be something like 'TABLE.id'.
  605. *
  606. * @param string $critOrColumn The column to run the comparison on, or Criterion object.
  607. * @param mixed $value
  608. * @param string $comparison A String.
  609. *
  610. * @return A modified Criteria object.
  611. */
  612. public function add($p1, $value = null, $comparison = null)
  613. {
  614. if ($p1 instanceof Criterion) {
  615. $this->map[$p1->getTable() . '.' . $p1->getColumn()] = $p1;
  616. } else {
  617. $criterion = new Criterion($this, $p1, $value, $comparison);
  618. $this->map[$p1] = $criterion;
  619. }
  620. return $this;
  621. }
  622. /**
  623. * This method creates a new criterion but keeps it for later use with combine()
  624. * Until combine() is called, the condition is not added to the query
  625. *
  626. * <code>
  627. * $crit = new Criteria();
  628. * $crit->addCond('cond1', $column1, $value1, Criteria::GREATER_THAN);
  629. * $crit->addCond('cond2', $column2, $value2, Criteria::EQUAL);
  630. * $crit->combine(array('cond1', 'cond2'), Criteria::LOGICAL_OR);
  631. * </code>
  632. *
  633. * Any comparison can be used.
  634. *
  635. * The name of the table must be used implicitly in the column name,
  636. * so the Column name must be something like 'TABLE.id'.
  637. *
  638. * @param string $name name to combine the criterion later
  639. * @param string $p1 The column to run the comparison on, or Criterion object.
  640. * @param mixed $value
  641. * @param string $comparison A String.
  642. *
  643. * @return A modified Criteria object.
  644. */
  645. public function addCond($name, $p1, $value = null, $comparison = null)
  646. {
  647. if ($p1 instanceof Criterion) {
  648. $this->namedCriterions[$name] = $p1;
  649. } else {
  650. $criterion = new Criterion($this, $p1, $value, $comparison);
  651. $this->namedCriterions[$name] = $criterion;
  652. }
  653. return $this;
  654. }
  655. /**
  656. * Combine several named criterions with a logical operator
  657. *
  658. * @param array $criterions array of the name of the criterions to combine
  659. * @param string $operator logical operator, either Criteria::LOGICAL_AND, or Criteria::LOGICAL_OR
  660. * @param string $name optional name to combine the criterion later
  661. */
  662. public function combine($criterions = array(), $operator = self::LOGICAL_AND, $name = null)
  663. {
  664. $operatorMethod = (strtoupper($operator) == self::LOGICAL_AND) ? 'addAnd' : 'addOr';
  665. $namedCriterions = array();
  666. foreach ($criterions as $key) {
  667. if (array_key_exists($key, $this->namedCriterions)) {
  668. $namedCriterions[]= $this->namedCriterions[$key];
  669. unset($this->namedCriterions[$key]);
  670. } else {
  671. throw new PropelException('Cannot combine unknown condition ' . $key);
  672. }
  673. }
  674. $firstCriterion = array_shift($namedCriterions);
  675. foreach ($namedCriterions as $criterion) {
  676. $firstCriterion->$operatorMethod($criterion);
  677. }
  678. if ($name === null) {
  679. $this->add($firstCriterion, null, null);
  680. } else {
  681. $this->addCond($name, $firstCriterion, null, null);
  682. }
  683. return $this;
  684. }
  685. /**
  686. * This is the way that you should add a join of two tables.
  687. * Example usage:
  688. * <code>
  689. * $c->addJoin(ProjectPeer::ID, FooPeer::PROJECT_ID, Criteria::LEFT_JOIN);
  690. * // LEFT JOIN FOO ON PROJECT.ID = FOO.PROJECT_ID
  691. * </code>
  692. *
  693. * @param mixed $left A String with the left side of the join.
  694. * @param mixed $right A String with the right side of the join.
  695. * @param mixed $operator A String with the join operator
  696. * among Criteria::INNER_JOIN, Criteria::LEFT_JOIN,
  697. * and Criteria::RIGHT_JOIN
  698. *
  699. * @return Criteria A modified Criteria object.
  700. */
  701. public function addJoin($left, $right, $operator = null)
  702. {
  703. $join = new Join();
  704. if (!is_array($left)) {
  705. // simple join
  706. $join->addCondition($left, $right);
  707. } else {
  708. // join with multiple conditions
  709. // deprecated: use addMultipleJoin() instead
  710. foreach ($left as $key => $value)
  711. {
  712. $join->addCondition($value, $right[$key]);
  713. }
  714. }
  715. $join->setJoinType($operator);
  716. return $this->addJoinObject($join);
  717. }
  718. /**
  719. * Add a join with multiple conditions
  720. * @see http://propel.phpdb.org/trac/ticket/167, http://propel.phpdb.org/trac/ticket/606
  721. *
  722. * Example usage:
  723. * $c->addMultipleJoin(array(
  724. * array(LeftPeer::LEFT_COLUMN, RightPeer::RIGHT_COLUMN), // if no third argument, defaults to Criteria::EQUAL
  725. * array(FoldersPeer::alias( 'fo', FoldersPeer::LFT ), FoldersPeer::alias( 'parent', FoldersPeer::RGT ), Criteria::LESS_EQUAL )
  726. * ),
  727. * Criteria::LEFT_JOIN
  728. * );
  729. *
  730. * @see addJoin()
  731. * @param array $conditions An array of conditions, each condition being an array (left, right, operator)
  732. * @param string $joinType A String with the join operator. Defaults to an implicit join.
  733. *
  734. * @return Criteria A modified Criteria object.
  735. */
  736. public function addMultipleJoin($conditions, $joinType = null)
  737. {
  738. $join = new Join();
  739. foreach ($conditions as $condition) {
  740. $join->addCondition($condition[0], $condition[1], isset($condition[2]) ? $condition[2] : Criteria::EQUAL);
  741. }
  742. $join->setJoinType($joinType);
  743. return $this->addJoinObject($join);
  744. }
  745. /**
  746. * Add a join object to the Criteria
  747. *
  748. * @param Join $join A join object
  749. *
  750. * @return Criteria A modified Criteria object
  751. */
  752. public function addJoinObject(Join $join)
  753. {
  754. if (!in_array($join, $this->joins)) { // compare equality, NOT identity
  755. $this->joins[] = $join;
  756. }
  757. return $this;
  758. }
  759. /**
  760. * Get the array of Joins.
  761. * @return array Join[]
  762. */
  763. public function getJoins()
  764. {
  765. return $this->joins;
  766. }
  767. /**
  768. * Adds "ALL" modifier to the SQL statement.
  769. * @return Criteria Modified Criteria object (for fluent API)
  770. */
  771. public function setAll()
  772. {
  773. $this->removeSelectModifier(self::DISTINCT);
  774. $this->addSelectModifier(self::ALL);
  775. return $this;
  776. }
  777. /**
  778. * Adds "DISTINCT" modifier to the SQL statement.
  779. * @return Criteria Modified Criteria object (for fluent API)
  780. */
  781. public function setDistinct()
  782. {
  783. $this->removeSelectModifier(self::ALL);
  784. $this->addSelectModifier(self::DISTINCT);
  785. return $this;
  786. }
  787. /**
  788. * Adds a modifier to the SQL statement.
  789. * e.g. self::ALL, self::DISTINCT, 'SQL_CALC_FOUND_ROWS', 'HIGH_PRIORITY', etc.
  790. *
  791. * @param string $modifier The modifier to add
  792. *
  793. * @return Criteria Modified Criteria object (for fluent API)
  794. */
  795. public function addSelectModifier($modifier)
  796. {
  797. //only allow the keyword once
  798. if (!$this->hasSelectModifier($modifier)) {
  799. $this->selectModifiers[] = $modifier;
  800. }
  801. return $this;
  802. }
  803. /**
  804. * Removes a modifier to the SQL statement.
  805. * Checks for existence before removal
  806. *
  807. * @param string $modifier The modifier to add
  808. *
  809. * @return Criteria Modified Criteria object (for fluent API)
  810. */
  811. public function removeSelectModifier($modifier)
  812. {
  813. $this->selectModifiers = array_values(array_diff($this->selectModifiers, array($modifier)));
  814. return $this;
  815. }
  816. /**
  817. * Checks the existence of a SQL select modifier
  818. *
  819. * @param string $modifier The modifier to add
  820. *
  821. * @return bool
  822. */
  823. public function hasSelectModifier($modifier)
  824. {
  825. return in_array($modifier, $this->selectModifiers);
  826. }
  827. /**
  828. * Sets ignore case.
  829. *
  830. * @param boolean $b True if case should be ignored.
  831. * @return Criteria Modified Criteria object (for fluent API)
  832. */
  833. public function setIgnoreCase($b)
  834. {
  835. $this->ignoreCase = (boolean) $b;
  836. return $this;
  837. }
  838. /**
  839. * Is ignore case on or off?
  840. *
  841. * @return boolean True if case is ignored.
  842. */
  843. public function isIgnoreCase()
  844. {
  845. return $this->ignoreCase;
  846. }
  847. /**
  848. * Set single record? Set this to <code>true</code> if you expect the query
  849. * to result in only a single result record (the default behaviour is to
  850. * throw a PropelException if multiple records are returned when the query
  851. * is executed). This should be used in situations where returning multiple
  852. * rows would indicate an error of some sort. If your query might return
  853. * multiple records but you are only interested in the first one then you
  854. * should be using setLimit(1).
  855. *
  856. * @param boolean $b Set to TRUE if you expect the query to select just one record.
  857. * @return Criteria Modified Criteria object (for fluent API)
  858. */
  859. public function setSingleRecord($b)
  860. {
  861. $this->singleRecord = (boolean) $b;
  862. return $this;
  863. }
  864. /**
  865. * Is single record?
  866. *
  867. * @return boolean True if a single record is being returned.
  868. */
  869. public function isSingleRecord()
  870. {
  871. return $this->singleRecord;
  872. }
  873. /**
  874. * Set limit.
  875. *
  876. * @param limit An int with the value for limit.
  877. * @return Criteria Modified Criteria object (for fluent API)
  878. */
  879. public function setLimit($limit)
  880. {
  881. // TODO: do we enforce int here? 32bit issue if we do
  882. $this->limit = $limit;
  883. return $this;
  884. }
  885. /**
  886. * Get limit.
  887. *
  888. * @return int An int with the value for limit.
  889. */
  890. public function getLimit()
  891. {
  892. return $this->limit;
  893. }
  894. /**
  895. * Set offset.
  896. *
  897. * @param int $offset An int with the value for offset. (Note this values is
  898. * cast to a 32bit integer and may result in truncatation)
  899. * @return Criteria Modified Criteria object (for fluent API)
  900. */
  901. public function setOffset($offset)
  902. {
  903. $this->offset = (int) $offset;
  904. return $this;
  905. }
  906. /**
  907. * Get offset.
  908. *
  909. * @return An int with the value for offset.
  910. */
  911. public function getOffset()
  912. {
  913. return $this->offset;
  914. }
  915. /**
  916. * Add select column.
  917. *
  918. * @param string $name Name of the select column.
  919. * @return Criteria Modified Criteria object (for fluent API)
  920. */
  921. public function addSelectColumn($name)
  922. {
  923. $this->selectColumns[] = $name;
  924. return $this;
  925. }
  926. /**
  927. * Set the query comment, that appears after the first verb in the SQL query
  928. *
  929. * @param string $comment The comment to add to the query, without comment sign
  930. * @return Criteria Modified Criteria object (for fluent API)
  931. */
  932. public function setComment($comment = null)
  933. {
  934. $this->queryComment = $comment;
  935. return $this;
  936. }
  937. /**
  938. * Get the query comment, that appears after the first verb in the SQL query
  939. *
  940. * @return string The comment to add to the query, without comment sign
  941. */
  942. public function getComment()
  943. {
  944. return $this->queryComment;
  945. }
  946. /**
  947. * Whether this Criteria has any select columns.
  948. *
  949. * This will include columns added with addAsColumn() method.
  950. *
  951. * @return boolean
  952. * @see addAsColumn()
  953. * @see addSelectColumn()
  954. */
  955. public function hasSelectClause()
  956. {
  957. return (!empty($this->selectColumns) || !empty($this->asColumns));
  958. }
  959. /**
  960. * Get select columns.
  961. *
  962. * @return array An array with the name of the select columns.
  963. */
  964. public function getSelectColumns()
  965. {
  966. return $this->selectColumns;
  967. }
  968. /**
  969. * Clears current select columns.
  970. *
  971. * @return Criteria Modified Criteria object (for fluent API)
  972. */
  973. public function clearSelectColumns()
  974. {
  975. $this->selectColumns = $this->asColumns = array();
  976. return $this;
  977. }
  978. /**
  979. * Get select modifiers.
  980. *
  981. * @return An array with the select modifiers.
  982. */
  983. public function getSelectModifiers()
  984. {
  985. return $this->selectModifiers;
  986. }
  987. /**
  988. * Add group by column name.
  989. *
  990. * @param string $groupBy The name of the column to group by.
  991. * @return A modified Criteria object.
  992. */
  993. public function addGroupByColumn($groupBy)
  994. {
  995. $this->groupByColumns[] = $groupBy;
  996. return $this;
  997. }
  998. /**
  999. * Add order by column name, explicitly specifying ascending.
  1000. *
  1001. * @param name The name of the column to order by.
  1002. * @return A modified Criteria object.
  1003. */
  1004. public function addAscendingOrderByColumn($name)
  1005. {
  1006. $this->orderByColumns[] = $name . ' ' . self::ASC;
  1007. return $this;
  1008. }
  1009. /**
  1010. * Add order by column name, explicitly specifying descending.
  1011. *
  1012. * @param string $name The name of the column to order by.
  1013. * @return Criteria Modified Criteria object (for fluent API)
  1014. */
  1015. public function addDescendingOrderByColumn($name)
  1016. {
  1017. $this->orderByColumns[] = $name . ' ' . self::DESC;
  1018. return $this;
  1019. }
  1020. /**
  1021. * Get order by columns.
  1022. *
  1023. * @return array An array with the name of the order columns.
  1024. */
  1025. public function getOrderByColumns()
  1026. {
  1027. return $this->orderByColumns;
  1028. }
  1029. /**
  1030. * Clear the order-by columns.
  1031. *
  1032. * @return Criteria Modified Criteria object (for fluent API)
  1033. */
  1034. public function clearOrderByColumns()
  1035. {
  1036. $this->orderByColumns = array();
  1037. return $this;
  1038. }
  1039. /**
  1040. * Clear the group-by columns.
  1041. *
  1042. * @return Criteria
  1043. */
  1044. public function clearGroupByColumns()
  1045. {
  1046. $this->groupByColumns = array();
  1047. return $this;
  1048. }
  1049. /**
  1050. * Get group by columns.
  1051. *
  1052. * @return array
  1053. */
  1054. public function getGroupByColumns()
  1055. {
  1056. return $this->groupByColumns;
  1057. }
  1058. /**
  1059. * Get Having Criterion.
  1060. *
  1061. * @return Criterion A Criterion object that is the having clause.
  1062. */
  1063. public function getHaving()
  1064. {
  1065. return $this->having;
  1066. }
  1067. /**
  1068. * Remove an object from the criteria.
  1069. *
  1070. * @param string $key A string with the key to be removed.
  1071. * @return mixed The removed value.
  1072. */
  1073. public function remove($key)
  1074. {
  1075. if ( isset ( $this->map[$key] ) ) {
  1076. $removed = $this->map[$key];
  1077. unset ( $this->map[$key] );
  1078. if ( $removed instanceof Criterion ) {
  1079. return $removed->getValue();
  1080. }
  1081. return $removed;
  1082. }
  1083. }
  1084. /**
  1085. * Build a string representation of the Criteria.
  1086. *
  1087. * @return string A String with the representation of the Criteria.
  1088. */
  1089. public function toString()
  1090. {
  1091. $sb = "Criteria:";
  1092. try {
  1093. $params = array();
  1094. $sb .= "\nSQL (may not be complete): "
  1095. . BasePeer::createSelectSql($this, $params);
  1096. $sb .= "\nParams: ";
  1097. $paramstr = array();
  1098. foreach ($params as $param) {
  1099. $paramstr[] = $param['table'] . '.' . $param['column'] . ' => ' . var_export($param['value'], true);
  1100. }
  1101. $sb .= implode(", ", $paramstr);
  1102. } catch (Exception $exc) {
  1103. $sb .= "(Error: " . $exc->getMessage() . ")";
  1104. }
  1105. return $sb;
  1106. }
  1107. /**
  1108. * Returns the size (count) of this criteria.
  1109. * @return int
  1110. */
  1111. public function size()
  1112. {
  1113. return count($this->map);
  1114. }
  1115. /**
  1116. * This method checks another Criteria to see if they contain
  1117. * the same attributes and hashtable entries.
  1118. * @return boolean
  1119. */
  1120. public function equals($crit)
  1121. {
  1122. if ($crit === null || !($crit instanceof Criteria)) {
  1123. return false;
  1124. } elseif ($this === $crit) {
  1125. return true;
  1126. } elseif ($this->size() === $crit->size()) {
  1127. // Important: nested criterion objects are checked
  1128. $criteria = $crit; // alias
  1129. if ($this->offset === $criteria->getOffset()
  1130. && $this->limit === $criteria->getLimit()
  1131. && $this->ignoreCase === $criteria->isIgnoreCase()
  1132. && $this->singleRecord === $criteria->isSingleRecord()
  1133. && $this->dbName === $criteria->getDbName()
  1134. && $this->selectModifiers === $criteria->getSelectModifiers()
  1135. && $this->selectColumns === $criteria->getSelectColumns()
  1136. && $this->asColumns === $criteria->getAsColumns()
  1137. && $this->orderByColumns === $criteria->getOrderByColumns()
  1138. && $this->groupByColumns === $criteria->getGroupByColumns()
  1139. && $this->aliases === $criteria->getAliases()
  1140. ) // what about having ??
  1141. {
  1142. foreach ($criteria->keys() as $key) {
  1143. if ($this->containsKey($key)) {
  1144. $a = $this->getCriterion($key);
  1145. $b = $criteria->getCriterion($key);
  1146. if (!$a->equals($b)) {
  1147. return false;
  1148. }
  1149. } else {
  1150. return false;
  1151. }
  1152. }
  1153. $joins = $criteria->getJoins();
  1154. if (count($joins) != count($this->joins)) {
  1155. return false;
  1156. }
  1157. foreach ($joins as $key => $join) {
  1158. if (!$join->equals($this->joins[$key])) {
  1159. return false;
  1160. }
  1161. }
  1162. return true;
  1163. } else {
  1164. return false;
  1165. }
  1166. }
  1167. return false;
  1168. }
  1169. /**
  1170. * Add the content of a Criteria to the current Criteria
  1171. * In case of conflict, the current Criteria keeps its properties
  1172. *
  1173. * @param Criteria $criteria The criteria to read properties from
  1174. * @param string $operator The logical operator used to combine conditions
  1175. * Defaults to Criteria::LOGICAL_AND, also accapts Criteria::LOGICAL_OR
  1176. *
  1177. * @return Criteria The current criteria object
  1178. */
  1179. public function mergeWith(Criteria $criteria, $operator = Criteria::LOGICAL_AND)
  1180. {
  1181. // merge limit
  1182. $limit = $criteria->getLimit();
  1183. if($limit != 0 && $this->getLimit() == 0) {
  1184. $this->limit = $limit;
  1185. }
  1186. // merge offset
  1187. $offset = $criteria->getOffset();
  1188. if($offset != 0 && $this->getOffset() == 0) {
  1189. $this->offset = $offset;
  1190. }
  1191. // merge select modifiers
  1192. $selectModifiers = $criteria->getSelectModifiers();
  1193. if ($selectModifiers && ! $this->selectModifiers){
  1194. $this->selectModifiers = $selectModifiers;
  1195. }
  1196. // merge select columns
  1197. $this->selectColumns = array_merge($this->getSelectColumns(), $criteria->getSelectColumns());
  1198. // merge as columns
  1199. $commonAsColumns = array_intersect_key($this->getAsColumns(), $criteria->getAsColumns());
  1200. if (!empty($commonAsColumns)) {
  1201. throw new PropelException('The given criteria contains an AsColumn with an alias already existing in the current object');
  1202. }
  1203. $this->asColumns = array_merge($this->getAsColumns(), $criteria->getAsColumns());
  1204. // merge orderByColumns
  1205. $orderByColumns = array_merge($this->getOrderByColumns(), $criteria->getOrderByColumns());
  1206. $this->orderByColumns = array_unique($orderByColumns);
  1207. // merge groupByColumns
  1208. $groupByColumns = array_merge($this->getGroupByColumns(), $criteria->getGroupByColumns());
  1209. $this->groupByColumns = array_unique($groupByColumns);
  1210. // merge where conditions
  1211. if ($operator == Criteria::LOGICAL_AND) {
  1212. foreach ($criteria->getMap() as $key => $criterion) {
  1213. if ($this->containsKey($key)) {
  1214. $this->addAnd($criterion);
  1215. } else {
  1216. $this->add($criterion);
  1217. }
  1218. }
  1219. } else {
  1220. foreach ($criteria->getMap() as $key => $criterion) {
  1221. $this->addOr($criterion);
  1222. }
  1223. }
  1224. // merge having
  1225. if ($having = $criteria->getHaving()) {
  1226. if ($this->getHaving()) {
  1227. $this->addHaving($this->getHaving()->addAnd($having));
  1228. } else {
  1229. $this->addHaving($having);
  1230. }
  1231. }
  1232. // merge alias
  1233. $commonAliases = array_intersect_key($this->getAliases(), $criteria->getAliases());
  1234. if (!empty($commonAliases)) {
  1235. throw new PropelException('The given criteria contains an alias already existing in the current object');
  1236. }
  1237. $this->aliases = array_merge($this->getAliases(), $criteria->getAliases());
  1238. // merge join
  1239. $this->joins = array_merge($this->getJoins(), $criteria->getJoins());
  1240. return $this;
  1241. }
  1242. /**
  1243. * This method adds a prepared Criterion object to the Criteria as a having clause.
  1244. * You can get a new, empty Criterion object with the
  1245. * getNewCriterion() method.
  1246. *
  1247. * <p>
  1248. * <code>
  1249. * $crit = new Criteria();
  1250. * $c = $crit->getNewCriterion(BasePeer::ID, 5, Criteria::LESS_THAN);
  1251. * $crit->addHaving($c);
  1252. * </code>
  1253. *
  1254. * @param having A Criterion object
  1255. *
  1256. * @return A modified Criteria object.
  1257. */
  1258. public function addHaving(Criterion $having)
  1259. {
  1260. $this->having = $having;
  1261. return $this;
  1262. }
  1263. /**
  1264. * If a criterion for the requested column already exists, the condition is "AND"ed to the existing criterion (necessary for Propel 1.4 compatibility).
  1265. * If no criterion for the requested column already exists, the condition is "AND"ed to the latest criterion.
  1266. * If no criterion exist, the condition is added a new criterion
  1267. *
  1268. * Any comparison can be used.
  1269. *
  1270. * Supports a number of different signatures:
  1271. * - addAnd(column, value, comparison)
  1272. * - addAnd(column, value)
  1273. * - addAnd(Criterion)
  1274. *
  1275. * @return Criteria A modified Criteria object.
  1276. */
  1277. public function addAnd($p1, $p2 = null, $p3 = null, $preferColumnCondition = true)
  1278. {
  1279. $criterion = ($p1 instanceof Criterion) ? $p1 : new Criterion($this, $p1, $p2, $p3);
  1280. $key = $criterion->getTable() . '.' . $criterion->getColumn();
  1281. if ($preferColumnCondition && $this->containsKey($key)) {
  1282. // FIXME: addAnd() operates preferably on existing conditions on the same column
  1283. // this may cause unexpected results, but it's there for BC with Propel 14
  1284. $this->getCriterion($key)->addAnd($criterion);
  1285. } else {
  1286. // simply add the condition to the list - this is the expected behavior
  1287. $this->add($criterion);
  1288. }
  1289. return $this;
  1290. }
  1291. /**
  1292. * If a criterion for the requested column already exists, the condition is "OR"ed to the existing criterion (necessary for Propel 1.4 compatibility).
  1293. * If no criterion for the requested column already exists, the condition is "OR"ed to the latest criterion.
  1294. * If no criterion exist, the condition is added a new criterion
  1295. *
  1296. * Any comparison can be used.
  1297. *
  1298. * Supports a number of different signatures:
  1299. * - addOr(column, value, comparison)
  1300. * - addOr(column, value)
  1301. * - addOr(Criterion)
  1302. *
  1303. * @return Criteria A modified Criteria object.
  1304. */
  1305. public function addOr($p1, $p2 = null, $p3 = null, $preferColumnCondition = true)
  1306. {
  1307. $rightCriterion = ($p1 instanceof Criterion) ? $p1 : new Criterion($this, $p1, $p2, $p3);
  1308. $key = $rightCriterion->getTable() . '.' . $rightCriterion->getColumn();
  1309. if ($preferColumnCondition && $this->containsKey($key)) {
  1310. // FIXME: addOr() operates preferably on existing conditions on the same column
  1311. // this may cause unexpected results, but it's there for BC with Propel 14
  1312. $leftCriterion = $this->getCriterion($key);
  1313. } else {
  1314. // fallback to the latest condition - this is the expected behavior
  1315. $leftCriterion = $this->getLastCriterion();
  1316. }
  1317. if ($leftCriterion !== null) {
  1318. // combine the given criterion with the existing one with an 'OR'
  1319. $leftCriterion->addOr($rightCriterion);
  1320. } else {
  1321. // nothing to do OR / AND with, so make it first condition
  1322. $this->add($rightCriterion);
  1323. }
  1324. return $this;
  1325. }
  1326. // Fluid Conditions
  1327. /**
  1328. * Returns the current object if the condition is true,
  1329. * or a PropelConditionalProxy instance otherwise.
  1330. * Allows for conditional statements in a fluid interface.
  1331. *
  1332. * @param bool $cond
  1333. *
  1334. * @return PropelConditionalProxy|Criteria
  1335. */
  1336. public function _if($cond)
  1337. {
  1338. if($cond) {
  1339. return $this;
  1340. } else {
  1341. return new PropelConditionalProxy($this);
  1342. }
  1343. }
  1344. /**
  1345. * Returns a PropelConditionalProxy instance.
  1346. * Allows for conditional statements in a fluid interface.
  1347. *
  1348. * @param bool $cond ignored
  1349. *
  1350. * @return PropelConditionalProxy
  1351. */
  1352. public function _elseif($cond)
  1353. {
  1354. return new PropelConditionalProxy($this);
  1355. }
  1356. /**
  1357. * Returns a PropelConditionalProxy instance.
  1358. * Allows for conditional statements in a fluid interface.
  1359. *
  1360. * @return PropelConditionalProxy
  1361. */
  1362. public function _else()
  1363. {
  1364. return new PropelConditionalProxy($this);
  1365. }
  1366. /**
  1367. * Returns the current object
  1368. * Allows for conditional statements in a fluid interface.
  1369. *
  1370. * @return Criteria
  1371. */
  1372. public function _endif()
  1373. {
  1374. return $this;
  1375. }
  1376. /**
  1377. * Ensures deep cloning of attached objects
  1378. */
  1379. public function __clone()
  1380. {
  1381. foreach ($this->map as $key => $criterion) {
  1382. $this->map[$key] = clone $criterion;
  1383. }
  1384. foreach ($this->joins as $key => $join) {
  1385. $this->joins[$key] = clone $join;
  1386. }
  1387. if (null !== $this->having) {
  1388. $this->having = clone $this->having;
  1389. }
  1390. }
  1391. }