소스 검색

Added stock and project autocomplete.

Lacey Sanderson 6 년 전
부모
커밋
fc8f2fde23
3개의 변경된 파일98개의 추가작업 그리고 0개의 파일을 삭제
  1. 48 0
      tripal_chado/api/modules/tripal_chado.project.api.inc
  2. 34 0
      tripal_chado/api/modules/tripal_chado.stock.api.inc
  3. 16 0
      tripal_chado/tripal_chado.module

+ 48 - 0
tripal_chado/api/modules/tripal_chado.project.api.inc

@@ -0,0 +1,48 @@
+<?php
+/**
+ * @file
+ * Provides API functions specificially for managing project
+ * records in Chado.
+ */
+
+/**
+ * @defgroup tripal_project_api Chado Project
+ * @ingroup tripal_chado_api
+ * @{
+ * Provides API functions specificially for managing project
+ * records in Chado.  The project table of Chado is used for storing a variety
+ * of data types besides just projects from a project collection.  Examples of
+ * other records commonly stored in the project table are germplasm and
+ * individuals from a breeding population.
+ * @}
+ */
+
+/**
+ * Used for autocomplete in forms for identifying projects 
+ *
+ * @param $string
+ *   The string to search for.
+ *    
+ * @return
+ *   A json array of terms that begin with the provided string.
+ *    
+ * @ingroup tripal_project_api
+ */     
+function chado_autocomplete_project($string = '') {
+  $items = array();
+  $sql = "
+    SELECT
+      B.project_id as id, B.name
+    FROM {project} B
+    WHERE lower(B.name) like lower(:str)
+    ORDER by B.name
+    LIMIT 25 OFFSET 0
+  "; 
+  $records = chado_query($sql, array(':str' => $string . '%'));
+  while ($r = $records->fetchObject()) {
+    $key = "$r->name [id: $r->id]";
+    $items[$key] = "$r->name";
+  }
+  
+  drupal_json_output($items);
+}

+ 34 - 0
tripal_chado/api/modules/tripal_chado.stock.api.inc

@@ -17,6 +17,40 @@
  * @}
  */
 
+/**
+ * Used for autocomplete in forms for identifying stocks
+ *
+ * @param $string
+ *   The string to search for.
+ *
+ * @return
+ *   A json array of terms that begin with the provided string.
+ *
+ * @ingroup tripal_stock_api
+ */
+function chado_autocomplete_stock($string = '') {
+  $items = array();
+  $sql = "
+    SELECT
+      B.stock_id as id, B.uniquename, B.name,
+      O.genus, O,species,
+      CVT.name as type
+    FROM {stock} B
+      INNER JOIN {organism} O ON O.organism_id = B.organism_id
+      INNER JOIN {cvterm} CVT ON CVT.cvterm_id = B.type_id
+    WHERE lower(B.uniquename) like lower(:str) OR lower(B.name) like lower(:str)
+    ORDER by B.name
+    LIMIT 25 OFFSET 0
+  ";
+  $records = chado_query($sql, array(':str' => $string . '%'));
+  while ($r = $records->fetchObject()) {
+    $key = "$r->name [id: $r->id]";
+    $items[$key] = "$r->name ($r->uniquename, $r->type, $r->genus $r->species)";
+  }
+
+  drupal_json_output($items);
+}
+
 /**
  * Retrieves a chado stock variable
  *

+ 16 - 0
tripal_chado/tripal_chado.module

@@ -571,6 +571,22 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_CALLBACK,
   );
+  $items['admin/tripal/storage/chado/auto_name/stock/%'] = array(
+    'page callback' => 'chado_autocomplete_stock',
+    'page arguments' => array(6),
+    'access arguments' => array('access content'),
+    'file' => 'api/modules/tripal_chado.stock.api.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/tripal/storage/chado/auto_name/project/%'] = array(
+    'page callback' => 'chado_autocomplete_project',
+    'page arguments' => array(6),
+    'access arguments' => array('access content'),
+    'file' => 'api/modules/tripal_chado.project.api.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
 
   //////////////////////////////////////////////////////////////////////////////
   //                          Controlled Vocabularies