|
@@ -81,11 +81,12 @@ function tripal_entities_content_overview_form($form, &$form_state) {
|
|
|
$headers = array('Title', 'Vocabulary', 'Term', 'Author', 'Status', 'Updated', 'Operations');
|
|
|
$rows = array();
|
|
|
while ($entity = $entities->fetchObject()) {
|
|
|
+ $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $entity->cvterm_id));
|
|
|
$author = user_load($entity->uid);
|
|
|
$rows[] = array(
|
|
|
l($entity->title, 'BioData/' . $entity->id),
|
|
|
- $entity->type,
|
|
|
- $entity->bundle,
|
|
|
+ $cvterm->cv_id->name . ' (' . $cvterm->dbxref_id->db_id->name . ')',
|
|
|
+ $cvterm->name,
|
|
|
l($author->name, 'user/' . $entity->uid),
|
|
|
$entity->status == 1 ? 'published' : 'unpublished',
|
|
|
format_date($entity->changed, 'short'),
|
|
@@ -330,7 +331,242 @@ function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+/**
|
|
|
+ * Implements hook_submit() for the tripal_entities_admin_publish_form.
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_entities_add_bundle($cvterm) {
|
|
|
+
|
|
|
+ // Create the bundle name and entity type name. The bundle name is the
|
|
|
+ // dbxref ID. This isn't very human readable, but the alternative is to
|
|
|
+ // use the accession which may not always be alpha-numeric.
|
|
|
+ $bundle_name = 'dbxref_' . $cvterm->dbxref_id->dbxref_id;
|
|
|
+
|
|
|
+ // Check to see if this bundle exists. If not then create it
|
|
|
+ $bundle = db_select('tripal_bundle', 't')
|
|
|
+ ->fields('t')
|
|
|
+ ->condition('type', 'BioData')
|
|
|
+ ->condition('bundle', $bundle_name)
|
|
|
+ ->execute()
|
|
|
+ ->fetchObject();
|
|
|
+
|
|
|
+ if (!$bundle) {
|
|
|
+ // The TripalBundle Entity manages the bundles we have available.
|
|
|
+ // Therefore, we need to add a new entity for each bundle "type".
|
|
|
+ $vals = array(
|
|
|
+ 'label' => $cvterm->name,
|
|
|
+ 'type' => 'BioData',
|
|
|
+ 'bundle' => $bundle_name,
|
|
|
+ 'data' => serialize(array()),
|
|
|
+ 'module' => 'tripal_entities'
|
|
|
+ );
|
|
|
+ $tripal_bundle = new TripalBundle($vals, 'BioData_bundles');
|
|
|
+ $tripal_bundle->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Allow modules to now add fields to the bundle
|
|
|
+ module_invoke_all('add_bundle_fields', 'BioData', $bundle_name, $cvterm);
|
|
|
+
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Implements hook_add_bundle_fields().
|
|
|
+ *
|
|
|
+ * @param $entity_type_name
|
|
|
+ * @param $bundle_name
|
|
|
+ * @param $cvterm
|
|
|
+ */
|
|
|
+function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvterm) {
|
|
|
+
|
|
|
+ // Adds the fields for the base table to the entity.
|
|
|
+ tripal_entities_add_bundle_base_fields($entity_type_name, $bundle_name, $cvterm);
|
|
|
+
|
|
|
+ // 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.
|
|
|
+ tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, 'featureprop');
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Adds the fields for a kv-property table fields
|
|
|
+ *
|
|
|
+ * @param $entity_type_name
|
|
|
+ * @param $bundle_name
|
|
|
+ * @param $kv_table
|
|
|
+ */
|
|
|
+function tripal_entities_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
|
|
|
+ // First add a generic property field so that users can add new proeprty types.
|
|
|
+ $field_name = $kv_table;
|
|
|
+
|
|
|
+ // Initialize the field array.
|
|
|
+ $field_info = array(
|
|
|
+ 'field_type' => 'kvproperty_adder',
|
|
|
+ 'widget_type' => 'tripal_fields_kvproperty_adder_widget',
|
|
|
+ 'field_settings' => array(),
|
|
|
+ 'widget_settings' => array('display_label' => 1),
|
|
|
+ 'description' => '',
|
|
|
+ 'label' => 'Additional Properties',
|
|
|
+ 'is_required' => 0,
|
|
|
+ );
|
|
|
+ tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 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)) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // Add the field to the bundle.
|
|
|
+ tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns a $field_info array for a field based on a databaes column.
|
|
|
+ *
|
|
|
+ */
|
|
|
+function tripal_entities_get_table_column_field_default($table_name, $schema, $column_name) {
|
|
|
+ $details = $schema['fields'][$column_name];
|
|
|
+
|
|
|
+ // Create an array with information about this field.
|
|
|
+ $field_info = array(
|
|
|
+ 'field_type' => '',
|
|
|
+ 'widget_type' => '',
|
|
|
+ 'field_settings' => array(
|
|
|
+ 'chado_table' => $table_name,
|
|
|
+ 'chado_column' => $column_name,
|
|
|
+ ),
|
|
|
+ 'widget_settings' => array('display_label' => 1),
|
|
|
+ 'description' => '',
|
|
|
+ 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
|
|
|
+ 'is_required' => 0,
|
|
|
+ );
|
|
|
+
|
|
|
+ // Alter the field info array depending on the column details.
|
|
|
+ switch($details['type']) {
|
|
|
+ case 'char':
|
|
|
+ $field_info['field_type'] = 'text';
|
|
|
+ $field_info['widget_type'] = 'text_textfield';
|
|
|
+ $field_info['field_settings']['max_length'] = $details['length'];
|
|
|
+ break;
|
|
|
+ case 'varchar':
|
|
|
+ $field_info['field_type'] = 'text';
|
|
|
+ $field_info['widget_type'] = 'text_textfield';
|
|
|
+ $field_info['field_settings']['max_length'] = $details['length'];
|
|
|
+ break;
|
|
|
+ case 'text':
|
|
|
+ $field_info['field_type'] = 'text';
|
|
|
+ $field_info['widget_type'] = 'text_textarea';
|
|
|
+ $field_info['field_settings']['max_length'] = 17179869184;
|
|
|
+ break;
|
|
|
+ case 'blob':
|
|
|
+ // not sure how to support a blob field.
|
|
|
+ continue;
|
|
|
+ break;
|
|
|
+ case 'int':
|
|
|
+ $field_info['field_type'] = 'number_integer';
|
|
|
+ $field_info['widget_type'] = 'number';
|
|
|
+ break;
|
|
|
+ case 'float':
|
|
|
+ $field_info['field_type'] = 'number_float';
|
|
|
+ $field_info['widget_type'] = 'number';
|
|
|
+ $field_info['field_settings']['precision'] = 10;
|
|
|
+ $field_info['field_settings']['scale'] = 2;
|
|
|
+ $field_info['field_settings']['decimal_separator'] = '.';
|
|
|
+ break;
|
|
|
+ case 'numeric':
|
|
|
+ $field_info['field_type'] = 'number_decimal';
|
|
|
+ $field_info['widget_type'] = 'number';
|
|
|
+ break;
|
|
|
+ case 'serial':
|
|
|
+ // Serial fields are most likely not needed as a field.
|
|
|
+ break;
|
|
|
+ case 'boolean':
|
|
|
+ $field_info['field_type'] = 'list_boolean';
|
|
|
+ $field_info['widget_type'] = 'options_onoff';
|
|
|
+ $field_info['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
|
|
|
+ break;
|
|
|
+ case 'datetime':
|
|
|
+ // Use the Drupal Date and Date API to create the field/widget
|
|
|
+ $field_info['field_type'] = 'datetime';
|
|
|
+ $field_info['widget_type'] = 'date_select';
|
|
|
+ $field_info['widget_settings']['increment'] = 1;
|
|
|
+ $field_info['widget_settings']['tz_handling'] = 'none';
|
|
|
+ $field_info['widget_settings']['collapsible'] = TRUE;
|
|
|
+
|
|
|
+ // TODO: Add settings so that the minutes increment by 1.
|
|
|
+ // And turn off the timezone, as the Chado field doesn't support it.
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $field_info;
|
|
|
+}
|
|
|
/**
|
|
|
* Adds a vocabulary and term to the Tripal term usage tables.
|
|
|
*
|