class image_gallery_join_subquery in Image 6
Same name and namespace in other branches
- 7 contrib/image_gallery/views/image_gallery.views.inc \image_gallery_join_subquery
Join handler for relationships that join with a subquery as the left field. To use this join, set 'left query' in the definition as a subquery to go on the left side of the JOIN condition, ie: LEFT JOIN node node_term_data ON ([YOUR SUBQUERY HERE]) = node_term_data.nid This should ultimately be replaced with the stuff for general groupwise max relationships in views:
Hierarchy
- class \image_gallery_join_subquery extends \views_join
Expanded class hierarchy of image_gallery_join_subquery
See also
<http://drupal.org/node/470258>.
File
- contrib/
image_gallery/ views/ image_gallery.views.inc, line 242 - Image Gallery views integration.
View source
class image_gallery_join_subquery extends views_join {
// PHP 4 doesn't call constructors of the base class automatically from a
// constructor of a derived class. It is your responsibility to propagate
// the call to constructors upstream where appropriate.
function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') {
parent::construct($table, $left_table, $left_field, $field, $extra, $type);
$this->left_query = $this->definition['left query'];
}
/**
* 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 ({$this->left_query}) = {$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. Set $q to
// a single-quote for non-numeric values and the
// empty-string for numeric values, then wrap all values in $q.
$raw_value = $this
->db_safe($info['value']);
$q = empty($info['numeric']) ? "'" : '';
if (is_array($raw_value)) {
$operator = !empty($info['operator']) ? $info['operator'] : 'IN';
// Transform from IN() notation to = notation if just one value.
if (count($raw_value) == 1) {
$value = $q . array_shift($raw_value) . $q;
$operator = $operator == 'NOT IN' ? '!=' : '=';
}
else {
$value = "({$q}" . implode("{$q}, {$q}", $raw_value) . "{$q})";
}
}
else {
$operator = !empty($info['operator']) ? $info['operator'] : '=';
$value = "{$q}{$raw_value}{$q}";
}
$extras[] = "{$join_table}{$info['field']} {$operator} {$value}";
}
if ($extras) {
if (count($extras) == 1) {
$output .= ' AND ' . array_shift($extras);
}
else {
$output .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')';
}
}
}
else {
if ($this->extra && is_string($this->extra)) {
$output .= " AND ({$this->extra})";
}
}
}
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
image_gallery_join_subquery:: |
function | |||
image_gallery_join_subquery:: |
function | Build the SQL for the join this object represents. |