123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php
- require_once "jobs.php";
- require_once "mviews.php";
- require_once "cvterms.php";
- require_once "chado_install.php";
- require_once "bulk_loader.php";
- require_once "tripal_core.api.inc";
- /**
- * @defgroup tripal_core Core Tripal Module
- * @{
- * Provides basic functions for interacting with chado
- * @}
- */
-
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_core_init(){
- // the two lines below are necessary to ensure that the search_path
- // variable is always set. In the case where a view needs to query the
- // chado schema when it is local to the Drupal database. Otherwise the
- // search_path isn't set. When tripal_db_set_active is called it
- // automatically sets the serach path if chado is local to the
- // Drupal database
- $previous = tripal_db_set_active('chado');
- tripal_db_set_active($previous);
- // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
- // only if the chado database is present.
- if(tripal_core_is_chado_installed()){
- $previous_db = tripal_db_set_active('chado'); // use chado database
- if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
- $results = db_query("INSERT INTO {cv} (name,definition) ".
- "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
- }
- if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
- $results = db_query("INSERT INTO {db} (name,description) ".
- "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
- }
- tripal_db_set_active($previous_db); // now use drupal database
- }
- }
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_create_moddir($module_name){
- // make the data directory for this module
- $data_dir = file_directory_path() . "/tripal/$module_name";
- if(!file_check_directory($data_dir,FILE_CREATE_DIRECTORY|FILE_MODIFY_PERMISSIONS)){
- $message = "Cannot create directory $data_dir. This module may not ".
- "behave correctly without this directory. Please create ".
- "the directory manually or fix the problem and reinstall.";
- drupal_set_message($message,'error');
- watchdog('tripal_core',$message,array(),WATCHDOG_ERROR);
- }
- }
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_get_moddir($module_name){
- $data_dir = file_directory_path() . "/tripal/$module_name";
- return $data_dir;
- }
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_core_menu() {
- $items = array();
-
- // Triapl setting groups
- $items['admin/tripal'] = array(
- 'title' => 'Tripal Management',
- 'description' => "Manage the behavior or Tripal and its various modules.",
- 'position' => 'right',
- 'weight' => -5,
- 'page callback' => 'system_admin_menu_block_page',
- 'access arguments' => array('administer site configuration'),
- 'file' => 'system.admin.inc',
- 'file path' => drupal_get_path('module', 'system'),
- );
- // the administative settings menu
- /* $items['admin/tripal/tripal_core'] = array(
- 'title' => 'Tripal core settings',
- 'description' => 'Tripal Settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_core_admin'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- */
- $items['admin/tripal/tripal_jobs'] = array(
- 'title' => 'Jobs',
- 'description' => 'Jobs managed by Tripal',
- 'page callback' => 'tripal_jobs_report',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_jobs/cancel/%'] = array(
- 'title' => 'Jobs',
- 'description' => 'Cancel a pending job',
- 'page callback' => 'tripal_jobs_cancel',
- 'page arguments' => array(4),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_jobs/rerun/%'] = array(
- 'title' => 'Jobs',
- 'description' => 'Re-run an existing job.',
- 'page callback' => 'tripal_jobs_rerun',
- 'page arguments' => array(4),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_jobs/view/%'] = array(
- 'title' => 'Jobs Details',
- 'description' => 'View job details.',
- 'page callback' => 'tripal_jobs_view',
- 'page arguments' => array(4),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_mview/%'] = array(
- 'title' => 'Materialized View',
- 'description' => 'Materialized views are used to improve speed of large or complex queries.',
- 'page callback' => 'tripal_mview_report',
- 'page arguments' => array(3),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_mviews'] = array(
- 'title' => 'Materialized Views',
- 'description' => 'Materialized views are used to improve speed of large or complex queries.',
- 'page callback' => 'tripal_mviews_report',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_mviews/new'] = array(
- 'title' => 'Create View',
- 'description' => 'Materialized views are used to improve speed of large or complex queries.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_form'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_mviews/edit/%'] = array(
- 'title' => 'Edit View',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_mviews_form',4),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_mviews/action/%/%'] = array(
- 'title' => 'Create View',
- 'description' => 'Materialized views are used to improve speed of large or complex queries.',
- 'page callback' => 'tripal_mviews_action',
- 'page arguments' => array(4,5),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['tripal_toggle_box_menu/%/%/%'] = array(
- 'title' => t('Libraries'),
- 'page callback' => 'tripal_toggle_box_menu',
- 'page arguments' => array(1,2,3),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
- );
- $items['admin/tripal/chado_1_11_install'] = array(
- 'title' => 'Install Chado v1.11',
- 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/bulk_load/create'] = array(
- 'title' => 'Create Bulk Loader',
- 'description' => 'Create a bulk loader template for loading data into Chado',
- 'page callback' => 'tripal_core_bulk_loader_create',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/bulk_load/step2_get_type/%'] = array(
- 'title' => 'Create Bulk Loader',
- 'description' => 'Create a bulk loader template for loading data into Chado',
- 'page callback' => 'tripal_core_bulk_loader_ahah_step2_feature_type',
- 'page arguments' => array(4),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- $items['test2'] = array(
- 'title' => 'test',
- 'description' => 'test',
- 'page callback' => 'tripal_core_chado_insert_test',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_core_admin () {
- $form['chado_feature_data_url'] = array (
- '#title' => t('URL for data files'),
- '#type' => t('textfield'),
- '#description' => t("This is the base URL location (without a leading forward slash) for where files (e.g. blast .xml files) related to each feature are stored. All files available for download or parsing that a feature needs for display should be located in this base directory."),
- '#required' => TRUE,
- '#default_value' => variable_get('chado_feature_data_url','sites/default/files/data'),
- );
-
- return system_settings_form($form);
- }
- /**
- * Set the Tripal Database
- *
- * The tripal_db_set_active function is used to prevent namespace collisions
- * when chado and drupal are installed in the same database but in different
- * schemas. It is also used for backwards compatibility with older versions
- * of tripal or in cases where chado is located outside of the Drupal database.
- *
- * @ingroup tripal_core
- */
- function tripal_db_set_active($dbname){
- global $db_url, $db_type;
- $chado_exists = 0;
- // only postgres can support search paths. So if this is MysQL then
- // just run the normal tripal_db_set_active function.
- if(strcmp($db_type,'pgsql')==0){
- // if the 'chado' database is in the $db_url variable then chado is
- // not in the same Drupal database
- if(is_array($db_url)){
- if(isset($db_url[$dbname])){
- return db_set_active($dbname);
- }
- }
- // check to make sure the chado schema exists
- $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
- if(db_fetch_object(db_query($sql))){
- $chado_exists = 1;
- }
- // here we make the assumption that the default database schema is
- // 'public'. This will most likely always be the case but if not,
- // then this code will break
- if($chado_exists && strcmp($dbname,'chado')==0){
- db_query("set search_path to %s",'chado,public');
- return 'public,chado';
- }
- elseif($chado_exists) {
- db_query("set search_path to %s",'public,chado');
- return 'chado,public';
- }
- else {
- return db_set_active($dbname);
- }
- }
- else return db_set_active($dbname);
- }
- /**
- *
- *
- * @ingroup tripal_core
- */
- function tripal_core_is_chado_installed(){
- global $db_url, $db_type;
- // first check if chado is in the db_url of the
- // settings.php file
- if(is_array($db_url)){
- if(isset($db_url['chado'])){
- return true;
- }
- }
- // check to make sure the chado schema exists
- $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
- if(db_fetch_object(db_query($sql))){
- return true;
- }
- return false;
- }
- /**
- * Implements hook_views_api()
- *
- * Purpose: Essentially this hook tells drupal that there is views support for
- * for this module which then includes tripal_core.views.inc where all the
- * views integration code is
- *
- * @ingroup tripal_core
- */
- function tripal_core_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- /**
- * Purpose: Get max rank for a given set of criteria
- * This function was developed with the many property tables in chado in mind
- *
- * @param $tablename
- * The name of the chado table you want to select the max rank from this table must contain a
- * rank column of type integer
- * @param $where_options
- * where options should include the id and type for that table to correctly
- * group a set of records together where the only difference are the value and rank
- * @code
- * array(
- * <column_name> => array(
- * 'type' => <type of column: INT/STRING>,
- * 'value' => <the value you want to filter on>,
- * 'exact' => <if TRUE use =; if FALSE use ~>,
- * )
- * )
- * @endcode
- * @return the maximum rank
- *
- * @ingroup tripal_core
- */
- function tripal_get_max_chado_rank ($tablename, $where_options) {
- $where= array();
- //generate the where clause from supplied options
- // the key is the column name
- foreach ($where_options as $key => $val_array) {
- if (preg_match('/INT/', $val_array['type'])) {
- $where[] = $key."=".$val_array['value'];
- } else {
- if ($val_array['exact']) { $operator='='; }
- else { $operator='~'; }
- $where[] = $key.$operator."'".$val_array['value']."'";
- }
- }
-
- $previous_db = tripal_db_set_active('chado');
- $result = db_fetch_object(db_query(
- "SELECT max(rank) as max_rank, count(rank) as count FROM %s WHERE %s",
- $tablename,
- implode(' AND ',$where)
- ));
- tripal_db_set_active($previous_db);
- //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
- if ($result->count > 0) {
- return $result->max_rank;
- } else {
- return -1;
- }
- }
- function tripal_core_theme () {
- return array(
- 'tripal_core_job_view' => array (
- 'arguments' => array('job_id'=> null),
- 'template' => 'tripal_core_job_view',
- ),
- );
- }
|