From: Florent Bruneau Date: Fri, 5 Mar 2010 22:02:16 +0000 (+0100) Subject: API changes on PlSqlJoin in order to simplify its usage. X-Git-Tag: core/1.1.0~63 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=ae3effcca10c409aef7a111cc778b9dca10561b9;p=platal.git API changes on PlSqlJoin in order to simplify its usage. New PlSqlJoin are built using factory functions (PlSqlJoin::left, PlSqlJoin::right, PlSqlJoin::inner). The factories takes 2 arguments: * a table name * a XDB query format and its parameters Example: $join = PlSqlJoin::left('table', 'blah = {?} AND truc = {?}', $param1, $param2); Signed-off-by: Florent Bruneau --- diff --git a/classes/plfilter.php b/classes/plfilter.php index b43880d..05c1edb 100644 --- a/classes/plfilter.php +++ b/classes/plfilter.php @@ -56,8 +56,10 @@ class PlSqlJoin const MODE_RIGHT = 'RIGHT'; const MODE_INNER = 'INNER'; - public function __construct($mode, $table, $condition) + private function __construct($mode, $params) { + $table = array_shift($params); + $condition = call_user_func_array(array('XDB', 'format'), $params); if ($mode != self::MODE_LEFT && $mode != self::MODE_RIGHT && $mode != self::MODE_INNER) { Platal::page()->kill("Join mode error: unknown mode $mode"); return; @@ -114,6 +116,36 @@ class PlSqlJoin } return $str; } + + /** 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); + } } // }}} @@ -375,4 +407,5 @@ abstract class PlFilter } // }}} +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>