From 2df3616f8835e248650e0dd9cf407f80c72d43e8 Mon Sep 17 00:00:00 2001 From: preecej Date: Wed, 7 Sep 2011 22:27:22 +0000 Subject: [PATCH] Making this file env-specific svn path=/; revision=177 --- ...earch_JSON.php => dev.TermSearch_JSON.php} | 0 .../services/test.TermSearch_JSON.php | 106 ++++++++++++++++++ 2 files changed, 106 insertions(+) rename preecej/semantic_wiki/services/{TermSearch_JSON.php => dev.TermSearch_JSON.php} (100%) create mode 100644 preecej/semantic_wiki/services/test.TermSearch_JSON.php diff --git a/preecej/semantic_wiki/services/TermSearch_JSON.php b/preecej/semantic_wiki/services/dev.TermSearch_JSON.php similarity index 100% rename from preecej/semantic_wiki/services/TermSearch_JSON.php rename to preecej/semantic_wiki/services/dev.TermSearch_JSON.php diff --git a/preecej/semantic_wiki/services/test.TermSearch_JSON.php b/preecej/semantic_wiki/services/test.TermSearch_JSON.php new file mode 100644 index 0000000..2bb7d9b --- /dev/null +++ b/preecej/semantic_wiki/services/test.TermSearch_JSON.php @@ -0,0 +1,106 @@ + 50) { $number_of_terms = 50; } + + $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 db */ + $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'); + + 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 ('plant_anatomy','plant_growth_and_development_stage')" + . " 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.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.name = '$qval'" + . " AND t.term_type in ('plant_anatomy','plant_growth_and_development_stage')" + . " 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)) { + $terms[] = array( + 'id'=>$term['acc'], + 'aspect'=>$term['type'] == "plant_anatomy" ? "Plant Anatomy" : "Plant Growth and Development Stage", + 'definition'=>$term['definition'], + 'comment'=>$term['comment']); + } + } + /* output in necessary format */ + if($format == 'json') { + header('Content-type: application/json'); + echo json_encode(array('PO_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.'); } +?> + -- 2.34.1