]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Tweaking request_queue -> group_join_queue, easier to deal with the indexes and keys...
authorBrion Vibber <brion@pobox.com>
Mon, 21 Mar 2011 22:04:32 +0000 (15:04 -0700)
committerBrion Vibber <brion@pobox.com>
Mon, 21 Mar 2011 22:05:36 +0000 (15:05 -0700)
classes/Group_join_queue.php [new file with mode: 0644]
classes/Managed_DataObject.php
classes/Profile.php
classes/Request_queue.php [deleted file]
classes/User_group.php
db/core.php
lib/groupeditform.php

diff --git a/classes/Group_join_queue.php b/classes/Group_join_queue.php
new file mode 100644 (file)
index 0000000..d8deb25
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Table Definition for request_queue
+ */
+require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
+
+class Group_join_queue extends Managed_DataObject
+{
+    ###START_AUTOCODE
+    /* the code below is auto generated do not remove the above tag */
+
+    public $__table = 'group_join_queue';       // table name
+    public $profile_id;
+    public $group_id;
+    public $created;
+
+    /* Static get */
+    function staticGet($k,$v=null)
+    { return Memcached_DataObject::staticGet('Group_join_queue',$k,$v); }
+
+    /* the code above is auto generated do not remove the tag below */
+    ###END_AUTOCODE
+
+    public static function schemaDef()
+    {
+        return array(
+            'description' => 'Holder for group join requests awaiting moderation.',
+            'fields' => array(
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
+                'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+            ),
+            'primary key' => array('profile_id', 'group_id'),
+            'indexes' => array(
+                'group_join_queue_profile_id_created_idx' => array('profile_id', 'created'),
+                'group_join_queue_group_id_created_idx' => array('group_id', 'created'),
+            ),
+            'foreign keys' => array(
+                'group_join_queue_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+                'group_join_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
+            )
+        );
+    }
+
+    public static function saveNew(Profile $profile, User_group $group)
+    {
+        $rq = new Group_join_queue();
+        $rq->profile_id = $profile->id;
+        $rq->group_id = $group->id;
+        $rq->created = common_sql_now();
+        $rq->insert();
+        return $rq;
+    }
+}
index 7990d7f40891fb0a6559062f35a1f77c4dfa24fd..7263b3e3206f787c6116599f43f1a2e1e489c7aa 100644 (file)
@@ -93,6 +93,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
     function keyTypes()
     {
         $table = call_user_func(array(get_class($this), 'schemaDef'));
+        $keys = array();
 
         if (!empty($table['unique keys'])) {
             foreach ($table['unique keys'] as $idx => $fields) {
index a80f121fc49d67322764266d356165223da1910f..d4b288fa7a67e48c1bc3feefeba1cf6cdc25478d 100644 (file)
@@ -344,14 +344,18 @@ class Profile extends Memcached_DataObject
      * May throw exceptions on failure.
      *
      * @param User_group $group
-     * @return Group_member
+     * @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
      */
     function joinGroup(User_group $group)
     {
         $ok = null;
-        if (Event::handle('StartJoinGroup', array($group, $this))) {
-            $ok = Group_member::join($group->id, $this->id);
-            Event::handle('EndJoinGroup', array($group, $this));
+        if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
+            $ok = Group_join_queue::saveNew($this, $group);
+        } else {
+            if (Event::handle('StartJoinGroup', array($group, $this))) {
+                $ok = Group_member::join($group->id, $this->id);
+                Event::handle('EndJoinGroup', array($group, $this));
+            }
         }
         return $ok;
     }
@@ -363,9 +367,9 @@ class Profile extends Memcached_DataObject
      */
     function leaveGroup(User_group $group)
     {
-        if (Event::handle('StartLeaveGroup', array($this->group, $this))) {
-            Group_member::leave($this->group->id, $this->id);
-            Event::handle('EndLeaveGroup', array($this->group, $this));
+        if (Event::handle('StartLeaveGroup', array($group, $this))) {
+            Group_member::leave($group->id, $this->id);
+            Event::handle('EndLeaveGroup', array($group, $this));
         }
     }
 
diff --git a/classes/Request_queue.php b/classes/Request_queue.php
deleted file mode 100644 (file)
index 3d094b1..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * Table Definition for request_queue
- */
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-
-class Request_queue extends Managed_DataObject
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'request_queue';       // table name
-    public $subscriber;
-    public $subscribed;
-    public $group_id;
-    public $created;
-
-    /* Static get */
-    function staticGet($k,$v=null)
-    { return Memcached_DataObject::staticGet('Confirm_address',$k,$v); }
-
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-
-    public static function schemaDef()
-    {
-        return array(
-            'description' => 'Holder for subscription & group join requests awaiting moderation.',
-            'fields' => array(
-                'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
-                'subscribed' => array('type' => 'int', 'description' => 'remote or local profile to subscribe to, if any'),
-                'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
-                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
-            ),
-            'unique key' => array(
-                'request_queue_subscriber_subscribed_group_id' => array('subscriber', 'subscribed', 'group_id'),
-            ),
-            'indexes' => array(
-                'request_queue_subscriber_created_idx' => array('subscriber', 'created'),
-                'request_queue_subscribed_created_idx' => array('subscriber', 'created'),
-                'request_queue_group_id_created_idx' => array('group_id', 'created'),
-            ),
-            'foreign keys' => array(
-                'request_queue_subscriber_fkey' => array('profile', array('subscriber' => 'id')),
-                'request_queue_subscribed_fkey' => array('profile', array('subscribed' => 'id')),
-                'request_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
-            )
-        );
-    }
-}
index 6ed51b506ba8a28b9a6715ac5f65153ded824a4e..11efe8d3afbfd8a51acc77f5b7e07277bcde6269 100644 (file)
@@ -5,6 +5,9 @@
 
 class User_group extends Memcached_DataObject
 {
+    const JOIN_POLICY_OPEN = 0;
+    const JOIN_POLICY_MODERATE = 1;
+
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
 
index 4aa1911d467ddf31805724cbfb59f9602a5b4d53..928186d94d9a69d96b1119b062499519a73bb4f8 100644 (file)
@@ -1027,4 +1027,4 @@ $schema['schema_version'] = array(
     'primary key' => array('table_name'),
 );
 
-$schema['request_queue'] = Request_queue::schemaDef();
+$schema['group_join_queue'] = Group_join_queue::schemaDef();
index 75f1344c11d59c2eca2205df1760bacc0e8b0f79..0e9c41055e91ca91dffb49766853a38840190981 100644 (file)
@@ -189,11 +189,11 @@ class GroupEditForm extends Form
             $this->out->elementStart('li');
             $this->out->dropdown('join_policy',
                                  _('Membership policy'),
-                                 array(0 => _('Open to all'),
-                                       1 => _('Admin must approve all members')),
+                                 array(User_group::JOIN_POLICY_OPEN     => _('Open to all'),
+                                       User_group::JOIN_POLICY_MODERATE => _('Admin must approve all members')),
                                  _('Whether admin approval is required to join this group.'),
                                  false,
-                                 (empty($this->group->join_policy)) ? 0 : $this->group->join_policy);
+                                 (empty($this->group->join_policy)) ? User_group::JOIN_POLICY_OPEN : $this->group->join_policy);
             $this->out->elementEnd('li');
             Event::handle('EndGroupEditFormData', array($this));
         }