/**
* @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#calculateRatingAverage()
*/
@Override
public Float calculateRatingAverage() {
DBQuery query;
if (getOLATResourceableSubPath() == null) {
// special query when sub path is null
query = DBFactory
.getInstance()
.createQuery(
"select avg(rating) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath is NULL");
} else {
query = DBFactory
.getInstance()
.createQuery(
"select avg(rating) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
query.setString("resSubPath", getOLATResourceableSubPath());
}
query.setString("resname", getOLATResourceable()
.getResourceableTypeName());
query.setLong("resId", getOLATResourceable().getResourceableId());
query.setCacheable(true);
//
List results = query.list();
Double average = (Double) query.list().get(0);
// When no ratings are found, a null value is returned!
if (average == null) return Float.valueOf(0);
else return average.floatValue();
}