From 481e8998c955bb2c30098e4cdd3f68afea5448bb Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Tue, 17 Dec 2024 00:34:59 -0500 Subject: [PATCH] User: Fix usergroup table loading and form updates - refs BT#22277 --- public/main/inc/lib/display.lib.php | 6 ++++-- public/main/inc/lib/usergroup.lib.php | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index 07da3cec870..d95d6f3463a 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -1200,11 +1200,13 @@ public static function grid_js( // Default row quantity if (!isset($extra_params['rowList'])) { - $extra_params['rowList'] = [20, 50, 100, 500, 1000, $all_value]; + $defaultRowList = [20, 50, 100, 500, 1000, $all_value]; $rowList = api_get_setting('platform.table_row_list', true); - if (!empty($rowList) && isset($rowList['options'])) { + if (is_array($rowList) && isset($rowList['options']) && is_array($rowList['options'])) { $rowList = $rowList['options']; $rowList[] = $all_value; + } else { + $rowList = $defaultRowList; } $extra_params['rowList'] = $rowList; } diff --git a/public/main/inc/lib/usergroup.lib.php b/public/main/inc/lib/usergroup.lib.php index 0055d602cc1..d1fcae341eb 100644 --- a/public/main/inc/lib/usergroup.lib.php +++ b/public/main/inc/lib/usergroup.lib.php @@ -1371,7 +1371,7 @@ public function getUsergroupsPagination($sidx, $sord, $start, $limit, $extraWher } $result = Database::store_result( - Database::query("SELECT u.* FROM $sqlFrom WHERE $sqlWhere ORDER BY title $sord LIMIT $start, $limit") + Database::query("SELECT DISTINCT u.* FROM $sqlFrom WHERE $sqlWhere ORDER BY title $sord LIMIT $start, $limit") ); $new_result = []; @@ -1588,8 +1588,9 @@ public function save($params, $showQuery = false) return false; } - public function update($params, $showQuery = false) + public function update($params, $showQuery = false): bool { + $em = Database::getManager(); $repo = Container::getUsergroupRepository(); /** @var Usergroup $userGroup */ $userGroup = $repo->find($params['id']); @@ -1597,7 +1598,22 @@ public function update($params, $showQuery = false) return false; } - //$params['updated_on'] = api_get_utc_datetime(); + if (isset($params['title'])) { + $userGroup->setTitle($params['title']); + } + + if (isset($params['description'])) { + $userGroup->setDescription($params['description']); + } + + if (isset($params['visibility'])) { + $userGroup->setVisibility($params['visibility']); + } + + if (isset($params['url'])) { + $userGroup->setUrl($params['url']); + } + $userGroup ->setGroupType(isset($params['group_type']) ? Usergroup::SOCIAL_CLASS : Usergroup::NORMAL_CLASS) ->setAllowMembersToLeaveGroup(isset($params['allow_members_leave_group']) ? 1 : 0) @@ -1612,7 +1628,8 @@ public function update($params, $showQuery = false) } } - $repo->update($userGroup); + $em->persist($userGroup); + $em->flush(); if (isset($params['delete_picture'])) { $this->delete_group_picture($params['id']);