Search in sources :

Example 1 with CmsVoteUser

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

the class CmsVoteUserDirective method execute.

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

Example 2 with CmsVoteUser

use of com.publiccms.entities.cms.CmsVoteUser 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

CmsVoteUser (com.publiccms.entities.cms.CmsVoteUser)2 CmsVote (com.publiccms.entities.cms.CmsVote)1 LinkedHashMap (java.util.LinkedHashMap)1