Skip to content
Snippets Groups Projects
Commit 310531bf authored by srosse's avatar srosse
Browse files

OO-984: make comment and rating in course configurable, guest cannot book,...

OO-984: make comment and rating in course configurable, guest cannot book, rate or comment, fix access to members only resource by administrators
parent 77d6945a
No related branches found
No related tags found
No related merge requests found
Showing
with 232 additions and 213 deletions
......@@ -89,6 +89,7 @@ import org.olat.search.service.indexer.LifeFullIndexer;
import org.olat.user.UserImpl;
import org.olat.util.logging.activity.LoggingResourceable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Initial Date: Mar 31, 2004
......@@ -98,6 +99,7 @@ import org.springframework.beans.factory.annotation.Autowired;
* Comment:
*
*/
@Service("repositoryManager")
public class RepositoryManager extends BasicManager {
private final int PICTUREWIDTH = 570;
......@@ -543,7 +545,11 @@ public class RepositoryManager extends BasicManager {
// allow if access granted for users
canLaunch = true;
} else if (re.getAccess() == RepositoryEntry.ACC_OWNERS && re.isMembersOnly()) {
canLaunch = repositoryEntryRelationDao.isMember(identity, re);
if(!canLaunch) {
if(repositoryEntryRelationDao.isMember(identity, re)) {
canLaunch = true;
}
}
}
}
......
......@@ -21,16 +21,19 @@ package org.olat.repository;
import org.olat.NewControllerFactory;
import org.olat.catalog.CatalogEntry;
import org.olat.core.configuration.AbstractOLATModule;
import org.olat.core.configuration.PersistedProperties;
import org.olat.core.configuration.AbstractSpringModule;
import org.olat.core.id.Roles;
import org.olat.core.id.context.SiteContextEntryControllerCreator;
import org.olat.core.util.StringHelper;
import org.olat.core.util.coordinate.CoordinatorManager;
import org.olat.course.site.CourseSite;
import org.olat.course.site.CourseSiteContextEntryControllerCreator;
import org.olat.group.BusinessGroupModule;
import org.olat.repository.site.MyCoursesSite;
import org.olat.repository.site.RepositorySite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* Description:<br>
......@@ -41,23 +44,45 @@ import org.olat.repository.site.RepositorySite;
*
* @author gnaegi
*/
public class RepositoryModule extends AbstractOLATModule {
@Service("repositoryModule")
public class RepositoryModule extends AbstractSpringModule {
private static final String MANAGED_REPOENTRY_ENABLED = "managedRepositoryEntries";
private static final String CATALOG_SITE_ENABLED = "site.catalog.enable";
private static final String CATALOG_ENABLED = "catalog.enable";
private static final String CATALOG_BROWSING_ENABLED = "catalog.brwosing.enable";
private static final String MYCOURSES_SEARCH_ENABLED = "mycourses.search.enable";
private static final String MYCOURSES_SEARCH_ENABLED = "mycourses.search.enabled";
private static final String MYCOURSES_ALL_RESOURCES_ENABLED = "mycourses.all.resources.enabled";
private static final String COMMENT_ENABLED = "repo.comment.enabled";
private static final String RATING_ENABLED = "repo.rating.enabled";
@Value("${site.catalog.enable:true}")
private boolean catalogSiteEnabled;
@Value("${catalog.enable:true}")
private boolean catalogEnabled;
@Value("${repo.catalog.browsing.enable}")
private boolean catalogBrowsingEnabled;
private boolean listAllResourceTypes;
@Value("${repo.managed}")
private boolean managedRepositoryEntries;
@Value("${mycourses.search.enabled:true}")
private boolean myCoursesSearchEnabled;
@Value("${mycourses.all.resources.enabled:true}")
private boolean listAllResourceTypes;
@Value("${repo.comment.enabled:true}")
private boolean commentEnabled;
@Value("${repo.rating.enabled:true}")
private boolean ratingEnabled;
@Autowired
private BusinessGroupModule groupModule;
@Autowired
public RepositoryModule(CoordinatorManager coordinatorManager) {
super(coordinatorManager);
}
/**
* @see org.olat.core.configuration.AbstractOLATModule#init()
*/
......@@ -90,20 +115,6 @@ public class RepositoryModule extends AbstractOLATModule {
this.groupModule = groupModule;
}
/**
* @see org.olat.core.configuration.AbstractOLATModule#initDefaultProperties()
*/
@Override
protected void initDefaultProperties() {
managedRepositoryEntries = getBooleanConfigParameter(MANAGED_REPOENTRY_ENABLED, false);
catalogSiteEnabled = getBooleanConfigParameter(CATALOG_SITE_ENABLED, true);
catalogEnabled = getBooleanConfigParameter(CATALOG_ENABLED, true);
catalogBrowsingEnabled = getBooleanConfigParameter(CATALOG_BROWSING_ENABLED, true);
myCoursesSearchEnabled = getBooleanConfigParameter(MYCOURSES_SEARCH_ENABLED, true);
}
private void updateProperties() {
String managedRepo = getStringPropertyValue(MANAGED_REPOENTRY_ENABLED, true);
if(StringHelper.containsNonWhitespace(managedRepo)) {
......@@ -129,6 +140,21 @@ public class RepositoryModule extends AbstractOLATModule {
if(StringHelper.containsNonWhitespace(myCoursesSearch)) {
myCoursesSearchEnabled = "true".equals(myCoursesSearch);
}
String myCoursesAllResources = getStringPropertyValue(MYCOURSES_ALL_RESOURCES_ENABLED, true);
if(StringHelper.containsNonWhitespace(myCoursesAllResources)) {
listAllResourceTypes = "true".equals(myCoursesAllResources);
}
String comment = getStringPropertyValue(COMMENT_ENABLED, true);
if(StringHelper.containsNonWhitespace(comment)) {
commentEnabled = "true".equals(comment);
}
String rating = getStringPropertyValue(RATING_ENABLED, true);
if(StringHelper.containsNonWhitespace(rating)) {
ratingEnabled = "true".equals(rating);
}
}
/**
......@@ -138,11 +164,6 @@ public class RepositoryModule extends AbstractOLATModule {
protected void initFromChangedProperties() {
updateProperties();
}
@Override
public void setPersistedProperties(PersistedProperties persistedProperties) {
this.moduleConfigProperties = persistedProperties;
}
public boolean isAcceptMembership(Roles roles) {
return groupModule.isAcceptMembership(roles);
......@@ -155,6 +176,10 @@ public class RepositoryModule extends AbstractOLATModule {
public boolean isListAllResourceTypes() {
return listAllResourceTypes;
}
public void setListAllResourceTypes(boolean enabled) {
setStringProperty(MYCOURSES_ALL_RESOURCES_ENABLED, Boolean.toString(enabled), true);
}
public boolean isManagedRepositoryEntries() {
return managedRepositoryEntries;
......@@ -195,6 +220,20 @@ public class RepositoryModule extends AbstractOLATModule {
public void setMyCoursesSearchEnabled(boolean enabled) {
setStringProperty(MYCOURSES_SEARCH_ENABLED, Boolean.toString(enabled), true);
}
public boolean isCommentEnabled() {
return commentEnabled;
}
public void setCommentEnabled(boolean enabled) {
setStringProperty(COMMENT_ENABLED, Boolean.toString(enabled), true);
}
public boolean isRatingEnabled() {
return ratingEnabled;
}
public void setRatingEnabled(boolean enabled) {
setStringProperty(RATING_ENABLED, Boolean.toString(enabled), true);
}
}
\ No newline at end of file
......@@ -86,8 +86,10 @@ table.search.author.desc=Placeholder
dialog.modal.bg.send.mail=$org.olat.group.ui.main\:dialog.modal.bg.send.mail
dialog.modal.bg.leave.text=$org.olat.group.ui.main\:dialog.modal.bg.leave.text
nomembers=XXX No members
my.course.search.on=ein
on=ein
my.course.search.enabled=Suche in "Kurs"
my.course.comment.enabled=Kommentar in "Kurs"
my.course.rating.enabled=Beurteilung in "Kurs"
repository.admin.title=Repository Einstellungen
mail.member=$org.olat.group.ui.main\:mail.member
user.notfound=Folgende Benutzer wurden nicht gefunden: {0}
......
......@@ -8,60 +8,7 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.olat.repository.manager,org.olat.repository.handlers" />
<bean id="repositoryModule" class="org.olat.repository.RepositoryModule" depends-on="userModule">
<property name="groupModule" ref="businessGroupModule"/>
<property name="persistedProperties">
<bean class="org.olat.core.configuration.PersistedProperties" scope="prototype" init-method="init" destroy-method="destroy">
<constructor-arg index="0" ref="coordinatorManager"/>
<constructor-arg index="1" ref="repositoryModule" />
</bean>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="repositoryModule" />
<property name="targetMethod" value="init" />
<property name="arguments">
<value>
managedRepositoryEntries=${repo.managed}
site.catalog.enable=${site.catalog.enable}
repo.catalog.enable=${repo.catalog.enable}
repo.catalog.browsing.enable=${repo.catalog.browsing.enable}
</value>
</property>
</bean>
<bean id="repositoryManager" class="org.olat.repository.RepositoryManager"/>
<bean id="deletionModule" class="org.olat.repository.delete.service.DeletionModule">
<property name="baseSecurityManager" ref="baseSecurityManager" />
<property name="persistedProperties">
<bean class="org.olat.core.configuration.PersistedProperties"
scope="prototype" init-method="init" destroy-method="destroy">
<constructor-arg index="0" ref="coordinatorManager" />
<constructor-arg index="1" ref="deletionModule" />
</bean>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="deletionModule" />
<property name="targetMethod" value="init" />
<property name="arguments">
<value>
archiveRootPath=${archive.dir}
deleteEmailResponseToUserName=administrator
adminUserName=${deletionModule.adminUserName}
</value>
</property>
</bean>
<bean id="repositoryDeletionManager"
class="org.olat.repository.delete.service.RepositoryDeletionManager">
<constructor-arg index="0" ref="deletionModule" />
<property name="mailManager" ref="mailManager" />
</bean>
<context:component-scan base-package="org.olat.repository" />
<!-- life cycle admin. panel -->
<bean class="org.olat.core.extensions.action.GenericActionExtension" init-method="initExtensionPoints">
......
......@@ -25,7 +25,6 @@
package org.olat.repository.delete.service;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
......@@ -33,46 +32,41 @@ import java.util.List;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.IdentityShort;
import org.olat.core.configuration.AbstractOLATModule;
import org.olat.core.configuration.PersistedProperties;
import org.olat.core.configuration.AbstractSpringModule;
import org.olat.core.id.Identity;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.WebappHelper;
import org.olat.core.util.coordinate.CoordinatorManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* TODO:cg Documentation
* Initial Date: 15.06.2006 <br>
* @author Christian Guretzki
*/
public class DeletionModule extends AbstractOLATModule {
private static final String CONF_ARCHIVE_ROOT_PATH = "archiveRootPath";
@Service("deletionModule")
public class DeletionModule extends AbstractSpringModule {
private static final OLog log = Tracing.createLoggerFor(DeletionModule.class);
private static final String CONF_DELETE_EMAIL_RESPONSE_TO_USER_NAME = "deleteEmailResponseToUserName";
private static final String CONF_ADMIN_USER_NAME = "adminUserName";
private static final String DEFAULT_ADMIN_USERNAME = "administrator";
@Value("${archive.dir}")
private String archiveRootPath;
@Value("${deleteEmailResponseToUserName:administrator}")
private String emailResponseTo;
@Value("${deletionModule.adminUserName:administrator}")
private String adminUserName;
private Identity adminUserIdentity;
@Autowired
private BaseSecurity baseSecurityManager;
/**
* [used by spring]
*/
private DeletionModule() {
//
}
/**
* [used by spring]
* @param baseSecurityManager
*/
public void setBaseSecurityManager(BaseSecurity baseSecurityManager) {
this.baseSecurityManager = baseSecurityManager;
}
@Override
protected void initDefaultProperties() {
//
@Autowired
public DeletionModule(CoordinatorManager coordinatorManager) {
super(coordinatorManager);
}
@Override
......@@ -80,35 +74,28 @@ public class DeletionModule extends AbstractOLATModule {
//
}
/**
* @see org.olat.core.configuration.OLATModule#init(com.anthonyeden.lib.config.Configuration)
*/
@Override
public void init() {
archiveRootPath = getStringConfigParameter(CONF_ARCHIVE_ROOT_PATH, System.getProperty("java.io.tmpdir") + File.separator+"olatdata"+File.separator + "deleted_archive", false);
emailResponseTo = getStringConfigParameter(CONF_DELETE_EMAIL_RESPONSE_TO_USER_NAME, WebappHelper.getMailConfig("mailDeleteUser"), false);
if (!emailResponseTo.contains("@")) {
List<IdentityShort> identities = baseSecurityManager.findShortIdentitiesByName(Collections.singletonList(emailResponseTo));
if (identities != null && identities.size() == 1) {
emailResponseTo = identities.get(0).getEmail();
} else {
logWarn("Could not find: " + CONF_DELETE_EMAIL_RESPONSE_TO_USER_NAME + " with name: " + emailResponseTo, null);
log.warn("Could not find: " + CONF_DELETE_EMAIL_RESPONSE_TO_USER_NAME + " with name: " + emailResponseTo, null);
emailResponseTo = WebappHelper.getMailConfig("mailFrom");
}
}
String adminUserName = getStringConfigParameter(CONF_ADMIN_USER_NAME, "administrator", false);
if (adminUserName != null) {
adminUserIdentity = baseSecurityManager.findIdentityByName(adminUserName);
} else {
adminUserIdentity = baseSecurityManager.findIdentityByName(DEFAULT_ADMIN_USERNAME);
}
if(isLogDebugEnabled()) {
logDebug("archiveRootPath=" + archiveRootPath);
logDebug("emailResponseTo=" + emailResponseTo);
logDebug("adminUserIdentity=" + adminUserIdentity);
if(log.isDebug()) {
log.debug("archiveRootPath=" + archiveRootPath);
log.debug("emailResponseTo=" + emailResponseTo);
log.debug("adminUserIdentity=" + adminUserIdentity);
}
}
......@@ -134,12 +121,4 @@ public class DeletionModule extends AbstractOLATModule {
public Identity getAdminUserIdentity() {
return adminUserIdentity;
}
/**
* [used by Spring]
*/
@Override
public void setPersistedProperties(PersistedProperties persistedProperties) {
this.moduleConfigProperties = persistedProperties;
}
}
......@@ -63,6 +63,8 @@ import org.olat.resource.OLATResourceManager;
import org.olat.resource.references.ReferenceManager;
import org.olat.user.UserDataDeletable;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
......@@ -73,6 +75,7 @@ import org.olat.user.UserManager;
* Comment:
*
*/
@Service("repositoryDeletionManager")
public class RepositoryDeletionManager extends BasicManager implements UserDataDeletable {
private static final String REPOSITORY_ARCHIVE_DIR = "archive_deleted_resources";
......@@ -87,35 +90,19 @@ public class RepositoryDeletionManager extends BasicManager implements UserDataD
public static final String SEND_DELETE_EMAIL_ACTION = "sendDeleteEmail";
private static final String REPOSITORY_DELETED_ACTION = "respositoryEntryDeleted";
private DeletionModule deletionModule;
private final DeletionModule deletionModule;
@Autowired
private MailManager mailManager;
@Autowired
private RepositoryService repositoryService;
/**
* [used by spring]
* @param userDeletionManager
*/
private RepositoryDeletionManager(DeletionModule deletionModule) {
@Autowired
public RepositoryDeletionManager(DeletionModule deletionModule) {
this.deletionModule = deletionModule;
INSTANCE = this;
}
/**
* [used by Spring]
* @param mailManager
*/
public void setMailManager(MailManager mailManager) {
this.mailManager = mailManager;
}
/**
* [used by Spring]
* @param repositoryService
*/
public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
/**
* @return Singleton.
......
......@@ -40,7 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
*/
public class RepositoryAdminController extends FormBasicController {
private MultipleSelectionElement enabled;
private MultipleSelectionElement myCourseSearchEl, commentEl, ratingEl;
private static final String[] keys = {"on"};
@Autowired
......@@ -57,11 +57,21 @@ public class RepositoryAdminController extends FormBasicController {
setFormTitle("repository.admin.title");
setFormContextHelp(RepositoryService.class.getPackage().getName(), "rep-admin.html", "help.hover.repository.admin");
boolean restEnabled = repositoryModule.isMyCoursesSearchEnabled();
String[] values = new String[] { translate("my.course.search.on") };
enabled = uifactory.addCheckboxesHorizontal("my.course.search.enabled", formLayout, keys, values);
enabled.addActionListener(FormEvent.ONCLICK);
enabled.select(keys[0], restEnabled);
boolean searchEnabled = repositoryModule.isMyCoursesSearchEnabled();
String[] values = new String[] { translate("on") };
myCourseSearchEl = uifactory.addCheckboxesHorizontal("my.course.search.enabled", formLayout, keys, values);
myCourseSearchEl.addActionListener(FormEvent.ONCLICK);
myCourseSearchEl.select(keys[0], searchEnabled);
boolean commentEnabled = repositoryModule.isCommentEnabled();
commentEl = uifactory.addCheckboxesHorizontal("my.course.comment.enabled", formLayout, keys, values);
commentEl.addActionListener(FormEvent.ONCLICK);
commentEl.select(keys[0], commentEnabled);
boolean ratingEnabled = repositoryModule.isCommentEnabled();
ratingEl = uifactory.addCheckboxesHorizontal("my.course.rating.enabled", formLayout, keys, values);
ratingEl.addActionListener(FormEvent.ONCLICK);
ratingEl.select(keys[0], ratingEnabled);
}
@Override
......@@ -71,10 +81,18 @@ public class RepositoryAdminController extends FormBasicController {
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if(enabled == source) {
boolean on = !enabled.getSelectedKeys().isEmpty();
if(myCourseSearchEl == source) {
boolean on = !myCourseSearchEl.getSelectedKeys().isEmpty();
repositoryModule.setMyCoursesSearchEnabled(on);
getWindowControl().setInfo("saved");
} else if(commentEl == source) {
boolean on = !commentEl.getSelectedKeys().isEmpty();
repositoryModule.setCommentEnabled(on);
getWindowControl().setInfo("saved");
} else if(ratingEl == source) {
boolean on = !ratingEl.getSelectedKeys().isEmpty();
repositoryModule.setRatingEnabled(on);
getWindowControl().setInfo("saved");
}
}
......
......@@ -249,28 +249,32 @@ public class RepositoryEntryDetailsController extends FormBasicController {
markLink.setIconLeftCSS(marked ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
}
Integer myRating;
if(row == null) {
myRating = userRatingsDao.getRatingValue(getIdentity(), entry, null);
} else {
myRating = row.getMyRating();
}
RepositoryEntryStatistics statistics = entry.getStatistics();
Double averageRating = statistics.getRating();
long numOfRatings = statistics.getNumOfRatings();
float ratingValue = myRating == null ? 0f : myRating.floatValue();
float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
ratingEl = new RatingWithAverageFormItem("rating", ratingValue, averageRatingValue, 5, numOfRatings);
ratingEl.setEnabled(!guestOnly);
layoutCont.add("rating", ratingEl);
if(repositoryModule.isRatingEnabled()) {
Integer myRating;
if(row == null) {
myRating = userRatingsDao.getRatingValue(getIdentity(), entry, null);
} else {
myRating = row.getMyRating();
}
Double averageRating = statistics.getRating();
long numOfRatings = statistics.getNumOfRatings();
float ratingValue = myRating == null ? 0f : myRating.floatValue();
float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
ratingEl = new RatingWithAverageFormItem("rating", ratingValue, averageRatingValue, 5, numOfRatings);
ratingEl.setEnabled(!guestOnly);
layoutCont.add("rating", ratingEl);
}
long numOfComments = statistics.getNumOfComments();
String title = "(" + numOfComments + ")";
commentsLink = uifactory.addFormLink("comments", "comments", title, null, layoutCont, Link.NONTRANSLATED);
commentsLink.setCustomEnabledLinkCSS("o_comments");
String css = numOfComments > 0 ? "o_icon o_icon_comments o_icon-lg" : "o_icon o_icon_comments_none o_icon-lg";
commentsLink.setIconLeftCSS(css);
if(repositoryModule.isCommentEnabled()) {
long numOfComments = statistics.getNumOfComments();
String title = "(" + numOfComments + ")";
commentsLink = uifactory.addFormLink("comments", "comments", title, null, layoutCont, Link.NONTRANSLATED);
commentsLink.setCustomEnabledLinkCSS("o_comments");
String css = numOfComments > 0 ? "o_icon o_icon_comments o_icon-lg" : "o_icon o_icon_comments_none o_icon-lg";
commentsLink.setIconLeftCSS(css);
}
//load memberships
boolean isMember = repositoryService.isMember(getIdentity(), entry);
......@@ -317,11 +321,13 @@ public class RepositoryEntryDetailsController extends FormBasicController {
startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON + Link.NONTRANSLATED);
startLink.setCustomEnabledLinkCSS("btn btn-success"); // custom style
startLink.setElementCssClass("o_book btn-block");
startLink.setVisible(!guestOnly);
} else {
String linkText = translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName()));
startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON + Link.NONTRANSLATED);
startLink.setEnabled(false);
startLink.setElementCssClass("o_start btn-block");
startLink.setVisible(!guestOnly);
}
startLink.setIconRightCSS("o_icon o_icon_start o_icon-lg");
startLink.setPrimary(true);
......
......@@ -52,6 +52,7 @@ import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTable
import org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent;
import org.olat.core.gui.components.link.Link;
import org.olat.core.gui.components.rating.RatingFormEvent;
import org.olat.core.gui.components.rating.RatingFormItem;
import org.olat.core.gui.components.rating.RatingWithAverageFormItem;
import org.olat.core.gui.components.stack.BreadcrumbPanel;
import org.olat.core.gui.components.velocity.VelocityContainer;
......@@ -69,6 +70,7 @@ import org.olat.core.util.Util;
import org.olat.core.util.resource.OresHelper;
import org.olat.course.CorruptedCourseException;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryModule;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter;
import org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy;
......@@ -108,6 +110,8 @@ public class RepositoryEntryListController extends FormBasicController
private UserRatingsDAO userRatingsDao;
@Autowired
private MapperService mapperService;
@Autowired
private RepositoryModule repositoryModule;
private final boolean guestOnly;
......@@ -162,9 +166,13 @@ public class RepositoryEntryListController extends FormBasicController
true, OrderBy.lifecycleEnd.name(), FlexiColumnModel.ALIGNMENT_LEFT, new DateFlexiCellRenderer(getLocale())));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false,Cols.details.i18nKey(), Cols.details.ordinal(), false, null));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.start.i18nKey(), Cols.start.ordinal()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.ratings.i18nKey(), Cols.ratings.ordinal(),
if(repositoryModule.isRatingEnabled()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.ratings.i18nKey(), Cols.ratings.ordinal(),
true, OrderBy.rating.name()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.comments.i18nKey(), Cols.comments.ordinal()));
}
if(repositoryModule.isCommentEnabled()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.comments.i18nKey(), Cols.comments.ordinal()));
}
model = new RepositoryEntryDataModel(dataSource, columnsModel);
tableEl = uifactory.addTableElement(getWindowControl(), "table", model, 20, false, getTranslator(), formLayout);
......@@ -503,6 +511,9 @@ public class RepositoryEntryListController extends FormBasicController
if(!row.isMembersOnly() && row.getAccessTypes() != null && !row.getAccessTypes().isEmpty() && !row.isMember()) {
label = "book";
isStart = false;
if(guestOnly) {
return;
}
} else {
label = "start";
}
......@@ -528,29 +539,42 @@ public class RepositoryEntryListController extends FormBasicController
@Override
public void forgeRatings(RepositoryEntryRow row) {
Integer myRating = row.getMyRating();
Double averageRating = row.getAverageRating();
long numOfRatings = row.getNumOfRatings();
float ratingValue = myRating == null ? 0f : myRating.floatValue();
float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
RatingWithAverageFormItem ratingCmp
= new RatingWithAverageFormItem("rat_" + row.getKey(), ratingValue, averageRatingValue, 5, numOfRatings);
ratingCmp.setEnabled(!guestOnly);
row.setRatingFormItem(ratingCmp);
ratingCmp.setUserObject(row);
if(repositoryModule.isRatingEnabled()) {
if(guestOnly) {
Double averageRating = row.getAverageRating();
float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
RatingFormItem ratingCmp
= new RatingFormItem("rat_" + row.getKey(), averageRatingValue, 5, false);
row.setRatingFormItem(ratingCmp);
ratingCmp.setUserObject(row);
} else {
Integer myRating = row.getMyRating();
Double averageRating = row.getAverageRating();
long numOfRatings = row.getNumOfRatings();
float ratingValue = myRating == null ? 0f : myRating.floatValue();
float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
RatingWithAverageFormItem ratingCmp
= new RatingWithAverageFormItem("rat_" + row.getKey(), ratingValue, averageRatingValue, 5, numOfRatings);
row.setRatingFormItem(ratingCmp);
ratingCmp.setUserObject(row);
}
}
}
@Override
public void forgeComments(RepositoryEntryRow row) {
long numOfComments = row.getNumOfComments();
String title = "(" + numOfComments + ")";
FormLink commentsLink = uifactory.addFormLink("comments_" + row.getKey(), "comments", title, null, null, Link.NONTRANSLATED);
commentsLink.setUserObject(row);
String css = numOfComments > 0 ? "o_icon o_icon_comments o_icon-lg" : "o_icon o_icon_comments_none o_icon-lg";
commentsLink.setCustomEnabledLinkCSS("o_comments");
commentsLink.setIconLeftCSS(css);
row.setCommentsLink(commentsLink);
if(repositoryModule.isCommentEnabled()) {
long numOfComments = row.getNumOfComments();
String title = "(" + numOfComments + ")";
FormLink commentsLink = uifactory.addFormLink("comments_" + row.getKey(), "comments", title, null, null, Link.NONTRANSLATED);
commentsLink.setUserObject(row);
String css = numOfComments > 0 ? "o_icon o_icon_comments o_icon-lg" : "o_icon o_icon_comments_none o_icon-lg";
commentsLink.setCustomEnabledLinkCSS("o_comments");
commentsLink.setIconLeftCSS(css);
row.setCommentsLink(commentsLink);
}
}
@Override
......
......@@ -22,8 +22,8 @@ package org.olat.repository.ui.list;
import java.util.Date;
import java.util.List;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.elements.FormLink;
import org.olat.core.gui.components.rating.RatingWithAverageFormItem;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.StringHelper;
import org.olat.core.util.filter.FilterFactory;
......@@ -78,7 +78,7 @@ public class RepositoryEntryRow implements RepositoryEntryRef {
private FormLink commentsLink;
private OLATResourceable olatResource;
private RatingWithAverageFormItem ratingFormItem;
private FormItem ratingFormItem;
public RepositoryEntryRow() {
//
......@@ -297,7 +297,7 @@ public class RepositoryEntryRow implements RepositoryEntryRef {
}
public String getStartLinkName() {
return startLink.getComponent().getComponentName();
return startLink == null ? null :startLink.getComponent().getComponentName();
}
public FormLink getStartLink() {
......@@ -336,14 +336,14 @@ public class RepositoryEntryRow implements RepositoryEntryRef {
}
public String getRatingFormItemName() {
return ratingFormItem.getComponent().getComponentName();
return ratingFormItem == null ? null : ratingFormItem.getComponent().getComponentName();
}
public RatingWithAverageFormItem getRatingFormItem() {
public FormItem getRatingFormItem() {
return ratingFormItem;
}
public void setRatingFormItem(RatingWithAverageFormItem ratingFormItem) {
public void setRatingFormItem(FormItem ratingFormItem) {
this.ratingFormItem = ratingFormItem;
}
......@@ -352,7 +352,7 @@ public class RepositoryEntryRow implements RepositoryEntryRef {
}
public String getCommentsLinkName() {
return commentsLink.getComponent().getComponentName();
return commentsLink == null ? null : commentsLink.getComponent().getComponentName();
}
public void setCommentsLink(FormLink commentsLink) {
......
......@@ -46,11 +46,14 @@
#end
</div>
#if($r.available("rating") || $r.available("comments"))
<div class="o_social o_block">
<h4>$r.translate("ratings")</h4>
#if($r.available("rating")) $r.render("rating") #end
$r.render("comments")
#if($r.available("comments")) $r.render("comments") #end
</div>
#end
#if($v.authors)
<div class="o_authors o_block">
<h4>$r.translate("cif.authors")</h4>
......
......@@ -83,15 +83,23 @@
</div>
#end
#if($row.ratingFormItemName || $row.commentsLinkName)
<div class="o_social o_ratings_and_comments row">
#if($row.ratingFormItemName)
<div class="o_rating_wrapper">
$r.render($row.ratingFormItemName)
</div>
$r.render($row.commentsLinkName)
#end
#if($row.commentsLinkName)
$r.render($row.commentsLinkName)
#end
</div>
#end
$r.render($row.getDetailsLinkName())
$r.render($row.getStartLinkName())
#if($row.getStartLinkName())
$r.render($row.getStartLinkName())
#end
</div>
<script type="text/javascript">
......
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