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 * @return: a data array which follows the structure outlined in the 00022 * views2 documentation for this hook. Essentially, it's an array of table 00023 * definitions keyed by chado/tripal table name. Each table definition 00024 * includes basic details about the table, fields in that table and 00025 * relationships between that table and others (joins) 00026 * 00027 * @ingroup tripal_library_views 00028 */ 00029 function tripal_library_views_data() { 00030 $data = array(); 00031 00032 if (module_exists('tripal_views')) { 00033 $tables = array( 00034 'library' 00035 ); 00036 foreach ($tables as $tablename) { 00037 $priority = 9; 00038 00039 // check to see if the table is integrated. If it is then integrate it's 00040 // corresponding 'chado_[table]' table. 00041 if (!tripal_views_is_integrated($tablename, $priority)) { 00042 $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, TRUE, $priority); 00043 00044 // Add in node relationships if chado is in the same db as drupal 00045 if (tripal_core_chado_schema_exists()) { 00046 $integrations = tripal_views_add_node_relationship_to_chado_table_integration($table_integration_array); 00047 foreach ($integrations as $integration) { 00048 tripal_views_integration_add_entry($integration); 00049 } 00050 } 00051 else { 00052 tripal_views_integration_add_entry($table_integration_array); 00053 } 00054 00055 } 00056 } 00057 00058 $tables = array( 00059 'library_cvterm', 00060 'library_feature', 00061 'library_pub', 00062 'library_synonym', 00063 'libraryprop' 00064 ); 00065 foreach ($tables as $tablename) { 00066 $priority = 9; 00067 if (!tripal_views_is_integrated($tablename, $priority)) { 00068 $table_integration_array = tripal_views_get_integration_array_for_chado_table($tablename, FALSE, $priority); 00069 tripal_views_integration_add_entry($table_integration_array); 00070 } 00071 } 00072 } 00073 00074 return $data; 00075 } 00076 00077 /************************************************************************* 00078 * Implements hook_views_handlers() 00079 * Purpose: Register all custom handlers with views 00080 * where a handler describes either "the type of field", 00081 * "how a field should be filtered", "how a field should be sorted" 00082 * @return: An array of handler definitions 00083 * 00084 * @ingroup tripal_library_views 00085 */ 00086 function tripal_library_views_handlers() { 00087 return array( 00088 'info' => array( 00089 'path' => drupal_get_path('module', 'tripal_library') . '/views/handlers', 00090 ), 00091 'handlers' => array( 00092 'views_handler_field_computed_library_nid' => array( 00093 'parent' => 'views_handler_field_numeric', 00094 ), 00095 ), 00096 ); 00097 } 00098 00102 function tripal_library_views_data_alter(&$data) { 00103 00104 if ( !(is_array($db_url) and array_key_exists('chado', $db_url)) ) { 00105 00106 // Add featuer relationship to node 00107 $data['node']['library_chado_nid'] = array( 00108 'group' => 'Library', 00109 'title' => 'Library Node', 00110 'help' => 'Links Chado Library Fields/Data to the Nodes in the current View.', 00111 'real field' => 'nid', 00112 'relationship' => array( 00113 'handler' => 'views_handler_relationship', 00114 'title' => t('Node => Chado'), 00115 'label' => t('Node => Chado'), 00116 'real field' => 'nid', 00117 'base' => 'chado_library', 00118 'base field' => 'nid' 00119 ), 00120 ); 00121 } 00122 00123 } 00124 00130 function tripal_library_views_default_views() { 00131 $views = array(); 00132 00133 if (!module_exists('tripal_views')) { 00134 return $views; 00135 } 00136 00137 // Main default view 00138 $view = new view; 00139 $view->name = 'library_listing'; 00140 $view->description = 'A listing of all libraries'; 00141 $view->tag = 'chado default'; 00142 $view->base_table = 'library'; 00143 $view->core = 0; 00144 $view->api_version = '2'; 00145 $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ 00146 $handler = $view->new_display('default', 'Defaults', 'default'); 00147 $handler->override_option('fields', array( 00148 'uniquename' => array( 00149 'label' => 'Unique Name', 00150 'alter' => array( 00151 'alter_text' => 0, 00152 'text' => '', 00153 'make_link' => 0, 00154 'path' => '', 00155 'link_class' => '', 00156 'alt' => '', 00157 'prefix' => '', 00158 'suffix' => '', 00159 'target' => '', 00160 'help' => '', 00161 'trim' => 0, 00162 'max_length' => '', 00163 'word_boundary' => 1, 00164 'ellipsis' => 1, 00165 'html' => 0, 00166 'strip_tags' => 0, 00167 ), 00168 'empty' => '', 00169 'hide_empty' => 0, 00170 'empty_zero' => 0, 00171 'link_to_node' => 1, 00172 'exclude' => 0, 00173 'id' => 'uniquename', 00174 'table' => 'library', 00175 'field' => 'uniquename', 00176 'relationship' => 'none', 00177 ), 00178 'name_1' => array( 00179 'label' => 'Name', 00180 'alter' => array( 00181 'alter_text' => 0, 00182 'text' => '', 00183 'make_link' => 0, 00184 'path' => '', 00185 'link_class' => '', 00186 'alt' => '', 00187 'prefix' => '', 00188 'suffix' => '', 00189 'target' => '', 00190 'help' => '', 00191 'trim' => 0, 00192 'max_length' => '', 00193 'word_boundary' => 1, 00194 'ellipsis' => 1, 00195 'html' => 0, 00196 'strip_tags' => 0, 00197 ), 00198 'empty' => '', 00199 'hide_empty' => 0, 00200 'empty_zero' => 0, 00201 'link_to_node' => 1, 00202 'exclude' => 0, 00203 'id' => 'name_1', 00204 'table' => 'library', 00205 'field' => 'name', 00206 'relationship' => 'none', 00207 ), 00208 'common_name' => array( 00209 'label' => 'Organism', 00210 'alter' => array( 00211 'alter_text' => 0, 00212 'text' => '', 00213 'make_link' => 0, 00214 'path' => '', 00215 'link_class' => '', 00216 'alt' => '', 00217 'prefix' => '', 00218 'suffix' => '', 00219 'target' => '', 00220 'help' => '', 00221 'trim' => 0, 00222 'max_length' => '', 00223 'word_boundary' => 1, 00224 'ellipsis' => 1, 00225 'html' => 0, 00226 'strip_tags' => 0, 00227 ), 00228 'empty' => '', 00229 'hide_empty' => 0, 00230 'empty_zero' => 0, 00231 'link_to_node' => 1, 00232 'exclude' => 0, 00233 'id' => 'common_name', 00234 'table' => 'organism', 00235 'field' => 'common_name', 00236 'relationship' => 'none', 00237 ), 00238 'name' => array( 00239 'label' => 'Type', 00240 'alter' => array( 00241 'alter_text' => 0, 00242 'text' => '', 00243 'make_link' => 0, 00244 'path' => '', 00245 'link_class' => '', 00246 'alt' => '', 00247 'prefix' => '', 00248 'suffix' => '', 00249 'target' => '', 00250 'help' => '', 00251 'trim' => 0, 00252 'max_length' => '', 00253 'word_boundary' => 1, 00254 'ellipsis' => 1, 00255 'html' => 0, 00256 'strip_tags' => 0, 00257 ), 00258 'empty' => '', 00259 'hide_empty' => 0, 00260 'empty_zero' => 0, 00261 'exclude' => 0, 00262 'id' => 'name', 00263 'table' => 'cvterm', 00264 'field' => 'name', 00265 'relationship' => 'none', 00266 ), 00267 'is_obsolete' => array( 00268 'label' => 'Is Obsolete?', 00269 'alter' => array( 00270 'alter_text' => 0, 00271 'text' => '', 00272 'make_link' => 0, 00273 'path' => '', 00274 'link_class' => '', 00275 'alt' => '', 00276 'prefix' => '', 00277 'suffix' => '', 00278 'target' => '', 00279 'help' => '', 00280 'trim' => 0, 00281 'max_length' => '', 00282 'word_boundary' => 1, 00283 'ellipsis' => 1, 00284 'html' => 0, 00285 'strip_tags' => 0, 00286 ), 00287 'empty' => '', 00288 'hide_empty' => 0, 00289 'empty_zero' => 0, 00290 'type' => 'yes-no', 00291 'not' => 0, 00292 'exclude' => 0, 00293 'id' => 'is_obsolete', 00294 'table' => 'library', 00295 'field' => 'is_obsolete', 00296 'relationship' => 'none', 00297 ), 00298 )); 00299 $handler->override_option('sorts', array( 00300 'name' => array( 00301 'id' => 'name', 00302 'table' => 'library', 00303 'field' => 'name', 00304 ), 00305 )); 00306 $handler->override_option('filters', array( 00307 'common_name' => array( 00308 'operator' => '=', 00309 'value' => array(), 00310 'group' => '0', 00311 'exposed' => TRUE, 00312 'expose' => array( 00313 'use_operator' => 0, 00314 'operator' => 'common_name_op', 00315 'identifier' => 'organism_common_name', 00316 'label' => 'Organism', 00317 'remember' => 0, 00318 ), 00319 'case' => 1, 00320 'id' => 'common_name', 00321 'table' => 'organism', 00322 'field' => 'common_name', 00323 'relationship' => 'none', 00324 'values_form_type' => 'select', 00325 'multiple' => 1, 00326 'optional' => 0, 00327 'agg' => array( 00328 'records_with' => 1, 00329 'aggregates_with' => 1, 00330 ), 00331 ), 00332 'type_id' => array( 00333 'operator' => '=', 00334 'value' => array(), 00335 'group' => '0', 00336 'exposed' => TRUE, 00337 'expose' => array( 00338 'use_operator' => 0, 00339 'operator' => 'type_id_op', 00340 'identifier' => 'type_id', 00341 'label' => 'Type', 00342 'remember' => 0, 00343 ), 00344 'case' => 1, 00345 'id' => 'type_id', 00346 'table' => 'library', 00347 'field' => 'type_id', 00348 'relationship' => 'none', 00349 'values_form_type' => 'select', 00350 'multiple' => 1, 00351 'optional' => 0, 00352 'show_all' => 0, 00353 'agg' => array( 00354 'records_with' => 1, 00355 'aggregates_with' => 0, 00356 ), 00357 ), 00358 )); 00359 $handler->override_option('access', array( 00360 'type' => 'perm', 00361 'perm' => 'access chado_library content', 00362 )); 00363 $handler->override_option('cache', array( 00364 'type' => 'none', 00365 )); 00366 $handler->override_option('title', 'Libraries'); 00367 $handler->override_option('header', 'Click "Show" to see a list of all libraries matching the entered criteria. If you leave a any of the criteria blank then the libraries will be not be filtered based on that field. Furthermore, if you leave all criteria blank then all libraries will be listed.'); 00368 $handler->override_option('header_format', '2'); 00369 $handler->override_option('header_empty', 0); 00370 $handler->override_option('empty', 'No libraries match the supplied criteria.'); 00371 $handler->override_option('empty_format', '1'); 00372 $handler->override_option('items_per_page', 50); 00373 $handler->override_option('use_pager', '1'); 00374 $handler->override_option('style_plugin', 'table'); 00375 $handler->override_option('style_options', array( 00376 'grouping' => '', 00377 'override' => 1, 00378 'sticky' => 0, 00379 'order' => 'asc', 00380 'summary' => '', 00381 'columns' => array( 00382 'uniquename' => 'uniquename', 00383 'name_1' => 'name_1', 00384 'common_name' => 'common_name', 00385 'name' => 'name', 00386 'is_obsolete' => 'is_obsolete', 00387 ), 00388 'info' => array( 00389 'uniquename' => array( 00390 'sortable' => 1, 00391 'separator' => '', 00392 ), 00393 'name_1' => array( 00394 'sortable' => 1, 00395 'separator' => '', 00396 ), 00397 'common_name' => array( 00398 'sortable' => 1, 00399 'separator' => '', 00400 ), 00401 'name' => array( 00402 'sortable' => 1, 00403 'separator' => '', 00404 ), 00405 'is_obsolete' => array( 00406 'sortable' => 1, 00407 'separator' => '', 00408 ), 00409 ), 00410 'default' => 'uniquename', 00411 )); 00412 $default_handler = $handler; 00413 $handler = $view->new_display('page', 'Page', 'page_1'); 00414 $handler->override_option('path', 'chado/libraries'); 00415 $handler->override_option('menu', array( 00416 'type' => 'normal', 00417 'title' => 'Libraries', 00418 'description' => 'A library is a collection of features of a given type. For example, a cDNA or BAC clone library.', 00419 'weight' => '10', 00420 'name' => 'navigation', 00421 )); 00422 $handler->override_option('tab_options', array( 00423 'type' => 'none', 00424 'title' => '', 00425 'description' => '', 00426 'weight' => 0, 00427 'name' => 'navigation', 00428 )); 00429 // Add code specific to a local chado installation 00430 // NOTE: Edit $handler above to $default_handler for the default display 00431 if (tripal_core_chado_schema_exists()) { 00432 // Add nid field 00433 $fields = $view->get_items('field', 'default'); 00434 $new_fields = array( 00435 'nid' => array( 00436 'label' => 'Nid', 00437 'alter' => array( 00438 'alter_text' => 0, 00439 'text' => '', 00440 'make_link' => 0, 00441 'path' => '', 00442 'absolute' => 0, 00443 'link_class' => '', 00444 'alt' => '', 00445 'rel' => '', 00446 'prefix' => '', 00447 'suffix' => '', 00448 'target' => '', 00449 'help' => '', 00450 'trim' => 0, 00451 'max_length' => '', 00452 'word_boundary' => 1, 00453 'ellipsis' => 1, 00454 'html' => 0, 00455 'strip_tags' => 0, 00456 ), 00457 'empty' => '', 00458 'hide_empty' => 0, 00459 'empty_zero' => 0, 00460 'hide_alter_empty' => 1, 00461 'link_to_node' => 0, 00462 'exclude' => 1, 00463 'id' => 'nid', 00464 'table' => 'node', 00465 'field' => 'nid', 00466 'relationship' => 'none', 00467 ) 00468 ); 00469 $fields = $new_fields + $fields; 00470 // Adds library => Node relationship 00471 $default_handler->override_option('relationships', array( 00472 'nid' => array( 00473 'label' => 'Library to Node', 00474 'required' => 0, 00475 'id' => 'nid', 00476 'table' => 'chado_library', 00477 'field' => 'nid', 00478 'relationship' => 'none', 00479 ), 00480 )); 00481 // Change analysis.name to have a link to the node 00482 $fields['name_1']['alter']['link_to_node'] = 1; 00483 $default_handler->override_option('fields', $fields); 00484 // Only show records with published nodes 00503 } 00504 $views[$view->name] = $view; 00505 00506 return $views; 00507 }