|
|
@ -103,10 +103,10 @@ var async = require('async'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoriesByPrivilege = function(uid, privilege, callback) {
|
|
|
|
Categories.getCategoriesByPrivilege = function(set, uid, privilege, callback) {
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function(next) {
|
|
|
|
function(next) {
|
|
|
|
db.getSortedSetRange('categories:cid', 0, -1, next);
|
|
|
|
db.getSortedSetRange(set, 0, -1, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(cids, next) {
|
|
|
|
function(cids, next) {
|
|
|
|
privileges.categories.filterCids(privilege, cids, uid, next);
|
|
|
|
privileges.categories.filterCids(privilege, cids, uid, next);
|
|
|
@ -273,6 +273,7 @@ var async = require('async'),
|
|
|
|
if (!category) {
|
|
|
|
if (!category) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var postCount = parseInt(category.post_count, 10) || 0;
|
|
|
|
var postCount = parseInt(category.post_count, 10) || 0;
|
|
|
|
var topicCount = parseInt(category.topic_count, 10) || 0;
|
|
|
|
var topicCount = parseInt(category.topic_count, 10) || 0;
|
|
|
|
if (!Array.isArray(category.children) || !category.children.length) {
|
|
|
|
if (!Array.isArray(category.children) || !category.children.length) {
|
|
|
@ -282,9 +283,11 @@ var async = require('async'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
category.children.forEach(function(child) {
|
|
|
|
category.children.forEach(function(child) {
|
|
|
|
postCount += parseInt(child.post_count, 10) || 0;
|
|
|
|
calculateTopicPostCount(child);
|
|
|
|
topicCount += parseInt(child.topic_count, 10) || 0;
|
|
|
|
postCount += parseInt(child.totalPostCount, 10) || 0;
|
|
|
|
|
|
|
|
topicCount += parseInt(child.totalTopicCount, 10) || 0;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
category.totalPostCount = postCount;
|
|
|
|
category.totalPostCount = postCount;
|
|
|
|
category.totalTopicCount = topicCount;
|
|
|
|
category.totalTopicCount = topicCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -308,23 +311,58 @@ var async = require('async'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getChildren = function(cids, uid, callback) {
|
|
|
|
Categories.getChildren = function(cids, uid, callback) {
|
|
|
|
|
|
|
|
var categories = cids.map(function(cid) {
|
|
|
|
|
|
|
|
return {cid: cid};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.each(categories, function(category, next) {
|
|
|
|
|
|
|
|
getChildrenRecursive(category, category.cid, uid, next);
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
|
|
|
|
callback(err, categories.map(function(c) {
|
|
|
|
|
|
|
|
return c && c.children;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getChildrenRecursive(category, parentCid, uid, callback) {
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
|
|
|
|
function (next) {
|
|
|
|
function(cids, next) {
|
|
|
|
db.getSortedSetRange('cid:' + parentCid + ':children', 0, -1, next);
|
|
|
|
privileges.categories.filterCids('find', cids, uid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (cids, next) {
|
|
|
|
function (children, next) {
|
|
|
|
Categories.getCategoriesData(cids, next);
|
|
|
|
privileges.categories.filterCids('find', children, uid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (children, next) {
|
|
|
|
|
|
|
|
if (!children.length) {
|
|
|
|
|
|
|
|
category.children = [];
|
|
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Categories.getCategoriesData(children, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (categories, next) {
|
|
|
|
function (childrenData, next) {
|
|
|
|
async.map(cids, function(cid, next) {
|
|
|
|
category.children = childrenData;
|
|
|
|
next(null, categories.filter(function(category) {
|
|
|
|
async.each(category.children, function(child, next) {
|
|
|
|
return category && parseInt(category.parentCid, 10) === parseInt(cid, 10);
|
|
|
|
getChildrenRecursive(child, child.cid, uid, next);
|
|
|
|
}));
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
}, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.flattenCategories = function(allCategories, categoryData) {
|
|
|
|
|
|
|
|
categoryData.forEach(function(category) {
|
|
|
|
|
|
|
|
if (!category) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!category.parent) {
|
|
|
|
|
|
|
|
allCategories.push(category);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(category.children) && category.children.length) {
|
|
|
|
|
|
|
|
Categories.flattenCategories(allCategories, category.children);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Recursively build tree
|
|
|
|
* Recursively build tree
|
|
|
@ -335,13 +373,13 @@ var async = require('async'),
|
|
|
|
Categories.getTree = function(categories, parentCid) {
|
|
|
|
Categories.getTree = function(categories, parentCid) {
|
|
|
|
var tree = [], i = 0, len = categories.length, category;
|
|
|
|
var tree = [], i = 0, len = categories.length, category;
|
|
|
|
|
|
|
|
|
|
|
|
for(i; i < len; ++i) {
|
|
|
|
for (i; i < len; ++i) {
|
|
|
|
category = categories[i];
|
|
|
|
category = categories[i];
|
|
|
|
if (!category.hasOwnProperty('parentCid')) {
|
|
|
|
if (!category.hasOwnProperty('parentCid')) {
|
|
|
|
category.parentCid = 0;
|
|
|
|
category.parentCid = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(category.parentCid == parentCid){
|
|
|
|
if (category.parentCid == parentCid){
|
|
|
|
tree.push(category);
|
|
|
|
tree.push(category);
|
|
|
|
category.children = Categories.getTree(categories, category.cid);
|
|
|
|
category.children = Categories.getTree(categories, category.cid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|