Index: lams_central/web/qb/collection.jsp =================================================================== diff -u -r5129d828c41c0731ee7889271cffde6421e2146c -r2470adfeccc15e927183270be2835deea00451c7 --- lams_central/web/qb/collection.jsp (.../collection.jsp) (revision 5129d828c41c0731ee7889271cffde6421e2146c) +++ lams_central/web/qb/collection.jsp (.../collection.jsp) (revision 2470adfeccc15e927183270be2835deea00451c7) @@ -126,7 +126,7 @@ {name:'questionType', index:'questionType', width:0, hidden: true}, {name:'questionVersion', index:'questionVersion', width:0, hidden: true}, {name: 'learningOutcomes', index: 'learningOutcomes', sortable:true, search:true, autoencode: true, width: 25, formatter: learningOutcomeFormatter}, - {name: 'usage', index: 'usage', sortable:false, width: 10, align: "center"}, + {name: 'usage', index: 'usage', sortable:true, width: 15, align: "center"}, // formatter gets just question uid and creates a button {name:'actions', index:'actions', classes: "stats-cell", sortable:false, width: 13, align: "center", formatter: actionsFormatter}, {name:'hasVersions', index:'hasVersions', width:0, hidden: true} @@ -176,7 +176,7 @@ ], colModel: [ {name:'id', index:'question_id', sortable:false, hidden:true, width: 10}, - {name:'name', index:'name', sortable:false, search:false, autoencode:true, formatter: questionNameFormatter}, + {name:'name', index:'name', sortable:false, search:false, autoencode:false, formatter: questionNameFormatter}, {name:'questionType', index:'questionType', width:0, hidden: true}, {name:'questionVersion', index:'questionVersion', width:0, hidden: true}, {name: 'learningOutcomes', index: 'learningOutcomes', width:0, hidden: true}, Index: lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java =================================================================== diff -u -r03a003d5613ffaac6f9b96bef5170e9743642808 -r2470adfeccc15e927183270be2835deea00451c7 --- lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 03a003d5613ffaac6f9b96bef5170e9743642808) +++ lams_common/src/java/org/lamsfoundation/lams/qb/dao/hibernate/QbDAO.java (.../QbDAO.java) (revision 2470adfeccc15e927183270be2835deea00451c7) @@ -63,8 +63,16 @@ private static final String FIND_COLLECTION_QUESTIONS = "SELECT q.* FROM lams_qb_collection_question AS cq " + "JOIN lams_qb_question AS q ON cq.qb_question_id = q.question_id WHERE " + "q.version = (SELECT MAX(version) FROM lams_qb_question WHERE question_id = q.question_id) " - + "AND cq.collection_uid = :collectionUid"; + + "AND cq.collection_uid = :collectionUid ?"; + private static final String FIND_COLLECTION_QUESTIONS_BY_USAGE = "SELECT q.* FROM lams_qb_collection_question AS cq " + + "JOIN lams_qb_question AS q ON cq.qb_question_id = q.question_id " + + "JOIN lams_qb_tool_question AS tq ON q.uid = tq.qb_question_uid " + + "JOIN lams_learning_activity AS a USING (tool_content_id) " + + "JOIN lams_lesson AS l USING (learning_design_id) WHERE l.lesson_state_id IN (3,4,5,6) " + + "AND q.version = (SELECT MAX(version) FROM lams_qb_question WHERE question_id = q.question_id) " + + "AND cq.collection_uid = :collectionUid ? GROUP BY q.question_id ORDER BY COUNT(l.lesson_id)"; + private static final String FIND_QUESTION_COLLECTIONS_BY_UID = "SELECT c.* FROM lams_qb_collection_question AS cq " + "JOIN lams_qb_collection AS c ON cq.collection_uid = c.uid JOIN lams_qb_question AS q ON cq.qb_question_id = q.question_id " + "WHERE q.uid = :qbQuestionUid"; @@ -358,12 +366,12 @@ String search, boolean isCount) { StringBuilder queryBuilder = new StringBuilder(FIND_COLLECTION_QUESTIONS); - if (StringUtils.isNotBlank(search)) { - queryBuilder.append(" AND (q.name LIKE :search OR q.description LIKE :search)"); - } - if (!isCount && StringUtils.isNotBlank(orderBy)) { - queryBuilder.append(" ORDER BY ").append(orderBy); + if (orderBy.equalsIgnoreCase("usage")) { + queryBuilder = new StringBuilder(FIND_COLLECTION_QUESTIONS_BY_USAGE); + } else { + queryBuilder.append(" ORDER BY ").append(orderBy); + } if (StringUtils.isNotBlank(orderDirection)) { queryBuilder.append(" ").append(orderDirection); } @@ -374,6 +382,9 @@ queryText = queryText.replace("q.*", "COUNT(*)"); } + queryText = queryText.replace("?", + (StringUtils.isBlank(search) ? "" : " AND (q.name LIKE :search OR q.description LIKE :search)")); + Query query = isCount ? getSession().createNativeQuery(queryText) : getSession().createNativeQuery(queryText, QbQuestion.class); query.setParameter("collectionUid", collectionUid);