Fix SUID.
[platal.git] / classes / plflagset.php
index 474f9d8..b5f30d9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
- * Copyright (C) 2003-2009 Polytechnique.org
+ * Copyright (C) 2003-2010 Polytechnique.org
  * http://opensource.polytechnique.org/
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,7 +21,7 @@
 
 /** class for describing flags
  */
-class PlFlagSet
+class PlFlagSet extends PlAbstractIterable implements XDBFormat
 {
     /** string that holds the PlFlagSet */
     private $values = array();
@@ -39,7 +39,9 @@ class PlFlagSet
         $this->sep = $sep;
         $splitted = explode($sep, $flags);
         foreach ($splitted as $part) {
-            $this->values[$part] = true;
+            if (!empty($part)) {
+                $this->values[$part] = true;
+            }
         }
     }
 
@@ -118,6 +120,28 @@ class PlFlagSet
         }
         return $flags;
     }
+
+
+    /** format for XDB
+     */
+    public function format()
+    {
+        return XDB::escape($this->flags());
+    }
+
+
+    /** Build an iterator for this PlFlagSet.
+     */
+    public function iterate()
+    {
+        $array = array();
+        foreach ($this->values as $key=>$value) {
+            if ($value) {
+                $array[] = $key;
+            }
+        }
+        return PlIteratorUtils::fromArray($array, 1, true);
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: