Explorar el Código

Initial import of version 0.2

spficklin hace 15 años
padre
commit
aa8ec3e519
Se han modificado 3 ficheros con 282 adiciones y 0 borrados
  1. 9 0
      tripal_db/tripal_db.info
  2. 36 0
      tripal_db/tripal_db.install
  3. 237 0
      tripal_db/tripal_db.module

+ 9 - 0
tripal_db/tripal_db.info

@@ -0,0 +1,9 @@
+; $Id: tripal_db.info,v 1.2 2009/12/05 06:11:56 ficklin Exp $
+name = Tripal DB
+description = The database module for the Tripal package that integrates Drupal and GMOD chado. This module provides support for managing and viewing external databases.
+core = 6.x
+project = tripal_db
+package = Tripal
+version = "6.x-0.2b-m0.1"
+
+dependencies[] = tripal_core

+ 36 - 0
tripal_db/tripal_db.install

@@ -0,0 +1,36 @@
+<?php
+
+/*******************************************************************************
+*  Implementation of hook_install();
+*/
+function tripal_db_install(){
+
+   // create the module's data directory
+   tripal_create_moddir('tripal_db');
+
+}
+
+/*******************************************************************************
+* Implementation of hook_uninstall()
+*/
+function tripal_db_uninstall(){
+
+}
+
+/*******************************************************************************
+ * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
+ * before installation
+ */
+function tripal_db_requirements($phase) {
+   $requirements = array();
+   if ($phase == 'install') {
+      if (!function_exists('tripal_create_moddir')) {
+         $requirements ['tripal_db'] = array(
+            'title' => "tripal_db",
+            'value' => "Required modules must be installed first before Tripal DB module can be installed. Please try again.",
+            'severity' => REQUIREMENT_ERROR,
+         );
+      }
+   }
+   return $requirements;
+}

+ 237 - 0
tripal_db/tripal_db.module

@@ -0,0 +1,237 @@
+<?php
+//
+// Copyright 2009 Clemson University
+//
+/*************************************************************************
+*
+*/
+function tripal_db_init(){
+
+   // add the tripal_db JS and CSS
+   drupal_add_css(drupal_get_path('theme', 'tripal').
+                                  '/css/tripal_db.css');
+   drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_db.js');
+}
+/*************************************************************************
+*
+*/
+function tripal_db_menu() {
+   $items = array();
+
+   $items['admin/tripal/tripal_db'] = array(
+     'title' => 'DB',
+     'description' => 'Manage External Databases ',
+     'page callback' => 'tripal_db_list',
+     'access arguments' => array('administer site configuration'),
+     'type' => MENU_NORMAL_ITEM,
+   );
+
+   $items['admin/tripal/tripal_db/new'] = array(
+     'title' => 'Add DB',
+     'page callback' => 'drupal_get_form',
+     'page arguments' => array('tripal_db_form'),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_NORMAL_ITEM,
+   );
+   $items['admin/tripal/tripal_db/edit/%'] = array(
+     'title' => 'Edit DB',
+     'page callback' => 'drupal_get_form',
+     'page arguments' => array('tripal_db_form',4),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_NORMAL_ITEM,
+   );
+
+   return $items;
+}
+/*******************************************************************************
+*  Set the permission types that the chado module uses.  Essentially we
+*  want permissionis that protect creation, editing and deleting of chado
+*  data objects
+*/
+function tripal_db_perm(){
+   return array(
+      'access chado_db content',
+      'create chado_db content',
+      'delete chado_db content',
+      'edit chado_db content',
+   );
+}
+
+/*************************************************************************
+*
+*/
+function tripal_db_list () {
+   $previous_db = db_set_active('chado');
+   $dbs = pager_query("SELECT * FROM {db} ORDER BY db_id",30,0,
+      "SELECT count(*) FROM {db}");
+   db_set_active($previous_db);
+
+
+   // build the URLs using the url function so we can handle installations where
+   // clean URLs are or are not used
+   $new_url = url("admin/tripal/tripal_db/new");
+   $output .= "Below is the list of all external databases.";
+   $output .= "<br><a href=\"$new_url\">Add a new external database</a>";
+   $output .= "<table class=\"border-table\">". 
+              "  <tr>".
+              "    <th></th>".
+              "    <th>ID</th>".
+              "    <th>Name</th>".
+              "    <th>Description</th>".             
+              "    <th>URL</th>".
+              "    <th>URL Prefix</th>".
+              "  </tr>";
+   while($db = db_fetch_object($dbs)){
+      $edit_url = url("admin/tripal/tripal_db/edit/$db->db_id");
+      $output .= "  <tr>".
+                 "    <td><a href=\"$edit_url\">edit</a></td>".
+                 "    <td>$db->db_id</td>".
+                 "    <td>$db->name</td>".
+                 "    <td>$db->description</td>".
+                 "    <td>$db->url</td>".
+                 "    <td>$db->urlprefix</td>".
+                 "  </tr>";
+   }
+   $output .= "</table>";
+   $output .= theme_pager();
+   return $output;
+}
+/*************************************************************************
+*
+*/
+function tripal_db_form(&$form_state = NULL,$db_id = NULL){
+
+   if(!$db_id){
+      $action = 'Add';
+   } else {
+      $action = 'Update';
+   }
+ 
+   // get this requested database
+   if(strcmp($action,'Update')==0){
+      $sql = "SELECT * FROM {db} WHERE db_id = $db_id ";
+      $previous_db = db_set_active('chado');
+      $db = db_fetch_object(db_query($sql));
+      db_set_active($previous_db);
+
+
+      # set the default values.  If there is a value set in the 
+      # form_state then let's use that, otherwise, we'll pull 
+      # the values from the database 
+      $default_db = $form_state['values']['name'];
+      $default_desc = $form_state['values']['description'];
+      $default_url = $form_state['values']['url'];
+      $default_urlprefix = $form_state['values']['urlprefix'];
+      if(!$default_db){
+         $default_db = $db->name;
+      }
+      if(!$default_desc){
+         $default_desc = $db->description;
+      }
+      if(!$default_url){
+         $default_url = $db->url;
+      }
+      if(!$default_urlprefix){
+         $default_urlprefix = $db->urlprefix;
+      }
+   }
+
+   // Build the form
+   $form['action'] = array(
+      '#type' => 'value',
+      '#value' => $action
+   );
+   $form['db_id'] = array(
+      '#type' => 'value',
+      '#value' => $db_id
+   );
+   $form['name']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('Database Name'),
+      '#description'   => t('Please enter the name for this external database.'),
+      '#required'      => TRUE,
+      '#default_value' => $default_db,
+      '#weight'        => 1
+   );
+
+   $form['description']= array(
+      '#type'          => 'textarea',
+      '#title'         => t('Description'),
+      '#description'   => t('Please enter a description for this database'),
+      '#default_value' => $default_desc,
+      '#weight'        => 2
+   );
+   $form['url']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('URL'),
+      '#description'   => t('Please enter the web address for this database.'),
+      '#default_value' => $default_url,
+      '#weight'        => 3
+   );
+   $form['urlprefix']= array(
+      '#type'          => 'textfield',
+      '#title'         => t('URL prefix'),
+      '#description'   => t('Tripal can provide links to external databases when accession numbers or unique identifiers are known.  Typically, a database will provide a unique web address for each accession and the accession usually is the last component of the page address.  Please enter the web address, minus the accession number for this database.  When an accession number is present, Tripal will combine this web address with the accession and provide a link to the external site.'),
+      '#default_value' => $default_urlprefix,
+      '#weight'        => 4
+   );
+   $form['submit'] = array (
+     '#type'         => 'submit',
+     '#value'        => t($action),
+     '#weight'       => 5,
+     '#executes_submit_callback' => TRUE,
+   );
+   $form['#redirect'] = 'admin/tripal/tripal_db';
+   return $form;
+}
+/************************************************************************
+*
+*/
+function tripal_db_form_submit($form, &$form_state){
+   $action =  $form_state['values']['action'];
+   $db_id =  $form_state['values']['db_id'];
+   $name =  $form_state['values']['name'];
+   $desc =  $form_state['values']['description'];
+   $url =  $form_state['values']['url'];
+   $urlp =  $form_state['values']['urlprefix'];
+
+   if(strcmp($action,'Update')==0){ 
+      $sql = "
+         UPDATE {db} SET 
+           name = '$name',
+           description = '$desc',
+           url = '$url',
+           urlprefix = '$urlp'
+         WHERE db_id = $db_id
+      ";
+      $previous_db = db_set_active('chado');
+      $db = db_query($sql);
+      db_set_active($previous_db);
+      if($db){
+        drupal_set_message("Database updated");
+      } else {
+        drupal_set_message("Failed to update database.");
+      }
+   } 
+   else if(strcmp($action,'Add')==0){ 
+      $sql = "
+         INSERT INTO {db}
+          (name,description,url,urlprefix)
+         VALUES 
+          ('$name','$desc','$url','$urlp')
+      ";
+      $previous_db = db_set_active('chado');
+      $db = db_query($sql);
+      db_set_active($previous_db);
+      if($db){
+        drupal_set_message("Database added");
+      } else {
+        drupal_set_message("Failed to add database.");
+      }
+   } 
+   else {
+        drupal_set_message("No action performed.");
+   }
+   return '';
+}
+