Index: lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java =================================================================== diff -u -r205422ba51f37efbdb79970f502a536219ea9cb0 -r5dbbc7b9946ede2b5de406e9adb39928e1dda083 --- lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (.../RatingServlet.java) (revision 205422ba51f37efbdb79970f502a536219ea9cb0) +++ lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (.../RatingServlet.java) (revision 5dbbc7b9946ede2b5de406e9adb39928e1dda083) @@ -74,10 +74,11 @@ Long ratingCriteriaId = Long.parseLong(objectId.split("-")[0]); Long itemId = Long.parseLong(objectId.split("-")[1]); RatingCriteria criteria = ratingService.getCriteriaByCriteriaId(ratingCriteriaId); + Long toolSessionId = WebUtil.readLongParam(request, "toolSessionId"); UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); Integer userId = user.getUserID(); - + // get rating value as either float or comment String try { boolean doSave = true; @@ -95,8 +96,8 @@ List itemIds = new LinkedList(); itemIds.add(itemId); Map itemIdToRatedUsersCountMap = ratingLimitsByCriteria ? - ratingService.countUsersRatedEachItemByCriteria(ratingCriteriaId, itemIds, userId) : - ratingService.countUsersRatedEachItem(toolCriteria.getToolContentId(), itemIds, userId); + ratingService.countUsersRatedEachItemByCriteria(ratingCriteriaId, toolSessionId, itemIds, userId) : + ratingService.countUsersRatedEachItem(toolCriteria.getToolContentId(), toolSessionId, itemIds, userId); Long currentRatings = itemIdToRatedUsersCountMap.get(itemId); if (currentRatings != null && maxRatingsForItem.compareTo(currentRatings) <= 0) { @@ -115,7 +116,7 @@ // can have but do not have to have comment String comment = WebUtil.readStrParam(request, "comment", true); if ( comment != null ) { - ratingService.commentItem(criteria, userId, itemId, comment); + ratingService.commentItem(criteria, toolSessionId, userId, itemId, comment); JSONObject.put("comment", StringEscapeUtils.escapeCsv(comment)); } } @@ -124,7 +125,7 @@ if ( floatString != null && floatString.length() > 0 ) { float rating = Float.parseFloat(request.getParameter("rate")); - ItemRatingCriteriaDTO averageRatingDTO = ratingService.rateItem(criteria, userId, itemId, rating); + ItemRatingCriteriaDTO averageRatingDTO = ratingService.rateItem(criteria, toolSessionId, userId, itemId, rating); NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); numberFormat.setMaximumFractionDigits(1); Index: lams_central/web/includes/javascript/rating.js =================================================================== diff -u -r1c26c2925be758ef3f54ac2e98687f6d9db079d1 -r5dbbc7b9946ede2b5de406e9adb39928e1dda083 --- lams_central/web/includes/javascript/rating.js (.../rating.js) (revision 1c26c2925be758ef3f54ac2e98687f6d9db079d1) +++ lams_central/web/includes/javascript/rating.js (.../rating.js) (revision 5dbbc7b9946ede2b5de406e9adb39928e1dda083) @@ -1,6 +1,6 @@ //Please, set up LAMS_URL, COUNT_RATED_ITEMS, COMMENTS_MIN_WORDS_LIMIT, MAX_RATES and MIN_RATES, MAX_RATINGS_FOR_ITEM, -//COMMENT_TEXTAREA_TIP_LABEL, WARN_COMMENTS_IS_BLANK_LABEL, WARN_MIN_NUMBER_WORDS_LABEL, ALLOW_RERATE constants in parent document +//COMMENT_TEXTAREA_TIP_LABEL, WARN_COMMENTS_IS_BLANK_LABEL, WARN_MIN_NUMBER_WORDS_LABEL, ALLOW_RERATE, SESSION_ID constants in parent document //constant indicating there is rting limits set up var HAS_RATING_LIMITS; @@ -43,9 +43,18 @@ } else { canRateAgain = ALLOW_RERATE; } - + + // if SESSION_ID is not defined do not allow them to update ratings as the servlet will fail. + // But in monitoring we will do initializeJRating to display the ratings properly so then SESSION_ID is undefined. + var phpPathValue; + if ( typeof SESSION_ID === "undefined" || SESSION_ID === undefined ) + phpPathValue = ""; + else + phpPathValue = LAMS_URL + "servlet/rateItem?hasRatingLimits=" + HAS_RATING_LIMITS + "&ratingLimitsByCriteria=" + ratingLimitsByCriteria + + "&maxRatingsForItem=" + maxRatingsForItem + "&toolSessionId=" + SESSION_ID; + $(".rating-stars-new").filter($(".rating-stars")).jRating({ - phpPath : LAMS_URL + "servlet/rateItem?hasRatingLimits=" + HAS_RATING_LIMITS + "&ratingLimitsByCriteria=" + ratingLimitsByCriteria + "&maxRatingsForItem=" + maxRatingsForItem, + phpPath : phpPathValue, rateMax : 5, decimalLength : 1, canRateAgain : canRateAgain, @@ -83,40 +92,43 @@ if ( ! comment ) return false; - //add new comment - $.ajax({ - type: "POST", - url: LAMS_URL + 'servlet/rateItem', - data: { - idBox: commentsCriteriaId + '-' + itemId, - comment: comment, - hasRatingLimits: HAS_RATING_LIMITS, - ratingLimitsByCriteria: ratingLimitsByCriteria, - maxRatingsForItem: maxRatingsForItem - }, - success: function(data, textStatus) { - if ( data.error ) { - handleError(); - } else { - //add comment to HTML - jQuery('
', { - 'class': "rating-comment", - html: data.comment - }).appendTo('#comments-area-' + itemId); - - //hide comments textarea and button - $("#add-comment-area-" + itemId).hide(); - - //handle rating limits if available - if (HAS_RATING_LIMITS) { - handleRatingLimits(data.countRatedItems, itemId); - } - } - }, - onError : function(){ - handleError(); - } - }); + if ( ! ( typeof SESSION_ID === "undefined" || SESSION_ID === undefined ) ) { + //add new comment + $.ajax({ + type: "POST", + url: LAMS_URL + 'servlet/rateItem', + data: { + idBox: commentsCriteriaId + '-' + itemId, + comment: comment, + hasRatingLimits: HAS_RATING_LIMITS, + ratingLimitsByCriteria: ratingLimitsByCriteria, + maxRatingsForItem: maxRatingsForItem, + toolSessionId: SESSION_ID + }, + success: function(data, textStatus) { + if ( data.error ) { + handleError(); + } else { + //add comment to HTML + jQuery('
', { + 'class': "rating-comment", + html: data.comment + }).appendTo('#comments-area-' + itemId); + + //hide comments textarea and button + $("#add-comment-area-" + itemId).hide(); + + //handle rating limits if available + if (HAS_RATING_LIMITS) { + handleRatingLimits(data.countRatedItems, itemId); + } + } + }, + onError : function(){ + handleError(); + } + }); + } //apply only once }).removeClass("add-comment-new"); } Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml =================================================================== diff -u -r8620cb3f29c4710a0ddfd597fdc1b676d4b2b4b0 -r5dbbc7b9946ede2b5de406e9adb39928e1dda083 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (.../Rating.hbm.xml) (revision 8620cb3f29c4710a0ddfd597fdc1b676d4b2b4b0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (.../Rating.hbm.xml) (revision 5dbbc7b9946ede2b5de406e9adb39928e1dda083) @@ -64,6 +64,8 @@ column="rating" /> + +