]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User_group.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / classes / User_group.php
index 3dc5fd4b2d8e0e1e799fad943b59301621a05ee3..1546414011bcf3e3c700cd2a24d26a7dd31a6291 100644 (file)
@@ -33,6 +33,12 @@ class User_group extends Managed_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
 
+    public function getObjectType()
+    {
+        return ActivityObject::GROUP;
+    }
+
+
     public static function schemaDef()
     {
         return array(
@@ -85,9 +91,22 @@ class User_group extends Managed_DataObject
     {
         if (!isset($this->_profile[$this->profile_id])) {
             $profile = Profile::getKV('id', $this->profile_id);
+
             if (!$profile instanceof Profile) {
-                throw new GroupNoProfileException($this);
+
+                $profile = new Profile();
+                $profile->nickname   = $this->nickname;
+                $profile->fullname   = $this->fullname;
+                $profile->profileurl = $this->mainpage;
+                $profile->homepage   = $this->homepage;
+                $profile->bio        = $this->description;
+                $profile->location   = $this->location;
+                $profile->created    = common_sql_now();
+                $this->profile_id = $profile->insert();
+
+                //throw new GroupNoProfileException($this);
             }
+
             $this->_profile[$this->profile_id] = $profile;
         }
         return $this->_profile[$this->profile_id];
@@ -214,24 +233,19 @@ class User_group extends Managed_DataObject
      */
     function getRequests($offset=0, $limit=null)
     {
-        $qry =
-          'SELECT profile.* ' .
-          'FROM profile JOIN group_join_queue '.
-          'ON profile.id = group_join_queue.profile_id ' .
-          'WHERE group_join_queue.group_id = %d ' .
-          'ORDER BY group_join_queue.created DESC ';
+        $rq = new Group_join_queue();
+        $rq->group_id = $this->id;
+
+        $members = new Profile();
+
+        $members->joinAdd(['id', $rq, 'profile_id']);
 
         if ($limit != null) {
-            if (common_config('db','type') == 'pgsql') {
-                $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
-            } else {
-                $qry .= ' LIMIT ' . $offset . ', ' . $limit;
-            }
+            $members->limit($offset, $limit);
         }
 
-        $members = new Profile();
+        $members->find();
 
-        $members->query(sprintf($qry, $this->id));
         return $members;
     }
 
@@ -312,13 +326,21 @@ class User_group extends Managed_DataObject
 
     function setOriginal($filename)
     {
-        $imagefile = new ImageFile($this->id, Avatar::path($filename));
+        // This should be handled by the Profile->setOriginal function so user and group avatars are handled the same
+        $imagefile = new ImageFile(null, Avatar::path($filename));
+
+        $sizes = array('homepage_logo' => AVATAR_PROFILE_SIZE,
+                       'stream_logo' => AVATAR_STREAM_SIZE,
+                       'mini_logo' => AVATAR_MINI_SIZE);
 
         $orig = clone($this);
         $this->original_logo = Avatar::url($filename);
-        $this->homepage_logo = Avatar::url($imagefile->resize(AVATAR_PROFILE_SIZE));
-        $this->stream_logo = Avatar::url($imagefile->resize(AVATAR_STREAM_SIZE));
-        $this->mini_logo = Avatar::url($imagefile->resize(AVATAR_MINI_SIZE));
+        foreach ($sizes as $name=>$size) {
+            $filename = Avatar::filename($this->profile_id, image_type_to_extension($imagefile->preferredType()),
+                                         $size, common_timestamp());
+            $imagefile->resizeTo(Avatar::path($filename), array('width'=>$size, 'height'=>$size));
+            $this->$name = Avatar::url($filename);
+        }
         common_debug(common_log_objstring($this));
         return $this->update($orig);
     }
@@ -810,7 +832,7 @@ class User_group extends Managed_DataObject
     function isPrivate()
     {
         return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
-                $this->force_scope == 1);
+                intval($this->force_scope) === 1);
     }
 
     public function isLocal()