extra_type = 'AND'; if (!empty($table)) { $this->table = $table; $this->left_table = $left_table; $this->left_field = $left_field; $this->field = $field; $this->extra = $extra; $this->type = strtoupper($type); } else if (!empty($this->definition)) { // if no arguments, construct from definition. // These four must exist or it will throw notices. $this->table = $this->definition['table']; $this->left_table = $this->definition['left_table']; $this->left_field = $this->definition['left_field']; $this->field = $this->definition['field']; if (!empty($this->definition['extra'])) { $this->extra = $this->definition['extra']; } if (!empty($this->definition['extra type'])) { $this->extra = strtoupper($this->definition['extra_type']); } $this->type = !empty($this->definition['type']) ? strtoupper($this->definition['type']) : 'LEFT'; } } /** * Build the SQL for the join this object represents. */ function join($table, &$query) { $left = $query->get_table_info($this->left_table); $output = " $this->type JOIN {" . $this->table . "} $table[alias] ON $left[alias].$this->left_field = $table[alias].$this->field"; // Tack on the extra. if (isset($this->extra)) { if (is_array($this->extra)) { $extras = array(); foreach ($this->extra as $info) { $extra = ''; // Figure out the table name. Remember, only use aliases provided // if at all possible. $join_table = ''; if (!array_key_exists('table', $info)) { $join_table = $table['alias'] . '.'; } elseif (isset($info['table'])) { $join_table = $info['table'] . '.'; } // And now deal with the value and the operator $value = $info['value']; if (is_array($value) && !empty($value)) { $extra = "$join_table$info[field] IN ('". implode("','", $value) ."')"; } else { $operator = "="; if (!empty($info['operator'])) { $operator = $info['operator']; } if (empty($info['numeric'])) { $extra .= "$join_table$info[field] $operator '$value'"; } else { $extra .= "$join_table$info[field] $operator $value"; } } $extras[] = $extra; } if ($extras) { $output .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')'; } } else if ($this->extra && is_string($this->extra)) { $output .= " AND ($this->extra)"; } } return $output; } } /** * @} */