|
Tripal 0.3b
|
00001 <?php 00002 00003 require_once "tripal_organism.api.inc"; 00004 00005 /** 00006 * @defgroup tripal_organism Organism 00007 * @ingroup tripal_modules 00008 */ 00009 00010 /** 00011 * 00012 * @ingroup tripal_organism 00013 */ 00014 function tripal_organism_init(){ 00015 00016 // add the jGCharts JS and CSS 00017 drupal_add_js (drupal_get_path('theme', 'tripal').'/js/tripal_organism.js'); 00018 drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_organism.css'); 00019 } 00020 /** 00021 * Provide information to drupal about the node types that we're creating 00022 * in this module 00023 * 00024 * @ingroup tripal_organism 00025 */ 00026 function tripal_organism_node_info() { 00027 $nodes = array(); 00028 $nodes['chado_organism'] = array( 00029 'name' => t('Organism'), 00030 'module' => 'chado_organism', 00031 'description' => t('An organism from the chado database'), 00032 'has_title' => FALSE, 00033 'title_label' => t('Organism'), 00034 'has_body' => FALSE, 00035 'body_label' => t('Organism Description'), 00036 'locked' => TRUE 00037 ); 00038 return $nodes; 00039 } 00040 00041 /** 00042 * Display block with organisms 00043 * @param op - parameter to define the phase being called for the block 00044 * @param delta - id of the block to return (ignored when op is list) 00045 * @param edit - when op is save, contains the submitted form data 00046 * 00047 * @ingroup tripal_organism 00048 */ 00049 function tripal_organism_block($op = 'list', $delta = '0', $edit = array()){ 00050 switch($op){ 00051 case 'list': 00052 $blocks['base']['info'] = t('Tripal Organism Details'); 00053 $blocks['base']['cache'] = BLOCK_NO_CACHE; 00054 00055 $blocks['description']['info'] = t('Tripal Organism Description'); 00056 $blocks['description']['cache'] = BLOCK_NO_CACHE; 00057 00058 $blocks['image']['info'] = t('Tripal Organism Image'); 00059 $blocks['image']['cache'] = BLOCK_NO_CACHE; 00060 00061 return $blocks; 00062 00063 case 'view': 00064 if(user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) { 00065 $nid = arg(1); 00066 $node = node_load($nid); 00067 00068 $block = array(); 00069 switch($delta){ 00070 case 'base': 00071 $block['subject'] = t('Organism Details'); 00072 $block['content'] = theme('tripal_organism_base',$node); 00073 break; 00074 case 'description': 00075 $block['subject'] = t('Organism Description'); 00076 $block['content'] = theme('tripal_organism_description',$node); 00077 break; 00078 case 'image': 00079 $block['subject'] = t('Organism Image'); 00080 $block['content'] = theme('tripal_organism_image',$node); 00081 break; 00082 default: 00083 } 00084 return $block; 00085 } 00086 } 00087 } 00088 /** 00089 * Menu items are automatically added for the new node types created 00090 * by this module to the 'Create Content' Navigation menu item. This function 00091 * adds more menu items needed for this module. 00092 * 00093 * @ingroup tripal_organism 00094 */ 00095 function tripal_organism_menu() { 00096 $items = array(); 00097 00098 $items['organisms'] = array( 00099 'menu_name' => ('primary-links'), //Enable the 'Organism' primary link 00100 'title' => t('Organisms'), 00101 'page callback' => 'tripal_organism_show_organisms', 00102 'access arguments' => array('access chado_organism content'), 00103 'type' => MENU_NORMAL_ITEM 00104 ); 00105 // the administative settings menu 00106 $items['admin/tripal/tripal_organism'] = array( 00107 'title' => 'Organisms', 00108 'description' => 'Basic Description of Tripal Organism Module Functionality', 00109 'page callback' => 'tripal_organism_module_description_page', 00110 'access arguments' => array('administer site configuration'), 00111 'type' => MENU_NORMAL_ITEM, 00112 ); 00113 00114 $items['admin/tripal/tripal_organism/configuration'] = array( 00115 'title' => 'Configuration', 00116 'description' => 'Manage integration of Chado organisms including associated features', 00117 'page callback' => 'drupal_get_form', 00118 'page arguments' => array('tripal_organism_admin'), 00119 'access arguments' => array('administer site configuration'), 00120 'type' => MENU_NORMAL_ITEM, 00121 ); 00122 00123 00124 return $items; 00125 } 00126 /** 00127 * The following function proves access control for users trying to 00128 * perform actions on data managed by this module 00129 * 00130 * @ingroup tripal_organism 00131 */ 00132 function chado_organism_access($op, $node, $account){ 00133 switch ($op){ 00134 case 'create': 00135 return user_access('create chado_organism content', $account); 00136 case 'update': 00137 return user_access('edit chado_organism content', $account); 00138 case 'delete': 00139 return user_access('delete chado_organism content', $account); 00140 case 'view' : 00141 return user_access('access chado_organism content', $account); 00142 } 00143 } 00144 /** 00145 * Set the permission types that the chado module uses. Essentially we 00146 * want permissionis that protect creation, editing and deleting of chado 00147 * data objects 00148 * 00149 * @ingroup tripal_organism 00150 */ 00151 function tripal_organism_perm(){ 00152 return array( 00153 'access chado_organism content', 00154 'create chado_organism content', 00155 'delete chado_organism content', 00156 'edit chado_organism content', 00157 ); 00158 } 00159 00160 /** 00161 * Purpose: Provide Guidance to new Tripal Admin 00162 * 00163 * @return HTML Formatted text 00164 * 00165 * @ingroup tripal_organism 00166 */ 00167 function tripal_organism_module_description_page() { 00168 $text = ''; 00169 00170 $text .= '<h3>Tripal Organism Administrative Tools Quick Links:</h3>'; 00171 $text .= "<ul> 00172 <li><a href=\"".url("admin/tripal/tripal_organism/configuration") . "\">Organism Configuration</a></li> 00173 </ul>"; 00174 00175 $text .= '<h3>Module Description:</h3>'; 00176 $text .= '<p>The Tripal Organism module allows you to add, edit and/or delete chado organisms. 00177 Furthermore, it also provides listing of organisms and details page for each organism. 00178 Basically, the chado organism module is designed to hold information about a given species. 00179 For more information on the chado organism module see the 00180 <a href="http://gmod.org/wiki/Chado_Organism_Module">GMOD wiki page</a></p>'; 00181 00182 $text .= '<h3>Setup Instructions:</h3>'; 00183 $text .= '<p>After installation of the organism module. The following tasks should be performed. 00184 <ol> 00185 <li><p><b>Set Permissions</b>: The organism module supports the Drupal user permissions interface for 00186 controlling access to organism content and functions. These permissions include viewing, 00187 creating, editing or administering of 00188 organism content. The default is that only the original site administrator has these 00189 permissions. You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users, 00190 <a href="'.url('admin/user/user').'">assign users to roles</a> and 00191 <a href="'.url('admin/user/permissions').'">assign permissions</a> for the organism content to 00192 those roles. For a simple setup, allow anonymous users access to view organism content and 00193 allow the site administrator all other permissions.</p></li> 00194 00195 <li><p><b>Create Organisms</b>: Organism pages can be created in two ways: 00196 <ol> 00197 <li><b>Sync Organisms</b>: If your organism has been pre-loaded into Chado then you need to sync the organism. 00198 This process is what creates the pages for viewing online. Not all organisms need be synced, only those 00199 that you want shown on the site. Use the the 00200 <a href="'.url('admin/tripal/tripal_organism/configuration').'">Organism Configuration page</a> 00201 to sync organisms. </li> 00202 <li><b>Manually Add An Organism</b>: If your organism is not already present in the Chado database 00203 you can create an organism using the <a href="'.url('node/add/chado-organism').'">Create Organism page</a>. 00204 Once saved, the organism will be present in Chado and also "synced". 00205 </ol></p></li> 00206 00207 <li><p><b>Indexing</b>: Once organism pages are ready for public access, 00208 you can index the organism pages for searching if you want to ues the Drupal default search mechanism. 00209 Use the <a href="'.url('admin/tripal/tripal_organism/configuration').'">Organism Configuration page</a> 00210 to either Index (for the first time) or "Reindex" (after updating data) 00211 the organism pages for searching. Once the site is 100% indexed the pages will be searchable using Drupal\'s 00212 full text searching. You can find the percent indexed for the entire site by visiting the 00213 <a href="'.url('admin/settings/search').'">Search settings page</a>. Indexing 00214 can take quite a while if you have a lot of data</p></li> 00215 00216 <li><p><b>Set Taxonomy</b>: Drupal provides a mechanism for categorizing content to allow 00217 for advanced searching. Drupal calls this "Taxonomy", but is essentially categorizing the pages. 00218 You can categorize feature pages by the 00219 organism to which they belong. This allows for filtering of search results by organism. 00220 Use the <a href="'.url('admin/tripal/tripal_organism/configuration').'">Organism Configuration page</a> to 00221 set the Taxonomy.</p></li> 00222 </ol>'; 00223 00224 $text .= '<h3>Features of this Module:</h3>'; 00225 $text .= '<p>Aside from organism page setup (as described in the Setup section above), 00226 The Tripal organism module also provides the following functionality 00227 <ul> 00228 <li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is 00229 a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content. 00230 It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database 00231 and create custom lists without PHP programming or customization of Tripal source code. Views can also 00232 be created to filter content that has not yet been synced with Druapl in order to protect access to non 00233 published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing 00234 Views <a href="'.url('admin/build/views/').'">here</a>, as well as create your own. </p></li> 00235 00236 <li><p><b>Basic Organism List</b>: This module provides a basic <a href="'.url('organisms').'">organism list</a> 00237 for showing the list of organisms in Chado. <a href="http://drupal.org/project/views">Drupal Views</a> must be 00238 installed. You can use the Views interface to alter the appearance of this list.</p></li> 00239 </ul> 00240 </p>'; 00241 00242 $text .= '<h3>Page Customizations</h3>'; 00243 $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal. 00244 Below is a description of several methods. These methods may be used in conjunction with one another to 00245 provide fine-grained control. 00246 <ul> 00247 00248 <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a> 00249 allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming. Tripal comes with pre-set layouts for organism pages. However, 00250 Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content 00251 is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the 00252 Panel\'s GUI.</p></li> 00253 00254 <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the 00255 <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content 00256 to any page without need to edit template files or knowing PHP. You must first download and install CCK. 00257 With CCK, the site administartor can create a new field to appear on the page. For example, currently, 00258 the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text 00259 field to the organism pages. This content is not stored in Chado, but will appear on the organism page. A field 00260 added by CCK will also appear in the form when editing a organism to allow users to manually enter the appropriate 00261 text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element, 00262 indicate that it is not to be shown (using the CCK interface), then manually add the new content type 00263 where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the 00264 location desired using the Panels interface.</p></li> 00265 00266 <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the 00267 themeing for Chado content. The organism module has a template file for organism "nodes" (Tripal organism pages). This file 00268 is named "node-chado_organism.tpl.php", and provides javascript, HTML and PHP code for display of the organism 00269 pages. You can edit this file to control which types of information (or which organism "blocks") are displayed for organisms. Be sure to 00270 copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as 00271 future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a> 00272 for instructions on how to access variables and other Chado content within the template file.</p></li> 00273 00274 <li><p><b>Organism "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_organism". 00275 Inside this directory is a set of templates that control distinct types of information for organisms. For example, 00276 there is a "base" template for displaying of data directly from the Chado organism table, and a "references" 00277 template for showing external site references for a organism (data from the organism_dbxref table). These templates are used both by Drupal blocks 00278 for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template 00279 provides (also desribed above). You can customize this template as you desire. Be sure to copy the 00280 template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as 00281 future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a> 00282 for instructions on how to access variables and other Chado content within the template files.</p></li> 00283 </li> 00284 00285 <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you 00286 will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated 00287 using Javascript for all of the organism "Blocks" that appear on the page. If you want to add additional links 00288 (e.g. a dynamic link to GBrowse for the organism) and you want that link to appear in the 00289 "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the 00290 section at the bottom of the template file where the resources section is found.</p></li> 00291 00292 </ul> 00293 </p>'; 00294 return $text; 00295 } 00296 00297 /** 00298 * Administrative settings for chado_orgnism 00299 * 00300 * @ingroup tripal_organism 00301 */ 00302 function tripal_organism_admin () { 00303 00304 $form = array(); 00305 00306 // before proceeding check to see if we have any 00307 // currently processing jobs. If so, we don't want 00308 // to give the opportunity to sync libraries 00309 $active_jobs = FALSE; 00310 if(tripal_get_module_active_jobs('tripal_organism')){ 00311 $active_jobs = TRUE; 00312 } 00313 00314 // add the field set for syncing libraries 00315 if(!$active_jobs){ 00316 get_tripal_organism_admin_form_sync_set($form); 00317 get_tripal_organism_admin_form_reindex_set($form); 00318 get_tripal_organism_admin_form_taxonomy_set($form); 00319 get_tripal_organism_admin_form_cleanup_set($form); 00320 } else { 00321 $form['notice'] = array( 00322 '#type' => 'fieldset', 00323 '#title' => t('Organism Management Temporarily Unavailable') 00324 ); 00325 $form['notice']['message'] = array( 00326 '#value' => t('Currently, organism 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.'), 00327 ); 00328 } 00329 00330 return system_settings_form($form); 00331 } 00332 /** 00333 * 00334 * 00335 * @ingroup tripal_organism 00336 */ 00337 function get_tripal_organism_admin_form_cleanup_set(&$form) { 00338 $form['cleanup'] = array( 00339 '#type' => 'fieldset', 00340 '#title' => t('Clean Up') 00341 ); 00342 $form['cleanup']['description'] = array( 00343 '#type' => 'item', 00344 '#value' => t("With Drupal and chado residing in different databases ". 00345 "it is possible that nodes in Drupal and organisms in Chado become ". 00346 "\"orphaned\". This can occur if an organism node in Drupal is ". 00347 "deleted but the corresponding chado organism is not and/or vice ". 00348 "versa. Click the button below to resolve these discrepancies."), 00349 '#weight' => 1, 00350 ); 00351 $form['cleanup']['button'] = array( 00352 '#type' => 'submit', 00353 '#value' => t('Clean up orphaned organisms'), 00354 '#weight' => 2, 00355 ); 00356 } 00357 /** 00358 * 00359 * 00360 * @ingroup tripal_organism 00361 */ 00362 function get_tripal_organism_admin_form_taxonomy_set(&$form) { 00363 $form['taxonify'] = array( 00364 '#type' => 'fieldset', 00365 '#title' => t('Assign Drupal Taxonomy to Organism Features') 00366 ); 00367 00368 // get the list of libraries 00369 $sql = "SELECT * FROM {Organism} ORDER BY genus,species"; 00370 $previous_db = tripal_db_set_active('chado'); // use chado database 00371 $org_rset = db_query($sql); 00372 tripal_db_set_active($previous_db); // now use drupal database 00373 00374 // iterate through all of the libraries 00375 $org_boxes = array(); 00376 while($organism = db_fetch_object($org_rset)){ 00377 $org_boxes[$organism->organism_id] = "$organism->genus $organism->species"; 00378 } 00379 00380 $form['taxonify']['description'] = array( 00381 '#type' => 'item', 00382 '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " . 00383 "nodes. These terms allow for advanced filtering during searching. This option allows ". 00384 "for setting taxonomy only for features that belong to the selected organisms below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."), 00385 '#weight' => 1, 00386 ); 00387 00388 $form['taxonify']['tx-organisms'] = array ( 00389 '#title' => t('Organisms'), 00390 '#type' => t('checkboxes'), 00391 '#description' => t("Check the organisms whose features you want to reset taxonomy. Note: this list contains all organisms, even those that may not be synced."), 00392 '#required' => FALSE, 00393 '#prefix' => '<div id="lib_boxes">', 00394 '#suffix' => '</div>', 00395 '#options' => $org_boxes, 00396 '#weight' => 2 00397 ); 00398 $form['taxonify']['tx-button'] = array( 00399 '#type' => 'submit', 00400 '#value' => t('Set Feature Taxonomy'), 00401 '#weight' => 3 00402 ); 00403 } 00404 /** 00405 * 00406 * @ingroup tripal_organism 00407 */ 00408 function get_tripal_organism_admin_form_reindex_set(&$form) { 00409 // define the fieldsets 00410 $form['reindex'] = array( 00411 '#type' => 'fieldset', 00412 '#title' => t('Reindex Organism Features') 00413 ); 00414 00415 // get the list of libraries 00416 $sql = "SELECT * FROM {Organism} ORDER BY genus,species"; 00417 $previous_db = tripal_db_set_active('chado'); // use chado database 00418 $org_rset = db_query($sql); 00419 tripal_db_set_active($previous_db); // now use drupal database 00420 00421 // iterate through all of the libraries 00422 $org_boxes = array(); 00423 while($organism = db_fetch_object($org_rset)){ 00424 $org_boxes[$organism->organism_id] = "$organism->genus $organism->species"; 00425 } 00426 $form['reindex']['description'] = array( 00427 '#type' => 'item', 00428 '#value' => t("This option allows for reindexing of only those features that belong to the selected organisms below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."), 00429 '#weight' => 1, 00430 ); 00431 00432 $form['reindex']['re-organisms'] = array ( 00433 '#title' => t('Organisms'), 00434 '#type' => t('checkboxes'), 00435 '#description' => t("Check the organisms whoee features you want to reindex. Note: this list contains all organisms, even those that may not be synced."), 00436 '#required' => FALSE, 00437 '#prefix' => '<div id="lib_boxes">', 00438 '#suffix' => '</div>', 00439 '#options' => $org_boxes, 00440 '#weight' => 2, 00441 ); 00442 $form['reindex']['re-button'] = array( 00443 '#type' => 'submit', 00444 '#value' => t('Reindex Features'), 00445 '#weight' => 3, 00446 ); 00447 } 00448 /** 00449 * 00450 * @ingroup tripal_organism 00451 */ 00452 function get_tripal_organism_admin_form_sync_set (&$form) { 00453 // define the fieldsets 00454 $form['sync'] = array( 00455 '#type' => 'fieldset', 00456 '#title' => t('Sync Organisms') 00457 ); 00458 00459 // before proceeding check to see if we have any 00460 // currently processing jobs. If so, we don't want 00461 // to give the opportunity to sync libraries 00462 $active_jobs = FALSE; 00463 if(tripal_get_module_active_jobs('tripal_organism')){ 00464 $active_jobs = TRUE; 00465 } 00466 00467 if(!$active_jobs){ 00468 00469 // get the list of organisms 00470 $sql = "SELECT * FROM {Organism} ORDER BY genus,species"; 00471 $previous_db = tripal_db_set_active('chado'); // use chado database 00472 $org_rset = db_query($sql); 00473 tripal_db_set_active($previous_db); // now use drupal database 00474 00475 // if we've added any organisms to the list that can be synced 00476 // then we want to build the form components to allow the user 00477 // to select one or all of them. Otherwise, just present 00478 // a message stating that all organisms are currently synced. 00479 $org_boxes = array(); 00480 $added = 0; 00481 while($organism = db_fetch_object($org_rset)){ 00482 // check to see if the organism is already present as a node in drupal. 00483 // if so, then skip it. 00484 $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d"; 00485 if(!db_fetch_object(db_query($sql,$organism->organism_id))){ 00486 $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)"; 00487 $added++; 00488 } 00489 } 00490 00491 // if we have organisms we need to add to the checkbox then 00492 // build that form element 00493 if($added > 0){ 00494 $org_boxes['all'] = "All Organisms"; 00495 00496 $form['sync']['organisms'] = array ( 00497 '#title' => t('Available Organisms'), 00498 '#type' => t('checkboxes'), 00499 '#description' => t("Check the organisms you want to sync. Drupal content will be created for each of the organisms listed above. Select 'All Organisms' to sync all of them."), 00500 '#required' => FALSE, 00501 '#prefix' => '<div id="org_boxes">', 00502 '#suffix' => '</div>', 00503 '#options' => $org_boxes, 00504 ); 00505 $form['sync']['button'] = array( 00506 '#type' => 'submit', 00507 '#value' => t('Submit Sync Job') 00508 ); 00509 } 00510 // we don't have any organisms to select from 00511 else { 00512 $form['sync']['value'] = array( 00513 '#value' => t('All organisms in Chado are currently synced with Drupal.') 00514 ); 00515 } 00516 } 00517 // we don't want to present a form since we have an active job running 00518 else { 00519 $form['sync']['value'] = array( 00520 '#value' => t('Currently, jobs exist related to chado organisms. Please check back later for organisms that can by synced once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.') 00521 ); 00522 } 00523 } 00524 /** 00525 * 00526 * @ingroup tripal_organism 00527 */ 00528 function tripal_organism_admin_validate($form, &$form_state) { 00529 global $user; // we need access to the user info 00530 $job_args = array(); 00531 00532 if ($form_state['values']['op'] == t('Submit Sync Job')) { 00533 00534 // check to see if the user wants to sync chado and drupal. If 00535 // so then we need to register a job to do so with tripal 00536 $organisms = $form_state['values']['organisms']; 00537 $do_all = FALSE; 00538 $to_sync = array(); 00539 00540 foreach ($organisms as $organism_id){ 00541 if(preg_match("/^all$/i",$organism_id)){ 00542 $do_all = TRUE; 00543 } 00544 if($organism_id and preg_match("/^\d+$/i",$organism_id)){ 00545 // get the list of organisms 00546 $sql = "SELECT * FROM {Organism} WHERE organism_id = %d"; 00547 $previous_db = tripal_db_set_active('chado'); // use chado database 00548 $organism = db_fetch_object(db_query($sql,$organism_id)); 00549 tripal_db_set_active($previous_db); // now use drupal database 00550 $to_sync[$organism_id] = "$organism->genus $organism->species"; 00551 } 00552 } 00553 00554 // submit the job the tripal job manager 00555 if($do_all){ 00556 tripal_add_job('Sync all organisms','tripal_organism', 00557 'tripal_organism_sync_organisms',$job_args,$user->uid); 00558 } 00559 else{ 00560 foreach($to_sync as $organism_id => $name){ 00561 $job_args[0] = $organism_id; 00562 tripal_add_job("Sync organism: $name",'tripal_organism', 00563 'tripal_organism_sync_organisms',$job_args,$user->uid); 00564 } 00565 } 00566 } 00567 00568 // ------------------------------------- 00569 // Submit the Reindex Job if selected 00570 if ($form_state['values']['op'] == t('Reindex Features')) { 00571 $organisms = $form_state['values']['re-organisms']; 00572 foreach ($organisms as $organism_id){ 00573 if($organism_id and preg_match("/^\d+$/i",$organism_id)){ 00574 // get the organism info 00575 $sql = "SELECT * FROM {organism} WHERE organism_id = %d"; 00576 $previous_db = tripal_db_set_active('chado'); // use chado database 00577 $organism = db_fetch_object(db_query($sql,$organism_id)); 00578 tripal_db_set_active($previous_db); // now use drupal database 00579 $job_args[0] = $organism_id; 00580 tripal_add_job("Reindex features for organism: $organism->genus ". 00581 "$organism->species",'tripal_organism', 00582 'tripal_organism_reindex_features',$job_args,$user->uid); 00583 } 00584 } 00585 } 00586 00587 // ------------------------------------- 00588 // Submit the taxonomy Job if selected 00589 if ($form_state['values']['op'] == t('Set Feature Taxonomy')) { 00590 $organisms = $form_state['values']['tx-organisms']; 00591 foreach ($organisms as $organism_id){ 00592 if($organism_id and preg_match("/^\d+$/i",$organism_id)){ 00593 // get the organism info 00594 $sql = "SELECT * FROM {organism} WHERE organism_id = %d"; 00595 $previous_db = tripal_db_set_active('chado'); // use chado database 00596 $organism = db_fetch_object(db_query($sql,$organism_id)); 00597 tripal_db_set_active($previous_db); // now use drupal database 00598 $job_args[0] = $organism_id; 00599 tripal_add_job("Set taxonomy for features in organism: ". 00600 "$organism->genus $organism->species",'tripal_organism', 00601 'tripal_organism_taxonify_features',$job_args,$user->uid); 00602 } 00603 } 00604 } 00605 00606 // ------------------------------------- 00607 // Submit the Cleanup Job if selected 00608 if ($form_state['values']['op'] == t('Clean up orphaned organisms')) { 00609 tripal_add_job('Cleanup orphaned organisms','tripal_organism', 00610 'tripal_organisms_cleanup',$job_args,$user->uid); 00611 } 00612 } 00613 /** 00614 * We need to let drupal know about our theme functions and their arguments. 00615 * We create theme functions to allow users of the module to customize the 00616 * look and feel of the output generated in this module 00617 * 00618 * @ingroup tripal_organism 00619 */ 00620 function tripal_organism_theme () { 00621 return array( 00622 'tripal_organism_organism_page' => array ( 00623 'arguments' => array('organisms'), 00624 ), 00625 'tripal_organism_base' => array ( 00626 'arguments' => array('node'=> null), 00627 'template' => 'tripal_organism_base', 00628 ), 00629 'tripal_organism_description' => array ( 00630 'arguments' => array('node'=> null), 00631 'template' => 'tripal_organism_description', 00632 ), 00633 'tripal_organism_image' => array ( 00634 'arguments' => array('node'=> null), 00635 'template' => 'tripal_organism_image', 00636 ), 00637 ); 00638 } 00639 /** 00640 * 00641 * @ingroup tripal_organism 00642 */ 00643 function tripal_organism_nodeapi(&$node, $op, $teaser, $page) { 00644 00645 switch ($op) { 00646 case 'view': 00647 switch($node->type){ 00648 00649 } 00650 } 00651 } 00652 /** 00653 * 00654 * @ingroup tripal_organism 00655 */ 00656 function tripal_organism_cron (){ 00657 // we want to make sure that any new organisms or features that were 00658 // added to the database external to drupal automatically get new 00659 // nodes created for themselves in drupal. 00660 // tripal_organism_sync_organisms(); 00661 } 00662 00663 /** 00664 * 00665 * @ingroup tripal_organism 00666 */ 00667 function chado_organism_validate($node,&$form){ 00668 // check to see if the organism already exists, but only for an insert 00669 if(!$node->nid){ 00670 $values = array( 00671 'genus' => $node->genus, 00672 'species' => $node->species, 00673 ); 00674 $organism = tripal_core_chado_select('organism', array('organism_id'),$values); 00675 if(sizeof($organism) > 0){ 00676 form_set_error('genus','Cannot add the organism with this genus and species. 00677 The organism already exists.'); 00678 } 00679 } 00680 } 00681 /** 00682 * When a new chado_organism node is created we also need to add information 00683 * to our chado_organism table. This function is called on insert of a new node 00684 * of type 'chado_organism' and inserts the necessary information. 00685 * 00686 * @ingroup tripal_organism 00687 */ 00688 function chado_organism_insert($node){ 00689 00690 $values = array( 00691 'genus' => $node->genus, 00692 'species' => $node->species, 00693 'abbreviation' => $node->abbreviation, 00694 'common_name' => $node->common_name, 00695 'comment' => $node->description 00696 ); 00697 $organism = tripal_core_chado_insert('organism', $values); 00698 if (!$organism) { 00699 drupal_set_message('Unable to add organism.', 'warning'); 00700 watchdog('tripal_organism', 00701 'Insert Organism: Unable to create organism where values:%values', 00702 array('%values' => print_r($values, TRUE)), 00703 WATCHDOG_WARNING 00704 ); 00705 return; 00706 } 00707 00708 // Make sure the entry for this organism doesn't already exist in the 00709 // chado_organism table if it doesn't exist then we want to add it. 00710 $organism_id = $organism['organism_id']; 00711 if(!chado_get_id_for_node('organism',$node) ){ 00712 // next add the item to the drupal table 00713 $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ". 00714 "VALUES (%d, %d, %d)"; 00715 chado_query($sql,$node->nid,$node->vid,$organism_id); 00716 } 00717 00718 // set the title for the node 00719 $record = new stdClass(); 00720 $record->title = "$node->genus $node->species"; 00721 $record->nid = $node->nid; 00722 drupal_write_record('node',$record,'nid'); 00723 drupal_write_record('node_revisions',$record,'nid'); 00724 00725 // add the image 00726 chado_organism_add_image($node); 00727 } 00728 /** 00729 * Update organisms 00730 * 00731 * @ingroup tripal_organism 00732 */ 00733 function chado_organism_update($node){ 00734 if($node->revision){ 00735 // TODO -- decide what to do about revisions 00736 } else { 00737 $match = array( 00738 'organism_id' => chado_get_id_for_node('organism',$node), 00739 ); 00740 $values = array( 00741 'genus' => $node->genus, 00742 'species' => $node->species, 00743 'abbreviation' => $node->abbreviation, 00744 'common_name' => $node->common_name, 00745 'comment' => $node->description 00746 ); 00747 $org_status = tripal_core_chado_update('organism', $match,$values); 00748 00749 // set the title for the node 00750 $record = new stdClass(); 00751 $record->title = "$node->genus $node->species"; 00752 $record->nid = $node->nid; 00753 drupal_write_record('node',$record,'nid'); 00754 drupal_write_record('node_revisions',$record,'nid'); 00755 00756 // add the image 00757 chado_organism_add_image($node); 00758 00759 } 00760 } 00761 /** 00762 * Delete organism from both drupal and chado databases. Check dependency before 00763 * deleting from chado. 00764 * 00765 * @ingroup tripal_organism 00766 */ 00767 function chado_organism_delete($node){ 00768 $organism_id = chado_get_id_for_node('organism',$node); 00769 00770 // Remove data from the {chado_organism}, {node}, and {node_revisions} tables 00771 $sql_del = "DELETE FROM {chado_organism} ". 00772 "WHERE nid = %d ". 00773 "AND vid = %d"; 00774 db_query($sql_del, $node->nid, $node->vid); 00775 $sql_del = "DELETE FROM {node} ". 00776 "WHERE nid = %d ". 00777 "AND vid = %d"; 00778 db_query($sql_del, $node->nid, $node->vid); 00779 $sql_del = "DELETE FROM {node_revisions} ". 00780 "WHERE nid = %d ". 00781 "AND vid = %d"; 00782 db_query($sql_del, $node->nid, $node->vid); 00783 00784 // Test dependency before deleting from chado database. If a library or 00785 // feature depends on this organism, don't delete it 00786 00787 $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d"; 00788 $previous_db = tripal_db_set_active('chado'); 00789 $check_feature = db_result(db_query($sql, $organism_id)); 00790 $sql = "SELECT library_id FROM {library} WHERE organism_id = %d"; 00791 $check_lib = db_result(db_query($sql, $organism_id)); 00792 00793 if ($check_lib == 0 && $check_feature == 0) { 00794 tripal_core_chado_delete('organism',array('organism_id' => $organism_id)); 00795 } else { 00796 drupal_set_message("Organism deleted from drupal. Warning: at least one ". 00797 "library or feature depends on this organism. It was ". 00798 "not removed from chado."); 00799 } 00800 tripal_db_set_active($previous_db); 00801 } 00802 /** 00803 * 00804 * 00805 * @ingroup tripal_organism 00806 */ 00807 function chado_organism_add_image($node){ 00808 // check to see if a file was uploaded. If so then copy it to the images 00809 // directory for display with the organism 00810 if (isset($_FILES['files']) && $_FILES['files']['name']['organism_image'] && 00811 is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) { 00812 $dest = file_directory_path() . "/tripal/tripal_organism/images"; 00813 $validators = array( 00814 'file_validate_is_image' => array(), 00815 ); 00816 file_check_directory($dest,FILE_CREATE_DIRECTORY,'organism_image'); 00817 if(!$file = file_save_upload('organism_image',$validators,$dest)){ 00818 drupal_set_message("Organism image was not uploaded."); 00819 } 00820 // move this image into the images directory 00821 file_move($file->filepath,$dest . "/".$node->nid.".jpg",FILE_EXISTS_REPLACE); 00822 } 00823 } 00824 00825 00826 /** 00827 * When editing or creating a new node of type 'chado_organism' we need 00828 * a form. This function creates the form that will be used for this. 00829 * 00830 * @ingroup tripal_organism 00831 */ 00832 function chado_organism_form ($node, $param){ 00833 $organism = $node->organism; 00834 00835 // add in the comment since it is a text field and may not be included if too big 00836 $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment'); 00837 00838 // get form defaults 00839 $abbreviation = $node->abbreviation; 00840 if(!$abbreviation){ 00841 $abbreviation = $organism->abbreviation; 00842 } 00843 $genus = $node->genus; 00844 if(!$genus){ 00845 $genus = $organism->genus; 00846 } 00847 $species = $node->species; 00848 if(!$species){ 00849 $species = $organism->species; 00850 } 00851 $common_name = $node->common_name; 00852 if(!$common_name){ 00853 $common_name = $organism->common_name; 00854 } 00855 $description = $node->description; 00856 if(!$description){ 00857 $description = $organism->comment; 00858 } 00859 $organism_image = $node->organism_image; 00860 00861 00862 $form = array(); 00863 $form['#attributes']['enctype'] = 'multipart/form-data'; 00864 00865 $form['abbreviation']= array( 00866 '#type' => 'textfield', 00867 '#title' => t('Abbreviation'), 00868 '#required' => TRUE, 00869 '#default_value' => $organism->abbreviation, 00870 '#weight' => 3 00871 ); 00872 $form['genus']= array( 00873 '#type' => 'textfield', 00874 '#title' => t('Genus'), 00875 '#required' => TRUE, 00876 '#default_value' => $organism->genus, 00877 '#weight' => 1 00878 ); 00879 $form['species']= array( 00880 '#type' => 'textfield', 00881 '#title' => t('Species'), 00882 '#required' => TRUE, 00883 '#default_value' => $organism->species, 00884 '#weight' => 2 00885 ); 00886 $form['common_name']= array( 00887 '#type' => 'textfield', 00888 '#title' => t('Common Name'), 00889 '#required' => TRUE, 00890 '#default_value' => $organism->common_name, 00891 '#weight' => 4 00892 ); 00893 $form['description']= array( 00894 '#type' => 'textarea', 00895 '#rows' => 15, 00896 '#title' => t('Description'), 00897 '#required' => TRUE, 00898 '#default_value' => $organism->comment, 00899 '#weight' => 5 00900 ); 00901 $form['organism_image']= array( 00902 '#type' => 'file', 00903 '#title' => t('Organism Image'), 00904 '#description' => 'Add an image for this organism', 00905 '#weight' => 6 00906 ); 00907 return $form; 00908 } 00909 00910 /** 00911 * When a node is requested by the user this function is called to allow us 00912 * to add auxiliary data to the node object. 00913 * 00914 * @ingroup tripal_organism 00915 */ 00916 function chado_organism_load($node){ 00917 // find the organism and add in the details 00918 $organism_id = chado_get_id_for_node('organism',$node); 00919 $values = array('organism_id' => $organism_id); 00920 $organism = tripal_core_generate_chado_var('organism',$values); 00921 00922 // add in the description field 00923 $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment'); 00924 00925 $additions->organism = $organism; 00926 return $additions; 00927 } 00928 00929 /** 00930 * This function customizes the view of the chado_organism node. It allows 00931 * us to generate the markup. 00932 * 00933 * @ingroup tripal_organism 00934 */ 00935 function chado_organism_view ($node, $teaser = FALSE, $page = FALSE) { 00936 // use drupal's default node view: 00937 $node = node_prepare($node, $teaser); 00938 return $node; 00939 } 00940 00941 /** 00942 * Synchronize organisms from chado to drupal 00943 * 00944 * @ingroup tripal_organism 00945 */ 00946 function tripal_organism_sync_organisms ($organism_id = NULL, $job_id = NULL){ 00947 global $user; 00948 $page_content = ''; 00949 00950 if(!$organism_id){ 00951 $sql = "SELECT * FROM {Organism} O"; 00952 $previous_db = tripal_db_set_active('chado'); // use chado database 00953 $results = db_query($sql); 00954 tripal_db_set_active($previous_db); // now use drupal database 00955 } else { 00956 $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d"; 00957 $previous_db = tripal_db_set_active('chado'); // use chado database 00958 $results = db_query($sql,$organism_id); 00959 tripal_db_set_active($previous_db); // now use drupal database 00960 } 00961 00962 // We'll use the following SQL statement for checking if the organism 00963 // already exists as a drupal node. 00964 $sql = "SELECT * FROM {chado_organism} ". 00965 "WHERE organism_id = %d"; 00966 00967 while($organism = db_fetch_object($results)){ 00968 // check if this organism already exists in the drupal database. if it 00969 // does then skip this organism and go to the next one. 00970 if(!db_fetch_object(db_query($sql,$organism->organism_id))){ 00971 $new_node = new stdClass(); 00972 $new_node->type = 'chado_organism'; 00973 $new_node->uid = $user->uid; 00974 $new_node->title = "$organism->genus $organism->species"; 00975 $new_node->organism_id = $organism->organism_id; 00976 $new_node->genus = $organism->genus; 00977 $new_node->species = $organism->species; 00978 $new_node->description = ''; 00979 node_validate($new_node); 00980 if(!form_get_errors()){ 00981 $node = node_submit($new_node); 00982 node_save($node); 00983 if($node->nid){ 00984 $page_content .= "Added $organism->common_name<br>"; 00985 } 00986 } 00987 } else { 00988 $page_content .= "Skipped $organism->common_name<br>"; 00989 } 00990 } 00991 return $page_content; 00992 } 00993 /** 00994 * Display help and module information 00995 * @param path which path of the site we're displaying help 00996 * @param arg array that holds the current path as would be returned from arg() 00997 * function 00998 * @return help text for the path 00999 * 01000 * @ingroup tripal_organism 01001 */ 01002 function tripal_organism_help($path, $arg) { 01003 $output = ''; 01004 switch ($path) { 01005 case "admin/help#tripal_organism": 01006 $output = '<p>'. 01007 t("Displays links to nodes created on this date"). 01008 '</p>'; 01009 break; 01010 } 01011 return $output; 01012 } 01013 01014 /** 01015 * Display the summary view of organisms when click on the 'Organisms' 01016 * primary-link 01017 * 01018 * @ingroup tripal_organism 01019 */ 01020 function tripal_organism_show_organisms (){ 01021 // Show libraries stored in Drupal's {chado_organism} table 01022 $sql = "SELECT COUNT(organism_id) FROM {chado_organism}"; 01023 $no_orgs = db_result(db_query ($sql)); 01024 if($no_orgs != 0) { 01025 $organisms = get_chado_organisms (); 01026 return theme('tripal_organism_organism_page', $organisms); 01027 } else { 01028 return t("No organism exists. Please contact administrators to ". 01029 "synchronize organisms."); 01030 } 01031 } 01032 /** 01033 * 01034 * @ingroup tripal_organism 01035 */ 01036 function theme_tripal_organism_organism_page($organisms) { 01037 01038 $output = "<br><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>"; 01039 foreach($organisms as $organism){ 01040 // Prepare information for html output 01041 $org_url = url("node/$organism->node_id"); 01042 01043 // Generate html output 01044 $output .= "<div class=\"tripal_chado_organism-info-box\" style=\"padding:5px\"> 01045 <div class=\"tripal_expandableBox\"> 01046 <h3>$organism->common_name</h3> 01047 </div> 01048 <div class=\"tripal_expandableBoxContent\"> 01049 <span> 01050 <table class=\"tripal_chado_analysis_content\"> 01051 <tr><td> 01052 Name: <a href=\"$org_url\">$organism->common_name</a> 01053 </td></tr> 01054 <tr><td> 01055 Genus: $organism->genus 01056 </td></tr> 01057 <tr><td> 01058 Species: $organism->species 01059 </td></tr> 01060 <tr><td> 01061 Description: $organism->comment 01062 </td></tr> 01063 </table> 01064 </span> 01065 </div> 01066 </div>"; 01067 } 01068 return $output; 01069 } 01070 01071 /** 01072 * This function uses organism_id's of all drupal organism nodes as input and 01073 * pull the organism information (genus, species, common_name, comment) from 01074 * chado database. The return type is an object array that stores $organism 01075 * objects sorted by common_name 01076 * 01077 * @ingroup tripal_organism 01078 */ 01079 function get_chado_organisms() { 01080 $sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}"; 01081 $no_orgs = db_result(db_query($sql_drupal)); 01082 if ($no_orgs != 0) { 01083 $sql = "SELECT organism_id, nid FROM {chado_organism}"; 01084 $result = db_query($sql); 01085 $previous_db = tripal_db_set_active('chado'); 01086 $sql = "SELECT genus, species, common_name, comment ". 01087 "FROM {Organism} ". 01088 "WHERE organism_id=%d"; 01089 $organisms = array(); 01090 $count = 0; 01091 while ($data = db_fetch_object($result)) { 01092 $organism = db_fetch_object(db_query($sql, $data->organism_id)); 01093 $organism->node_id = $data->nid; 01094 // Use common_name plus $count as the key so we can sort by common 01095 // name later. Since common_name is not unique, we need to add $count 01096 // to the key 01097 $key = strtolower($organism->common_name).$count; 01098 $organisms [$key] = $organism; 01099 $count ++; 01100 } 01101 tripal_db_set_active($previous_db); 01102 01103 //Sort organisms by common name 01104 ksort($organisms, SORT_STRING); 01105 return $organisms; 01106 } 01107 } 01108 /** 01109 * 01110 * @ingroup tripal_organism 01111 */ 01112 function tripal_organism_reindex_features ($organism_id = NULL, $job_id = NULL){ 01113 $i = 0; 01114 01115 if(!$organism_id){ 01116 return; 01117 } 01118 01119 $sql = "SELECT * ". 01120 "FROM {feature} ". 01121 "WHERE organism_id = $organism_id ". 01122 "ORDER BY feature_id"; 01123 $previous_db = tripal_db_set_active('chado'); // use chado database 01124 $results = db_query($sql); 01125 tripal_db_set_active($previous_db); // now use drupal databa tripal_db_set_active($previous_db); // now use drupal database 01126 01127 // load into ids array 01128 $count = 0; 01129 $ids = array(); 01130 while($id = db_fetch_object($results)){ 01131 $ids[$count] = $id->feature_id; 01132 $count++; 01133 } 01134 01135 $interval = intval($count * 0.01); 01136 foreach($ids as $feature_id){ 01137 // update the job status every 1% features 01138 if($job_id and $i % $interval == 0){ 01139 tripal_job_set_progress($job_id,intval(($i/$count)*100)); 01140 } 01141 tripal_feature_sync_feature ($feature_id); 01142 $i++; 01143 } 01144 } 01145 /** 01146 * 01147 * @ingroup tripal_organism 01148 */ 01149 function tripal_organism_taxonify_features ($organism_id = NULL, $job_id = NULL){ 01150 $i = 0; 01151 01152 if(!$organism_id){ 01153 return; 01154 } 01155 01156 $sql = "SELECT * ". 01157 "FROM {feature} ". 01158 "WHERE organism_id = $organism_id ". 01159 "ORDER BY feature_id"; 01160 $previous_db = tripal_db_set_active('chado'); // use chado database 01161 $results = db_query($sql); 01162 tripal_db_set_active($previous_db); // now use drupal database 01163 01164 // load into ids array 01165 $count = 0; 01166 $ids = array(); 01167 while($id = db_fetch_object($results)){ 01168 $ids[$count] = $id->feature_id; 01169 $count++; 01170 } 01171 01172 // make sure our vocabularies are set before proceeding 01173 tripal_feature_set_vocabulary(); 01174 01175 // use this SQL for getting the nodes 01176 $nsql = "SELECT * FROM {chado_feature} CF ". 01177 " INNER JOIN {node} N ON N.nid = CF.nid ". 01178 "WHERE feature_id = %d"; 01179 01180 // iterate through the features and set the taxonomy 01181 $interval = intval($count * 0.01); 01182 foreach($ids as $feature_id){ 01183 // update the job status every 1% features 01184 if($job_id and $i % $interval == 0){ 01185 tripal_job_set_progress($job_id,intval(($i/$count)*100)); 01186 } 01187 $node = db_fetch_object(db_query($nsql,$feature_id)); 01188 tripal_feature_set_taxonomy($node,$feature_id); 01189 $i++; 01190 } 01191 } 01192 /** 01193 * Returns a list of organisms that are currently synced with Drupal 01194 * @ingroup tripal_organism 01195 */ 01196 function tripal_organism_get_synced() { 01197 01198 // use this SQL for getting synced organisms 01199 $dsql = "SELECT * FROM {chado_organism}"; 01200 $orgs = db_query($dsql); 01201 01202 // use this SQL statement for getting the organisms 01203 $csql = "SELECT * FROM {Organism} ". 01204 "WHERE organism_id = %d"; 01205 01206 $org_list = array(); 01207 01208 // iterate through the organisms and build an array of those that are synced 01209 while($org = db_fetch_object($orgs)){ 01210 $previous_db = tripal_db_set_active('chado'); // use chado database 01211 $info = db_fetch_object(db_query($csql,$org->organism_id)); 01212 tripal_db_set_active($previous_db); // now use drupal database 01213 $org_list[] = $info; 01214 } 01215 return $org_list; 01216 } 01217 /** 01218 * 01219 * @ingroup tripal_organism 01220 */ 01221 function tripal_organisms_cleanup($dummy = NULL, $job_id = NULL) { 01222 01223 // build the SQL statments needed to check if nodes point to valid organisms 01224 $dsql = "SELECT * FROM {node} WHERE type = 'chado_organism' order by nid"; 01225 $nsql = "SELECT * FROM {node} WHERE nid = %d"; 01226 $csql = "SELECT * FROM {chado_organism} where nid = %d "; 01227 $cosql= "SELECT * FROM {chado_organism}"; 01228 $tsql = "SELECT * FROM {Organism} O ". 01229 "WHERE organism_id = %d"; 01230 01231 // load into nodes array 01232 $results = db_query($dsql); 01233 $count = 0; 01234 $nodes = array(); 01235 while($node = db_fetch_object($results)){ 01236 $nodes[$count] = $node; 01237 $count++; 01238 } 01239 01240 // load the chado_organisms into an array 01241 $results = db_query($cosql); 01242 $cnodes = array(); 01243 while($node = db_fetch_object($results)){ 01244 $cnodes[$count] = $node; 01245 $count++; 01246 } 01247 $interval = intval($count * 0.01); 01248 01249 // iterate through all of the chado_organism nodes and delete those that aren't valid 01250 foreach($nodes as $nid){ 01251 01252 // update the job status every 1% organisms 01253 if($job_id and $i % $interval == 0){ 01254 tripal_job_set_progress($job_id,intval(($i/$count)*100)); 01255 } 01256 01257 // first check to see if the node has a corresponding entry 01258 // in the chado_organism table. If not then delete the node. 01259 $organism = db_fetch_object(db_query($csql,$nid->nid)); 01260 if(!$organism){ 01261 node_delete($nid->nid); 01262 $message = "Missing in chado_organism table.... DELETING: $nid->nid\n"; 01263 watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING); 01264 continue; 01265 } 01266 $i++; 01267 } 01268 01269 // iterate through all of the chado_organism nodes and delete those that aren't valid 01270 foreach($cnodes as $nid){ 01271 // update the job status every 1% organisms 01272 if($job_id and $i % $interval == 0){ 01273 tripal_job_set_progress($job_id,intval(($i/$count)*100)); 01274 } 01275 $node = db_fetch_object(db_query($nsql,$nid->nid)); 01276 if(!$node){ 01277 db_query("DELETE FROM {chado_organism} WHERE nid = $nid->nid"); 01278 $message = "chado_organism missing node.... DELETING: $nid->nid\n"; 01279 watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING); 01280 } 01281 01282 $i++; 01283 } 01284 return ''; 01285 } 01286 01287 /** 01288 * Implements hook_views_api() 01289 * Purpose: Essentially this hook tells drupal that there is views support for 01290 * for this module which then includes tripal_db.views.inc where all the 01291 * views integration code is 01292 * 01293 * @ingroup tripal_organism 01294 */ 01295 function tripal_organism_views_api() { 01296 return array( 01297 'api' => 2.0, 01298 ); 01299 }