瀏覽代碼

Merge branch '7.x-2.x' of git.drupal.org:project/tripal into 7.x-2.x

Lacey Sanderson 10 年之前
父節點
當前提交
92c60d96d8

+ 1 - 1
tripal_core/api/tripal_core.custom_tables.api.inc

@@ -229,7 +229,7 @@ function chado_validate_custom_table_schema($schema_array) {
     return "The schema array must have key named 'table'";
   }
 
-  if (!ctype_lower($schema_array['table'])) {
+  if (preg_match('/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/', $schema_array['table'])) {
     return "Postgres will automatically change the table name to lower-case. To prevent unwanted side-effects, please rename the table with all lower-case characters.";
   }
 

+ 5 - 5
tripal_core/includes/tripal_core.custom_tables.inc

@@ -185,8 +185,8 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
     '#collapsed' => TRUE,
   );
   $form['instructions']['text'] = array(
-    '#type'          => 'item',
-    '#description'         => '<p>' . t('At times it is necessary to add a custom table
+    '#type'   => 'item',
+    '#markup' => '<p>' . t('At times it is necessary to add a custom table
        to the Chado schema. These are not offically sanctioned tables but may
        be necessary for local data requirements. Avoid creating custom tables
        when possible as other GMOD tools may not recognize these tables nor
@@ -195,7 +195,7 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
        libraries (e.g. library_stock). Try to model linker or propery tables
        after existing tables.  If the table already exists it will not be
        modified.  To force dropping and recreation of the table
-       click the checkbox below.  Tables are defined usign the ' .
+       click the checkbox below.  Tables are defined using the ' .
        l('Drupal Schema API', 'https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7',
          array('attributes' => array('target' => '_blank'))) . '</p>' .
       '<p>Please note that table names should be all lower-case.</p>'
@@ -203,8 +203,8 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
   );
 
   $form['instructions']['example']= array(
-      '#type'          => 'item',
-      '#description'         => "Example library_stock table: <pre>
+      '#type'    => 'item',
+      '#markup'  => "Example library_stock table: <pre>
 array (
   'table' => 'library_stock',
   'fields' => array (

+ 96 - 60
tripal_core/includes/tripal_core.mviews.inc

@@ -258,6 +258,89 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
     '#description' => l("Return to table of materialized views", "admin/tripal/schema/mviews/"),
   );
 
+  $form['instructions'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Instructions',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['instructions']['text'] = array(
+    '#type'          => 'item',
+    '#markup'   =>  t('Materialized views are used to help speed data
+      querying, particularly for searching.  A materialized view is essentially
+      a database table that is pre-populated with the desired data to search on.
+      Rows in the materialized view are typically a combination of data from
+      multiple tables with indexes on searchable columns. The table structure
+      for materialized views is defined using the ' .
+      l('Drupal Schema API', 'https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7',
+        array('attributes' => array('target' => '_blank'))) . '. '. t('Additionally,
+      an SQL statement is provided that populates the table with data. ' .
+      'Please note that table names should be all lower-case.')
+    ),
+  );
+  $form['instructions']['example_schema']= array(
+    '#type'          => 'item',
+    '#markup'         => "An example Schema API definition for a materialized view: <pre>
+array (
+  'description' => 'Stores the type and number of features per organism',
+  'table' => 'organism_feature_count',
+  'fields' => array (
+    'organism_id' => array (
+      'type' => 'int',
+      'not null' => true,
+    ),
+    'genus' => array (
+      'type' => 'varchar',
+      'length' => '255',
+      'not null' => true,
+    ),
+    'species' => array (
+      'type' => 'varchar',
+      'length' => '255',
+      'not null' => true,
+    ),
+    'common_name' => array (
+      'type' => 'varchar',
+      'length' => '255',
+      'not null' => false,
+    ),
+    'num_features' => array (
+      'type' => 'int',
+      'not null' => true,
+    ),
+    'cvterm_id' => array (
+      'type' => 'int',
+      'not null' => true,
+    ),
+    'feature_type' => array (
+      'type' => 'varchar',
+      'length' => '255',
+      'not null' => true,
+    ),
+  ),
+  'indexes' => array (
+    'organism_id_idx'  => array ('organism_id'),
+    'cvterm_id_idx'    => array ('cvterm_id'),
+    'feature_type_idx' => array ('feature_type'),
+  ),
+)
+</pre>"
+  );
+  $form['instructions']['example_sql'] = array(
+    '#type' => 'item',
+    '#markup' => "An example SQL statement to populate the table: <pre>
+SELECT
+    O.organism_id, O.genus, O.species, O.common_name,
+    count(F.feature_id) as num_features,
+    CVT.cvterm_id, CVT.name as feature_type
+ FROM organism O
+    INNER JOIN feature F  ON O.Organism_id = F.organism_id
+    INNER JOIN cvterm CVT ON F.type_id     = CVT.cvterm_id
+ GROUP BY
+    O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
+    </pre>"
+  );
+
 
   $form['name']= array(
     '#type'          => 'textfield',
@@ -279,7 +362,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
   $form['schema'] = array(
     '#type' => 'fieldset',
     '#title' => 'Table Schema',
-    '#description' => t('Use a ' . l("Drupal Schema API", "https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7", array('attributes' => array('target' => '_blank'))) . 
+    '#description' => t('Use a ' . l("Drupal Schema API", "https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7", array('attributes' => array('target' => '_blank'))) .
         ' array to describe the table. See the bottom of this page for an example.'),
     '#collapsible' => 1,
     '#collapsed' => $schema_collapsed ,
@@ -288,7 +371,7 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
   $form['schema']['schema']= array(
     '#type'          => 'textarea',
     '#title'         => t('Schema Array'),
-    '#description'   => t('Please enter the ' . l("Drupal Schema API", "https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7", array('attributes' => array('target' => '_blank'))) . 
+    '#description'   => t('Please enter the ' . l("Drupal Schema API", "https://api.drupal.org/api/drupal/includes!database!schema.inc/group/schemaapi/7", array('attributes' => array('target' => '_blank'))) .
         ' compatible array that defines the table. There must also be a "table" key with the name of the table as the value. See the example at the bottom of this page.'),
     '#required'      => FALSE,
     '#default_value' => $default_schema,
@@ -370,55 +453,8 @@ function tripal_mviews_form($form, &$form_state = NULL, $mview_id = NULL) {
     '#value'        => t($value),
     '#executes_submit_callback' => TRUE,
   );
-  
-  $form['example']= array(
-    '#type'          => 'item',
-    '#description'         => "<br>An example Schema API definition for a materialized view: <pre>
-array (
-  'description' => 'Stores the type and number of features per organism',
-  'table' => 'organism_feature_count',
-  'fields' => array (
-    'organism_id' => array (
-      'type' => 'int',
-      'not null' => true,
-    ),
-    'genus' => array (
-      'type' => 'varchar',
-      'length' => '255',
-      'not null' => true,
-    ),
-    'species' => array (
-      'type' => 'varchar',
-      'length' => '255',
-      'not null' => true,
-    ),
-    'common_name' => array (
-      'type' => 'varchar',
-      'length' => '255',
-      'not null' => false,
-    ),
-    'num_features' => array (
-      'type' => 'int',
-      'not null' => true,
-    ),
-    'cvterm_id' => array (
-      'type' => 'int',
-      'not null' => true,
-    ),
-    'feature_type' => array (
-      'type' => 'varchar',
-      'length' => '255',
-      'not null' => true,
-    ),
-  ),
-  'indexes' => array (
-    'organism_id_idx'  => array ('organism_id'),
-    'cvterm_id_idx'    => array ('cvterm_id'),
-    'feature_type_idx' => array ('feature_type'),
-  ),
-)
-</pre>"
-  );
+
+
   return $form;
 }
 
@@ -429,14 +465,14 @@ array (
  * @ingroup tripal_mviews
  */
 function tripal_mviews_form_validate($form, &$form_state) {
-  
-  
+
+
   $action    = $form_state['values']['action'];
   $mview_id  = $form_state['values']['mview_id'];
   $name      = trim($form_state['values']['name']);
   $is_legacy = $form_state['values']['is_legacy'];
   $query     = $form_state['values']['mvquery'];
-  
+
   // if this is a legacy materialized view (no longer supported in Tripal v2.0
   // but code left just in case)
   if ($is_legacy) {
@@ -453,7 +489,7 @@ function tripal_mviews_form_validate($form, &$form_state) {
   }
   $comment = trim($form_state['values']['comment']);
   $schema  = $form_state['values']['schema'];
-  
+
   // validate the contents of the array
   $schema_array = array();
   $success = eval("\$schema_array = $schema;");
@@ -469,7 +505,7 @@ function tripal_mviews_form_validate($form, &$form_state) {
       t('You can create an MView using the Drupal Schema API method or the ' .
         'traditional method but not both.'));
   }
-  
+
   // if we don't have a schema and are missing fields for the legacy views then
   // inform the user.
   if (!$schema) {
@@ -508,7 +544,7 @@ function tripal_mviews_form_validate($form, &$form_state) {
 function tripal_mviews_form_submit($form, &$form_state) {
 
   $ret = array();
-  
+
   $action     = $form_state['values']['action'];
   $mview_id   = $form_state['values']['mview_id'];
   $name       = trim($form_state['values']['name']);
@@ -521,7 +557,7 @@ function tripal_mviews_form_submit($form, &$form_state) {
   $mv_specs = '';
   $indexed = '';
   $special_index = '';
-  
+
   // if this is a legacy materialized view (no longer supported in Tripal v2.0
   // but code left just in case)
   if ($is_legacy) {
@@ -611,11 +647,11 @@ function tripal_mviews_delete_form_submit($form, &$form_state) {
 /**
  * A wrapper for the tripal_refresh_mview() API function, which
  * then redirects back to the admin page for mviews.
- * 
+ *
  * @param $mview_id
  */
 function tripal_mviews_add_populate_job($mview_id) {
-  
+
   tripal_refresh_mview($mview_id);
   drupal_goto("admin/tripal/schema/mviews");
 }

+ 4 - 1
tripal_example/includes/tripal_example.admin.inc

@@ -56,10 +56,13 @@ function tripal_example_admin() {
 
   // If your module is using the Chado Node: Title & Path API to allow custom
   // titles for your node type then you need to add the configuration form for
-  // this functionality.
+  // this functionality. To do so, we first have to preapre a $details array
+  // the describe our node type.  Then we call the function to create the form
+  // elements.
   $details = array(
       // the name of the MODULE implementing the content type
     'module' => 'tripal_example',
+    'content_type' => 'chado_example',
       // An array of options to use under "Page Titles"
       // the key should be the token and the value should be the human-readable
       // option

+ 40 - 14
tripal_example/includes/tripal_example.chado_node.inc

@@ -330,14 +330,14 @@ function chado_example_validate($node, $form, &$form_state) {
   // this is an update and validation can be different for updates
   if (property_exists($node, 'nid')) {
 
-    // make sure the feature type is an allowed term
+    // make sure the example type is an allowed term
     $type_cv = tripal_get_default_cv('example', 'type_id');
     $type = tripal_get_cvterm(array(
       'name' => $node->example_type,
       'cv_id' => $type_cv->cv_id,
     ));
     if (!$type) {
-      form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
+      form_set_error('example_type', t("The example type is not a valid name from the Sequence Ontology."));
     }
 
     // TODO: also we should check that the unique constraint is not invalidated
@@ -345,14 +345,14 @@ function chado_example_validate($node, $form, &$form_state) {
   }
   // Validating for an insert
   else {
-    // make sure the feature type is an allowed term
+    // make sure the example type is an allowed term
     $type_cv = tripal_get_default_cv('example', 'type_id');
     $type = tripal_get_cvterm(array(
       'name' => $node->example_type,
       'cv_id' => $type_cv->cv_id,
     ));
     if (!$type) {
-      form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
+      form_set_error('example_type', t("The example type is not a valid name from the Sequence Ontology."));
     }
 
     // TODO: also we should check that the unique constraint doesn't already exist
@@ -703,17 +703,23 @@ function tripal_example_node_insert($node) {
       $example = chado_generate_var('example', $values);
       $node->example = $example;
 
-      // If your module is using the 'Chado Node: Title & Path API' to allow
-      // custom titles for your node type. Every time you want the title of the
-      // node, you need to use the following API function:
-      $example->title = chado_get_node_title($node);
 
-      // set the URL for this example page
-      // see the code in the tripal_feature/includes/tripal_feature.chado_node.inc
-      // file in the function tripal_feature_node_insert for an example of how
-      // that module sets the URL. It uses a configuration file to allow the
-      // user to dynamically build a URL schema and then uses that schema to
-      // generate a URL string.
+      // EXPLANATION: You can allow the site admin to customize the
+      // title and URL of your node.  The 'Chado Node: Title & Path API'
+      // contains two functions that can be called to generate the title and
+      // URL based a schema provided by the site admin. These functions are
+      // named chado_get_node_title() and chado_set_node_url().  These
+      // functions use a string of tokens to build the URL and titles and the
+      // site admin has the ability to set these tokens.  There are
+      // form elements made available in the tripal_example_admin() function
+      // that allow the admin to set these tokens.  The default token string
+      // is provided to Tripal using two hook functions, and are found below.
+      // These are: chado_exmaple_chado_node_default_title() and
+      // chado_example_chdo_node_default_url().
+
+      // Set the Title and URL for this node.
+      $example->title = chado_get_node_title($node);
+      chado_set_node_url($node);
       break;
   }
 }
@@ -853,3 +859,23 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
     // ... etc
   }
 }
+
+
+/**
+ * Implements [content_type]_chado_node_default_title_format().
+ *
+ * Defines a default title format for the Chado Node API to set the titles on
+ * Chado example nodes based on chado fields.
+ */
+function chado_example_chado_node_default_title_format() {
+  return '[example.name], [example.uniquename] ([example.type_id>cvterm.name]) [example.organism_id>organism.genus] [example.organism_id>organism.species]';
+}
+
+/**
+ * Implements hook_chado_node_default_url_format().
+ *
+ * Designates a default URL format for example nodes.
+ */
+function chado_example_chado_node_default_url_format() {
+  return '/example/[example.organism_id>organism.genus]/[example.organism_id>organism.species]/[example.type_id>cvterm.name]/[example.uniquename]';
+}

File diff suppressed because it is too large
+ 276 - 337
tripal_feature/includes/tripal_feature.fasta_loader.inc


Some files were not shown because too many files changed in this diff