Browse Source

Added contact autocomplete API function

Stephen Ficklin 10 years ago
parent
commit
1eae519a9e

+ 28 - 0
tripal_contact/api/tripal_contact.api.inc

@@ -110,3 +110,31 @@ function tripal_insert_contact($values) {
   }
   return $contact;
 }
+
+
+/**
+ * This function is intended to be used in autocomplete forms for contacts.
+ *
+ * @param $text
+ *   The string to search for
+ *
+ * @return
+ *   A json array of terms that begin with the provided string
+ *
+ * @ingroup tripal_organism_api
+ */
+function tripal_autocomplete_contact($text) {
+  $matches = array();
+
+  $sql = "SELECT * FROM {contact} WHERE lower(new) like lower(:name) ";
+  $args = array();
+  $args[':name'] = $name . '%';
+  $sql .= "ORDER BY name ";
+  $sql .= "LIMIT 25 OFFSET 0 ";
+  $results = chado_query($sql, $args);
+  $items = array();
+  foreach ($results as $contact) {
+    $items[$contact->contact_id] = $contact->name;
+  }
+  drupal_json_output($items);
+}

+ 7 - 0
tripal_contact/tripal_contact.module

@@ -101,6 +101,13 @@ function tripal_contact_menu() {
     'file path' => drupal_get_path('module', 'tripal_core'),
     'weight' => 3
   );
+
+  $items['admin/tripal/chado/tripal_contact/contact/auto_name/%'] = array(
+    'page callback' => 'tripal_autocomplete_contact',
+    'page arguments' => array(6),
+    'access arguments' => array('administer tripal contact'),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 

+ 2 - 6
tripal_core/api/tripal_core.chado_nodes.api.inc

@@ -925,11 +925,7 @@ function chado_node_sync_records($base_table, $max_sync = FALSE,
         ->execute()
         ->fetchObject();
 
-      if (!empty($result)) {
-        //print " Previously Sync'd";
-      }
-      else {
-
+      if (empty($result)) {
         // Create generic new node
         $new_node = new stdClass();
         $new_node->type = $node_type;
@@ -956,7 +952,7 @@ function chado_node_sync_records($base_table, $max_sync = FALSE,
           //print " Node Created (nid=".$node->nid.")";
         }
         else {
-          watchdog('trp-fsync', "Failed to insert $base_table: %title", array('%title' => $new_node->title), WATCHDOG_ERROR);
+          throw new Exception(t("Failed to insert $base_table: %title", array('%title' => $new_node->title)));
         }
       }
       $i++;

+ 22 - 23
tripal_organism/tripal_organism.module

@@ -41,13 +41,13 @@ function tripal_organism_menu() {
   );
 
   $items['admin/tripal/chado/tripal_organism/sync'] = array(
-      'title' => ' Sync',
-      'description' => 'Create pages on this site for organisms stored in Chado',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('chado_node_sync_form', 'tripal_organism', 'chado_organism'),
-      'access arguments' => array('administer tripal organism'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 1
+    'title' => ' Sync',
+    'description' => 'Create pages on this site for organisms stored in Chado',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('chado_node_sync_form', 'tripal_organism', 'chado_organism'),
+    'access arguments' => array('administer tripal organism'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 1
   );
   $items['admin/tripal/chado/tripal_organism/delete'] = array(
     'title' => ' Delete',
@@ -72,22 +72,22 @@ function tripal_organism_menu() {
     'weight' => 3
   );
   $items['admin/tripal/chado/tripal_organism/configuration'] = array(
-      'title' => 'Settings',
-      'description' => 'Manage integration of Chado organisms including associated features',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_organism_admin'),
-      'access arguments' => array('administer tripal organism'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 5
+    'title' => 'Settings',
+    'description' => 'Manage integration of Chado organisms including associated features',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_organism_admin'),
+    'access arguments' => array('administer tripal organism'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 5
   );
   $items['admin/tripal/chado/tripal_organism/help'] = array(
-      'title' => 'Help',
-      'description' => "A description of the Tripal Organism module including a short description of it's usage.",
-      'page callback' => 'theme',
-      'page arguments' => array('tripal_organism_help'),
-      'access arguments' => array('administer tripal organism'),
-      'type' => MENU_LOCAL_TASK,
-      'weight' => 10
+    'title' => 'Help',
+    'description' => "A description of the Tripal Organism module including a short description of it's usage.",
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_organism_help'),
+    'access arguments' => array('administer tripal organism'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10
   );
   $items['admin/tripal/chado/tripal_organism/views/organisms/enable'] = array(
     'title' => 'Enable Organism Administrative View',
@@ -99,11 +99,10 @@ function tripal_organism_menu() {
   $items['admin/tripal/chado/tripal_organism/organism/auto_name/%'] = array(
     'page callback' => 'tripal_autocomplete_organism',
     'page arguments' => array(6),
-    'access arguments' => array('administer tripal phylotree'),
+    'access arguments' => array('administer tripal organism'),
     'type' => MENU_CALLBACK,
   );
 
-
   return $items;
 }