|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
-require_once "tripal_organism.api.inc";
|
|
|
+require_once "api/tripal_organism.api.inc";
|
|
|
+require_once "includes/tripal_organism.admin.inc";
|
|
|
|
|
|
/**
|
|
|
* @file
|
|
@@ -100,7 +101,8 @@ function tripal_organism_menu() {
|
|
|
$items['admin/tripal/tripal_organism'] = array(
|
|
|
'title' => 'Organisms',
|
|
|
'description' => 'Basic Description of Tripal Organism Module Functionality',
|
|
|
- 'page callback' => 'tripal_organism_module_description_page',
|
|
|
+ 'page callback' => 'theme',
|
|
|
+ 'page arguments' => array('tripal_organism_admin'),
|
|
|
'access arguments' => array('adminster tripal organism'),
|
|
|
'type' => MENU_NORMAL_ITEM,
|
|
|
);
|
|
@@ -117,6 +119,38 @@ function tripal_organism_menu() {
|
|
|
|
|
|
return $items;
|
|
|
}
|
|
|
+/**
|
|
|
+ * 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
|
|
|
+ *
|
|
|
+ * @ingroup tripal_organism
|
|
|
+ */
|
|
|
+function tripal_organism_theme() {
|
|
|
+ return array(
|
|
|
+ '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',
|
|
|
+ ),
|
|
|
+ 'tripal_organism_teaser' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
+ 'template' => 'tripal_organism_teaser',
|
|
|
+ ),
|
|
|
+ 'tripal_organism_admin' => array(
|
|
|
+ 'template' => 'tripal_organism_admin',
|
|
|
+ 'arguments' => array(NULL),
|
|
|
+ 'path' => drupal_get_path('module', 'tripal_organism') . '/theme'
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
/**
|
|
|
* The following function proves access control for users trying to
|
|
|
* perform actions on data managed by this module
|
|
@@ -164,475 +198,7 @@ function tripal_organism_perm() {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Purpose: Provide Guidance to new Tripal Admin
|
|
|
- *
|
|
|
- * @return HTML Formatted text
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_module_description_page() {
|
|
|
- $text = '';
|
|
|
-
|
|
|
- $text .= '<h3>Tripal Organism Administrative Tools Quick Links:</h3>';
|
|
|
- $text .= "<ul>
|
|
|
- <li><a href=\"" . url("admin/tripal/tripal_organism/configuration") . "\">Organism Configuration</a></li>
|
|
|
- </ul>";
|
|
|
-
|
|
|
- $text .= '<h3>Module 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>Setup Instructions:</h3>';
|
|
|
- $text .= '<p>After installation of the organism module. The following tasks should be performed.
|
|
|
- <ol>
|
|
|
- <li><p><b>Set Permissions</b>: The organism module supports the Drupal user permissions interface for
|
|
|
- controlling access to organism content and functions. These permissions include viewing,
|
|
|
- creating, editing or administering of
|
|
|
- organism content. The default is that only the original site administrator has these
|
|
|
- permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
|
|
|
- <a href="' . url('admin/user/user') . '">assign users to roles</a> and
|
|
|
- <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the organism content to
|
|
|
- those roles. For a simple setup, allow anonymous users access to view organism content and
|
|
|
- allow the site administrator all other permissions.</p></li>
|
|
|
-
|
|
|
- <li><p><b>Create Organisms</b>: Organism pages can be created in two ways:
|
|
|
- <ol>
|
|
|
- <li><b>Sync Organisms</b>: If your organism has been pre-loaded into Chado then you need to sync the organism.
|
|
|
- This process is what creates the pages for viewing online. Not all organisms need be synced, only those
|
|
|
- that you want shown on the site. Use the the
|
|
|
- <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a>
|
|
|
- to sync organisms. </li>
|
|
|
- <li><b>Manually Add An Organism</b>: If your organism is not already present in the Chado database
|
|
|
- you can create an organism using the <a href="' . url('node/add/chado-organism') . '">Create Organism page</a>.
|
|
|
- Once saved, the organism will be present in Chado and also "synced".
|
|
|
- </ol></p></li>
|
|
|
-
|
|
|
- <li><p><b>Indexing</b>: Once organism pages are ready for public access,
|
|
|
- you can index the organism pages for searching if you want to ues the Drupal default search mechanism.
|
|
|
- Use the <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a>
|
|
|
- to either Index (for the first time) or "Reindex" (after updating data)
|
|
|
- the organism pages for searching. Once the site is 100% indexed the pages will be searchable using Drupal\'s
|
|
|
- full text searching. You can find the percent indexed for the entire site by visiting the
|
|
|
- <a href="' . url('admin/settings/search') . '">Search settings page</a>. Indexing
|
|
|
- can take quite a while if you have a lot of data</p></li>
|
|
|
-
|
|
|
- <li><p><b>Set Taxonomy</b>: Drupal provides a mechanism for categorizing content to allow
|
|
|
- for advanced searching. Drupal calls this "Taxonomy", but is essentially categorizing the pages.
|
|
|
- You can categorize feature pages by the
|
|
|
- organism to which they belong. This allows for filtering of search results by organism.
|
|
|
- Use the <a href="' . url('admin/tripal/tripal_organism/configuration') . '">Organism Configuration page</a> to
|
|
|
- set the Taxonomy.</p></li>
|
|
|
- </ol>';
|
|
|
-
|
|
|
- $text .= '<h3>Features of this Module:</h3>';
|
|
|
- $text .= '<p>Aside from organism page setup (as described in the Setup section above),
|
|
|
- The Tripal organism module also provides the following functionality
|
|
|
- <ul>
|
|
|
- <li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
|
|
|
- a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
|
|
|
- It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
|
|
|
- and create custom lists without PHP programming or customization of Tripal source code. Views can also
|
|
|
- be created to filter content that has not yet been synced with Druapl in order to protect access to non
|
|
|
- published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
|
|
|
- Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>
|
|
|
-
|
|
|
- <li><p><b>Basic Organism List</b>: This module provides a basic <a href="' . url('organisms') . '">organism list</a>
|
|
|
- for showing the list of organisms in Chado. <a href="http://drupal.org/project/views">Drupal Views</a> must be
|
|
|
- installed. You can use the Views interface to alter the appearance of this list.</p></li>
|
|
|
- </ul>
|
|
|
- </p>';
|
|
|
-
|
|
|
- $text .= '<h3>Page Customizations</h3>';
|
|
|
- $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
|
|
|
- Below is a description of several methods. These methods may be used in conjunction with one another to
|
|
|
- provide fine-grained control.
|
|
|
- <ul>
|
|
|
-
|
|
|
- <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
|
|
|
- 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,
|
|
|
- Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
|
|
|
- is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
|
|
|
- Panel\'s GUI.</p></li>
|
|
|
-
|
|
|
- <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
|
|
|
- <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
|
|
|
- to any page without need to edit template files or knowing PHP. You must first download and install CCK.
|
|
|
- With CCK, the site administartor can create a new field to appear on the page. For example, currently,
|
|
|
- the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
|
|
|
- field to the organism pages. This content is not stored in Chado, but will appear on the organism page. A field
|
|
|
- added by CCK will also appear in the form when editing a organism to allow users to manually enter the appropriate
|
|
|
- text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
|
|
|
- indicate that it is not to be shown (using the CCK interface), then manually add the new content type
|
|
|
- where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
|
|
|
- location desired using the Panels interface.</p></li>
|
|
|
-
|
|
|
- <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
|
|
|
- themeing for Chado content. The organism module has a template file for organism "nodes" (Tripal organism pages). This file
|
|
|
- is named "node-chado_organism.tpl.php", and provides javascript, HTML and PHP code for display of the organism
|
|
|
- pages. You can edit this file to control which types of information (or which organism "blocks") are displayed for organisms. Be sure to
|
|
|
- copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
|
|
|
- future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
|
|
|
- for instructions on how to access variables and other Chado content within the template file.</p></li>
|
|
|
-
|
|
|
- <li><p><b>Organism "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_organism".
|
|
|
- Inside this directory is a set of templates that control distinct types of information for organisms. For example,
|
|
|
- there is a "base" template for displaying of data directly from the Chado organism table, and a "references"
|
|
|
- template for showing external site references for a organism (data from the organism_dbxref table). These templates are used both by Drupal blocks
|
|
|
- for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
|
|
|
- provides (also desribed above). You can customize this template as you desire. Be sure to copy the
|
|
|
- template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
|
|
|
- future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
|
|
|
- for instructions on how to access variables and other Chado content within the template files.</p></li>
|
|
|
- </li>
|
|
|
-
|
|
|
- <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
|
|
|
- will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
|
|
|
- using Javascript for all of the organism "Blocks" that appear on the page. If you want to add additional links
|
|
|
- (e.g. a dynamic link to GBrowse for the organism) and you want that link to appear in the
|
|
|
- "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
|
|
|
- section at the bottom of the template file where the resources section is found.</p></li>
|
|
|
-
|
|
|
- </ul>
|
|
|
- </p>';
|
|
|
- return $text;
|
|
|
-}
|
|
|
|
|
|
-/**
|
|
|
- * Administrative settings for chado_orgnism
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_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_organism')) {
|
|
|
- $active_jobs = TRUE;
|
|
|
- }
|
|
|
-
|
|
|
- // add the field set for syncing libraries
|
|
|
- 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);
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-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,
|
|
|
- );
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function get_tripal_organism_admin_form_taxonomy_set(&$form) {
|
|
|
- $form['taxonify'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Assign Drupal Taxonomy to Organism Features')
|
|
|
- );
|
|
|
-
|
|
|
- // get the list of libraries
|
|
|
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
|
|
|
- $org_rset = chado_query($sql);
|
|
|
-
|
|
|
- // iterate through all of the libraries
|
|
|
- $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
|
|
|
- );
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function get_tripal_organism_admin_form_reindex_set(&$form) {
|
|
|
- // define the fieldsets
|
|
|
- $form['reindex'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Reindex Organism Features')
|
|
|
- );
|
|
|
-
|
|
|
- // get the list of libraries
|
|
|
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
|
|
|
- $org_rset = chado_query($sql);
|
|
|
-
|
|
|
- // iterate through all of the libraries
|
|
|
- $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,
|
|
|
- );
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function get_tripal_organism_admin_form_sync_set(&$form) {
|
|
|
- // define the fieldsets
|
|
|
- $form['sync'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Sync Organisms')
|
|
|
- );
|
|
|
-
|
|
|
- // 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_organism')) {
|
|
|
- $active_jobs = TRUE;
|
|
|
- }
|
|
|
-
|
|
|
- if (!$active_jobs) {
|
|
|
-
|
|
|
- // get the list of organisms
|
|
|
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
|
|
|
- $org_rset = chado_query($sql);
|
|
|
-
|
|
|
- // if we've added any organisms to the list that can be synced
|
|
|
- // then we want to build the form components to allow the user
|
|
|
- // to select one or all of them. Otherwise, just present
|
|
|
- // a message stating that all organisms are currently synced.
|
|
|
- $org_boxes = array();
|
|
|
- $added = 0;
|
|
|
- while ($organism = db_fetch_object($org_rset)) {
|
|
|
- // check to see if the organism is already present as a node in drupal.
|
|
|
- // if so, then skip it.
|
|
|
- $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 we have organisms we need to add to the checkbox then
|
|
|
- // build that form element
|
|
|
- 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')
|
|
|
- );
|
|
|
- }
|
|
|
- // we don't have any organisms to select from
|
|
|
- else {
|
|
|
- $form['sync']['value'] = array(
|
|
|
- '#value' => t('All organisms in Chado are currently synced with Drupal.')
|
|
|
- );
|
|
|
- }
|
|
|
- }
|
|
|
- // we don't want to present a form since we have an active job running
|
|
|
- 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.')
|
|
|
- );
|
|
|
- }
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_admin_validate($form, &$form_state) {
|
|
|
- global $user; // we need access to the user info
|
|
|
- $job_args = array();
|
|
|
-
|
|
|
- if ($form_state['values']['op'] == t('Submit Sync Job')) {
|
|
|
-
|
|
|
- // check to see if the user wants to sync chado and drupal. If
|
|
|
- // so then we need to register a job to do so with tripal
|
|
|
- $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)) {
|
|
|
- // get the list of organisms
|
|
|
- $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
|
|
|
- $organism = db_fetch_object(chado_query($sql, $organism_id));
|
|
|
- $to_sync[$organism_id] = "$organism->genus $organism->species";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // submit the job the tripal job manager
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // -------------------------------------
|
|
|
- // Submit the Reindex Job if selected
|
|
|
- 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)) {
|
|
|
- // get the organism info
|
|
|
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
|
|
|
- $organism = db_fetch_object(chado_query($sql , $organism_id));
|
|
|
- $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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // -------------------------------------
|
|
|
- // Submit the taxonomy Job if selected
|
|
|
- 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)) {
|
|
|
- // get the organism info
|
|
|
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
|
|
|
- $organism = db_fetch_object(chado_query($sql , $organism_id));
|
|
|
- $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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // -------------------------------------
|
|
|
- // Submit the Cleanup Job if selected
|
|
|
- if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
|
|
|
- tripal_add_job('Cleanup orphaned organisms', 'tripal_organism',
|
|
|
- 'tripal_organism_cleanup', $job_args, $user->uid);
|
|
|
- }
|
|
|
-}
|
|
|
-/**
|
|
|
- * 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
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_theme() {
|
|
|
- return array(
|
|
|
- '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',
|
|
|
- ),
|
|
|
- 'tripal_organism_teaser' => array(
|
|
|
- 'arguments' => array('node' => NULL),
|
|
|
- 'template' => 'tripal_organism_teaser',
|
|
|
- ),
|
|
|
- );
|
|
|
-}
|
|
|
/**
|
|
|
*
|
|
|
* @ingroup tripal_organism
|
|
@@ -977,61 +543,7 @@ function chado_organism_view($node, $teaser = FALSE, $page = FALSE) {
|
|
|
return $node;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Synchronize organisms from chado to drupal
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_sync_organisms($organism_id = NULL, $job_id = NULL) {
|
|
|
- global $user;
|
|
|
- $page_content = '';
|
|
|
|
|
|
- if (!$organism_id) {
|
|
|
- $sql = "SELECT * FROM {Organism} O";
|
|
|
- $results = chado_query($sql);
|
|
|
- }
|
|
|
- else {
|
|
|
- $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d";
|
|
|
- $results = chado_query($sql, $organism_id);
|
|
|
- }
|
|
|
-
|
|
|
- // We'll use the following SQL statement for checking if the organism
|
|
|
- // already exists as a drupal node.
|
|
|
- $sql = "SELECT * FROM {chado_organism} ".
|
|
|
- "WHERE organism_id = %d";
|
|
|
-
|
|
|
- while ($organism = db_fetch_object($results)) {
|
|
|
-
|
|
|
- // check if this organism already exists in the drupal database. if it
|
|
|
- // does then skip this organism and go to the next one.
|
|
|
- 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) {
|
|
|
- print "Added $organism->common_name\n";
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- print "Failed to insert organism $organism->common_name\n";
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- print "Skipped $organism->common_name\n";
|
|
|
- }
|
|
|
- }
|
|
|
- return $page_content;
|
|
|
-}
|
|
|
/**
|
|
|
* Display help and module information
|
|
|
* @param path which path of the site we're displaying help
|
|
@@ -1089,100 +601,7 @@ function get_chado_organisms() {
|
|
|
return $organisms;
|
|
|
}
|
|
|
}
|
|
|
-/**
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-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";
|
|
|
- $results = chado_query($sql);
|
|
|
|
|
|
- // load into ids array
|
|
|
- $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) {
|
|
|
- // update the job status every 1% features
|
|
|
- if ($job_id and $i % $interval == 0) {
|
|
|
- tripal_job_set_progress($job_id , intval(($i/$count)*100));
|
|
|
- }
|
|
|
- tripal_feature_sync_feature($feature_id);
|
|
|
- $i++;
|
|
|
- }
|
|
|
-}
|
|
|
-/**
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-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";
|
|
|
- $results = chado_query($sql);
|
|
|
-
|
|
|
- // load into ids array
|
|
|
- $count = 0;
|
|
|
- $ids = array();
|
|
|
- while ($id = db_fetch_object($results)) {
|
|
|
- $ids[$count] = $id->feature_id;
|
|
|
- $count++;
|
|
|
- }
|
|
|
-
|
|
|
- // make sure our vocabularies are set before proceeding
|
|
|
- tripal_feature_set_vocabulary();
|
|
|
-
|
|
|
- // use this SQL for getting the nodes
|
|
|
- $nsql = "SELECT * FROM {chado_feature} CF ".
|
|
|
- " INNER JOIN {node} N ON N.nid = CF.nid ".
|
|
|
- "WHERE feature_id = %d";
|
|
|
-
|
|
|
- // iterate through the features and set the taxonomy
|
|
|
- $interval = intval($count * 0.01);
|
|
|
- foreach ($ids as $feature_id) {
|
|
|
- // update the job status every 1% features
|
|
|
- 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++;
|
|
|
- }
|
|
|
-}
|
|
|
-/**
|
|
|
- * Remove orphaned drupal nodes
|
|
|
- *
|
|
|
- * @param $dummy
|
|
|
- * Not Used -kept for backwards compatibility
|
|
|
- * @param $job_id
|
|
|
- * The id of the tripal job executing this function
|
|
|
- *
|
|
|
- * @ingroup tripal_organism
|
|
|
- */
|
|
|
-function tripal_organism_cleanup($dummy = NULL, $job_id = NULL) {
|
|
|
-
|
|
|
- return tripal_core_clean_orphaned_nodes('organism', $job_id);
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* Implements hook_views_api()
|