Add a $page-> function for displaying a message and a "continue" link
[platal.git] / classes / plfilter.php
index 8c65ae7..7771fa4 100644 (file)
@@ -19,6 +19,8 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+__autoload('xdb');
+
 // {{{ class PlLimit
 class PlLimit
 {
@@ -56,8 +58,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 +118,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);
+    }
 }
 // }}}
 
@@ -128,7 +162,7 @@ abstract class PlFilterOrder
 
     public function toggleDesc()
     {
-        $this->desc = !$desc;
+        $this->desc = !$this->desc;
     }
 
     public function setDescending($desc = true)
@@ -212,10 +246,14 @@ abstract class PFC_NChildren implements PlFilterCondition
 
     public function __construct()
     {
-        $children = func_get_args();
-        foreach ($children as &$child) {
-            if (!is_null($child) && ($child instanceof PlFilterCondition)) {
-                $this->addChild($child);
+        $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);
             }
         }
     }
@@ -334,7 +372,7 @@ abstract class PlFilter
      * @param $objects The objects to filter
      * @param $limit The portion of the matching objects to show
      */
-    public abstract function filter(array $objects, PlLimit &$limit);
+    public abstract function filter(array $objects, $limit = null);
 
     public abstract function setCondition(PlFilterCondition &$cond);
 
@@ -345,7 +383,7 @@ abstract class PlFilter
     /** Get objects, selecting only those within a limit
      * @param $limit The portion of the matching objects to select
      */
-    public abstract function get(PlLimit &$limit);
+    public abstract function get($limit = null);
 
     /** PRIVATE FUNCTIONS
      */
@@ -375,4 +413,5 @@ abstract class PlFilter
 }
 // }}}
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>