Prevents a file_get_contents warning when retrieving sql errors.
[platal.git] / classes / xdb.php
index 13c4be5..ea728d4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -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;