From a1e7082fecd901ce91d09ab51808699cca7eeb3d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 13 Sep 2018 14:33:28 +0200 Subject: [PATCH] Fix empty user group select when editing an announcement see BT#14824 --- main/announcements/announcements.php | 3 ++- main/inc/lib/course.lib.php | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/main/announcements/announcements.php b/main/announcements/announcements.php index a81f04d891..c13be1a8cc 100755 --- a/main/announcements/announcements.php +++ b/main/announcements/announcements.php @@ -450,7 +450,7 @@ switch ($action) { ); // when we want to remind the users who have never been active // then we have a different subject and content for the announcement - if ($_GET['since'] == 'never') { + if ($_GET['since'] === 'never') { $title_to_modify = sprintf( get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName') @@ -475,6 +475,7 @@ switch ($action) { $announcementInfo = AnnouncementManager::get_by_id($courseId, $id); if (isset($announcementInfo) && !empty($announcementInfo)) { $to = AnnouncementManager::load_edit_users('announcement', $id); + $defaults = [ 'title' => $announcementInfo['title'], 'content' => $announcementInfo['content'], diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 83de286815..d966a89ba7 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -6051,7 +6051,7 @@ class CourseManager public static function addGroupMultiSelect($form, $groupInfo, $to = []) { $group_users = GroupManager::get_subscribed_users($groupInfo); - $array = self::buildSelectOptions(null, $group_users, $to); + $array = self::buildSelectOptions([$groupInfo], $group_users, $to); $result = []; foreach ($array as $content) { @@ -6089,14 +6089,19 @@ class CourseManager "GROUP:".$groupId, $alreadySelected ) - ) { // $alreadySelected is the array containing the groups (and users) that are already selected - $user_label = ($thisGroup['userNb'] > 0) ? get_lang('Users') : get_lang('LowerCaseUser'); - $user_disabled = ($thisGroup['userNb'] > 0) ? "" : "disabled=disabled"; + ) { + $userCount = isset($thisGroup['userNb']) ? $thisGroup['userNb'] : 0; + if (empty($userCount)) { + $userCount = isset($thisGroup['count_users']) ? $thisGroup['count_users'] : 0; + } + // $alreadySelected is the array containing the groups (and users) that are already selected + $user_label = ($userCount > 0) ? get_lang('Users') : get_lang('LowerCaseUser'); + $user_disabled = ($userCount > 0) ? "" : "disabled=disabled"; $result[] = [ 'disabled' => $user_disabled, 'value' => "GROUP:".$groupId, // The space before "G" is needed in order to advmultiselect.php js puts groups first - 'content' => " G: ".$thisGroup['name']." - ".$thisGroup['userNb']." ".$user_label, + 'content' => " G: ".$thisGroup['name']." - ".$userCount." ".$user_label, ]; } }