Views will only allow a single entry for a chado table in hook_views_data. Thus currently, although there is the User Interface to create a custom views definition for a chado table it is overridden by the default views integration and as such non-functional.
In order to solve this it has been proposed that we add priorities to views integration definitions and choose the definition with the lightest (drupal-style) priority. Priorities will be as follows:
How Definition is provided | Priority Range | Default Priority |
---|---|---|
base tripal module (feature, cv, etc) | 10 | 10 |
custom modules (ND Genotypes, etc.) | 9 to 0 | 9 |
through UI | -1 to -10 | -1 |
This way definitions created through the web interface will always override those created by modules and custom modules will always override base tripal modules.
The API will consist of a two functions called in the .install file of the module.
- tripal_core_views_integration_add_entry($defn_array) which takes a single paramater defining the table and it's fields (see below for proposed array structure.
- tripal_core_views_integration_remove_entry($tablename, $priority) where tablename and priority uniquely identify the views definition to remove.
Proposed $defn_array:
array(
'table' => <tablename>,
'type' => mview | chado,
'description' => <description for views>,
'priority' => -10 to 10,
'fields' => array(
<field name> => array(
'name' => <field name in database>,
'title' => <human-readable name -in views>,
'handlers' => array(
'field' => array(
'name' => <handler name>
),
'filter' => array( ... ),
...
),
'join' => array(
'table' => <table to join to>,
'field' => <field to join to>
),
)
),
);
Comments
Comment #1
laceysanderson CreditAttribution: laceysanderson commentedFor Base Tripal module the $defn_array will be at least partially generated from the hook_chado_
_schema() table definition. From the schema definition we know the tablename, type, list of fields with field name -we can choose handlers for field/filter/sort with a switch based on the field type from schema. Then we just need to hardcode the human readable names and description in the above hook. This allows us to keep views integration even when we switch chado versions.
Comment #2
laceysanderson CreditAttribution: laceysanderson commentedAPI functions in place: tripal_core_views_integration_add_entry($defn_array) and tripal_core_views_integration_remove_entry($tablename, $priority). Neither yet use priority.
Commit 6.x-1482618-API_for_default_views_integration 38a1070
Comment #3
laceysanderson CreditAttribution: laceysanderson commentedNeed to make some changes to the tripal_views* tables:
Comment #4
laceysanderson CreditAttribution: laceysanderson commentedTable modifications discussed in comment #3 were done in 6.x-1482618-API_for_default_views_integration 224a032.
Comment #5
laceysanderson CreditAttribution: laceysanderson commentedStarted work on an API for tripal views.
List of Functions so far:
tripal_views_get_lightest_priority_setup ($table_name)
Retrieve the views integration setup with the lightest priority for a given table
NOTE: Uses lightest priority (drupal-style) where the range is from -10 to 10
and -10 is of highest priority.
@param $table_name
The name of the table to retrieve the setup ID for. This can be either a materialized
view or a chado table
@return
On success, the setup_id to use for integration of this table; otherwise FALSE
tripal_views_is_integrated($table_name, $priority = NULL)
Check to see if this table already has an integration record with the given priority
@param $table_name
The name of the table to check for integration
@param $priority (optional)
The priority of record to check for
@return
If the table is already integrated, the setup_id of the existing integration
record is returned (If priority is not specified this will be the lightest record);
Otherwise the table is not already integrated and FALSE is returned.
tripal_views_is_lightest_priority_setup ($setup_id, $table_name)
Checks if you are dealing with the lightest priority setup for a given table
@param $setup_id
The ID of the setup to check (is this setup the lightest one?)
@param $table_name
The name of the table associated with this setup
@return TRUE is this is the lightest priority; FALSE otherwise
tripal_views_integration_add_entry($defn_array)
Add views integration records into the tripal_views* tables
@param $defn_array
An array describing the structure and fields of the table
@return
True/False if completed successfully/not
Example usage (in hook_install()):
tripal_views_integration_remove_entry_by_table_name ($table_name, $priority)
Removes a View Integration Entry
@param $table_name
The name of the table to remove a views integration entry for
@param $priority
The priority of the of views integration entry
@return
TRUE on Success; FALSE otherwise
tripal_views_integration_remove_entry_by_setup_id ($setup_id)
Removes a View Integration Entry
@param $setup_id
The setup ID of the views integration entry to remove
tripal_views_get_integration_array_for_chado_table ($table_name)
Returns the array needed to integrate a given chado table with views
@param $tablename
The table to generate the tripal views integration array for
@return
The tripal views integration array which is the parameter for
tripal_views_integration_add_entry($defn_array)
Comment #6
laceysanderson CreditAttribution: laceysanderson commentedThis API allows a tripal module to integrate all chado tables associated with it via the following code (example is for the organism module):
Comment #7
laceysanderson CreditAttribution: laceysanderson commentedModules can also integrate their own custom tables using tripal_views_integration_add_entry($table_integration_array) by manually coding their own definition array. The following example is from the new ND Genotypes module which has not yet been released:
Table to be integrated:
Tripal Views Integration code:
Comment #8
laceysanderson CreditAttribution: laceysanderson commentedIntegration code can either be done when a module is enabled or is the hook_views_data() hook.
Things to keep in mind:
- When integrating when the module is enabled, the table will not be integrated if the tripal_views module is enabled after the module in question
- When integrating in the hook_views_data() make sure to include a check so you don't try to integrate the same table multiple times. This hook is executed often so the check may be made a lot and could have performance issues.
Comment #9
laceysanderson CreditAttribution: laceysanderson commentedAdded a new tag to differentiate which teasks must be completed for the next release of Tripal.
Comment #10
laceysanderson CreditAttribution: laceysanderson commentedThings yet to be done for this issue to be closed:
1) Upgrade of specialty handlers (ie: select list filter) to use chado_wrapper functionality -so they are safe to use with aggregated tables
2) Add specialty handler defaults to chado tables
3) Tripal Views Integration Import/Export
4) Full Testing of tripal views integration
Comment #11
laceysanderson CreditAttribution: laceysanderson commentedChecked views_handler_filter_chado_select_cvterm_name and set as the default handler for cvterm.name and *.type_id fields.
Comment #12
laceysanderson CreditAttribution: laceysanderson commentedImport/Export of Views Integration is done and in the 6.x-0.4-dev branch.
Comment #13
laceysanderson CreditAttribution: laceysanderson commented