Class: Xforum::Category
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Xforum::Category
- Defined in:
- app/models/xforum/category.rb
Class Method Summary collapse
- .add_category(params, user) ⇒ Object
- .categories(params, user) ⇒ Object
- .edit_category(params, user) ⇒ Object
- .get_category_id(params) ⇒ Object
- .get_suggestions(params, user) ⇒ Object
- .remove_object(params, user) ⇒ Object
- .restrict_me(params, user) ⇒ Object
-
.suggestion(params, user) ⇒ Object
add new category or topic.
- .suggestion_close(params, user) ⇒ Object
Class Method Details
.add_category(params, user) ⇒ Object
9 10 11 12 13 |
# File 'app/models/xforum/category.rb', line 9 def self.add_category(params,user) params[:user.id]=user.id if params[:user_id] == 'me' user.forum_admin? ? id= Category.create(name:params[:new_item],user_id:user.id).id : id='not happening' {id:id} end |
.categories(params, user) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/xforum/category.rb', line 66 def self.categories(params,user) if Category.first.nil? Category.create(name:'request new category',closed:false,suggestion:false) Category.create(name:'select category',closed:false,suggestion:false) end params[:hold_test]=='true' ? category_list= Category.grab({closed:false,suggestion:false},[:id,:name,:closed,:restricted,:is_moderated],{}) : category_list= Category.grab('all',[:id,:name,:closed,:restricted,:is_moderated],{}) category_list=ForumAssist.make_last(category_list.clone, {key: :id,ref:Category.where(name:'request new category').pluck(:id)[0]}) category_list=ForumAssist.make_first(category_list.clone,{key: :id,ref:Category.where(name:'select category').pluck(:id)[0]}) category_list=PeopleList.check_restrictions(category_list.clone,user,'categories') category_list=Translation.translate_list(category_list.clone,params[:language],'category') category_list.push({id:0, item:'admin',value: I18n.t('xForum.Admin_name')}) if user.forum_admin? {list_data:category_list,id:params[:list]} end |
.edit_category(params, user) ⇒ Object
52 53 54 |
# File 'app/models/xforum/category.rb', line 52 def self.edit_category(params,user) Category.where(id: params[:id]).update_all(name: params[:newline], is_moderated: params[:moderate_me]=='true') if user.forum_admin? end |
.get_category_id(params) ⇒ Object
81 82 83 |
# File 'app/models/xforum/category.rb', line 81 def self.get_category_id(params) Category.where(name:params[:category]).pluck(:id)[0] end |
.get_suggestions(params, user) ⇒ Object
45 46 47 48 49 50 |
# File 'app/models/xforum/category.rb', line 45 def self.get_suggestions(params,user) data= Category.where(suggestion:true).pluck(:name, :user_id,:id) data=ForumAssist.named_array(data, [:suggestion, :user,:id]) unless data.empty? data=ForumAssist.add_user_name(data.clone) unless data.empty? user.forum_admin? ? {data: data, list: 'forum-category-prososals-list'} : {response: 'nothing doing'} end |
.remove_object(params, user) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/models/xforum/category.rb', line 15 def self.remove_object(params,user) case(params[:state_action]) when 'del' then Category.where(id:params[:id]).update_all(closed:true) when 'open' then Category.where(id:params[:id]).update_all(closed:false) else # type code here end if user.forum_admin? {action:'nothing to do'} end |
.restrict_me(params, user) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/xforum/category.rb', line 25 def self.restrict_me(params,user) if user.forum_admin? category=Category.find_by(name: params[:category]) unless category.nil? unless params[:user_list].nil? || params[:user_list]=='select list' people_list=PeopleList.find_by(id:params[:user_list]) if people_list.category_id.nil? && people_list.list =='invitation' people_list.update(category_id:category.id ) else new_list=people_list.clone new_list.name=category.name+'-invitees' new_list.list='invitation' new_list.category_id=category.id end end category.update(restricted:!category.restricted) end end end |
.suggestion(params, user) ⇒ Object
add new category or topic
55 56 57 58 |
# File 'app/models/xforum/category.rb', line 55 def self.suggestion(params,user) #add new category or topic Category.create(suggestion:true,name:params[:suggestion],user_id:user.id) {response:'nothing to do'} end |
.suggestion_close(params, user) ⇒ Object
60 61 62 63 64 |
# File 'app/models/xforum/category.rb', line 60 def self.suggestion_close(params,user) params[:result]=='Accept' ? (Category.where(id: params[:id]).update_all(suggestion: false) if user.forum_admin?) : Category.where(id: params[:id]).update_all(state: 'closed') if user.forum_admin? end |