Ver código fonte

Fixed publication properties so they are more convenient, and fixed some fields

Stephen Ficklin 7 anos atrás
pai
commit
d5038d1901

+ 32 - 16
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -302,7 +302,8 @@ function tripal_autocomplete_pub($string = '') {
   ";
   $pubs = chado_query($sql, array(':str' => $string . '%'));
   while ($pub = $pubs->fetchObject()) {
-    $items[$pub->uniquename] = $pub->uniquename;
+    $val = $pub->title  . " [id:" . $pub->pub_id . "]";
+    $items[$val] = $pub->title;
   }
 
   drupal_json_output($items);
@@ -1025,21 +1026,6 @@ function tripal_get_minimal_pub_info($pub) {
   $pub = chado_expand_var($pub, 'field', 'pub.title');
   $pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
 
-  // get the citation
-  $values = array(
-    'pub_id' => $pub->pub_id,
-    'type_id' => array(
-      'name' => 'Citation',
-    ),
-  );
-  $options = array(
-    'include_fk' => array(
-    ),
-  );
-  $citation = chado_generate_var('pubprop', $values, $options);
-  $citation = chado_expand_var($citation, 'field', 'pubprop.value');
-  $citation = $citation->value;
-
   // get the abstract
   $values = array(
     'pub_id' => $pub->pub_id,
@@ -1121,6 +1107,36 @@ function tripal_get_minimal_pub_info($pub) {
     $dbxrefs[] = $pub_dbxref->dbxref_id->db_id->name . ':' . $pub_dbxref->dbxref_id->accession;
   }
 
+  // get the citation
+  $values = array(
+    'pub_id' => $pub->pub_id,
+    'type_id' => array(
+      'name' => 'Citation',
+    ),
+  );
+  $options = array(
+    'include_fk' => array(
+    ),
+  );
+  $citation = chado_generate_var('pubprop', $values, $options);
+  if ($citation) {
+    $citation = chado_expand_var($citation, 'field', 'pubprop.value');
+    $citation = $citation->value;
+  }
+  else {
+    $pub_info = array(
+      'Title' => $pub->title,
+      'Publication Type' => $pub->type_id->name,
+      'Authors' => $authors_list,
+      'Series Name' => $pub->series_name,
+      'Volume' => $pub->volume,
+      'Issue' => $pub->issue,
+      'Pages' => $pub->pages,
+      'Publication Date' => $pub->pyear,
+    );
+    $citation = tripal_pub_create_citation($pub_info);
+  }
+
   return array(
     'TPUB:0000039' => $pub->title,
     'TPUB:0000003' => $citation,

+ 2 - 0
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop.inc

@@ -41,6 +41,8 @@ class chado_linker__prop extends ChadoField {
     'chado_column' => '',
     // The base table.
     'base_table' => '',
+    // The number of default rows to show. The default is 1.
+    'rows' => 1,
   );
 
   // The default widget for this field.

+ 3 - 1
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc

@@ -19,6 +19,7 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     $base_table = $this->instance['settings']['base_table'];
     $field_table = $this->instance['settings']['chado_table'];
     $chado_column = $this->instance['settings']['chado_column'];
+    $rows = array_key_exists('rows', $this->instance['settings']) ? $this->instance['settings']['rows'] : 1;
     $instance = $this->instance;
 
     // Get the name of the pkey field for this property table and the name
@@ -94,7 +95,8 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
       '#default_value' => $value,
       '#title' => $instance['label'],
       '#description' => $instance['description'],
-      '#rows' => 1,
+      '#rows' => $rows,
+      '#required' => $instance['required'],
     );
     $widget['chado-' . $field_table . '__type_id'] = array(
       '#type' => 'hidden',

+ 0 - 1
tripal_chado/includes/TripalFields/schema__additional_type/schema__additional_type.inc

@@ -71,7 +71,6 @@ class schema__additional_type extends ChadoField {
    * @see ChadoField::query()
    */
   public function queryOrder($query, $order) {
-    dpm('hi');
     $alias = $this->field['field_name'];
 
     $field_name = $this->field['field_name'];

+ 0 - 2
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -94,7 +94,6 @@ class schema__publication extends ChadoField {
       'chado-' . $field_table . '__' . $pkey => '',
       'chado-' . $field_table . '__' . $fkey_lcolumn => '',
       'chado-' . $field_table . '__' . 'pub_id' => '',
-      'uniquename' => '',
     );
 
     $linker_table = $base_table . '_pub';
@@ -112,7 +111,6 @@ class schema__publication extends ChadoField {
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $linker->$pkey;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $fkey_lcolumn] = $linker->$fkey_lcolumn->$fkey_lcolumn;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . 'pub_id'] = $pub->pub_id;
-        $entity->{$field_name}['und'][$i]['uniquename'] =  $pub->uniquename;
 
         if (property_exists($pub, 'entity_id')) {
           $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $pub->entity_id;

+ 37 - 31
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -25,15 +25,28 @@ class schema__publication_widget extends ChadoFieldWidget {
     $fkey = $fkeys[0];
 
     // Get the field defaults.
-    $fkey_value = (array_key_exists('#entity', $element) and is_object($element['#entity'])) ? $element['#entity']->chado_record_id : NULL;
+    $pkey_val = '';
+    $fkey_value = '';
     $pub_id = '';
-    $uname = '';
+    $title = '';
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
+      $pkey_val =  tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $pkey, $pkey_val);
+      $fkey_value = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $fkey, $fkey_value);
       $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
-      $uname = tripal_get_field_item_keyval($items, $delta, 'uniquename', $uname);
+      if ($pub_id) {
+        $pub = tripal_get_publication(array('pub_id' => $pub_id));
+        $title =  $pub->title . ' [id:' . $pub->pub_id . ']';
+      }
+    }
+
+    // Check $form_state['values'] to see if an AJAX call set the values.
+    if (array_key_exists('values', $form_state) and
+        array_key_exists($field_name, $form_state['values'])) {
+      $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
+      $pub_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
     }
 
     $schema = chado_get_schema('pub');
@@ -50,7 +63,7 @@ class schema__publication_widget extends ChadoFieldWidget {
 
     $widget['chado-' . $table_name . '__' . $pkey] = array(
       '#type' => 'value',
-      '#default_value' => '',
+      '#default_value' => $pkey_val,
     );
     $widget['chado-' . $table_name . '__' . $fkey] = array(
       '#type' => 'value',
@@ -61,17 +74,11 @@ class schema__publication_widget extends ChadoFieldWidget {
       '#default_value' => $pub_id,
     );
 
-    $widget['uniquename'] = array(
+    $widget['pub_title'] = array(
       '#type' => 'textfield',
       '#title' => t('Publication'),
-      '#default_value' => $uname,
+      '#default_value' => $title,
       '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/pub',
-      '#ajax' => array(
-        'callback' => "schema__publication_widget_form_ajax_callback",
-        'wrapper' => "$table_name-$delta",
-        'effect' => 'fade',
-        'method' => 'replace'
-      ),
       '#maxlength' => 100000,
     );
   }
@@ -81,7 +88,7 @@ class schema__publication_widget extends ChadoFieldWidget {
    *
    * @see TripalFieldWidget::submit()
    */
-  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
     // Get the FK column that links to the base table.
     $table_name = $this->instance['settings']['chado_table'];
     $base_table = $this->instance['settings']['base_table'];
@@ -92,31 +99,30 @@ class schema__publication_widget extends ChadoFieldWidget {
     $field_name = $this->field['field_name'];
 
     // Get the field values.
-    $fkey_value = isset($form_state['values'][$field_name][$langcode][$delta]['value']) ? $form_state['values'][$field_name][$langcode][$delta]['value'] : '';
-    $pub_id = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] : '';
-    $uname = isset($form_state['values'][$field_name][$langcode][$delta]['uniquename']) ? $form_state['values'][$field_name][$langcode][$delta]['uniquename'] : '';
+    $fkey_value = $form_state['values'][$field_name]['und'][$delta]['value'];
+    $pub_id = $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'];
+    $title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
 
-    // If the user provided a uniquename then we want to set the foreign key
+    // If the user provided a pub_title then we want to set the foreign key
     // value to be the chado_record_id
-    if ($uname and !$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => $uname));
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+    if ($title) {
+      $matches = array();
+      if (preg_match('/^.*\[id:(\d+)]$/', $title, $matches)) {
+        $pub_id = $matches[1];
+        $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
+        $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+        $form_state['values'][$field_name]['und'][$delta]['value'] = $pub->pub_id;
+      }
     }
 
     // In the widgetFrom function we automatically add the foreign key
     // record.  But if the user did not provide a publication we want to take
     // it out so that the Chado field_storage infrastructure won't try to
     // write a record.
-    if (!$uname and !$pub_id) {
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-    }
-
-    // If the user removed the publication from the pub_uniquename field
-    // then we want to clear out the rest of the hidden values.
-    // Leave the primary key so the record can be deleted.
-    if (!$uname and $pub_id) {
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = '';
+    if (!$title) {
+      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+      $form_state['values'][$field_name]['und'][$delta]['chado-' . $table_name . '__pub_id'] = '';
     }
   }
 
@@ -128,7 +134,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     $layout = "
       <div class=\"pub-widget\">
         <div class=\"pub-widget-item\">" .
-          drupal_render($element['uniquename']) . "
+          drupal_render($element['pub_title']) . "
         </div>
       </div>
     ";

+ 15 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -1810,6 +1810,21 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
              ),
            ),
          );
+
+         // Make some customizations to some fields
+         if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
+           $info[$field_name]['required'] = TRUE;
+           $info[$field_name]['description'] = t('All publications must have a unique citation.
+            Please enter the full citation for this publication.  For PubMed style citations list
+            the last name of the author followed by initials. Each author should be separated by a comma. Next comes
+            the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
+            Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
+              suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
+           $info[$field_name]['settings']['rows'] = 3;
+         }
+         if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
+           $info[$field_name]['settings']['rows'] = 5;
+         }
        }
      }
    }

+ 16 - 0
tripal_chado/tripal_chado.install

@@ -1185,4 +1185,20 @@ function tripal_chado_update_7312() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not perform update: '. $error);
   }
+}
+
+/**
+ * Run the cvtermpath for the Tripal Pub and Contact ontologies.
+ */
+function tripal_chado_update_7313() {
+  try {
+    $cv = tripal_get_cv(array('name' => 'tripal_pub'));
+    tripal_update_cvtermpath($cv->cv_id);
+    $cv = tripal_get_cv(array('name' => 'tripal_contact'));
+    tripal_update_cvtermpath($cv->cv_id);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }

+ 0 - 1
tripal_ds/tripal_ds.install

@@ -79,7 +79,6 @@ function tripal_ds_disable(){
   $output .= '</ul>';
   if(!empty($entities_with_tripal_panes)){
     drupal_set_message($output, 'warning');
-
   }
 }