]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/CATS.java
add: check if the last valid test is within the last 12 month
[gigi.git] / src / org / cacert / gigi / dbObjects / CATS.java
index cac16694d81a83954b3d12288edbd9d7c36124d7..a353e1684e7ff9bd81c63bf1cd3f5966b8bc7ca1 100644 (file)
@@ -42,6 +42,11 @@ public class CATS {
         }
     }
 
+    /**
+     * The maximal number of months a passed test is considered "recent".
+     */
+    public static final int TEST_MONTHS = 12;
+
     private static HashMap<String, Integer> names = new HashMap<>();
 
     private CATS() {
@@ -89,4 +94,15 @@ public class CATS {
             ps.execute();
         }
     }
+
+    public static boolean isInCatsLimit(int uID, int testID) {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `cats_passed` WHERE `user_id` = ? AND `variant_id` = ? AND`pass_date` > (now() - interval '1 months' * ?)")) {
+            ps.setInt(1, uID);
+            ps.setInt(2, testID);
+            ps.setInt(3, TEST_MONTHS);
+
+            GigiResultSet rs = ps.executeQuery();
+            return rs.next();
+        }
+    }
 }