v1.18.x
barisusakli 10 years ago
parent 20983c43f4
commit 48b5d90a9e

@ -159,7 +159,11 @@ var async = require('async'),
category.disabled = parseInt(category.disabled, 10) === 1; category.disabled = parseInt(category.disabled, 10) === 1;
category.icon = category.icon || 'hidden'; category.icon = category.icon || 'hidden';
if (category.hasOwnProperty('post_count')) { if (category.hasOwnProperty('post_count')) {
category.post_count = category.post_count || 0; category.post_count = category.totalPostCount = category.post_count || 0;
}
if (category.hasOwnProperty('topic_count')) {
category.topic_count = category.totalTopicCount = category.topic_count || 0;
} }
if (category.description) { if (category.description) {
@ -250,18 +254,23 @@ var async = require('async'),
}; };
function calculateTopicPostCount(category) { function calculateTopicPostCount(category) {
if (!Array.isArray(category.children) || !category.children.length) { 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) {
category.totalPostCount = postCount;
category.totalTopicCount = topicCount;
return;
}
category.children.forEach(function(child) { category.children.forEach(function(child) {
postCount += parseInt(child.post_count, 10) || 0; postCount += parseInt(child.post_count, 10) || 0;
topicCount += parseInt(child.topic_count, 10) || 0; topicCount += parseInt(child.topic_count, 10) || 0;
}); });
category.post_count = postCount; category.totalPostCount = postCount;
category.topic_count = topicCount; category.totalTopicCount = topicCount;
} }
Categories.getParents = function(cids, callback) { Categories.getParents = function(cids, callback) {

Loading…
Cancel
Save