]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Group_member.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / classes / Group_member.php
index 5385e0f4874133d4ad2da47c798cac374204dce3..3abb7681e8e5517d67a00693b90ce85f8fe45203 100644 (file)
@@ -3,7 +3,7 @@
  * Table Definition for group_member
  */
 
-class Group_member extends Memcached_DataObject
+class Group_member extends Managed_DataObject
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -12,18 +12,40 @@ class Group_member extends Memcached_DataObject
     public $group_id;                        // int(4)  primary_key not_null
     public $profile_id;                      // int(4)  primary_key not_null
     public $is_admin;                        // tinyint(1)
+    public $uri;                             // varchar(191)   not 255 because utf8mb4 takes more space
     public $created;                         // datetime()   not_null
     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
-    /* Static get */
-    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_member',$k,$v); }
-
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
-    function pkeyGet($kv)
+    public static function schemaDef()
     {
-        return Memcached_DataObject::pkeyGet('Group_member', $kv);
+        return array(
+            'fields' => array(
+                'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
+                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
+                'is_admin' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this user an admin?'),
+                'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'),
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
+            ),
+            'primary key' => array('group_id', 'profile_id'),
+            'unique keys' => array(
+                'group_member_uri_key' => array('uri'),
+            ),
+            'foreign keys' => array(
+                'group_member_group_id_fkey' => array('user_group', array('group_id' => 'id')),
+                'group_member_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
+            ),
+            'indexes' => array(
+                // @fixme probably we want a (profile_id, created) index here?
+                'group_member_profile_id_idx' => array('profile_id'),
+                'group_member_created_idx' => array('created'),
+                'group_member_profile_id_created_idx' => array('profile_id', 'created'),
+                'group_member_group_id_created_idx' => array('group_id', 'created'),
+            ),
+        );
     }
 
     /**
@@ -43,6 +65,9 @@ class Group_member extends Memcached_DataObject
         $member->group_id   = $group_id;
         $member->profile_id = $profile_id;
         $member->created    = common_sql_now();
+        $member->uri        = self::newUri(Profile::getByID($profile_id),
+                                           User_group::getByID($group_id),
+                                           $member->created);
 
         $result = $member->insert();
 
@@ -78,7 +103,7 @@ class Group_member extends Memcached_DataObject
 
     function getMember()
     {
-        $member = Profile::staticGet('id', $this->profile_id);
+        $member = Profile::getKV('id', $this->profile_id);
 
         if (empty($member)) {
             // TRANS: Exception thrown providing an invalid profile ID.
@@ -91,7 +116,7 @@ class Group_member extends Memcached_DataObject
 
     function getGroup()
     {
-        $group  = User_group::staticGet('id', $this->group_id);
+        $group  = User_group::getKV('id', $this->group_id);
 
         if (empty($group)) {
             // TRANS: Exception thrown providing an invalid group ID.
@@ -130,16 +155,22 @@ class Group_member extends Memcached_DataObject
     function asActivity()
     {
         $member = $this->getMember();
+
+        if (!$member) {
+            throw new Exception("No such member: " . $this->profile_id);
+        }
+
         $group  = $this->getGroup();
 
+        if (!$group) {
+            throw new Exception("No such group: " . $this->group_id);
+        }
+
         $act = new Activity();
 
-        $act->id = TagURI::mint('join:%d:%d:%s',
-                                $member->id,
-                                $group->id,
-                                common_date_iso8601($this->created));
+        $act->id = $this->getUri();
 
-        $act->actor     = ActivityObject::fromProfile($member);
+        $act->actor     = $member->asActivityObject();
         $act->verb      = ActivityVerb::JOIN;
         $act->objects[] = ActivityObject::fromGroup($group);
 
@@ -171,4 +202,9 @@ class Group_member extends Memcached_DataObject
     {
         mail_notify_group_join($this->getGroup(), $this->getMember());
     }
+
+    function getUri()
+    {
+        return $this->uri ?: self::newUri($this->getMember(), $this->getGroup()->getProfile(), $this->created);
+    }
 }