12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238 |
- <?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){
- switch ($op){
- case 'create':
- return user_access('create chado_organism content', $account);
- case 'update':
- return user_access('edit chado_organism content', $account);
- case 'delete':
- return user_access('delete chado_organism content', $account);
- case 'view' :
- return user_access('access chado_organism content', $account);
- }
- }
- 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>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;
- }
- 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_validate($node,&$form){
-
- if(!$node->nid){
- $values = array(
- 'genus' => $node->genus,
- 'species' => $node->species,
- );
- $organism = tripal_core_chado_select('organism', array('organism_id'),$values);
- if(sizeof($organism) > 0){
- form_set_error('genus','Cannot add the organism with this genus and species.
- The organism already exists.');
- }
- }
- }
- function chado_organism_insert($node){
- $values = array(
- 'genus' => $node->genus,
- 'species' => $node->species,
- 'abbreviation' => $node->abbreviation,
- 'common_name' => $node->common_name,
- 'comment' => $node->description
- );
- $organism = tripal_core_chado_insert('organism', $values);
- if (!$organism) {
- drupal_set_message('Unable to add organism.', 'warning');
- watchdog('tripal_organism',
- 'Insert Organism: Unable to create organism where values:%values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- return;
- }
-
-
- $organism_id = $organism['organism_id'];
- if(!chado_get_id_for_node('organism',$node) ){
-
- $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ".
- "VALUES (%d, %d, %d)";
- chado_query($sql,$node->nid,$node->vid,$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');
-
- chado_organism_add_image($node);
- }
- function chado_organism_update($node){
- if($node->revision){
-
- } else {
- $match = array(
- 'organism_id' => chado_get_id_for_node('organism',$node),
- );
- $values = array(
- 'genus' => $node->genus,
- 'species' => $node->species,
- 'abbreviation' => $node->abbreviation,
- 'common_name' => $node->common_name,
- 'comment' => $node->description
- );
- $org_status = tripal_core_chado_update('organism', $match,$values);
-
- $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');
-
- chado_organism_add_image($node);
- }
- }
- function chado_organism_delete($node){
- $organism_id = chado_get_id_for_node('organism',$node);
-
- $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) {
- tripal_core_chado_delete('organism',array('organism_id' => $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_add_image($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->nid.".jpg",FILE_EXISTS_REPLACE);
- }
- }
- function chado_organism_form ($node, $param){
- $organism = $node->organism;
-
- $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
-
- $abbreviation = $node->abbreviation;
- if(!$abbreviation){
- $abbreviation = $organism->abbreviation;
- }
- $genus = $node->genus;
- if(!$genus){
- $genus = $organism->genus;
- }
- $species = $node->species;
- if(!$species){
- $species = $organism->species;
- }
- $common_name = $node->common_name;
- if(!$common_name){
- $common_name = $organism->common_name;
- }
- $description = $node->description;
- if(!$description){
- $description = $organism->comment;
- }
- $organism_image = $node->organism_image;
- $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' => $organism->comment,
- '#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){
-
- $organism_id = chado_get_id_for_node('organism',$node);
- $values = array('organism_id' => $organism_id);
- $organism = tripal_core_generate_chado_var('organism',$values);
-
- $organism = tripal_core_expand_chado_vars($organism,'field','organism.comment');
- $additions->organism = $organism;
- 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,
- );
- }
|