3.0, ); } /** * Implements hook_menu(). */ function tripal_chado_menu() { $items = array(); ////////////////////////////////////////////////////////////////////////////// // Chado Storage Backend ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado'] = array( 'title' => 'Chado', 'description' => t("Integrates Chado with Tripal and includes tools to load data, and extend the chado schema through custom tables & materialized views."), 'weight' => -100, 'access arguments' => array('administer tripal'), ); $items['admin/tripal/storage/chado/chado_install'] = array( 'title' => 'Install Chado', 'description' => t('Installs the Chado database tables, views, etc., inside the current Drupal database'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_chado_install_form'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('install chado'), 'file' => 'includes/tripal_chado.install.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => -100 ); $items['admin/tripal/storage/chado/chado_prepare'] = array( 'title' => 'Prepare Chado', 'description' => t('Prepares Drupal to use Chado.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_chado_prepare_form'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('install chado'), 'file' => 'includes/tripal_chado.setup.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => -99 ); $items['admin/tripal/storage/chado/publish'] = array( 'title' => 'Publish', 'description' => t('Publish data that is present in Chado but which does not yet have a page on this site for viewing. In Tripal v2.0 or earlier this was refered to as "syncing".'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_chado_publish_form'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.publish.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => -99 ); $items['admin/structure/bio_data/publish'] = array( 'title' => 'Publish Chado Content', 'description' => t('Publish data that is present in Chado but which does not yet have a page on this site for viewing. In Tripal v2.0 or earlier this was refered to as "syncing".'), 'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_chado_publish_form'), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.publish.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_LOCAL_ACTION, 'weight' => 2 ); ////////////////////////////////////////////////////////////////////////////// // Materialized Views ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado/mviews'] = array( 'title' => 'Materialized Views', 'description' => t('Materialized views are used to improve speed of large or complex queries.'), 'page callback' => 'tripal_mview_admin_view', 'access arguments' => array('administer tripal'), 'type' => MENU_NORMAL_ITEM, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => -10 ); $items['admin/tripal/storage/chado/mviews/help'] = array( 'title' => 'Help', 'description' => t('Help for the materialized views management system'), 'page callback' => 'theme', 'page arguments' => array('tripal_mviews_help'), 'access arguments' => array('administer tripal'), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => 10 ); $items['admin/tripal/storage/chado/mviews/report/%'] = array( 'title' => 'Materialized View', 'description' => t('Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.'), 'page callback' => 'tripal_mview_report', 'page arguments' => array(6), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/mviews/new'] = array( 'title' => 'Create Materialized View', 'description' => t('Create a new materialized view.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_mviews_form'), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/mviews/edit/%'] = array( 'title' => 'Edit Materialized View', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_mviews_form', 6), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/mviews/update/%'] = array( 'title' => 'Create Materialized View', 'description' => t('Materialized views are used to improve speed of large or complex queries.'), 'page callback' => 'tripal_mviews_add_populate_job', 'page arguments' => array(6), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/mviews/delete/%'] = array( 'title' => 'Create Materialized View', 'description' => t('Materialized views are used to improve speed of large or complex queries.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_mviews_delete_form', 5), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); // TODO: complete the code for exporting and importing of MViews. // Need to address security issues of sharing SQL. $items['admin/tripal/storage/chado/mviews/import'] = array( 'title' => 'Import MView', 'description' => 'Import a materialized view from another Tripal instance.', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_mviews_import_form'), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/mviews/%tblid/export'] = array( 'title' => 'Export MView', 'description' => 'Export a materialized view for use by another Tripal instance.', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_mviews_export_form', 5), 'access arguments' => array('administer tripal'), 'type' => MENU_CALLBACK, 'file' => 'includes/tripal_chado.mviews.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); ////////////////////////////////////////////////////////////////////////////// // Custom Tables ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado/custom_tables'] = array( 'title' => 'Custom Tables', 'description' => t('Creation of custom tables that are added to Chado database.'), 'page callback' => 'tripal_custom_table_admin_view', 'access arguments' => array('administer tripal'), 'type' => MENU_NORMAL_ITEM, 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => -10 ); $items['admin/tripal/storage/chado/custom_tables/help'] = array( 'title' => 'Help', 'description' => t('Help for the tripal job management system'), 'page callback' => 'theme', 'page arguments' => array('tripal_job_help'), 'access arguments' => array('administer tripal'), 'type' => MENU_LOCAL_TASK, 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => 10 ); $items['admin/tripal/storage/chado/custom_tables/view/%'] = array( 'title' => 'Custom Tables', 'description' => t('Custom tables are added to Chado.'), 'page callback' => 'tripal_custom_table_view', 'page arguments' => array(6), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/custom_tables/new'] = array( 'title' => 'Create Custom Table', 'description' => t('An interface for creating your own custom tables.'), 'page callback' => 'tripal_custom_table_new_page', 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/custom_tables/edit/%'] = array( 'title' => 'Edit Custom Table', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_custom_tables_form', 6), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/custom_tables/delete/%'] = array( 'title' => 'Create Custom Table', 'description' => t('Custom tables are added to Chado.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_custom_tables_delete_form', 6), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/custom_tables/views/tables/enable'] = array( 'title' => 'Enable Custom Tables Administrative View', 'page callback' => 'tripal_enable_view', 'page arguments' => array('tripal_admin_custom_table', 'admin/tripal/storage/chado/custom_tables'), 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.custom_tables.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); ////////////////////////////////////////////////////////////////////////////// // Data Loaders ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado/loaders'] = array( 'title' => 'Data Loaders', 'description' => t('Tools facilitating data import.'), 'access arguments' => array('administer tripal'), 'type' => MENU_NORMAL_ITEM, 'weight' => 6 ); $items['admin/tripal/storage/chado/loaders/fasta_loader'] = array( 'title' => 'FASTA file Loader', 'description' => 'Load sequences from a multi-FASTA file into Chado', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_feature_fasta_load_form'), 'access arguments' => array('administer tripal feature'), 'file' => 'includes/loaders/tripal_chado.fasta_loader.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/storage/chado/loaders/gff3_load'] = array( 'title' => 'GFF3 file Loader', 'description' => 'Import a GFF3 file into Chado', 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_feature_gff3_load_form'), 'access arguments' => array('administer tripal feature'), 'file' => 'includes/loaders/tripal_chado.gff_loader.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_NORMAL_ITEM, ); $items['admin/tripal/storage/chado/loaders/pub'] = array( 'title' => t('Publication Importers'), 'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'), 'page callback' => 'tripal_pub_importers_list', 'access arguments' => array('administer tripal pub'), 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_NORMAL_ITEM, 'weight' => 0 ); $items['admin/tripal/storage/chado/loaders/pub/new'] = array( 'title' => t('Add an Importer'), 'description' => t('Add a new publication importer.'), 'page callback' => 'tripal_pub_importer_setup_page', 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/edit/%'] = array( 'page callback' => 'tripal_pub_importer_setup_page', 'page arguments' => array(6, 7), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/raw/%'] = array( 'title' => t('Raw Data From Publication Import'), 'page callback' => 'tripal_get_remote_pub_raw_page', 'page arguments' => array(6), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); // add a second link for the importer on the data loaders page $items['admin/tripal/storage/chado/loaders/pub/import'] = array( 'title' => t('Publication Importers'), 'page callback' => 'tripal_pub_importers_list', 'access arguments' => array('administer tripal pub'), 'type' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/submit/%'] = array( 'page callback' => 'tripal_pub_importer_submit_job', 'page arguments' => array(7), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/delete/%'] = array( 'page callback' => 'tripal_pub_importer_delete', 'page arguments' => array(7), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/changedb'] = array( 'page callback' => 'tripal_pub_importer_setup_page_update_remotedb', 'page arguments' => array(), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); $items['admin/tripal/storage/chado/loaders/pub/criteria/%/%'] = array( 'page callback' => 'tripal_pub_importer_setup_page_update_criteria', 'page arguments' => array(7, 8), 'access arguments' => array('administer tripal pub'), 'type ' => MENU_CALLBACK, 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), ); ////////////////////////////////////////////////////////////////////////////// // Migrate Content ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado/migrate'] = array( 'title' => 'Migrate', 'description' => t('Migrate Tripal v2 content to Tripal v3'), 'page callback' => 'drupal_get_form', 'page arguments' => array('tripal_chado_migrate_form'), 'type' => MENU_NORMAL_ITEM, 'access arguments' => array('administer tripal'), 'file' => 'includes/tripal_chado.migrate.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'weight' => 10 ); ////////////////////////////////////////////////////////////////////////////// // Auto Completes ////////////////////////////////////////////////////////////////////////////// $items['admin/tripal/storage/chado/auto_name/dbxref/%/%'] = array( 'page callback' => 'tripal_autocomplete_dbxref', 'page arguments' => array(6, 7), 'access arguments' => array('access content'), 'file' => 'api/modules/tripal_chado.db.api.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/auto_name/cvterm/%/%'] = array( 'page callback' => 'tripal_autocomplete_cvterm', 'page arguments' => array(6, 7), 'access arguments' => array('access content'), 'file' => 'api/modules/tripal_chado.db.api.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); $items['admin/tripal/storage/chado/auto_name/pub/%'] = array( 'page callback' => 'tripal_autocomplete_pub', 'page arguments' => array(6), 'access arguments' => array('access content'), 'file' => 'api/modules/tripal_chado.pub.api.inc', 'file path' => drupal_get_path('module', 'tripal_chado'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implements hook_permission(). * * Set the permission types that the chado module uses. Essentially we * want permissionis that protect creation, editing and deleting of chado * data objects * * @ingroup tripal */ function tripal_chado_permission() { return array( 'install chado' => array( 'title' => t('Install Chado'), 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.') ), 'view chado_ids' => array( 'title' => t('View Internal IDs'), 'description' => t('On content pages Tripal will typically provide a table of information pulled from the Chado database but the primary key IDs for that data is typically not shown. The default Tripal templates can show the primary key ID inside of a blue shaded table row if this permission is enabled. This can be useful for site developers who might want these IDs when working with the underlying database.'), 'restrict access' => TRUE, ) ); } /** * Implements hook_theme(). */ function tripal_chado_theme($existing, $type, $theme, $path) { $themes = array( // Theme fields. 'chado_base__dbxref_id_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_base__dbxref_id.inc', ), 'chado_linker__dbxref_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_linker__dbxref.inc', ), 'chado_linker__cvterm_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_linker__cvterm.inc', ), 'chado_linker__synonym_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_linker__synonym.inc', ), 'chado_linker__pub_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_linker__pub.inc', ), 'chado_linker__prop_adder_widget' => array( 'render element' => 'element', 'file' => 'includes/fields/chado_linker__prop_adder.inc', ), 'tripal_chado_date_combo' => array( 'render element' => 'element', 'file' => 'theme/tripal_chado.theme.inc', ), // Themed forms 'tripal_pub_importer_setup_form_elements' => array( 'render element' => 'form', 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', ), 'tripal_pub_search_setup_form_elements' => array( 'render element' => 'form', 'file' => 'includes/loaders/tripal_chado.pub_importers.inc', ), ); // Override the theme for each entity to use the legacy modules // templates. if (module_exists('tripal_core')) { $core_path = drupal_get_path('module', 'tripal_core'); // Get the list of node types that have legacy templates. $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array()); // Get the list of TripalEntity bundle. $bundles = db_select('tripal_bundle', 'tb') ->fields('tb') ->execute(); // Iterate through all of the TripalEntity bundles and see which ones // map to tables that used had Tripal v2 nodes. For those, if the // legacy support is turned on then we want to use the legacy template. while ($bundle = $bundles->fetchObject()) { $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id); $legacy_template = 'legacy_template--tripal_' . $chado_table; if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) { $themes['TripalEntity__' . $bundle->name] = array( 'template' => 'node--chado-generic', 'render element' => 'entity', 'base hook' => 'entity', 'path' => "$core_path/theme/templates", ); } } } return $themes; } /** * Implements hook_entity_view(). * * This function is used to support legacy Tripal v2 templates * for use with Tripal v3 entities. */ function tripal_chado_entity_view($entity, $type, $view_mode, $langcode) { // If this entity is a TripalEntity and is a full view, then // we want to support the legacy view, but only if the legacy // module is enabled (the functions exist). if ($type =='TripalEntity') { // Use the generic template to render the fields if ($view_mode == 'full') { // Get the Chado table for this data type. $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle)); $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id); $chado_field = tripal_get_bundle_variable('chado_column', $bundle->id); $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array()); $legacy_template = 'legacy_template--tripal_' . $chado_table; if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) { // Remove the fields added by the chado_field_storage. $fields = field_info_fields(); foreach($fields as $field) { if ($field['storage']['type'] == 'field_chado_storage' or $field['storage']['type'] == 'tripal_no_storage') { $field_name = $field['field_name']; if (property_exists($entity, $field_name)) { $entity->$field_name = NULL; unset($entity->content[$field_name]); } } } // Now call the module's node_view hook to add additional // content to our 'fake' entity node. $entity->type = 'chado_' . $chado_table; $entity->$chado_table = $entity->chado_record; // The comment module is expecting a 'comment' property // is attached to the node, so just set it to NULL. $entity->comment = NULL; $modules = module_list(); foreach ($modules as $mname => $details) { $function_name = $mname . '_node_view'; if (function_exists($function_name)) { $function_name($entity, $view_mode, $langcode); } } } } } } /** * Implements hook_entity_view_alter(). * * This function is used to support legacy Tripal v2 templates * for use with Tripal v3 entities. */ function tripal_chado_entity_view_alter(&$build) { // For the legacy support, we need to make sure the TOC // is built. if ($build['#entity_type'] == 'TripalEntity') { $enabled_templates = variable_get('tripal_chado_enabled_legacy_templates', array()); $entity = $build['#entity']; $legacy_template = 'legacy_template--' . str_replace('chado', 'tripal', $entity->type); if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) { $build['#entity']->nid = NULL; $build['#node'] = $build['#entity']; $modules = module_list(); foreach ($modules as $mname => $details) { $function_name = $mname . '_node_view_alter'; if (function_exists($function_name)) { $function_name($build); } } } } } /** * Implements hook_preprocess(). * * This function is used to support legacy Tripal v2 templates * for use with Tripal v3 entities. */ function tripal_chado_preprocess(&$variables, $hook) { if ($hook == 'entity' and array_key_exists('TripalEntity', $variables)) { // The node--chado-generic template expets there to be a // teaser and node variables. So, we'll add them. $variables['teaser'] = FALSE; $variables['node'] = $variables['TripalEntity']; } } /** * Implements hook_exclude_type_by_default() * * This hooks allows fields of a specified type that match a specified criteria * to be excluded by default from any table when chado_generate_var() is called. * Keep in mind that if fields are excluded by default they can always be * expanded at a later date using chado_expand_var(). * * Criteria are php strings that evaluate to either TRUE or FALSE. These * strings are evaluated using drupal_eval() which suppresses syntax errors and * throws watchdog entries of type php. There are also watchdog entries of type * tripal stating the exact criteria evaluated. Criteria can * contain the following tokens: * - * Replaced by the name of the field to be excluded * - * Replaced by the value of the field in the current record * Also keep in mind that if your criteria doesn't contain the * >field_value< token then it will be evaluated before the query is * executed and if the field is excluded it won't be included in the * query. * * @return * An array of type => criteria where the type is excluded if the criteria * evaluates to TRUE * * @ingroup tripal */ function tripal_chado_exclude_type_by_default() { return array('text' => 'strlen(" ") > 250'); } /** * Implements hook_job_describe_args(). * * Describes the arguements for the tripal_populate_mview job to allow for * greater readability in the jobs details pages. * * @param $callback * The callback of the current tripal job (this is the function that will be * executed when tripal_launch_jobs.php is run. * @param $args * An array of arguments passed in when the job was registered. * * @return * A more readable $args array * * @ingroup tripal */ function tripal_chado_job_describe_args($callback, $args) { $new_args = array(); if ($callback == 'tripal_populate_mview') { // get this mview details $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id "; $results = db_query($sql, array(':mview_id' => $args[0])); $mview = $results->fetchObject(); $new_args['View Name'] = $mview->name; } elseif ($callback == 'tripal_install_chado') { $new_args['Action'] = $args[0]; } return $new_args; } /** * Implements hook_entity_property_info_alter(). * * This is being implemented to ensure chado fields are exposed for search api indexing. * All fields are available for index by default but the getter function set by default * is not actually capable of getting the value from chado. Thus we change the getter * function to one that can :-). */ function tripal_chado_entity_property_info_alter(&$info) { // Get a list of fields with the chado storage backend. // Loop through all of the bundles. if (isset($info['TripalEntity']['bundles'])) { foreach ($info['TripalEntity']['bundles'] as $bundle_id => $bundle) { // Loop through each of the fields for a given bundle. foreach ($bundle['properties'] as $field_name => $field_info) { // If the field is a chado field, then change the callback. // @todo check this properly. if (preg_match('/(\w+)__(\w+)/', $field_name, $matches)) { $info['TripalEntity']['bundles'][$bundle_id]['properties'][$field_name]['getter callback'] = 'tripal_chado_entity_property_get_value'; } } } } } /** * Provides a way for the search api to grab the value of a chado field. * * @param $entity * The fully-loaded entity object to be indexed. * @param $options * Options that can be ued when retrieving the value. * @param $field_name * The machine name of the field we want to retrieve. * @param $entity_type * The type of entity (ie: TripalEntity). * * @return * The rendered value of the field specified by $field_name. */ function tripal_chado_entity_property_get_value($entity, $options, $field_name, $entity_type) { $display = array( 'type' => '', 'label' => 'hidden', ); $langcode = LANGUAGE_NONE; $items = field_get_items($entity_type, $entity, $field_name); if (count($items) == 1) { $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode); } // @todo: handle fields with multiple values. else { $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode); drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning'); } return drupal_render($render_array); } /** * Remove the nid from chado_entity if it exists when the node is deleted */ function tripal_chado_node_delete($node) { $nid = $node->nid; $sql = "UPDATE chado_entity SET nid = NULL WHERE nid = :nid"; db_query($sql, array('nid' => $nid)); }