X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser_group.php;h=d89f3376f8028adc9a1b020da23eb0eaa027d88b;hb=aa41afc28b9933d2c1da34504ad1c1ef4f020639;hp=df54b7987c7d7228ca507cd9b842a159b095005a;hpb=c94d9994d898eddf654121ac45d455891954e830;p=quix0rs-gnu-social.git diff --git a/classes/User_group.php b/classes/User_group.php index df54b7987c..d89f3376f8 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -14,6 +14,7 @@ class User_group extends Managed_DataObject public $__table = 'user_group'; // table name public $id; // int(4) primary_key not_null + public $profile_id; // int(4) primary_key not_null public $nickname; // varchar(64) public $fullname; // varchar(191) not 255 because utf8mb4 takes more space public $homepage; // varchar(191) not 255 because utf8mb4 takes more space @@ -33,6 +34,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 +92,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]; @@ -108,18 +128,7 @@ class User_group extends Managed_DataObject function homeUrl() { - $url = null; - if (Event::handle('StartUserGroupHomeUrl', array($this, &$url))) { - // normally stored in mainpage, but older ones may be null - if (!empty($this->mainpage)) { - $url = $this->mainpage; - } elseif ($this->isLocal()) { - $url = common_local_url('showgroup', - array('nickname' => $this->nickname)); - } - } - Event::handle('EndUserGroupHomeUrl', array($this, &$url)); - return $url; + return $this->getProfile()->getUrl(); } function getUri() @@ -214,24 +223,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; } @@ -818,7 +822,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()