| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 | 
							- <?php
 
- /**
 
-  * @file
 
-  * @todo Add file header description
 
-  */
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_install() {
 
-   // create the module's data directory
 
-   tripal_create_moddir('tripal_library');
 
-   // create the tables that correlate drupal nodes with chado
 
-   // features, librarys, etc....
 
-   drupal_install_schema('tripal_library');
 
-   // Insert cvterm 'library_description' into cvterm table of chado
 
-   // database. This CV term is used to keep track of the library
 
-   // description in the libraryprop table.
 
-   tripal_cv_add_cvterm(array('name' => 'library_description', 'def' => 'Description of a library'), 'tripal', 0, 1, 'tripal');
 
-   // Add CVTerms for the library types
 
-   tripal_cv_add_cvterm(array('name' => 'cdna_library', 'def' => 'cDNA Library'), 'tripal', 0, 1, 'tripal');
 
-   tripal_cv_add_cvterm(array('name' => 'bac_library', 'def' => 'BAC Library'), 'tripal', 0, 1, 'tripal');
 
-   tripal_cv_add_cvterm(array('name' => 'fosmid_library', 'def' => 'FOSMID Library'), 'tripal', 0, 1, 'tripal');
 
-   tripal_cv_add_cvterm(array('name' => 'cosmid_library', 'def' => 'COSMID Library'), 'tripal', 0, 1, 'tripal');
 
-   tripal_cv_add_cvterm(array('name' => 'yac_library', 'def' => 'YAC Library'), 'tripal', 0, 1, 'tripal');
 
-   // Add the materialized view needed to count the features for the library
 
-   // Drop the MView table if it exists
 
-   $previous_db = tripal_db_set_active('chado');
 
-   if (db_table_exists('library_feature_count')) {
 
-     $sql = "DROP TABLE library_feature_count";
 
-     db_query($sql);
 
-   }
 
-   tripal_db_set_active($previous_db);
 
-   // Create the MView
 
-   tripal_add_mview('library_feature_count', 'tripal_library',
 
-     'library_feature_count',
 
-     'library_id integer, name character varying(255), '.
 
-   '  num_features integer, feature_type character varying(255)',
 
-    'library_id',
 
-    'SELECT '.
 
-     '   L.library_id, '.
 
-     '   L.name, '.
 
-     '    count(F.feature_id) as num_features, '.
 
-     '    CVT.name as feature_type '.
 
-     'FROM {Library} L '.
 
-     '    INNER JOIN Library_Feature LF  ON LF.library_id = L.library_id '.
 
-     '    INNER JOIN Feature F           ON LF.feature_id = F.feature_id '.
 
-     '    INNER JOIN Cvterm CVT          ON F.type_id = CVT.cvterm_id '.
 
-     'GROUP BY L.library_id, L.name, CVT.name',
 
-    ''
 
-   );
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_schema() {
 
-   $schema = tripal_library_get_schemas();
 
-   return $schema;
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_uninstall() {
 
-   drupal_uninstall_schema('tripal_library');
 
-   // remove the materialized view
 
-   $sql = "SELECT * FROM {tripal_mviews} ".
 
-         "WHERE name = 'library_feature_count'";
 
-   if (db_table_exists('tripal_mviews')) {
 
-     $mview = db_fetch_object(db_query($sql));
 
-     if ($mview) {
 
-       tripal_mviews_action('delete', $mview->mview_id);
 
-     }
 
-   }
 
-   // Get the list of nodes to remove
 
-   $sql_lib_id = "SELECT nid, vid ".
 
-                "FROM {node} ".
 
-                "WHERE type='chado_library'";
 
-   $result = db_query($sql_lib_id);
 
-   while ($node = db_fetch_object($result)) {
 
-     node_delete($node->nid);
 
-   }
 
- }
 
- /**
 
-  * This function simply defines all tables needed for the module to work
 
-  * correctly.  By putting the table definitions in a separate function we
 
-  * can easily provide the entire list for hook_install or individual
 
-  * tables for an update.
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_get_schemas() {
 
-   $schema = array();
 
-   $schema['chado_library'] = 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
 
-       ),
 
-     'library_id' => array(
 
-       'type' => 'int',
 
-       'not null' => TRUE,
 
-       'default' => 0
 
-       )
 
-       ),
 
-     'indexes' => array(
 
-       'library_id' => array('library_id')
 
-       ),
 
-     'unique keys' => array(
 
-       'nid_vid' => array('nid', 'vid'),
 
-       'vid' => array('vid')
 
-       ),
 
-     'primary key' => array('nid'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Implementation of hook_requirements(). 
 
-  */
 
- function tripal_library_requirements($phase) {
 
-   $requirements = array();
 
-   if ($phase == 'install') {
 
-     // make sure chado is installed
 
-     if (!tripal_core_is_chado_installed()) {
 
-       $requirements ['tripal_library'] = array(
 
-             'title' => "tripal_library",
 
-             'value' => "ERROR: Chado most be installed before this module can be enabled",
 
-             'severity' => REQUIREMENT_ERROR,
 
-       );
 
-     }
 
-   }
 
-   return $requirements;
 
- }
 
 
  |