Class: Xforum::Forum
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Xforum::Forum
- Defined in:
- app/models/xforum/forum.rb
Constant Summary collapse
- USER_BLOCK_SIZE =
300
Class Method Summary collapse
- .add_comment(params, user) ⇒ Object
- .change_state(params, user) ⇒ Object
- .clear_user_topic(user_id, topic_id) ⇒ Object
- .do_admin_action(params, user) ⇒ Object
- .get_forum_actions(params, user) ⇒ Object
- .get_indent(id, index) ⇒ Object
- .is_child_there?(senate_list, new_list, parent, me, user_id) ⇒ Boolean
- .look_for_key(list, key, test) ⇒ Object
- .senate(params, user) ⇒ Object
- .set_new_senate_entry(senate_list, new_list, index, user_id, options) ⇒ Object
- .set_the_rest(params, user) ⇒ Object
Class Method Details
.add_comment(params, user) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/models/xforum/forum.rb', line 166 def self.add_comment(params,user) topic_id=Topic.where(name:params[:topic]).pluck(:id)[0] restricted=params[:restricted] == 'true' unless params[:comment].nil? || params[:comment].empty? || !user.forum_posting_privileges? has_photo=params[:already_has_photo] == 'true' || params[:needs_photo] == 'true' params[:id]=Forum.where(user_id:user.id,tag:params[:tag].to_s).pluck(:id)[0] if params[:id].nil? if params[:edit]=='true' && (user.id==Forum.where(id:params[:id]).pluck(:user_id)[0] || user.forum_admin?) forum_id=params[:id] Forum.where(id: params[:id]).update_all(content: params[:comment],has_photo:has_photo, parent: params[:parent],restricted:restricted) else owner_name=Xforum.user_class.where(id:user.id).pluck(:forum_post_name)[0] forum_id= Forum.create(parent:params[:parent],topic_id:topic_id,tag:params[:tag], has_photo:has_photo, user_id:user.id,content:params[:comment],restricted:restricted,owner_name:owner_name).id Translation.create(forum_id:forum_id,user_id:user.id,topic_id:topic_id, language_id:Language.get_language_locale(params), content:params[:comment],suggestion:false,state:'new') end Translation.add_one(params,topic_id,user.id,forum_id) if params[:translating] && user.forum_translating_privileges? PeopleList.make_invitation(params,forum_id,user) if params[:restricted]=='true' PeopleList.add_to_invitation(params,forum_id,user) unless params[:invitees].nil? Hyperlink.add_set(params,forum_id) unless params[:link_ref].nil? end {parent:params[:parent],id:forum_id,topic_id:topic_id,tag:params[:tag],edit:params[:edit]=='true'} end |
.change_state(params, user) ⇒ Object
203 204 205 206 |
# File 'app/models/xforum/forum.rb', line 203 def self.change_state(params,user) Forum.where(id:params[:id]).update_all(state: params[:function],resolution:params[:resolution]) if PeopleList.check_people({topic:params[:id], user_id:user.id,list:'moderator'}) || user.forum_admin? {action:'nothing to do'} end |
.clear_user_topic(user_id, topic_id) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/xforum/forum.rb', line 101 def self.clear_user_topic(user_id,topic_id) comments=Forum.grab({topic_id:topic_id},[:id,:tag],{order:[:tag]}) =[] test_comments=comments.clone test_comments.each{ |comment| if (comment[:tag].to_i) < USER_BLOCK_SIZE*user_id && comment[:tag].to_i <= USER_BLOCK_SIZE*(user_id+1) comments.delete_at(comments.index(comment)) else .push((comment[:tag].to_i)%USER_BLOCK_SIZE ) comment[:tag]= .last end } if .empty? index=0 elsif .index(USER_BLOCK_SIZE*1/3).nil? && .index(USER_BLOCK_SIZE*2/3).nil? index=USER_BLOCK_SIZE*1/3 elsif .index(USER_BLOCK_SIZE*2/3).nil? index= USER_BLOCK_SIZE*2/3 (0....size).each {|i| Forum.where(id:comments[i][:id]).update_all(tag:-1) if [i] < USER_BLOCK_SIZE*1/3 } elsif .index(USER_BLOCK_SIZE*0/3).nil? index=0 (0....size).each {|i| Forum.where(id:comments[i][:id]).update_all(tag:-1) if [i] >= USER_BLOCK_SIZE*1/3 && [i]< USER_BLOCK_SIZE*2/3 } else .index(USER_BLOCK_SIZE*1/3).nil? index=USER_BLOCK_SIZE*1/3 (0....size).each {|i| Forum.where(id:comments[i][:id]).update_all(tag:-1) if [i] >= USER_BLOCK_SIZE*2/3 } end index+user_id*USER_BLOCK_SIZE end |
.do_admin_action(params, user) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/xforum/forum.rb', line 13 def self.do_admin_action(params,user) params[:users1]=[] if params[:users1].nil? params[:users2]=[] if params[:users2].nil? user_ids=[] unless params[:user_emails].nil? people_emails=params[:user_emails].split(",\n") people_emails.each{|email|user_ids.push(User.where(email:email).pluck(:id)[0] ) } (0...user_ids.size).each{|i| user_ids[i]=user_ids[i].to_i} end case params[:forum_action] when 'suspend posting' users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_posting_priviages: false) } when 'suspend all' users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_reading_priviages: false) } users_ids.each { |user_id| Xforum.user_class.where(id: user_id).update_all(forum_posting_priviages: false) } when 'send email to' UserMailer.note_to_forum_users(params, user_ids).deliver when 'create list', 'edit list' PeopleList.manage_list(params, user_ids) when 'add topic monitor' Topic.add_topic_monitor(params, user_ids) when 'restrict topic' Topic.restrict_me(params, user) when 'restrict category' Category.restrict_me(params, user) else # type code here end if user.forum_admin? {action:'nothing to do'} end |
.get_forum_actions(params, user) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/models/xforum/forum.rb', line 188 def self.get_forum_actions(params,user) alist= [] alist.push(['select action',I18n.t('xForum.select_action')]) if user.forum_admin? alist.push(['suspend posting',I18n.t('xForum.suspend_posting')]) alist.push(['suspend all',I18n.t('xForum.suspend_all')]) alist.push(['send email to',I18n.t('xForum.send_email_to')]) alist.push(['create list',I18n.t('xForum.create_user_list')]) alist.push(['edit list',I18n.t('xForum.edit_user_list') ]) alist.push(['add topic monitor',I18n.t('xForum.Add_Topic_Monitor') ]) end {list_data:ForumAssist.named_array(alist,[:item,:value]),id:'forum-actions'} end |
.get_indent(id, index) ⇒ Object
152 153 154 155 156 |
# File 'app/models/xforum/forum.rb', line 152 def self.get_indent(id,index) parent=Forum.where(id:id).pluck(:parent)[0] index=Forum.get_indent(parent,index+1) unless parent==0 || parent.nil? index end |
.is_child_there?(senate_list, new_list, parent, me, user_id) ⇒ Boolean
214 215 216 217 218 219 220 221 222 223 |
# File 'app/models/xforum/forum.rb', line 214 def self.is_child_there?(senate_list,new_list, parent,me,user_id) child=Forum.look_for_key(senate_list,:parent,me) unless child.nil? child=Forum.set_new_senate_entry(senate_list, new_list, child, user_id, {}) is_child_there?(senate_list, new_list, me, child, user_id) unless senate_list.empty? end if me!=parent && me!=0 Forum.is_child_there?(senate_list, new_list,parent ,parent, user_id) unless senate_list.empty? end end |
.look_for_key(list, key, test) ⇒ Object
158 159 160 161 162 163 164 |
# File 'app/models/xforum/forum.rb', line 158 def self.look_for_key(list,key,test) index_out=nil (list.size-1).downto(0).each { |index| index_out=index if list[index][key]==test } unless list.empty? index_out end |
.senate(params, user) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/xforum/forum.rb', line 44 def self.senate(params,user) if params[:topic]== 'select topic' return end topic=Topic.find_by(name:params[:topic]) category=Category.find_by(id:topic.category_id) if (category.private || !user.forum_admin?) && PeopleList.check_invitation(category.name,category.id, user.id, 'category') {to_do:'nothing'} elsif (topic.restricted && !user.forum_admin?) && PeopleList.check_invitation(topic.name,topic.id, user.id, 'topic') {to_do:'nothing'} else index=Forum.clear_user_topic(user.id,topic.id) the_list=[] plucking= [:id, :parent, :content, :user_id,:owner_name,:state,:restricted,:tag,:has_photo] plucking_names= [:id, :parent, :content,:owner,:owner_name,:comment_state,:restricted,:tag,:has_photo,:needs_translation,:empty_list] #we're going to append empty list to the reply moderator=PeopleList.check_people({topic:topic.id,user_id:user.id,list:'moderator'}) || user.forum_admin? if params[:review]=='true' && moderator test=Forum.where(topic_id:topic.id,state:'new').pluck(:id) unless test.empty? item1=ForumAssist.named_array(Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic.id},plucking:plucking,size:0}),plucking_names) item1.store(:moderator,true) item1.store(:review,true) new_list= ForumAssist.named_array( Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic.id,state:'new'},ordering:([:topic_id]),plucking:plucking,size:'all'}),plucking_names ) new_list.unshift(item1) the_list=new_list end else senate_list=ForumAssist.named_array(Translation.get_localized_forum(Language.get_me(params),{lookup:{topic_id:topic.id,hold:false},ordering:[:parent,:created_at],plucking:plucking,size:'all'}), plucking_names ) if senate_list.nil? || senate_list.empty? [] else voting=Topic.grab({id:topic.id},[:vote,:votes],{})[0] voting[:vote] ? votes=Topic.count_votes(JSON.load(voting[:votes])) : votes=0 parent=Forum.look_for_key(senate_list,:parent,0) new_list=[] subscribed=PeopleList.check_people({topic:topic.id,user_id:user.id,list:'subscribers'}) parent=set_new_senate_entry(senate_list,new_list,parent,user.id, {moderator:moderator,vote:voting[:vote],votes:votes,subscribed:subscribed,admin:user.forum_admin?}) unless parent.nil? Forum.is_child_there?(senate_list,new_list,0,parent,user.id) #push first child new_list.delete_if {|record| test=!PeopleList.check_people_list({topic:record[:id], user_id:user.id,list:'invitation'}) if (record[:restricted] && !record[:owner]) if test.nil? case record[:state] when 'reject' then test= true when 'new' ENV['XFORUM_NEW_RULE']=='no' || Topic.where(id:topic.id).is_moderated else test=false end end test } the_list=new_list end end {the_list:the_list,index:index} end end |
.set_new_senate_entry(senate_list, new_list, index, user_id, options) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/models/xforum/forum.rb', line 136 def self.set_new_senate_entry(senate_list,new_list,index,user_id,) senate_list[index].store(:photos,Photo.get_photos(senate_list[index][:id])) if senate_list[index][:has_photo] senate_list[index].store(:hyperlinks,Hyperlink.get_links(senate_list[index][:id])) senate_list[index].store(:indent,Forum.get_indent(senate_list[index][:id],0) ) senate_list[index][:owner]= senate_list[index][:owner]==user_id senate_list[index].store(:moderator,[:moderator]) unless [:moderator].nil? senate_list[index].store(:vote,[:vote]) unless [:vote].nil? senate_list[index].store(:votes,[:votes]) unless [:votes].nil? senate_list[index].store(:admin_lists,[:admin_lists]) unless [:admin_lists].nil? senate_list[index].store(:subscribed,[:subscribed]) unless [:subscribed].nil? new_list.push(senate_list[index]) id=senate_list[index][:id] senate_list.delete_at(index) id end |
.set_the_rest(params, user) ⇒ Object
208 209 210 211 212 |
# File 'app/models/xforum/forum.rb', line 208 def self.set_the_rest(params,user) topic_id=Topic.where(name:params[:topic]).pluck(:id)[0] Forum.where(topic_id:topic_id, state: 'new').update_all(state: params[:state]) if PeopleList.check_people({topic:topic_id,user_id:user.id,list:'moderator'}) || user.forum_admin? {action:'nothing to do'} end |