Source for file JoinCondition.php

Documentation is available at JoinCondition.php

  1. <?php
  2. /*
  3.  *  $Id: JoinCondition.php 2217 2007-08-11 21:53:02Z zYne $
  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, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21. Doctrine::autoload('Doctrine_Query_Part');
  22. /**
  23.  * Doctrine_Query_JoinCondition
  24.  *
  25.  * @package     Doctrine
  26.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  27.  * @category    Object Relational Mapping
  28.  * @link        www.phpdoctrine.com
  29.  * @since       1.0
  30.  * @version     $Revision: 2217 $
  31.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  32.  */
  33. {
  34.     public function load($condition
  35.     {
  36.         $condition trim($condition);
  37.  
  38.         $e         Doctrine_Tokenizer::sqlExplode($condition);
  39.  
  40.         if(count($e2{
  41.             $a         explode('.'$e[0]);
  42.             $field     array_pop($a);
  43.             $reference implode('.'$a);
  44.             $operator  $e[1];
  45.             $value     $e[2];
  46.  
  47.             $alias     $this->query->getTableAlias($reference);
  48.             $map       $this->query->getAliasDeclaration($reference);
  49.             $table     $map['table'];
  50.             // check if value is enumerated value
  51.             $enumIndex $table->enumIndex($fieldtrim($value"'"));
  52.  
  53.  
  54.             if (substr($value01== '('{
  55.                 // trim brackets
  56.                 $trimmed   Doctrine_Tokenizer::bracketTrim($value);
  57.  
  58.                 if (substr($trimmed04== 'FROM' || substr($trimmed06== 'SELECT'{
  59.                     // subquery found
  60.                     $q $this->query->createSubquery();
  61.                     $value '(' $q->parseQuery($trimmed)->getQuery(')';
  62.                 elseif (substr($trimmed04== 'SQL:'{
  63.                     $value '(' substr($trimmed4')';
  64.                 else {
  65.                     // simple in expression found
  66.                     $e     Doctrine_Tokenizer::sqlExplode($trimmed',');
  67.  
  68.                     $value array();
  69.                     foreach ($e as $part{
  70.                         $index   $table->enumIndex($fieldtrim($part"'"));
  71.                         if ($index !== false{
  72.                             $value[$index;
  73.                         else {
  74.                             $value[$this->parseLiteralValue($part);
  75.                         }
  76.                     }
  77.                     $value '(' implode(', '$value')';
  78.                 }
  79.             else {
  80.                 if ($enumIndex !== false{
  81.                     $value $enumIndex;
  82.                 else {
  83.                     $value $this->parseLiteralValue($value);
  84.                 }
  85.             }
  86.  
  87.             switch ($operator{
  88.                 case '<':
  89.                 case '>':
  90.                 case '=':
  91.                 case '!=':
  92.                     if ($enumIndex !== false{
  93.                         $value  $enumIndex;
  94.                     }
  95.                 default:
  96.                     $condition  $alias '.' $field ' '
  97.                                 . $operator ' ' $value;
  98.             }
  99.  
  100.         }
  101.         return $condition;
  102.     }
  103. }