| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 | 
							- <?php
 
- /**
 
-  * @file
 
-  * @todo Add file header description
 
-  */
 
- /**
 
-  * Disable default views when module is disabled
 
-  */
 
- function tripal_feature_disable() {
 
-   // Disable all default views provided by this module
 
-   require_once("tripal_feature.views_default.inc");
 
-   $views = tripal_feature_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().
 
-  */
 
- function tripal_feature_requirements($phase) {
 
-   $requirements = array();
 
-   if ($phase == 'install') {
 
-     // make sure chado is installed
 
-     if (!tripal_core_is_chado_installed()) {
 
-       $requirements ['tripal_feature'] = array(
 
-           'title' => "tripal_feature",
 
-           'value' => "ERROR: Chado most be installed before this module can be enabled",
 
-           'severity' => REQUIREMENT_ERROR,
 
-       );
 
-     }
 
-   }
 
-   return $requirements;
 
- }
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_feature
 
-  */
 
- function tripal_feature_install() {
 
-   // create the module's data directory
 
-   tripal_create_moddir('tripal_feature');
 
-   // add the materialized view
 
-   tripal_feature_add_organism_count_mview();
 
-   // add a job to the job queue so this view gets updated automatically next
 
-   // time the job facility is run
 
-   if ($mview_id = tripal_mviews_get_mview_id('organism_feature_count')) {
 
-     tripal_mviews_action('update', $mview_id);
 
-   }
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_feature
 
-  */
 
- function tripal_feature_uninstall() {
 
-   // Drop the MView table if it exists
 
-   // D7 @todo Fix tripal_mviews_get_mview_id()
 
-   /**
 
-   if ($mview_id = tripal_mviews_get_mview_id('organism_feature_count')) {
 
-     tripal_mviews_action("delete", $mview_id);
 
-   }
 
-   */
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_feature
 
-  */
 
- function tripal_feature_schema() {
 
-   $schema['chado_feature'] = 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
 
-        ),
 
-       'feature_id' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-         'default' => 0
 
-       ),
 
-       'sync_date' => array(
 
-         'type' => 'int',
 
-         'not null' => FALSE,
 
-         'description' => 'UNIX integer sync date/time'
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'chado_feature_idx1' => array('feature_id')
 
-     ),
 
-     'unique keys' => array(
 
-       'chado_feature_uq1' => array('nid', 'vid'),
 
-       'chado_feature_uq2' => array('vid')
 
-     ),
 
-     'primary key' => array('nid'),
 
-   );
 
-   return $schema;
 
- };
 
- /**
 
-  *
 
-  * @ingroup tripal_feature
 
-  */
 
- function tripal_feature_add_organism_count_mview() {
 
-   $view_name = 'organism_feature_count';
 
-   $comment = 'Stores the type and number of features per organism';
 
-   $schema = array(
 
-     'description' => $comment,
 
-     'table' => $view_name,
 
-     '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_feature_count_idx1' => array('organism_id'),
 
-       'organism_feature_count_idx2' => array('cvterm_id'),
 
-       'organism_feature_count_idx3' => array('feature_type'),
 
-     ),
 
-   );
 
-   $sql = "
 
-     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
 
-   ";
 
-   tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
 
- }
 
 
  |