use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class BinderPageListController method loadModel.
@Override
protected void loadModel(UserRequest ureq, String searchString) {
if (StringHelper.containsNonWhitespace(binder.getSummary())) {
summaryComp.setText(binder.getSummary());
flc.getFormItemComponent().put("summary", summaryCtrl.getInitialComponent());
} else {
flc.getFormItemComponent().remove("summary");
}
List<Section> sections = portfolioService.getSections(binder);
List<CategoryToElement> categorizedElements = portfolioService.getCategorizedSectionsAndPages(binder);
Map<OLATResourceable, List<Category>> categorizedElementMap = new HashMap<>();
Map<Section, Set<String>> sectionAggregatedCategoriesMap = new HashMap<>();
for (CategoryToElement categorizedElement : categorizedElements) {
List<Category> categories = categorizedElementMap.get(categorizedElement.getCategorizedResource());
if (categories == null) {
categories = new ArrayList<>();
categorizedElementMap.put(categorizedElement.getCategorizedResource(), categories);
}
categories.add(categorizedElement.getCategory());
}
// comments
Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfComments(binder);
// assessment sections
List<AssessmentSection> assessmentSections = portfolioService.getAssessmentSections(binder, getIdentity());
Map<Section, AssessmentSection> sectionToAssessmentSectionMap = assessmentSections.stream().collect(Collectors.toMap(as -> as.getSection(), as -> as));
List<PortfolioElementRow> rows = new ArrayList<>();
// assignments
List<Assignment> assignments = portfolioService.getAssignments(binder, searchString);
Map<Section, List<Assignment>> sectionToAssignmentMap = new HashMap<>();
for (Assignment assignment : assignments) {
List<Assignment> assignmentList;
Section section = assignment.getSection();
if (sectionToAssignmentMap.containsKey(section)) {
assignmentList = sectionToAssignmentMap.get(section);
} else {
assignmentList = new ArrayList<>();
sectionToAssignmentMap.put(section, assignmentList);
}
assignmentList.add(assignment);
}
for (Assignment assignment : assignments) {
Section section = assignment.getSection();
if (assignment.getPage() == null && secCallback.canViewPendingAssignments(section)) {
List<Assignment> sectionAssignments = sectionToAssignmentMap.get(section);
PortfolioElementRow row = forgePendingAssignmentRow(assignment, section, sectionAssignments);
rows.add(row);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(row);
row.setNewEntryLink(newEntryButton);
}
}
}
boolean userInfos = secCallback.canPageUserInfosStatus();
Map<Long, PageUserInformations> userInfosToPage = new HashMap<>();
rowVC.contextPut("userInfos", Boolean.valueOf(userInfos));
if (userInfos) {
rowVC.contextPut("userInfosRenderer", new SharedPageStatusCellRenderer(getTranslator()));
List<PageUserInformations> userInfoList = portfolioService.getPageUserInfos(binder, getIdentity());
for (PageUserInformations userInfo : userInfoList) {
userInfosToPage.put(userInfo.getPage().getKey(), userInfo);
}
}
List<Page> pages = portfolioService.getPages(binder, searchString);
for (Page page : pages) {
boolean viewElement = secCallback.canViewElement(page);
boolean viewTitleElement = viewElement || secCallback.canViewTitleOfElement(page);
if (!viewTitleElement) {
continue;
}
Section section = page.getSection();
PortfolioElementRow pageRow = forgePageRow(ureq, page, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap, numberOfCommentsMap, viewElement);
rows.add(pageRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(pageRow);
pageRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(pageRow);
pageRow.setNewAssignmentLink(newAssignmentButton);
}
if (userInfos) {
PageUserInformations infos = userInfosToPage.get(page.getKey());
if (infos != null) {
pageRow.setUserInfosStatus(infos.getStatus());
}
}
if (section != null) {
Set<String> categories = sectionAggregatedCategoriesMap.get(section);
if (categories == null) {
categories = new HashSet<>();
sectionAggregatedCategoriesMap.put(section, categories);
}
if (pageRow.getPageCategories() != null && pageRow.getPageCategories().size() > 0) {
categories.addAll(pageRow.getPageCategories());
}
pageRow.setSectionCategories(categories);
}
}
// sections without pages
if (!StringHelper.containsNonWhitespace(searchString)) {
for (Section section : sections) {
if (!secCallback.canViewElement(section)) {
continue;
}
PortfolioElementRow sectionRow = forgeSectionRow(section, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap);
rows.add(sectionRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(sectionRow);
sectionRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(sectionRow);
sectionRow.setNewAssignmentLink(newAssignmentButton);
}
}
}
if (newSectionButton != null && rows.isEmpty()) {
flc.add("create.new.section", newSectionButton);
} else if (newSectionButton != null) {
flc.remove(newSectionButton);
}
if (newEntryLink != null && !newEntryLink.isVisible()) {
newEntryLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
if (newAssignmentLink != null && !newAssignmentLink.isVisible()) {
newAssignmentLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
// clean up the posters
disposeRows();
model.setObjects(rows);
if (filteringSection != null) {
doFilterSection(filteringSection);
} else {
tableEl.reloadData();
updateTimeline();
}
}
use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class MyPageListController method loadModel.
@Override
protected void loadModel(UserRequest ureq, String searchString) {
Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfCommentsOnOwnedPage(getIdentity());
List<CategoryToElement> categorizedElements = portfolioService.getCategorizedOwnedPages(getIdentity());
Map<OLATResourceable, List<Category>> categorizedElementMap = new HashMap<>();
for (CategoryToElement categorizedElement : categorizedElements) {
List<Category> categories = categorizedElementMap.get(categorizedElement.getCategorizedResource());
if (categories == null) {
categories = new ArrayList<>();
categorizedElementMap.put(categorizedElement.getCategorizedResource(), categories);
}
categories.add(categorizedElement.getCategory());
}
List<Assignment> assignments = portfolioService.searchOwnedAssignments(getIdentity());
Map<Page, List<Assignment>> pageToAssignments = new HashMap<>();
for (Assignment assignment : assignments) {
Page page = assignment.getPage();
List<Assignment> assignmentList;
if (pageToAssignments.containsKey(page)) {
assignmentList = pageToAssignments.get(page);
} else {
assignmentList = new ArrayList<>();
pageToAssignments.put(page, assignmentList);
}
assignmentList.add(assignment);
}
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary");
List<Page> pages = portfolioService.searchOwnedPages(getIdentity(), searchString);
List<PortfolioElementRow> rows = new ArrayList<>(pages.size());
List<TimelinePoint> points = new ArrayList<>(pages.size());
for (Page page : pages) {
if (page.getPageStatus() == PageStatus.deleted) {
continue;
}
List<Assignment> assignmentList = pageToAssignments.get(page);
PortfolioElementRow row = forgePageRow(ureq, page, null, assignmentList, categorizedElementMap, numberOfCommentsMap, true);
rows.add(row);
if (page.getSection() != null) {
Section section = page.getSection();
row.setMetaSectionTitle(section.getTitle());
if (section.getBinder() != null) {
row.setMetaBinderTitle(section.getBinder().getTitle());
}
}
row.setNewFloatingEntryLink(newEntryButton);
String s = page.getPageStatus() == null ? "draft" : page.getPageStatus().name();
points.add(new TimelinePoint(page.getKey().toString(), page.getTitle(), page.getCreationDate(), s));
}
timelineEl.setPoints(points);
// clean up the posters
disposeRows();
model.setObjects(rows);
tableEl.reset();
tableEl.reloadData();
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class CategoryDAOTest method createCategory.
@Test
public void createCategory() {
Category category = categoryDao.createAndPersistCategory("Swag");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(category);
Assert.assertNotNull(category.getKey());
Assert.assertNotNull(category.getCreationDate());
Assert.assertEquals("Swag", category.getName());
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class CategoryDAOTest method getMediaCategoriesStatistics.
@Test
public void getMediaCategoriesStatistics() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
dbInstance.commit();
Category category = categoryDao.createAndPersistCategory("Cool");
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load medias
List<CategoryStatistics> catStatistics = categoryDao.getMediaCategoriesStatistics(id);
Assert.assertNotNull(catStatistics);
Assert.assertEquals(1, catStatistics.size());
Assert.assertEquals(category.getName(), catStatistics.get(0).getName());
Assert.assertTrue(1 <= catStatistics.get(0).getCount());
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class BinderPageListController method loadModel.
@Override
protected void loadModel(UserRequest ureq, String searchString) {
if (StringHelper.containsNonWhitespace(binder.getSummary())) {
summaryComp.setText(binder.getSummary());
flc.getFormItemComponent().put("summary", summaryCtrl.getInitialComponent());
} else {
flc.getFormItemComponent().remove("summary");
}
List<Section> sections = portfolioService.getSections(binder);
List<CategoryToElement> categorizedElements = portfolioService.getCategorizedSectionsAndPages(binder);
Map<OLATResourceable, List<Category>> categorizedElementMap = new HashMap<>();
Map<Section, Set<String>> sectionAggregatedCategoriesMap = new HashMap<>();
for (CategoryToElement categorizedElement : categorizedElements) {
List<Category> categories = categorizedElementMap.get(categorizedElement.getCategorizedResource());
if (categories == null) {
categories = new ArrayList<>();
categorizedElementMap.put(categorizedElement.getCategorizedResource(), categories);
}
categories.add(categorizedElement.getCategory());
}
// comments
Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfComments(binder);
// assessment sections
List<AssessmentSection> assessmentSections = portfolioService.getAssessmentSections(binder, getIdentity());
Map<Section, AssessmentSection> sectionToAssessmentSectionMap = assessmentSections.stream().collect(Collectors.toMap(as -> as.getSection(), as -> as));
List<PortfolioElementRow> rows = new ArrayList<>();
// assignments
List<Assignment> assignments = portfolioService.getAssignments(binder, searchString);
Map<Section, List<Assignment>> sectionToAssignmentMap = new HashMap<>();
for (Assignment assignment : assignments) {
List<Assignment> assignmentList;
Section section = assignment.getSection();
if (sectionToAssignmentMap.containsKey(section)) {
assignmentList = sectionToAssignmentMap.get(section);
} else {
assignmentList = new ArrayList<>();
sectionToAssignmentMap.put(section, assignmentList);
}
assignmentList.add(assignment);
}
for (Assignment assignment : assignments) {
Section section = assignment.getSection();
if (assignment.getPage() == null && secCallback.canViewPendingAssignments(section)) {
List<Assignment> sectionAssignments = sectionToAssignmentMap.get(section);
PortfolioElementRow row = forgePendingAssignmentRow(assignment, section, sectionAssignments);
rows.add(row);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(row);
row.setNewEntryLink(newEntryButton);
}
}
}
boolean userInfos = secCallback.canPageUserInfosStatus();
Map<Long, PageUserInformations> userInfosToPage = new HashMap<>();
rowVC.contextPut("userInfos", Boolean.valueOf(userInfos));
if (userInfos) {
rowVC.contextPut("userInfosRenderer", new SharedPageStatusCellRenderer(getTranslator()));
List<PageUserInformations> userInfoList = portfolioService.getPageUserInfos(binder, getIdentity());
for (PageUserInformations userInfo : userInfoList) {
userInfosToPage.put(userInfo.getPage().getKey(), userInfo);
}
}
List<Page> pages = portfolioService.getPages(binder, searchString);
for (Page page : pages) {
boolean viewElement = secCallback.canViewElement(page);
boolean viewTitleElement = viewElement || secCallback.canViewTitleOfElement(page);
if (!viewTitleElement) {
continue;
}
Section section = page.getSection();
PortfolioElementRow pageRow = forgePageRow(ureq, page, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap, numberOfCommentsMap, viewElement);
rows.add(pageRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(pageRow);
pageRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(pageRow);
pageRow.setNewAssignmentLink(newAssignmentButton);
}
if (userInfos) {
PageUserInformations infos = userInfosToPage.get(page.getKey());
if (infos != null) {
pageRow.setUserInfosStatus(infos.getStatus());
}
}
if (section != null) {
Set<String> categories = sectionAggregatedCategoriesMap.get(section);
if (categories == null) {
categories = new HashSet<>();
sectionAggregatedCategoriesMap.put(section, categories);
}
if (pageRow.getPageCategories() != null && pageRow.getPageCategories().size() > 0) {
categories.addAll(pageRow.getPageCategories());
}
pageRow.setSectionCategories(categories);
}
}
// sections without pages
if (!StringHelper.containsNonWhitespace(searchString)) {
for (Section section : sections) {
if (!secCallback.canViewElement(section)) {
continue;
}
PortfolioElementRow sectionRow = forgeSectionRow(section, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), categorizedElementMap);
rows.add(sectionRow);
if (secCallback.canAddPage(section)) {
FormLink newEntryButton = uifactory.addFormLink("new.entry." + (++counter), "new.entry", "create.new.page", null, flc, Link.BUTTON);
newEntryButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_entry");
newEntryButton.setUserObject(sectionRow);
sectionRow.setNewEntryLink(newEntryButton);
}
if (secCallback.canNewAssignment() && section != null) {
FormLink newAssignmentButton = uifactory.addFormLink("new.assignment." + (++counter), "new.assignment", "create.new.assignment", null, flc, Link.BUTTON);
newAssignmentButton.setCustomEnabledLinkCSS("btn btn-primary o_sel_pf_new_assignment");
newAssignmentButton.setUserObject(sectionRow);
sectionRow.setNewAssignmentLink(newAssignmentButton);
}
}
}
if (newSectionButton != null && rows.isEmpty()) {
flc.add("create.new.section", newSectionButton);
} else if (newSectionButton != null) {
flc.remove(newSectionButton);
}
if (newEntryLink != null && !newEntryLink.isVisible()) {
newEntryLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
if (newAssignmentLink != null && !newAssignmentLink.isVisible()) {
newAssignmentLink.setVisible(rows.size() > 0);
stackPanel.setDirty(true);
}
// clean up the posters
disposeRows();
model.setObjects(rows);
if (filteringSection != null) {
doFilterSection(filteringSection);
} else {
tableEl.reloadData();
updateTimeline();
}
}
Aggregations