Class: Xforum::PeopleList

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/xforum/people_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_to_invitation(params, id, user_id) ⇒ Object



160
161
162
163
# File 'app/models/xforum/people_list.rb', line 160

def self.add_to_invitation(params, id, user_id)
  peoplelist = PeopleList.find_people_list(params, id)
  peoplelist.invite_these_guys(PeopleList.get_people_id_list(user_id,params[:invitees])) unless peoplelist.nil?
end

.add_to_list(params, users) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/xforum/people_list.rb', line 138

def self.add_to_list(params,users)
  if params[:name].nil?
    a_list=PeopleList.where(list: params[:list], owner_id: params[:owner]).first_or_create { |new|
      new.list=params[:list]
      new.owner_id=params[:owner]
    }
  else
    a_list=PeopleList.where(list: 'distribution list', name: params[:list]).first_or_create { |new|
      new.list = 'distribution list'
      new.name = params[:list]
    }
  end
  a_list.invite_these_guys(users)
end

.check_invitation(id, user_id, list_type) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/xforum/people_list.rb', line 102

def self.check_invitation(id,user_id,list_type)
  case list_type
    when 'topic'
      JSON.load(PeopleList.where(topic_id:id,list:'invitation').people).include(user_id.to_s)
    when 'category'
      JSON.load(PeopleList.where(category_id:id,list:'invitation').people).include(user_id.to_s)
    when 'forum'
      JSON.load(PeopleList.where(forum_id:id,list:'invitation').people).include(user_id.to_s)

  end
end

.check_people(params) ⇒ Object

owner_id,user_id,list)



153
154
155
156
157
158
# File 'app/models/xforum/people_list.rb', line 153

def self.check_people(params) # owner_id,user_id,list)
  which=PeopleList.get_which_owner(params)
  which.store(:list,params[:llist])
  people=PeopleList.where(which).pluck(:people)[0]
  (people.nil? || people.empty?) ? false : people.include?(params[:user_id].to_s)
end

.check_restrictions(alist, user_id, list_type) ⇒ Object



94
95
96
97
98
99
100
# File 'app/models/xforum/people_list.rb', line 94

def self.check_restrictions(alist,user_id, list_type)
  blist=alist.clone
  blist.each { |record|
    list.delete(record) if record[:restricted] && PeopleList.check_invitation(record[:id], user_id,list_type)
  }
  alist
end

.find_people_list(params, forum_id) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/xforum/people_list.rb', line 165

def self.find_people_list(params, forum_id)
  which=PeopleList.get_which_owner(params)
  which.store(:list,'invitation')
  list = PeopleList.find_by(which)
  if list.nil?
    parent=Forum.where(id: forum_id).pluck(:parent)[0]
    if parent == 0
      topic=Forum.where(id:forum_id).pluck(:topic_id)
      PeopleList.find_by(topic_id:topic,list:params[:list])
    else
      PeopleList.find_people_list(params, parent) unless parent.nil?
    end
  end
end

.get_forum_distribution_lists(params, user) ⇒ Object



113
114
115
116
117
# File 'app/models/xforum/people_list.rb', line 113

def self.get_forum_distribution_lists(params,user)
  user.forum_admin? ? alist=PeopleList.where(list: 'distribution list').pluck(:name, :id) : alist=[]
  alist.unshift([I18n.t('xForum.select_list'), 'select list', 0])
  {list_data: ForumAssist.named_array(alist, [:value, :item]), id:params[:list]}
end

.get_forum_emails(params, user) ⇒ Object



82
83
84
85
86
# File 'app/models/xforum/people_list.rb', line 82

def self.get_forum_emails(params, user)
  user.forum_admin? ? alist=Xforum.user_class.all.pluck(:email, :id) : alist= []
  alist.unshift([I18n.t('xForum.select_none'), 'select none', 0])
  {list_data: ForumAssist.named_array(alist, [:value, :item]), name: 'forum-user-email'}
end

.get_forum_users(params, user) ⇒ Object



88
89
90
91
92
# File 'app/models/xforum/people_list.rb', line 88

def self.get_forum_users(params, user)
  user.forum_admin? ? alist = Xforum.user_class.all.pluck(:forum_post_name, :id) : alist =[]
  alist.unshift([I18n.t('xForum.select_none'), 'select none', 0])
  {list_data: ForumAssist.named_array(alist, [:value, :item]), name: 'forum-user-tag'}
end

.get_people_id_list(user_id, list) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/xforum/people_list.rb', line 11

def self.get_people_id_list(user_id, list)
  people = []
  people.push(user_id)
  unless list.nil?
    list.gsub(',', ';')
    new_list=list.split(';')
    email_list=[]
    user_list=[]
    new_list.each { |entry|
      if entry.include?('@')
        email_list.push(entry)
      else
        user_list.push(entry)
      end
    }
    user_list.each { |entry|
      id=Xforum.user_class.where(forum_post_name: entry).pluck(:id)[0]
      people.push id unless id.nil?
    }
    email_list.each { |entry|
      id=Xforum.user_class.where(email: entry).pluck(:id)[0]
      people.push id unless id.nil?
    }
  end
  people
end

.get_people_list(params) ⇒ Object



53
54
55
56
57
58
59
# File 'app/models/xforum/people_list.rb', line 53

def self.get_people_list(params)
  which=PeopleList.get_which_owner(params)
  params.merge!(which)
  people_object=PeopleList.make_a_list(params)
  list=JSON.load(people_object.people)
  list.nil? ? [] : list
end

.get_which_owner(params) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/xforum/people_list.rb', line 70

def self.get_which_owner(params)
  if  !params[:topic].nil?
     {topic_id:params[:topic]}
  elsif !params[:forum].nil?
    {forum_id:params[:topic]}
  elsif  !params[:category].nil?
    {category_id:params[:topic]}
  else
    {}
  end
end

.is_a_moderator?(user_id) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
122
123
124
125
126
127
# File 'app/models/xforum/people_list.rb', line 119

def self.is_a_moderator?(user_id)
  the_lists=PeopleList.where(list: 'moderator').pluck(:people)
  moderators=[]
  the_lists.each { |a_list|
    moderators+= a_list
    moderators.uniq!
  }
  moderators.include?(user_id)
end

.make_a_list(params) ⇒ Object



61
62
63
64
65
66
67
68
# File 'app/models/xforum/people_list.rb', line 61

def self.make_a_list(params)
  PeopleList.first_or_create {|joe|
    joe.topic_id=params[:topic_id] unless  params[:topic_id].nil?
    joe.category_id=params[:topic_id] unless params[:category_id].nil?
    joe.forum_id =params[:topic_id] unless params[:forum_id].nil?
    joe.list = params[:list]
  }
end

.make_invitation(params, forum_id, user) ⇒ Object



129
130
131
132
133
134
135
136
# File 'app/models/xforum/people_list.rb', line 129

def self.make_invitation(params, forum_id, user)
  invitees=PeopleList.get_people_id_list(user.id, params[:invitees])
  peoplelist=PeopleList.where(list: 'invitation', owner_id: forum_id).first_or_create { |invitation|
    invitation.owner_id=forum_id
    invitation.list='invitaton'
  }
  peoplelist.invite_these_guys(invitees)
end

.manage_list(params, user_ids) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/xforum/people_list.rb', line 38

def self.manage_list(params, user_ids)
  case params[:forum_action]
    when 'create distribution'
      PeopleList.find_or_create_by(name:params[:new_list_name], list:'distribution list'){|list|
          list.people=params[:people].to_json
      }
    when 'add to distribution'
      alist= user_ids
      blist=  JSON.load(PeopleList.where(id: params[:distribution_list]).pluck(:people)[0])
      clist=(alist|blist)-(alist&blist)
      PeopleList.where(id: params[:distribution_list]).update_all(people: clist.to_json)
    else
  end
end

Instance Method Details

#invite_these_guys(invitees) ⇒ Object



180
181
182
183
184
185
# File 'app/models/xforum/people_list.rb', line 180

def invite_these_guys(invitees)
  invitees += JSON.load(self.people) unless  JSON.load(self.people).nil?
  invitees.uniq!
  self.people = invitees.to_json
  self.save
end