aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorGravatar Thomas Petazzoni <thomas.petazzoni@bootlin.com>2018-11-01 10:57:49 +0100
committerGravatar Thomas Petazzoni <thomas.petazzoni@bootlin.com>2018-11-01 12:08:51 +0100
commit13ce40e354eaaf62a05b4cdddf4d9a37b0e3ed61 (patch)
treee28fd45f499f5cbf1364a922185fa76124e26149 /web
parenta3b2cc69bc928e3748f6c3280079280e391ad7b0 (diff)
downloadbuildroot-test-13ce40e354eaaf62a05b4cdddf4d9a37b0e3ed61.tar.gz
buildroot-test-13ce40e354eaaf62a05b4cdddf4d9a37b0e3ed61.tar.bz2
web: introduce bab_format_sql_filter() function
This will allow to re-use it in bab_total_results_count(). Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Diffstat (limited to 'web')
-rw-r--r--web/funcs.inc.php50
1 files changed, 28 insertions, 22 deletions
diff --git a/web/funcs.inc.php b/web/funcs.inc.php
index 784b142..14256bb 100644
--- a/web/funcs.inc.php
+++ b/web/funcs.inc.php
@@ -30,6 +30,33 @@ function bab_footer()
echo "</html>\n";
}
+function bab_format_sql_filter($db, $filters)
+{
+ $status_map = array(
+ "OK" => 0,
+ "NOK" => 1,
+ "TIMEOUT" => 2,
+ );
+
+ $sql_filters = implode(' and ', array_map(
+ function ($v, $k) use ($db, $status_map) {
+ if ($k == "reason")
+ return sprintf("%s like %s", $k, $db->quote_smart($v));
+ else if ($k == "status")
+ return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v]));
+ else
+ return sprintf("%s=%s", $k, $db->quote_smart($v));
+ },
+ $filters,
+ array_keys($filters)
+ ));
+
+ if (count($filters))
+ return "where " . $sql_filters;
+ else
+ return "";
+}
+
/*
* Returns the total number of results.
*/
@@ -47,12 +74,6 @@ function bab_total_results_count()
return $ret[0];
}
-$status_map = array(
- "OK" => 0,
- "NOK" => 1,
- "TIMEOUT" => 2,
-);
-
/*
* Returns an array containing the build results starting from $start,
* and limited to $count items. The items starting with $start=0 are
@@ -63,22 +84,7 @@ function bab_get_results($start=0, $count=100, $filters = array())
global $status_map;
$db = new db();
- $sql_filters = implode(' and ', array_map(
- function ($v, $k) use ($db, $status_map) {
- if ($k == "reason")
- return sprintf("%s like %s", $k, $db->quote_smart($v));
- else if ($k == "status")
- return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v]));
- else
- return sprintf("%s=%s", $k, $db->quote_smart($v));
- },
- $filters,
- array_keys($filters)
- ));
-
- if (count($filters))
- $condition = "where " . $sql_filters;
-
+ $condition = bab_format_sql_filter($db, $filters);
$sql = "select * from results $condition order by builddate desc limit $start, $count;";
$ret = $db->query($sql);
if ($ret == FALSE) {