aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2014-12-31 08:58:19 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2015-01-14 00:23:00 +0100
commit061c965330497235a8450103cd0865832b04b625 (patch)
tree03bc61d07f87dd9ebb1f4adcbbd3209a1e835621
parent8d7b012a535b18925b37d0d00d9c33e7183c36e9 (diff)
downloadecs2-061c965330497235a8450103cd0865832b04b625.tar.gz
ecs2-061c965330497235a8450103cd0865832b04b625.zip
Code rework.
Moved code from MembershipsController to Membership model.
-rw-r--r--app/controllers/memberships_controller.rb21
-rw-r--r--app/models/membership.rb27
2 files changed, 28 insertions, 20 deletions
diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb
index 5a5cf6d..6a7bd50 100644
--- a/app/controllers/memberships_controller.rb
+++ b/app/controllers/memberships_controller.rb
@@ -28,26 +28,7 @@ class MembershipsController < ApplicationController
end
def index
- memberships = []
- Membership.for_participant_id(@participant.id).each do |membership|
- memberships <<
- { :community => lambda { |memb|
- attribs = memb.community_with_reduced_attributes.attributes
- id = attribs["id"]; attribs.delete("id"); attribs["cid"] = id
- attribs
- }.call(membership),
- :participants => membership.community.participants.with_reduced_attributes_and_without_anonymous.map {|p|
- attribs = p.attributes
- attribs["mid"] = Membership.for_participant_id_and_community_id(p.id, membership.community.id).first.id
- attribs["org"] = {"name" => p.organization.name, "abbr" => p.organization.abrev}
- attribs["itsyou"] = p.id == @participant.id
- attribs["pid"] = p.id
- attribs.delete("id")
- attribs.delete("organization_id")
- attribs
- }
- }
- end
+ memberships = Membership.memberships(@participant)
if memberships.empty?
render :text => "", :content_type => "application/json", :layout => false
else
diff --git a/app/models/membership.rb b/app/models/membership.rb
index d26f8f0..7e7aebf 100644
--- a/app/models/membership.rb
+++ b/app/models/membership.rb
@@ -59,6 +59,33 @@ class Membership < ActiveRecord::Base
end
end
+ def self.memberships(participant)
+ memberships = []
+ Membership.for_participant_id(participant.id).each do |membership|
+ community= lambda { |memb|
+ attribs = memb.community_with_reduced_attributes.attributes
+ id = attribs["id"]; attribs.delete("id"); attribs["cid"] = id
+ attribs
+ }.call(membership)
+ logger.debug "**** Membership::memberships: community: #{community.inspect}"
+ participants= membership.community.participants.with_reduced_attributes_and_without_anonymous.map do |p|
+ attribs = p.attributes
+ attribs["mid"] = Membership.for_participant_id_and_community_id(p.id, membership.community.id).first.id
+ attribs["org"] = {"name" => p.organization.name, "abbr" => p.organization.abrev}
+ attribs["itsyou"] = p.id == participant.id
+ attribs["pid"] = p.id
+ attribs.delete("id")
+ attribs.delete("organization_id")
+ attribs
+ end
+ logger.debug "**** Membership::memberships: participants: #{participants.inspect}"
+ memberships <<
+ { :community => community,
+ :participants => participants
+ }
+ end
+ memberships
+ end
private