mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
aurjson: add result count to JSON result
We already ask for the result count, but only use it as a basis for testing query success or failure. Add the value to the JSON reply. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
9415e078a3
commit
168a51431b
1 changed files with 6 additions and 5 deletions
|
@ -103,7 +103,7 @@ class AurJSON {
|
||||||
private function json_error($msg) {
|
private function json_error($msg) {
|
||||||
// set content type header to app/json
|
// set content type header to app/json
|
||||||
header('content-type: application/json');
|
header('content-type: application/json');
|
||||||
return $this->json_results('error', $msg);
|
return $this->json_results('error', 0, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,8 +112,8 @@ class AurJSON {
|
||||||
* @param $data The result data to return
|
* @param $data The result data to return
|
||||||
* @return mixed A json formatted result response.
|
* @return mixed A json formatted result response.
|
||||||
**/
|
**/
|
||||||
private function json_results($type, $data) {
|
private function json_results($type, $count, $data) {
|
||||||
return json_encode( array('type' => $type, 'results' => $data) );
|
return json_encode( array('type' => $type, 'resultcount' => $count, 'results' => $data) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private function process_query($type, $where_condition) {
|
private function process_query($type, $where_condition) {
|
||||||
|
@ -124,7 +124,8 @@ class AurJSON {
|
||||||
"WHERE ${where_condition}";
|
"WHERE ${where_condition}";
|
||||||
$result = db_query($query, $this->dbh);
|
$result = db_query($query, $this->dbh);
|
||||||
|
|
||||||
if ( $result && (mysql_num_rows($result) > 0) ) {
|
$resultcount = mysql_num_rows($result);
|
||||||
|
if ( $result && $resultcount > 0 ) {
|
||||||
$search_data = array();
|
$search_data = array();
|
||||||
while ( $row = mysql_fetch_assoc($result) ) {
|
while ( $row = mysql_fetch_assoc($result) ) {
|
||||||
$name = $row['Name'];
|
$name = $row['Name'];
|
||||||
|
@ -148,7 +149,7 @@ class AurJSON {
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_free_result($result);
|
mysql_free_result($result);
|
||||||
return $this->json_results($type, $search_data);
|
return $this->json_results($type, $resultcount, $search_data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $this->json_error('No results found');
|
return $this->json_error('No results found');
|
||||||
|
|
Loading…
Add table
Reference in a new issue