Add PlImage, short wrapper to send images.
[platal.git] / classes / plfilter.php
index ed0e039..b43880d 100644 (file)
@@ -19,6 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
+// {{{ class PlLimit
 class PlLimit
 {
     private $count = null;
@@ -32,7 +33,7 @@ class PlLimit
 
     public function getSql()
     {
-        if (!is_null($this->count)) {
+        if (!is_null($this->count) && $this->count != 0) {
             if (!is_null($this->from) && $this->from != 0) {
                 return XDB::format('LIMIT {?}, {?}', (int)$this->from, (int)$this->count);
             } else {
@@ -42,7 +43,9 @@ class PlLimit
         return '';
     }
 }
+// }}}
 
+// {{{ class PlSqlJoin
 class PlSqlJoin
 {
     private $mode;
@@ -56,7 +59,7 @@ class PlSqlJoin
     public function __construct($mode, $table, $condition)
     {
         if ($mode != self::MODE_LEFT && $mode != self::MODE_RIGHT && $mode != self::MODE_INNER) {
-            Platal::page()->kill("Join mode error : unknown mode $mode");
+            Platal::page()->kill("Join mode error: unknown mode $mode");
             return;
         }
         $this->mode = $mode;
@@ -98,7 +101,7 @@ class PlSqlJoin
     {
         $str = '';
         foreach ($joins as $key => $join) {
-            if (! ($join instanceof PlSqlJoin)) {
+            if (!($join instanceof PlSqlJoin)) {
                 Platal::page()->kill("Error: not a join: $join");
             }
             $mode  = $join->mode();
@@ -112,7 +115,9 @@ class PlSqlJoin
         return $str;
     }
 }
+// }}}
 
+// {{{ class PlFilterOrder
 abstract class PlFilterOrder
 {
     protected $desc = false;
@@ -145,8 +150,31 @@ abstract class PlFilterOrder
         return $sel;
     }
 
-//    abstract protected function getSortTokens(&$pf);
+    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
@@ -299,14 +327,14 @@ class PFC_Or extends PFC_NChildren
 }
 // }}}
 
-
+// {{{ class PlFilter
 abstract class PlFilter
 {
     /** Filters objects matching the 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);
 
@@ -317,7 +345,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
      */
@@ -345,5 +373,6 @@ abstract class PlFilter
     }
 
 }
+// }}}
 
 ?>