| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 | 
							- <?php
 
- /**
 
-  * Install the tripal stock module including it's content type
 
-  * @file
 
-  */
 
- /**
 
-  * Implements hook_disable().
 
-  * Disable default views when module is disabled
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_disable() {
 
-   // Disable all default views provided by this module
 
-   require_once("tripal_stock.views_default.inc");
 
-   $views = tripal_stock_views_default_views();
 
-   foreach (array_keys($views) as $view_name) {
 
-     tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
 
-   }
 
- }
 
- /**
 
-  * Implementation of hook_requirements().
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_requirements($phase) {
 
-   $requirements = array();
 
-   if ($phase == 'install') {
 
-     // make sure chado is installed
 
-     if (!$GLOBALS["chado_is_installed"]) {
 
-       $requirements ['tripal_stock'] = array(
 
-         'title' => "tripal_stock",
 
-         'value' => "ERROR: Chado must be installed before this module can be enabled",
 
-         'severity' => REQUIREMENT_ERROR,
 
-       );
 
-     }
 
-   }
 
-   return $requirements;
 
- }
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_install() {
 
-   // add some controlled vocabularies
 
-   tripal_stock_add_cvs();
 
-   tripal_stock_add_cvterms();
 
-   // set the default vocabularies
 
-   tripal_set_default_cv('stock', 'type_id', 'stock_type');
 
-   tripal_set_default_cv('stockprop', 'type_id', 'stock_property');
 
-   tripal_set_default_cv('stock_relationship', 'type_id', 'stock_relationship');
 
-   // add the materialized view
 
-   tripal_stock_add_organism_count_mview();
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_uninstall() {
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_schema() {
 
-   $schema['chado_stock'] = array(
 
-     'fields' => array(
 
-       'vid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE,
 
-       ),
 
-       'nid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE,
 
-       ),
 
-       'stock_id' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE,
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'stock_id' => array('stock_id'),
 
-        'nid' => array('nid'),
 
-     ),
 
-     'unique' => array(
 
-       'stock_id' => array('stock_id'),
 
-     ),
 
-     'primary key' => array('vid'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Creates a materialized view that stores the type & number of stocks per organism
 
-  *
 
-  * @ingroup tripal_stock
 
-  */
 
- function tripal_stock_add_organism_count_mview() {
 
-   $view_name = 'organism_stock_count';
 
-   $comment = 'Stores the type and number of stocks 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_stocks' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-       ),
 
-       'cvterm_id' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-       ),
 
-       'stock_type' => array(
 
-         'type' => 'varchar',
 
-         'length' => '255',
 
-         'not null' => TRUE,
 
-       ),
 
-     ),
 
-     'indexes' => array(
 
-       'organism_stock_count_idx1' => array('organism_id'),
 
-       'organism_stock_count_idx2' => array('cvterm_id'),
 
-       'organism_stock_count_idx3' => array('stock_type'),
 
-     ),
 
-   );
 
-   $sql = "
 
-     SELECT
 
-         O.organism_id, O.genus, O.species, O.common_name,
 
-         count(S.stock_id) as num_stocks,
 
-         CVT.cvterm_id, CVT.name as stock_type
 
-      FROM organism O
 
-         INNER JOIN stock S  ON O.Organism_id = S.organism_id
 
-         INNER JOIN cvterm CVT ON S.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_stock', $schema, $sql, $comment);
 
- }
 
- /**
 
-  * Add cvs related to publications
 
-  *
 
-  * @ingroup tripal_pub
 
-  */
 
- function tripal_stock_add_cvs() {
 
-   // Add cv for relationship types
 
-   tripal_insert_cv(
 
-     'stock_relationship',
 
-     'Contains types of relationships between stocks.'
 
-   );
 
-   tripal_insert_cv(
 
-     'stock_property',
 
-     'Contains properties for stocks.'
 
-   );
 
-   tripal_insert_cv(
 
-     'stock_type',
 
-     'Contains a list of types for stocks.'
 
-   );
 
- }
 
- /**
 
-  * Add cvterms related to publications
 
-  *
 
-  * @ingroup tripal_pub
 
-  */
 
- function tripal_stock_add_cvterms() {
 
- }
 
- /**
 
-  * This is the required update for tripal_stock when upgrading from Drupal core API 6.x.
 
-  *
 
-  */
 
- function tripal_stock_update_7200() {
 
-   // add the new CVs.  We can't use the Tripal API because during
 
-   // an upgrade from D6 to D7 Tripal is disable. So, we have to manually add these
 
-   // new vocabularies.
 
-   // add the stock_relationshp CV
 
-   try {
 
-     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_relationship'")->fetchField();
 
-     if (!$cv_id) {
 
-       // add the vocabulary
 
-       $cv_id = db_insert('chado.cv')
 
-         ->fields(array(
 
-           'name' => 'stock_relationship',
 
-           'definition' => 'Contains types of relationships between stocks.'
 
-         ))
 
-         ->execute();
 
-     }
 
-     // for backwards compatibility, get the previously set stock relationship CV, otherwise
 
-     // use the new stock_relationship CV we just added
 
-     $default_stockrel_cv = variable_get('chado_stock_relationship_cv', $cv_id);
 
-     db_insert('tripal_cv_defaults')
 
-       ->fields(array(
 
-         'table_name' => 'stock_relationship',
 
-         'field_name' => 'type_id',
 
-         'cv_id' => $default_stockrel_cv
 
-       ))
 
-       ->execute();
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add stock_relationship vocabulary: '. $error);
 
-   }
 
-   // add the stock_property CV
 
-   try {
 
-     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_property'")->fetchField();
 
-     if (!$cv_id) {
 
-       // add the vocabulary
 
-       $cv_id = db_insert('chado.cv')
 
-         ->fields(array(
 
-           'name' => 'stock_property',
 
-           'definition' => 'Contains properties for stocks.'
 
-         ))
 
-         ->execute();
 
-     }
 
-     // for backwards compatibility, get the previously set stock property CV, otherwise
 
-     // use the new stock_property CV we just added
 
-     $default_stockprop_cv = variable_get('chado_stock_prop_types_cv', $cv_id);
 
-     db_insert('tripal_cv_defaults')
 
-       ->fields(array(
 
-       'table_name' => 'stockprop',
 
-       'field_name' => 'type_id',
 
-       'cv_id' => $default_stockprop_cv
 
-       ))
 
-       ->execute();
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add stock_property vocabulary: '. $error);
 
-   }
 
-   // add the stock_type CV
 
-   try {
 
-     $cv_id = db_query("SELECT cv_id FROM chado.cv WHERE name = 'stock_type'")->fetchField();
 
-     if (!$cv_id) {
 
-       // add the vocabulary
 
-       $cv_id = db_insert('chado.cv')
 
-       ->fields(array(
 
-         'name' => 'stock_type',
 
-         'definition' => 'Contains a list of types for stocks.'
 
-       ))
 
-       ->execute();
 
-     }
 
-     // for backwards compatibility, get the previously set stock types CV, otherwise
 
-     // use the new stock_type CV we just added
 
-     $default_stocktype_cv = variable_get('chado_stock_types_cv', $cv_id);
 
-     db_insert('tripal_cv_defaults')
 
-       ->fields(array(
 
-       'table_name' => 'stock',
 
-       'field_name' => 'type_id',
 
-       'cv_id' => $default_stocktype_cv
 
-       ))
 
-       ->execute();
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add stock_type vocabulary: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Add materialized views
 
-  */
 
- function tripal_stock_update_7201() {
 
-   // add the materialized view
 
-   tripal_stock_add_organism_count_mview();
 
- }
 
- /**
 
-  * Implementation of hook_update_dependencies().  It specifies a list of
 
-  * other modules whose updates must be run prior to this one.
 
-  */
 
- function tripal_stock_update_dependencies() {
 
-   $dependencies = array();
 
-   // the tripal_cv update 7200 must run prior to update 7200 of this module
 
-   $dependencies['tripal_stock'][7200] = array(
 
-     'tripal_cv' => 7200
 
-   );
 
-   return $dependencies;
 
- }
 
 
  |