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
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/models/xforum/forum.rb', line 157 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[:translation],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
194 195 196 197 |
# File 'app/models/xforum/forum.rb', line 194 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
92 93 94 95 96 97 98 99 100 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 |
# File 'app/models/xforum/forum.rb', line 92 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 |
# 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=(params[:users1] + params[:users2]) user_ids.uniq! (0...user_ids.size).each{|i| user_ids[i]=user_ids[i].to_i} user_ids.delete(0) 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 distribution', 'add to distribution', 'remove from distro' 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
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/models/xforum/forum.rb', line 179 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 distribution',I18n.t('xForum.create_distribution')]) alist.push(['add to distribution',I18n.t('xForum.add_to_distribution') ]) 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
143 144 145 146 147 |
# File 'app/models/xforum/forum.rb', line 143 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
205 206 207 208 209 210 211 212 213 214 |
# File 'app/models/xforum/forum.rb', line 205 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
149 150 151 152 153 154 155 |
# File 'app/models/xforum/forum.rb', line 149 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
42 43 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 |
# File 'app/models/xforum/forum.rb', line 42 def self.senate(params,user) if params[:topic]== 'select topic' {to_do:'nothing'} else topic_id=Topic.where(name:params[:topic]).pluck(:id)[0] 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= false when 'new' then test= !(ENV['XFORUM_NEW_RULE']=='no') else test=true 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/models/xforum/forum.rb', line 127 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
199 200 201 202 203 |
# File 'app/models/xforum/forum.rb', line 199 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 |