123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- function tripal_organism_views_data() {
-
- if (db_table_exists('tripal_organism_views_common_name')) {
- $sql = "DROP TABLE {tripal_organism_views_common_name}";
- db_query ($sql);
- }
-
-
-
- drupal_install_schema('tripal_organism_views_common_name');
-
-
-
- $sql = 'SELECT nid, organism_id FROM {chado_organism}';
- $result = db_query($sql);
-
-
- $sql = 'SELECT common_name FROM {organism} WHERE organism_id=%d';
- $previous_db = tripal_db_set_active ('chado');
- $common_names = array ();
- while ($org = db_fetch_object($result)) {
- $common_name = db_result(db_query ($sql, $org->organism_id));
- $common_names [$org->nid] = $common_name;
- }
- tripal_db_set_active ($previous_db);
-
-
- $sql = "INSERT INTO {tripal_organism_views_common_name} (nid, common_name) VALUES (%d, '%s')";
- foreach ($common_names as $nid => $common_name) {
- db_query($sql, $nid, $common_name);
- }
-
-
- $data['tripal_organism_views_common_name'] = array(
-
- 'table' => array(
- 'group' => 'Tripal organism',
- 'join' => array(
- 'node' => array(
- 'left_field' => 'nid',
- 'field' => 'nid',
- ),
- ),
- ),
-
- 'common_name' => array(
- 'title' => t('Common name'),
-
- 'help' => t('The common name of an organism.'),
-
- 'field' => array(
- 'handler' => 'views_handler_field_node',
- 'click sortable' => TRUE,
- ),
-
- 'filter' => array(
- 'handler' => 'views_handler_filter_numeric',
- ),
-
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- ),
- );
- return $data;
- }
- function tripal_organism_views_common_name_schema() {
- $schema['tripal_organism_views_common_name'] = array(
- 'fields' => array(
- 'nid' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0
- ),
- 'common_name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => 'NA',
- 'description' => t('To provide common name for the Views module')
- ),
- ),
- );
- return $schema;
- }
|