+ protected function getSortTokens(PlFilter &$pf)
+ {
+ if ($this->seed == null) {
+ return 'RAND()';
+ } else {
+ return XDB::format('RAND({?})', $this->seed);
+ }
+ }
+}
+// }}}
+
+// {{{ interface PlFilterCondition
+interface PlFilterCondition
+{
+ const COND_TRUE = 'TRUE';
+ const COND_FALSE = 'FALSE';
+
+ public function buildCondition(PlFilter &$pf);
+}
+// }}}
+
+// {{{ class PFC_OneChild
+abstract class PFC_OneChild implements PlFilterCondition
+{
+ protected $child;
+
+ public function __construct(&$child = null)
+ {
+ if (!is_null($child) && ($child instanceof PlFilterCondition)) {
+ $this->setChild($child);
+ }
+ }
+
+ public function setChild(PlFilterCondition &$cond)
+ {
+ $this->child =& $cond;
+ }
+}
+// }}}
+
+// {{{ class PFC_NChildren
+abstract class PFC_NChildren implements PlFilterCondition
+{
+ protected $children = array();
+
+ public function __construct()
+ {
+ $this->addChildren(pl_flatten(func_get_args()));
+ }
+
+ public function addChildren(array $conds)
+ {
+ foreach ($conds as &$cond) {
+ if (!is_null($cond) && ($cond instanceof PlFilterCondition)) {
+ $this->addChild($cond);
+ }
+ }
+ }
+
+ public function addChild(PlFilterCondition &$cond)
+ {
+ $this->children[] =& $cond;
+ }
+
+ protected function catConds(array $cond, $op, $fallback)
+ {
+ if (count($cond) == 0) {
+ return $fallback;
+ } else if (count($cond) == 1) {
+ return $cond[0];
+ } else {
+ return '(' . implode(') ' . $op . ' (', $cond) . ')';
+ }
+ }
+}
+// }}}