Skip to content
Snippets Groups Projects
Commit 9031b1f0 authored by srosse's avatar srosse
Browse files

OO-2435: add fallback to the big portrait if the small one is missing

parent 6ec60fa5
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,6 @@ import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.creator.ControllerCreator;
import org.olat.core.gui.control.generic.closablewrapper.CloseableModalController;
import org.olat.core.gui.media.MediaResource;
import org.olat.core.helpers.Settings;
import org.olat.core.id.Identity;
import org.olat.core.id.UserConstants;
......@@ -319,8 +318,8 @@ public class MembersCourseNodeRunController extends FormBasicController {
}
private Member createMember(Identity identity) {
MediaResource rsrc = portraitManager.getSmallPortraitResource(identity.getName());
boolean hasPortrait = portraitManager.hasPortrait(identity.getName());
String portraitCssClass;
String gender = identity.getUser().getProperty(UserConstants.GENDER, Locale.ENGLISH);
if ("male".equalsIgnoreCase(gender)) {
......@@ -331,7 +330,7 @@ public class MembersCourseNodeRunController extends FormBasicController {
portraitCssClass = DisplayPortraitManager.DUMMY_BIG_CSS_CLASS;
}
String fullname = userManager.getUserDisplayName(identity);
return new Member(identity, fullname, userPropertyHandlers, getLocale(), rsrc != null, portraitCssClass);
return new Member(identity, fullname, userPropertyHandlers, getLocale(), hasPortrait, portraitCssClass);
}
@Override
......
......@@ -164,6 +164,9 @@ public class DisplayPortraitController extends BasicController implements Generi
}
} else {
image = DisplayPortraitManager.getInstance().getSmallPortrait(portraitIdent.getName());
if(image == null) {
image = DisplayPortraitManager.getInstance().getBigPortrait(portraitIdent.getName());
}
if (image != null) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_SMALL_CSS_CLASS);
} else if (isAnonymous) {
......
......@@ -169,13 +169,31 @@ public class DisplayPortraitManager extends BasicManager implements UserDataDele
public File getBigLogo(String username) {
return getPortraitFile(username, LOGO_BIG_FILENAME);
}
public boolean hasPortrait(String username) {
File portraitDir = getPortraitDir(username);
if(portraitDir != null) {
File[] portraits = portraitDir.listFiles();
if(portraits.length > 0) {
for(File file:portraits) {
if(file.getName().startsWith(PORTRAIT_PREFIX_FILENAME)) {
return true;
}
}
}
}
return false;
}
private File getPortraitFile(String username, String prefix) {
File portraitDir = getPortraitDir(username);
if(portraitDir != null) {
for(File file:portraitDir.listFiles()) {
if(file.getName().startsWith(prefix)) {
return file;
File[] portraits = portraitDir.listFiles();
if(portraits.length > 0) {
for(File file:portraits) {
if(file.getName().startsWith(prefix)) {
return file;
}
}
}
}
......
......@@ -48,6 +48,7 @@ public class UserAvatarMapper implements Mapper {
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
MediaResource rsrc = null;
if(relPath != null && relPath.endsWith(POSTFIX_LARGE) || relPath.endsWith(POSTFIX_SMALL)) {
if(relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
......@@ -59,13 +60,16 @@ public class UserAvatarMapper implements Mapper {
Long key = Long.parseLong(idKey);
String username = userManager.getUsername(key);
if (useLarge) {
return portraitManager.getBigPortraitResource(username);
rsrc = portraitManager.getBigPortraitResource(username);
} else {
return portraitManager.getSmallPortraitResource(username);
rsrc = portraitManager.getSmallPortraitResource(username);
if(rsrc == null) {
rsrc = portraitManager.getBigPortraitResource(username);
}
}
}
}
return null;
return rsrc;
}
public String createPathFor(String mapperPath, Identity identity) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment