X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplflagset.php;h=b5f30d93cfc350fbb9ad59d4eccd5f43b044f9d2;hb=988a0ceddebb96949ca74e62129d9b3dbe2450c3;hp=1971751ce368fe3d31b6187713abd3dd02fb0f92;hpb=113f6de8c1546c1d1caf6e6b48f5e10ea85fd211;p=platal.git diff --git a/classes/plflagset.php b/classes/plflagset.php index 1971751..b5f30d9 100644 --- a/classes/plflagset.php +++ b/classes/plflagset.php @@ -1,6 +1,6 @@ sep = $sep; $splitted = explode($sep, $flags); foreach ($splitted as $part) { - $this->values[$part] = true; + if (!empty($part)) { + $this->values[$part] = true; + } } } /** add flag - * @param $flag XXX + * @param $flag name of the flag + * @param $cond if true, add the flag (default is true), else, ignore. * @return VOID */ - public function addFlag($flag) + public function addFlag($flag, $cond = true) { - if (empty($flag)) { + if (empty($flag) || !$cond) { return; } $this->values[$flag] = true; @@ -117,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: