@ -7,59 +7,7 @@ var RDB = require('./redis.js'),
( function ( Categories ) {
// START Move into possibly admin/categories.js
// An admin-only function. Seeing how we have no control panel yet ima leave this right here. sit pretty, you
Categories . create = function ( data , callback ) {
RDB . incr ( 'global:next_category_id' , function ( err , cid ) {
RDB . handle ( err ) ;
var slug = cid + '/' + utils . slugify ( data . name ) ;
RDB . rpush ( 'categories:cid' , cid ) ;
// Topic Info
RDB . set ( 'cid:' + cid + ':name' , data . name ) ;
RDB . set ( 'cid:' + cid + ':description' , data . description ) ;
RDB . set ( 'cid:' + cid + ':icon' , data . icon ) ;
RDB . set ( 'cid:' + cid + ':blockclass' , data . blockclass ) ;
RDB . set ( 'cid:' + cid + ':slug' , slug ) ;
RDB . set ( 'category:slug:' + slug + ':cid' , cid ) ;
if ( callback ) callback ( { 'status' : 1 } ) ;
} ) ;
} ;
Categories . edit = function ( data , callback ) {
// just a reminder to self that name + slugs are stored into topics data as well.
} ;
// END Move into possibly admin/categories.js
Categories . privileges = function ( cid , uid , callback ) {
function isModerator ( next ) {
user . isModerator ( uid , cid , function ( isMod ) {
next ( null , isMod ) ;
} ) ;
}
function isAdministrator ( next ) {
user . isAdministrator ( uid , function ( isAdmin ) {
next ( null , isAdmin ) ;
} ) ;
}
async . parallel ( [ isModerator , isAdministrator ] , function ( err , results ) {
callback ( {
editable : results . indexOf ( true ) !== - 1 ? true : false ,
view _deleted : results . indexOf ( true ) !== - 1 ? true : false
} ) ;
} ) ;
}
Categories . get = function ( callback , category _id , current _user ) {
Categories . getCategoryById = function ( category _id , current _user , callback ) {
RDB . smembers ( 'categories:' + category _id + ':tid' , function ( err , tids ) {
RDB . multi ( )
. get ( 'cid:' + category _id + ':name' )
@ -79,7 +27,8 @@ var RDB = require('./redis.js'),
var categoryData = {
'category_name' : category _name ,
'show_topic_button' : 'show' ,
'show_category_features' : 'show' ,
'topic_row_size' : 'span9' ,
'category_id' : category _id ,
'active_users' : active _users ,
'topics' : [ ]
@ -112,8 +61,6 @@ var RDB = require('./redis.js'),
callback ( categoryData ) ;
} ) ;
}
} ) ;
} ) ;
}
@ -123,7 +70,8 @@ var RDB = require('./redis.js'),
RDB . zrange ( 'topics:recent' , 0 , - 1 , function ( err , tids ) {
var latestTopics = {
'category_name' : 'Recent' ,
'show_topic_button' : 'hidden' ,
'show_category_features' : 'hidden' ,
'topic_row_size' : 'span12' ,
'category_id' : false ,
'topics' : [ ]
} ;
@ -140,7 +88,7 @@ var RDB = require('./redis.js'),
} ) ;
}
// not the permanent location for this function
Categories . getTopicsByTids = function ( tids , current _user , callback , category _id /*temporary*/ ) {
var title = [ ] ,
uid = [ ] ,
@ -276,6 +224,29 @@ var RDB = require('./redis.js'),
}
Categories . privileges = function ( cid , uid , callback ) {
function isModerator ( next ) {
user . isModerator ( uid , cid , function ( isMod ) {
next ( null , isMod ) ;
} ) ;
}
function isAdministrator ( next ) {
user . isAdministrator ( uid , function ( isAdmin ) {
next ( null , isAdmin ) ;
} ) ;
}
async . parallel ( [ isModerator , isAdministrator ] , function ( err , results ) {
callback ( {
editable : results . indexOf ( true ) !== - 1 ? true : false ,
view _deleted : results . indexOf ( true ) !== - 1 ? true : false
} ) ;
} ) ;
}
Categories . hasReadCategories = function ( cids , uid , callback ) {
var batch = RDB . multi ( ) ;
@ -291,6 +262,11 @@ var RDB = require('./redis.js'),
Categories . getCategories = function ( cids , callback , current _user ) {
if ( cids . length === 0 ) {
callback ( { 'categories' : [ ] } ) ;
return ;
}
var name = [ ] ,
description = [ ] ,
icon = [ ] ,
@ -308,7 +284,6 @@ var RDB = require('./redis.js'),
topic _count . push ( 'cid:' + cids [ i ] + ':topiccount' ) ;
}
if ( cids . length > 0 ) {
RDB . multi ( )
. mget ( name )
. mget ( description )
@ -349,7 +324,6 @@ var RDB = require('./redis.js'),
} ) ;
} ) ;
} else callback ( { 'categories' : [ ] } ) ;
} ;
} ( exports ) ) ;