Ejemplo n.º 1
0
 function create_query_from_relationship($field, &$query, &$list_value, &$list_items)
 {
     foreach ($this->relations as $id => $rel) {
         if (back_quote_smart($rel['link_child']) == back_quote_smart($field)) {
             $list_value = 'queried_' . strip_back_quote_smart($rel['link_parent']);
             $list_items = array();
             foreach ($rel['link_subtext'] as $subtext) {
                 $list_items[] = strip_back_quote_smart($subtext);
             }
             //**************************************
             //Create the query:
             require_once 'Subclasses/' . strip_back_quote_smart($rel['table']) . '.php';
             $class = strip_back_quote_smart($rel['table']);
             $objDB = new $class();
             $database = $objDB->DB_USE;
             $objDB->close_DB();
             $value_field = back_quote_smart($rel['link_parent']) . ' as `Queried_' . strip_back_quote_smart($rel['link_parent']) . '`';
             $items_field = '';
             foreach ($rel['link_subtext'] as $subtext) {
                 if (back_quote_smart($subtext) != back_quote_smart($rel['link_parent'])) {
                     make_list($items_field, strip_back_quote_smart($subtext), $delimiter = ',', $quotes = TRUE, '`', '`');
                 }
             }
             $query = "SELECT {$value_field}";
             if ($items_field != '') {
                 $query .= ', ' . $items_field;
             }
             $query .= ' FROM ' . back_quote_smart($database) . '.' . back_quote_smart($rel['table']);
             if ($rel['where_clause'] != '') {
                 $query .= ' WHERE ' . $rel['Where_clause'];
             }
             if ($items_field != '') {
                 $query .= " ORDER BY {$items_field}";
             } else {
                 $query .= ' ORDER BY ' . back_quote_smart($rel['link_parent']);
             }
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 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;
 }