'. t("Displays links to nodes created on this date"). '
'; break; } return $output; } /******************************************************************************* * Provide information to drupal about the node types that we're creating * in this module */ function tripal_library_node_info() { $nodes = array(); $nodes['chado_library'] = array( 'name' => t('Library'), 'module' => 'chado_library', 'description' => t('A library from the chado database'), 'has_title' => FALSE, 'title_label' => t('Library'), 'has_body' => FALSE, 'body_label' => t('Library Description'), 'locked' => TRUE ); return $nodes; } /******************************************************************************* * Set the permission types that the chado module uses. Essentially we * want permissionis that protect creation, editing and deleting of chado * data objects */ function tripal_library_perm(){ return array( 'access chado_library content', 'create chado_library content', 'delete chado_library content', 'edit chado_library content', ); } /************************************************************************ * Set the permission types that the module uses. */ function chado_library_access($op, $node, $account) { if ($op == 'create') { return user_access('create chado_library content', $account); } if ($op == 'update') { if (user_access('edit chado_library content', $account)) { return TRUE; } } if ($op == 'delete') { if (user_access('delete chado_library content', $account)) { return TRUE; } } if ($op == 'view') { if (user_access('access chado_library content', $account)) { return TRUE; } } return FALSE; } /******************************************************************************* * Menu items are automatically added for the new node types created * by this module to the 'Create Content' Navigation menu item. This function * adds more menu items needed for this module. */ function tripal_library_menu() { $items = array(); // The administative settings menu $items['admin/tripal/tripal_library'] = array( 'title' => 'Libraries', 'description' => 'Manage integration of Chado libraries including associated features.', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_library_admin'), 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); // Synchronizing libraries from Chado to Drupal $items['chado_sync_libraries'] = array( 'title' => t('Sync Data'), 'page callback' => 'tripal_library_sync_libraries', 'access arguments' => array('access administration pages'), 'type' => MENU_CALLBACK ); // Displaying libraries $items['libraries'] = array( 'menu_name' => ('primary-links'), //Enable the 'Library' primary link 'title' => t('DNA Libraries'), 'page callback' => 'tripal_library_show_libraries', 'access arguments' => array('access chado_library content'), 'type' => MENU_NORMAL_ITEM ); $items['node/%/libraries'] = array( 'title' => t('Libraries'), 'page callback' => 'get_tripal_library_organism_libraries', 'page arguments' => array(1), 'access callback' => 'tripal_library_node_has_menu', 'access arguments' => array('access chado_library content',1), 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM ); return $items; } /************************************************************************* * Implements hook_views_api() * Purpose: Essentially this hook tells drupal that there is views support for * for this module which then includes tripal_db.views.inc where all the * views integration code is */ function tripal_library_views_api() { return array( 'api' => 2.0, ); } /******************************************************************************* * Dynamic addition/removal of menu item */ function tripal_library_node_has_menu($type,$vid){ // check to see if this node is an organism node $sql = 'SELECT organism_id FROM {chado_organism} WHERE vid = %d'; $result = db_query($sql, $vid); // menu status $box_status =variable_get("tripal_library-box-libraries","menu_off"); // if this node is not an organism or a feature node then return false // we don't want the menu item to be shown, otherwise get the normal perms if($org_id = db_fetch_object($result)){ if(strcmp($box_status,"menu_on")==0){ return user_access($type); } } else { return FALSE; } } /******************************************************************************* * Administrative settings form */ function tripal_library_admin () { $form = array(); // before proceeding check to see if we have any // currently processing jobs. If so, we don't want // to give the opportunity to sync libraries $active_jobs = FALSE; if(tripal_get_module_active_jobs('tripal_library')){ $active_jobs = TRUE; } // add the field set for syncing libraries if(!$active_jobs){ get_tripal_library_admin_form_sync_set ($form); get_tripal_library_admin_form_reindex_set($form); get_tripal_library_admin_form_taxonomy_set($form); get_tripal_library_admin_form_cleanup_set($form); get_tripal_library_admin_form_menu_set($form); } else { $form['notice'] = array( '#type' => 'fieldset', '#title' => t('Library Management Temporarily Unavailable') ); $form['notice']['message'] = array( '#value' => t('Currently, library management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'), ); } return system_settings_form($form); } /******************************************************************************* * HOOK: Implementation of hook_nodeapi() * Display library information for associated features or organisms * This function also provides contents for indexing */ function tripal_library_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { // Note that this function only adds library view to an organism/feature // node. The view of a library node is controled by the theme *.tpl file case 'view': // Set the node types for showing library information $types_to_show = array('chado_organism', 'chado_feature'); // Abort if this node is not one of the types we should show. if (!in_array($node->type, $types_to_show, TRUE)) { break; } // Add library to the content item if it's not a teaser if (!$teaser) { // add the library to the organism/feature search indexing if($node->build_mode == NODE_BUILD_SEARCH_INDEX){ $node->content['tripal_library_index_version'] = array( '#value' => theme('tripal_library_search_index',$node), '#weight' => 4, ); } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) { $node->content['tripal_library_index_version'] = array( '#value' => theme('tripal_library_search_result',$node), '#weight' => 4, ); } else { // Show library if the organism/feature is not at teaser view $node->content['tripal_library_node_addition'] = array( '#value' => theme('tripal_library_node_libraries', $node), '#weight' => 4 ); } } } } /************************************************************************ * We need to let drupal know about our theme functions and their arguments. * We create theme functions to allow users of the module to customize the * look and feel of the output generated in this module */ function tripal_library_theme () { return array( 'tripal_library_library_table' => array ( 'arguments' => array('libraries'), ), 'tripal_library_search_index' => array ( 'arguments' => array('node'), ), 'tripal_library_search_result' => array ( 'arguments' => array('node'), ), 'tripal_library_node_libraries' => array ( 'arguments' => array('node'), ) ); } /************************************************************************ * This function is an extension of the chado_feature_view and * chado_organism_view by providing the markup for the feature/organism object * to show on a search result page. */ function theme_tripal_library_search_result ($node) { if ($node->type == 'chado_organism') { $content = ""; // get the libraries for the organism $previous_db = tripal_db_set_active('chado'); $sql = "SELECT * FROM {library} L ". "WHERE L.Organism_id = $node->organism_id"; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ // get the description $sql = "SELECT * FROM {libraryprop} LP ". " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ". "WHERE LP.library_id = $library->library_id ". " AND CVT.name = 'library_description'"; $desc = db_fetch_object(db_query($sql)); $library->description = $desc->value; $libraries[] = $library; } tripal_db_set_active($previous_db); if(count($libraries) > 0){ foreach ($libraries as $library){ $content .= "Library: $library->name. "; $content .= "$library->description"; }; } // Provide library names to show in a feature page } else if ($node->type == 'chado_feature') { $content = ""; $organism_id = $node->feature->organism_id; $previous_db = tripal_db_set_active('chado'); $sql = "SELECT * FROM {library} L ". " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ". "WHERE LF.feature_id = " . $node->feature->feature_id; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ $libraries[] = $library; } tripal_db_set_active($previous_db); if(count($libraries) > 0){ $lib_additions = array(); foreach ($libraries as $library){ $content .= "Library: ".$library->name; }; } } return $content; } /************************************************************************ * This function is an extension of the chado_feature_view and * chado_organism_view by providing the markup for the library object * THAT WILL BE INDEXED. */ function theme_tripal_library_search_index ($node) { if ($node->type == 'chado_organism') { $content = ""; // get the libraries for the organism $previous_db = tripal_db_set_active('chado'); $sql = "SELECT * FROM {library} L ". "WHERE L.Organism_id = $node->organism_id"; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ // get the description $sql = "SELECT * FROM {libraryprop} LP ". " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ". "WHERE LP.library_id = $library->library_id ". " AND CVT.name = 'library_description'"; $desc = db_fetch_object(db_query($sql)); $library->description = $desc->value; $libraries[] = $library; } tripal_db_set_active($previous_db); if(count($libraries) > 0){ foreach ($libraries as $library){ $content .= "$library->name "; $content .= "$library->description"; }; } // Provide library names to show in a feature page } else if ($node->type == 'chado_feature') { $content = ""; $organism_id = $node->feature->organism_id; $previous_db = tripal_db_set_active('chado'); $sql = "SELECT * FROM {library} L ". " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ". "WHERE LF.feature_id = " . $node->feature->feature_id; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ $libraries[] = $library; } tripal_db_set_active($previous_db); if(count($libraries) > 0){ $lib_additions = array(); foreach ($libraries as $library){ $content .= $library->name; }; } } return $content; } /******************************************************************************* * This function shows library information on an organism/feature node */ function theme_tripal_library_node_libraries($node) { $content = ""; // Show library information in a expandable box for a organism page. // Make sure we have $node->organism_id. In the case of creating a new // organism, the organism_id is not created until we save. This will cause // an error when users preview the creation without a $node->organism_id if ($node->type == 'chado_organism' && $node->organism_id) { $box_status = variable_get("tripal_library-box-libraries","menu_off"); if(strcmp($box_status,"menu_off")==0){ return get_tripal_library_organism_libraries($node->nid); } } // Provide library names to show in a feature page. // Make sure we have $node->feature->feature_id or there will be an error // when a feature is previewed at its creation else if ($node->type == 'chado_feature' && $node->feature->feature_id) { $organism_id = $node->feature->organism_id; $previous_db = tripal_db_set_active('chado'); $sql = "SELECT * FROM {library} L ". " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ". "WHERE LF.feature_id = " . $node->feature->feature_id; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ $libraries[] = $library; } tripal_db_set_active($previous_db); if(count($libraries) > 0){ $lib_additions = array(); foreach ($libraries as $library){ $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d"; $lib_nid = db_result(db_query($sql, $library->library_id)); if ($lib_nid) { $lib_url = url("node/$lib_nid"); } $lib_additions[$lib_url] = $library->name; }; $node->lib_additions = $lib_additions; } } return $content; } /************************************************************************ * */ function get_tripal_library_organism_libraries($nid) { $content = ""; // if this content is intended to be a menu item the // we need to know so we can format the content slightly different $box_status =variable_get("tripal_library-box-libraries","menu_off"); // get the organism id for this node $sql = "SELECT organism_id FROM {chado_organism} WHERE nid = %d"; $organism_id = db_result(db_query($sql, $nid)); // get the libraries for the organism $previous_db = tripal_db_set_active('chado'); $sql = "SELECT L.library_id, L.organism_id, L.name, L.uniquename, ". " L.type_id, CVT.name as cvname, CVT.definition ". "FROM {library} L ". " INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ". "WHERE L.Organism_id = $organism_id"; $libraries = array(); $results = db_query($sql); while($library = db_fetch_object($results)){ // get the description $sql = "SELECT * FROM {libraryprop} LP ". " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ". "WHERE LP.library_id = $library->library_id ". " AND CVT.name = 'library_description'"; $desc = db_fetch_object(db_query($sql)); $library->description = $desc->value; $libraries[] = $library; } tripal_db_set_active($previous_db); if(strcmp($box_status,"menu_off")==0){ $content .= "Name | "; $output .= "Type | "; $output .= "Organism | "; $output .= "Description | "; $output .= "||
---|---|---|---|---|---|
". " $library->name". " | "; if(strcasecmp($library->type_name, 'bac_library') == 0){ $output .= "BAC | "; } elseif(strcasecmp($library->type_name, 'cdna_library') == 0){ $output .= "cDNA | "; } else{ $output .= "$library->type_name | "; } $output .= "". " $library->common_name". " | "; $description = $library->library_description; $output .= "$description | "; $output .= "