xforum 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +139 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/images/xforum/addphoto.jpg +0 -0
  6. data/app/assets/images/xforum/bg-input-focus.png +0 -0
  7. data/app/assets/images/xforum/internet.png +0 -0
  8. data/app/assets/images/xforum/silver_selector.png +0 -0
  9. data/app/assets/javascripts/xforum/application.js +25 -0
  10. data/app/assets/javascripts/xforum/forum_admin.js.coffee +477 -0
  11. data/app/assets/javascripts/xforum/forum_basic.js.coffee +321 -0
  12. data/app/assets/javascripts/xforum/forum_translator.js.coffee +116 -0
  13. data/app/assets/javascripts/xforum/forum_user.js.coffee +403 -0
  14. data/app/assets/javascripts/xforum/global_java.js +141 -0
  15. data/app/assets/javascripts/xforum/help.js.coffee +10 -0
  16. data/app/assets/stylesheets/xforum/application.css.scss +15 -0
  17. data/app/assets/stylesheets/xforum/custom.css.scss +295 -0
  18. data/app/controllers/xforum/application_controller.rb +25 -0
  19. data/app/controllers/xforum/forums_controller.rb +123 -0
  20. data/app/helpers/xforum/application_helper.rb +4 -0
  21. data/app/mailers/xforum/user_mailer.rb +15 -0
  22. data/app/models/xforum/category.rb +76 -0
  23. data/app/models/xforum/forum.rb +217 -0
  24. data/app/models/xforum/hyperlink.rb +42 -0
  25. data/app/models/xforum/language.rb +104 -0
  26. data/app/models/xforum/people_list.rb +189 -0
  27. data/app/models/xforum/photo.rb +60 -0
  28. data/app/models/xforum/topic.rb +140 -0
  29. data/app/models/xforum/translation.rb +92 -0
  30. data/app/views/layouts/xforum/application.html.erb +14 -0
  31. data/app/views/user_mailer/xforum/note_to_forum_users.html.erb +32 -0
  32. data/app/views/xforum/forums/_dummy.html.erb +0 -0
  33. data/app/views/xforum/forums/_forum.html.erb +18 -0
  34. data/app/views/xforum/forums/_forum_admin.html.erb +139 -0
  35. data/app/views/xforum/forums/_forum_comments.html.erb +45 -0
  36. data/app/views/xforum/forums/_forum_entry.html.erb +44 -0
  37. data/app/views/xforum/forums/_forum_video.html.erb +7 -0
  38. data/app/views/xforum/forums/newphoto.js.erb +1 -0
  39. data/app/views/xforum/forums/the_page.html.erb +3 -0
  40. data/config/intiializers/xforum.rb +2 -0
  41. data/config/locales/forum.de.yml +93 -0
  42. data/config/locales/forum.en.yml +96 -0
  43. data/config/locales/forum.es.yml +94 -0
  44. data/config/locales/forum.fr.yml +94 -0
  45. data/config/routes.rb +10 -0
  46. data/db/migrate/20140600_add_forum_to_users.rb +20 -0
  47. data/db/migrate/20140601_create_forum_forums.rb +147 -0
  48. data/db/migrate/20140602_add_restricted_to_category.rb +6 -0
  49. data/db/migrate/20140602_change_suggestion_default.rb +7 -0
  50. data/lib/tasks/xforum_tasks.rake +65 -0
  51. data/lib/xforum.rb +95 -0
  52. data/lib/xforum/engine.rb +6 -0
  53. data/lib/xforum/set.yml +209 -0
  54. data/lib/xforum/user_include.rb +13 -0
  55. data/lib/xforum/version.rb +3 -0
  56. data/test/dummy/README.rdoc +28 -0
  57. data/test/dummy/Rakefile +6 -0
  58. data/test/dummy/app/assets/javascripts/application.js +13 -0
  59. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  60. data/test/dummy/app/controllers/application_controller.rb +5 -0
  61. data/test/dummy/app/helpers/application_helper.rb +2 -0
  62. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/test/dummy/bin/bundle +3 -0
  64. data/test/dummy/bin/rails +4 -0
  65. data/test/dummy/bin/rake +4 -0
  66. data/test/dummy/config.ru +4 -0
  67. data/test/dummy/config/application.rb +23 -0
  68. data/test/dummy/config/boot.rb +5 -0
  69. data/test/dummy/config/database.yml +25 -0
  70. data/test/dummy/config/environment.rb +5 -0
  71. data/test/dummy/config/environments/development.rb +37 -0
  72. data/test/dummy/config/environments/production.rb +83 -0
  73. data/test/dummy/config/environments/test.rb +39 -0
  74. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  76. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  77. data/test/dummy/config/initializers/inflections.rb +16 -0
  78. data/test/dummy/config/initializers/mime_types.rb +4 -0
  79. data/test/dummy/config/initializers/session_store.rb +3 -0
  80. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  81. data/test/dummy/config/locales/en.yml +23 -0
  82. data/test/dummy/config/routes.rb +4 -0
  83. data/test/dummy/config/secrets.yml +22 -0
  84. data/test/dummy/db/development.sqlite3 +0 -0
  85. data/test/dummy/log/development.log +0 -0
  86. data/test/dummy/public/404.html +67 -0
  87. data/test/dummy/public/422.html +67 -0
  88. data/test/dummy/public/500.html +66 -0
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/integration/navigation_test.rb +10 -0
  91. data/test/test_helper.rb +15 -0
  92. data/test/xforum_test.rb +7 -0
  93. metadata +327 -0
@@ -0,0 +1,42 @@
1
+
2
+ module Xforum
3
+ class Hyperlink < ActiveRecord::Base
4
+ require 'json'
5
+
6
+ belongs_to :forum
7
+ has_many :translations, dependent: :destroy
8
+
9
+ def self.add_one(params)
10
+ the_link=Hyperlink.where(link_address:params[:link_address],forum_id:params[:forum_id]).first_or_create{ |link|
11
+ link.link_address= params[:link_address]
12
+ link.link_text=params[:link_text]
13
+ link.forum_id= params[:forum_id]
14
+ }
15
+ Hyperlink.where(link_address:params[:link_address],forum_id:params[:forum_id]).update_all(link_text:params[:link_text])
16
+ unless params[:link_translation].nil? || params[:link_translation] == ''
17
+ Translation.where(hyperlink_id:the_link.id,language_id:Language.get_me(params)).first_or_create{|link|
18
+ link.hyperlink_id=the_link.id
19
+ link.language_id=Language.get_me(params)
20
+ link.content= params[:link_translation]
21
+ }
22
+ Translation.where(hyperlink_id:the_link.id,language_id:Language.get_me(params)).update_all(content:params[:link_translation])
23
+ end
24
+ {todo:'nothing'}
25
+ end
26
+
27
+ def self.add_set(params,forum_id)
28
+ (0...params[:link_ref].to_i).each { |i|
29
+ data=params['link-'+i.to_s]
30
+ data[:forum_id]=forum_id
31
+ Hyperlink.add_one(data)
32
+ }
33
+ end
34
+
35
+ def self.get_links(forum_id)
36
+ alist=Hyperlink.where(forum_id:forum_id).pluck(:link_address,:link_text,:id)
37
+ unless alist.empty?
38
+ ForumAssist.named_array(alist,[:link_address,:link_text,:id])
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,104 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: languages
4
+ #
5
+ # id :integer not null, primary key
6
+ # user_id :integer
7
+ # code :string(5)
8
+ # name :string(50)
9
+ # local_name :string(50)
10
+ # region :string(50)
11
+ # suggestion :boolean
12
+ # state :string(50) default("suggesiton")
13
+ # active :boolean default(FALSE)
14
+ # created_at :datetime
15
+ # updated_at :datetime
16
+ #
17
+ module Xforum
18
+ class Language < ActiveRecord::Base
19
+ require 'json'
20
+
21
+ has_many :translations, dependent: :destroy
22
+
23
+ def self.toggle_language(params,user) #this has to be an all new language
24
+ state= Language.where(name:params[:language]).pluck(:active)[0]
25
+ Language.where(name:params[:language]).update_all(active:!state) if user.forum_admin?
26
+ {action:'nothing to do'}
27
+ end
28
+
29
+ def self.add_language(params,user)
30
+ if user.forum_admin?
31
+ Language.create(code:params[:code],name:params[:name],local_name:params[:local])
32
+ end
33
+ end
34
+
35
+ def self.languages(params)
36
+ if ENV['XFORUM_LANGUAGES'].nil?
37
+ alist=[]
38
+ elsif Language.first.nil?
39
+ Language.init_language_set
40
+ Language.load_env_set
41
+ else
42
+ Language.load_env_set
43
+ params[:active] == 'true' ?
44
+ alist=Language.where(active:true).order(:code).pluck(:id,:name,:code,:local_name,:active) :
45
+ alist=Language.where(active:false).order(:code).pluck(:id,:name,:code,:local_name,:active)
46
+ unless alist.empty?
47
+ alist=ForumAssist.named_array(alist,[:id,:item,:value,:local_name,:state])
48
+ alist=Translation.translate_list(alist,'','language')
49
+ end
50
+ alist.unshift({value: I18n.t('xForum.select_language'),item: I18n.t('xForum.select_language') ,state:'open',id:0}) unless params[:short]
51
+ {list_data:alist,id:params[:list]}
52
+ end
53
+ end
54
+
55
+ def self.load_env_set
56
+ set=ENV['XFORUM_LANGUAGES'].split(';')
57
+ set.each {|code|
58
+ Language.where(code:code).update_all(active:true)
59
+ }
60
+
61
+ end
62
+ def self.get_suggestions(params,user)
63
+ if user.forum_admin?
64
+ data= Language.where(suggestion:true).pluck(:name, :user_id, :id)
65
+ data=ForumAssist.named_array(data, [:suggestion, :user,:id ]) unless data.empty?
66
+ data=ForumAssist.add_user_name(data.clone) unless data.empty?
67
+ {data:data,list:'forum-language-prososals-list'}
68
+ else
69
+ {reply:'nothing doing'}
70
+ end
71
+ end
72
+
73
+ def self.suggestion(params,user) #add new category or topic
74
+ Language.create(suggestion:true,content:params[:suggestion],user_id:user.id,hold:true)
75
+ {response:'nothing to do'}
76
+ end
77
+
78
+ def self.suggestion_close(params,user)
79
+ params[:result]=='Accept' ?
80
+ (Language.where(id: params[:id]).update_all(suggestion: false) if user.forum_admin?) :
81
+ Language.where(id: params[:id]).update_all(state: 'closed') if user.forum_admin?
82
+ end
83
+ def self.get_locale(params)
84
+ params[:language].nil? ? Language.where(code:I18n.locale.to_s) : Language.get_me(params)
85
+ end
86
+ def self.get_me(params)
87
+ return if params[:langeuage].nil?
88
+ params[:language] = params[:language][0] if params[:language].is_a?(Array)
89
+ code=params[:language].split('-')[0].strip
90
+ Language.where(code:code).pluck(:id)[0]
91
+ end
92
+
93
+ def self.init_language_set
94
+ language_table = %w(af.Afrikaans.Afrikaans ar.Arabic.العربية be.Belarusian.беларускі bg.Bulgarian.български ca.Catalan.Català cs.Czech.čeština da.Danish.dansk de.German.dansk el.Greek.ελληνικά en.English.English es.Spanish.español et.Estonian.eesti eu.Basque.Euskal fa.Farsi.فارسی fi.Finnish.suomalainen fo.Faroese.føroyskt fr.French.français ga.Irish.Gaeilge gd.Gaelic.gaélico he.Hebrew.עברית hi.Hindi.हिंदी hr.Croatian.hrvatski hu.Hungarian.magyar id.Indonesian.Indonesia is.Icelandic.Icelandic it.Italian.italiano ja.Japanese.日本の ji.Yiddish.ייִדיש ko.Korean.한국의 lt.Lithuanian.Lietuvos lv.Latvian.Latvijas mk.Macedonian.македонски ms.Malaysian.Malaysia mt.Maltese.Malti nl.Dutch.Nederlands no.Norwegian.norsk pl.Polish.polski pt.Portuguese.português ro.Romanian.român ru.Russian.русский sk.Slovak.slovenský sl.Slovenian.slovenščina sq.Albanian.shqiptar sr.Serbian.српски sv.Swedish.Svenska th.Thai.ภาษาไทย tr.Turkish.Türk uk.Ukrainian.Український ur.Urdu.اردو vi.Vietnamese.Việt zh.Chinese.中國的 zu.Zulu.Zulu)
95
+ language_table.each {|entry|
96
+ language=ForumAssist.named_array(entry.split('.'),[:code,:language,:local])[0]
97
+ Language.find_or_create_by(code:language[:code]) {|entry|
98
+ entry.name=language[:language]
99
+ entry.local_name=language[:local]
100
+ entry.active=false
101
+ } }
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,189 @@
1
+
2
+ module Xforum
3
+ class PeopleList < ActiveRecord::Base
4
+ require 'json'
5
+ belongs_to :topic
6
+ belongs_to :category
7
+ belongs_to :forum
8
+
9
+ serialize :people
10
+
11
+ def self.get_people_id_list(user_id, list)
12
+ people = []
13
+ people.push(user_id)
14
+ unless list.nil?
15
+ list.gsub(',', ';')
16
+ new_list=list.split(';')
17
+ email_list=[]
18
+ user_list=[]
19
+ new_list.each { |entry|
20
+ if entry.include?('@')
21
+ email_list.push(entry)
22
+ else
23
+ user_list.push(entry)
24
+ end
25
+ }
26
+ user_list.each { |entry|
27
+ id=Xforum.user_class.where(forum_post_name: entry).pluck(:id)[0]
28
+ people.push id unless id.nil?
29
+ }
30
+ email_list.each { |entry|
31
+ id=Xforum.user_class.where(email: entry).pluck(:id)[0]
32
+ people.push id unless id.nil?
33
+ }
34
+ end
35
+ people
36
+ end
37
+
38
+ def self.manage_list(params, user_ids)
39
+ case params[:forum_action]
40
+ when 'create distribution'
41
+ PeopleList.find_or_create_by(name:params[:new_list_name], list:'distribution list'){|list|
42
+ list.people=params[:people].to_json
43
+ }
44
+ when 'add to distribution'
45
+ alist=user_ids+JSON.load(PeopleList.where(id: params[:distribution_list]).pluck(:people)[0])
46
+ alist.uniq!
47
+ PeopleList.where(id: params[:distribution_list]).update_all(people: alist.to_json)
48
+ when 'remove from distro'
49
+ alist=JSON.load(PeopleList.where(id: params[:distribution_list]).pluck(:people)[0])-user_ids
50
+ PeopleList.where(id: params[:distribution_list]).update_all(people: alist.to_json)
51
+ else
52
+ end
53
+ end
54
+
55
+ def self.get_people_list(params)
56
+ which=PeopleList.get_which_owner(params)
57
+ params.merge!(which)
58
+ people_object=PeopleList.make_a_list(params)
59
+ list=JSON.load(people_object.people)
60
+ list.nil? ? [] : list
61
+ end
62
+
63
+ def self.make_a_list(params)
64
+ PeopleList.first_or_create {|joe|
65
+ joe.topic_id=params[:topic_id] unless params[:topic_id].nil?
66
+ joe.category_id=params[:topic_id] unless params[:category_id].nil?
67
+ joe.forum_id =params[:topic_id] unless params[:forum_id].nil?
68
+ joe.list = params[:list]
69
+ }
70
+ end
71
+
72
+ def self.get_which_owner(params)
73
+ if !params[:topic].nil?
74
+ {topic_id:params[:topic]}
75
+ elsif !params[:forum].nil?
76
+ {forum_id:params[:topic]}
77
+ elsif !params[:category].nil?
78
+ {category_id:params[:topic]}
79
+ else
80
+ {}
81
+ end
82
+ end
83
+
84
+ def self.get_forum_emails(params, user)
85
+ user.forum_admin? ? alist=Xforum.user_class.all.pluck(:email, :id) : alist= []
86
+ alist.unshift([I18n.t('xForum.select_none'), 'select none', 0])
87
+ {list_data: ForumAssist.named_array(alist, [:value, :item]), name: 'forum-user-email'}
88
+ end
89
+
90
+ def self.get_forum_users(params, user)
91
+ user.forum_admin? ? alist = Xforum.user_class.all.pluck(:forum_post_name, :id) : alist =[]
92
+ alist.unshift([I18n.t('xForum.select_none'), 'select none', 0])
93
+ {list_data: ForumAssist.named_array(alist, [:value, :item]), name: 'forum-user-tag'}
94
+ end
95
+
96
+ def self.check_restrictions(alist,user_id, list_type)
97
+ blist=alist.clone
98
+ blist.each { |record|
99
+ list.delete(record) if record[:restricted] && PeopleList.check_invitation(record[:id], user_id,list_type)
100
+ }
101
+ alist
102
+ end
103
+
104
+ def self.check_invitation(id,user_id,list_type)
105
+ case list_type
106
+ when 'topic'
107
+ JSON.load(PeopleList.where(topic_id:id,list:'invitation').people).include(user_id.to_s)
108
+ when 'category'
109
+ JSON.load(PeopleList.where(category_id:id,list:'invitation').people).include(user_id.to_s)
110
+ when 'forum'
111
+ JSON.load(PeopleList.where(forum_id:id,list:'invitation').people).include(user_id.to_s)
112
+
113
+ end
114
+ end
115
+ def self.get_forum_distribution_lists(params,user)
116
+ user.forum_admin? ? alist=PeopleList.where(list: 'distribution list').pluck(:name, :id) : alist=[]
117
+ alist.unshift([I18n.t('xForum.select_list'), 'select list', 0])
118
+ {list_data: ForumAssist.named_array(alist, [:value, :item]), id:params[:list]}
119
+ end
120
+
121
+ def self.is_a_moderator?(user_id)
122
+ the_lists=PeopleList.where(list: 'moderator').pluck(:people)
123
+ moderators=[]
124
+ the_lists.each { |a_list|
125
+ moderators+= a_list
126
+ moderators.uniq!
127
+ }
128
+ moderators.include?(user_id)
129
+ end
130
+
131
+ def self.make_invitation(params, forum_id, user)
132
+ invitees=PeopleList.get_people_id_list(user.id, params[:invitees])
133
+ peoplelist=PeopleList.where(list: 'invitation', owner_id: forum_id).first_or_create { |invitation|
134
+ invitation.owner_id=forum_id
135
+ invitation.list='invitaton'
136
+ }
137
+ peoplelist.invite_these_guys(invitees)
138
+ end
139
+
140
+ def self.add_to_list(params,users)
141
+ if params[:name].nil?
142
+ a_list=PeopleList.where(list: params[:list], owner_id: params[:owner]).first_or_create { |new|
143
+ new.list=params[:list]
144
+ new.owner_id=params[:owner]
145
+ }
146
+ else
147
+ a_list=PeopleList.where(list: 'distribution list', name: params[:list]).first_or_create { |new|
148
+ new.list = 'distribution list'
149
+ new.name = params[:list]
150
+ }
151
+ end
152
+ a_list.invite_these_guys(users)
153
+ end
154
+
155
+ def self.check_people(params) # owner_id,user_id,list)
156
+ which=PeopleList.get_which_owner(params)
157
+ which.store(:list,params[:llist])
158
+ people=PeopleList.where(which).pluck(:people)[0]
159
+ (people.nil? || people.empty?) ? false : people.include?(params[:user_id].to_s)
160
+ end
161
+
162
+ def self.add_to_invitation(params, id, user_id)
163
+ peoplelist = PeopleList.find_people_list(params, id)
164
+ peoplelist.invite_these_guys(PeopleList.get_people_id_list(user_id,params[:invitees])) unless peoplelist.nil?
165
+ end
166
+
167
+ def self.find_people_list(params, forum_id)
168
+ which=PeopleList.get_which_owner(params)
169
+ which.store(:list,'invitation')
170
+ list = PeopleList.find_by(which)
171
+ if list.nil?
172
+ parent=Forum.where(id: forum_id).pluck(:parent)[0]
173
+ if parent == 0
174
+ topic=Forum.where(id:forum_id).pluck(:topic_id)
175
+ PeopleList.find_by(topic_id:topic,list:params[:list])
176
+ else
177
+ PeopleList.find_people_list(params, parent) unless parent.nil?
178
+ end
179
+ end
180
+ end
181
+
182
+ def invite_these_guys(invitees)
183
+ invitees += JSON.load(self.people) unless JSON.load(self.people).nil?
184
+ invitees.uniq!
185
+ self.people = invitees.to_json
186
+ self.save
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,60 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: photos
4
+ #
5
+ # id :integer not null, primary key
6
+ # forum_id :integer
7
+ # user_id :integer
8
+ # name :string(50)
9
+ # resized :boolean default(FALSE)
10
+ # key :string(255)
11
+ # created_at :datetime
12
+ # updated_at :datetime
13
+ #
14
+ module Xforum
15
+ class Photo < ActiveRecord::Base
16
+ require 'json'
17
+
18
+ belongs_to :forum
19
+
20
+ def self.get_photos(forum_id)
21
+ photos=Photo.where(forum_id:forum_id).pluck(:key)
22
+ urls=[]
23
+ photos.each {|photo|
24
+ urls.push(ForumAssist.get_url(photo) )
25
+ }
26
+ urls
27
+ end
28
+
29
+ def self.get_photo(params)
30
+ params[:id].nil? || params[:id] == '' ? which = {tag:params[:tag]} : which = {id:params[:id]}
31
+ data=ForumAssist.named_array(Forum.where(which).pluck(:id,:parent),[:id,:parent])[0]
32
+ urls=Photo.get_photos(data[:id])
33
+ {tag:params[:tag],edit:params[:edit],urls:urls,id:data[:id],parent:data[:parent],count:params[:count].to_i+1}
34
+ end
35
+
36
+ def self.upload(params,user_id)
37
+ temp=JSON.load(params[:photo][:data])
38
+ pforward=Hash[temp.map{|k,v| [k.to_sym,v]}] #make the true/false strings again
39
+ pforward[:needs_photo] ? pforward[:needs_photo] ='true' : pforward[:needs_photo] ='false'
40
+ pforward[:already_has_photo] ? pforward[:already_has_photo] ='true' : pforward[:already_has_photo] ='false'
41
+ pforward[:edit] ? pforward[:edit] ='true' : pforward[:edit] ='false'
42
+ pforward[:translating] ? pforward[:translating] ='true' : pforward[:translating] ='false'
43
+ comment_info=Forum.add_comment(pforward,user_id)
44
+ k=params[:photo][:file]
45
+ Spawnling.new {
46
+ (0...k.size).each {|i|
47
+ name=k[i].original_filename.downcase
48
+ ext=name.split('.').last
49
+ if %w(jpg gif png).include?(ext)
50
+ folder=ENV['XFORUM_PHOTOS'] # todo make this programable
51
+ save_name=File.join(folder,name)
52
+ ForumAssist.save_image(k[i].tempfile.path, save_name)
53
+ Photo.create(user_id:user_id,forum_id:comment_info[:id],name:name,key:save_name)
54
+ end
55
+ }
56
+ } unless k.nil?
57
+ Rails.logger.debug 'saved job, now going back'
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,140 @@
1
+
2
+ module Xforum
3
+ class Topic < ActiveRecord::Base
4
+ require 'json'
5
+ belongs_to :category
6
+ has_many :forums, dependent: :destroy
7
+ has_many :people_lists, dependent: :destroy
8
+ serialize :votes
9
+
10
+ def self.topics(params,user)
11
+ if Topic.first.nil?
12
+ Topic.create(name:'select topic')
13
+ Topic.create(name:'request new topic')
14
+ end
15
+ unless params[:category] == 'select category'
16
+ category_id=Category.where(name:params[:category]).pluck(:id)[0]
17
+ params[:hold_test]=='true' ?
18
+ topics=ForumAssist.named_array(Topic.where(category_id:category_id,closed:false,suggestion:false).pluck(:id,:name,:state,:restricted,:closed), [:id,:item,:state,:restricted,:closed]) :
19
+ topics=ForumAssist.named_array(Topic.where(category_id:category_id).pluck(:id,:name,:state,:restricted,:closed), [:id,:item,:state,:restricted,:closed])
20
+ topics=[] if topics[0][:id].nil?
21
+ topics=PeopleList.check_restrictions(topics,user,'topic') unless user.forum_admin?
22
+ a=ForumAssist.named_array(Topic.where(name:'select topic').pluck(:id,:name,:state,:restricted,:closed), [:id,:item,:state,:restricted,:closed])[0]
23
+ b=ForumAssist.named_array(Topic.where(name:'request new topic').pluck(:id,:name,:state,:restricted,:closed), [:id,:item,:state,:restricted,:closed])[0]
24
+ topics.unshift(a)
25
+ topics.push(b)
26
+ {list_data:Translation.translate_list(topics,params[:language],'topic'),id:params[:list]}
27
+ end
28
+ end
29
+
30
+ def self.voting_booth?(params)
31
+ topic=Topic.find_by(name:params[:topic])
32
+ topic.vote=!topic.vote
33
+ topic.save
34
+ {vote:topic.vote,votes:'0'}
35
+ end
36
+
37
+ def self.add_topic_monitor(params,user_ids)
38
+ topic=Topic.where(name:params[:topic]).pluck(:id)[0]
39
+ PeopleList.add_to_list({list:'monitor',owner:topic},user_ids)
40
+ end
41
+
42
+ def self.restrict_me(params,user)
43
+ if user.forum_admin?
44
+ topic=Topic.find_by(name:params[:topic])
45
+ topic.restricted= !topic.restricted
46
+ invitation=PeopleList.find_or_create_by(topic_id:topic.id,list:'invitation')
47
+ invitation.people= PeopleList.find_by(name:params[:user_list],list:'distribution').people
48
+ end
49
+ end
50
+
51
+ def self.get_suggestions(params,user)
52
+ if user.forum_admin?
53
+ data=Topic.where(suggestion:true).pluck(:name, :user_id, :category_id,:id)
54
+ data=ForumAssist.named_array(data, [:suggestion, :user, :category, :id]) unless data.empty?
55
+ data=ForumAssist.add_user_name(data.clone) unless data.empty?
56
+ {data:data,list:'forum-topic-prososals-list'}
57
+ else
58
+ {response:'nothing doing'}
59
+ end
60
+ end
61
+
62
+ def self.suggestion(params,user) #add new category or topic
63
+ Topic.create(suggestion:true,name:params[:suggestion],user_id:user.id,category_id:Category.get_category_id(params))
64
+ {response:'nothing to do'}
65
+ end
66
+
67
+ def self.suggestion_close(params,user)
68
+ params[:result]=='Accept' ?
69
+ (Topic.where(id: params[:id]).update_all(suggestion: false) if user.forum_admin?) :
70
+ Topic.where(id: params[:id]).update_all(state: 'closed') if user.forum_admin? if user.forum_admin?
71
+ {response:'nothing to do'}
72
+ end
73
+
74
+ def self.count_votes(votes)
75
+ count=votes.length
76
+ count2=votes.delete_if{|element| element=='-1'
77
+ }.length
78
+ 2*count2-count
79
+ end
80
+
81
+ def self.cast_vote(topic,user,vote)
82
+ topic_record=Topic.find_by(name:topic)
83
+ voters=PeopleList.get_people_list({topic:topic_record.id,list:'voters'})
84
+ votes=JSON.load(topic_record.votes)
85
+ if voters.empty?
86
+ index=nil
87
+ votes=[]
88
+ else
89
+ index=voters.index(user.id)
90
+ end
91
+ if vote == '1' || vote == '-1'
92
+ if index.nil?
93
+ voters.push(user.id)
94
+ votes.push(vote)
95
+ else
96
+ votes[index]=vote
97
+ end
98
+ end
99
+ PeopleList.where(topic_id:topic_record.id,list:'voters').update_all(people:voters.to_json)
100
+ topic_record.votes=votes.to_json
101
+ topic_record.save
102
+ votes.empty? ? 0 : Topic.count_votes(votes)
103
+ end
104
+
105
+ def self.subscribe(topic,user) #if they're in the list unsubscribe else subscribe
106
+ id=Topic.where(name:topic).pluck(:id)[0]
107
+ subscribers=JSON.load(PeopleList.where(id:id,list:'subscribers').pluck(:people)[0])
108
+ subscribers=[] if subscribers.nil?
109
+ index= subscribers.index(user_id.to_s) unless subscribers.empty?
110
+ index.nil? ? subscribers.push(user.id.to_s) : subscribers.delete_at(index)
111
+ PeopleList.where(id:id,list:'subscribers').update_all(people:subscribers.to_json)[0]
112
+ end
113
+
114
+ def self.add_topic(params,user)
115
+ if user.forum_admin?
116
+ params[:user_id]=user_id if params[:user_id] == 'me'
117
+ category=Category.where(name:params[:category]).pluck(:id)[0]
118
+ id=Topic.create(name:params[:topic],user_id:params[:user_id],category_id:category).id
119
+ Forum.add_comment({topic:params[:topic],comment:params[:topic],parent:0},user)
120
+ else
121
+ id='not happening'
122
+ end
123
+ {id:id}
124
+ end
125
+
126
+ def self.edit_topic(params,user)
127
+ Topic.where(id: params[:id]).update_all(name:params[:newline]) if user.forum_admin?
128
+ end
129
+
130
+ def self.remove_topic(params,user)
131
+ case(params[:state_action])
132
+ when 'del' then Forum.where(id:params[:id]).update_all(closed:true)
133
+ when 'open' then Forum.where(id:params[:id]).update_all(closed:false)
134
+ else
135
+ # type code here
136
+ end if user.forum_admin?
137
+ {action:'nothing to do'}
138
+ end
139
+ end
140
+ end