Skip to content

Commit

Permalink
SAK-43899 Date Manager doesn't work with Shared Lessons Page (sakaipr…
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjmerono authored Jul 8, 2020
1 parent 92d746a commit 3b7f1dd
Showing 1 changed file with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimplePageItem> items = simplePageToolDao.findItemsInSite(siteId);
jsonLessons = addAllSubpages(simplePageToolDao.findItemsInSite(siteId), null, jsonLessons, "false");
return jsonLessons;
}

private JSONArray addAllSubpages(List<SimplePageItem> 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());
Expand All @@ -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<SimplePageItem> 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}
Expand Down

0 comments on commit 3b7f1dd

Please sign in to comment.