/usr/share/php/propel/query/Criteria.php is in php-propel-runtime 1.6.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 | <?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
/**
* This is a utility class for holding criteria information for a query.
*
* BasePeer constructs SQL statements based on the values in this class.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Kaspars Jaudzems <kaspars.jaudzems@inbox.lv> (Propel)
* @author Frank Y. Kim <frank.kim@clearink.com> (Torque)
* @author John D. McNally <jmcnally@collab.net> (Torque)
* @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
* @author Eric Dobbs <eric@dobbse.net> (Torque)
* @author Henning P. Schmiedehausen <hps@intermeta.de> (Torque)
* @author Sam Joseph <sam@neurogrid.com> (Torque)
* @version $Revision$
* @package propel.runtime.query
*/
class Criteria implements IteratorAggregate
{
/** Comparison type. */
const EQUAL = "=";
/** Comparison type. */
const NOT_EQUAL = "<>";
/** Comparison type. */
const ALT_NOT_EQUAL = "!=";
/** Comparison type. */
const GREATER_THAN = ">";
/** Comparison type. */
const LESS_THAN = "<";
/** Comparison type. */
const GREATER_EQUAL = ">=";
/** Comparison type. */
const LESS_EQUAL = "<=";
/** Comparison type. */
const LIKE = " LIKE ";
/** Comparison type. */
const NOT_LIKE = " NOT LIKE ";
/** Comparison for array column types */
const CONTAINS_ALL = "CONTAINS_ALL";
/** Comparison for array column types */
const CONTAINS_SOME = "CONTAINS_SOME";
/** Comparison for array column types */
const CONTAINS_NONE = "CONTAINS_NONE";
/** PostgreSQL comparison type */
const ILIKE = " ILIKE ";
/** PostgreSQL comparison type */
const NOT_ILIKE = " NOT ILIKE ";
/** Comparison type. */
const CUSTOM = "CUSTOM";
/** Comparison type */
const RAW = "RAW";
/** Comparison type for update */
const CUSTOM_EQUAL = "CUSTOM_EQUAL";
/** Comparison type. */
const DISTINCT = "DISTINCT";
/** Comparison type. */
const IN = " IN ";
/** Comparison type. */
const NOT_IN = " NOT IN ";
/** Comparison type. */
const ALL = "ALL";
/** Comparison type. */
const JOIN = "JOIN";
/** Binary math operator: AND */
const BINARY_AND = "&";
/** Binary math operator: OR */
const BINARY_OR = "|";
/** "Order by" qualifier - ascending */
const ASC = "ASC";
/** "Order by" qualifier - descending */
const DESC = "DESC";
/** "IS NULL" null comparison */
const ISNULL = " IS NULL ";
/** "IS NOT NULL" null comparison */
const ISNOTNULL = " IS NOT NULL ";
/** "CURRENT_DATE" ANSI SQL function */
const CURRENT_DATE = "CURRENT_DATE";
/** "CURRENT_TIME" ANSI SQL function */
const CURRENT_TIME = "CURRENT_TIME";
/** "CURRENT_TIMESTAMP" ANSI SQL function */
const CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
/** "LEFT JOIN" SQL statement */
const LEFT_JOIN = "LEFT JOIN";
/** "RIGHT JOIN" SQL statement */
const RIGHT_JOIN = "RIGHT JOIN";
/** "INNER JOIN" SQL statement */
const INNER_JOIN = "INNER JOIN";
/** logical OR operator */
const LOGICAL_OR = "OR";
/** logical AND operator */
const LOGICAL_AND = "AND";
protected $ignoreCase = false;
protected $singleRecord = false;
/**
* Storage of select data. Collection of column names.
* @var array
*/
protected $selectColumns = array();
/**
* Storage of aliased select data. Collection of column names.
* @var array
*/
protected $asColumns = array();
/**
* Storage of select modifiers data. Collection of modifier names.
* @var array
*/
protected $selectModifiers = array();
/**
* Storage of conditions data. Collection of Criterion objects.
* @var array
*/
protected $map = array();
/**
* Storage of ordering data. Collection of column names.
* @var array
*/
protected $orderByColumns = array();
/**
* Storage of grouping data. Collection of column names.
* @var array
*/
protected $groupByColumns = array();
/**
* Storage of having data.
* @var Criterion
*/
protected $having = null;
/**
* Storage of join data. colleciton of Join objects.
* @var array
*/
protected $joins = array();
protected $selectQueries = array();
/**
* The name of the database.
* @var string
*/
protected $dbName;
/**
* The primary table for this Criteria.
* Useful in cases where there are no select or where
* columns.
* @var string
*/
protected $primaryTableName;
/** The name of the database as given in the contructor. */
protected $originalDbName;
/**
* To limit the number of rows to return. <code>0</code> means return all
* rows.
*/
protected $limit = 0;
/** To start the results at a row other than the first one. */
protected $offset = 0;
/**
* Comment to add to the SQL query
* @var string
*/
protected $queryComment;
// flag to note that the criteria involves a blob.
protected $blobFlag = null;
protected $aliases = array();
protected $useTransaction = false;
/**
* Storage for Criterions expected to be combined
* @var array
*/
protected $namedCriterions = array();
/**
* Default operator for combination of criterions
* @see addUsingOperator
* @var string Criteria::LOGICAL_AND or Criteria::LOGICAL_OR
*/
protected $defaultCombineOperator = Criteria::LOGICAL_AND;
/**
* Flags for boolean functions
* @var PropelConditionalProxy
*/
protected $conditionalProxy = null;
/**
* Creates a new instance with the default capacity which corresponds to
* the specified database.
*
* @param string $dbName The dabase name.
*/
public function __construct($dbName = null)
{
$this->setDbName($dbName);
$this->originalDbName = $dbName;
}
/**
* Implementing SPL IteratorAggregate interface. This allows
* you to foreach () over a Criteria object.
*/
public function getIterator()
{
return new CriterionIterator($this);
}
/**
* Get the criteria map, i.e. the array of Criterions
* @return array
*/
public function getMap()
{
return $this->map;
}
/**
* Brings this criteria back to its initial state, so that it
* can be reused as if it was new. Except if the criteria has grown in
* capacity, it is left at the current capacity.
* @return void
*/
public function clear()
{
$this->map = array();
$this->namedCriterions = array();
$this->ignoreCase = false;
$this->singleRecord = false;
$this->selectModifiers = array();
$this->selectColumns = array();
$this->orderByColumns = array();
$this->groupByColumns = array();
$this->having = null;
$this->asColumns = array();
$this->joins = array();
$this->selectQueries = array();
$this->dbName = $this->originalDbName;
$this->offset = 0;
$this->limit = 0;
$this->blobFlag = null;
$this->aliases = array();
$this->useTransaction = false;
$this->ifLvlCount = false;
$this->wasTrue = false;
}
/**
* Add an AS clause to the select columns. Usage:
*
* <code>
* Criteria myCrit = new Criteria();
* myCrit->addAsColumn("alias", "ALIAS(".MyPeer::ID.")");
* </code>
*
* @param string $name Wanted Name of the column (alias).
* @param string $clause SQL clause to select from the table
*
* If the name already exists, it is replaced by the new clause.
*
* @return Criteria A modified Criteria object.
*/
public function addAsColumn($name, $clause)
{
$this->asColumns[$name] = $clause;
return $this;
}
/**
* Get the column aliases.
*
* @return array An assoc array which map the column alias names
* to the alias clauses.
*/
public function getAsColumns()
{
return $this->asColumns;
}
/**
* Returns the column name associated with an alias (AS-column).
*
* @param string $as
* @return string|null $string The name if found, null otherwise.
*/
public function getColumnForAs($as)
{
if (isset($this->asColumns[$as])) {
return $this->asColumns[$as];
}
return null;
}
/**
* Allows one to specify an alias for a table that can
* be used in various parts of the SQL.
*
* @param string $alias
* @param string $table
*
* @return Criteria A modified Criteria object.
*/
public function addAlias($alias, $table)
{
$this->aliases[$alias] = $table;
return $this;
}
/**
* Remove an alias for a table (useful when merging Criterias).
*
* @param string $alias
*
* @return Criteria A modified Criteria object.
*/
public function removeAlias($alias)
{
unset($this->aliases[$alias]);
return $this;
}
/**
* Returns the aliases for this Criteria
*
* @return array
*/
public function getAliases()
{
return $this->aliases;
}
/**
* Returns the table name associated with an alias.
*
* @param string $alias
* @return string|null $string The name if given, null otherwise.
*/
public function getTableForAlias($alias)
{
if (isset($this->aliases[$alias])) {
return $this->aliases[$alias];
}
return null;
}
/**
* Returns the table name and alias based on a table alias or name.
* Use this method to get the details of a table name that comes in a clause,
* which can be either a table name or an alias name.
*
* @param string $tableAliasOrName
* @return array($tableName, $tableAlias)
*/
public function getTableNameAndAlias($tableAliasOrName)
{
if (isset($this->aliases[$tableAliasOrName])) {
return array($this->aliases[$tableAliasOrName], $tableAliasOrName);
} else {
return array($tableAliasOrName, null);
}
}
/**
* Get the keys of the criteria map, i.e. the list of columns bearing a condition
* <code>
* print_r($c->keys());
* => array('book.price', 'book.title', 'author.first_name')
* </code>
*
* @return array
*/
public function keys()
{
return array_keys($this->map);
}
/**
* Does this Criteria object contain the specified key?
*
* @param string $column [table.]column
* @return boolean True if this Criteria object contain the specified key.
*/
public function containsKey($column)
{
// must use array_key_exists() because the key could
// exist but have a NULL value (that'd be valid).
return array_key_exists($column, $this->map);
}
/**
* Does this Criteria object contain the specified key and does it have a value set for the key
*
* @param string $column [table.]column
* @return boolean True if this Criteria object contain the specified key and a value for that key
*/
public function keyContainsValue($column)
{
// must use array_key_exists() because the key could
// exist but have a NULL value (that'd be valid).
return (array_key_exists($column, $this->map) && ($this->map[$column]->getValue() !== null) );
}
/**
* Whether this Criteria has any where columns.
*
* This counts conditions added with the add() method.
*
* @return boolean
* @see add()
*/
public function hasWhereClause()
{
return !empty($this->map);
}
/**
* Will force the sql represented by this criteria to be executed within
* a transaction. This is here primarily to support the oid type in
* postgresql. Though it can be used to require any single sql statement
* to use a transaction.
*
* @param bool $v
* @return void
*/
public function setUseTransaction($v)
{
$this->useTransaction = (boolean) $v;
}
/**
* Whether the sql command specified by this criteria must be wrapped
* in a transaction.
*
* @return boolean
*/
public function isUseTransaction()
{
return $this->useTransaction;
}
/**
* Method to return criteria related to columns in a table.
*
* Make sure you call containsKey($column) prior to calling this method,
* since no check on the existence of the $column is made in this method.
*
* @param string $column Column name.
* @return Criterion A Criterion object.
*/
public function getCriterion($column)
{
return $this->map[$column];
}
/**
* Method to return the latest Criterion in a table.
*
* @return Criterion A Criterion or null no Criterion is added.
*/
public function getLastCriterion()
{
if ($cnt = count($this->map)) {
$map = array_values($this->map);
return $map[$cnt - 1];
}
return null;
}
/**
* Method to return criterion that is not added automatically
* to this Criteria. This can be used to chain the
* Criterions to form a more complex where clause.
*
* @param string $column Full name of column (for example TABLE.COLUMN).
* @param mixed $value
* @param string $comparison
* @return Criterion
*/
public function getNewCriterion($column, $value = null, $comparison = self::EQUAL)
{
return new Criterion($this, $column, $value, $comparison);
}
/**
* Method to return a String table name.
*
* @param string $name Name of the key.
* @return string The value of the object at key.
*/
public function getColumnName($name)
{
if (isset($this->map[$name])) {
return $this->map[$name]->getColumn();
}
return null;
}
/**
* Shortcut method to get an array of columns indexed by table.
* <code>
* print_r($c->getTablesColumns());
* => array(
* 'book' => array('book.price', 'book.title'),
* 'author' => array('author.first_name')
* )
* </code>
*
* @return array array(table => array(table.column1, table.column2))
*/
public function getTablesColumns()
{
$tables = array();
foreach ($this->keys() as $key) {
$tableName = substr($key, 0, strrpos($key, '.' ));
$tables[$tableName][] = $key;
}
return $tables;
}
/**
* Method to return a comparison String.
*
* @param string $key String name of the key.
* @return string A String with the value of the object at key.
*/
public function getComparison($key)
{
if ( isset ( $this->map[$key] ) ) {
return $this->map[$key]->getComparison();
}
return null;
}
/**
* Get the Database(Map) name.
*
* @return string A String with the Database(Map) name.
*/
public function getDbName()
{
return $this->dbName;
}
/**
* Set the DatabaseMap name. If <code>null</code> is supplied, uses value
* provided by <code>Propel::getDefaultDB()</code>.
*
* @param string $dbName The Database (Map) name.
* @return void
*/
public function setDbName($dbName = null)
{
$this->dbName = ($dbName === null ? Propel::getDefaultDB() : $dbName);
}
/**
* Get the primary table for this Criteria.
*
* This is useful for cases where a Criteria may not contain
* any SELECT columns or WHERE columns. This must be explicitly
* set, of course, in order to be useful.
*
* @return string
*/
public function getPrimaryTableName()
{
return $this->primaryTableName;
}
/**
* Sets the primary table for this Criteria.
*
* This is useful for cases where a Criteria may not contain
* any SELECT columns or WHERE columns. This must be explicitly
* set, of course, in order to be useful.
*
* @param string $tableName
*/
public function setPrimaryTableName($tableName)
{
$this->primaryTableName = $tableName;
}
/**
* Method to return a String table name.
*
* @param string $name The name of the key.
* @return string The value of table for criterion at key.
*/
public function getTableName($name)
{
if (isset($this->map[$name])) {
return $this->map[$name]->getTable();
}
return null;
}
/**
* Method to return the value that was added to Criteria.
*
* @param string $name A String with the name of the key.
* @return mixed The value of object at key.
*/
public function getValue($name)
{
if (isset($this->map[$name])) {
return $this->map[$name]->getValue();
}
return null;
}
/**
* An alias to getValue() -- exposing a Hashtable-like interface.
*
* @param string $key An Object.
* @return mixed The value within the Criterion (not the Criterion object).
*/
public function get($key)
{
return $this->getValue($key);
}
/**
* Overrides Hashtable put, so that this object is returned
* instead of the value previously in the Criteria object.
* The reason is so that it more closely matches the behavior
* of the add() methods. If you want to get the previous value
* then you should first Criteria.get() it yourself. Note, if
* you attempt to pass in an Object that is not a String, it will
* throw a NPE. The reason for this is that none of the add()
* methods support adding anything other than a String as a key.
*
* @param string $key
* @param mixed $value
* @return Criteria A modified Criteria object.
*/
public function put($key, $value)
{
return $this->add($key, $value);
}
/**
* Copies all of the mappings from the specified Map to this Criteria
* These mappings will replace any mappings that this Criteria had for any
* of the keys currently in the specified Map.
*
* if the map was another Criteria, its attributes are copied to this
* Criteria, overwriting previous settings.
*
* @param mixed $t Mappings to be stored in this map.
*/
public function putAll($t)
{
if (is_array($t)) {
foreach ($t as $key=>$value) {
if ($value instanceof Criterion) {
$this->map[$key] = $value;
} else {
$this->put($key, $value);
}
}
} elseif ($t instanceof Criteria) {
$this->joins = $t->joins;
}
}
/**
* This method adds a new criterion to the list of criterias.
* If a criterion for the requested column already exists, it is
* replaced. If is used as follow:
*
* <code>
* $crit = new Criteria();
* $crit->add($column, $value, Criteria::GREATER_THAN);
* </code>
*
* Any comparison can be used.
*
* The name of the table must be used implicitly in the column name,
* so the Column name must be something like 'TABLE.id'.
*
* @param string $critOrColumn The column to run the comparison on, or a Criterion object.
* @param mixed $value
* @param string $comparison A String.
*
* @return Criteria A modified Criteria object.
*/
public function add($critOrColumn, $value = null, $comparison = null)
{
$criterion = $this->getCriterionForCondition($critOrColumn, $value, $comparison);
if ($critOrColumn instanceof Criterion) {
$this->map[$critOrColumn->getTable() . '.' . $critOrColumn->getColumn()] = $criterion;
} else {
$this->map[$critOrColumn] = $criterion;
}
return $this;
}
/**
* This method creates a new criterion but keeps it for later use with combine()
* Until combine() is called, the condition is not added to the query
*
* <code>
* $crit = new Criteria();
* $crit->addCond('cond1', $column1, $value1, Criteria::GREATER_THAN);
* $crit->addCond('cond2', $column2, $value2, Criteria::EQUAL);
* $crit->combine(array('cond1', 'cond2'), Criteria::LOGICAL_OR);
* </code>
*
* Any comparison can be used.
*
* The name of the table must be used implicitly in the column name,
* so the Column name must be something like 'TABLE.id'.
*
* @param string $name name to combine the criterion later
* @param string $p1 The column to run the comparison on, or Criterion object.
* @param mixed $value
* @param string $comparison A String.
*
* @return Criteria A modified Criteria object.
*/
public function addCond($name, $p1, $value = null, $comparison = null)
{
$this->namedCriterions[$name] = $this->getCriterionForCondition($p1, $value, $comparison);
return $this;
}
/**
* Combine several named criterions with a logical operator
*
* @param array $criterions array of the name of the criterions to combine
* @param string $operator logical operator, either Criteria::LOGICAL_AND, or Criteria::LOGICAL_OR
* @param string $name optional name to combine the criterion later
*
* @return Criteria
*
* @throws PropelException
*/
public function combine($criterions = array(), $operator = self::LOGICAL_AND, $name = null)
{
$operatorMethod = (strtoupper($operator) == self::LOGICAL_AND) ? 'addAnd' : 'addOr';
$namedCriterions = array();
foreach ($criterions as $key) {
if (array_key_exists($key, $this->namedCriterions)) {
$namedCriterions[]= $this->namedCriterions[$key];
unset($this->namedCriterions[$key]);
} else {
throw new PropelException('Cannot combine unknown condition ' . $key);
}
}
$firstCriterion = array_shift($namedCriterions);
foreach ($namedCriterions as $criterion) {
$firstCriterion->$operatorMethod($criterion);
}
if ($name === null) {
$this->addAnd($firstCriterion, null, null);
} else {
$this->addCond($name, $firstCriterion, null, null);
}
return $this;
}
/**
* This is the way that you should add a join of two tables.
* Example usage:
* <code>
* $c->addJoin(ProjectPeer::ID, FooPeer::PROJECT_ID, Criteria::LEFT_JOIN);
* // LEFT JOIN FOO ON (PROJECT.ID = FOO.PROJECT_ID)
* </code>
*
* @param mixed $left A String with the left side of the join, or an array (@see addMultipleJoin).
* @param mixed $right A String with the right side of the join, or an array (@see addMultipleJoin).
* @param mixed $joinType A String with the join operator
* among Criteria::INNER_JOIN, Criteria::LEFT_JOIN,
* and Criteria::RIGHT_JOIN
*
* @return Criteria A modified Criteria object.
*/
public function addJoin($left, $right, $joinType = null)
{
if (is_array($left)) {
$conditions = array();
foreach ($left as $key => $value) {
$condition = array($value, $right[$key]);
$conditions []= $condition;
}
return $this->addMultipleJoin($conditions, $joinType);
}
$join = new Join();
// is the left table an alias ?
$dotpos = strrpos($left, '.');
$leftTableAlias = substr($left, 0, $dotpos);
$leftColumnName = substr($left, $dotpos + 1);
list($leftTableName, $leftTableAlias) = $this->getTableNameAndAlias($leftTableAlias);
// is the right table an alias ?
$dotpos = strrpos($right, '.');
$rightTableAlias = substr($right, 0, $dotpos);
$rightColumnName = substr($right, $dotpos + 1);
list($rightTableName, $rightTableAlias) = $this->getTableNameAndAlias($rightTableAlias);
$join->addExplicitCondition(
$leftTableName, $leftColumnName, $leftTableAlias,
$rightTableName, $rightColumnName, $rightTableAlias,
Join::EQUAL);
$join->setJoinType($joinType);
return $this->addJoinObject($join);
}
/**
* Add a join with multiple conditions
* @deprecated use Join::setJoinCondition($criterion) instead
*
* @see http://propel.phpdb.org/trac/ticket/167, http://propel.phpdb.org/trac/ticket/606
*
* Example usage:
* $c->addMultipleJoin(array(
* array(LeftPeer::LEFT_COLUMN, RightPeer::RIGHT_COLUMN), // if no third argument, defaults to Criteria::EQUAL
* array(FoldersPeer::alias( 'fo', FoldersPeer::LFT ), FoldersPeer::alias( 'parent', FoldersPeer::RGT ), Criteria::LESS_EQUAL )
* ),
* Criteria::LEFT_JOIN
* );
*
* @see addJoin()
* @param array $conditions An array of conditions, each condition being an array (left, right, operator)
* @param string $joinType A String with the join operator. Defaults to an implicit join.
*
* @return Criteria A modified Criteria object.
*/
public function addMultipleJoin($conditions, $joinType = null)
{
$join = new Join();
$joinCondition = null;
foreach ($conditions as $condition) {
$left = $condition[0];
$right = $condition[1];
if ($pos = strrpos($left, '.')) {
$leftTableAlias = substr($left, 0, $pos);
$leftColumnName = substr($left, $pos + 1);
list($leftTableName, $leftTableAlias) = $this->getTableNameAndAlias($leftTableAlias);
} else {
list($leftTableName, $leftTableAlias) = array(null, null);
$leftColumnName = $left;
}
if ($pos = strrpos($right, '.')) {
$rightTableAlias = substr($right, 0, $pos);
$rightColumnName = substr($right, $pos + 1);
list($rightTableName, $rightTableAlias) = $this->getTableNameAndAlias($rightTableAlias);
} else {
list($rightTableName, $rightTableAlias) = array(null, null);
$rightColumnName = $right;
}
if (!$join->getRightTableName()) {
$join->setRightTableName($rightTableName);
}
if (!$join->getRightTableAlias()) {
$join->setRightTableAlias($rightTableAlias);
}
$conditionClause = $leftTableAlias ? $leftTableAlias . '.' : ($leftTableName ? $leftTableName . '.' : '');
$conditionClause .= $leftColumnName;
$conditionClause .= isset($condition[2]) ? $condition[2] : JOIN::EQUAL;
$conditionClause .= $rightTableAlias ? $rightTableAlias . '.' : ($rightTableName ? $rightTableName . '.' : '');
$conditionClause .= $rightColumnName;
$criterion = $this->getNewCriterion($leftTableName.'.'.$leftColumnName, $conditionClause, Criteria::CUSTOM);
if (null === $joinCondition) {
$joinCondition = $criterion;
} else {
$joinCondition = $joinCondition->addAnd($criterion);
}
}
$join->setJoinType($joinType);
$join->setJoinCondition($joinCondition);
return $this->addJoinObject($join);
}
/**
* Add a join object to the Criteria
*
* @param Join $join A join object
*
* @return Criteria A modified Criteria object
*/
public function addJoinObject(Join $join)
{
if (!in_array($join, $this->joins)) { // compare equality, NOT identity
$this->joins[] = $join;
}
return $this;
}
/**
* Get the array of Joins.
* @return array Join[]
*/
public function getJoins()
{
return $this->joins;
}
/**
* Adds a Criteria as subQuery in the From Clause.
*
* @param Criteria $subQueryCriteria Criteria to build the subquery from
* @param string $alias alias for the subQuery
*
* @return Criteria this modified Criteria object (Fluid API)
*/
public function addSelectQuery(Criteria $subQueryCriteria, $alias = null)
{
if (null === $alias) {
$alias = 'alias_' . ($subQueryCriteria->forgeSelectQueryAlias() + count($this->selectQueries));
}
$this->selectQueries[$alias] = $subQueryCriteria;
return $this;
}
/**
* Checks whether this Criteria has a subquery.
*
* @return Boolean
*/
public function hasSelectQueries()
{
return (bool) $this->selectQueries;
}
/**
* Get the associative array of Criteria for the subQueries per alias.
*
* @return array Criteria[]
*/
public function getSelectQueries()
{
return $this->selectQueries;
}
/**
* Get the Criteria for a specific subQuery.
*
* @param string $alias alias for the subQuery
* @return Criteria
*/
public function getSelectQuery($alias)
{
return $this->selectQueries[$alias];
}
/**
* checks if the Criteria for a specific subQuery is set.
*
* @param string $alias alias for the subQuery
* @return boolean
*/
public function hasSelectQuery($alias)
{
return isset($this->selectQueries[$alias]);
}
public function forgeSelectQueryAlias()
{
$aliasNumber = 0;
foreach ($this->getSelectQueries() as $c1) {
$aliasNumber += $c1->forgeSelectQueryAlias();
}
return ++$aliasNumber;
}
/**
* Adds "ALL" modifier to the SQL statement.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setAll()
{
$this->removeSelectModifier(self::DISTINCT);
$this->addSelectModifier(self::ALL);
return $this;
}
/**
* Adds "DISTINCT" modifier to the SQL statement.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setDistinct()
{
$this->removeSelectModifier(self::ALL);
$this->addSelectModifier(self::DISTINCT);
return $this;
}
/**
* Adds a modifier to the SQL statement.
* e.g. self::ALL, self::DISTINCT, 'SQL_CALC_FOUND_ROWS', 'HIGH_PRIORITY', etc.
*
* @param string $modifier The modifier to add
*
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addSelectModifier($modifier)
{
//only allow the keyword once
if (!$this->hasSelectModifier($modifier)) {
$this->selectModifiers[] = $modifier;
}
return $this;
}
/**
* Removes a modifier to the SQL statement.
* Checks for existence before removal
*
* @param string $modifier The modifier to add
*
* @return Criteria Modified Criteria object (for fluent API)
*/
public function removeSelectModifier($modifier)
{
$this->selectModifiers = array_values(array_diff($this->selectModifiers, array($modifier)));
return $this;
}
/**
* Checks the existence of a SQL select modifier
*
* @param string $modifier The modifier to add
*
* @return bool
*/
public function hasSelectModifier($modifier)
{
return in_array($modifier, $this->selectModifiers);
}
/**
* Sets ignore case.
*
* @param boolean $b True if case should be ignored.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setIgnoreCase($b)
{
$this->ignoreCase = (boolean) $b;
return $this;
}
/**
* Is ignore case on or off?
*
* @return boolean True if case is ignored.
*/
public function isIgnoreCase()
{
return $this->ignoreCase;
}
/**
* Set single record? Set this to <code>true</code> if you expect the query
* to result in only a single result record (the default behaviour is to
* throw a PropelException if multiple records are returned when the query
* is executed). This should be used in situations where returning multiple
* rows would indicate an error of some sort. If your query might return
* multiple records but you are only interested in the first one then you
* should be using setLimit(1).
*
* @param boolean $b Set to TRUE if you expect the query to select just one record.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setSingleRecord($b)
{
$this->singleRecord = (boolean) $b;
return $this;
}
/**
* Is single record?
*
* @return boolean True if a single record is being returned.
*/
public function isSingleRecord()
{
return $this->singleRecord;
}
/**
* Set limit.
*
* @param int $limit An int with the value for limit.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setLimit($limit)
{
// TODO: do we enforce int here? 32bit issue if we do
$this->limit = $limit;
return $this;
}
/**
* Get limit.
*
* @return int An int with the value for limit.
*/
public function getLimit()
{
return $this->limit;
}
/**
* Set offset.
*
* @param int $offset An int with the value for offset. (Note this values is
* cast to a 32bit integer and may result in truncatation)
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setOffset($offset)
{
$this->offset = (int) $offset;
return $this;
}
/**
* Get offset.
*
* @return int An int with the value for offset.
*/
public function getOffset()
{
return $this->offset;
}
/**
* Add select column.
*
* @param string $name Name of the select column.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addSelectColumn($name)
{
$this->selectColumns[] = $name;
return $this;
}
/**
* Set the query comment, that appears after the first verb in the SQL query
*
* @param string $comment The comment to add to the query, without comment sign
* @return Criteria Modified Criteria object (for fluent API)
*/
public function setComment($comment = null)
{
$this->queryComment = $comment;
return $this;
}
/**
* Get the query comment, that appears after the first verb in the SQL query
*
* @return string The comment to add to the query, without comment sign
*/
public function getComment()
{
return $this->queryComment;
}
/**
* Whether this Criteria has any select columns.
*
* This will include columns added with addAsColumn() method.
*
* @return boolean
* @see addAsColumn()
* @see addSelectColumn()
*/
public function hasSelectClause()
{
return (!empty($this->selectColumns) || !empty($this->asColumns));
}
/**
* Get select columns.
*
* @return array An array with the name of the select columns.
*/
public function getSelectColumns()
{
return $this->selectColumns;
}
/**
* Clears current select columns.
*
* @return Criteria Modified Criteria object (for fluent API)
*/
public function clearSelectColumns()
{
$this->selectColumns = $this->asColumns = array();
return $this;
}
/**
* Get select modifiers.
*
* @return array An array with the select modifiers.
*/
public function getSelectModifiers()
{
return $this->selectModifiers;
}
/**
* Add group by column name.
*
* @param string $groupBy The name of the column to group by.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addGroupByColumn($groupBy)
{
$this->groupByColumns[] = $groupBy;
return $this;
}
/**
* Add order by column name, explicitly specifying ascending.
*
* @param string $name The name of the column to order by.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addAscendingOrderByColumn($name)
{
$this->orderByColumns[] = $name . ' ' . self::ASC;
return $this;
}
/**
* Add order by column name, explicitly specifying descending.
*
* @param string $name The name of the column to order by.
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addDescendingOrderByColumn($name)
{
$this->orderByColumns[] = $name . ' ' . self::DESC;
return $this;
}
/**
* Get order by columns.
*
* @return array An array with the name of the order columns.
*/
public function getOrderByColumns()
{
return $this->orderByColumns;
}
/**
* Clear the order-by columns.
*
* @return Criteria Modified Criteria object (for fluent API)
*/
public function clearOrderByColumns()
{
$this->orderByColumns = array();
return $this;
}
/**
* Clear the group-by columns.
*
* @return Criteria
*/
public function clearGroupByColumns()
{
$this->groupByColumns = array();
return $this;
}
/**
* Get group by columns.
*
* @return array
*/
public function getGroupByColumns()
{
return $this->groupByColumns;
}
/**
* Get Having Criterion.
*
* @return Criterion A Criterion object that is the having clause.
*/
public function getHaving()
{
return $this->having;
}
/**
* Remove an object from the criteria.
*
* @param string $key A string with the key to be removed.
* @return mixed|null The removed value, null if not set.
*/
public function remove($key)
{
if ( isset ( $this->map[$key] ) ) {
$removed = $this->map[$key];
unset ( $this->map[$key] );
if ($removed instanceof Criterion) {
return $removed->getValue();
}
return $removed;
}
return null;
}
/**
* Build a string representation of the Criteria.
*
* @return string A String with the representation of the Criteria.
*/
public function toString()
{
$sb = "Criteria:";
try {
$params = array();
$sb .= "\nSQL (may not be complete): "
. BasePeer::createSelectSql($this, $params);
$sb .= "\nParams: ";
$paramstr = array();
foreach ($params as $param) {
$paramstr[] = $param['table'] . '.' . $param['column'] . ' => ' . var_export($param['value'], true);
}
$sb .= implode(", ", $paramstr);
} catch (Exception $exc) {
$sb .= "(Error: " . $exc->getMessage() . ")";
}
return $sb;
}
/**
* Returns the size (count) of this criteria.
* @return int
*/
public function size()
{
return count($this->map);
}
/**
* This method checks another Criteria to see if they contain
* the same attributes and hashtable entries.
*
* @param Criteria|null $crit
* @return boolean
*/
public function equals($crit)
{
if ($crit === null || !($crit instanceof Criteria)) {
return false;
} elseif ($this === $crit) {
return true;
} elseif ($this->size() === $crit->size()) {
// Important: nested criterion objects are checked
$criteria = $crit; // alias
if ($this->offset === $criteria->getOffset()
&& $this->limit === $criteria->getLimit()
&& $this->ignoreCase === $criteria->isIgnoreCase()
&& $this->singleRecord === $criteria->isSingleRecord()
&& $this->dbName === $criteria->getDbName()
&& $this->selectModifiers === $criteria->getSelectModifiers()
&& $this->selectColumns === $criteria->getSelectColumns()
&& $this->asColumns === $criteria->getAsColumns()
&& $this->orderByColumns === $criteria->getOrderByColumns()
&& $this->groupByColumns === $criteria->getGroupByColumns()
&& $this->aliases === $criteria->getAliases()
) // what about having ??
{
foreach ($criteria->keys() as $key) {
if ($this->containsKey($key)) {
$a = $this->getCriterion($key);
$b = $criteria->getCriterion($key);
if (!$a->equals($b)) {
return false;
}
} else {
return false;
}
}
$joins = $criteria->getJoins();
if (count($joins) != count($this->joins)) {
return false;
}
foreach ($joins as $key => $join) {
if (!$join->equals($this->joins[$key])) {
return false;
}
}
return true;
} else {
return false;
}
}
return false;
}
/**
* Add the content of a Criteria to the current Criteria
* In case of conflict, the current Criteria keeps its properties
*
* @param Criteria $criteria The criteria to read properties from
* @param string $operator The logical operator used to combine conditions
* Defaults to Criteria::LOGICAL_AND, also accapts Criteria::LOGICAL_OR
* This parameter is deprecated, use _or() instead
*
* @return Criteria The current criteria object
*
* @throws PropelException
*/
public function mergeWith(Criteria $criteria, $operator = null)
{
// merge limit
$limit = $criteria->getLimit();
if ($limit != 0 && $this->getLimit() == 0) {
$this->limit = $limit;
}
// merge offset
$offset = $criteria->getOffset();
if ($offset != 0 && $this->getOffset() == 0) {
$this->offset = $offset;
}
// merge select modifiers
$selectModifiers = $criteria->getSelectModifiers();
if ($selectModifiers && ! $this->selectModifiers) {
$this->selectModifiers = $selectModifiers;
}
// merge select columns
$this->selectColumns = array_merge($this->getSelectColumns(), $criteria->getSelectColumns());
// merge as columns
$commonAsColumns = array_intersect_key($this->getAsColumns(), $criteria->getAsColumns());
if (!empty($commonAsColumns)) {
throw new PropelException('The given criteria contains an AsColumn with an alias already existing in the current object');
}
$this->asColumns = array_merge($this->getAsColumns(), $criteria->getAsColumns());
// merge orderByColumns
$orderByColumns = array_merge($this->getOrderByColumns(), $criteria->getOrderByColumns());
$this->orderByColumns = array_unique($orderByColumns);
// merge groupByColumns
$groupByColumns = array_merge($this->getGroupByColumns(), $criteria->getGroupByColumns());
$this->groupByColumns = array_unique($groupByColumns);
// merge where conditions
if ($operator == Criteria::LOGICAL_OR) {
$this->_or();
}
$isFirstCondition = true;
foreach ($criteria->getMap() as $key => $criterion) {
if ($isFirstCondition && $this->defaultCombineOperator == Criteria::LOGICAL_OR) {
$this->addOr($criterion, null, null, false);
$this->defaultCombineOperator == Criteria::LOGICAL_AND;
} elseif ($this->containsKey($key)) {
$this->addAnd($criterion);
} else {
$this->add($criterion);
}
$isFirstCondition = false;
}
// merge having
if ($having = $criteria->getHaving()) {
if ($this->getHaving()) {
$this->addHaving($this->getHaving()->addAnd($having));
} else {
$this->addHaving($having);
}
}
// merge alias
$commonAliases = array_intersect_key($this->getAliases(), $criteria->getAliases());
if (!empty($commonAliases)) {
throw new PropelException('The given criteria contains an alias already existing in the current object');
}
$this->aliases = array_merge($this->getAliases(), $criteria->getAliases());
// merge join
$this->joins = array_merge($this->getJoins(), $criteria->getJoins());
return $this;
}
/**
* This method adds a prepared Criterion object to the Criteria as a having clause.
* You can get a new, empty Criterion object with the
* getNewCriterion() method.
*
* <p>
* <code>
* $crit = new Criteria();
* $c = $crit->getNewCriterion(BasePeer::ID, 5, Criteria::LESS_THAN);
* $crit->addHaving($c);
* </code>
*
* @param mixed $p1 A Criterion, or a SQL clause with a question mark placeholder, or a column name
* @param mixed $value The value to bind in the condition
* @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant
*
* @return Criteria Modified Criteria object (for fluent API)
*/
public function addHaving($p1, $value = null, $comparison = null)
{
$this->having = $this->getCriterionForCondition($p1, $value, $comparison);
return $this;
}
/**
* Build a Criterion.
*
* This method has multiple signatures, and behaves differently according to it:
*
* - If the first argument is a Criterion, it just resturns this Criterion.
* <code>$c->getCriterionForConsition($criterion); // returns $criterion</code>
*
* - If the last argument is a PDO::PARAM_* constant value, create a Criterion
* using Criteria::RAW and $comparison as a type.
* <code>$c->getCriterionForConsition('foo like ?', '%bar%', PDO::PARAM_STR);</code>
*
* - Otherwise, create a classic Criterion based on a column name and a comparison.
* <code>$c->getCriterionForConsition(BookPeer::TITLE, 'War%', Criteria::LIKE);</code>
*
* @param mixed $p1 A Criterion, or a SQL clause with a question mark placeholder, or a column name
* @param mixed $value The value to bind in the condition
* @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant
*
* @return Criterion
*/
protected function getCriterionForCondition($p1, $value = null, $comparison = null)
{
if ($p1 instanceof Criterion) {
// it's already a Criterion, so ignore $value and $comparison
return $p1;
} elseif (is_int($comparison)) {
// $comparison is a PDO::PARAM_* constant value
// something like $c->add('foo like ?', '%bar%', PDO::PARAM_STR);
return new Criterion($this, $p1, $value, Criteria::RAW, $comparison);
}
// $comparison is one of Criteria's constants
// something like $c->add(BookPeer::TITLE, 'War%', Criteria::LIKE);
return new Criterion($this, $p1, $value, $comparison);
}
/**
* If a criterion for the requested column already exists, the condition is "AND"ed to the existing criterion (necessary for Propel 1.4 compatibility).
* If no criterion for the requested column already exists, the condition is "AND"ed to the latest criterion.
* If no criterion exist, the condition is added a new criterion
*
* Any comparison can be used.
*
* Supports a number of different signatures:
* - addAnd(column, value, comparison)
* - addAnd(column, value)
* - addAnd(Criterion)
*
* @param mixed $p1 A Criterion, or a SQL clause with a question mark placeholder, or a column name
* @param mixed $value The value to bind in the condition
* @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant
* @param bool $preferColumnCondition
*
* @return Criteria A modified Criteria object.
*/
public function addAnd($p1, $value = null, $comparison = null, $preferColumnCondition = true)
{
$criterion = $this->getCriterionForCondition($p1, $value, $comparison);
$key = $criterion->getTable() . '.' . $criterion->getColumn();
if ($preferColumnCondition && $this->containsKey($key)) {
// FIXME: addAnd() operates preferably on existing conditions on the same column
// this may cause unexpected results, but it's there for BC with Propel 14
$this->getCriterion($key)->addAnd($criterion);
} else {
// simply add the condition to the list - this is the expected behavior
$this->add($criterion);
}
return $this;
}
/**
* If a criterion for the requested column already exists, the condition is "OR"ed to the existing criterion (necessary for Propel 1.4 compatibility).
* If no criterion for the requested column already exists, the condition is "OR"ed to the latest criterion.
* If no criterion exist, the condition is added a new criterion
*
* Any comparison can be used.
*
* Supports a number of different signatures:
* - addOr(column, value, comparison)
* - addOr(column, value)
* - addOr(Criterion)
*
* @param mixed $p1 A Criterion, or a SQL clause with a question mark placeholder, or a column name
* @param mixed $value The value to bind in the condition
* @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant
* @param bool $preferColumnCondition
*
* @return Criteria A modified Criteria object.
*/
public function addOr($p1, $value = null, $comparison = null, $preferColumnCondition = true)
{
$rightCriterion = $this->getCriterionForCondition($p1, $value, $comparison);
$key = $rightCriterion->getTable() . '.' . $rightCriterion->getColumn();
if ($preferColumnCondition && $this->containsKey($key)) {
// FIXME: addOr() operates preferably on existing conditions on the same column
// this may cause unexpected results, but it's there for BC with Propel 14
$leftCriterion = $this->getCriterion($key);
} else {
// fallback to the latest condition - this is the expected behavior
$leftCriterion = $this->getLastCriterion();
}
if ($leftCriterion !== null) {
// combine the given criterion with the existing one with an 'OR'
$leftCriterion->addOr($rightCriterion);
} else {
// nothing to do OR / AND with, so make it first condition
$this->add($rightCriterion);
}
return $this;
}
/**
* Overrides Criteria::add() to use the default combine operator
* @see Criteria::add()
*
* @param string|Criterion $p1 The column to run the comparison on (e.g. BookPeer::ID), or Criterion object
* @param mixed $value
* @param string $operator A String, like Criteria::EQUAL.
* @param boolean $preferColumnCondition If true, the condition is combined with an existing condition on the same column
* (necessary for Propel 1.4 compatibility).
* If false, the condition is combined with the last existing condition.
*
* @return Criteria A modified Criteria object.
*/
public function addUsingOperator($p1, $value = null, $operator = null, $preferColumnCondition = true)
{
if ($this->defaultCombineOperator == Criteria::LOGICAL_OR) {
$this->defaultCombineOperator = Criteria::LOGICAL_AND;
return $this->addOr($p1, $value, $operator, $preferColumnCondition);
} else {
return $this->addAnd($p1, $value, $operator, $preferColumnCondition);
}
}
// Fluid operators
/**
* @return Criteria
*/
public function _or()
{
$this->defaultCombineOperator = Criteria::LOGICAL_OR;
return $this;
}
/**
* @return Criteria
*/
public function _and()
{
$this->defaultCombineOperator = Criteria::LOGICAL_AND;
return $this;
}
// Fluid Conditions
/**
* Returns the current object if the condition is true,
* or a PropelConditionalProxy instance otherwise.
* Allows for conditional statements in a fluid interface.
*
* @param bool $cond
*
* @return PropelConditionalProxy|Criteria
*/
public function _if($cond)
{
$this->conditionalProxy = new PropelConditionalProxy($this, $cond, $this->conditionalProxy);
return $this->conditionalProxy->getCriteriaOrProxy();
}
/**
* Returns a PropelConditionalProxy instance.
* Allows for conditional statements in a fluid interface.
*
* @param bool $cond ignored
*
* @return PropelConditionalProxy|Criteria
*
* @throws PropelException
*/
public function _elseif($cond)
{
if (!$this->conditionalProxy) {
throw new PropelException('_elseif() must be called after _if()');
}
return $this->conditionalProxy->_elseif($cond);
}
/**
* Returns a PropelConditionalProxy instance.
* Allows for conditional statements in a fluid interface.
*
* @return PropelConditionalProxy|Criteria
*
* @throws PropelException
*/
public function _else()
{
if (!$this->conditionalProxy) {
throw new PropelException('_else() must be called after _if()');
}
return $this->conditionalProxy->_else();
}
/**
* Returns the current object
* Allows for conditional statements in a fluid interface.
*
* @return Criteria
*
* @throws PropelException
*/
public function _endif()
{
if (!$this->conditionalProxy) {
throw new PropelException('_endif() must be called after _if()');
}
$this->conditionalProxy = $this->conditionalProxy->getParentProxy();
if ($this->conditionalProxy) {
return $this->conditionalProxy->getCriteriaOrProxy();
}
// reached last level
return $this;
}
/**
* Ensures deep cloning of attached objects
*/
public function __clone()
{
foreach ($this->map as $key => $criterion) {
$this->map[$key] = clone $criterion;
}
foreach ($this->joins as $key => $join) {
$this->joins[$key] = clone $join;
}
if (null !== $this->having) {
$this->having = clone $this->having;
}
}
}
|