Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class QueryCombination
00016 extends QueryIdentification
00017 implements DialectString
00018 {
00019 private $left = null;
00020 private $right = null;
00021 private $logic = null;
00022
00023 private $limit = null;
00024 private $offset = null;
00025
00026 private $order = null;
00027
00028 public function __construct(
00029 Query $left,
00030 Query $right,
00031 $logic
00032 )
00033 {
00034 $this->left = $left;
00035 $this->right = $right;
00036 $this->logic = $logic;
00037 $this->order = new OrderChain();
00038 }
00039
00040 public function __clone()
00041 {
00042 $this->left = clone $this->left;
00043 $this->right = clone $this->right;
00044 $this->order = clone $this->order;
00045 }
00046
00047 public function getLimit()
00048 {
00049 return $this->limit;
00050 }
00051
00052 public function getOffset()
00053 {
00054 return $this->offset;
00055 }
00056
00061 public function limit($limit = null, $offset = null)
00062 {
00063 if ($limit !== null)
00064 Assert::isPositiveInteger($limit, 'invalid limit specified');
00065
00066 if ($offset !== null)
00067 Assert::isInteger($offset, 'invalid offset specified');
00068
00069 $this->limit = $limit;
00070 $this->offset = $offset;
00071
00072 return $this;
00073 }
00074
00078 public function dropOrder()
00079 {
00080 $this->order = new OrderChain();
00081
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 ?>