Jelajahi Sumber

Added an interface for creating custom tables to the Tripa UI

spficklin 12 tahun lalu
induk
melakukan
ecd03c3e16
2 mengubah file dengan 41 tambahan dan 78 penghapusan
  1. 0 78
      tripal_core/api/tripal_core.api.inc
  2. 41 0
      tripal_core/tripal_core.module

+ 0 - 78
tripal_core/api/tripal_core.api.inc

@@ -2590,84 +2590,6 @@ function tripal_get_max_chado_rank($tablename, $where_options) {
   }
 }
 
-/**
- * Add a new table to the Chado schema. This function is simply a wrapper for
- * the db_create_table() function of Drupal, but ensures the table is created
- * inside the Chado schema rather than the Drupal schema.  If the table already
- * exists then it will be dropped and recreated using the schema provided.
- * Howver, it will only drop a table if it exsits in the tripal_custom_tables
- * table. This way the function cannot be used to accidentally alter existing
- * non custom tables.
- *
- * @param $ret
- *   Array to which query results will be added.
- * @param $table
- *   The name of the table to create.
- * @param $schema
- *   A Drupal-style Schema API definition of the table
- *
- * @return
- *   A database query result resource for the new table, or FALSE if table was not constructed.
- *
- * @ingroup tripal_core_api
- */
-function tripal_create_chado_table(&$ret, $table, $schema) {
-  $ret = array();
-
-  // If the table exits in Chado but not in the tripal_custom_tables field
-  // then call an error.  if the table exits in the tripal_custom_tables but
-  // not in Chado then create the table and replace the entry.
-  $sql = "SELECT * FROM {tripal_custom_tables} WHERE table_name = '%s'";
-  $centry = db_fetch_object(db_query($sql, $table));
-  $previous_db = tripal_db_set_active('chado');  // use chado database
-  $exists = db_table_exists($table);
-  tripal_db_set_active($previous_db);  // now use drupal database
-
-  if (!$exists) {
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    db_create_table($ret, $table, $schema);
-    tripal_db_set_active($previous_db);  // now use drupal database
-    if (count($ret)==0) {
-      watchdog('tripal_core', "Error adding custom table '!table_name'.",
-        array('!table_name' => $table), WATCHDOG_ERROR);
-      return FALSE;
-    }
-  }
-  if ($exists and !$centry) {
-    watchdog('tripal_core', "Could not add custom table '!table_name'. It ".
-            "already exists but is not known to Tripal as being a custom table.",
-      array('!table_name' => $table), WATCHDOG_WARNING);
-    return FALSE;
-  }
-  if ($exists and $centry) {
-    // drop the table we'll recreate it with the new schema
-    $previous_db = tripal_db_set_active('chado');  // use chado database
-    db_drop_table($ret, $table);
-    db_create_table($ret, $table, $schema);
-    tripal_db_set_active($previous_db);  // now use drupal database
-  }
-
-  // if the table creation was succesful then add an entry
-  // in the tripal_custom_table
-  $record = new stdClass();
-  $record->table_name = $table;
-  $record->schema = serialize($schema);
-
-  // if an entry already exists then remove it
-  if ($centry) {
-    $sql = "DELETE FROM {tripal_custom_tables} WHERE table_name = '%s'";
-    db_query($sql, $table);
-  }
-  $success = drupal_write_record('tripal_custom_tables', $record);
-  if (!$success) {
-    watchdog('tripal_core', "Error adding custom table.",
-      array('!table_name' => $table), WATCHDOG_ERROR);
-    return FALSE;
-  }
-
-  return $ret;
-}
-
 /**
  * Retrieves the schema in an array for the specified custom table.
  *

+ 41 - 0
tripal_core/tripal_core.module

@@ -2,6 +2,7 @@
 
 require_once "includes/jobs.php";
 require_once "includes/mviews.php";
+require_once "includes/custom_tables.php";
 require_once "includes/chado_install.php";
 require_once "api/tripal_core.api.inc";
 
@@ -174,6 +175,46 @@ function tripal_core_menu() {
     'access arguments' => array('access administration pages'),
     'type' => MENU_CALLBACK,
   );
+  
+  // Custom Tables
+  $items['admin/tripal/custom_tables'] = array(
+    'title' => 'Custom Tables',
+    'description' => 'Custom tables are added to Chado.',
+    'page callback' => 'tripal_custom_tables_list',
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/custom_tables/view/%'] = array(
+    'title' => 'Custom Tables',
+    'description' => 'Custom tables are added to Chado.',
+    'page callback' => 'tripal_custom_table_view',
+    'page arguments' => array(4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/custom_tables/new'] = array(
+    'title' => 'Create Custom Table',
+    'description' => 'Custom tables are added to Chado.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_custom_tables_form'),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/custom_tables/edit/%'] = array(
+    'title' => 'Edit Custom Table',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_custom_tables_form', 4),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/tripal/custom_tables/action/%/%'] = array(
+    'title' => 'Create Custom TAble',
+    'description' => 'Custom tables are added to Chado.',
+    'page callback' => 'tripal_custom_tables_action',
+    'page arguments' => array(4, 5, "1"),
+    'access arguments' => array('access administration pages'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }