[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel/util/ -> Criteria.php (source)

   1  <?php
   2  /*

   3   *  $Id: Criteria.php 338 2006-02-15 14:46:02Z hans $

   4   *

   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  16   *

  17   * This software consists of voluntary contributions made by many individuals

  18   * and is licensed under the LGPL. For more information please see

  19   * <http://propel.phpdb.org>.

  20   */
  21  
  22  /**

  23   * This is a utility class for holding criteria information for a query.

  24   * 

  25   * BasePeer constructs SQL statements based on the values in this class.

  26   *

  27   * @author Hans Lellelid <hans@xmpl.org> (Propel)

  28   * @author Kaspars Jaudzems <kaspars.jaudzems@inbox.lv> (Propel)

  29   * @author Frank Y. Kim <frank.kim@clearink.com> (Torque)

  30   * @author John D. McNally <jmcnally@collab.net> (Torque)

  31   * @author Brett McLaughlin <bmclaugh@algx.net> (Torque)

  32   * @author Eric Dobbs <eric@dobbse.net> (Torque)

  33   * @author Henning P. Schmiedehausen <hps@intermeta.de> (Torque)

  34   * @author Sam Joseph <sam@neurogrid.com> (Torque)

  35   * @version $Revision: 338 $

  36   * @package propel.util

  37   */
  38  class Criteria implements IteratorAggregate {
  39  
  40      /** Comparison type. */

  41      const EQUAL = "=";
  42  
  43      /** Comparison type. */

  44      const NOT_EQUAL = "<>";
  45  
  46      /** Comparison type. */

  47      const ALT_NOT_EQUAL = "!=";
  48  
  49      /** Comparison type. */

  50      const GREATER_THAN = ">";
  51  
  52      /** Comparison type. */

  53      const LESS_THAN = "<";
  54  
  55      /** Comparison type. */

  56      const GREATER_EQUAL = ">=";
  57  
  58      /** Comparison type. */

  59      const LESS_EQUAL = "<=";
  60  
  61      /** Comparison type. */

  62      const LIKE = " LIKE ";
  63  
  64      /** Comparison type. */

  65      const NOT_LIKE = " NOT LIKE ";
  66  
  67      /** PostgreSQL comparison type */

  68      const ILIKE = " ILIKE ";
  69      
  70      /** PostgreSQL comparison type */

  71      const NOT_ILIKE = " NOT ILIKE ";
  72  
  73      /** Comparison type. */

  74      const CUSTOM = "CUSTOM";
  75  
  76      /** Comparison type. */

  77      const DISTINCT = "DISTINCT ";
  78  
  79      /** Comparison type. */

  80      const IN = " IN ";
  81  
  82      /** Comparison type. */

  83      const NOT_IN = " NOT IN ";
  84  
  85      /** Comparison type. */

  86      const ALL = "ALL ";
  87      
  88      /** Comparison type. */

  89      const JOIN = "JOIN";
  90  
  91      /** Binary math operator: AND */

  92      const BINARY_AND = "&";
  93  
  94      /** Binary math operator: OR */

  95      const BINARY_OR = "|";
  96  
  97      /** "Order by" qualifier - ascending */

  98      const ASC = "ASC";
  99  
 100      /** "Order by" qualifier - descending */

 101      const DESC = "DESC";
 102  
 103      /** "IS NULL" null comparison */

 104      const ISNULL = " IS NULL ";
 105  
 106      /** "IS NOT NULL" null comparison */

 107      const ISNOTNULL = " IS NOT NULL ";
 108  
 109      /** "CURRENT_DATE" ANSI SQL function */

 110      const CURRENT_DATE = "CURRENT_DATE";
 111  
 112      /** "CURRENT_TIME" ANSI SQL function */

 113      const CURRENT_TIME = "CURRENT_TIME";    
 114      
 115      /** "CURRENT_TIMESTAMP" ANSI SQL function */

 116      const CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
 117      
 118      /** "LEFT JOIN" SQL statement */

 119      const LEFT_JOIN = "LEFT JOIN";
 120  
 121      /** "RIGHT JOIN" SQL statement */

 122      const RIGHT_JOIN = "RIGHT JOIN";
 123  
 124      /** "INNER JOIN" SQL statement */

 125      const INNER_JOIN = "INNER JOIN";
 126      
 127      private $ignoreCase = false;
 128      private $singleRecord = false;
 129      private $selectModifiers = array();
 130      private $selectColumns = array();
 131      private $orderByColumns = array();
 132      private $groupByColumns = array();
 133      private $having = null;
 134      private $asColumns = array();
 135      private $joins = array();
 136  
 137      /** The name of the database. */

 138      private $dbName;
 139  
 140      /** The name of the database as given in the contructor. */

 141      private $originalDbName;
 142  
 143      /**

 144       * To limit the number of rows to return.  <code>0</code> means return all

 145       * rows.

 146       */
 147      private $limit = 0;
 148  
 149      /** To start the results at a row other than the first one. */

 150      private $offset = 0;
 151  
 152      // flag to note that the criteria involves a blob.

 153      private $blobFlag = null;
 154  
 155      private $aliases = null;
 156  
 157      private $useTransaction = false;
 158  
 159      /**

 160       * Primary storage of criteria data.

 161       * @var array

 162       */
 163      private $map = array();
 164      
 165      /**

 166       * Creates a new instance with the default capacity which corresponds to

 167       * the specified database.

 168       *

 169       * @param dbName The dabase name.

 170       */
 171      public function __construct($dbName = null)
 172      {
 173          $this->setDbName($dbName);
 174          $this->originalDbName = $dbName;
 175      }
 176      
 177      /**

 178       * Implementing SPL IteratorAggregate interface.  This allows

 179       * you to foreach() over a Criteria object.

 180       */
 181      public function getIterator()
 182          {
 183          return new CriterionIterator($this);
 184      }
 185      
 186          /**

 187           * Get the criteria map.

 188           * @return array

 189           */
 190  		public function getMap()
 191          {
 192              return $this->map;
 193          }
 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->ignoreCase = false;
 205          $this->singleRecord = false;
 206          $this->selectModifiers = array();
 207          $this->selectColumns = array();
 208          $this->orderByColumns = array();
 209          $this->groupByColumns = array();
 210          $this->having = null;
 211          $this->asColumns = array();
 212          $this->joins = array();
 213          $this->dbName = $this->originalDbName;
 214          $this->offset = 0;
 215          $this->limit = -1;
 216          $this->blobFlag = null;
 217          $this->aliases = null;
 218          $this->useTransaction = false;
 219      }
 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      /**

 243       * Get the column aliases.

 244       *

 245       * @return array An assoc array which map the column alias names

 246       * to the alias clauses.

 247       */
 248      public function getAsColumns()
 249      {
 250          return $this->asColumns;
 251      }
 252  
 253          /**

 254       * Returns the column name associated with an alias (AS-column).

 255       *

 256       * @param string $alias

 257       * @return string $string

 258       */
 259      public function getColumnForAs($as)
 260      {
 261          if (isset($this->asColumns[$as])) {
 262              return $this->asColumns[$as];
 263          }
 264      }
 265      
 266      /**

 267       * Allows one to specify an alias for a table that can

 268       * be used in various parts of the SQL.

 269       *

 270       * @param string $alias

 271       * @param string $table

 272       * @return void

 273       */
 274      public function addAlias($alias, $table)
 275      {
 276          if ($this->aliases === null) {
 277              $this->aliases = array();
 278          }
 279          $this->aliases[$alias] = $table;
 280      }
 281  
 282      /**

 283       * Returns the table name associated with an alias.

 284       *

 285       * @param string $alias

 286       * @return string $string

 287       */
 288      public function getTableForAlias($alias)
 289      {
 290          if (isset($this->aliases[$alias])) {
 291              return $this->aliases[$alias];
 292          }
 293      }
 294      
 295      /**

 296       * Get the keys for the criteria map.

 297       * @return array

 298       */
 299      public function keys()
 300      {
 301          return array_keys($this->map);
 302      }
 303      
 304      /**

 305       * Does this Criteria object contain the specified key?

 306       *

 307       * @param string $column [table.]column

 308       * @return boolean True if this Criteria object contain the specified key.

 309       */
 310      public function containsKey($column)
 311      {
 312          // must use array_key_exists() because the key could

 313          // exist but have a NULL value (that'd be valid).

 314          return array_key_exists($column, $this->map);
 315      }
 316  
 317      /**

 318       * Will force the sql represented by this criteria to be executed within

 319       * a transaction.  This is here primarily to support the oid type in

 320       * postgresql.  Though it can be used to require any single sql statement

 321       * to use a transaction.

 322       * @return void

 323       */
 324      public function setUseTransaction($v)
 325      {
 326          $this->useTransaction = (boolean) $v;
 327      }
 328  
 329      /**

 330       * called by BasePeer to determine whether the sql command specified by

 331       * this criteria must be wrapped in a transaction.

 332       *

 333       * @return a <code>boolean</code> value

 334       */
 335      public function isUseTransaction()
 336      {
 337          return $this->useTransaction;
 338      }
 339  
 340      /**

 341       * Method to return criteria related to columns in a table.

 342       *

 343           * @param string $column Column name.

 344       * @return A Criterion or null if $column is invalid.

 345       */
 346      public function getCriterion($column)
 347      {
 348              if (isset($this->map[$column])) {
 349              return $this->map[$column];
 350              }
 351      }
 352  
 353      /**

 354       * Method to return criterion that is not added automatically

 355       * to this Criteria.  This can be used to chain the

 356       * Criterions to form a more complex where clause.

 357       *

 358       * @param column String full name of column (for example TABLE.COLUMN).

 359       * @param mixed $value

 360       * @param string $comparison

 361       * @return A Criterion.

 362       */
 363      public function getNewCriterion($column, $value, $comparison = null)
 364      {
 365          return new Criterion($this, $column, $value, $comparison);
 366      }
 367  
 368      /**

 369       * Method to return a String table name.

 370       *

 371       * @param name A String with the name of the key.

 372       * @return A String with the value of the object at key.

 373       */
 374      public function getColumnName($name)
 375      {
 376          $c = isset($this->map[$name]) ? $this->map[$name] : null;
 377          $val = null;
 378          if ($c !== null) {
 379              $val = $c->getColumn();
 380          }
 381          return $val;
 382      }
 383  
 384      /**

 385       * Shortcut method to get an array of columns indexed by table.

 386       * @return array array(table => array(table.column1, table.column2))

 387       */
 388      function getTablesColumns()
 389      {
 390          $tables = array();
 391          $keys = array_keys($this->map);
 392          foreach($keys as $key) {
 393              $t = substr($key, 0, strpos($key, '.'));
 394              // this happens automatically, so if no notices

 395              // are raised, then leave it out:

 396              // if (!isset($tables[$t])) $tables[$t] = array();

 397              $tables[$t][] = $key;
 398          }
 399          return $tables;
 400      }
 401      
 402      /**

 403       * Method to return a comparison String.

 404       *

 405       * @param string $key String name of the key.

 406       * @return string A String with the value of the object at key.

 407       */
 408      public function getComparison($key)
 409      {
 410          $c = isset($this->map[$key]) ? $this->map[$key] : null;
 411          $val = null;
 412          if ($c !== null) {
 413              $val = $c->getComparison();
 414          }
 415          return $val;
 416      }
 417      
 418      /**

 419       * Get the Database(Map) name.

 420       *

 421       * @return string A String with the Database(Map) name.

 422       */
 423      public function getDbName()
 424      {
 425          return $this->dbName;
 426      }
 427  
 428      /**

 429       * Set the DatabaseMap name.  If <code>null</code> is supplied, uses value

 430       * provided by <code>Propel::getDefaultDB()</code>.

 431       *

 432       * @param $dbName A String with the Database(Map) name.

 433       * @return void

 434       */
 435      public function setDbName($dbName = null)
 436      {
 437          $this->dbName = ($dbName === null ? Propel::getDefaultDB() : $dbName);
 438      }
 439  
 440      /**

 441       * Method to return a String table name.

 442       *

 443       * @param $name A String with the name of the key.

 444       * @return string A String with the value of table for criterion at key.

 445       */
 446      public function getTableName($name)
 447      {
 448          $c = isset($this->map[$name]) ? $this->map[$name] : null;
 449          $val = null;
 450          if ($c !== null) {
 451              $val = $c->getTable();
 452          }
 453          return $val;
 454      }
 455  
 456      /**

 457       * Method to return the value that was added to Criteria.

 458       *

 459       * @param string $name A String with the name of the key.

 460       * @return mixed The value of object at key.

 461       */
 462      public function getValue($name)
 463      {
 464          $c = isset($this->map[$name]) ? $this->map[$name] : null;
 465          $val = null;
 466          if ($c !== null) {
 467              $val = $c->getValue();
 468          }
 469          return $val;
 470      }     
 471  
 472      /**

 473       * An alias to getValue() -- exposing a Hashtable-like interface.

 474       *

 475       * @param string $key An Object.

 476       * @return mixed The value within the Criterion (not the Criterion object).

 477       */
 478      public function get($key)
 479      {
 480          return $this->getValue($key);
 481      }
 482  
 483      /**

 484       * Overrides Hashtable put, so that this object is returned

 485       * instead of the value previously in the Criteria object.

 486       * The reason is so that it more closely matches the behavior

 487       * of the add() methods. If you want to get the previous value

 488       * then you should first Criteria.get() it yourself. Note, if

 489       * you attempt to pass in an Object that is not a String, it will

 490       * throw a NPE. The reason for this is that none of the add()

 491       * methods support adding anything other than a String as a key.

 492       *

 493       * @param string $key

 494       * @param mixed $value

 495       * @return Instance of self.

 496       */
 497      public function put($key, $value)
 498      {        
 499          return $this->add($key, $value);
 500      }
 501  
 502      /**

 503       * Copies all of the mappings from the specified Map to this Criteria

 504       * These mappings will replace any mappings that this Criteria had for any

 505       * of the keys currently in the specified Map.

 506       *

 507       * if the map was another Criteria, its attributes are copied to this

 508       * Criteria, overwriting previous settings.

 509       *

 510       * @param mixed $t Mappings to be stored in this map.

 511       */
 512      public function putAll($t)
 513      {
 514      
 515          if (is_array($t)) {
 516          
 517              $keys = array_keys($t);
 518              foreach ($keys as $key) {
 519                  $val = $t[$key];
 520                  if ($val instanceof Criterion) {
 521                      $this->map[$key] = $val;
 522                  } else {
 523                      // put throws an exception ... right?

 524                      // otherwise there's no difference ... not sure why this is here

 525                      // %%%

 526                      $this->put($key, $val);
 527                  }
 528              }
 529              
 530          } elseif ($t instanceof Criteria) {
 531              $this->joins = $t->joins;
 532          }       
 533      }
 534  
 535  
 536      /**

 537       * This method adds a new criterion to the list of criterias.

 538       * If a criterion for the requested column already exists, it is

 539       * replaced. If is used as follow:

 540       *

 541       * <p>

 542       * <code>

 543       * $crit = new Criteria();

 544       * $crit->add(&quot;column&quot;,

 545       *                                      &quot;value&quot;

 546       *                                      &quot;Criteria::GREATER_THAN&quot;);

 547       * </code>

 548       *

 549       * Any comparison can be used.

 550       *

 551       * The name of the table must be used implicitly in the column name,

 552       * so the Column name must be something like 'TABLE.id'. If you

 553       * don't like this, you can use the add(table, column, value) method.

 554       *

 555       * @param string $critOrColumn The column to run the comparison on, or Criterion object.

 556       * @param mixed $value

 557       * @param string $comparison A String.

 558       *

 559       * @return A modified Criteria object.

 560       */
 561      public function add($p1, $value = null, $comparison = null)
 562      {
 563          if ($p1 instanceof Criterion) {
 564              $c = $p1;
 565              $this->map[$c->getTable() . '.' . $c->getColumn()] = $c;
 566          } else {
 567              $column = $p1;
 568              $this->map[$column] = new Criterion($this, $column, $value, $comparison);
 569          }        
 570          return $this;
 571      }
 572  
 573      /**

 574       * This is the way that you should add a straight (inner) join of two tables.  For

 575       * example:

 576       *

 577       * <p>

 578       * AND PROJECT.PROJECT_ID=FOO.PROJECT_ID

 579       * <p>

 580       *

 581       * left = PROJECT.PROJECT_ID

 582       * right = FOO.PROJECT_ID

 583       *

 584       * @param string $left A String with the left side of the join.

 585       * @param string $right A String with the right side of the join.

 586           * @param string $operator A String with the join operator e.g. LEFT JOIN, ...

 587       * @return Criteria A modified Criteria object.

 588       */
 589      public function addJoin($left, $right, $operator = null)
 590      {
 591          $this->joins [] = new Join($left, $right, $operator);
 592  
 593          return $this;
 594      }
 595      
 596      /**

 597       * Get the array of Joins.  This method is meant to

 598       * be called by BasePeer.

 599       * @return an array which contains objects of type Join,

 600       *         or an empty array if the criteria does not contains any joins

 601       */
 602      function & getJoins()
 603      {
 604          return $this->joins;
 605      }
 606      
 607      /**

 608       * get one side of the set of possible joins.  This method is meant to

 609       * be called by BasePeer.

 610       * @return array

 611       * @deprecated This method is no longer used by BasePeer.

 612       */
 613      public function getJoinL()
 614      {
 615          throw new PropelException("getJoinL() in Criteria is no longer supported!");
 616      }
 617  
 618      /**

 619       * get one side of the set of possible joins.  This method is meant to

 620       * be called by BasePeer.

 621       * @return array

 622           * @deprecated This method is no longer used by BasePeer.

 623       */
 624      public function getJoinR()
 625      {
 626          throw new PropelException("getJoinL() in Criteria is no longer supported!");
 627      }    
 628      
 629      /**

 630       * Adds "ALL " to the SQL statement.

 631       * @return void

 632       */
 633      public function setAll()
 634      {
 635          $this->selectModifiers[] = self::ALL;
 636      }
 637  
 638      /**

 639       * Adds "DISTINCT " to the SQL statement.

 640       * @return void

 641       */
 642      public function setDistinct()
 643      {
 644          $this->selectModifiers[] = self::DISTINCT;
 645      }
 646  
 647      /**

 648       * Sets ignore case.

 649       *

 650       * @param boolean $b True if case should be ignored.

 651       * @return A modified Criteria object.

 652       */
 653      public function setIgnoreCase($b)
 654      {
 655          $this->ignoreCase = (boolean) $b;
 656          return $this;
 657      }
 658  
 659      /**

 660       * Is ignore case on or off?

 661       *

 662       * @return boolean True if case is ignored.

 663       */
 664      public function isIgnoreCase()
 665      {
 666          return $this->ignoreCase;
 667      }
 668  
 669      /**

 670       * Set single record?  Set this to <code>true</code> if you expect the query

 671       * to result in only a single result record (the default behaviour is to

 672       * throw a PropelException if multiple records are returned when the query

 673       * is executed).  This should be used in situations where returning multiple

 674       * rows would indicate an error of some sort.  If your query might return

 675       * multiple records but you are only interested in the first one then you

 676       * should be using setLimit(1).

 677       *

 678       * @param b set to <code>true</code> if you expect the query to select just

 679       * one record.

 680       * @return A modified Criteria object.

 681       */
 682      public function setSingleRecord($b)
 683      {
 684          $this->singleRecord = (boolean) $b;
 685          return $this;
 686      }
 687  
 688      /**

 689       * Is single record?

 690       *

 691       * @return boolean True if a single record is being returned.

 692       */
 693      public function isSingleRecord()
 694      {
 695          return $this->singleRecord;
 696      }
 697      
 698      /**

 699       * Set limit.

 700       *

 701       * @param limit An int with the value for limit.

 702       * @return A modified Criteria object.

 703       */
 704      public function setLimit($limit)
 705      {
 706          $this->limit = $limit;
 707          return $this;
 708      }
 709  
 710      /**

 711       * Get limit.

 712       *

 713       * @return int An int with the value for limit.

 714       */
 715      public function getLimit()
 716      {
 717          return $this->limit;
 718      }
 719  
 720      /**

 721       * Set offset.

 722       *

 723       * @param int $offset An int with the value for offset.

 724       * @return A modified Criteria object.

 725       */
 726      public function setOffset($offset)
 727      {
 728          $this->offset = $offset;
 729          return $this;
 730      }
 731  
 732      /**

 733       * Get offset.

 734       *

 735       * @return An int with the value for offset.

 736       */
 737      public function getOffset()
 738      {
 739          return $this->offset;
 740      }
 741  
 742      /**

 743       * Add select column.

 744       *

 745       * @param name A String with the name of the select column.

 746       * @return A modified Criteria object.

 747       */
 748      public function addSelectColumn($name)
 749      {
 750          $this->selectColumns[] = $name;
 751          return $this;
 752      }
 753  
 754      /**

 755       * Get select columns.

 756       *

 757       * @return array An array with the name of the select

 758       * columns.

 759       */
 760      public function getSelectColumns()
 761      {
 762          return $this->selectColumns;
 763      }
 764      
 765      /**

 766       * Clears current select columns.

 767       * 

 768       * @return Criteria A modified Criteria object.

 769       */
 770      public function clearSelectColumns() {
 771                  $this->selectColumns = array();
 772                  $this->asColumns = array();
 773          return $this;
 774      }
 775  
 776      /**

 777       * Get select modifiers.

 778       *

 779       * @return An array with the select modifiers.

 780       */
 781      public function getSelectModifiers()
 782      {
 783          return $this->selectModifiers;
 784      }
 785      
 786      /**

 787       * Add group by column name.

 788       *

 789       * @param string $groupBy The name of the column to group by.

 790       * @return A modified Criteria object.

 791       */
 792      public function addGroupByColumn($groupBy)
 793      {
 794          $this->groupByColumns[] = $groupBy;
 795          return $this;
 796      }
 797  
 798      /**

 799       * Add order by column name, explicitly specifying ascending.

 800       *

 801       * @param name The name of the column to order by.

 802       * @return A modified Criteria object.

 803       */
 804      public function addAscendingOrderByColumn($name)
 805      {
 806          $this->orderByColumns[] = $name . ' ' . self::ASC;
 807          return $this;
 808      }
 809  
 810      /**

 811       * Add order by column name, explicitly specifying descending.

 812       *

 813       * @param string $name The name of the column to order by.

 814       * @return Criteria The modified Criteria object.

 815       */
 816      public function addDescendingOrderByColumn($name)
 817      {
 818          $this->orderByColumns[] = $name . ' ' . self::DESC;
 819          return $this;
 820      }
 821  
 822      /**

 823       * Get order by columns.

 824       *

 825       * @return array An array with the name of the order columns.

 826       */
 827      public function getOrderByColumns()
 828      {
 829          return $this->orderByColumns;
 830      }
 831      
 832      /**

 833       * Clear the order-by columns.

 834       * 

 835       * @return Criteria 

 836       */
 837      public function clearOrderByColumns()
 838      {
 839          $this->orderByColumns = array();
 840          return $this;
 841      }
 842      
 843      /**

 844       * Clear the group-by columns.

 845       * 

 846       * @return Criteria 

 847       */
 848      public function clearGroupByColumns()
 849      {
 850          $this->groupByColumns = array();
 851          return $this;
 852      }
 853      
 854      /**

 855       * Get group by columns.

 856       *

 857       * @return array

 858       */
 859      public function getGroupByColumns()
 860      {
 861          return $this->groupByColumns;
 862      }
 863  
 864      /**

 865       * Get Having Criterion.

 866       *

 867       * @return Criterion A Criterion object that is the having clause.

 868       */
 869      public function getHaving()
 870      {
 871          return $this->having;
 872      }
 873  
 874      /**

 875       * Remove an object from the criteria.

 876       *

 877       * @param string $key A string with the key to be removed.

 878       * @return mixed The removed value.

 879       */
 880      public function remove($key)
 881      {
 882          $c = isset($this->map[$key]) ? $this->map[$key] : null;
 883          unset($this->map[$key]);
 884          if ($c instanceof Criterion) {
 885              return $c->getValue();
 886          }
 887          return $c;
 888      }
 889  
 890      /**

 891       * Build a string representation of the Criteria.

 892       *

 893       * @return string A String with the representation of the Criteria.

 894       */
 895      public function toString()
 896      {
 897          $sb = "Criteria:: ";        
 898  
 899          try {
 900              
 901              $sb .= "\nCurrent Query SQL (may not be complete or applicable): "
 902                . BasePeer::createSelectSql($this, $params=array());
 903               
 904              $sb .= "\nParameters to replace: " . var_export($params, true);
 905   
 906          } catch (Exception $exc) {
 907              $sb .= "(Error: " . $exc->getMessage() . ")";
 908          }
 909  
 910          return $sb;
 911      }
 912  
 913      /**

 914       * Returns the size (count) of this criteria.

 915       * @return int

 916       */
 917      public function size()
 918      {
 919          return count($this->map);
 920      }
 921      
 922      /**

 923       * This method checks another Criteria to see if they contain

 924       * the same attributes and hashtable entries.

 925       * @return boolean

 926       */
 927      public function equals($crit)
 928      {
 929          $isEquiv = false;
 930          if ($crit === null || !($crit instanceof Criteria)) {
 931              $isEquiv = false;
 932          } elseif ($this === $crit) {
 933              $isEquiv = true;
 934          } elseif ($this->size() === $crit->size()) {
 935              
 936              // Important: nested criterion objects are checked

 937              
 938              $criteria = $crit; // alias

 939              if ($this->offset === $criteria->getOffset()
 940                  && $this->limit === $criteria->getLimit()
 941                  && $this->ignoreCase === $criteria->isIgnoreCase()
 942                  && $this->singleRecord === $criteria->isSingleRecord()
 943                  && $this->dbName === $criteria->getDbName()
 944                  && $this->selectModifiers === $criteria->getSelectModifiers()
 945                  && $this->selectColumns === $criteria->getSelectColumns()
 946                  && $this->orderByColumns === $criteria->getOrderByColumns()
 947                 )
 948              {
 949                  $isEquiv = true;
 950                  foreach($criteria->keys() as $key) {
 951                      if ($this->containsKey($key)) {
 952                          $a = $this->getCriterion($key);
 953                          $b = $criteria->getCriterion($key);
 954                          if (!$a->equals($b)) {
 955                              $isEquiv = false;
 956                              break;
 957                          }
 958                      } else {
 959                          $isEquiv = false;
 960                          break;
 961                      }
 962                  }
 963              }
 964          }
 965          return $isEquiv;
 966      }
 967  
 968      /**

 969       * This method adds a prepared Criterion object to the Criteria as a having clause.

 970       * You can get a new, empty Criterion object with the

 971       * getNewCriterion() method.

 972       *

 973       * <p>

 974       * <code>

 975       * $crit = new Criteria();

 976       * $c = $crit->getNewCriterion(BasePeer::ID, 5, Criteria::LESS_THAN);

 977       * $crit->addHaving($c);

 978       * </code>

 979       *

 980       * @param having A Criterion object

 981       *

 982       * @return A modified Criteria object.

 983       */
 984      public function addHaving(Criterion $having)
 985      {
 986          $this->having = $having;
 987          return $this;
 988      }
 989  
 990      /**

 991       * This method adds a new criterion to the list of criterias.

 992       * If a criterion for the requested column already exists, it is

 993       * "AND"ed to the existing criterion.

 994        *

 995       * addAnd(column, value, comparison)

 996       * <code>

 997       * $crit = $orig_crit->addAnd(&quot;column&quot;,

 998       *                                      &quot;value&quot;

 999       *                                      &quot;Criterion::GREATER_THAN&quot;);

1000       * </code>

1001       *

1002       * addAnd(column, value)

1003       * <code>

1004       * $crit = $orig_crit->addAnd(&quot;column&quot;, &quot;value&quot;);

1005       * </code>

1006       *

1007       * addAnd(Criterion)

1008       * <code>

1009       * $crit = new Criteria();

1010       * $c = $crit->getNewCriterion(BasePeer::ID, 5, Criteria::LESS_THAN);

1011       * $crit->addAnd($c);

1012       * </code>

1013       *

1014       * Any comparison can be used, of course.

1015       *

1016       *

1017       * @return Criteria A modified Criteria object.

1018       */
1019      public function addAnd($p1, $p2 = null, $p3 = null)
1020      {        
1021          if ($p3 !== null) {            
1022              // addAnd(column, value, comparison)

1023              $oc = $this->getCriterion($p1);
1024              $nc = new Criterion($this, $p1, $p2, $p3);
1025              if ($oc === null) {
1026                  $this->map[$p1] = $nc;
1027              } else {
1028                  $oc->addAnd($nc);
1029              }
1030          } elseif ($p2 !== null) {
1031              // addAnd(column, value)

1032              $this->addAnd($p1, $p2, self::EQUAL);
1033          } elseif ($p1 instanceof Criterion) {
1034              // addAnd(Criterion)

1035              $c = $p1;
1036              $oc = $this->getCriterion($c->getTable() . '.' . $c->getColumn());
1037              if ($oc === null) {
1038                  $this->add($c);
1039              } else {
1040                  $oc->addAnd($c);
1041              }
1042          } elseif ($p2 === null && $p3 === null) {
1043              // client has not specified $p3 (comparison)

1044              // which means Criteria::EQUAL but has also specified $p2 == null 

1045              // which is a valid combination we should handle by creating "IS NULL"

1046              $this->addAnd($p1, $p2, self::EQUAL);
1047          }                                    
1048          return $this;
1049      }
1050      
1051      /**

1052       * This method adds a new criterion to the list of criterias.

1053       * If a criterion for the requested column already exists, it is

1054       * "OR"ed to the existing criterion.

1055       * 

1056       * Any comparison can be used.

1057       *

1058       * Supports a number of different signatures:

1059       * 

1060       * addOr(column, value, comparison)

1061       * <code>

1062       * $crit = $orig_crit->addOr(&quot;column&quot;,

1063       *                                      &quot;value&quot;

1064       *                                      &quot;Criterion::GREATER_THAN&quot;);

1065       * </code>

1066       *

1067       * addOr(column, value)

1068       * <code>

1069       * $crit = $orig_crit->addOr(&quot;column&quot;, &quot;value&quot;);

1070       * </code>

1071       * 

1072       * addOr(Criterion)

1073       * 

1074       * @return Criteria A modified Criteria object.

1075       */
1076      public function addOr($p1, $p2 = null, $p3 = null)
1077      {
1078          if ($p3 !== null) {            
1079              // addOr(column, value, comparison)

1080              $oc = $this->getCriterion($p1);
1081              $nc = new Criterion($this, $p1, $p2, $p3);
1082              if ($oc === null) {
1083                  $this->map[$p1] = $nc;
1084              } else {
1085                  $oc->addOr($nc);
1086              }                        
1087          } elseif ($p2 !== null) {
1088              // addOr(column, value)

1089              $this->addOr($p1, $p2, self::EQUAL);
1090          } elseif ($p1 instanceof Criterion) {
1091              // addOr(Criterion)

1092              $c = $p1;
1093              $oc = $this->getCriterion($c->getTable() . '.' . $c->getColumn());
1094              if ($oc === null) {
1095                  $this->add($c);
1096              } else {
1097                  $oc->addOr($c);
1098              }
1099          } elseif ($p2 === null && $p3 === null) {
1100              // client has not specified $p3 (comparison)

1101              // which means Criteria::EQUAL but has also specified $p2 == null 

1102              // which is a valid combination we should handle by creating "IS NULL"

1103              $this->addOr($p1, $p2, self::EQUAL);
1104          }
1105                                      
1106          return $this;
1107      }   
1108  }
1109  
1110  // --------------------------------------------------------------------

1111  // Criterion Iterator class -- allows foreach($criteria as $criterion)

1112  // --------------------------------------------------------------------

1113  
1114  /**

1115   * Class that implements SPL Iterator interface.  This allows foreach() to 

1116   * be used w/ Criteria objects.  Probably there is no performance advantage

1117   * to doing it this way, but it makes sense -- and simpler code.

1118   * 

1119   * @author Hans Lellelid <hans@xmpl.org>

1120   * @package propel.util

1121   */
1122  class CriterionIterator implements Iterator {
1123  
1124      private $idx = 0;
1125      private $criteria;
1126      private $criteriaKeys;
1127      private $criteriaSize;
1128      
1129      public function __construct($criteria) {
1130          $this->criteria = $criteria;
1131          $this->criteriaKeys = $criteria->keys();
1132          $this->criteriaSize = count($this->criteriaKeys);
1133      }
1134  
1135      public function rewind() {
1136          $this->idx = 0;
1137      }
1138      
1139      public function valid() {
1140          return $this->idx < $this->criteriaSize;
1141      }
1142      
1143      public function key() {
1144          return $this->criteriaKeys[$this->idx];
1145      }
1146      
1147      public function current() {
1148          return $this->criteria->getCriterion($this->criteriaKeys[$this->idx]);
1149      }
1150      
1151      public function next() {
1152          $this->idx++;
1153      }
1154  
1155  }
1156  
1157  // --------------------------------------------------------------------

1158  // Criterion "inner" class

1159  // --------------------------------------------------------------------

1160  
1161  /**

1162   * This is an "inner" class that describes an object in the criteria.

1163   *

1164   * In Torque this is an inner class of the Criteria class.

1165   *

1166   * @author Hans Lellelid <hans@xmpl.org> (Propel)

1167   * @package propel.util

1168   */
1169  class Criterion  {
1170  
1171      const UND = " AND ";
1172      const ODER = " OR ";
1173  
1174      /** Value of the CO. */

1175      private $value;
1176  
1177      /** Comparison value. 

1178       * @var SqlEnum

1179       */
1180      private $comparison;
1181  
1182      /** Table name. */

1183      private $table;
1184      
1185      /** Real table name */

1186      private $realtable;
1187  
1188      /** Column name. */

1189      private $column;
1190  
1191      /** flag to ignore case in comparision */

1192      private $ignoreStringCase = false;
1193  
1194      /**

1195       * The DBAdaptor which might be used to get db specific

1196       * variations of sql.

1197       */
1198      private $db;
1199  
1200      /**

1201       * other connected criteria and their conjunctions.

1202       */
1203      private $clauses = array();
1204      private $conjunctions = array();
1205  
1206      /** "Parent" Criteria class */

1207      private $parent;
1208      
1209      /**

1210       * Create a new instance.

1211       *

1212       * @param Criteria $parent The outer class (this is an "inner" class).

1213       * @param string $column TABLE.COLUMN format.

1214       * @param mixed $value

1215       * @param string $comparison

1216       */
1217      public function __construct(Criteria $outer, $column, $value, $comparison = null)
1218      {              
1219          list($this->table, $this->column) = explode('.', $column);        
1220          $this->value = $value;
1221          $this->comparison = ($comparison === null ? Criteria::EQUAL : $comparison);
1222          $this->init($outer);
1223      }
1224          
1225      /**

1226      * Init some properties with the help of outer class

1227      * @param Criteria $criteria The outer class

1228      */
1229      public function init(Criteria $criteria)
1230      {
1231          //init $this->db

1232          try {
1233              $db = Propel::getDB($criteria->getDbName());
1234              $this->setDB($db);
1235          } catch (Exception $e) {
1236              // we are only doing this to allow easier debugging, so

1237              // no need to throw up the exception, just make note of it.

1238              Propel::log("Could not get a DBAdapter, so sql may be wrong", Propel::LOG_ERR);
1239          }
1240          
1241          //init $this->realtable

1242          $realtable = $criteria->getTableForAlias($this->table);
1243          if(!$realtable) $realtable = $this->table;
1244          $this->realtable = $realtable;                
1245          
1246      }
1247      
1248      /**

1249       * Get the column name.

1250       *

1251       * @return string A String with the column name.

1252       */
1253      public function getColumn()
1254      {
1255          return $this->column;
1256      }
1257  
1258      /**

1259       * Set the table name.

1260       *

1261       * @param name A String with the table name.

1262       * @return void

1263       */
1264      public function setTable($name)
1265      {
1266          $this->table = $name;
1267      }
1268  
1269      /**

1270       * Get the table name.

1271       *

1272       * @return string A String with the table name.

1273       */
1274      public function getTable()
1275      {
1276          return $this->table;
1277      }
1278  
1279      /**

1280       * Get the comparison.

1281       *

1282       * @return string A String with the comparison.

1283       */
1284      public function getComparison()
1285      {
1286          return $this->comparison;
1287      }
1288  
1289      /**

1290       * Get the value.

1291       *

1292       * @return mixed An Object with the value.

1293       */
1294      public function getValue()
1295      {
1296          return $this->value;
1297      }
1298  
1299      /**

1300       * Get the value of db.

1301       * The DBAdapter which might be used to get db specific

1302       * variations of sql.

1303       * @return DBAdapter value of db.

1304       */
1305      public function getDB()
1306      {
1307          return $this->db;
1308      }
1309  
1310      /**

1311       * Set the value of db.

1312       * The DBAdapter might be used to get db specific variations of sql.

1313       * @param DBAdapter $v Value to assign to db.

1314       * @return void

1315       */
1316      public function setDB(DBAdapter $v)
1317      {
1318          $this->db = $v;
1319          for($i=0, $_i=count($this->clauses); $i < $_i; $i++) {
1320              $this->clauses[$i]->setDB($v);
1321          }
1322      }
1323  
1324      /**

1325       * Sets ignore case.

1326       *

1327       * @param boolean $b True if case should be ignored.

1328       * @return Criterion A modified Criterion object.

1329       */
1330      public function setIgnoreCase($b)
1331      {
1332          $this->ignoreStringCase = $b;
1333          return $this;
1334      }
1335  
1336      /**

1337       * Is ignore case on or off?

1338       *

1339       * @return boolean True if case is ignored.

1340       */
1341       public function isIgnoreCase()
1342       {
1343           return $this->ignoreStringCase;
1344       }
1345  
1346      /**

1347       * Get the list of clauses in this Criterion.

1348       * @return array

1349       */
1350      private function getClauses()
1351      {
1352          return $this->clauses;
1353      }
1354  
1355      /**

1356       * Get the list of conjunctions in this Criterion

1357       * @return array

1358       */
1359      private function getConjunctions()
1360      {
1361          return $this->conjunctions;
1362      }
1363  
1364      /**

1365       * Append an AND Criterion onto this Criterion's list.

1366       */
1367      public function addAnd(Criterion $criterion)
1368      {
1369          $this->clauses[] = $criterion;
1370          $this->conjunctions[] = self::UND;
1371          return $this;
1372      }
1373  
1374      /**

1375       * Append an OR Criterion onto this Criterion's list.

1376       * @return Criterion

1377       */
1378      public function addOr(Criterion $criterion)
1379      {
1380          $this->clauses[] = $criterion;
1381          $this->conjunctions[] = self::ODER;
1382          return $this;
1383      }    
1384  
1385      /**

1386       * Appends a Prepared Statement representation of the Criterion

1387       * onto the buffer.

1388       *

1389       * @param string &$sb The stringbuffer that will receive the Prepared Statement

1390       * @param array $params A list to which Prepared Statement parameters

1391       * will be appended

1392       * @return void

1393       * @throws PropelException - if the expression builder cannot figure out how to turn a specified 

1394       *                           expression into proper SQL.

1395       */
1396      public function appendPsTo(&$sb, &$params)
1397      {
1398          if ($this->column === null) {
1399              return;
1400          }
1401  
1402          $db = $this->getDb();
1403          $clausesLength = count($this->clauses);
1404          for($j = 0; $j < $clausesLength; $j++) {
1405              $sb .= '(';
1406          }
1407          
1408          if (Criteria::CUSTOM === $this->comparison) {
1409              if ($this->value !== "") {
1410                  $sb .= (string) $this->value;
1411              }
1412          } else {
1413          
1414              if  ($this->table === null) {
1415                  $field = $this->column;
1416              } else {
1417                  $field = $this->table . '.' . $this->column;
1418              }
1419  
1420              // Check to see if table is an alias & store real name, if so

1421              // (real table name is needed for the returned $params array)

1422              $realtable = $this->realtable;
1423              
1424              // There are several different types of expressions that need individual handling:

1425              // IN/NOT IN, LIKE/NOT LIKE, and traditional expressions.

1426              
1427              // OPTION 1:  table.column IN (?, ?) or table.column NOT IN (?, ?)

1428              if ($this->comparison === Criteria::IN || $this->comparison === Criteria::NOT_IN) {
1429              
1430                  $values = (array) $this->value;
1431                  $valuesLength = count($values);
1432                  if ($valuesLength == 0) {
1433                      // a SQL error will result if we have COLUMN IN (), so replace it with an expression

1434                      // that will always evaluate to FALSE for Criteria::IN and TRUE for Criteria::NOT_IN

1435                      $sb .= ($this->comparison === Criteria::IN) ? "1<>1" : "1=1";
1436                  } else {
1437                      $sb .= $field . $this->comparison;
1438                      for ($i=0; $i < $valuesLength; $i++) {
1439                          $params[] = array('table' => $realtable, 'column' => $this->column, 'value' => $values[$i]);
1440                      }
1441                      $inString = '(' . substr(str_repeat("?,", $valuesLength), 0, -1) . ')';
1442                      $sb .= $inString;
1443                  }
1444              
1445              // OPTION 2:  table.column LIKE ? or table.column NOT LIKE ?  (or ILIKE for Postgres)

1446              } elseif ($this->comparison === Criteria::LIKE || $this->comparison === Criteria::NOT_LIKE 
1447                  || $this->comparison === Criteria::ILIKE || $this->comparison === Criteria::NOT_ILIKE) {
1448                  // Handle LIKE, NOT LIKE (and related ILIKE, NOT ILIKE for Postgres)

1449                  
1450                  // If selection is case insensitive use ILIKE for PostgreSQL or SQL 

1451                  // UPPER() function on column name for other databases.

1452                  if ($this->ignoreStringCase) {
1453                      include_once 'propel/adapter/DBPostgres.php'; // for instanceof, since is_a() is not E_STRICT

1454                      if ($db instanceof DBPostgres) { // use is_a() because instanceof needs class to have been loaded
1455                          if ($this->comparison === Criteria::LIKE) {
1456                              $this->comparison = Criteria::ILIKE; 
1457                          } elseif ($this->comparison === Criteria::NOT_LIKE) {
1458                              $this->comparison = Criteria::NOT_ILIKE; 
1459                            }
1460                      } else {
1461                          $field = $db->ignoreCase($field);
1462                      }
1463                  }
1464                  
1465                  $sb .= $field . $this->comparison;
1466          
1467                  // If selection is case insensitive use SQL UPPER() function

1468                  // on criteria or, if Postgres we are using ILIKE, so not necessary.

1469                  if ($this->ignoreStringCase && !($db instanceof DBPostgres)) {
1470                      $sb .= $db->ignoreCase('?');
1471                  } else {
1472                      $sb .= '?';
1473                  }
1474                  
1475                  $params[] = array('table' => $realtable, 'column' => $this->column, 'value' => $this->value);
1476              
1477              // OPTION 3:  table.column = ? or table.column >= ? etc. (traditional expressions, the default)

1478              } else {            
1479              
1480                  // NULL VALUES need special treatment because the SQL syntax is different

1481                  // i.e. table.column IS NULL rather than table.column = null

1482                  if ($this->value !== null) {
1483                  
1484                      // ANSI SQL functions get inserted right into SQL (not escaped, etc.)                    

1485                      if ($this->value === Criteria::CURRENT_DATE || $this->value === Criteria::CURRENT_TIME || $this->value === Criteria::CURRENT_TIMESTAMP) {
1486                          $sb .= $field . $this->comparison . $this->value;
1487                      } else {
1488                          // default case, it is a normal col = value expression; value

1489                          // will be replaced w/ '?' and will be inserted later using native Creole functions

1490                          if ($this->ignoreStringCase) {
1491                              $sb .= $db->ignoreCase($field) . $this->comparison . $db->ignoreCase("?");
1492                          } else {
1493                              $sb .= $field . $this->comparison . "?";
1494                          }
1495                          // need to track the field in params, because

1496                          // we'll need it to determine the correct setter

1497                          // method later on (e.g. field 'review.DATE' => setDate());

1498                          $params[] = array('table' => $realtable, 'column' => $this->column, 'value' => $this->value);                        
1499                      }
1500                  } else {
1501                      
1502                      // value is null, which means it was either not specified or specifically

1503                      // set to null.                    

1504                      if ($this->comparison === Criteria::EQUAL || $this->comparison === Criteria::ISNULL) {
1505                          $sb .= $field . Criteria::ISNULL;
1506                      } elseif ($this->comparison === Criteria::NOT_EQUAL || $this->comparison === Criteria::ISNOTNULL) {
1507                          $sb .= $field . Criteria::ISNOTNULL;
1508                      } else {
1509                          // for now throw an exception, because not sure how to interpret this

1510                          throw new PropelException("Could not build SQL for expression: $field " . $this->comparison . " NULL");
1511                      }
1512                                          
1513                  }
1514                  
1515              }
1516          }
1517          
1518          for($i=0; $i < $clausesLength; $i++) {
1519              $sb .= $this->conjunctions[$i];
1520              $this->clauses[$i]->appendPsTo($sb, $params);
1521              $sb .= ')';
1522          }
1523      }
1524  
1525      /**

1526       * This method checks another Criteria to see if they contain

1527       * the same attributes and hashtable entries.

1528       * @return boolean

1529       */
1530      public function equals($obj)
1531      {
1532          if ($this === $obj) {
1533              return true;
1534          }
1535  
1536          if (($obj === null) || !($obj instanceof Criterion)) {
1537              return false;
1538          }
1539  
1540          $crit = $obj;
1541  
1542          $isEquiv = ( ( ($this->table === null && $crit->getTable() === null)
1543              || ( $this->table !== null && $this->table === $crit->getTable() )
1544                            )
1545              && $this->column === $crit->getColumn()
1546              && $this->comparison === $crit->getComparison());
1547  
1548          // check chained criterion

1549          
1550          $clausesLength = count($this->clauses);
1551          $isEquiv &= (count($crit->getClauses()) == $clausesLength);
1552          $critConjunctions = $crit->getConjunctions();
1553          $critClauses = $crit->getClauses();
1554          for ($i=0; $i < $clausesLength && $isEquiv; $i++) {
1555              $isEquiv &= ($this->conjunctions[$i] === $critConjunctions[$i]);
1556              $isEquiv &= ($this->clauses[$i] === $critClauses[$i]);
1557          }
1558          
1559          if ($isEquiv) {
1560              $isEquiv &= $this->value === $crit->getValue();
1561          }
1562          
1563          return $isEquiv;
1564      }
1565  
1566      /**

1567       * Returns a hash code value for the object.

1568       */
1569      public function hashCode()
1570      {
1571          $h = crc32(serialize($this->value)) ^ crc32($this->comparison);
1572  
1573          if ($this->table !== null) {
1574              $h ^= crc32($this->table);
1575          }
1576  
1577          if ($this->column !== null) {
1578              $h ^= crc32($this->column);
1579          }
1580          
1581          $clausesLength = count($this->clauses);
1582          for($i=0; $i < $clausesLength; $i++) {
1583              $this->clauses[$i]->appendPsTo($sb="", $params=array());
1584              $h ^= crc32(serialize(array($sb, $params)));
1585          }
1586  
1587          return $h;
1588      }
1589  
1590      /**

1591       * Get all tables from nested criterion objects

1592       * @return array

1593       */
1594      public function getAllTables()
1595      {
1596          $tables = array();
1597          $this->addCriterionTable($this, $tables);
1598          return $tables;
1599      }
1600  
1601      /**

1602       * method supporting recursion through all criterions to give

1603       * us a string array of tables from each criterion

1604       * @return void

1605       */
1606      private function addCriterionTable(Criterion $c, &$s)
1607      {
1608          $s[] = $c->getTable();
1609          $clauses = $c->getClauses();
1610          $clausesLength = count($clauses);
1611          for($i = 0; $i < $clausesLength; $i++) {
1612              $this->addCriterionTable($clauses[$i], $s);
1613          }        
1614      }
1615  
1616      /**

1617       * get an array of all criterion attached to this

1618       * recursing through all sub criterion

1619       * @return array Criterion[]

1620       */
1621      public function getAttachedCriterion()
1622      {
1623          $crits = array();
1624          $this->traverseCriterion($this, $crits);
1625          return $crits;        
1626      }
1627  
1628      /**

1629       * method supporting recursion through all criterions to give

1630       * us an array of them

1631       * @param Criterion $c

1632       * @param array &$a

1633       * @return void

1634       */
1635      private function traverseCriterion(Criterion $c, &$a)
1636      {        
1637          $a[] = $c;
1638          $clauses = $c->getClauses();
1639          $clausesLength = count($clauses);
1640          for($i=0; $i < $clausesLength; $i++) {
1641              $this->traverseCriterion($clauses[$i], $a);
1642          }        
1643      }
1644  }
1645  
1646  /**

1647  * Data object to describe a join between two tables, for example

1648  * <pre>

1649  * table_a LEFT JOIN table_b ON table_a.id = table_b.a_id

1650  * </pre>

1651  */
1652  class Join
1653  {
1654      /** the left column of the join condition */

1655      private $leftColumn = null;
1656  
1657      /** the right column of the join condition */

1658      private $rightColumn = null;
1659  
1660      /** the type of the join (LEFT JOIN, ...), or null */

1661      private $joinType = null;
1662  
1663      /**

1664       * Constructor

1665       * @param leftColumn the left column of the join condition;

1666       *        might contain an alias name

1667       * @param rightColumn the right column of the join condition

1668       *        might contain an alias name

1669       * @param joinType the type of the join. Valid join types are

1670       *        null (adding the join condition to the where clause),

1671       *        Criteria::LEFT_JOIN(), Criteria::RIGHT_JOIN(), and Criteria::INNER_JOIN()

1672       */
1673      public function __construct($leftColumn, $rightColumn, $joinType = null)
1674      {
1675          $this->leftColumn = $leftColumn;
1676          $this->rightColumn = $rightColumn;
1677          $this->joinType = $joinType;
1678      }
1679  
1680      /**

1681       * @return the type of the join, i.e. Criteria::LEFT_JOIN(), ...,

1682       *         or null for adding the join condition to the where Clause

1683       */
1684      public function getJoinType()
1685      {
1686          return $this->joinType;
1687      }
1688  
1689      /**

1690       * @return the left column of the join condition

1691       */
1692      public function getLeftColumn()
1693      {
1694          return $this->leftColumn;
1695      }
1696  
1697  		public function getLeftColumnName()
1698          {
1699              return substr($this->leftColumn, strpos($this->leftColumn, '.') + 1);
1700          }
1701          
1702  		public function getLeftTableName()
1703          {
1704              return substr($this->leftColumn, 0, strpos($this->leftColumn, '.'));
1705          }
1706          
1707      /**

1708       * @return the right column of the join condition

1709       */
1710      public function getRightColumn()
1711      {
1712          return $this->rightColumn;
1713      }
1714          
1715  		public function getRightColumnName()
1716          {
1717              return substr($this->rightColumn, strpos($this->rightColumn, '.') + 1);
1718          }
1719          
1720  		public function getRightTableName()
1721          {
1722              return substr($this->rightColumn, 0, strpos($this->rightColumn, '.'));
1723          }
1724  
1725      /**

1726       * returns a String representation of the class,

1727       * mainly for debugging purposes

1728       * @return a String representation of the class

1729       */
1730      public function toString()
1731      {
1732          $result = "";
1733          if ($this->joinType != null)
1734          {
1735              $result .= $this->joinType . " : ";
1736          }
1737          $result .= $this->leftColumn . "=" . $this->rightColumn . " (ignoreCase not considered)";
1738  
1739          return $result;
1740      }
1741  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7