00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class Joiner implements DialectString
00017 {
00018 private $from = array();
00019 private $tables = array();
00020
00024 public function from(FromTable $from)
00025 {
00026 $this->from[] = $from;
00027
00028 return $this;
00029 }
00030
00031 public function hasJoinedTable($table)
00032 {
00033 return isset($this->tables[$table]);
00034 }
00035
00036 public function getTablesCount()
00037 {
00038 return count($this->from);
00039 }
00040
00044 public function join(SQLJoin $join)
00045 {
00046 $this->from[] = $join;
00047 $this->tables[$join->getTable()] = true;
00048
00049 return $this;
00050 }
00051
00055 public function leftJoin(SQLLeftJoin $join)
00056 {
00057 $this->from[] = $join;
00058 $this->tables[$join->getTable()] = true;
00059
00060 return $this;
00061 }
00062
00063 public function getLastTable()
00064 {
00065 if ($this->from)
00066 return $this->from[count($this->from) - 1]->getTable();
00067
00068 return null;
00069 }
00070
00071 public function toDialectString(Dialect $dialect)
00072 {
00073 $fromString = null;
00074
00075 for ($i = 0, $size = count($this->from); $i < $size; ++$i) {
00076 if ($i == 0)
00077 $separator = null;
00078 elseif (
00079 $this->from[$i] instanceof FromTable &&
00080 !$this->from[$i]->getTable() instanceof SelectQuery
00081 )
00082 $separator = ', ';
00083 else
00084 $separator = ' ';
00085
00086 $fromString .=
00087 $separator
00088 .$this->from[$i]->toDialectString($dialect);
00089 }
00090
00091 if ($fromString)
00092 return ' FROM '.$fromString;
00093
00094 return null;
00095 }
00096 }
00097 ?>