diff --git a/site-manage/datemanager/impl/src/java/org/sakaiproject/datemanager/impl/DateManagerServiceImpl.java b/site-manage/datemanager/impl/src/java/org/sakaiproject/datemanager/impl/DateManagerServiceImpl.java index e6e896179db5..c838f69d2a0a 100644 --- a/site-manage/datemanager/impl/src/java/org/sakaiproject/datemanager/impl/DateManagerServiceImpl.java +++ b/site-manage/datemanager/impl/src/java/org/sakaiproject/datemanager/impl/DateManagerServiceImpl.java @@ -1248,12 +1248,18 @@ public void updateAnnouncements(DateManagerValidation announcementValidate) thro @Override public JSONArray getLessonsForContext(String siteId) { JSONArray jsonLessons = new JSONArray(); - String url = getUrlForTool(DateManagerConstants.COMMON_ID_LESSONS); - List items = simplePageToolDao.findItemsInSite(siteId); + jsonLessons = addAllSubpages(simplePageToolDao.findItemsInSite(siteId), null, jsonLessons, "false"); + return jsonLessons; + } + + private JSONArray addAllSubpages(List items, Long pageId, JSONArray jsonLessons, String extraInfo) { if (items != null) { + String url = getUrlForTool(DateManagerConstants.COMMON_ID_LESSONS); String toolTitle = toolManager.getTool(DateManagerConstants.COMMON_ID_LESSONS).getTitle(); for (SimplePageItem item : items) { - if (item.getType() == SimplePageItem.PAGE) { + if (item.getType() == SimplePageItem.PAGE // Avoid creating a infinite loop + && !Long.valueOf(item.getSakaiId()).equals(pageId) + && !jsonLessons.toString().contains("\"id\":\""+item.getSakaiId()+"\"")) { JSONObject lobj = new JSONObject(); lobj.put("id", Long.parseLong(item.getSakaiId())); lobj.put("title", item.getName()); @@ -1265,39 +1271,16 @@ public JSONArray getLessonsForContext(String siteId) { } lobj.put("tool_title", toolTitle); lobj.put("url", url); - lobj.put("extraInfo", "false"); + lobj.put("extraInfo", extraInfo); jsonLessons.add(lobj); - jsonLessons = addAllSubpages(Long.parseLong(item.getSakaiId()), jsonLessons); + long itemId = Long.parseLong(item.getSakaiId()); + jsonLessons = addAllSubpages(simplePageToolDao.findItemsOnPage(itemId), itemId, jsonLessons, rb.getString("tool.lessons.extra.subpage")); } } } return jsonLessons; } - private JSONArray addAllSubpages(Long pageId, JSONArray jsonLessons) { - List items = simplePageToolDao.findItemsOnPage(pageId); - String url = getUrlForTool(DateManagerConstants.COMMON_ID_LESSONS); - for (SimplePageItem item : items) { - String toolTitle = toolManager.getTool(DateManagerConstants.COMMON_ID_LESSONS).getTitle(); - if (item.getType() == SimplePageItem.PAGE) { - JSONObject lobj = new JSONObject(); - lobj.put("id", Long.parseLong(item.getSakaiId())); - lobj.put("title", item.getName()); - SimplePage page = simplePageToolDao.getPage(Long.parseLong(item.getSakaiId())); - if(page.getReleaseDate() != null) { - lobj.put("open_date", formatToUserDateFormat(page.getReleaseDate())); - } else { - lobj.put("open_date", null); - } - lobj.put("tool_title", toolTitle); - lobj.put("url", url); - lobj.put("extraInfo", rb.getString("tool.lessons.extra.subpage")); - jsonLessons.add(lobj); - jsonLessons = addAllSubpages(Long.parseLong(item.getSakaiId()), jsonLessons); - } - } - return jsonLessons; - } /** * {@inheritDoc}