+
+ /** Build a left join
+ * @param table The name of the table.
+ * @param condition The condition of the jointure
+ */
+ public static function left()
+ {
+ $params = func_get_args();
+ return new PlSqlJoin(self::MODE_LEFT, $params);
+ }
+
+ /** Build a right join
+ * @param table The name of the table.
+ * @param condition The condition of the jointure
+ */
+ public static function right()
+ {
+ $params = func_get_args();
+ return new PlSqlJoin(self::MODE_RIGHT, $params);
+ }
+
+ /** Build a inner join
+ * @param table The name of the table.
+ * @param condition The condition of the jointure
+ */
+ public static function inner()
+ {
+ $params = func_get_args();
+ return new PlSqlJoin(self::MODE_INNER, $params);
+ }
+}
+// }}}
+
+// {{{ class PlFilterOrder
+abstract class PlFilterOrder
+{
+ protected $desc = false;
+ public function __construct($desc = false)
+ {
+ $this->desc = $desc;
+ }
+
+ public function toggleDesc()
+ {
+ $this->desc = !$desc;
+ }
+
+ public function setDescending($desc = true)
+ {
+ $this->desc = $desc;
+ }
+
+ public function buildSort(PlFilter &$pf)
+ {
+ $sel = $this->getSortTokens($pf);
+ if (!is_array($sel)) {
+ $sel = array($sel);
+ }
+ if ($this->desc) {
+ foreach ($sel as $k => $s) {
+ $sel[$k] = $s . ' DESC';
+ }
+ }
+ return $sel;
+ }
+
+ abstract protected function getSortTokens(PlFilter &$pf);
+}
+// }}}
+
+// {{{ class PFO_Random
+class PFO_Random extends PlFilterOrder
+{
+ private $seed = null;
+
+ public function __construct($seed = null, $desc = false)
+ {
+ parent::__construct($desc);
+ $this->seed = $seed;
+ }
+
+ 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()
+ {
+ $children = func_get_args();
+ foreach ($children as &$child) {
+ if (!is_null($child) && ($child instanceof PlFilterCondition)) {
+ $this->addChild($child);
+ }
+ }
+ }
+
+ 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) . ')';
+ }
+ }
+}
+// }}}
+
+// {{{ class PFC_True
+class PFC_True implements PlFilterCondition
+{
+ public function buildCondition(PlFilter &$uf)
+ {
+ return self::COND_TRUE;
+ }
+}
+// }}}
+
+// {{{ class PFC_False
+class PFC_False implements PlFilterCondition
+{
+ public function buildCondition(PlFilter &$uf)
+ {
+ return self::COND_FALSE;
+ }