function get_join_clause($join_type = 'LEFT JOIN') { $this->join_clause = back_quote_smart($this->tables); foreach ($this->relations as $key => $rel) { if ($rel['type'] == '1-1') { $this->join_clause .= ' ' . $join_type . ' ' . back_quote_smart($rel['table']); if (isset($rel['alias']) && $rel['alias'] != '') { $this->join_clause .= ' ' . back_quote_smart($rel['alias']) . ' ON ' . back_quote_smart($this->tables) . '.' . back_quote_smart($rel['link_child']) . ' = ' . back_quote_smart($rel['alias']) . '.' . back_quote_smart($rel['link_parent']); } else { $this->join_clause .= ' ON ' . back_quote_smart($this->tables) . '.' . back_quote_smart($rel['link_child']) . ' = ' . back_quote_smart($rel['table']) . '.' . back_quote_smart($rel['link_parent']); } } } if ($this->join_clause == '') { $this->join_clause = $this->tables; } return $this; }
function get_listview_fields() { $table_name = $this->table_name; $this->arr_subtext_separators = array(); foreach ($this->fields as $field_name => $field_struct) { if ($field_struct['in_listview'] == TRUE) { $make_filter_label = TRUE; if ($field_struct['attribute'] == 'foreign key' || $field_struct['attribute'] == 'primary&foreign key') { $has_no_defined_relationship = TRUE; //find the relationship information for this field; only 1-1 foreach ($this->relations as $key => $rel) { if (strip_back_quote_smart($rel['link_child']) == $field_name && $rel['type'] == '1-1') { $has_no_defined_relationship = FALSE; require_once 'subclasses/' . strip_back_quote_smart($rel['table']) . '.php'; $class = strip_back_quote_smart($rel['table']); $data_con = new $class(); $database = $data_con->db_use; $temp_field_name = ''; $filter_field_name = ''; $arr_subtexts = array(); $arr_subtext_labels = array(); $subtext_cntr = 0; foreach ($rel['link_subtext'] as $subtext) { if ($temp_field_name != '') { $temp_field_name .= ', '; } if ($filter_field_name != '') { $filter_field_name .= ', '; } if (isset($rel['alias']) && $rel['alias'] != '') { $temp_field_name .= back_quote_smart($database) . '.' . back_quote_smart($rel['alias']) . '.' . back_quote_smart($subtext) . ' AS ' . back_quote_smart($database . '_' . $rel['alias'] . '_' . $subtext); $filter_field_name .= back_quote_smart($database) . '.' . back_quote_smart($rel['alias']) . '.' . back_quote_smart($subtext); $arr_subtexts[] = $database . '_' . $rel['alias'] . '_' . $subtext; } else { $temp_field_name .= back_quote_smart($database) . '.' . back_quote_smart($rel['table']) . '.' . back_quote_smart($subtext) . ' AS ' . back_quote_smart($database . '_' . $rel['table'] . '_' . $subtext); $filter_field_name .= back_quote_smart($database) . '.' . back_quote_smart($rel['table']) . '.' . back_quote_smart($subtext); $arr_subtexts[] = $database . '_' . $rel['table'] . '_' . $subtext; } $arr_subtext_labels[] = $data_con->fields[$subtext]['label']; ++$subtext_cntr; } if ($subtext_cntr > 1) { foreach ($arr_subtext_labels as $new_filter_label) { make_list_array($this->arr_filter_field_labels, $new_filter_label); } $make_filter_label = FALSE; } if (isset($this->fields[$field_name]['list_settings']['list_separators'])) { $this->arr_subtext_separators[] = $this->fields[$field_name]['list_settings']['list_separators']; } $related_field_name = $temp_field_name; make_list($this->lst_fields, back_quote_smart($related_field_name), ',', FALSE); make_list($this->lst_filter_fields, back_quote_smart($filter_field_name), ',', FALSE); $this->arr_fields[] = $arr_subtexts; if ($field_struct['attribute'] == 'primary&foreign key') { //if foreign key is also a primary key, we also need the original field aside from the subtext field $orig_field_name = back_quote_smart($table_name) . '.' . back_quote_smart($field_name); make_list($this->lst_fields, back_quote_smart($orig_field_name), ',', FALSE); } } } if ($has_no_defined_relationship) { error_handler('Cannot render ListView, incorrect configuration.', ' Missing relationship information for foreign-key column "' . $field_name . '".'); } } else { make_list($this->lst_fields, back_quote_smart($table_name) . '.' . back_quote_smart($field_name), ',', FALSE); make_list($this->lst_filter_fields, back_quote_smart($table_name) . '.' . back_quote_smart($field_name), ',', FALSE); make_list_array($this->arr_fields, $field_name); } make_list($this->lst_field_labels, $field_struct['label'], ','); make_list_array($this->arr_field_labels, $field_struct['label']); if ($make_filter_label) { make_list_array($this->arr_filter_field_labels, $field_struct['label']); } } elseif ($field_struct['attribute'] == 'primary key') { make_list($this->lst_fields, back_quote_smart($table_name) . '.' . back_quote_smart($field_name), ',', FALSE); } } return $this; }