]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Pending subscription requests now work as they should
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 3 Jan 2016 19:27:53 +0000 (20:27 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 3 Jan 2016 19:27:53 +0000 (20:27 +0100)
A slight layout issue with the buttons still persists

actions/subqueue.php
classes/Profile.php
lib/profilelist.php
lib/profilelistitem.php
lib/subqueuelist.php [new file with mode: 0644]
lib/subqueuelistitem.php [new file with mode: 0644]

index ba473456004ef06ffa364d1fc7ad4b59e56415bd..e4dcb025135c910844779c3df63583e50ecf39ff 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once(INSTALLDIR.'/lib/profilelist.php');
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * List of group members
@@ -50,9 +46,9 @@ class SubqueueAction extends GalleryAction
     {
         parent::prepare($args);
 
-        if ($this->scoped->id != $this->target->id) {
+        if (!$this->target->sameAs($this->scoped)) {
             // TRANS: Client error displayed when trying to approve group applicants without being a group administrator.
-            $this->clientError(_('You may only approve your own pending subscriptions.'));
+            throw new ClientException(_('You may only approve your own pending subscriptions.'));
         }
         return true;
     }
@@ -88,47 +84,21 @@ class SubqueueAction extends GalleryAction
 
         $cnt = 0;
 
-        $members = $this->target->getRequests($offset, $limit);
-
-        if ($members) {
-            // @fixme change!
-            $member_list = new SubQueueList($members, $this);
-            $cnt = $member_list->show();
+        try {
+            $subqueue = $this->target->getRequests($offset, $limit);
+        } catch (NoResultException $e) {
+            // TRANS: If no pending subscription requests are found
+            $this->element('div', null, _m('You have no pending subscription requests.'));
+            return;
         }
 
-        $members->free();
+        $list = new SubQueueList($subqueue, $this);
+        $cnt = $list->show();
+
+        $subqueue->free();
 
         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
                           $this->page, 'subqueue',
                           array('nickname' => $this->target->getNickname())); // urgh
     }
 }
-
-class SubQueueList extends ProfileList
-{
-    function newListItem($profile)
-    {
-        return new SubQueueListItem($profile, $this->action);
-    }
-}
-
-class SubQueueListItem extends ProfileListItem
-{
-    function showActions()
-    {
-        $this->startActions();
-        if (Event::handle('StartProfileListItemActionElements', array($this))) {
-            $this->showApproveButtons();
-            Event::handle('EndProfileListItemActionElements', array($this));
-        }
-        $this->endActions();
-    }
-
-    function showApproveButtons()
-    {
-        $this->out->elementStart('li', 'entity_approval');
-        $form = new ApproveSubForm($this->out, $this->profile);
-        $form->show();
-        $this->out->elementEnd('li');
-    }
-}
index f4452391c25819dadb930e08d7d2c9eb1d93db64..619f5e3c7cd849ff1a7277415dbdcf2c99bfa805 100644 (file)
@@ -682,25 +682,16 @@ class Profile extends Managed_DataObject
      */
     function getRequests($offset=0, $limit=null)
     {
-        $qry =
-          'SELECT profile.* ' .
-          'FROM profile JOIN subscription_queue '.
-          'ON profile.id = subscription_queue.subscriber ' .
-          'WHERE subscription_queue.subscribed = %d ' .
-          'ORDER BY subscription_queue.created DESC ';
-
-        if ($limit != null) {
-            if (common_config('db','type') == 'pgsql') {
-                $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-            } else {
-                $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-            }
-        }
-
-        $members = new Profile();
-
-        $members->query(sprintf($qry, $this->id));
-        return $members;
+        // FIXME: mysql only
+        $subqueue = new Profile();
+        $subqueue->joinAdd(array('id', 'subscription_queue:subscriber'));
+        $subqueue->whereAdd(sprintf('subscription_queue.subscribed = %d', $this->getID()));
+        $subqueue->limit($offset, $limit);
+        $subqueue->orderBy('subscription_queue.created', 'DESC');
+        if (!$subqueue->find()) {
+            throw new NoResultException($subqueue);
+        }
+        return $subqueue;
     }
 
     function subscriptionCount()
index 177560cdf568844ef7f2a070d463c343684a4f7b..9f735b1b88d8d02e61a8be4f91cb34fb01f2f0d4 100644 (file)
@@ -46,7 +46,7 @@ class ProfileList extends Widget
     /** Action object using us. */
     var $action = null;
 
-    function __construct($profile, $action=null)
+    function __construct($profile, HTMLOutputter $action=null)
     {
         parent::__construct($action);
 
@@ -93,9 +93,9 @@ class ProfileList extends Widget
         return $cnt;
     }
 
-    function newListItem($profile)
+    function newListItem(Profile $target)
     {
-        return new ProfileListItem($profile, $this->action);
+        return new ProfileListItem($target, $this->action);
     }
 
     function maxProfiles()
index 6fe7b99c7b3a967515815df5a3e1bde0c425fa04..e0e2838f58a3245525405035ad4b3f1eb291130b 100644 (file)
@@ -72,7 +72,7 @@ class ProfileListItem extends Widget
     function startItem()
     {
         $this->out->elementStart('li', array('class' => 'profile',
-                                             'id' => 'profile-' . $this->profile->id));
+                                             'id' => 'profile-' . $this->getTarget()->getID()));
     }
 
     function showProfile()
diff --git a/lib/subqueuelist.php b/lib/subqueuelist.php
new file mode 100644 (file)
index 0000000..e4f7742
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class SubQueueList extends ProfileList
+{
+    public function newListItem(Profile $target)
+    {
+        return new SubQueueListItem($target, $this->action);
+    }
+}
diff --git a/lib/subqueuelistitem.php b/lib/subqueuelistitem.php
new file mode 100644 (file)
index 0000000..f426241
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class SubQueueListItem extends ProfileListItem
+{
+    public function showActions()
+    {
+        $this->startActions();
+        if (Event::handle('StartProfileListItemActionElements', array($this))) {
+            $this->showApproveButtons();
+            Event::handle('EndProfileListItemActionElements', array($this));
+        }
+        $this->endActions();
+    }
+
+    public function showApproveButtons()
+    {
+        $this->out->elementStart('li', 'entity_approval');
+        $form = new ApproveSubForm($this->out, $this->profile);
+        $form->show();
+        $this->out->elementEnd('li');
+    }
+}