Search in sources :

Example 16 with PageBody

use of org.olat.modules.portfolio.PageBody in project OpenOLAT by OpenOLAT.

the class PageDAOTest method persistPart.

@Test
public void persistPart() {
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, null, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    TitlePart titlePart = new TitlePart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, titlePart, 0);
    dbInstance.commitAndCloseSession();
    // reload
    List<PagePart> reloadedPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(reloadedPageParts);
    Assert.assertEquals(2, reloadedPageParts.size());
    Assert.assertEquals(titlePart, reloadedPageParts.get(0));
    Assert.assertEquals(htmlPart, reloadedPageParts.get(1));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) TitlePart(org.olat.modules.portfolio.model.TitlePart) Page(org.olat.modules.portfolio.Page) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Example 17 with PageBody

use of org.olat.modules.portfolio.PageBody in project OpenOLAT by OpenOLAT.

the class PageDAO method deletePage.

/**
 * The page cannot be detached (reload it if necessary).
 *
 * @param page
 * @return
 */
public int deletePage(Page page) {
    // nothing to do
    if (page == null || page.getKey() == null)
        return 0;
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Page.class, page.getKey());
    PageBody body = page.getBody();
    String partQ = "delete from pfpagepart part where part.body.key=:bodyKey";
    int parts = dbInstance.getCurrentEntityManager().createQuery(partQ).setParameter("bodyKey", body.getKey()).executeUpdate();
    String assignmentQ = "delete from pfassignment assignment where assignment.page.key=:pageKey";
    int assignments = dbInstance.getCurrentEntityManager().createQuery(assignmentQ).setParameter("pageKey", page.getKey()).executeUpdate();
    int evaluations = evaluationFormSessionDao.deleteSessionForPortfolioEvaluation(body);
    dbInstance.getCurrentEntityManager().remove(page);
    dbInstance.getCurrentEntityManager().remove(body);
    int comments = userCommentsDAO.deleteAllComments(ores, null);
    return comments + parts + evaluations + assignments + 2;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PersistenceHelper.makeFuzzyQueryString(org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString) PageBody(org.olat.modules.portfolio.PageBody)

Example 18 with PageBody

use of org.olat.modules.portfolio.PageBody in project OpenOLAT by OpenOLAT.

the class PortfolioServiceImpl method removePagePart.

@Override
public void removePagePart(Page page, PagePart part) {
    PageBody body = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.removePart(body, part);
}
Also used : PageBody(org.olat.modules.portfolio.PageBody)

Example 19 with PageBody

use of org.olat.modules.portfolio.PageBody in project OpenOLAT by OpenOLAT.

the class EvaluationFormHandler method getEditor.

@Override
public Controller getEditor(UserRequest ureq, WindowControl wControl, PageElement element) {
    if (element instanceof EvaluationFormPart) {
        PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
        // find assignment
        EvaluationFormPart eva = (EvaluationFormPart) element;
        PageBody body = eva.getBody();
        Assignment assignment = portfolioService.getAssignment(body);
        // find the evaluation form
        RepositoryEntry re = assignment.getFormEntry();
        File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), FileResourceManager.ZIPDIR);
        File formFile = new File(repositoryDir, FORM_XML_FILE);
        return new EvaluationFormController(ureq, wControl, formFile);
    }
    return null;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) MultiEvaluationFormController(org.olat.modules.portfolio.ui.MultiEvaluationFormController) EvaluationFormController(org.olat.modules.forms.ui.EvaluationFormController) EvaluationFormPart(org.olat.modules.portfolio.model.EvaluationFormPart) PortfolioService(org.olat.modules.portfolio.PortfolioService) RepositoryEntry(org.olat.repository.RepositoryEntry) PageBody(org.olat.modules.portfolio.PageBody) File(java.io.File)

Example 20 with PageBody

use of org.olat.modules.portfolio.PageBody in project openolat by klemens.

the class PageDAOTest method moveParts.

@Test
public void moveParts() {
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, null, null);
    dbInstance.commitAndCloseSession();
    HTMLPart htmlPart = new HTMLPart();
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, htmlPart);
    dbInstance.commitAndCloseSession();
    TitlePart titlePart = new TitlePart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, titlePart, 0);
    dbInstance.commitAndCloseSession();
    SpacerPart spacePart = new SpacerPart();
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, spacePart, 0);
    dbInstance.commitAndCloseSession();
    // check the order
    List<PagePart> reloadedPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(reloadedPageParts);
    Assert.assertEquals(3, reloadedPageParts.size());
    Assert.assertEquals(spacePart, reloadedPageParts.get(0));
    Assert.assertEquals(titlePart, reloadedPageParts.get(1));
    Assert.assertEquals(htmlPart, reloadedPageParts.get(2));
    // move title part up
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveUpPart(reloadedBody, titlePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveUpPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveUpPageParts);
    Assert.assertEquals(3, moveUpPageParts.size());
    Assert.assertEquals(titlePart, moveUpPageParts.get(0));
    Assert.assertEquals(spacePart, moveUpPageParts.get(1));
    Assert.assertEquals(htmlPart, moveUpPageParts.get(2));
    // move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts);
    Assert.assertEquals(3, moveDownPageParts.size());
    Assert.assertEquals(titlePart, moveDownPageParts.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts.get(2));
    // not useful move space part down
    reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.moveDownPart(reloadedBody, spacePart);
    dbInstance.commitAndCloseSession();
    List<PagePart> moveDownPageParts2 = pageDao.getParts(reloadedBody);
    Assert.assertNotNull(moveDownPageParts2);
    Assert.assertEquals(3, moveDownPageParts2.size());
    Assert.assertEquals(titlePart, moveDownPageParts2.get(0));
    Assert.assertEquals(htmlPart, moveDownPageParts2.get(1));
    Assert.assertEquals(spacePart, moveDownPageParts2.get(2));
}
Also used : PagePart(org.olat.modules.portfolio.PagePart) HTMLPart(org.olat.modules.portfolio.model.HTMLPart) TitlePart(org.olat.modules.portfolio.model.TitlePart) Page(org.olat.modules.portfolio.Page) PageBody(org.olat.modules.portfolio.PageBody) SpacerPart(org.olat.modules.portfolio.model.SpacerPart) Test(org.junit.Test)

Aggregations

PageBody (org.olat.modules.portfolio.PageBody)26 Test (org.junit.Test)14 Page (org.olat.modules.portfolio.Page)14 Section (org.olat.modules.portfolio.Section)8 HTMLPart (org.olat.modules.portfolio.model.HTMLPart)8 Identity (org.olat.core.id.Identity)6 PagePart (org.olat.modules.portfolio.PagePart)6 BinderImpl (org.olat.modules.portfolio.model.BinderImpl)6 TitlePart (org.olat.modules.portfolio.model.TitlePart)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 EvaluationFormSession (org.olat.modules.forms.EvaluationFormSession)4 EvaluationFormController (org.olat.modules.forms.ui.EvaluationFormController)4 Assignment (org.olat.modules.portfolio.Assignment)4 PortfolioService (org.olat.modules.portfolio.PortfolioService)4 EvaluationFormPart (org.olat.modules.portfolio.model.EvaluationFormPart)4 MultiEvaluationFormController (org.olat.modules.portfolio.ui.MultiEvaluationFormController)4 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 Path (java.nio.file.Path)2 PersistenceHelper.makeFuzzyQueryString (org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString)2