]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apigrouplistall.php
Document messages for which clarification was requested.
[quix0rs-gnu-social.git] / actions / apigrouplistall.php
index ef96a08bdd591f987e1b7a5ee3b7f9d6b75b41a1..bd05fa3ea880712a1c1061af5d7039d0730bbbd4 100644 (file)
@@ -21,6 +21,9 @@
  *
  * @category  API
  * @package   StatusNet
+ * @author    Craig Andrews <candrews@integralblue.com>
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Jeffery To <jeffery.to@gmail.com>
  * @author    Zach Copley <zach@status.net>
  * @copyright 2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -31,19 +34,22 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/api.php';
+require_once INSTALLDIR . '/lib/apiprivateauth.php';
 
 /**
  * Returns of the lastest 20 groups for the site
  *
  * @category API
  * @package  StatusNet
+ * @author   Craig Andrews <candrews@integralblue.com>
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Jeffery To <jeffery.to@gmail.com>
  * @author   Zach Copley <zach@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
 
-class ApiGroupListAllAction extends ApiAction
+class ApiGroupListAllAction extends ApiPrivateAuthAction
 {
     var $groups   = null;
 
@@ -60,7 +66,7 @@ class ApiGroupListAllAction extends ApiAction
     {
         parent::prepare($args);
 
-        $this->user   = $this->getTargetUser($id);
+        $this->user   = $this->getTargetUser(null);
         $this->groups = $this->getGroups();
 
         return true;
@@ -81,8 +87,9 @@ class ApiGroupListAllAction extends ApiAction
         parent::handle($args);
 
         $sitename   = common_config('site', 'name');
+        // TRANS: Message is used as a title. %s is a site name.
         $title      = sprintf(_("%s groups"), $sitename);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Groups";
         $link       = common_local_url('groups');
         $subtitle   = sprintf(_("groups on %s"), $sitename);
@@ -111,7 +118,7 @@ class ApiGroupListAllAction extends ApiAction
             break;
         default:
             $this->clientError(
-                _('API method not found!'),
+                _('API method not found.'),
                 404,
                 $this->format
             );
@@ -128,14 +135,21 @@ class ApiGroupListAllAction extends ApiAction
 
     function getGroups()
     {
-        $groups = array();
-
-        // XXX: Use the $page, $count, $max_id, $since_id, and $since parameters
-
+        $qry = 'SELECT user_group.* '.
+          'from user_group join local_group on user_group.id = local_group.group_id '.
+          'order by created desc ';
+        $offset = intval($this->page - 1) * intval($this->count);
+        $limit = intval($this->count);
+        if (common_config('db', 'type') == 'pgsql') {
+            $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+        } else {
+            $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+        }
         $group = new User_group();
-        $group->orderBy('created DESC');
-        $group->find();
 
+        $group->query($qry);
+
+        $groups = array();
         while ($group->fetch()) {
             $groups[] = clone($group);
         }