/packages/Db/QueryBuilder/Objects/Expr/Join.php
PHP | 80 lines | 41 code | 9 blank | 30 comment | 1 complexity | 10f76f9248d32acca197017e22c5e821 MD5 | raw file
1<?php
2/*
3 * $Id$
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.doctrine-project.org>.
20 */
21
22/**
23 * Expression class for SQL from
24 *
25 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
26 * @link www.doctrine-project.org
27 * @since 2.0
28 * @version $Revision$
29 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
30 * @author Jonathan Wage <jonwage@gmail.com>
31 * @author Roman Borschel <roman@code-factory.org>
32 */
33class Join extends QBpart
34{
35 const INNER_JOIN = 'INNER';
36 const LEFT_JOIN = 'LEFT';
37 const RIGHT_JOIN = 'RIGHT';
38 const OUTER_JOIN = 'OUTER';
39
40 const ON = 'ON';
41 const WITH = 'WITH';
42
43 private $_joinType;
44 private $_join;
45 private $_alias;
46 private $_condition;
47 private $_indexBy;
48
49 public function __construct($joinType, $join, $alias = null, $condition = null, $indexBy = null)
50 {
51 $this->_joinType = $joinType;
52 $this->_join = $join;
53 $this->_alias = $alias;
54 $this->_condition = $condition;
55 $this->_indexBy = $indexBy;
56 }
57
58 public function getAlias()
59 {
60 return $this->_alias;
61 }
62
63 public function __toString()
64 {
65 $returnString = strtoupper($this->_joinType) . ' JOIN ';
66
67 if($this->_join instanceof QueryBuilder or $this->_join instanceof Unionx){
68 $returnString .= "($this->_join)";
69 }
70 else{
71 $returnString .= "`$this->_join`";
72 }
73
74 $returnString .= ($this->_alias ? ' as `' . $this->_alias . '`' : '')
75 . ($this->_condition ? ' ON (' . $this->_condition . ')' : '')
76 . ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : '');
77
78 return $returnString;
79 }
80}