00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 abstract class QuerySkeleton extends QueryIdentification
00017 {
00018 protected $where = array();
00019 protected $whereLogic = array();
00020
00025 public function where(LogicalObject $exp, $logic = null)
00026 {
00027 if ($this->where && !$logic)
00028 throw new WrongArgumentException(
00029 'you have to specify expression logic'
00030 );
00031 else {
00032 if (!$this->where && $logic)
00033 $logic = null;
00034
00035 $this->whereLogic[] = $logic;
00036 $this->where[] = $exp;
00037 }
00038
00039 return $this;
00040 }
00041
00045 public function andWhere(LogicalObject $exp)
00046 {
00047 return $this->where($exp, 'AND');
00048 }
00049
00053 public function orWhere(LogicalObject $exp)
00054 {
00055 return $this->where($exp, 'OR');
00056 }
00057
00058 public function toDialectString(Dialect $dialect)
00059 {
00060 if ($this->where) {
00061 $clause = ' WHERE';
00062 $outputLogic = false;
00063
00064 for ($i = 0, $size = count($this->where); $i < $size; ++$i) {
00065
00066 if ($exp = $this->where[$i]->toDialectString($dialect)) {
00067
00068 $clause .= "{$this->whereLogic[$i]} {$exp} ";
00069 $outputLogic = true;
00070
00071 } elseif (!$outputLogic && isset($this->whereLogic[$i + 1]))
00072 $this->whereLogic[$i + 1] = null;
00073
00074 }
00075
00076 return $clause;
00077 }
00078
00079 return null;
00080 }
00081 }
00082 ?>