API changes on PlSqlJoin in order to simplify its usage.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 5 Mar 2010 22:02:16 +0000 (23:02 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 5 Mar 2010 22:05:46 +0000 (23:05 +0100)
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 <florent.bruneau@polytechnique.org>
classes/plfilter.php

index b43880d..05c1edb 100644 (file)
@@ -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:
 ?>