Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00018 /************************************************************************* 00019 * Implements hook_views_data() 00020 * Purpose: Describe chado/tripal tables & fields to views 00021 * 00022 * @return: a data array which follows the structure outlined in the 00023 * views2 documentation for this hook. Essentially, it's an array of table 00024 * definitions keyed by chado/tripal table name. Each table definition 00025 * includes basic details about the table, fields in that table and 00026 * relationships between that table and others (joins) 00027 */ 00028 function tripal_project_views_data() { 00029 $data = array(); 00030 00031 if (module_exists('tripal_views')) { 00032 $tables = array( 00033 'project' 00034 ); 00035 foreach ($tables as $tablename) { 00036 $priority = 9; 00037 00038 // check to see if the table is integrated. If it is then integrate it's 00039 // corresponding 'chado_[table]' table. 00040 if (!tripal_views_is_integrated($tablename, $priority)) { 00041 $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority); 00042 00043 // Add in node relationships if chado is in the same db as drupal 00044 if (tripal_core_chado_schema_exists()) { 00045 $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array); 00046 foreach ($integrations as $integration) { 00047 tripal_views_integration_add_entry($integration); 00048 } 00049 } 00050 else { 00051 tripal_views_integration_add_entry($table_integration_array); 00052 } 00053 } 00054 } 00055 00056 $tables = array( 00057 ); 00058 foreach ($tables as $tablename) { 00059 $priority = 9; 00060 if (!tripal_views_is_integrated($tablename, $priority)) { 00061 $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority); 00062 tripal_views_integration_add_entry($table_integration_array); 00063 } 00064 } 00065 } 00066 00067 return $data; 00068 } 00069 00070 /************************************************************************* 00071 * Implements hook_views_handlers() 00072 * Purpose: Register all custom handlers with views 00073 * where a handler describes either "the type of field", 00074 * "how a field should be filtered", "how a field should be sorted" 00075 * 00076 * @return: An array of handler definitions 00077 */ 00078 function tripal_project_views_handlers() { 00079 return array( 00080 'info' => array( 00081 'path' => drupal_get_path('module', 'tripal_project') . '/views/handlers', 00082 ), 00083 'handlers' => array( 00084 00085 ), 00086 ); 00087 } 00088 00093 function tripal_project_views_default_views() { 00094 $views = array(); 00095 00096 if (!module_exists('tripal_views')) { 00097 return $views; 00098 } 00099 00100 $description_type_id = tripal_core_chado_select('cvterm',array('cvterm_id'),array('name' => 'project_description')); 00101 $description_type_id = $description_type_id[0]->cvterm_id; 00102 00103 // Main default view 00104 $view = new view; 00105 $view->name = 'project_listing'; 00106 $view->description = 'A listing of chado projects'; 00107 $view->tag = 'chado default'; 00108 $view->base_table = 'project'; 00109 $view->core = 6; 00110 $view->api_version = '2'; 00111 $view->disabled = FALSE; 00112 $handler = $view->new_display('default', 'Defaults', 'default'); 00113 $handler->override_option('fields', array( 00114 'name' => array( 00115 'label' => 'Name', 00116 'alter' => array( 00117 'alter_text' => 0, 00118 'text' => '', 00119 'make_link' => 0, 00120 'path' => '', 00121 'absolute' => 0, 00122 'link_class' => '', 00123 'alt' => '', 00124 'rel' => '', 00125 'prefix' => '', 00126 'suffix' => '', 00127 'target' => '', 00128 'help' => '', 00129 'trim' => 0, 00130 'max_length' => '', 00131 'word_boundary' => 1, 00132 'ellipsis' => 1, 00133 'html' => 0, 00134 'strip_tags' => 0, 00135 ), 00136 'empty' => '', 00137 'hide_empty' => 0, 00138 'empty_zero' => 0, 00139 'hide_alter_empty' => 1, 00140 'type' => 'separator', 00141 'separator' => ', ', 00142 'exclude' => 0, 00143 'id' => 'name', 00144 'table' => 'project', 00145 'field' => 'name', 00146 'relationship' => 'none', 00147 ), 00148 'value' => array( 00149 'label' => 'Description', 00150 'alter' => array( 00151 'alter_text' => 0, 00152 'text' => '', 00153 'make_link' => 0, 00154 'path' => '', 00155 'absolute' => 0, 00156 'link_class' => '', 00157 'alt' => '', 00158 'rel' => '', 00159 'prefix' => '', 00160 'suffix' => '', 00161 'target' => '', 00162 'help' => '', 00163 'trim' => 0, 00164 'max_length' => '', 00165 'word_boundary' => 1, 00166 'ellipsis' => 1, 00167 'html' => 0, 00168 'strip_tags' => 0, 00169 ), 00170 'empty' => '', 00171 'hide_empty' => 0, 00172 'empty_zero' => 0, 00173 'hide_alter_empty' => 1, 00174 'type' => 'separator', 00175 'separator' => ', ', 00176 'exclude' => 0, 00177 'id' => 'value', 00178 'table' => 'projectprop', 00179 'field' => 'value', 00180 'override' => array( 00181 'button' => 'Override', 00182 ), 00183 'relationship' => 'none', 00184 ), 00185 )); 00186 $handler->override_option('filters', array( 00187 'name' => array( 00188 'operator' => '~', 00189 'value' => '', 00190 'group' => '0', 00191 'exposed' => TRUE, 00192 'expose' => array( 00193 'use_operator' => 0, 00194 'operator' => 'name_op', 00195 'identifier' => 'name', 00196 'label' => 'Name Contains', 00197 'remember' => 0, 00198 ), 00199 'case' => 0, 00200 'id' => 'name', 00201 'table' => 'project', 00202 'field' => 'name', 00203 'relationship' => 'none', 00204 'agg' => array( 00205 'records_with' => 1, 00206 'aggregates_with' => 1, 00207 ), 00208 ), 00209 'type_id' => array( 00210 'operator' => '=', 00211 'value' => $description_type_id, 00212 'group' => '0', 00213 'exposed' => FALSE, 00214 'expose' => array( 00215 'operator' => FALSE, 00216 'label' => '', 00217 'optional' => FALSE, 00218 ), 00219 'case' => 1, 00220 'id' => 'type_id', 00221 'table' => 'projectprop', 00222 'field' => 'type_id', 00223 'override' => array( 00224 'button' => 'Override', 00225 ), 00226 'relationship' => 'none', 00227 'values_form_type' => 'select', 00228 'multiple' => 0, 00229 'optional' => 0, 00230 'show_all' => 0, 00231 'agg' => array( 00232 'records_with' => 0, 00233 'aggregates_with' => 1, 00234 ), 00235 ), 00236 'value' => array( 00237 'operator' => '~', 00238 'value' => '', 00239 'group' => '0', 00240 'exposed' => TRUE, 00241 'expose' => array( 00242 'use_operator' => 0, 00243 'operator' => 'value_op', 00244 'identifier' => 'description', 00245 'label' => 'Description Contains', 00246 'remember' => 0, 00247 ), 00248 'case' => 0, 00249 'id' => 'value', 00250 'table' => 'projectprop', 00251 'field' => 'value', 00252 'override' => array( 00253 'button' => 'Override', 00254 ), 00255 'relationship' => 'none', 00256 'agg' => array( 00257 'records_with' => 1, 00258 'aggregates_with' => 1, 00259 ), 00260 ), 00261 )); 00262 $handler->override_option('access', array( 00263 'type' => 'perm', 00264 'perm' => 'access chado_projects', 00265 )); 00266 $handler->override_option('cache', array( 00267 'type' => 'none', 00268 )); 00269 $handler->override_option('title', 'Projects'); 00270 $handler->override_option('empty', 'No projects match the supplied criteria.'); 00271 $handler->override_option('empty_format', '2'); 00272 $handler->override_option('items_per_page', 50); 00273 $handler->override_option('use_pager', '1'); 00274 $handler->override_option('style_plugin', 'table'); 00275 $handler->override_option('style_options', array( 00276 'grouping' => '', 00277 'override' => 1, 00278 'sticky' => 0, 00279 'order' => 'asc', 00280 'summary' => '', 00281 'columns' => array( 00282 'name' => 'name', 00283 'description' => 'description', 00284 ), 00285 'info' => array( 00286 'name' => array( 00287 'sortable' => 1, 00288 'separator' => '', 00289 ), 00290 'description' => array( 00291 'sortable' => 0, 00292 'separator' => '', 00293 ), 00294 ), 00295 'default' => 'name', 00296 )); 00297 $default_handler = $handler; 00298 $handler = $view->new_display('page', 'Page', 'page_1'); 00299 $handler->override_option('path', 'chado/projects'); 00300 $handler->override_option('menu', array( 00301 'type' => 'normal', 00302 'title' => 'Projects', 00303 'description' => 'A project is a collection of data resulting from a biological experiment.', 00304 'weight' => '10', 00305 'name' => 'navigation', 00306 )); 00307 $handler->override_option('tab_options', array( 00308 'type' => 'none', 00309 'title' => '', 00310 'description' => '', 00311 'weight' => 0, 00312 'name' => 'navigation', 00313 )); 00314 00315 // Add code specific to a local chado installation 00316 // NOTE: Edit $handler above to $default_handler for the default display 00317 if (tripal_core_chado_schema_exists()) { 00318 // Add nid field 00319 $fields = $view->get_items('field', 'default'); 00320 $new_fields = array( 00321 'nid' => array( 00322 'label' => 'Nid', 00323 'alter' => array( 00324 'alter_text' => 0, 00325 'text' => '', 00326 'make_link' => 0, 00327 'path' => '', 00328 'absolute' => 0, 00329 'link_class' => '', 00330 'alt' => '', 00331 'rel' => '', 00332 'prefix' => '', 00333 'suffix' => '', 00334 'target' => '', 00335 'help' => '', 00336 'trim' => 0, 00337 'max_length' => '', 00338 'word_boundary' => 1, 00339 'ellipsis' => 1, 00340 'html' => 0, 00341 'strip_tags' => 0, 00342 ), 00343 'empty' => '', 00344 'hide_empty' => 0, 00345 'empty_zero' => 0, 00346 'hide_alter_empty' => 1, 00347 'link_to_node' => 0, 00348 'exclude' => 1, 00349 'id' => 'nid', 00350 'table' => 'node', 00351 'field' => 'nid', 00352 'relationship' => 'none', 00353 ) 00354 ); 00355 $fields = $new_fields + $fields; 00356 // Adds project => Node relationship 00357 $default_handler->override_option('relationships', array( 00358 'nid' => array( 00359 'label' => 'Project to Node', 00360 'required' => 0, 00361 'id' => 'nid', 00362 'table' => 'chado_project', 00363 'field' => 'nid', 00364 'relationship' => 'none', 00365 ), 00366 )); 00367 // Change project.name to have a link to the node 00368 $fields['name']['alter']['link_to_node'] = 1; 00369 $default_handler->override_option('fields', $fields); 00370 // Only show records with published nodes 00389 } 00390 $views[$view->name] = $view; 00391 00392 return $views; 00393 }