Class: Group

Inherits:
KitIndexed show all
Defined in:
app/models/group.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from KitIndexed

do_indexing, indexed_columns, paginate

Class Method Details

.mailchimp_groups(system_id) ⇒ Object



43
44
45
# File 'app/models/group.rb', line 43

def self.mailchimp_groups(system_id)
  Group.sys(system_id).all.collect { |group| group.name } << "All"
end

Instance Method Details

#grant_permission_to_this_groupObject



47
48
49
50
51
52
53
# File 'app/models/group.rb', line 47

def grant_permission_to_this_group
  Category.all.each do |category|
    CategoryGroup.create(:group_id=>self.id, :category_id=>category.id, :can_read=>1, :can_write=>0)
  end

  Category.build_permission_cache(self.system_id)
end

#mailchimp_connectionObject



78
79
80
# File 'app/models/group.rb', line 78

def mailchimp_connection
  Gibbon.new(Preference.get_cached(self.system_id,'mailchimp_api_key'))
end

#mailchimp_createObject



13
14
15
16
17
18
19
20
# File 'app/models/group.rb', line 13

def mailchimp_create
  gibbon = mailchimp_connection
  begin
  gibbon.list_interest_group_add({:id=>Preference.get(self.system_id, 'mailchimp_all_user_list'), :group_name=>self.name, :grouping_id=>mailchimp_get_group_id}) 
  rescue Exception => e
    logger.info "Mailchimp_create in group.rb #{e.message}"
  end
end

#mailchimp_deleteObject



22
23
24
25
26
27
28
29
# File 'app/models/group.rb', line 22

def mailchimp_delete
    gibbon = mailchimp_connection
  begin
    gibbon.list_interest_group_del({:id=>Preference.get(self.system_id, 'mailchimp_all_user_list'), :group_name=>self.name, :grouping_id=>mailchimp_get_group_id}) rescue nil
  rescue Exception => e
    logger.info "Mailchimp_create in group.rb #{e.message}"
  end
end

#mailchimp_get_group_idObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/group.rb', line 64

def mailchimp_get_group_id
  groups = mailchimp_connection.list_interest_groupings({:id=>Preference.get_cached(self.system_id, 'mailchimp_all_user_list')}) 

  raise "no groups found" unless groups 
  group_id = nil
  groups.each do |group|
    if group["name"] == "KIT Groups"
      return group["id"]
    end
  end
  
  raise "no KIT Groups found" 
end

#mailchimp_updateObject



31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/group.rb', line 31

def mailchimp_update
  if self.name_changed?
    gibbon = mailchimp_connection
    begin
    gibbon.list_interest_group_del({:id=>Preference.get(self.system_id, 'mailchimp_all_user_list'), :group_name=>self.name_was, :grouping_id=>mailchimp_get_group_id})    
    gibbon.list_interest_group_add({:id=>Preference.get(self.system_id, 'mailchimp_all_user_list'), :group_name=>self.name, :grouping_id=>mailchimp_get_group_id})    
  rescue Exception => e
    logger.info "Mailchimp_create in group.rb #{e.message}"
  end
  end
end

#remove_permissions_for_this_groupObject



57
58
59
60
# File 'app/models/group.rb', line 57

def remove_permissions_for_this_group
  CategoryGroup.delete_all("group_id = #{self.id}")
  Category.build_permission_cache(self.system_id)
end