| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 | 
							- <?php
 
- /**
 
-  * @file
 
-  * Installation of the library module
 
-  */
 
- /**
 
-  * Implements hook_disable().
 
-  * Disable default views when module is disabled
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_disable() {
 
-   // Disable all default views provided by this module
 
-   require_once("tripal_library.views_default.inc");
 
-   $views = tripal_library_views_default_views();
 
-   foreach (array_keys($views) as $view_name) {
 
-     tripal_views_admin_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
 
-   }
 
- }
 
- /**
 
-  * Implementation of hook_requirements().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_requirements($phase) {
 
-   $requirements = array();
 
-   if ($phase == 'install') {
 
-     // make sure chado is installed
 
-     if (!$GLOBALS["chado_is_installed"]) {
 
-       $requirements ['tripal_library'] = array(
 
-         'title' => "tripal_library",
 
-         'value' => "ERROR: Chado must be installed before this module can be enabled",
 
-         'severity' => REQUIREMENT_ERROR,
 
-       );
 
-     }
 
-   }
 
-   return $requirements;
 
- }
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_install() {
 
-   // create the module's data directory
 
-   tripal_create_files_dir('tripal_library');
 
-   // add the materialized view
 
-   tripal_library_add_mview_library_feature_count();
 
-   // add cvterms
 
-   tripal_library_add_cvs();
 
-   tripal_library_add_cvterms();
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_uninstall() {
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_schema() {
 
-   $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(
 
-       'chado_library_idx1' => array('library_id')
 
-     ),
 
-     'unique keys' => array(
 
-       'chado_library_uq1' => array('nid', 'vid'),
 
-       'chado_library_uq2' => array('vid')
 
-     ),
 
-     'primary key' => array('nid'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Adds a materialized view keeping track of the type of features associated with each library
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_add_mview_library_feature_count(){
 
-   $view_name = 'library_feature_count';
 
-   $comment = 'Provides count of feature by type that are associated with all libraries';
 
-   $schema = array(
 
-     'table' => $view_name,
 
-     'description' => $comment,
 
-     'fields' => array(
 
-       'library_id' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-       ),
 
-       'name' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => TRUE,
 
-       ),
 
-       'num_features' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-       ),
 
-       'feature_type' => array(
 
-         'type' => 'varchar',
 
-         'length' => 255,
 
-         'not null' => TRUE,
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'library_feature_count_idx1' => array('library_id'),
 
-     ),
 
-   );
 
-   $sql = "
 
-     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
 
-   ";
 
-   tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
 
- }
 
- /**
 
-  * Adds new CV's used by this module
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_add_cvs(){
 
-   tripal_cv_add_cv(
 
-     'library_property',
 
-     'Contains properties for libraries'
 
-   );
 
-   tripal_cv_add_cv(
 
-     'library_type',
 
-     'Contains terms for types of libraries (e.g. BAC, cDNA, FOSMID, etc).'
 
-   );
 
- }
 
- /**
 
-  * Adds cvterms needed for the library module
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_add_cvterms() {
 
-   // 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'
 
-      ),
 
-     'library_property', 0, 1, 'tripal'
 
-    );
 
-   // add cvterms for the map unit types
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'cdna_library',
 
-       'def' => 'cDNA library'
 
-     ),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'bac_library',
 
-       'def' => 'Bacterial Artifical Chromsome (BAC) library'
 
-     ),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'fosmid_library',
 
-       'def' => 'Fosmid library'
 
-     ),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'cosmid_library',
 
-       'def' => 'Cosmid library'
 
-     ),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'yac_library',
 
-       'def' => 'Yeast Artificial Chromosome (YAC) library'
 
-     ),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
-   tripal_cv_add_cvterm(
 
-     array(
 
-       'name' => 'genomic_library',
 
-       'def' => 'Genomic Library'),
 
-     'library_type', 0, 1, 'tripal'
 
-   );
 
- }
 
- /**
 
-  * This is the required update for tripal_library when upgrading from Drupal core API 6.x.
 
-  *
 
-  * @ingroup tripal_library
 
-  */
 
- function tripal_library_update_7000() {
 
-   // the library types were formerly in a vocabulary named 'tripal_library_types'.
 
-   // rename that to just be 'library_type'
 
-   $cv = tripal_cv_get_cv_by_name('tripal_library_types');
 
-   $match = array(
 
-     'cv_id' => $cv->cv_id
 
-   );
 
-   $values = array(
 
-     'name' => 'library_type'
 
-   );
 
-   $success = chado_update_record('cv', $match, $values);
 
-   if (!$success) {
 
-     throw new DrupalUpdateException('Failed to rename tripal_library_types CV.');
 
-   }
 
-   // For Tripal in Drupal 6 the library_description cvterm was stored in the
 
-   // 'tripal' CV.  It should be stored in the new library_property CV that
 
-   // is added by this module for Tripal 2.0 and Drupal 7.  So, we need to
 
-   // reset the CV ID for that term and rename the term to 'Library Description'
 
-   tripal_library_add_cvs();
 
-   $cv = tripal_cv_get_cv_by_name('library_property');
 
-   $cvterm = tripal_cv_get_cvterm_by_name('library_description');
 
-   $match = array(
 
-     'cvterm_id' => $cvterm->cvterm_id,
 
-   );
 
-   $values = array(
 
-     'cv_id' => $cv->cv_id,
 
-     'name' => 'Library Description',
 
-   );
 
-   chado_update_record('cvterm', $match, $values);
 
-   if (!$success) {
 
-     throw new DrupalUpdateException('Failed to move library properties to new library_property CV.');
 
-   }
 
- }
 
 
  |