]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Group_join_queue.php
If there's no Happening, we can't use the RSVP.
[quix0rs-gnu-social.git] / classes / Group_join_queue.php
index ee47b4932d8801c3f1f328810649709645ac5e72..9ff221c49fcf4b00daff2bed97921253b9185133 100644 (file)
@@ -14,14 +14,6 @@ class Group_join_queue extends Managed_DataObject
     public $group_id;
     public $created;
 
-    /* Static get */
-    function staticGet($k,$v=null)
-    { return Memcached_DataObject::staticGet('Group_join_queue',$k,$v); }
-
-    /* Pkey get */
-    function pkeyGet($k)
-    { return Memcached_DataObject::pkeyGet('Group_join_queue',$k); }
-
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
@@ -55,4 +47,77 @@ class Group_join_queue extends Managed_DataObject
         $rq->insert();
         return $rq;
     }
+
+    function getMember()
+    {
+        $member = Profile::getKV('id', $this->profile_id);
+
+        if (empty($member)) {
+            // TRANS: Exception thrown providing an invalid profile ID.
+            // TRANS: %s is the invalid profile ID.
+            throw new Exception(sprintf(_('Profile ID %s is invalid.'),$this->profile_id));
+        }
+
+        return $member;
+    }
+
+    function getGroup()
+    {
+        $group  = User_group::getKV('id', $this->group_id);
+
+        if (empty($group)) {
+            // TRANS: Exception thrown providing an invalid group ID.
+            // TRANS: %s is the invalid group ID.
+            throw new Exception(sprintf(_('Group ID %s is invalid.'),$this->group_id));
+        }
+
+        return $group;
+    }
+
+    /**
+     * Abort the pending group join...
+     */
+    function abort()
+    {
+        $profile = $this->getMember();
+        $group = $this->getGroup();
+
+        if (Event::handle('StartCancelJoinGroup', array($profile, $group))) {
+            $this->delete();
+            Event::handle('EndCancelJoinGroup', array($profile, $group));
+        }
+    }
+
+    /**
+     * Complete a pending group join...
+     *
+     * @return Group_member object on success
+     */
+    function complete()
+    {
+        $join = null;
+        $profile = $this->getMember();
+        $group = $this->getGroup();
+        if (Event::handle('StartJoinGroup', array($profile, $group))) {
+            $join = Group_member::join($group->id, $profile->id);
+            $this->delete();
+            Event::handle('EndJoinGroup', array($profile, $group));
+        }
+        if (!$join) {
+            throw new Exception('Internal error: group join failed.');
+        }
+        $join->notify();
+        return $join;
+    }
+
+    /**
+     * Send notifications via email etc to group administrators about
+     * this exciting new pending moderation queue item!
+     */
+    public function notify()
+    {
+        $joiner = Profile::getKV('id', $this->profile_id);
+        $group = User_group::getKV('id', $this->group_id);
+        mail_notify_group_join_pending($group, $joiner);
+    }
 }