1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147 |
- <?php
- require_once "tripal_organism.api.inc";
- function tripal_organism_init(){
-
- drupal_add_js (drupal_get_path('theme', 'tripal').'/js/tripal_organism.js');
- drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_organism.css');
- }
- function tripal_organism_node_info() {
- $nodes = array();
- $nodes['chado_organism'] = array(
- 'name' => t('Organism'),
- 'module' => 'chado_organism',
- 'description' => t('An organism from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Organism'),
- 'has_body' => FALSE,
- 'body_label' => t('Organism Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function tripal_organism_block($op = 'list', $delta = '0', $edit = array()){
- switch($op){
- case 'list':
- $blocks['base']['info'] = t('Tripal Organism Details');
- $blocks['base']['cache'] = BLOCK_NO_CACHE;
- $blocks['description']['info'] = t('Tripal Organism Description');
- $blocks['description']['cache'] = BLOCK_NO_CACHE;
- $blocks['image']['info'] = t('Tripal Organism Image');
- $blocks['image']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- case 'view':
- if(user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
- $nid = arg(1);
- $node = node_load($nid);
- $block = array();
- switch($delta){
- case 'base':
- $block['subject'] = t('Organism Details');
- $block['content'] = theme('tripal_organism_base',$node);
- break;
- case 'description':
- $block['subject'] = t('Organism Description');
- $block['content'] = theme('tripal_organism_description',$node);
- break;
- case 'image':
- $block['subject'] = t('Organism Image');
- $block['content'] = theme('tripal_organism_image',$node);
- break;
- default:
- }
- return $block;
- }
- }
- }
- function tripal_organism_menu() {
- $items = array();
- $items['organisms'] = array(
- 'menu_name' => ('primary-links'),
- 'title' => t('Organisms'),
- 'page callback' => 'tripal_organism_show_organisms',
- 'access arguments' => array('access chado_organism content'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_organism'] = array(
- 'title' => 'Organisms',
- 'description' => 'Basic Description of Tripal Organism Module Functionality',
- 'page callback' => 'tripal_organism_module_description_page',
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
- $items['admin/tripal/tripal_organism/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Manage integration of Chado organisms including associated features',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_organism_admin'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
-
- return $items;
- }
- function chado_organism_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_organism content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_organism content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_organism content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_organism content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function tripal_organism_perm(){
- return array(
- 'access chado_organism content',
- 'create chado_organism content',
- 'delete chado_organism content',
- 'edit chado_organism content',
- );
- }
- function tripal_organism_module_description_page() {
- $text = '';
-
- $text .= '<h3>Description:</h3>';
-
- $text .= '<p>The Tripal Organism module allows you to add, edit and/or delete chado organisms. Furthermore, it also provides listing of organisms and details page for each organism. Basically, the chado organism module is designed to hold information about a given species. For more information on the chado organism module see the <a href="http://gmod.org/wiki/Chado_Organism_Module">GMOD wiki page</a></p>';
- $text .= '<h3>Post Installation Instructions:</h3>';
-
- $text .= '<p>This module also provides <b>User Permissions</b> to control which users or groups of users (roles) can view/access organism content (access chado_organism content), create organisms (create chado_organism content), edit or delete organisms (edit chado_organism content or delete chado_organism content). The default is that only the original administration account has these permissions. To allow additional users/roles any combination of the above permissions:</p>';
- $text .= '<ol>';
- $text .= '<li><a href="../user/roles">Add Roles</a> to provide permissions to. For example, you might want a "View Tripal organism Content" and a "Manage Tripal organism Content" Role. If you only want to provide permissions based on whether the user is logged in (authenticated) or not (anonymous) then you don\'t need to create roles.</li>';
- $text .= '<li><a href="../user/permissions">Assign permissions</a> to roles. Specically focus on those mentioned above, then for each permission add a checkmark to the rolw (columns) that you want to have this permission.</li>';
- $text .= '<li><a href="../user/user">Assign Users Roles</a>. This is what gives a given user the set of permissions associated with a given role. Notice that you can assign more than one role to a user and that each user is "Authenticated" by default. A user has permission is any of his/her roles have that permission.</li>';
- $text .= '</ol>';
-
- $text .= '<p>Another important step, <b>if you chado database already contains organisms, is to sync\' Chado with Drupal</b>. This creates Drupal Content including detail pages for each organism (known as nodes in Drupal). To sync\' Chado with Drupal simply go to the <a href="tripal_organism/configuration">Configuration Page for organisms</a> and in the "Sync Organisms" Fieldset select the Organisms you would like to sync.</p>';
-
-
- $text .= '<h3>Features of this Module:</h3>';
-
- $text .= '<b><a href="../../node/add/chado_organism">Create an Organism:</a></b>';
- $text .= '<p>This allows you to create content in your drupal and chado for an organism (only the unique organism identifier is duplicated). An organism must have a genus, species, abreviation, common name. In addition, you can optionally supply a short description.</p>';
-
- $text .= '<b>Details Page of a Organism:</b>';
- $text .= '<p>Each organism get\'s it\'s own page on this website. This page is meant to give an overall picture of the organism and it\'s associated details. To understand where it is -All page content in Drupal is known as a node and is given a unique identifier or nid. Thus every drupal page has a path of node/<nid>. You can get to the Details page for a given organism from either of the organism listings described below.</p>';
- $text .= '<p>If you want to customize the look of the Organism Details page simply copy the PHP/HTML template node-chado_organism.tpl.php from theme_tripal to the base theme you are currently using. Then edit it as desired. There are plans to integrate this details page with Drupal Panels which will provide a much more user-friendly and no-programming-needed method to customize this page.</p>';
-
- $text .= '<b>Updating/Deleting Organisms:</b>';
- $text .= '<p>The Organisms Details Page also acts as a landing pad for updating/deleting organisms. To <b>update an organism</b>, go to the organism details page and click on the Edit tab near the top of the page. This tab will only be visable if you have permission to edit chado organism content (See post installation steps above for information on setting user permissions). If you want to <b>delete an organism</b>, click the Edit tab and then near the bottom of the form, click the Delete button. This will delete the entire organism and cannot be undone.</p>';
-
- $text .= '<b><a href="../../organisms">Basic Listing of Organisms:</a></b>';
- $text .= '<p>This module also provides a basic listing of all organisms currently sync\'d with Drupal. To access this listing, there should be a Stocks Primary Menu item which links you to <a href="../../organisms">this page</a>. This page lists each organism in it\'s own triapl expandable box and provides a link to each organism by clicking on it\'s common name. Currently there is no way to easily customize this listing.</p>';
-
- $text .= '<b><a href="../build/views/">Flexible Listing of Organisms using Drupal Views:</a></b>';
- $text .= '<p>In order to access a more flexible listing of organisms you must first install the <a href="http://drupal.org/project/views">Drupal Views2 module</a>. You should then be able to access the default views <a href="../build/views/">here</a>. Essentially, Views is a module which allows you to create custom SQL queries completely through the web interface without knowing SQL. Furthermore, it also does some formatting of the results allowing you to display them as HTML lists, tables or grids. You can also expose filters to the user to let them customize the results they see and even implement various sorting.</p>';
- $text .= '<p>To use one of the Default Views simply click "Enable" and then "Edit" to change it to show exactly what you want. To view the current listing simply clikc "View Page" at the top of the Edit user interface. There are a number of good tutorials out there for Views2, any of which can be used to help you create your own custom listings of biological content. (Note: there aren\'t any tutorials specifically for tripal content but any tutorial for Views2 will show you how to use the views interface.</p>';
-
- return $text;
- }
- function tripal_organism_admin () {
- $form = array();
-
-
-
- $active_jobs = FALSE;
- if(tripal_get_module_active_jobs('tripal_organism')){
- $active_jobs = TRUE;
- }
-
- if(!$active_jobs){
- get_tripal_organism_admin_form_sync_set($form);
- get_tripal_organism_admin_form_reindex_set($form);
- get_tripal_organism_admin_form_taxonomy_set($form);
- get_tripal_organism_admin_form_cleanup_set($form);
- } else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Organism Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#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.'),
- );
- }
- return system_settings_form($form);
- }
- function get_tripal_organism_admin_form_cleanup_set(&$form) {
- $form['cleanup'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clean Up')
- );
- $form['cleanup']['description'] = array(
- '#type' => 'item',
- '#value' => t("With Drupal and chado residing in different databases ".
- "it is possible that nodes in Drupal and organisms in Chado become ".
- "\"orphaned\". This can occur if an organism node in Drupal is ".
- "deleted but the corresponding chado organism is not and/or vice ".
- "versa. Click the button below to resolve these discrepancies."),
- '#weight' => 1,
- );
- $form['cleanup']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Clean up orphaned organisms'),
- '#weight' => 2,
- );
- }
- function get_tripal_organism_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Organism Features')
- );
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $org_boxes = array();
- while($organism = db_fetch_object($org_rset)){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
- }
- $form['taxonify']['description'] = array(
- '#type' => 'item',
- '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
- "nodes. These terms allow for advanced filtering during searching. This option allows ".
- "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."),
- '#weight' => 1,
- );
- $form['taxonify']['tx-organisms'] = array (
- '#title' => t('Organisms'),
- '#type' => t('checkboxes'),
- '#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."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- '#weight' => 2
- );
- $form['taxonify']['tx-button'] = array(
- '#type' => 'submit',
- '#value' => t('Set Feature Taxonomy'),
- '#weight' => 3
- );
- }
- function get_tripal_organism_admin_form_reindex_set(&$form) {
-
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Organism Features')
- );
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $org_boxes = array();
- while($organism = db_fetch_object($org_rset)){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#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."),
- '#weight' => 1,
- );
- $form['reindex']['re-organisms'] = array (
- '#title' => t('Organisms'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the organisms whoee features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- '#weight' => 2,
- );
- $form['reindex']['re-button'] = array(
- '#type' => 'submit',
- '#value' => t('Reindex Features'),
- '#weight' => 3,
- );
- }
- function get_tripal_organism_admin_form_sync_set (&$form) {
-
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Organisms')
- );
-
-
-
- $active_jobs = FALSE;
- if(tripal_get_module_active_jobs('tripal_organism')){
- $active_jobs = TRUE;
- }
- if(!$active_jobs){
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
-
-
-
- $org_boxes = array();
- $added = 0;
- while($organism = db_fetch_object($org_rset)){
-
-
- $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d";
- if(!db_fetch_object(db_query($sql,$organism->organism_id))){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
- $added++;
- }
- }
-
-
- if($added > 0){
- $org_boxes['all'] = "All Organisms";
- $form['sync']['organisms'] = array (
- '#title' => t('Available Organisms'),
- '#type' => t('checkboxes'),
- '#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."),
- '#required' => FALSE,
- '#prefix' => '<div id="org_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- );
- $form['sync']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Submit Sync Job')
- );
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('All organisms in Chado are currently synced with Drupal.')
- );
- }
- }
-
- else {
- $form['sync']['value'] = array(
- '#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.')
- );
- }
- }
- function tripal_organism_admin_validate($form, &$form_state) {
- global $user;
- $job_args = array();
- if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-
- $organisms = $form_state['values']['organisms'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($organisms as $organism_id){
- if(preg_match("/^all$/i",$organism_id)){
- $do_all = TRUE;
- }
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $to_sync[$organism_id] = "$organism->genus $organism->species";
- }
- }
-
- if($do_all){
- tripal_add_job('Sync all organisms','tripal_organism',
- 'tripal_organism_sync_organisms',$job_args,$user->uid);
- }
- else{
- foreach($to_sync as $organism_id => $name){
- $job_args[0] = $organism_id;
- tripal_add_job("Sync organism: $name",'tripal_organism',
- 'tripal_organism_sync_organisms',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Reindex Features')) {
- $organisms = $form_state['values']['re-organisms'];
- foreach ($organisms as $organism_id){
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $organism_id;
- tripal_add_job("Reindex features for organism: $organism->genus ".
- "$organism->species",'tripal_organism',
- 'tripal_organism_reindex_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- $organisms = $form_state['values']['tx-organisms'];
- foreach ($organisms as $organism_id){
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $organism_id;
- tripal_add_job("Set taxonomy for features in organism: ".
- "$organism->genus $organism->species",'tripal_organism',
- 'tripal_organism_taxonify_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
- tripal_add_job('Cleanup orphaned organisms','tripal_organism',
- 'tripal_organisms_cleanup',$job_args,$user->uid);
- }
- }
- function tripal_organism_theme () {
- return array(
- 'tripal_organism_organism_page' => array (
- 'arguments' => array('organisms'),
- ),
- 'tripal_organism_base' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_base',
- ),
- 'tripal_organism_description' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_description',
- ),
- 'tripal_organism_image' => array (
- 'arguments' => array('node'=> null),
- 'template' => 'tripal_organism_image',
- ),
- );
- }
- function tripal_organism_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'view':
- switch($node->type){
-
- }
- }
- }
- function tripal_organism_cron (){
-
-
-
- }
- function chado_organism_insert($node){
-
- $o_sql = "SELECT organism_id ".
- "FROM {Organism} ".
- "WHERE genus = '%s' ".
- "AND species = '%s'";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
- tripal_db_set_active($previous_db);
-
- if(!$organism){
-
- $sql = "INSERT INTO {organism} ".
- " (abbreviation, genus, species,common_name,comment) VALUES ".
- " ('%s','%s','%s','%s','%s')";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->abbreviation, $node->genus,
- $node->species,$node->common_name,$node->description);
-
- $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
- tripal_db_set_active($previous_db);
- }
-
-
- $node_check_sql = "SELECT * FROM {chado_organism} ".
- "WHERE organism_id = %d";
- $node_check = db_fetch_object(db_query($node_check_sql,
- $organism->organism_id));
- if(!$node_check){
-
- $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql,$node->nid,$node->vid,$organism->organism_id);
- }
- $record = new stdClass();
- $record->title = "$node->genus $node->species";
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- function chado_organism_delete($node){
-
-
- $sql_drupal = "SELECT organism_id ".
- "FROM {chado_organism} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- $organism_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
- $sql_del = "DELETE FROM {chado_organism} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
-
- $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $check_feature = db_result(db_query($sql, $organism_id));
- $sql = "SELECT library_id FROM {library} WHERE organism_id = %d";
- $check_lib = db_result(db_query($sql, $organism_id));
- if ($check_lib == 0 && $check_feature == 0) {
-
-
- db_query("DELETE FROM {organism} WHERE organism_id = %d", $organism_id);
- db_query("DELETE FROM {organism_dbxref} WHERE organism_id = %d",
- $organism_id);
- db_query("DELETE FROM {organismprop} WHERE organism_id = %d",
- $organism_id);
- } else {
- drupal_set_message("Organism deleted from drupal. Warning: at least one ".
- "library or feature depends on this organism. It was ".
- "not removed from chado.");
- }
- tripal_db_set_active($previous_db);
- }
- function chado_organism_validate($node){
-
-
- if (isset($_FILES['files']) && $_FILES['files']['name']['organism-image'] &&
- is_uploaded_file($_FILES['files']['tmp_name']['organism-image'])) {
- $dest = file_directory_path() . "/tripal/tripal_organism/images";
- $validators = array(
- 'file_validate_is_image' => array(),
- );
- file_check_directory($dest,FILE_CREATE_DIRECTORY,'organism-image');
- if(!$file = file_save_upload('organism-image',$validators,$dest)){
- drupal_set_message("Organism image was not uploaded.");
- }
-
- file_move($file->filepath,$dest . "/".$node->genus."_".$node->species.".jpg",FILE_EXISTS_REPLACE);
- }
- }
- function chado_organism_update($node){
- if($node->revision){
-
- } else {
-
- $sql = "SELECT organism_id ".
- "FROM {chado_organism} ".
- "WHERE nid = %d";
- $org = db_fetch_object(db_query($sql, $node->nid));
- $sql = "UPDATE {organism} ".
- " SET comment = '%s', ".
- " abbreviation = '%s', ".
- " genus = '%s', ".
- " species = '%s', ".
- " common_name = '%s' ".
- "WHERE organism_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->description, $node->abbreviation, $node->genus,
- $node->species,$node->common_name,$org->organism_id);
- tripal_db_set_active($previous_db);
-
-
- $record = new stdClass();
- $record->title = "$node->genus $node->species";
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- }
- function chado_organism_form ($node, $param){
- $organism = $node->organism;
- $type = node_get_types('type',$node);
- $form = array();
- $form['#attributes']['enctype'] = 'multipart/form-data';
- $form['abbreviation']= array(
- '#type' => 'textfield',
- '#title' => t('Abbreviation'),
- '#required' => TRUE,
- '#default_value' => $organism->abbreviation,
- '#weight' => 3
- );
- $form['genus']= array(
- '#type' => 'textfield',
- '#title' => t('Genus'),
- '#required' => TRUE,
- '#default_value' => $organism->genus,
- '#weight' => 1
- );
- $form['species']= array(
- '#type' => 'textfield',
- '#title' => t('Species'),
- '#required' => TRUE,
- '#default_value' => $organism->species,
- '#weight' => 2
- );
- $form['common_name']= array(
- '#type' => 'textfield',
- '#title' => t('Common Name'),
- '#required' => TRUE,
- '#default_value' => $organism->common_name,
- '#weight' => 4
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#rows' => 15,
- '#title' => t('Description'),
- '#required' => TRUE,
- '#default_value' => check_plain($organism->description),
- '#weight' => 5
- );
- $form['organism-image']= array(
- '#type' => 'file',
- '#title' => t('Organism Image'),
- '#description' => 'Add an image for this organism',
- '#weight' => 6
- );
- return $form;
- }
- function chado_organism_load($node){
-
- $sql = "SELECT organism_id FROM {chado_organism} WHERE vid = %d";
- $org_node = db_fetch_object(db_query($sql, $node->vid));
-
- $previous_db = tripal_db_set_active('chado');
- if ($org_node->organism_id) {
- $sql = "SELECT O.organism_id,O.genus,O.species, ".
- " O.common_name, O.comment as description, O.abbreviation ".
- "FROM {Organism} O ".
- "WHERE O.Organism_id = $org_node->organism_id";
- $organism = db_fetch_object(db_query($sql));
- $additions->organism = $organism;
- }
- tripal_db_set_active($previous_db);
- return $additions;
- }
- function chado_organism_view ($node, $teaser = FALSE, $page = FALSE) {
-
- $node = node_prepare($node, $teaser);
- return $node;
- }
- function tripal_organism_sync_organisms ($organism_id = NULL, $job_id = NULL){
- global $user;
- $page_content = '';
- if(!$organism_id){
- $sql = "SELECT * FROM {Organism} O";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- } else {
- $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$organism_id);
- tripal_db_set_active($previous_db);
- }
-
-
- $sql = "SELECT * FROM {chado_organism} ".
- "WHERE organism_id = %d";
- while($organism = db_fetch_object($results)){
-
-
- if(!db_fetch_object(db_query($sql,$organism->organism_id))){
- $new_node = new stdClass();
- $new_node->type = 'chado_organism';
- $new_node->uid = $user->uid;
- $new_node->title = "$organism->genus $organism->species";
- $new_node->organism_id = $organism->organism_id;
- $new_node->genus = $organism->genus;
- $new_node->species = $organism->species;
- $new_node->description = '';
- node_validate($new_node);
- if(!form_get_errors()){
- $node = node_submit($new_node);
- node_save($node);
- if($node->nid){
- $page_content .= "Added $organism->common_name<br>";
- }
- }
- } else {
- $page_content .= "Skipped $organism->common_name<br>";
- }
- }
- return $page_content;
- }
- function tripal_organism_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_organism":
- $output = '<p>'.
- t("Displays links to nodes created on this date").
- '</p>';
- break;
- }
- return $output;
- }
- function tripal_organism_show_organisms (){
-
- $sql = "SELECT COUNT(organism_id) FROM {chado_organism}";
- $no_orgs = db_result(db_query ($sql));
- if($no_orgs != 0) {
- $organisms = get_chado_organisms ();
- return theme('tripal_organism_organism_page', $organisms);
- } else {
- return t("No organism exists. Please contact administrators to ".
- "synchronize organisms.");
- }
- }
- function theme_tripal_organism_organism_page($organisms) {
- $output = "<br><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>";
- foreach($organisms as $organism){
-
- $org_url = url("node/$organism->node_id");
-
-
- $output .= "<div class=\"tripal_chado_organism-info-box\" style=\"padding:5px\">
- <div class=\"tripal_expandableBox\">
- <h3>$organism->common_name</h3>
- </div>
- <div class=\"tripal_expandableBoxContent\">
- <span>
- <table class=\"tripal_chado_analysis_content\">
- <tr><td>
- Name: <a href=\"$org_url\">$organism->common_name</a>
- </td></tr>
- <tr><td>
- Genus: $organism->genus
- </td></tr>
- <tr><td>
- Species: $organism->species
- </td></tr>
- <tr><td>
- Description: $organism->comment
- </td></tr>
- </table>
- </span>
- </div>
- </div>";
- }
- return $output;
- }
- function get_chado_organisms() {
- $sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}";
- $no_orgs = db_result(db_query($sql_drupal));
- if ($no_orgs != 0) {
- $sql = "SELECT organism_id, nid FROM {chado_organism}";
- $result = db_query($sql);
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT genus, species, common_name, comment ".
- "FROM {Organism} ".
- "WHERE organism_id=%d";
- $organisms = array();
- $count = 0;
- while ($data = db_fetch_object($result)) {
- $organism = db_fetch_object(db_query($sql, $data->organism_id));
- $organism->node_id = $data->nid;
-
-
-
- $key = strtolower($organism->common_name).$count;
- $organisms [$key] = $organism;
- $count ++;
- }
- tripal_db_set_active($previous_db);
-
- ksort($organisms, SORT_STRING);
- return $organisms;
- }
- }
- function tripal_organism_reindex_features ($organism_id = NULL, $job_id = NULL){
- $i = 0;
- if(!$organism_id){
- return;
- }
- $sql = "SELECT * ".
- "FROM {feature} ".
- "WHERE organism_id = $organism_id ".
- "ORDER BY feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $count = 0;
- $ids = array();
- while($id = db_fetch_object($results)){
- $ids[$count] = $id->feature_id;
- $count++;
- }
- $interval = intval($count * 0.01);
- foreach($ids as $feature_id){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- tripal_feature_sync_feature ($feature_id);
- $i++;
- }
- }
- function tripal_organism_taxonify_features ($organism_id = NULL, $job_id = NULL){
- $i = 0;
- if(!$organism_id){
- return;
- }
- $sql = "SELECT * ".
- "FROM {feature} ".
- "WHERE organism_id = $organism_id ".
- "ORDER BY feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $count = 0;
- $ids = array();
- while($id = db_fetch_object($results)){
- $ids[$count] = $id->feature_id;
- $count++;
- }
-
- tripal_feature_set_vocabulary();
-
- $nsql = "SELECT * FROM {chado_feature} CF ".
- " INNER JOIN {node} N ON N.nid = CF.nid ".
- "WHERE feature_id = %d";
-
- $interval = intval($count * 0.01);
- foreach($ids as $feature_id){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$feature_id));
- tripal_feature_set_taxonomy($node,$feature_id);
- $i++;
- }
- }
- function tripal_organism_get_synced() {
-
- $dsql = "SELECT * FROM {chado_organism}";
- $orgs = db_query($dsql);
-
- $csql = "SELECT * FROM {Organism} ".
- "WHERE organism_id = %d";
- $org_list = array();
-
- while($org = db_fetch_object($orgs)){
- $previous_db = tripal_db_set_active('chado');
- $info = db_fetch_object(db_query($csql,$org->organism_id));
- tripal_db_set_active($previous_db);
- $org_list[] = $info;
- }
- return $org_list;
- }
- function tripal_organisms_cleanup($dummy = NULL, $job_id = NULL) {
-
- $dsql = "SELECT * FROM {node} WHERE type = 'chado_organism' order by nid";
- $nsql = "SELECT * FROM {node} WHERE nid = %d";
- $csql = "SELECT * FROM {chado_organism} where nid = %d ";
- $cosql= "SELECT * FROM {chado_organism}";
- $tsql = "SELECT * FROM {Organism} O ".
- "WHERE organism_id = %d";
-
- $results = db_query($dsql);
- $count = 0;
- $nodes = array();
- while($node = db_fetch_object($results)){
- $nodes[$count] = $node;
- $count++;
- }
-
- $results = db_query($cosql);
- $cnodes = array();
- while($node = db_fetch_object($results)){
- $cnodes[$count] = $node;
- $count++;
- }
- $interval = intval($count * 0.01);
-
- foreach($nodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
-
-
- $organism = db_fetch_object(db_query($csql,$nid->nid));
- if(!$organism){
- node_delete($nid->nid);
- $message = "Missing in chado_organism table.... DELETING: $nid->nid\n";
- watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING);
- continue;
- }
- $i++;
- }
-
- foreach($cnodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$nid->nid));
- if(!$node){
- db_query("DELETE FROM {chado_organism} WHERE nid = $nid->nid");
- $message = "chado_organism missing node.... DELETING: $nid->nid\n";
- watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING);
- }
- $i++;
- }
- return '';
- }
-
- function tripal_organism_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
|