QueryCombination.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2004-2007 by Konstantin V. Arkhipov, Anton E. Lebedevich *
00004  *                                                                          *
00005  *   This program is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Lesser General Public License as         *
00007  *   published by the Free Software Foundation; either version 3 of the     *
00008  *   License, or (at your option) any later version.                        *
00009  *                                                                          *
00010  ****************************************************************************/
00011 /* $Id: QueryCombination.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class QueryCombination
00017         extends QueryIdentification
00018         implements DialectString
00019     {
00020         private $left   = null;
00021         private $right  = null;
00022         private $logic  = null;
00023         
00024         private $limit  = null;
00025         private $offset = null;
00026         
00027         private $order  = null;
00028         
00029         public function __construct(
00030             Query $left,
00031             Query $right,
00032             $logic
00033         )
00034         {
00035             $this->left     = $left;
00036             $this->right    = $right;
00037             $this->logic    = $logic;
00038             $this->order    = new OrderChain();
00039         }
00040         
00041         public function __clone()
00042         {
00043             $this->left = clone $this->left;
00044             $this->right = clone $this->right;
00045             $this->order = clone $this->order;
00046         }
00047         
00048         public function getLimit()
00049         {
00050             return $this->limit;
00051         }
00052         
00053         public function getOffset()
00054         {
00055             return $this->offset;
00056         }
00057 
00062         public function limit($limit = null, $offset = null)
00063         {
00064             if ($limit !== null)
00065                 Assert::isPositiveInteger($limit, 'invalid limit specified');
00066                 
00067             if ($offset !== null)
00068                 Assert::isInteger($offset, 'invalid offset specified');
00069             
00070             $this->limit = $limit;
00071             $this->offset = $offset;
00072             
00073             return $this;
00074         }
00075         
00079         public function dropOrder()
00080         {
00081             $this->order = new OrderChain();
00082             return $this;
00083         }
00084         
00088         public function setOrderChain(OrderChain $chain)
00089         {
00090             $this->order = $chain;
00091             
00092             return $this;
00093         }
00094         
00098         public function orderBy($field)
00099         {
00100             $this->order->add($field);
00101             
00102             return $this;
00103         }
00104 
00105         public function toDialectString(Dialect $dialect)
00106         {
00107             $query =
00108                 $this->left->toDialectString($dialect)
00109                 ." {$this->logic} "
00110                 .$this->right->toDialectString($dialect);
00111                 
00112             if ($this->order->getCount()) {
00113                 $query .= ' ORDER BY '.$this->order->toDialectString($dialect);
00114             }
00115             
00116             if ($this->limit)
00117                 $query .= " LIMIT {$this->limit}";
00118             
00119             if ($this->offset)
00120                 $query .= " OFFSET {$this->offset}";
00121                 
00122             return $query;
00123         }
00124     }
00125 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4