Fix empty user group select when editing an announcement see BT#14824

pull/2688/head
Julio Montoya 7 years ago
parent 260549e93c
commit a1e7082fec
  1. 3
      main/announcements/announcements.php
  2. 15
      main/inc/lib/course.lib.php

@ -450,7 +450,7 @@ switch ($action) {
); );
// when we want to remind the users who have never been active // when we want to remind the users who have never been active
// then we have a different subject and content for the announcement // then we have a different subject and content for the announcement
if ($_GET['since'] == 'never') { if ($_GET['since'] === 'never') {
$title_to_modify = sprintf( $title_to_modify = sprintf(
get_lang('RemindInactiveLearnersMailSubject'), get_lang('RemindInactiveLearnersMailSubject'),
api_get_setting('siteName') api_get_setting('siteName')
@ -475,6 +475,7 @@ switch ($action) {
$announcementInfo = AnnouncementManager::get_by_id($courseId, $id); $announcementInfo = AnnouncementManager::get_by_id($courseId, $id);
if (isset($announcementInfo) && !empty($announcementInfo)) { if (isset($announcementInfo) && !empty($announcementInfo)) {
$to = AnnouncementManager::load_edit_users('announcement', $id); $to = AnnouncementManager::load_edit_users('announcement', $id);
$defaults = [ $defaults = [
'title' => $announcementInfo['title'], 'title' => $announcementInfo['title'],
'content' => $announcementInfo['content'], 'content' => $announcementInfo['content'],

@ -6051,7 +6051,7 @@ class CourseManager
public static function addGroupMultiSelect($form, $groupInfo, $to = []) public static function addGroupMultiSelect($form, $groupInfo, $to = [])
{ {
$group_users = GroupManager::get_subscribed_users($groupInfo); $group_users = GroupManager::get_subscribed_users($groupInfo);
$array = self::buildSelectOptions(null, $group_users, $to); $array = self::buildSelectOptions([$groupInfo], $group_users, $to);
$result = []; $result = [];
foreach ($array as $content) { foreach ($array as $content) {
@ -6089,14 +6089,19 @@ class CourseManager
"GROUP:".$groupId, "GROUP:".$groupId,
$alreadySelected $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'); $userCount = isset($thisGroup['userNb']) ? $thisGroup['userNb'] : 0;
$user_disabled = ($thisGroup['userNb'] > 0) ? "" : "disabled=disabled"; 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[] = [ $result[] = [
'disabled' => $user_disabled, 'disabled' => $user_disabled,
'value' => "GROUP:".$groupId, 'value' => "GROUP:".$groupId,
// The space before "G" is needed in order to advmultiselect.php js puts groups first // 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,
]; ];
} }
} }

Loading…
Cancel
Save