Helper function to format some queries.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 17:16:19 +0000 (18:16 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 17:16:58 +0000 (18:16 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/xdb.php

index 5f200d8..ea728d4 100644 (file)
@@ -140,6 +140,22 @@ class XDB
         return self::_prepare(func_get_args());
     }
 
+    // Produce the SQL statement for setting/unsetting a flag
+    public static function changeFlag($fieldname, $flagname, $state)
+    {
+        if ($state) {
+            return XDB::format($fieldname . ' = CONCAT({?}, \',\', ' . $fieldname . ')', $flagname);
+        } else {
+            return XDB::format($fieldname . ' = REPLACE(' . $fieldname . ', {?}, \'\')', $flagname);
+        }
+    }
+
+    // Produce the SQL statement representing an array
+    public static function formatArray(array $array)
+    {
+        return '(' . implode(', ', array_map(array('XDB', 'escape'), $array)) . ')';
+    }
+
     public static function execute()
     {
         global $globals;