related_organizations_block.rb
1.43 KB
1
2
3
4
5
6
7
8
9
10
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class RelatedOrganizationsBlock < ProfileListBlock
settings_items :organization_type, :type => :string, :default => 'both'
attr_accessible :organization_type
def self.description
_("Related Organizations")
end
def display_type
@display_type ||= {:title => 'related', :action => 'children' }
end
def default_title
case organization_type
when 'enterprise'
n_("{#} #{display_type[:title]} enterprise", "{#} #{display_type[:title]} enterprises", profile_count)
when 'community'
n_("{#} #{display_type[:title]} community", "{#} #{display_type[:title]} communities", profile_count)
else
n_("{#} #{display_type[:title]} organization", "{#} #{display_type[:title]} organizations", profile_count)
end
end
def help
_("This block displays %s organizations of this organization") % display_type[:title]
end
def profiles
organizations = related_organizations
case organization_type
when 'enterprise'
organizations.enterprises
when 'community'
organizations.communities
else
organizations
end
end
def related_organizations
profile = self.owner
organizations = Organization.parentz(profile)
if organizations.blank?
@display_type = {:title => 'sub', :action => 'children'}
organizations = Organization.children(profile)
else
@display_type = {:title => 'parent', :action => 'parents' }
organizations
end
end
end