|
@@ -1,27 +1,10 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-/**
|
|
|
|
- * Launchpad for biological data administration.
|
|
|
|
- */
|
|
|
|
-function tripal_entities_admin_view() {
|
|
|
|
-
|
|
|
|
- // Render the tripal entites bundle form.
|
|
|
|
- $form = drupal_get_form('tripal_entities_admin_bundles_form');
|
|
|
|
- $output = drupal_render($form) . "<br>[ Image Place Holder for Data Type Summary ]<br>";
|
|
|
|
-
|
|
|
|
- // Set the breadcrumb.
|
|
|
|
- $breadcrumb = array();
|
|
|
|
- $breadcrumb[] = l('Home', '<front>');
|
|
|
|
- $breadcrumb[] = l('Administration', 'admin');
|
|
|
|
- $breadcrumb[] = l('Tripal', 'admin/tripal');
|
|
|
|
- drupal_set_breadcrumb($breadcrumb);
|
|
|
|
-
|
|
|
|
- return $output;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Provide a data listing for tripal entites (ie: biological data).
|
|
* Provide a data listing for tripal entites (ie: biological data).
|
|
- * Note: This hook returns a rendered page but we want a form.
|
|
|
|
|
|
+ *
|
|
|
|
+ * This function is a callback in a menu item which is set in the
|
|
|
|
+ * TripalEntityUIController class.
|
|
*/
|
|
*/
|
|
function tripal_entities_content_view() {
|
|
function tripal_entities_content_view() {
|
|
|
|
|
|
@@ -40,7 +23,7 @@ function tripal_entities_content_view() {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Display a listing of Biological Data to the administrator.
|
|
|
|
|
|
+ * Display a listing of Tripal entities.
|
|
*
|
|
*
|
|
* @TODO Filters and bulk operations needed to be added to this form.
|
|
* @TODO Filters and bulk operations needed to be added to this form.
|
|
*
|
|
*
|
|
@@ -76,14 +59,14 @@ function tripal_entities_content_overview_form($form, &$form_state) {
|
|
|
|
|
|
// Add information to the table.
|
|
// Add information to the table.
|
|
$rows[] = array(
|
|
$rows[] = array(
|
|
- l($entity->title, 'BioData/' . $entity->id),
|
|
|
|
|
|
+ l($entity->title, 'bio-data/' . $entity->id),
|
|
$cvterm->cv_id->name . ' (' . $cvterm->dbxref_id->db_id->name . ')',
|
|
$cvterm->cv_id->name . ' (' . $cvterm->dbxref_id->db_id->name . ')',
|
|
$cvterm->name,
|
|
$cvterm->name,
|
|
l($author->name, 'user/' . $entity->uid),
|
|
l($author->name, 'user/' . $entity->uid),
|
|
$entity->status == 1 ? 'published' : 'unpublished',
|
|
$entity->status == 1 ? 'published' : 'unpublished',
|
|
format_date($entity->changed, 'short'),
|
|
format_date($entity->changed, 'short'),
|
|
- l('edit', 'BioData/' . $entity->id . '/edit') . ' ' .
|
|
|
|
- l('delete', 'BioData/' . $entity->id . '/delete')
|
|
|
|
|
|
+ l('edit', 'bio-data/' . $entity->id . '/edit') . ' ' .
|
|
|
|
+ l('delete', 'bio-data/' . $entity->id . '/delete')
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,86 +100,7 @@ function tripal_entities_content_overview_form($form, &$form_state) {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Tripal administration form for Biological data (Admin > Tripal > Biological Data).
|
|
|
|
- *
|
|
|
|
- * @TODO Add graph showing available data types.
|
|
|
|
- *
|
|
|
|
- * @param unknown $form
|
|
|
|
- * @param unknown $form_state
|
|
|
|
- * @return multitype:
|
|
|
|
- */
|
|
|
|
-function tripal_entities_admin_bundles_form($form, &$form_state) {
|
|
|
|
- $form = array();
|
|
|
|
-
|
|
|
|
- // Set the defaults.
|
|
|
|
- $cv_id = NULL;
|
|
|
|
- $term_name = NULL;
|
|
|
|
-
|
|
|
|
- // Set defaults using the form state.
|
|
|
|
- if (array_key_exists('values', $form_state)) {
|
|
|
|
- $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : NULL;
|
|
|
|
- $term_name = array_key_exists('term_name', $form_state['values']) ? $form_state['values']['term_name'] : NULL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Let the user select the vocabulary and tripal_entity but only if they haven't
|
|
|
|
- // already selected a tripal_entity.
|
|
|
|
- $sql = "
|
|
|
|
- SELECT CV.cv_id, CV.name
|
|
|
|
- FROM {cv} CV
|
|
|
|
- ORDER BY CV.name
|
|
|
|
- ";
|
|
|
|
- $vocabs = chado_query($sql);
|
|
|
|
- $cvs = array();
|
|
|
|
- while ($vocab = $vocabs->fetchObject()) {
|
|
|
|
- $cvs[$vocab->cv_id] = $vocab->name;
|
|
|
|
- }
|
|
|
|
- $form['cv_id'] = array(
|
|
|
|
- '#type' => 'select',
|
|
|
|
- '#title' => t('Vocabulary'),
|
|
|
|
- '#options' => $cvs,
|
|
|
|
- '#required' => FALSE,
|
|
|
|
- '#description' => t('Select a vocabulary to view potential data types in the chart below. Limit the chart to only published data types by selecting the checkbox.'),
|
|
|
|
- '#default_value' => $cv_id,
|
|
|
|
- '#ajax' => array(
|
|
|
|
- 'callback' => "tripal_entities_admin_bundles_form_ajax_callback",
|
|
|
|
- 'wrapper' => 'tripal_entities_admin_bundles_form',
|
|
|
|
- 'effect' => 'fade',
|
|
|
|
- 'method' => 'replace'
|
|
|
|
- )
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- $form['refresh_bundles'] = array(
|
|
|
|
- '#type' => 'submit',
|
|
|
|
- '#value' => t('Refresh Data Types'),
|
|
|
|
- '#name' => 'refresh_bundles',
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- $form['publish_new_data'] = array(
|
|
|
|
- '#type' => 'submit',
|
|
|
|
- '#value' => t('Publish New Data'),
|
|
|
|
- '#name' => 'publish_new_data',
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- $form['#prefix'] = '<div id="tripal_entities_admin_bundle_form">';
|
|
|
|
- $form['#suffix'] = '</div>';
|
|
|
|
- return $form;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Submit a job to populate the entity tables
|
|
|
|
- * This operation makes available data types in the database publishable
|
|
|
|
- */
|
|
|
|
-function tripal_entities_admin_bundles_form_submit($form, $form_state) {
|
|
|
|
- global $user;
|
|
|
|
- if ($form_state['clicked_button']['#name'] == 'refresh_bundles') {
|
|
|
|
- tripal_add_job('Create publishable data types', 'tripal_entity', 'tripal_entities_populate_entity_tables', array(), $user->uid);
|
|
|
|
- }
|
|
|
|
- if ($form_state['clicked_button']['#name'] == 'publish_new_data') {
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Form for creating biological data types (ie: tripal entity types).
|
|
|
|
|
|
+ * Form for creating tripal data types.
|
|
*
|
|
*
|
|
* This form is available on the menu at Admin >> Structure >> Biological Data
|
|
* This form is available on the menu at Admin >> Structure >> Biological Data
|
|
* Types
|
|
* Types
|
|
@@ -244,11 +148,13 @@ function tripal_entities_admin_add_type_form($form, &$form_state) {
|
|
// If no term has been selected yet then provide the auto complete field.
|
|
// If no term has been selected yet then provide the auto complete field.
|
|
if ($num_terms == 0) {
|
|
if ($num_terms == 0) {
|
|
$form['term_name'] = array(
|
|
$form['term_name'] = array(
|
|
- '#title' => t('Biological Data Type'),
|
|
|
|
|
|
+ '#title' => t('Content Type'),
|
|
'#type' => 'textfield',
|
|
'#type' => 'textfield',
|
|
- '#description' => t("Please enter the type of data that you want to add.
|
|
|
|
- Once added, priviledged users can add new records of the selected
|
|
|
|
- type. As you type, suggestions will be provided."),
|
|
|
|
|
|
+ '#description' => t("The content type must be the name of a term in
|
|
|
|
+ a controlled vocabulary and the controlled vocabulary should
|
|
|
|
+ already be loaded into Tripal. For example, to create a content
|
|
|
|
+ type for storing 'genes', use the 'gene' term from the
|
|
|
|
+ Sequence Ontology (SO)."),
|
|
'#required' => TRUE,
|
|
'#required' => TRUE,
|
|
'#default_value' => $term_name,
|
|
'#default_value' => $term_name,
|
|
'#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/$cv_id",
|
|
'#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/$cv_id",
|
|
@@ -291,8 +197,6 @@ function tripal_entities_admin_add_type_form($form, &$form_state) {
|
|
*/
|
|
*/
|
|
function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
|
|
function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
|
|
|
|
|
|
- // Check if this term and vocabulary is in the tripal_vocabulary usage tables.
|
|
|
|
- // If not then add it.
|
|
|
|
if (array_key_exists('clicked_button', $form_state) and
|
|
if (array_key_exists('clicked_button', $form_state) and
|
|
$form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
$form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
|
|
|
|
@@ -346,21 +250,21 @@ function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
|
|
if ($form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
if ($form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
$cvterm = $form_state['storage']['terms'][0];
|
|
$cvterm = $form_state['storage']['terms'][0];
|
|
|
|
|
|
- $bundle_id = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
|
|
|
|
|
|
+ $bundle_id = 'bio-data_' . $cvterm->cvterm_id;
|
|
|
|
|
|
// Before we try to add this type, check to see if it already exists
|
|
// Before we try to add this type, check to see if it already exists
|
|
// as a bundle.
|
|
// as a bundle.
|
|
- $einfo = entity_get_info('BioData');
|
|
|
|
|
|
+ $einfo = entity_get_info('TripalEntity');
|
|
if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
|
|
if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
|
|
$error = '';
|
|
$error = '';
|
|
$success = tripal_create_entity_type($cvterm, $error);
|
|
$success = tripal_create_entity_type($cvterm, $error);
|
|
if (!$success) {
|
|
if (!$success) {
|
|
drupal_set_message($error, 'error');
|
|
drupal_set_message($error, 'error');
|
|
- $form_state['redirect'] = "admin/structure/BioData";
|
|
|
|
|
|
+ $form_state['redirect'] = "admin/structure/bio-data";
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
drupal_set_message('New biological data type created. Fields are added automatically to this type.');
|
|
drupal_set_message('New biological data type created. Fields are added automatically to this type.');
|
|
- $form_state['redirect'] = "admin/structure/BioData";
|
|
|
|
|
|
+ $form_state['redirect'] = "admin/structure/bio-data";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -373,26 +277,26 @@ function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
|
|
* Implements hook_add_bundle_fields().
|
|
* Implements hook_add_bundle_fields().
|
|
*
|
|
*
|
|
* @param $entity_type_name
|
|
* @param $entity_type_name
|
|
- * @param $bundle_name
|
|
|
|
|
|
+ * @param $bundle_id
|
|
* @param $cvterm
|
|
* @param $cvterm
|
|
*/
|
|
*/
|
|
-function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvterm) {
|
|
|
|
|
|
+function tripal_entities_add_bundle_fields($entity_type_name, $bundle_id, $cvterm) {
|
|
// Adds the fields for the base table to the entity.
|
|
// Adds the fields for the base table to the entity.
|
|
- tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_name, $cvterm);
|
|
|
|
|
|
+ tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_id, $cvterm);
|
|
|
|
|
|
// Check to see if there are any kv-property tables associated to this
|
|
// Check to see if there are any kv-property tables associated to this
|
|
// base table. If so, add the fields for that type of table.
|
|
// base table. If so, add the fields for that type of table.
|
|
- tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, 'featureprop');
|
|
|
|
|
|
+ tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_id, 'featureprop');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Adds the fields for a kv-property table fields
|
|
* Adds the fields for a kv-property table fields
|
|
*
|
|
*
|
|
* @param $entity_type_name
|
|
* @param $entity_type_name
|
|
- * @param $bundle_name
|
|
|
|
|
|
+ * @param $bundle_id
|
|
* @param $kv_table
|
|
* @param $kv_table
|
|
*/
|
|
*/
|
|
-function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
|
|
|
|
|
|
+function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_id, $kv_table) {
|
|
// First add a generic property field so that users can add new proeprty types.
|
|
// First add a generic property field so that users can add new proeprty types.
|
|
$field_name = $kv_table;
|
|
$field_name = $kv_table;
|
|
|
|
|
|
@@ -406,90 +310,82 @@ function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $b
|
|
'label' => 'Additional Properties',
|
|
'label' => 'Additional Properties',
|
|
'is_required' => 0,
|
|
'is_required' => 0,
|
|
);
|
|
);
|
|
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
|
|
|
|
|
|
+ tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Adds the fields for the base table to the entity.
|
|
* Adds the fields for the base table to the entity.
|
|
*/
|
|
*/
|
|
-function tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_name, $cvterm) {
|
|
|
|
-
|
|
|
|
- // Get the list of tables where this cvterm is used.
|
|
|
|
- $match = array('cvterm_id' => $cvterm->cvterm_id);
|
|
|
|
- $term = chado_select_record('tripal_term', array('*'), $match);
|
|
|
|
- $values = array('term_id' => $term[0]->term_id);
|
|
|
|
- $tables = chado_select_record('tripal_term_usage', array('*'), $values);
|
|
|
|
-
|
|
|
|
- // Iterate through the tables.
|
|
|
|
- foreach ($tables as $table) {
|
|
|
|
- $table_name = $table->data_table;
|
|
|
|
- $type_table = $table->type_table;
|
|
|
|
- $type_field = $table->field;
|
|
|
|
-
|
|
|
|
- // We only want to look at base tables.
|
|
|
|
- if ($table_name == 'cvterm_dbxref' || $table_name == 'cvterm_relationship' ||
|
|
|
|
- $table_name == 'cvtermpath' || $table_name == 'cvtermprop' || $table_name == 'chadoprop' ||
|
|
|
|
- $table_name == 'cvtermsynonym' || preg_match('/_relationship$/', $table_name) ||
|
|
|
|
- preg_match('/_cvterm$/', $table_name)) {
|
|
|
|
|
|
+function tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_id, $cvterm) {
|
|
|
|
+
|
|
|
|
+ // Get the details for this bundle
|
|
|
|
+ $bundle = db_select('tripal_bundle', 't')
|
|
|
|
+ ->fields('t')
|
|
|
|
+ ->condition('type', 'TripalEntity')
|
|
|
|
+ ->condition('bundle', $bundle_id)
|
|
|
|
+ ->execute()
|
|
|
|
+ ->fetchObject();
|
|
|
|
+ $bundle_data = unserialize($bundle->data);
|
|
|
|
+
|
|
|
|
+ $table_name = $bundle_data['data_table'];
|
|
|
|
+ $type_table = $bundle_data['type_table'];
|
|
|
|
+ $type_field = $bundle_data['field'];
|
|
|
|
+
|
|
|
|
+ // Iterate through the columns of the table and see if fields have been
|
|
|
|
+ // created for each one. If not, then create them.
|
|
|
|
+ $schema = chado_get_schema($table_name);
|
|
|
|
+ $columns = $schema['fields'];
|
|
|
|
+ foreach ($columns as $column_name => $details) {
|
|
|
|
+ $field_name = $table_name . '__' . $column_name;
|
|
|
|
+
|
|
|
|
+ // Skip the primary key field.
|
|
|
|
+ if ($column_name == $schema['primary key'][0]) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- // Iterate through the columns of the table and see if fields have been
|
|
|
|
- // created for each one. If not, then create them.
|
|
|
|
- $schema = chado_get_schema($table_name);
|
|
|
|
- $columns = $schema['fields'];
|
|
|
|
- foreach ($columns as $column_name => $details) {
|
|
|
|
- $field_name = $table_name . '__' . $column_name;
|
|
|
|
-
|
|
|
|
- // Skip the primary key field.
|
|
|
|
- if ($column_name == $schema['primary key'][0]) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Skip the type field.
|
|
|
|
- if ($table_name == $type_table and $column_name == $type_field) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ // Skip the type field.
|
|
|
|
+ if ($table_name == $type_table and $column_name == $type_field) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- // Get the field defaults for this column.
|
|
|
|
- $field_info = tripal_entities_get_table_column_field_default($table_name, $schema, $column_name);
|
|
|
|
|
|
+ // Get the field defaults for this column.
|
|
|
|
+ $field_info = tripal_entities_get_table_column_field_default($table_name, $schema, $column_name);
|
|
|
|
|
|
|
|
|
|
- // Determine if the field is required.
|
|
|
|
- if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
|
|
|
|
- $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
|
|
|
|
- }
|
|
|
|
|
|
+ // Determine if the field is required.
|
|
|
|
+ if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
|
|
|
|
+ $field_info['is_required'] = array_key_exists('default', $details) ? 0 : 1;
|
|
|
|
+ }
|
|
|
|
|
|
- // If we don't have a field type then we don't need to create a field.
|
|
|
|
- if (!$field_info['field_type']) {
|
|
|
|
- // If we don't have a field type but it is required and doesn't have
|
|
|
|
- // a default value then we are in trouble.
|
|
|
|
- if ($field_info['is_required'] and !array_key_exists('default', $details)) {
|
|
|
|
- throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
|
|
|
|
- array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
|
|
|
|
- }
|
|
|
|
- continue;
|
|
|
|
|
|
+ // If we don't have a field type then we don't need to create a field.
|
|
|
|
+ if (!$field_info['field_type']) {
|
|
|
|
+ // If we don't have a field type but it is required and doesn't have
|
|
|
|
+ // a default value then we are in trouble.
|
|
|
|
+ if ($field_info['is_required'] and !array_key_exists('default', $details)) {
|
|
|
|
+ throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
|
|
|
|
+ array('%table' => $table_name, '%field' => $column_name, '%type' => $details['type'])));
|
|
}
|
|
}
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- // If this field is a foreign key field then we will have a special custom
|
|
|
|
- // field provided by Tripal.
|
|
|
|
- $is_fk = FALSE;
|
|
|
|
- if (array_key_exists('foreign keys', $schema)) {
|
|
|
|
- foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
|
|
|
|
- if (array_key_exists($column_name, $fk_details['columns'])) {
|
|
|
|
- $is_fk = TRUE;
|
|
|
|
- }
|
|
|
|
|
|
+ // If this field is a foreign key field then we will have a special custom
|
|
|
|
+ // field provided by Tripal.
|
|
|
|
+ $is_fk = FALSE;
|
|
|
|
+ if (array_key_exists('foreign keys', $schema)) {
|
|
|
|
+ foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
|
|
|
|
+ if (array_key_exists($column_name, $fk_details['columns'])) {
|
|
|
|
+ $is_fk = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Add the field to the bundle.
|
|
|
|
- tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Add the field to the bundle.
|
|
|
|
+ tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns a $field_info array for a field based on a databaes column.
|
|
|
|
|
|
+ * Returns a $field_info array for a field based on a database column.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
function tripal_entities_get_table_column_field_default($table_name, $schema, $column_name) {
|
|
function tripal_entities_get_table_column_field_default($table_name, $schema, $column_name) {
|
|
@@ -568,15 +464,3 @@ function tripal_entities_get_table_column_field_default($table_name, $schema, $c
|
|
|
|
|
|
return $field_info;
|
|
return $field_info;
|
|
}
|
|
}
|
|
-
|
|
|
|
-/**
|
|
|
|
- *
|
|
|
|
- * @param unknown $form
|
|
|
|
- * @param unknown $form_state
|
|
|
|
- * @return multitype:
|
|
|
|
- */
|
|
|
|
-function tripal_entities_admin_access_form($form, &$form_state) {
|
|
|
|
- $form = array();
|
|
|
|
-
|
|
|
|
- return $form;
|
|
|
|
-}
|
|
|