use of com.publiccms.entities.cms.CmsCategory in project PublicCMS-preview by sanluan.
the class CmsCategoryService method delete.
/**
* @param siteId
* @param ids
*/
public void delete(short siteId, Integer[] ids) {
for (CmsCategory entity : getEntitys(ids)) {
if (siteId == entity.getSiteId() && !entity.isDisabled()) {
@SuppressWarnings("unchecked") List<CmsCategory> list = (List<CmsCategory>) getPage(new CmsCategoryQuery(siteId, entity.getId(), false, null, null, null, null), null, null).getList();
for (CmsCategory child : list) {
child.setParentId(entity.getParentId());
}
entity.setDisabled(true);
generateChildIds(entity.getSiteId(), entity.getParentId());
}
}
}
use of com.publiccms.entities.cms.CmsCategory in project PublicCMS-preview by sanluan.
the class CmsCategoryService method getChildIds.
private String getChildIds(short siteId, Integer parentId) {
StringBuilder childIds = new StringBuilder();
@SuppressWarnings("unchecked") List<CmsCategory> list = (List<CmsCategory>) getPage(new CmsCategoryQuery(siteId, parentId, false, null, null, null, false), null, null).getList();
if (0 < list.size()) {
for (CmsCategory category : list) {
childIds.append(category.getId());
childIds.append(COMMA_DELIMITED);
String childChildIds = getChildIds(siteId, category.getId());
if (CommonUtils.notEmpty(childChildIds)) {
childIds.append(childChildIds);
childIds.append(COMMA_DELIMITED);
}
}
if (0 < childIds.length()) {
childIds.setLength(childIds.length() - 1);
}
}
if (0 < childIds.length()) {
return childIds.toString();
} else {
return null;
}
}
use of com.publiccms.entities.cms.CmsCategory in project PublicCMS-preview by sanluan.
the class CmsCategoryService method generateChildIds.
/**
* @param siteId
* @param parentId
*/
public void generateChildIds(short siteId, Integer parentId) {
if (null != parentId) {
updateChildIds(parentId, getChildIds(siteId, parentId));
CmsCategory parent = getEntity(parentId);
if (null != parent) {
generateChildIds(siteId, parent.getParentId());
}
}
}
use of com.publiccms.entities.cms.CmsCategory in project PublicCMS-preview by sanluan.
the class CmsCategoryService method addChildIds.
/**
* @param parentId
* @param id
*/
public void addChildIds(Serializable parentId, Serializable id) {
if (null != parentId) {
CmsCategory parent = getEntity(parentId);
if (null != parent) {
addChildIds(parent.getParentId(), id);
String childIds;
if (CommonUtils.notEmpty(parent.getChildIds())) {
childIds = parent.getChildIds() + COMMA_DELIMITED + String.valueOf(id);
} else {
childIds = String.valueOf(id);
}
updateChildIds(parent.getId(), childIds);
}
}
}
use of com.publiccms.entities.cms.CmsCategory in project PublicCMS-preview by sanluan.
the class CmsCategoryDirective method execute.
@Override
public void execute(RenderHandler handler) throws IOException, Exception {
Integer id = handler.getInteger("id");
SysSite site = getSite(handler);
if (CommonUtils.notEmpty(id)) {
CmsCategory entity = service.getEntity(id);
if (null != entity && site.getId() == entity.getSiteId()) {
handler.put("object", entity).render();
}
} else {
Integer[] ids = handler.getIntegerArray("ids");
if (CommonUtils.notEmpty(ids)) {
List<CmsCategory> entityList = service.getEntitys(ids);
Map<String, CmsCategory> map = new LinkedHashMap<>();
for (CmsCategory entity : entityList) {
if (site.getId() == entity.getSiteId()) {
map.put(String.valueOf(entity.getId()), entity);
}
}
handler.put("map", map).render();
}
}
}
Aggregations