Retrieves ids from a PlSet.
authorStéphane Jacob <sj@m4x.org>
Mon, 20 Dec 2010 20:39:39 +0000 (21:39 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 20 Dec 2010 22:10:25 +0000 (23:10 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/plfilter.php
classes/plset.php

index af8141d..79a9a1b 100644 (file)
@@ -319,6 +319,14 @@ abstract class PlFilter
      */
     public abstract function get($limit = null);
 
+    /** Get ids, selecting only those within a limit
+     * @param $limit The portion of the matching objects to select
+     */
+    public function getIds($limit = null)
+    {
+        return $this->get($limit);
+    }
+
     /** PRIVATE FUNCTIONS
      */
 
index 106c18a..837a327 100644 (file)
@@ -113,30 +113,54 @@ abstract class PlSet
         return $res;
     }
 
-    /** This function returns the values of the set, and sets $count with the
-     * total number of results.
-     * @param $limit A PlLimit for selecting users
-     * @param $orders An optional array of PFO to use before the "default" ones
-     * @return The result of $pf->get();
+    /** Helper function, calls buildFilter with the adequate condition/orders.
+     * @param $orders Additional orders to use before the default ones.
+     * @return A newly created PlFilter.
      */
-    public function &get(PlLimit $limit = null, $orders = array())
+    private function buildFilterHelper($orders = array())
     {
         if (!is_array($orders)) {
             $orders = array($orders);
         }
-
         $orders = array_merge($orders, $this->orders);
 
-        $pf = $this->buildFilter($this->conds, $orders);
+        return $this->buildFilter($this->conds, $orders);
+    }
 
+    /** This function returns the values of the set, and sets $count with the
+     * total number of results.
+     * @param $limit A PlLimit for selecting users
+     * @param $orders An optional array of PFO to use before the "default" ones
+     * @return The result of $pf->get();
+     */
+    public function &get(PlLimit $limit = null, $orders = array())
+    {
         if (is_null($limit)) {
             $limit = new PlLimit(self::DEFAULT_MAX_RES, 0);
         }
-        $it          = $this->getFilterResults($pf, $limit);
+        $pf = $this->buildFilterHelper($orders);
+        $it = $this->getFilterResults($pf, $limit);
         $this->count = $pf->getTotalCount();
         return $it;
     }
 
+    /** This function returns the ids of the set, and sets $count with the
+     * total number of results.
+     * @param $limit A PlLimit for selecting profiles
+     * @param $orders An optional array of PFO to use before the "default" ones
+     * @return The result of $pf->getId();
+     */
+    public function &getIds(PlLimit $limit = null, $orders = array())
+    {
+        if (is_null($limit)) {
+            $limit = new PlLimit(self::DEFAULT_MAX_RES, 0);
+        }
+        $pf = $this->buildFilterHelper($orders);
+        $result = $pf->getIds($limit);
+        $this->count = count($result);
+        return $result;
+    }
+
     /** Return an array containing all pertinent parameters for this page
      * Generated from $_GET, after some cleanup (remove 'n' (plat/al field
      * for the handler path)