Search in sources :

Example 1 with CmsVote

use of com.publiccms.entities.cms.CmsVote in project PublicCMS-preview by sanluan.

the class CmsVoteAdminController method save.

/**
 * @param entity
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("save")
public String save(CmsVote entity, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    if (null != entity.getId()) {
        CmsVote oldEntity = service.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        entity = service.update(entity.getId(), entity, ignoreProperties);
        if (null != entity) {
            logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.vote", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        entity.setSiteId(site.getId());
        service.save(entity);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.vote", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsVote(com.publiccms.entities.cms.CmsVote) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CmsVote

use of com.publiccms.entities.cms.CmsVote in project PublicCMS-preview by sanluan.

the class CmsVoteAdminController method delete.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Integer id, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    CmsVote entity = service.getEntity(id);
    if (null != entity) {
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        service.delete(id);
        logOperateService.save(new LogOperate(site.getId(), getAdminFromSession(session).getId(), LogLoginService.CHANNEL_WEB_MANAGER, "delete.vote", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsVote(com.publiccms.entities.cms.CmsVote) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CmsVote

use of com.publiccms.entities.cms.CmsVote in project PublicCMS-preview by sanluan.

the class CmsVoteDirective method execute.

@Override
public void execute(RenderHandler handler) throws IOException, Exception {
    Integer id = handler.getInteger("id");
    if (CommonUtils.notEmpty(id)) {
        handler.put("object", service.getEntity(id)).render();
    } else {
        Integer[] ids = handler.getIntegerArray("ids");
        if (CommonUtils.notEmpty(ids)) {
            List<CmsVote> entityList = service.getEntitys(ids);
            Map<String, CmsVote> map = new LinkedHashMap<>();
            for (CmsVote entity : entityList) {
                map.put(String.valueOf(entity.getId()), entity);
            }
            handler.put("map", map).render();
        }
    }
}
Also used : CmsVote(com.publiccms.entities.cms.CmsVote) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with CmsVote

use of com.publiccms.entities.cms.CmsVote in project PublicCMS-preview by sanluan.

the class VoteDirective method execute.

@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
    Integer voteId = handler.getInteger("voteId");
    Long[] itemIds = handler.getLongArray("itemIds");
    CmsVote vote = voteService.getEntity(voteId);
    if (null != vote && CommonUtils.notEmpty(itemIds) && !vote.isDisabled() && 0 == voteUserService.getPage(voteId, user.getId(), null, null, null, null, null, null).getTotalCount()) {
        CmsVoteUser entity = new CmsVoteUser(voteId, user.getId(), StringUtils.arrayToCommaDelimitedString(itemIds), RequestUtils.getIpAddress(handler.getRequest()), CommonUtils.getDate());
        voteUserService.save(entity);
        voteService.updateUserCounts(voteId);
        voteItemService.updateScores(itemIds);
    }
}
Also used : CmsVote(com.publiccms.entities.cms.CmsVote) CmsVoteUser(com.publiccms.entities.cms.CmsVoteUser)

Aggregations

CmsVote (com.publiccms.entities.cms.CmsVote)4 LogOperate (com.publiccms.entities.log.LogOperate)2 SysSite (com.publiccms.entities.sys.SysSite)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CmsVoteUser (com.publiccms.entities.cms.CmsVoteUser)1 LinkedHashMap (java.util.LinkedHashMap)1