Index: lams_gradebook/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/conf/language/lams/ApplicationResources.properties,v diff -u -r1.1.2.9 -r1.1.2.10 --- lams_gradebook/conf/language/lams/ApplicationResources.properties 9 May 2009 06:47:38 -0000 1.1.2.9 +++ lams_gradebook/conf/language/lams/ApplicationResources.properties 10 Jun 2009 05:08:35 -0000 1.1.2.10 @@ -33,7 +33,7 @@ gradebook.columntitle.activity =Activity gradebook.columntitle.activityFeedback =Activity Feedback gradebook.columntitle.outputs =Tool Outputs -gradebook.columntitle.competences =Competences +gradebook.columntitle.competences =Competencies gradebook.columntitle.averageTimeTaken =Average Time Taken gradebook.columntitle.averageMark =Average Mark gradebook.columntitle.learnerName =Learner Name @@ -57,6 +57,20 @@ error.markhigher =Mark must be lower than maximum mark. error.releasemarks.fail =Mark release failed, please contact your system administrator. gradebook.monitor.releasemarks.2 =Hide +gradebook.export.excel.1 =Export +gradebook.export.excel.2 =grades to spreadsheet file. +gradebook.export.user =User +gradebook.export.activity =Activity +gradebook.export.activities =Activities +gradebook.export.outputs =Outputs +gradebook.export.average.lesson.mark =Average lesson mark: +gradebook.export.average.lesson.time.taken =Average time taken for lesson (seconds): +gradebook.export.total.marks.for.lesson =Total Marks for Lesson +gradebook.export.total.mark =Total Mark +gradebook.export.dateheader =Exported on: +gradebook.export.lesson.summary =Lesson Summary +gradebook.export.learner.view =Learner View +gradebook.export.time.taken.seconds =Time Taken (seconds) +gradebook.export.average.time.taken.seconds =Average Time Taken (seconds) - #======= End labels: Exported 51 labels for en AU ===== Index: lams_gradebook/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.1.2.9 -r1.1.2.10 --- lams_gradebook/conf/language/lams/ApplicationResources_en_AU.properties 9 May 2009 06:47:40 -0000 1.1.2.9 +++ lams_gradebook/conf/language/lams/ApplicationResources_en_AU.properties 10 Jun 2009 05:08:35 -0000 1.1.2.10 @@ -33,7 +33,7 @@ gradebook.columntitle.activity =Activity gradebook.columntitle.activityFeedback =Activity Feedback gradebook.columntitle.outputs =Tool Outputs -gradebook.columntitle.competences =Competences +gradebook.columntitle.competences =Competencies gradebook.columntitle.averageTimeTaken =Average Time Taken gradebook.columntitle.averageMark =Average Mark gradebook.columntitle.learnerName =Learner Name @@ -57,6 +57,20 @@ error.markhigher =Mark must be lower than maximum mark. error.releasemarks.fail =Mark release failed, please contact your system administrator. gradebook.monitor.releasemarks.2 =Hide +gradebook.export.excel.1 =Export +gradebook.export.excel.2 =grades to spreadsheet file. +gradebook.export.user =User +gradebook.export.activity =Activity +gradebook.export.activities =Activities +gradebook.export.outputs =Outputs +gradebook.export.average.lesson.mark =Average lesson mark: +gradebook.export.average.lesson.time.taken =Average time taken for lesson (seconds): +gradebook.export.total.marks.for.lesson =Total Marks for Lesson +gradebook.export.total.mark =Total Mark +gradebook.export.dateheader =Exported on: +gradebook.export.lesson.summary =Lesson Summary +gradebook.export.learner.view =Learner View +gradebook.export.time.taken.seconds =Time Taken (seconds) +gradebook.export.average.time.taken.seconds =Average Time Taken (seconds) - #======= End labels: Exported 51 labels for en AU ===== Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/gradebookApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/gradebookApplicationContext.xml,v diff -u -r1.1.2.2 -r1.1.2.3 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/gradebookApplicationContext.xml 22 Apr 2009 06:39:06 -0000 1.1.2.2 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/gradebookApplicationContext.xml 10 Jun 2009 05:08:26 -0000 1.1.2.3 @@ -1,9 +1,13 @@ - - - org.lamsfoundation.lams.gradebook.ApplicationResources + + + + + org.lamsfoundation.lams.gradebook.ApplicationResources + + @@ -13,6 +17,7 @@ + Fisheye: Tag 1.1 refers to a dead (removed) revision in file `lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/ExcelCell.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GradebookGridRowDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GradebookGridRowDTO.java,v diff -u -r1.1.2.3 -r1.1.2.4 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GradebookGridRowDTO.java 26 Apr 2009 23:52:22 -0000 1.1.2.3 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/dto/GradebookGridRowDTO.java 10 Jun 2009 05:08:25 -0000 1.1.2.4 @@ -113,9 +113,9 @@ } } - protected String averageMarkToString(){ + protected String averageMarkToString() { if (averageMark != null) { - String avgStr = new DecimalFormat("###.00").format(averageMark); + String avgStr = new DecimalFormat("###.00").format(averageMark); if (marksAvailable != null) { return avgStr + "/" + marksAvailable.toString(); } else { @@ -134,6 +134,14 @@ return timeTaken; } + public Long getTimeTakenSeconds() { + if (timeTaken != null) { + return timeTaken / 1000; + } else { + return null; + } + } + public void setTimeTaken(Long timeTaken) { this.timeTaken = timeTaken; } @@ -165,6 +173,14 @@ public Long getAverageTimeTaken() { return averageTimeTaken; } + + public Long getAverageTimeTakenSeconds() { + if (averageTimeTaken != null) { + return averageTimeTaken/1000; + } else { + return null; + } + } public void setAverageTimeTaken(Long averageTimeTaken) { this.averageTimeTaken = averageTimeTaken; Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java,v diff -u -r1.1.2.13 -r1.1.2.14 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java 1 May 2009 06:15:09 -0000 1.1.2.13 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/GradebookService.java 10 Jun 2009 05:08:26 -0000 1.1.2.14 @@ -28,6 +28,8 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -41,6 +43,7 @@ import org.lamsfoundation.lams.gradebook.GradebookUserActivity; import org.lamsfoundation.lams.gradebook.GradebookUserLesson; import org.lamsfoundation.lams.gradebook.dao.IGradebookDAO; +import org.lamsfoundation.lams.gradebook.dto.ExcelCell; import org.lamsfoundation.lams.gradebook.dto.GBActivityGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.GBLessonGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.GBUserGridRowDTO; @@ -69,24 +72,32 @@ import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.util.MessageService; /** * @author lfoxton * * This service handles all gradebook-related service calls * */ +/** + * @author lfoxton + * + */ public class GradebookService implements IGradebookService { private static Logger logger = Logger.getLogger(GradebookService.class); + private static final ExcelCell[] EMPTY_ROW = new ExcelCell[4]; + // Services private ILamsCoreToolService toolService; private IGradebookDAO gradebookDAO; private ILessonService lessonService; private IUserManagementService userService; private IBaseDAO baseDAO; private IActivityDAO activityDAO; + private MessageService messageService; /** * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#getGBActivityRowsForLearner(org.lamsfoundation.lams.lesson.Lesson, @@ -374,7 +385,8 @@ * org.lamsfoundation.lams.usermanagement.User, * org.lamsfoundation.lams.learningdesign.Activity, java.lang.Double) */ - public void updateUserActivityGradebookMark(Lesson lesson, User learner, Activity activity, Double mark, Boolean markedInGradebook) { + public void updateUserActivityGradebookMark(Lesson lesson, User learner, Activity activity, Double mark, + Boolean markedInGradebook) { if (lesson != null && activity != null && learner != null && activity.isToolActivity()) { // First, update the mark for the activity @@ -520,11 +532,210 @@ return lessonRows; } + /** + * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#getActivityViewDataForExcel(org.lamsfoundation.lams.lesson.Lesson) + */ + @SuppressWarnings("unchecked") + public ExcelCell[][] getActivityViewDataForExcel(Lesson lesson) { + ExcelCell[][] data = null; + if (lesson != null) { + + Set activities = (Set) lesson.getLearningDesign().getActivities(); + + Activity firstActivity = activityDAO.getActivityByActivityId(lesson.getLearningDesign().getFirstActivity() + .getActivityId()); + + HashMap> activityViewMap = new HashMap>(); + + if (firstActivity != null && firstActivity.isToolActivity() && firstActivity instanceof ToolActivity) { + + List userRows = getGBUserRowsForActivity(lesson, (ToolActivity) firstActivity, null); + activityViewMap.put(firstActivity, userRows); + } + + SortedSet sortedActivities = new TreeSet(activities); + + for (Activity activity : sortedActivities) { + if (activity.getActivityId().longValue() != firstActivity.getActivityId().longValue() + && activity instanceof ToolActivity) { + + List userRows = getGBUserRowsForActivity(lesson, (ToolActivity) activity, null); + activityViewMap.put(activity, userRows); + } + } + + List rowList = new LinkedList(); + + for (Activity act : activityViewMap.keySet()) { + + ExcelCell[] activityTitleRow = new ExcelCell[4]; + activityTitleRow[0] = new ExcelCell(act.getTitle(), true); + rowList.add(activityTitleRow); + ExcelCell[] titleRow = new ExcelCell[4]; + titleRow[0] = new ExcelCell(getMessage("gradebook.export.user"), true); + titleRow[1] = new ExcelCell(getMessage("gradebook.export.time.taken.seconds"), true); + titleRow[2] = new ExcelCell(getMessage("gradebook.export.outputs"), true); + titleRow[3] = new ExcelCell(getMessage("gradebook.columntitle.mark"), true); + rowList.add(titleRow); + + // Get the rest of the data + List userRows = activityViewMap.get(act); + for (GBUserGridRowDTO userRow : userRows) { + ExcelCell[] userDataRow = new ExcelCell[4]; + + userDataRow[0] = new ExcelCell(userRow.getRowName(), false); + userDataRow[1] = new ExcelCell(userRow.getTimeTakenSeconds(), false); + userDataRow[2] = new ExcelCell(userRow.getOutput(), false); + userDataRow[3] = new ExcelCell(userRow.getMark(), false); + rowList.add(userDataRow); + } + + rowList.add(EMPTY_ROW); + } + + data = rowList.toArray(new ExcelCell[][] {}); + + } + return data; + } + + /** + * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#getUserViewDataForExcel(org.lamsfoundation.lams.lesson.Lesson) + */ + @SuppressWarnings("unchecked") + public ExcelCell[][] getUserViewDataForExcel(Lesson lesson) { + ExcelCell[][] data = null; + if (lesson != null) { + + Set learners = (Set) lesson.getAllLearners(); + + List rowList = new LinkedList(); + for (User learner : learners) { + List activityRows = getGBActivityRowsForLearner(lesson, learner); + + ExcelCell[] activityTitleRow = new ExcelCell[4]; + activityTitleRow[0] = new ExcelCell(learner.getFullName(), true); + rowList.add(activityTitleRow); + + ExcelCell[] titleRow = new ExcelCell[4]; + titleRow[0] = new ExcelCell(getMessage("gradebook.export.activity"), true); + titleRow[1] = new ExcelCell(getMessage("gradebook.export.time.taken.seconds"), true); + titleRow[2] = new ExcelCell(getMessage("gradebook.export.outputs"), true); + titleRow[3] = new ExcelCell(getMessage("gradebook.columntitle.mark"), true); + rowList.add(titleRow); + + Iterator it = activityRows.iterator(); + while (it.hasNext()) { + GBActivityGridRowDTO activityRow = (GBActivityGridRowDTO) it.next(); + ExcelCell[] activityDataRow = new ExcelCell[4]; + activityDataRow[0] = new ExcelCell(activityRow.getRowName(), false); + activityDataRow[1] = new ExcelCell(activityRow.getTimeTakenSeconds(), false); + activityDataRow[2] = new ExcelCell(activityRow.getOutput(), false); + activityDataRow[3] = new ExcelCell(activityRow.getMark(), false); + rowList.add(activityDataRow); + } + + rowList.add(EMPTY_ROW); + } + + data = rowList.toArray(new ExcelCell[][] {}); + + } + return data; + } + + /** + * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#getSummaryDataForExcel(org.lamsfoundation.lams.lesson.Lesson) + */ + @SuppressWarnings("unchecked") + public ExcelCell[][] getSummaryDataForExcel(Lesson lesson) { + ExcelCell[][] data = null; + if (lesson != null) { + + // The entire data list + List rowList = new LinkedList(); + + // Adding the lesson average data to the summary ------------------- + ExcelCell[] lessonAverageMark = new ExcelCell[2]; + lessonAverageMark[0] = new ExcelCell(getMessage("gradebook.export.average.lesson.mark"), true); + lessonAverageMark[1] = new ExcelCell(getAverageMarkForLesson(lesson.getLessonId()), false); + rowList.add(lessonAverageMark); + + ExcelCell[] lessonAverageTimeTaken = new ExcelCell[2]; + lessonAverageTimeTaken[0] = new ExcelCell(getMessage("gradebook.export.average.lesson.time.taken"), true); + lessonAverageTimeTaken[1] = new ExcelCell(gradebookDAO.getAverageDurationLesson(lesson.getLessonId()), false); + rowList.add(lessonAverageTimeTaken); + rowList.add(EMPTY_ROW); + //------------------------------------------------------------------ + + + // Adding the activity average data to the summary ----------------- + List activityRows = getGBActivityRowsForLesson(lesson); + ExcelCell[] activityAverageTitle = new ExcelCell[1]; + activityAverageTitle[0] = new ExcelCell(getMessage("gradebook.export.activities"), true); + rowList.add(activityAverageTitle); + + // Setting up the activity summary table + ExcelCell[] activityAverageRow = new ExcelCell[4]; + activityAverageRow[0] = new ExcelCell(getMessage("gradebook.export.activity"), true); + activityAverageRow[1] = new ExcelCell(getMessage("gradebook.columntitle.competences"), true); + activityAverageRow[2] = new ExcelCell(getMessage("gradebook.export.average.time.taken.seconds"), true); + activityAverageRow[3] = new ExcelCell(getMessage("gradebook.columntitle.averageMark"), true); + rowList.add(activityAverageRow); + + Iterator it = activityRows.iterator(); + while (it.hasNext()) { + GBActivityGridRowDTO activityRow = (GBActivityGridRowDTO)it.next(); + // Add the activity average data + ExcelCell[] activityDataRow = new ExcelCell[4]; + activityDataRow[0] = new ExcelCell(activityRow.getRowName(), false); + activityDataRow[1] = new ExcelCell(activityRow.getCompetences(), false); + activityDataRow[2] = new ExcelCell(activityRow.getAverageTimeTakenSeconds(), false); + activityDataRow[3] = new ExcelCell(activityRow.getAverageMark(), false); + rowList.add(activityDataRow); + } + rowList.add(EMPTY_ROW); + //------------------------------------------------------------------ + + + // Adding the user lesson marks to the summary---------------------- + ExcelCell[] userMarksTitle = new ExcelCell[1]; + userMarksTitle[0] = new ExcelCell(getMessage("gradebook.export.total.marks.for.lesson"), true); + rowList.add(userMarksTitle); + + // Fetching the user data + ArrayList userRows = getGBUserRowsForLesson(lesson); + + // Setting up the user marks table + ExcelCell[] userTitleRow = new ExcelCell[3]; + userTitleRow[0] = new ExcelCell(getMessage("gradebook.export.user"), true); + userTitleRow[1] = new ExcelCell(getMessage("gradebook.export.time.taken.seconds"), true); + userTitleRow[2] = new ExcelCell(getMessage("gradebook.export.total.mark"), true); + rowList.add(userTitleRow); + + for (GBUserGridRowDTO userRow : userRows) { + // Adding the user data for the lesson + ExcelCell[] userDataRow = new ExcelCell[3]; + userDataRow[0] = new ExcelCell(userRow.getRowName(), false); + userDataRow[1] = new ExcelCell(userRow.getTimeTakenSeconds(), false); + userDataRow[2] = new ExcelCell(userRow.getMark(), false); + rowList.add(userDataRow); + } + //------------------------------------------------------------------ + + data = rowList.toArray(new ExcelCell[][] {}); + + } + return data; + } + + /** * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#updateActivityMark(java.lang.Double, * java.lang.String, java.lang.Integer, java.lang.Long) */ - public void updateActivityMark(Double mark, String feedback, Integer userID, Long toolSessionID, Boolean markedInGradebook) { + public void updateActivityMark(Double mark, String feedback, Integer userID, Long toolSessionID, + Boolean markedInGradebook) { ToolSession toolSession = toolService.getToolSessionById(toolSessionID); User learner = (User) userService.findById(User.class, userID); if (learner != null && toolSession != null) { @@ -534,11 +745,11 @@ // If gradebook user activity is null, save the mark and feedback if (gradebookUserActivity == null || !gradebookUserActivity.getMarkedInGradebook()) { updateUserActivityGradebookMark(toolSession.getLesson(), learner, activity, mark, markedInGradebook); - } + } } } - + /** * @see org.lamsfoundation.lams.gradebook.service.IGradebookService#getActivityById(java.lang.Long) */ @@ -808,7 +1019,6 @@ if (toolOutput != null && toolOutput.getValue().getType() != OutputType.OUTPUT_COMPLEX) { toolOutputs.add(toolOutput); - toolOutputsStr += toolOutput.getDescription() + ": " + toolOutput.getValue().getString(); toolOutputsStr += "
"; @@ -827,8 +1037,8 @@ // Fix up outputs html if there are not outputs available if (noOutputs) { toolOutputsStr = "-"; - } - + } + return toolOutputsStr; } @@ -891,6 +1101,10 @@ return null; } } + + public String getMessage(String key) { + return messageService.getMessage(key); + } // Getter and setter methods ----------------------------------------------- @@ -942,5 +1156,13 @@ this.activityDAO = activityDAO; } + public MessageService getMessageService() { + return messageService; + } + + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } + // ------------------------------------------------------------------------- } Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/IGradebookService.java =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/IGradebookService.java,v diff -u -r1.1.2.5 -r1.1.2.6 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/IGradebookService.java 1 May 2009 06:15:09 -0000 1.1.2.5 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/service/IGradebookService.java 10 Jun 2009 05:08:26 -0000 1.1.2.6 @@ -27,6 +27,7 @@ import org.lamsfoundation.lams.gradebook.GradebookUserActivity; import org.lamsfoundation.lams.gradebook.GradebookUserLesson; +import org.lamsfoundation.lams.gradebook.dto.ExcelCell; import org.lamsfoundation.lams.gradebook.dto.GBLessonGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.GBUserGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.GradebookGridRowDTO; @@ -177,5 +178,33 @@ * @return */ public Activity getActivityById(Long activityID); + + /** + * Get a language label + * @param key + * @return + */ + public String getMessage(String key); + + /** + * Get the activity view data in 2d array format for an excel export + * @param lesson + * @return + */ + public ExcelCell[][] getActivityViewDataForExcel(Lesson lesson); + + /** + * Get the user view data in a 2d array format for an excel export + * @param lesson + * @return + */ + public ExcelCell[][] getUserViewDataForExcel(Lesson lesson); + + /** + * Get the summary data in a 2s array for an excel export + * @param lesson + * @return + */ + public ExcelCell[][] getSummaryDataForExcel(Lesson lesson); } Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java,v diff -u -r1.1.2.1 -r1.1.2.2 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java 15 Apr 2009 07:40:21 -0000 1.1.2.1 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/util/GradebookUtil.java 10 Jun 2009 05:08:26 -0000 1.1.2.2 @@ -23,10 +23,15 @@ /* $Id$ */ package org.lamsfoundation.lams.gradebook.util; +import java.io.IOException; +import java.io.OutputStream; import java.io.StringWriter; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -39,6 +44,22 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import jxl.CellView; +import jxl.JXLException; +import jxl.Workbook; +import jxl.format.Font; +import jxl.write.Label; +import jxl.write.Number; +import jxl.write.WritableCell; +import jxl.write.WritableCellFormat; +import jxl.write.WritableFont; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; +import jxl.write.WriteException; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.gradebook.dto.ExcelCell; +import org.lamsfoundation.lams.gradebook.dto.GBActivityGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.GradebookGridRowDTO; import org.lamsfoundation.lams.gradebook.dto.comparators.GBAverageMarkComparator; import org.lamsfoundation.lams.gradebook.dto.comparators.GBAverageTimeTakenComparator; @@ -47,6 +68,7 @@ import org.lamsfoundation.lams.gradebook.dto.comparators.GBRowNameComparator; import org.lamsfoundation.lams.gradebook.dto.comparators.GBStartDateComparator; import org.lamsfoundation.lams.gradebook.dto.comparators.GBTimeTakenComparator; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.WebUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -56,7 +78,7 @@ /** * Wrapper method for printing the xml for grid rows * - * It takes the list of rows along with the grid parameter and returns the + * It takes the list of rows along with the grid parameter and returns the * xml for the altered set * * @@ -75,7 +97,7 @@ @SuppressWarnings("unchecked") public static String toGridXML(List gridRows, GBGridView view, String sortBy, boolean isSearch, String searchField, String searchOper, String searchString, String sortOrder, int rowLimit, int page) { - + // Alter the set based on the parameters gridRows = makeGridRowAlterations(gridRows, sortBy, isSearch, searchField, searchOper, searchString, sortOrder, rowLimit, page); @@ -285,7 +307,7 @@ } return ret; } - + public static GBGridView readGBGridViewParam(HttpServletRequest request, String param_mode, boolean optional) { String view = WebUtil.readStrParam(request, param_mode, optional); if (view == null) { @@ -304,4 +326,84 @@ throw new IllegalArgumentException("[" + view + "] is not a legal gradebook view"); } + public static void exportGradebookLessonToExcel(OutputStream out, String dateHeader, + LinkedHashMap dataToExport) throws IOException, JXLException { + WritableWorkbook workbook = Workbook.createWorkbook(out); + + int i = 0; + for (String sheetName : dataToExport.keySet()) { + if (dataToExport.get(sheetName) != null) { + createSheet(workbook, sheetName, sheetName, i, dateHeader, dataToExport.get(sheetName)); + i++; + } + } + + workbook.write(); + workbook.close(); + } + + public static void createSheet(WritableWorkbook workbook, String sheetName, String sheetTitle, int sheetIndex, + String dateHeader, ExcelCell[][] data) throws IOException, JXLException { + WritableSheet sheet = workbook.createSheet(sheetName, sheetIndex); + + // Prepare cell formatter used in all columns + CellView stretchedCellView = new CellView(); + stretchedCellView.setAutosize(true); + + // Print title in bold, if needed + if (!StringUtils.isBlank(sheetTitle)) { + sheet.addCell(createWritableCell(new ExcelCell(sheetTitle, true), 0, 0)); + } + + // Print current date, if needed + if (!StringUtils.isBlank(dateHeader)) { + sheet.addCell(new Label(0, 1, dateHeader)); + SimpleDateFormat titleDateFormat = new SimpleDateFormat(FileUtil.EXPORT_TO_SPREADSHEET_TITLE_DATE_FORMAT); + sheet.addCell(new Label(1, 1, titleDateFormat.format(new Date()))); + } + + if (data != null) { + // Print data + for (int rowIndex = 0; rowIndex < data.length; rowIndex++) { + int sheetRowIndex = rowIndex + 4; + for (int columnIndex = 0; columnIndex < data[rowIndex].length; columnIndex++) { + ExcelCell excelCell = data[rowIndex][columnIndex]; + if (excelCell != null) { + sheet.addCell(createWritableCell(excelCell, columnIndex, sheetRowIndex)); + } + } + } + } + } + + public static WritableCell createWritableCell(ExcelCell cell, int col, int row) throws WriteException { + + if (cell != null) { + WritableCell writeableCell = null; + if (cell.getCellValue() != null && cell.getCellValue() instanceof Date) { + SimpleDateFormat cellDateFormat = new SimpleDateFormat(FileUtil.EXPORT_TO_SPREADSHEET_CELL_DATE_FORMAT); + writeableCell = new Label(col, row, cellDateFormat.format(cell.getCellValue())); + } else if (cell.getCellValue() != null && cell.getCellValue() instanceof java.lang.Double) { + writeableCell = new Number(col, row, (Double) cell.getCellValue()); + } else if (cell.getCellValue() != null && cell.getCellValue() instanceof java.lang.Long) { + writeableCell = new Number(col, row, ((Long) cell.getCellValue()).doubleValue()); + } else if (cell.getCellValue() != null) { + writeableCell = new Label(col, row, cell.getCellValue().toString()); + } else { + writeableCell = new Label(col, row, null); + } + + if (cell.getIsBold() == Boolean.TRUE) { + Font font = writeableCell.getCellFormat().getFont(); + WritableFont labelFont = new WritableFont(font); + labelFont.setBoldStyle(WritableFont.BOLD); + WritableCellFormat labelCellFormat = new WritableCellFormat(labelFont); + writeableCell.setCellFormat(labelCellFormat); + } + return writeableCell; + } else { + return null; + } + } + } Index: lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/web/action/GradebookMonitoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/web/action/GradebookMonitoringAction.java,v diff -u -r1.1.2.6 -r1.1.2.7 --- lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/web/action/GradebookMonitoringAction.java 1 May 2009 06:15:09 -0000 1.1.2.6 +++ lams_gradebook/src/java/org/lamsfoundation/lams/gradebook/web/action/GradebookMonitoringAction.java 10 Jun 2009 05:08:26 -0000 1.1.2.7 @@ -23,6 +23,9 @@ /* $Id$ */ package org.lamsfoundation.lams.gradebook.web.action; +import java.util.LinkedHashMap; + +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -31,6 +34,7 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.gradebook.dto.ExcelCell; import org.lamsfoundation.lams.gradebook.service.IGradebookService; import org.lamsfoundation.lams.gradebook.util.GBGridView; import org.lamsfoundation.lams.gradebook.util.GradebookConstants; @@ -104,17 +108,15 @@ logger.debug("user is staff"); boolean marksReleased = lesson.getMarksReleased() != null && lesson.getMarksReleased(); - - + LessonDetailsDTO lessonDetatilsDTO = lesson.getLessonDetails(); request.setAttribute("lessonDetails", lessonDetatilsDTO); request.setAttribute("marksReleased", marksReleased); - return mapping.findForward("monitorgradebook"); } } catch (Exception e) { - logger.error("Failed to load gradebook monitor", e); + logger.error("Failed to load gradebook monitor", e); return mapping.findForward("error"); } } @@ -221,15 +223,15 @@ // Fetch the id based on which grid it came from if (view == GBGridView.MON_ACTIVITY) { String rowID = WebUtil.readStrParam(request, AttributeNames.PARAM_ACTIVITY_ID); - + // Splitting the rowID param to get the activity/group id pair String[] split = rowID.split("_"); if (split.length == 2) { activityID = Long.parseLong(split[0]); } else { activityID = Long.parseLong(rowID); } - + userID = WebUtil.readIntParam(request, GradebookConstants.PARAM_ID); } else if (view == GBGridView.MON_USER) { @@ -240,7 +242,7 @@ String markStr = WebUtil.readStrParam(request, GradebookConstants.PARAM_MARK, true); String feedback = WebUtil.readStrParam(request, GradebookConstants.PARAM_FEEDBACK, true); - Activity activity = (Activity)userService.findById(Activity.class, activityID); + Activity activity = (Activity) userService.findById(Activity.class, activityID); User learner = (User) userService.findById(User.class, userID); Lesson lesson = lessonService.getLesson(lessonID); @@ -260,7 +262,7 @@ } return null; } - + /** * Toggles the release mark flag for a lesson * @@ -271,22 +273,58 @@ * @return * @throws Exception */ - public ActionForward toggleReleaseMarks(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) throws Exception { + public ActionForward toggleReleaseMarks(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { initServices(); Long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); Lesson lesson = lessonService.getLesson(lessonID); - + boolean marksReleased = lesson.getMarksReleased() != null && lesson.getMarksReleased(); - + lesson.setMarksReleased(!marksReleased); userService.save(lesson); - + writeResponse(response, CONTENT_TYPE_TEXT_PLAIN, ENCODING_UTF8, "success"); return null; } + public ActionForward exportExcelLessonGradebook(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + Long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); + Lesson lesson = lessonService.getLesson(lessonID); + + if (lesson != null) { + String fileName = lesson.getLessonName().replaceAll(" ", "_") + ".xls"; + + response.getOutputStream(); + response.setContentType("application/x-download"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + logger.debug("Exporting to a spreadsheet gradebook lesson: " + lessonID); + ServletOutputStream out = response.getOutputStream(); + + LinkedHashMap dataToExport = new LinkedHashMap(); + + ExcelCell[][] summaryData = gradebookService.getSummaryDataForExcel(lesson); + dataToExport.put(gradebookService.getMessage("gradebook.export.lesson.summary"), summaryData); + + ExcelCell[][] activityData = gradebookService.getActivityViewDataForExcel(lesson); + dataToExport.put(gradebookService.getMessage("gradebook.gridtitle.activitygrid"), activityData); + + ExcelCell[][] userData = gradebookService.getUserViewDataForExcel(lesson); + dataToExport.put(gradebookService.getMessage("gradebook.export.learner.view"), userData); + + GradebookUtil.exportGradebookLessonToExcel(out, gradebookService.getMessage("gradebook.export.dateheader"), dataToExport); + + } else { + throw new Exception("Attempt to retrieve gradebook data for null lesson"); + } + return null; + } + private UserDTO getUser() { HttpSession ss = SessionManager.getSession(); return (UserDTO) ss.getAttribute(AttributeNames.USER); Index: lams_gradebook/web/gradebookMonitor.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_gradebook/web/gradebookMonitor.jsp,v diff -u -r1.1.2.11 -r1.1.2.12 --- lams_gradebook/web/gradebookMonitor.jsp 11 May 2009 00:16:18 -0000 1.1.2.11 +++ lams_gradebook/web/gradebookMonitor.jsp 10 Jun 2009 05:08:35 -0000 1.1.2.12 @@ -478,6 +478,12 @@
+ + + +
+
+