TRUE)); } } /** * Implementation of hook_requirements(). * * @ingroup tripal_legacy_phylogeny */ function tripal_phylogeny_requirements($phase) { $requirements = array(); if ($phase == 'install') { // Make sure chado is installed. if (!$GLOBALS["chado_is_installed"]) { $requirements ['tripal_phylogeny'] = array( 'title' => "tripal_phylogeny", 'value' => "ERROR: Chado must be installed before this module can be enabled", 'severity' => REQUIREMENT_ERROR, ); } } return $requirements; } /** * Implementation of hook_schema(). * Standard tripal linker table between a node and a phylotree record. * @ingroup tripal_legacy_phylogeny */ function tripal_phylogeny_schema() { $schema['chado_phylotree'] = array( 'fields' => array( 'vid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0 ), 'phylotree_id' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0 ) ), 'indexes' => array( 'chado_phylotree_idx1' => array('phylotree_id') ), 'unique keys' => array( 'chado_phylotree_uq1' => array('nid', 'vid'), 'chado_phylotree_uq2' => array('vid') ), 'primary key' => array('nid'), ); return $schema; } /** * Adds controlled vocabulary terms needed by this module. * * @ingroup tripal_legacy_phylogeny */ function tripal_phylogeny_add_cvterms() { } /** * Implementation of hook_uninstall(). */ function tripal_phylogeny_uninstall() { // Drop the MView table if it exists $mview_id = tripal_get_mview_id('phylotree_count'); if ($mview_id) { tripal_delete_mview($mview_id); } // Remove views integration. // Note: tripal_remove_views_intergration accepts table_name and priority in a key value form. $delete_view=array( 'table_name' => 'phylotree_count', 'priority' => '-1', ); tripal_remove_views_integration($delete_view); } function tripal_phylogeny_add_mview(){ // Materialized view addition. $sql_query=" WITH count_genes as (SELECT count(*) count, t.phylotree_id FROM phylotree t, phylonode n WHERE n.phylotree_id = t.phylotree_id AND n.label is NOT NULL GROUP BY t.phylotree_id) SELECT phylotree.phylotree_id AS phylotree_phylotree_id, phylotree.name AS phylotree_name, phylotree.comment AS phylotree_comment, count_genes.count AS total_count FROM chado.phylotree phylotree LEFT JOIN chado_phylotree chado_phylotree ON phylotree.phylotree_id = chado_phylotree.phylotree_id LEFT JOIN count_genes count_genes ON phylotree.phylotree_id = count_genes.phylotree_id "; // Table Phylotree User Search description. $schema = array ( 'table' => 'phylotree_count', 'fields' => array( 'phylotree_phylotree_id' => array( 'type' => 'int', 'not null' => FALSE, ), 'phylotree_name' => array( 'type' => 'text', 'not null' => FALSE, ), 'phylotree_comment' => array( 'type' => 'text', 'not null' => FALSE, ), 'total_count' => array( 'type' => 'int', 'not null' => TRUE, ), ), 'primary key' => array('phylotree_phylotree_id'), ); // Add a comment to make sure this view makes sense to the site administator. $comment = t('This view is used to provide a table for Phylotree User Search with total count.'); tripal_add_mview('phylotree_count', 'tripal_phylogeny', $schema, $sql_query, $comment); } /** * Integrate the qtl_search materialized view for use by Drupal Views and * our search form */ function tripal_phylogeny_integrate_view(){ $integration = array ( 'table' => 'phylotree_count', 'name' => 'phylotree_count', 'type' => 'chado', 'description' => '', 'priority' => '-1', 'base_table' => '1', 'fields' => array ( 'phylotree_phylotree_id' => array ( 'name' => 'phylotree_phylotree_id', 'title' => 'Phylotree ID', 'description' => 'Phylotree ID', 'type' => 'int', 'handlers' => array ( 'filter' => array ( 'name' => 'views_handler_filter_numeric' ), 'field' => array ( 'name' => 'views_handler_field_numeric' ), 'sort' => array ( 'name' => 'views_handler_sort' ), 'argument' => array ( 'name' => 'views_handler_argument_numeric' ), 'relationship' => array ( 'name' => 'views_handler_relationship' ) ), 'joins' => array () ), 'phylotree_name' => array ( 'name' => 'phylotree_name', 'title' => 'Family ID', 'description' => 'Family ID', 'type' => 'text', 'handlers' => array ( 'filter' => array ( 'name' => 'tripal_views_handler_filter_select_string' ), 'field' => array ( 'name' => 'views_handler_field' ), 'sort' => array ( 'name' => 'views_handler_sort' ), 'argument' => array ( 'name' => 'views_handler_argument_string' ), 'relationship' => array ( 'name' => 'views_handler_relationship' ) ), 'joins' => array () ), 'phylotree_comment' => array ( 'name' => 'phylotree_comment', 'title' => 'Description', 'description' => 'Description', 'type' => 'text', 'handlers' => array ( 'filter' => array ( 'name' => 'tripal_views_handler_filter_select_string' ), 'field' => array ( 'name' => 'views_handler_field' ), 'sort' => array ( 'name' => 'views_handler_sort' ), 'argument' => array ( 'name' => 'views_handler_argument_string' ), 'relationship' => array ( 'name' => 'views_handler_relationship' ) ), 'joins' => array () ), 'total_count' => array ( 'name' => 'total_count', 'title' => 'Total count', 'description' => 'Total count', 'type' => 'int', 'handlers' => array ( 'filter' => array ( 'name' => 'views_handler_filter_numeric' ), 'field' => array ( 'name' => 'views_handler_field' ), 'sort' => array ( 'name' => 'views_handler_sort' ), 'argument' => array ( 'name' => 'views_handler_argument_numeric' ), 'relationship' => array ( 'name' => 'views_handler_relationship' ) ), 'joins' => array () ) ) ); // Add the array above that will integrate our qtl_search materialized view // for use with Drupal Views. tripal_add_views_integration($integration); } /** * Add any custom tables needed by this module. * - phylotreeprop: keep track of properties of phylotree * * @ingroup tripal_legacy_phylogeny */ function tripal_phylogeny_add_custom_tables() { $schema = array ( 'table' => 'phylotreeprop', 'fields' => array ( 'phylotreeprop_id' => array ( 'type' => 'serial', 'not null' => true, ), 'phylotree_id' => array ( 'type' => 'int', 'not null' => true, ), 'type_id' => array ( 'type' => 'int', 'not null' => true, ), 'value' => array ( 'type' => 'text', 'not null' => false, ), 'rank' => array ( 'type' => 'int', 'not null' => true, 'default' => 0, ), ), 'primary key' => array ( 0 => 'phylotreeprop_id', ), 'unique keys' => array ( 'phylotreeprop_c1' => array ( 0 => 'phylotree_id', 1 => 'type_id', 2 => 'rank', ), ), 'indexes' => array ( 'phylotreeprop_idx1' => array ( 0 => 'phylotree_id', ), 'phylotreeprop_idx2' => array ( 0 => 'type_id', ), ), 'foreign keys' => array ( 'cvterm' => array ( 'table' => 'cvterm', 'columns' => array ( 'type_id' => 'cvterm_id', ), ), 'phylotree' => array ( 'table' => 'phylotree', 'columns' => array ( 'phylotree_id' => 'phylotree_id', ), ), ), ); chado_create_custom_table('phylotreeprop', $schema, TRUE); } /** * Adds the vocabulary needed for storing taxonmies. */ function tripal_phylogeny_update_7200() { try { tripal_phylogeny_add_cvterms(); } catch (\PDOException $e) { $error = $e->getMessage(); throw new DrupalUpdateException('Failed to complete update' . $error); } }