Index: lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r59192abca4167aef55fee0d559349575ee330cd0 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 59192abca4167aef55fee0d559349575ee330cd0) +++ lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -195,4 +195,8 @@ label.burning.question =Burning question label.general.burning.question =General burning question +label.count =Count +label.like =Like +label.unlike =Unlike + #======= End labels: Exported 182 labels for en AU ===== Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r0e47151ba97eed4c2638f8dcc4fff17d4d0d225c -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 0e47151ba97eed4c2638f8dcc4fff17d4d0d225c) +++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -212,6 +212,14 @@ + + + + getBurningQuestionsByItemUid(Long itemUid); + List getBurningQuestionsByContentId(Long scratchieUid, Long sessionId); ScratchieBurningQuestion getBurningQuestionBySessionAndItem(Long sessionId, Long itemUid); Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -0,0 +1,37 @@ +package org.lamsfoundation.lams.tool.scratchie.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.tool.scratchie.dao.BurningQuestionLikeDAO; +import org.lamsfoundation.lams.tool.scratchie.model.BurningQuestionLike; +import org.springframework.orm.hibernate3.support.HibernateDaoSupport; + +public class BurningQuestionLikeDAOHibernate extends HibernateDaoSupport implements BurningQuestionLikeDAO { + + private static String INSERT_LIKE = "INSERT IGNORE INTO tl_lascrt11_burning_que_like(burning_question_uid, session_id) VALUES (:burningQuestionUid,:sessionId);"; + + public boolean addLike(Long burningQuestionUid, Long sessionId) { + int status = getSession().createSQLQuery(INSERT_LIKE) + .setParameter("burningQuestionUid", burningQuestionUid) + .setParameter("sessionId", sessionId) + .executeUpdate(); + return status == 1; + } + + public void removeLike(Long burningQuestionUid, Long sessionId) { + + final String FIND_BY_SESSION_AND_BURNING_QUESTION = "from " + BurningQuestionLike.class.getName() + + " as l where l.sessionId=? and l.burningQuestion.uid = ?"; + + List list = getHibernateTemplate().find(FIND_BY_SESSION_AND_BURNING_QUESTION, new Object[] {sessionId, burningQuestionUid}); + if (list == null || list.size() == 0) { + return; + } + BurningQuestionLike like = list.get(0); + + if (like != null) { + getHibernateTemplate().delete(like); + } + } + +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java =================================================================== diff -u -r447eb31b1898bb52f8c723f3e91f3a94fdae497d -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java (.../ScratchieBurningQuestionDAOHibernate.java) (revision 447eb31b1898bb52f8c723f3e91f3a94fdae497d) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java (.../ScratchieBurningQuestionDAOHibernate.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -23,9 +23,13 @@ /* $Id$ */ package org.lamsfoundation.lams.tool.scratchie.dao.hibernate; +import java.util.ArrayList; import java.util.List; +import org.hibernate.Hibernate; +import org.hibernate.SQLQuery; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieBurningQuestionDAO; +import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieBurningQuestion; public class ScratchieBurningQuestionDAOHibernate extends BaseDAOHibernate implements ScratchieBurningQuestionDAO { @@ -39,17 +43,56 @@ private static final String FIND_BY_SESSION = "from " + ScratchieBurningQuestion.class.getName() + " as r where r.sessionId=?"; - private static final String FIND_BY_ITEM_UID = "from " + ScratchieBurningQuestion.class.getName() + private static final String FIND_BY_CONTENT_ID = "from " + ScratchieBurningQuestion.class.getName() + " as r where r.scratchieItem.uid=? order by r.sessionId asc"; // @Override // public List getBurningQuestionsByContentId(Long contentId) { // return getHibernateTemplate().find(FIND_BY_CONTENT_ID, new Object[] { contentId}); // } - + @Override - public List getBurningQuestionsByItemUid(Long itemUid) { - return getHibernateTemplate().find(FIND_BY_ITEM_UID, new Object[] { itemUid}); + @SuppressWarnings("unchecked") + public List getBurningQuestionsByContentId(Long scratchieUid, Long sessionId) { + + /* Thread based lookups - Returns a complex structure so that the likes information can be passed + * back with it. */ + final String GET_BURNING_QUESTIONS_WITH_LIKES = + "SELECT bq.*, session.session_name sessionName, count(like1.uid) total_likes, like2.uid user_like FROM tl_lascrt11_burning_question bq " + + " JOIN tl_lascrt11_session session" + + " ON session.scratchie_uid = :scratchieUid AND bq.session_id = session.session_id " + + " LEFT JOIN tl_lascrt11_burning_que_like like1 ON bq.uid = like1.burning_question_uid " + + " LEFT JOIN tl_lascrt11_burning_que_like like2 ON bq.uid = like2.burning_question_uid AND like2.session_id=:sessionId " + + " WHERE bq.question IS NOT NULL AND bq.question != ''" + + " GROUP BY bq.uid"; + + SQLQuery query = getSession().createSQLQuery(GET_BURNING_QUESTIONS_WITH_LIKES); + query.addEntity("bq", ScratchieBurningQuestion.class) + .addScalar("sessionName", Hibernate.STRING) + .addScalar("total_likes", Hibernate.INTEGER) + .addScalar("user_like", Hibernate.LONG) + .setLong("sessionId", sessionId != null ? sessionId : 0) + .setLong("scratchieUid", scratchieUid); + List rawObjects = query.list(); + +// Comparator comparator = ICommentService.SORT_BY_LIKE.equals(sortBy) ? new TopicComparatorLike() : new TopicComparator(); +// SortedSet results = new TreeSet(comparator); + List results = new ArrayList(); + for ( Object[] rawObject : rawObjects ) { + + ScratchieBurningQuestion burningQuestion = (ScratchieBurningQuestion) rawObject[0]; + String sessionName = (String) rawObject[1]; + Integer likeCount = (Integer) rawObject[2]; + Long userLikeUid = (Long) rawObject[3]; + + BurningQuestionDTO burningQuestionDTO = new BurningQuestionDTO(); + burningQuestionDTO.setBurningQuestion(burningQuestion); + burningQuestionDTO.setLikeCount(likeCount != null ? likeCount : 0); + burningQuestionDTO.setUserLikeUid(userLikeUid); + burningQuestionDTO.setSessionName(sessionName); + results.add(burningQuestionDTO); + } + return results; } @Override Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20160329.sql =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20160329.sql (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20160329.sql (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -0,0 +1,22 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; +SET FOREIGN_KEY_CHECKS=0; +----------------------Put all sql statements below here------------------------- + +-- LDEV- +--ALTER TABLE tl_lascrt11_scratchie ADD COLUMN burning_questions_enabled TINYINT DEFAULT 1; +CREATE TABLE tl_lascrt11_burning_que_like ( + uid bigint NOT NULL auto_increment, + burning_question_uid BIGINT, + session_id bigint, + PRIMARY KEY (uid) +)ENGINE=InnoDB; +ALTER TABLE tl_lascrt11_burning_que_like ADD INDEX FK_burning_que_uid (burning_question_uid), ADD CONSTRAINT FK_burning_que_uid FOREIGN KEY (burning_question_uid) REFERENCES tl_lascrt11_burning_question (uid) ON DELETE CASCADE ON UPDATE CASCADE; + + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; +SET FOREIGN_KEY_CHECKS=1; Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionDTO.java =================================================================== diff -u -r2adb14cdb105f3e0e72bd3c052e9dc254949049b -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionDTO.java (.../BurningQuestionDTO.java) (revision 2adb14cdb105f3e0e72bd3c052e9dc254949049b) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionDTO.java (.../BurningQuestionDTO.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -23,29 +23,53 @@ /* $Id$ */ package org.lamsfoundation.lams.tool.scratchie.dto; -import java.util.Map; - import org.lamsfoundation.lams.tool.scratchie.model.ScratchieBurningQuestion; -import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; public class BurningQuestionDTO { - private ScratchieItem item; + private ScratchieBurningQuestion burningQuestion; + private String escapedBurningQuestion; + private String sessionName; - private Map groupNameToBurningQuestion; + private Integer likeCount; + private Long userLikeUid; - public ScratchieItem getItem() { - return item; + public ScratchieBurningQuestion getBurningQuestion() { + return burningQuestion; } - public void setItem(ScratchieItem item) { - this.item = item; + public void setBurningQuestion(ScratchieBurningQuestion burningQuestion) { + this.burningQuestion = burningQuestion; } + + public String getEscapedBurningQuestion() { + return escapedBurningQuestion; + } - public Map getGroupNameToBurningQuestion() { - return groupNameToBurningQuestion; + public void setEscapedBurningQuestion(String escapedBurningQuestion) { + this.escapedBurningQuestion = escapedBurningQuestion; } + + public String getSessionName() { + return sessionName; + } - public void setGroupNameToBurningQuestion(Map leaderNameToBurningQuestion) { - this.groupNameToBurningQuestion = leaderNameToBurningQuestion; + public void setSessionName(String sessionName) { + this.sessionName = sessionName; } + + public Integer getLikeCount() { + return likeCount; + } + + public void setLikeCount(Integer likeCount) { + this.likeCount = likeCount; + } + + public Long getUserLikeUid() { + return userLikeUid; + } + + public void setUserLikeUid(Long userLikeUid) { + this.userLikeUid = userLikeUid; + } } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionItemDTO.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionItemDTO.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dto/BurningQuestionItemDTO.java (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -0,0 +1,29 @@ +package org.lamsfoundation.lams.tool.scratchie.dto; + +import java.util.List; + +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; + +/** + * Holds all non empty burning questions for the specified ScratchieItem. + */ +public class BurningQuestionItemDTO { + private ScratchieItem scratchieItem; + private List burningQuestionDtos; + + public ScratchieItem getScratchieItem() { + return scratchieItem; + } + + public void setScratchieItem(ScratchieItem scratchieItem) { + this.scratchieItem = scratchieItem; + } + + public List getBurningQuestionDtos() { + return burningQuestionDtos; + } + + public void setBurningQuestionDtos(List burningQuestionDtos) { + this.burningQuestionDtos = burningQuestionDtos; + } +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/BurningQuestionLike.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/BurningQuestionLike.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/BurningQuestionLike.java (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -0,0 +1,50 @@ +package org.lamsfoundation.lams.tool.scratchie.model; + +/** + * @author Andrey Balan + * + * @hibernate.class table="tl_lascrt11_burning_que_like" + */ +public class BurningQuestionLike { + + private Long uid; + private ScratchieBurningQuestion burningQuestion; + private Long sessionId; + + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * @return Returns the log Uid. + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + /** + * @hibernate.many-to-one column="burning_question_uid" cascade="none" + * @return + */ + public ScratchieBurningQuestion getBurningQuestion() { + return burningQuestion; + } + + public void setBurningQuestion(ScratchieBurningQuestion burningQuestion) { + this.burningQuestion = burningQuestion; + } + + /** + * @hibernate.property column="session_id" + * @return + */ + public Long getSessionId() { + return sessionId; + } + + public void setSessionId(Long sessionId) { + this.sessionId = sessionId; + } + +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml =================================================================== diff -u -r73c1472c62db79b6ec21be7a5cba1d901f193013 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision 73c1472c62db79b6ec21be7a5cba1d901f193013) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -31,6 +31,11 @@ + + + + + @@ -73,6 +78,9 @@ + + + Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -r447eb31b1898bb52f8c723f3e91f3a94fdae497d -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision 447eb31b1898bb52f8c723f3e91f3a94fdae497d) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -31,6 +31,7 @@ import org.lamsfoundation.lams.events.IEventNotificationService; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; +import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; import org.lamsfoundation.lams.tool.scratchie.dto.GroupSummary; import org.lamsfoundation.lams.tool.scratchie.dto.ReflectDTO; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; @@ -227,10 +228,15 @@ * Get BurningQuestionDtos used for summary tab * * @param scratchie + * @param sessionId optional parameter, if it's specified, BurningQuestionDTO will also contain whether leader liked * @return */ - List getBurningQuestionDtos(Scratchie scratchie); + List getBurningQuestionDtos(Scratchie scratchie, Long sessionId); + boolean addLike(Long burningQuestionUid, Long sessionId); + + void removeLike(Long burningQuestionUid, Long sessionId); + /** * Export excel spreadheet * Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -reb5846868ef426639cefa14bfb5881f2cb68ad63 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision eb5846868ef426639cefa14bfb5881f2cb68ad63) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -41,6 +41,7 @@ import java.util.SortedMap; import java.util.TreeSet; +import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -68,6 +69,7 @@ import org.lamsfoundation.lams.tool.exception.DataMissingException; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; +import org.lamsfoundation.lams.tool.scratchie.dao.BurningQuestionLikeDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieAnswerVisitDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieBurningQuestionDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieConfigItemDAO; @@ -76,6 +78,7 @@ import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieSessionDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieUserDAO; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; +import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; import org.lamsfoundation.lams.tool.scratchie.dto.GroupSummary; import org.lamsfoundation.lams.tool.scratchie.dto.ReflectDTO; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; @@ -118,6 +121,8 @@ private ScratchieAnswerVisitDAO scratchieAnswerVisitDao; private ScratchieBurningQuestionDAO scratchieBurningQuestionDao; + + private BurningQuestionLikeDAO burningQuestionLikeDao; private ScratchieConfigItemDAO scratchieConfigItemDao; @@ -777,68 +782,75 @@ } @Override - public List getBurningQuestionDtos(Scratchie scratchie) { + public List getBurningQuestionDtos(Scratchie scratchie, Long sessionId) { Set items = new TreeSet(new ScratchieItemComparator()); items.addAll(scratchie.getScratchieItems()); - // get all available leaders associated with this content as only leaders have reflections - List sessionList = scratchieSessionDao.getByContentId(scratchie.getContentId()); - - List burningQuestionDtos = new LinkedList(); + List burningQuestionDtos = scratchieBurningQuestionDao + .getBurningQuestionsByContentId(scratchie.getUid(), sessionId); + + List burningQuestionItemDtos = new ArrayList(); for (ScratchieItem item : items) { - BurningQuestionDTO burningQuestionDTO = new BurningQuestionDTO(); - burningQuestionDTO.setItem(item); - List burningQuestions = scratchieBurningQuestionDao - .getBurningQuestionsByItemUid(item.getUid()); + List burningQuestionDtosOfSpecifiedItem = new ArrayList(); - Map groupNameToBurningQuestion = new LinkedHashMap(); - for (ScratchieBurningQuestion burningQuestion : burningQuestions) { - - // find corresponding session - ScratchieSession session = null; - for (ScratchieSession sessionIter : sessionList) { - if (burningQuestion.getSessionId().equals(sessionIter.getSessionId())) { - session = sessionIter; - break; - } + for (BurningQuestionDTO burningQuestionDto : burningQuestionDtos) { + ScratchieBurningQuestion burningQuestion = burningQuestionDto.getBurningQuestion(); + + if (!burningQuestion.isGeneralQuestion() && item.getUid().equals(burningQuestion.getScratchieItem().getUid())) { + burningQuestionDtosOfSpecifiedItem.add(burningQuestionDto); } - - String groupName = StringEscapeUtils.escapeJavaScript(session.getSessionName()); - String burningQuestionText = StringEscapeUtils.escapeJavaScript(burningQuestion.getQuestion()); - groupNameToBurningQuestion.put(groupName, burningQuestionText); } - burningQuestionDTO.setGroupNameToBurningQuestion(groupNameToBurningQuestion); - - burningQuestionDtos.add(burningQuestionDTO); + + BurningQuestionItemDTO burningQuestionItemDto = new BurningQuestionItemDTO(); + burningQuestionItemDto.setScratchieItem(item); + burningQuestionItemDto.setBurningQuestionDtos(burningQuestionDtosOfSpecifiedItem); + burningQuestionItemDtos.add(burningQuestionItemDto); } - // general burning question - BurningQuestionDTO generalBurningQuestionDTO = new BurningQuestionDTO(); + // handle general burning question + BurningQuestionItemDTO generalBurningQuestionItemDto = new BurningQuestionItemDTO(); ScratchieItem generalDummyItem = new ScratchieItem(); generalDummyItem.setUid(0L); final String generalQuestionMessage = messageService.getMessage("label.general.burning.question"); generalDummyItem.setTitle(generalQuestionMessage); - generalBurningQuestionDTO.setItem(generalDummyItem); - Map groupNameToBurningQuestion = new LinkedHashMap(); - generalBurningQuestionDTO.setGroupNameToBurningQuestion(groupNameToBurningQuestion); - for (ScratchieSession session : sessionList) { - - ScratchieBurningQuestion burningQuestion = scratchieBurningQuestionDao - .getGeneralBurningQuestionBySession(session.getSessionId()); - if (burningQuestion == null) { - continue; + generalBurningQuestionItemDto.setScratchieItem(generalDummyItem); + List burningQuestionDtosOfSpecifiedItem = new ArrayList(); + for (BurningQuestionDTO burningQuestionDto : burningQuestionDtos) { + ScratchieBurningQuestion burningQuestion = burningQuestionDto.getBurningQuestion(); + + if (burningQuestion.isGeneralQuestion()) { + burningQuestionDtosOfSpecifiedItem.add(burningQuestionDto); } + } + generalBurningQuestionItemDto.setBurningQuestionDtos(burningQuestionDtosOfSpecifiedItem); + burningQuestionItemDtos.add(generalBurningQuestionItemDto); + + //escape for Javascript + for (BurningQuestionItemDTO burningQuestionItemDto : burningQuestionItemDtos) { + for (BurningQuestionDTO burningQuestionDto : burningQuestionItemDto.getBurningQuestionDtos()) { + String escapedSessionName = StringEscapeUtils.escapeJavaScript(burningQuestionDto.getSessionName()); + burningQuestionDto.setSessionName(escapedSessionName); - String groupName = StringEscapeUtils.escapeJavaScript(session.getSessionName()); - String burningQuestionText = StringEscapeUtils.escapeJavaScript(burningQuestion.getQuestion()); - groupNameToBurningQuestion.put(groupName, burningQuestionText); + String escapedBurningQuestion = StringEscapeUtils + .escapeJavaScript(burningQuestionDto.getBurningQuestion().getQuestion()); + burningQuestionDto.setEscapedBurningQuestion(escapedBurningQuestion); + } } - burningQuestionDtos.add(generalBurningQuestionDTO); - return burningQuestionDtos; + return burningQuestionItemDtos; } + + @Override + public boolean addLike(Long burningQuestionUid, Long sessionId) { + return burningQuestionLikeDao.addLike(burningQuestionUid, sessionId); + } + + @Override + public void removeLike(Long burningQuestionUid, Long sessionId) { + burningQuestionLikeDao.removeLike(burningQuestionUid, sessionId); + } @Override public List getReflectionList(Long contentId) { @@ -1048,7 +1060,8 @@ for (int i = 0; i < percentages.length; i++) { sum += percentages[i]; } - int avgMean = sum / percentages.length; + int percentagesLength = percentages.length == 0 ? 1 : percentages.length; + int avgMean = sum / percentagesLength; row = new ExcelCell[numberOfItems + 3]; row[0] = new ExcelCell(getMessage("label.avg.mean"), false); row[numberOfItems + 2] = new ExcelCell(avgMean + "%", false); @@ -1467,18 +1480,18 @@ rowList.add(row); rowList.add(ScratchieServiceImpl.EMPTY_ROW); - List burningQuestionDtos = getBurningQuestionDtos(scratchie); - for (BurningQuestionDTO burningQuestionDto : burningQuestionDtos) { - ScratchieItem item = burningQuestionDto.getItem(); + List burningQuestionItemDtos = getBurningQuestionDtos(scratchie, null); + for (BurningQuestionItemDTO burningQuestionItemDto : burningQuestionItemDtos) { + ScratchieItem item = burningQuestionItemDto.getScratchieItem(); row = new ExcelCell[1]; row[0] = new ExcelCell(item.getTitle(), false); rowList.add(row); - Map groupNameToBurningQuestion = burningQuestionDto.getGroupNameToBurningQuestion(); - for (String groupName : groupNameToBurningQuestion.keySet()) { - String burningQuestion = groupNameToBurningQuestion.get(groupName); + List burningQuestionDtos = burningQuestionItemDto.getBurningQuestionDtos(); + for (BurningQuestionDTO burningQuestionDto : burningQuestionDtos) { + String burningQuestion = burningQuestionDto.getBurningQuestion().getQuestion(); row = new ExcelCell[2]; - row[0] = new ExcelCell(groupName, false); + row[0] = new ExcelCell(burningQuestionDto.getSessionName(), false); row[1] = new ExcelCell(burningQuestion, false); rowList.add(row); } @@ -1644,6 +1657,10 @@ public void setScratchieBurningQuestionDao(ScratchieBurningQuestionDAO scratchieBurningQuestionDao) { this.scratchieBurningQuestionDao = scratchieBurningQuestionDao; } + + public void setBurningQuestionLikeDao(BurningQuestionLikeDAO burningQuestionLikeDao) { + this.burningQuestionLikeDao = burningQuestionLikeDao; + } public void setScratchieConfigItemDao(ScratchieConfigItemDAO scratchieConfigItemDao) { this.scratchieConfigItemDao = scratchieConfigItemDao; Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== diff -u -r82cc782937edbef30643db2908ccac010247ea56 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 82cc782937edbef30643db2908ccac010247ea56) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -55,7 +55,7 @@ import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; -import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; +import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; import org.lamsfoundation.lams.tool.scratchie.dto.ReflectDTO; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswer; @@ -116,6 +116,12 @@ if (param.equals("showResults")) { return showResults(mapping, form, request, response); } + if (param.equals("like")) { + return like(mapping, form, request, response); + } + if (param.equals("removeLike")) { + return removeLike(mapping, form, request, response); + } // ================ Reflection ======================= if (param.equals("newReflection")) { @@ -503,8 +509,8 @@ // display other groups' BurningQuestions if (isBurningQuestionsEnabled) { Scratchie scratchie = toolSession.getScratchie(); - List burningQuestionDtos = LearningAction.service.getBurningQuestionDtos(scratchie); - request.setAttribute(ScratchieConstants.ATTR_BURNING_QUESTIONS_DTOS, burningQuestionDtos); + List burningQuestionItemDtos = LearningAction.service.getBurningQuestionDtos(scratchie, toolSessionId); + request.setAttribute(ScratchieConstants.ATTR_BURNING_QUESTION_ITEM_DTOS, burningQuestionItemDtos); } // display other groups' notebooks @@ -533,8 +539,66 @@ return mapping.findForward(ScratchieConstants.SUCCESS); } + + /** + * @throws ServletException + * @throws ScratchieApplicationException + */ + private synchronized ActionForward like(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException, ServletException, ScratchieApplicationException { + initializeScratchieService(); + + String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); + final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); + ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(sessionId); + Long burningQuestionUid = WebUtil.readLongParam(request, ScratchieConstants.PARAM_BURNING_QUESTION_UID); + + ScratchieUser leader = this.getCurrentUser(sessionId); + // only leader is allowed to scratch answers + if (!toolSession.isUserGroupLeader(leader.getUid())) { + return null; + } + + boolean added = service.addLike(burningQuestionUid, sessionId); + + JSONObject JSONObject = new JSONObject(); + JSONObject.put("added", added); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(JSONObject); + return null; + } + /** + * @throws ServletException + * @throws ScratchieApplicationException + */ + private synchronized ActionForward removeLike(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException, ServletException, ScratchieApplicationException { + initializeScratchieService(); + + String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); + final Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); + ScratchieSession toolSession = LearningAction.service.getScratchieSessionBySessionId(sessionId); + + Long burningQuestionUid = WebUtil.readLongParam(request, ScratchieConstants.PARAM_BURNING_QUESTION_UID); + + ScratchieUser leader = this.getCurrentUser(sessionId); + // only leader is allowed to scratch answers + if (!toolSession.isUserGroupLeader(leader.getUid())) { + return null; + } + + service.removeLike(burningQuestionUid, sessionId); + + return null; + } + + /** * Finish learning session. * * @param mapping Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java =================================================================== diff -u -r2adb14cdb105f3e0e72bd3c052e9dc254949049b -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 2adb14cdb105f3e0e72bd3c052e9dc254949049b) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -46,6 +46,7 @@ import org.apache.struts.action.ActionMapping; import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO; +import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionItemDTO; import org.lamsfoundation.lams.tool.scratchie.dto.GroupSummary; import org.lamsfoundation.lams.tool.scratchie.dto.ReflectDTO; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; @@ -134,8 +135,8 @@ // Create BurningQuestionsDtos if BurningQuestions is enabled. if (scratchie.isBurningQuestionsEnabled()) { - List burningQuestionDtos = service.getBurningQuestionDtos(scratchie); - sessionMap.put(ScratchieConstants.ATTR_BURNING_QUESTIONS_DTOS, burningQuestionDtos); + List burningQuestionItemDtos = service.getBurningQuestionDtos(scratchie, null); + sessionMap.put(ScratchieConstants.ATTR_BURNING_QUESTION_ITEM_DTOS, burningQuestionItemDtos); } // Create reflectList if reflection is enabled. Index: lams_tool_scratchie/web/pages/learning/results.jsp =================================================================== diff -u -r313f8d6b66048cd3257c069e73343bc92ff2cb02 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/web/pages/learning/results.jsp (.../results.jsp) (revision 313f8d6b66048cd3257c069e73343bc92ff2cb02) +++ lams_tool_scratchie/web/pages/learning/results.jsp (.../results.jsp) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -19,6 +19,7 @@ + @@ -131,6 +206,12 @@

+ +
+ + + +

@@ -153,23 +234,18 @@ - +

- +
-
+
- -
-
-
- Index: lams_tool_scratchie/web/pages/monitoring/summary.jsp =================================================================== diff -u -r313f8d6b66048cd3257c069e73343bc92ff2cb02 -rf8801506e4b6b221595fb585797851a9a6a09404 --- lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 313f8d6b66048cd3257c069e73343bc92ff2cb02) +++ lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision f8801506e4b6b221595fb585797851a9a6a09404) @@ -93,37 +93,40 @@
- - - jQuery("#burningQuestions${burningQuestionDto.item.uid}").jqGrid({ + + + + + jQuery("#burningQuestions${scratchieItem.uid}").jqGrid({ datatype: "local", rowNum: 10000, height: 'auto', autowidth: true, shrinkToFit: false, colNames:['#', "", - "" + "", + "" ], colModel:[ {name:'id', index:'id', width:0, sorttype:"int", hidden: true}, {name:'groupName', index:'groupName', width:200}, - {name:'feedback', index:'feedback', width:570} + {name:'feedback', index:'feedback', width:530}, + {name:'count', index:'count', width:40} ], - caption: "${burningQuestionDto.item.title}" + caption: "${scratchieItem.title}" }); - - - - - jQuery("#burningQuestions${burningQuestionDto.item.uid}").addRowData(${i.index + 1}, { + + + jQuery("#burningQuestions${scratchieItem.uid}").addRowData(${i.index + 1}, { id:"${i.index + 1}", - groupName:"${groupName}", - feedback:"" + groupName:"${burningQuestionDto.sessionName}", + feedback:"", + count:"${burningQuestionDto.likeCount}" }); - jQuery("#burningQuestions${burningQuestionDto.item.uid}").jqGrid('sortGrid','groupName', false, 'asc'); + jQuery("#burningQuestions${scratchieItem.uid}").jqGrid('sortGrid','groupName', false, 'asc'); @@ -305,7 +308,7 @@
- +
@@ -314,16 +317,11 @@
- +
-
+
- - -
-
-