Index: lams_build/lib/lams/lams.jar
===================================================================
diff -u -rbbd946d0a18f784ff7f72d0cebaaa3828980dfd0 -r7dd6c7cb14fde37748dddaf510d178232d13db84
Binary files differ
Index: lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java
===================================================================
diff -u
--- lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (revision 0)
+++ lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,101 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.web;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.tomcat.util.json.JSONException;
+import org.apache.tomcat.util.json.JSONObject;
+import org.lamsfoundation.lams.rating.dto.RatingDTO;
+import org.lamsfoundation.lams.rating.service.RatingService;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * Stores rating.
+ *
+ * @author Andrey Balan
+ *
+ * @web:servlet name="ratingServlet"
+ * @web:servlet-mapping url-pattern="/servlet/rateItem"
+ */
+public class RatingServlet extends HttpServlet {
+
+ private static Logger log = Logger.getLogger(RatingServlet.class);
+ private static RatingService ratingService;
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ getRatingService();
+
+ float rating = Float.parseFloat((String) request.getParameter("rate"));
+ String objectId = WebUtil.readStrParam(request, "idBox");
+ Long ratingCriteriaId = Long.parseLong(objectId.split("-")[0]);
+ Long itemId = Long.parseLong(objectId.split("-")[1]);
+ UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER);
+ Integer userId = user.getUserID();
+
+ RatingDTO averageRatingDTO = ratingService.rateItem(ratingCriteriaId, userId, itemId, rating);
+
+ // refresh numOfRatings
+ // int numOfRatings = ratingService.getNumOfRatingsByUserAndForum(userUid, forumUid);
+
+ JSONObject JSONObject = new JSONObject();
+ try {
+ JSONObject.put("averageRating", averageRatingDTO.getAverageRating());
+ JSONObject.put("numberOfVotes", averageRatingDTO.getNumberOfVotes());
+
+ } catch (JSONException e) {
+ throw new ServletException(e);
+ }
+ // JSONObject.put("numOfRatings", numOfRatings);
+ response.setContentType("application/json;charset=utf-8");
+ response.getWriter().print(JSONObject);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
+ doGet(request, response);
+ }
+
+ private RatingService getRatingService() {
+ if (ratingService == null) {
+ WebApplicationContext ctx = WebApplicationContextUtils
+ .getRequiredWebApplicationContext(getServletContext());
+ ratingService = (RatingService) ctx.getBean("ratingService");
+ }
+ return ratingService;
+ }
+}
Index: lams_central/web/css/defaultHTML.css
===================================================================
diff -u -r0b85d3d42a2ec95d010ecdf98807043a3522f654 -r7dd6c7cb14fde37748dddaf510d178232d13db84
--- lams_central/web/css/defaultHTML.css (.../defaultHTML.css) (revision 0b85d3d42a2ec95d010ecdf98807043a3522f654)
+++ lams_central/web/css/defaultHTML.css (.../defaultHTML.css) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -1684,4 +1684,37 @@
border: thin solid #2E6E9E !important;
color: #222222 !important;
background-color: #D0E5F5;"
-}
\ No newline at end of file
+}
+
+.rating-criteria-tag {
+ width: 60%;
+ padding-bottom: 25px;
+}
+.rating-criteria-tag input[type="text"] {
+ width: 100%;
+}
+#criterias-table td {
+ vertical-align:middle;
+}
+img.up-arrow, img.up-arrow-disabled, img.down-arrow, img.down-arrow-disabled, img.delete-arrow {
+ width:0px;
+ height:0px;
+ padding: 4px 8px;
+ border:0;
+ background-repeat: no-repeat;
+}
+img.up-arrow {
+ background-image: url('../images/uparrow.gif');
+}
+img.up-arrow-disabled {
+ background-image: url('../images/uparrow_disabled.gif');
+}
+img.down-arrow {
+ background-image: url('../images/downarrow.gif');
+}
+img.down-arrow-disabled {
+ background-image: url('../images/downarrow_disabled.gif');
+}
+img.delete-arrow {
+ background-image: url('../images/disposal.gif');
+}
Index: lams_central/web/css/jquery.jRating.css
===================================================================
diff -u -rf7d806b0ab4f783c2dd89e920d7f6edf370c04db -r7dd6c7cb14fde37748dddaf510d178232d13db84
--- lams_central/web/css/jquery.jRating.css (.../jquery.jRating.css) (revision f7d806b0ab4f783c2dd89e920d7f6edf370c04db)
+++ lams_central/web/css/jquery.jRating.css (.../jquery.jRating.css) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -40,11 +40,17 @@
text-align:center;
padding-top:5px;
}
- p.jRatingInfos span.maxRate {
- color:#c9c9c9;
- font-size:14px;
- }
+p.jRatingInfos span.maxRate {
+ color:#c9c9c9;
+ font-size:14px;
+}
+
/** Please, note this is a LAMS customization. In case of library upgrade copy these lines manually. **/
+.rating-stars-holder {width: 150px; text-align: center;}
+.rating-stars-caption {padding-top: 6px;}
+.rating-stars, .rating-stars-disabled {margin: 0px auto;}
+
+/** Remove the following once we move all tools to use Rating.tag. **/
.rating-stars-div {float:right; padding-right: 10px; margin-top: -8px; min-height: 45px;}
-.rating-stars-caption {text-align: center; padding-top: 6px;}
+.rating-stars-caption {text-align: center}
\ No newline at end of file
Index: lams_central/web/includes/javascript/jquery.jRating.js
===================================================================
diff -u -rf7d806b0ab4f783c2dd89e920d7f6edf370c04db -r7dd6c7cb14fde37748dddaf510d178232d13db84
--- lams_central/web/includes/javascript/jquery.jRating.js (.../jquery.jRating.js) (revision f7d806b0ab4f783c2dd89e920d7f6edf370c04db)
+++ lams_central/web/includes/javascript/jquery.jRating.js (.../jquery.jRating.js) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -62,7 +62,8 @@
$(this).height(starHeight);
var average = parseFloat($(this).attr('data-average')), // get the average of all rates
- idBox = parseInt($(this).attr('data-id')), // get the id of the box
+ //**LAMS** customized. originally it looked like idBox = parseInt($(this).attr('data-id')),
+ idBox = $(this).attr('data-id'), // get the id of the box
widthRatingContainer = starWidth*opts.length, // Width of the Container
widthColor = average/opts.rateMax*widthRatingContainer, // Width of the color Container
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml
===================================================================
diff -u
--- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (revision 0)
+++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml
===================================================================
diff -u
--- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml (revision 0)
+++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+ @hibernate.class table="lams_rating_criteria"
+ true
+
+
+ @hibernate.id generator-class="native" type="java.lang.Long" column="rating_criteria_id"
+
+
+
+
+
+
+ @hibernate.property column="title" length="255"
+
+
+
+ @hibernate.property column="order_id" length="11"
+
+
+
+ @hibernate.property column="rating_criteria_type_id" length="11"
+
+
+
+
+ @hibernate.class
+
+
+
+ @hibernate.class
+
+
+
+
+ @hibernate.class
+
+
+
+
+ @hibernate.class
+
+
+
+ @hibernate.column name="lesson_id"
+
+
+
+
+
+
+
Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml
===================================================================
diff -u -r27f1c5a7f08417a5d6f5e4c7faff092f520078a6 -r7dd6c7cb14fde37748dddaf510d178232d13db84
--- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 27f1c5a7f08417a5d6f5e4c7faff092f520078a6)
+++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -198,7 +198,7 @@
-
+
@@ -222,6 +222,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
+ PROPAGATION_REQUIRED
+
+
+
+
@@ -391,6 +416,14 @@
+
+
+
+
+
+
+
+
Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,57 @@
+-- Turn off autocommit, so nothing is committed if there is an error
+
+SET AUTOCOMMIT = 0;
+SET FOREIGN_KEY_CHECKS=0;
+
+-- LDEV-3450 Implement peer review feature
+CREATE TABLE lams_rating_criteria_type (
+ rating_criteria_type_id INT(11) NOT NULL DEFAULT 0
+ , description VARCHAR(255) NOT NULL
+ , PRIMARY KEY (rating_criteria_type_id)
+)ENGINE=InnoDB;
+
+CREATE TABLE lams_rating_criteria (
+ rating_criteria_id BIGINT(20) NOT NULL AUTO_INCREMENT
+ , title VARCHAR(255)
+ , rating_criteria_type_id INT(11) NOT NULL DEFAULT 0
+ , order_id INT(11) NOT NULL
+ , tool_content_id BIGINT(20)
+ , item_id BIGINT(20)
+ , lesson_id BIGINT(20)
+ , PRIMARY KEY (rating_criteria_id)
+ , INDEX (rating_criteria_type_id)
+ , CONSTRAINT FK_lams_rating_criteria_1 FOREIGN KEY (rating_criteria_type_id)
+ REFERENCES lams_rating_criteria_type (rating_criteria_type_id)
+ , INDEX (tool_content_id)
+ , CONSTRAINT FK_lams_rating_criteria_2 FOREIGN KEY (tool_content_id)
+ REFERENCES lams_tool_content (tool_content_id) ON DELETE NO ACTION ON UPDATE NO ACTION
+ , INDEX (lesson_id)
+ , CONSTRAINT FK_lams_rating_criteria_3 FOREIGN KEY (lesson_id)
+ REFERENCES lams_lesson (lesson_id) ON DELETE NO ACTION ON UPDATE NO ACTION
+)ENGINE=InnoDB;
+
+CREATE TABLE lams_rating (
+ uid BIGINT(20) NOT NULL AUTO_INCREMENT
+ , rating_criteria_id BIGINT(20) NOT NULL
+ , item_id BIGINT(20)
+ , user_id BIGINT(20) NOT NULL
+ , rating FLOAT
+ , PRIMARY KEY (uid)
+ , INDEX (rating_criteria_id)
+ , CONSTRAINT FK_lams_rating_1 FOREIGN KEY (rating_criteria_id)
+ REFERENCES lams_rating_criteria (rating_criteria_id) ON DELETE CASCADE ON UPDATE CASCADE
+ , INDEX (user_id)
+ , CONSTRAINT FK_lams_rating_2 FOREIGN KEY (user_id)
+ REFERENCES lams_user (user_id) ON DELETE CASCADE ON UPDATE CASCADE
+)ENGINE=InnoDB;
+
+INSERT INTO lams_rating_criteria_type VALUES (1, 'TOOL_ACTIVITY');
+INSERT INTO lams_rating_criteria_type VALUES (2, 'AUTHORED_ITEM');
+INSERT INTO lams_rating_criteria_type VALUES (3, 'LEARNER_ITEM');
+INSERT INTO lams_rating_criteria_type VALUES (4, 'LESSON');
+
+
+-- If there were no errors, commit and restore autocommit to on
+SET FOREIGN_KEY_CHECKS=0;
+COMMIT;
+SET AUTOCOMMIT = 1;
Index: lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,70 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+/* $Id$ */
+package org.lamsfoundation.lams.rating;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.lamsfoundation.lams.rating.model.RatingCriteria;
+
+/**
+ * The ratingCriteria order comparator used for sorted set. Order id is used as the primary comparing criteria as it is
+ * unique within a complex ratingCriteria. If they are the same, ratingCriteria id are used for comparison to ensure the
+ * sorted set won't treat two activities with the same order id as the same ratingCriteria. If either of the
+ * ratingCriteria ids are null (activities are not yet saved in the database) use the ratingCriteria ui id. The ui ids
+ * will compare nulls if required, with null being lower than not null. Two nulls will equal true.
+ *
+ * @author andreyb
+ */
+public class RatingCriteriaOrderComparator implements Comparator, Serializable {
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ RatingCriteria ratingCriteria1 = (RatingCriteria) o1;
+ RatingCriteria ratingCriteria2 = (RatingCriteria) o2;
+
+ if (ratingCriteria1.getOrderId() == null || ratingCriteria2.getOrderId() == null)
+ return compareRatingCriteriaId(ratingCriteria1, ratingCriteria2);
+
+ int orderDiff = ratingCriteria1.getOrderId().compareTo(ratingCriteria2.getOrderId());
+ // return order id compare result if they are not the same
+ if (orderDiff != 0)
+ return orderDiff;
+ // if order id are the same, compare ratingCriteria id.
+ else
+ return compareRatingCriteriaId(ratingCriteria1, ratingCriteria2);
+ }
+
+ private int compareRatingCriteriaId(RatingCriteria ratingCriteria1, RatingCriteria ratingCriteria2) {
+ if (ratingCriteria1.getRatingCriteriaId() == null && ratingCriteria2.getRatingCriteriaId() == null) {
+ return 0;
+ }
+ if (ratingCriteria1.getRatingCriteriaId() == null) {
+ return -1;
+ }
+ if (ratingCriteria2.getRatingCriteriaId() == null) {
+ return 1;
+ }
+ return ratingCriteria1.getRatingCriteriaId().compareTo(ratingCriteria2.getRatingCriteriaId());
+ }
+}
Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.rating.dao;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.rating.model.RatingCriteria;
+
+public interface IRatingCriteriaDAO {
+
+ void saveOrUpdate(RatingCriteria criteria);
+
+ void deleteRatingCriteria(Long ratingCriteriaId);
+
+ List getByToolContentId(Long toolContentId);
+
+ RatingCriteria getByUid(Long ratingCriteriaId);
+
+}
Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+
+package org.lamsfoundation.lams.rating.dao;
+
+import org.lamsfoundation.lams.rating.dto.RatingDTO;
+import org.lamsfoundation.lams.rating.model.Rating;
+
+public interface IRatingDAO {
+
+ void saveOrUpdate(Rating rating);
+
+ Rating getRating(Long ratingCriteriaId, Integer userId, Long itemId);
+
+ Rating getRating(Long ratingCriteriaId, Integer userId);
+
+ /**
+ * Returns rating statistics by particular item
+ *
+ * @param itemId
+ * @return
+ */
+ RatingDTO getRatingAverageDTOByItem(Long ratingCriteriaId, Long itemId);
+
+ RatingDTO getRatingAverageDTOByUser(Long ratingCriteriaId, Long itemId, Integer userId);
+
+ Rating get(Long uid);
+
+}
Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,65 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.rating.dao.hibernate;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.dao.hibernate.BaseDAO;
+import org.lamsfoundation.lams.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.rating.dao.IRatingCriteriaDAO;
+import org.lamsfoundation.lams.rating.model.Rating;
+import org.lamsfoundation.lams.rating.model.RatingCriteria;
+import org.lamsfoundation.lams.rating.model.ToolActivityRatingCriteria;
+
+public class RatingCriteriaDAO extends BaseDAO implements IRatingCriteriaDAO {
+
+ private static final String FIND_BY_TOOL_CONTENT_ID = "from " + RatingCriteria.class.getName()
+ + " as r where r.toolContentId=? order by r.orderId asc";
+
+ @Override
+ public void saveOrUpdate(RatingCriteria criteria) {
+ this.getHibernateTemplate().saveOrUpdate(criteria);
+ this.getHibernateTemplate().flush();
+ }
+
+ @Override
+ public void deleteRatingCriteria(Long ratingCriteriaId) {
+ this.deleteById(RatingCriteria.class, ratingCriteriaId);
+ }
+
+ @Override
+ public List getByToolContentId(Long toolContentId) {
+ return (List) (getHibernateTemplate().find(FIND_BY_TOOL_CONTENT_ID,
+ new Object[] { toolContentId }));
+ }
+
+ public RatingCriteria getByUid(Long ratingCriteriaId) {
+ if (ratingCriteriaId != null) {
+ Object o = getHibernateTemplate().get(RatingCriteria.class, ratingCriteriaId);
+ return (RatingCriteria) o;
+ } else {
+ return null;
+ }
+ }
+}
Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java
===================================================================
diff -u
--- lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java (revision 0)
+++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84)
@@ -0,0 +1,115 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+
+package org.lamsfoundation.lams.rating.dao.hibernate;
+
+import java.text.NumberFormat;
+import java.util.List;
+import java.util.Locale;
+
+import org.lamsfoundation.lams.dao.hibernate.BaseDAO;
+import org.lamsfoundation.lams.rating.dao.IRatingDAO;
+import org.lamsfoundation.lams.rating.dto.RatingDTO;
+import org.lamsfoundation.lams.rating.model.Rating;
+
+public class RatingDAO extends BaseDAO implements IRatingDAO {
+
+ private static final String FIND_RATING_BY_CRITERIA_AND_USER_AND_ITEM = "FROM " + Rating.class.getName()
+ + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=? AND r.itemId=?";
+ private static final String FIND_RATING_VALUE = "SELECT r.rating FROM " + Rating.class.getName()
+ + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=? AND r.itemId=?";
+ private static final String FIND_RATING_BY_CRITERIA_AND_USER = "FROM " + Rating.class.getName()
+ + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=?";
+ private static final String FIND_RATING_AVERAGE_BY_ITEM = "SELECT AVG(r.rating), COUNT(*) FROM "
+ + Rating.class.getName() + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.itemId=?";
+
+ @Override
+ public void saveOrUpdate(Rating rating) {
+ this.getHibernateTemplate().saveOrUpdate(rating);
+ this.getHibernateTemplate().flush();
+ }
+
+ @Override
+ public Rating getRating(Long ratingCriteriaId, Integer userId, Long itemId) {
+ List list = getHibernateTemplate().find(FIND_RATING_BY_CRITERIA_AND_USER_AND_ITEM,
+ new Object[] { ratingCriteriaId, userId, itemId });
+ if (list.size() > 0) {
+ return (Rating) list.get(0);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Rating getRating(Long ratingCriteriaId, Integer userId) {
+ List list = getHibernateTemplate().find(FIND_RATING_BY_CRITERIA_AND_USER,
+ new Object[] { ratingCriteriaId, userId });
+ if (list.size() > 0) {
+ return (Rating) list.get(0);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public RatingDTO getRatingAverageDTOByItem(Long ratingCriteriaId, Long itemId) {
+ List