Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00003 module_load_include('inc', 'views', 'includes/base'); 00004 module_load_include('inc', 'views', 'includes/handlers'); 00005 00036 class views_handler_join_chado_through_linking extends views_join { 00037 00038 // PHP 4 doesn't call constructors of the base class automatically from a 00039 // constructor of a derived class. It is your responsibility to propagate 00040 // the call to constructors upstream where appropriate. 00041 function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT', $added = NULL) { 00042 parent::construct($table, $left_table, $left_field, $field, $extra, $type); 00043 } 00044 00049 function join($table, &$query) { 00050 $output = ''; 00051 $joins = array(); 00052 00053 $joins[] = $this->create_single_join( 00054 $query, 00055 array( 00056 'table' => $this->definition['linking']['table'], 00057 'field' => $this->definition['linking']['left_field'], 00058 'is_drupal' => FALSE, 00059 ), 00060 array( 00061 'table' => $this->definition['left_table'], 00062 'field' => $this->definition['left_field'], 00063 ), 00064 'LEFT' 00065 ); 00066 00067 $joins[] = $this->create_single_join( 00068 $query, 00069 array( 00070 'table' => $this->definition['table'], 00071 'field' => $this->definition['field'], 00072 'is_drupal' => $this->definition['table_is_drupal'], 00073 ), 00074 array( 00075 'table' => $this->definition['linking']['table'], 00076 'field' => $this->definition['linking']['field'], 00077 ), 00078 'LEFT' 00079 ); 00080 00081 $output .= implode("\n", $joins); 00082 return $output; 00083 } 00084 00088 function create_single_join(&$query, $right_spec, $left_spec, $join_type) { 00089 00090 if ($right_spec['table']) { 00091 $right = $query->get_table_info($right_spec['table']); 00092 if (!$right['alias']) { 00093 $right['alias'] = $right_spec['table']; 00094 } 00095 $right_field = "$right[alias].$right_spec[field]"; 00096 00097 if ($right_spec['is_drupal']) { 00098 $right_table = '{' . $right_spec['table'] . '}'; 00099 } 00100 else { 00101 $right_table = $right_spec['table']; 00102 } 00103 } 00104 00105 if ($left_spec['table']) { 00106 $left = $query->get_table_info($left_spec['table']); 00107 if (!$left['alias']) { 00108 $left['alias'] = $left_spec['table']; 00109 } 00110 $left_field = "$left[alias].$left_spec[field]"; 00111 } 00112 else { 00113 // This can be used if left_field is a formula or something. It should be used only *very* rarely. 00114 $left_field = $this->left_spec['field']; 00115 } 00116 00117 $output = " $join_type JOIN $right_table $right[alias] ON $left_field = $right_field"; 00118 00119 return $output; 00120 } 00121 00122 }