/packages/Db/QueryBuilder/Objects/Expr/Join.php

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