Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Made this service environment-independent. Now refers to db connection
authorpreecej <preecej@localhost>
Wed, 11 Apr 2012 22:59:50 +0000 (22:59 +0000)
committerpreecej <preecej@localhost>
Wed, 11 Apr 2012 22:59:50 +0000 (22:59 +0000)
string values with generic names.

svn path=/; revision=321

planteome/paw/services/TermSearch_JSON.php [new file with mode: 0644]
planteome/paw/services/dev.TermSearch_JSON.php [deleted file]
planteome/paw/services/test.TermSearch_JSON.php [deleted file]

diff --git a/planteome/paw/services/TermSearch_JSON.php b/planteome/paw/services/TermSearch_JSON.php
new file mode 100644 (file)
index 0000000..5c7ab73
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+// JSON web service for PO terms: autocomplete and search methods
+
+/* require the user as the parameter */
+if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
+
+        $arr_field_names = array('name','acc');
+        $arr_ontologies = array('go','po');
+        
+        /* read the params and/or set our own */
+        $type = isset($_GET['type']) ? $_GET['type'] : autocomplete; // autocomplete is the default
+        
+        // security measures; helps to avoid SQL injection attacks
+        $field = isset($_GET['field']) && in_array($_GET['field'],$arr_field_names)
+            ? $_GET['field']
+            : die('"field" is a required parameter and must match an available data field.');
+            
+        $number_of_terms = isset($_GET['max']) ? intval($_GET['max']) : 10; //10 is the default
+        if ($number_of_terms > 50) { $number_of_terms = 50; } 
+
+        $ont = isset($_GET['ontology']) && in_array(strtolower($_GET['ontology']),$arr_ontologies)
+            ? strtolower($_GET['ontology'])
+            : die('"ontology" is a required parameter and must match an available data field.');
+        
+        $qval = $_GET['qval'];
+        
+        $qval = isset($_GET['qval']) && strlen($_GET['qval']) > 0 
+            ? strtolower($_GET['qval'])
+            : die('Please provide a searchable value');
+
+        $format = strtolower($_GET['format']) != 'json' 
+            ? strtolower($_GET['format']) 
+            : 'json'; //json is the default
+        
+        /* connect to the appropriate db */
+        switch ($ont) {
+            case 'po':
+                $link = mysql_connect($_SERVER['po_host'], $_SERVER['po_user'], $_SERVER['po_pw']) or die('Cannot connect to the DB');
+                mysql_select_db($_SERVER['po_db'],$link) or die('Cannot select the DB');
+
+                $term_types = "'plant_anatomy','plant_growth_and_development_stage'"; 
+                break;
+
+            case 'go':
+                $link = mysql_connect($_SERVER['go_host'], $_SERVER['go_user'], $_SERVER['go_pw']) or die('Cannot connect to the DB');
+                mysql_select_db($_SERVER['go_db'],$link) or die('Cannot select the DB');
+
+                $term_types = "'biological_process','cellular_component','molecular_function'"; 
+                break;
+
+            default:
+                die('Sorry, this ontology type is not available.');
+        }
+        
+        switch ($type) {
+            case 'autocomplete':
+                /* grab the terms from the db */
+                $query = "SELECT t.$field FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.$field LIKE '%$qval%'"
+                    . " AND t.term_type in ($term_types)"
+                    . " AND t.is_obsolete = 0"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY name LIMIT $number_of_terms";
+                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
+            
+                /* create one master array of the records */
+                $terms = array();
+                if(mysql_num_rows($result)) {
+                    while($term = mysql_fetch_assoc($result)) {
+                        $terms[] = array('title'=>$term[$field]);
+                    }
+                }
+
+                /* output in necessary format */
+                if($format == 'json') {
+                    header('Content-type: application/json');
+                    echo json_encode(array('sfautocomplete'=>$terms));
+                }
+                else {
+                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
+                }
+                break;
+
+            case 'term_detail':
+                /* grab the ontology data from the db */
+                $query = "SELECT DISTINCT t.name as 'name', t.acc as 'acc', t.term_type as 'type', d.term_definition as 'definition', d.term_comment as 'comment'"
+                    . " FROM term t"
+                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
+                    . " WHERE t.$field = '$qval'"
+                    . " AND t.term_type in ($term_types)"
+                    . " AND t.is_obsolete = 0"
+                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
+                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
+                    . " ORDER BY t.name LIMIT 1";
+                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
+            
+                /* create one master array of the records */
+                $terms = array();
+                if(mysql_num_rows($result)) {
+                    while($term = mysql_fetch_assoc($result)) {
+                        switch($term['type']) {
+                            case 'plant_anatomy':
+                                $term_type_formal = "Plant Anatomy"; break;
+                            case 'plant_growth_and_development_stage':
+                                $term_type_formal = "Plant Growth and Development Stage"; break;
+                            case 'biological_process':
+                                $term_type_formal = "Biological Process"; break;
+                            case 'cellular_component':
+                                $term_type_formal = "Cellular Component"; break;
+                            case 'molecular_function':
+                                $term_type_formal = "Molecular Function"; break;
+                        }
+                        $terms[] = array(
+                            'name'=>$term['name'],
+                            'id'=>$term['acc'],
+                            'aspect'=>$term_type_formal,
+                            'definition'=>$term['definition'],
+                            'comment'=>$term['comment']);
+                    }
+                }
+                /* output in necessary format */
+                if($format == 'json') {
+                    header('Content-type: application/json');
+                    echo json_encode(array('term_detail_result'=>$terms));
+                }
+                else {
+                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
+                }
+                break;
+            default:
+                die('Sorry, this web service method is not available.');
+        }
+        /* disconnect from the db */
+        @mysql_close($link);
+}
+else { die('Not authorized.'); }
+?>
+
diff --git a/planteome/paw/services/dev.TermSearch_JSON.php b/planteome/paw/services/dev.TermSearch_JSON.php
deleted file mode 100644 (file)
index cffbdaf..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-// JSON web service for PO terms: autocomplete and search methods
-
-/* require the user as the parameter */
-if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
-
-        $arr_field_names = array('name','acc');
-        $arr_ontologies = array('go','po');
-        
-        /* read the params and/or set our own */
-        $type = isset($_GET['type']) ? $_GET['type'] : autocomplete; // autocomplete is the default
-        
-        // security measures; helps to avoid SQL injection attacks
-        $field = isset($_GET['field']) && in_array($_GET['field'],$arr_field_names)
-            ? $_GET['field']
-            : die('"field" is a required parameter and must match an available data field.');
-            
-        $number_of_terms = isset($_GET['max']) ? intval($_GET['max']) : 10; //10 is the default
-        if ($number_of_terms > 50) { $number_of_terms = 50; } 
-
-        $ont = isset($_GET['ontology']) && in_array(strtolower($_GET['ontology']),$arr_ontologies)
-            ? strtolower($_GET['ontology'])
-            : die('"ontology" is a required parameter and must match an available data field.');
-        
-        $qval = $_GET['qval'];
-        
-        $qval = isset($_GET['qval']) && strlen($_GET['qval']) > 0 
-            ? strtolower($_GET['qval'])
-            : die('Please provide a searchable value');
-
-        $format = strtolower($_GET['format']) != 'json' 
-            ? strtolower($_GET['format']) 
-            : 'json'; //json is the default
-        
-        /* connect to the appropriate db */
-        switch ($ont) {
-            case 'po':
-                $link = mysql_connect($_SERVER['dev_po_host'], $_SERVER['dev_po_user'], $_SERVER['dev_po_pw']) or die('Cannot connect to the DB');
-                mysql_select_db($_SERVER['dev_po_db'],$link) or die('Cannot select the DB');
-
-                $term_types = "'plant_anatomy','plant_growth_and_development_stage'"; 
-                break;
-
-            case 'go':
-                $link = mysql_connect($_SERVER['dev_go_host'], $_SERVER['dev_go_user'], $_SERVER['dev_go_pw']) or die('Cannot connect to the DB');
-                mysql_select_db($_SERVER['dev_go_db'],$link) or die('Cannot select the DB');
-
-                $term_types = "'biological_process','cellular_component','molecular_function'"; 
-                break;
-
-            default:
-                die('Sorry, this ontology type is not available.');
-        }
-        
-        switch ($type) {
-            case 'autocomplete':
-                /* grab the terms from the db */
-                $query = "SELECT t.$field FROM term t"
-                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
-                    . " WHERE t.$field LIKE '%$qval%'"
-                    . " AND t.term_type in ($term_types)"
-                    . " AND t.is_obsolete = 0"
-                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
-                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
-                    . " ORDER BY name LIMIT $number_of_terms";
-                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
-            
-                /* create one master array of the records */
-                $terms = array();
-                if(mysql_num_rows($result)) {
-                    while($term = mysql_fetch_assoc($result)) {
-                        $terms[] = array('title'=>$term[$field]);
-                    }
-                }
-
-                /* output in necessary format */
-                if($format == 'json') {
-                    header('Content-type: application/json');
-                    echo json_encode(array('sfautocomplete'=>$terms));
-                }
-                else {
-                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
-                }
-                break;
-
-            case 'term_detail':
-                /* grab the ontology data from the db */
-                $query = "SELECT DISTINCT t.name as 'name', t.acc as 'acc', t.term_type as 'type', d.term_definition as 'definition', d.term_comment as 'comment'"
-                    . " FROM term t"
-                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
-                    . " WHERE t.$field = '$qval'"
-                    . " AND t.term_type in ($term_types)"
-                    . " AND t.is_obsolete = 0"
-                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
-                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
-                    . " ORDER BY t.name LIMIT 1";
-                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
-            
-                /* create one master array of the records */
-                $terms = array();
-                if(mysql_num_rows($result)) {
-                    while($term = mysql_fetch_assoc($result)) {
-                        switch($term['type']) {
-                            case 'plant_anatomy':
-                                $term_type_formal = "Plant Anatomy"; break;
-                            case 'plant_growth_and_development_stage':
-                                $term_type_formal = "Plant Growth and Development Stage"; break;
-                            case 'biological_process':
-                                $term_type_formal = "Biological Process"; break;
-                            case 'cellular_component':
-                                $term_type_formal = "Cellular Component"; break;
-                            case 'molecular_function':
-                                $term_type_formal = "Molecular Function"; break;
-                        }
-                        $terms[] = array(
-                            'name'=>$term['name'],
-                            'id'=>$term['acc'],
-                            'aspect'=>$term_type_formal,
-                            'definition'=>$term['definition'],
-                            'comment'=>$term['comment']);
-                    }
-                }
-                /* output in necessary format */
-                if($format == 'json') {
-                    header('Content-type: application/json');
-                    echo json_encode(array('term_detail_result'=>$terms));
-                }
-                else {
-                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
-                }
-                break;
-            default:
-                die('Sorry, this web service method is not available.');
-        }
-        /* disconnect from the db */
-        @mysql_close($link);
-}
-else { die('Not authorized.'); }
-?>
-
diff --git a/planteome/paw/services/test.TermSearch_JSON.php b/planteome/paw/services/test.TermSearch_JSON.php
deleted file mode 100644 (file)
index f60dcc5..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-// JSON web service for PO terms: autocomplete and search methods
-
-/* require the user as the parameter */
-if(isset($_GET['user']) && ($_GET['user']) == 'paw') {
-
-        $arr_field_names = array('name','acc');
-        $arr_ontologies = array('go','po');
-        
-        /* read the params and/or set our own */
-        $type = isset($_GET['type']) ? $_GET['type'] : autocomplete; // autocomplete is the default
-        
-        // security measures; helps to avoid SQL injection attacks
-        $field = isset($_GET['field']) && in_array($_GET['field'],$arr_field_names)
-            ? $_GET['field']
-            : die('"field" is a required parameter and must match an available data field.');
-            
-        $number_of_terms = isset($_GET['max']) ? intval($_GET['max']) : 10; //10 is the default
-        if ($number_of_terms > 50) { $number_of_terms = 50; } 
-
-        $ont = isset($_GET['ontology']) && in_array(strtolower($_GET['ontology']),$arr_ontologies)
-            ? strtolower($_GET['ontology'])
-            : die('"ontology" is a required parameter and must match an available data field.');
-        
-        $qval = $_GET['qval'];
-        
-        $qval = isset($_GET['qval']) && strlen($_GET['qval']) > 0 
-            ? strtolower($_GET['qval'])
-            : die('Please provide a searchable value');
-
-        $format = strtolower($_GET['format']) != 'json' 
-            ? strtolower($_GET['format']) 
-            : 'json'; //json is the default
-        
-        /* connect to the appropriate db */
-        switch ($ont) {
-            case 'po':
-                $link = mysql_connect($_SERVER['test_po_host'], $_SERVER['test_po_user'], $_SERVER['test_po_pw']) or die('Cannot connect to the DB');
-                mysql_select_db($_SERVER['test_po_db'],$link) or die('Cannot select the DB');
-
-                $term_types = "'plant_anatomy','plant_growth_and_development_stage'"; 
-                break;
-
-            case 'go':
-                $link = mysql_connect($_SERVER['test_go_host'], $_SERVER['test_go_user'], $_SERVER['test_go_pw']) or die('Cannot connect to the DB');
-                mysql_select_db($_SERVER['test_go_db'],$link) or die('Cannot select the DB');
-
-                $term_types = "'biological_process','cellular_component','molecular_function'"; 
-                break;
-
-            default:
-                die('Sorry, this ontology type is not available.');
-        }
-        
-        switch ($type) {
-            case 'autocomplete':
-                /* grab the terms from the db */
-                $query = "SELECT t.$field FROM term t"
-                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
-                    . " WHERE t.$field LIKE '%$qval%'"
-                    . " AND t.term_type in ($term_types)"
-                    . " AND t.is_obsolete = 0"
-                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
-                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
-                    . " ORDER BY name LIMIT $number_of_terms";
-                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
-            
-                /* create one master array of the records */
-                $terms = array();
-                if(mysql_num_rows($result)) {
-                    while($term = mysql_fetch_assoc($result)) {
-                        $terms[] = array('title'=>$term[$field]);
-                    }
-                }
-
-                /* output in necessary format */
-                if($format == 'json') {
-                    header('Content-type: application/json');
-                    echo json_encode(array('sfautocomplete'=>$terms));
-                }
-                else {
-                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
-                }
-                break;
-
-            case 'term_detail':
-                /* grab the ontology data from the db */
-                $query = "SELECT DISTINCT t.name as 'name', t.acc as 'acc', t.term_type as 'type', d.term_definition as 'definition', d.term_comment as 'comment'"
-                    . " FROM term t"
-                    . " LEFT JOIN term_definition d ON d.term_id = t.id"
-                    . " WHERE t.$field = '$qval'"
-                    . " AND t.term_type in ($term_types)"
-                    . " AND t.is_obsolete = 0"
-                    . " AND UCASE(t.name) NOT LIKE 'OBSOLETE%'"
-                    . " AND UCASE(d.term_definition) NOT LIKE 'OBSOLETE%'"
-                    . " ORDER BY t.name LIMIT 1";
-                $result = mysql_query($query,$link) or die('Errant query:  '.$query);
-            
-                /* create one master array of the records */
-                $terms = array();
-                if(mysql_num_rows($result)) {
-                    while($term = mysql_fetch_assoc($result)) {
-                        switch($term['type']) {
-                            case 'plant_anatomy':
-                                $term_type_formal = "Plant Anatomy"; break;
-                            case 'plant_growth_and_development_stage':
-                                $term_type_formal = "Plant Growth and Development Stage"; break;
-                            case 'biological_process':
-                                $term_type_formal = "Biological Process"; break;
-                            case 'cellular_component':
-                                $term_type_formal = "Cellular Component"; break;
-                            case 'molecular_function':
-                                $term_type_formal = "Molecular Function"; break;
-                        }
-                        $terms[] = array(
-                            'name'=>$term['name'],
-                            'id'=>$term['acc'],
-                            'aspect'=>$term_type_formal,
-                            'definition'=>$term['definition'],
-                            'comment'=>$term['comment']);
-                    }
-                }
-                /* output in necessary format */
-                if($format == 'json') {
-                    header('Content-type: application/json');
-                    echo json_encode(array('term_detail_result'=>$terms));
-                }
-                else {
-                    die('Sorry, this request cannot be fulfilled in '.$format.' format.');
-                }
-                break;
-            default:
-                die('Sorry, this web service method is not available.');
-        }
-        /* disconnect from the db */
-        @mysql_close($link);
-}
-else { die('Not authorized.'); }
-?>
-