Class: Corporation

Inherits:
Group show all
Defined in:
app/models/corporation.rb

Overview

A Corporation is one of the central organizational units in your_platform. Being a Group, the Corporation adds certain features:

  • The corporations of the current_user are listed as primary entry points of navigation in the ui.

  • The memebrships in corporations and their subgroups are listed in the users’ “corporate vitae”.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Group

#cached_members_postal_addresses_created_at, #child_workflows, #corporation, #corporation?, #corporation_id, #deceased, #delete_cache, #descendant_groups_by_name, #descendant_workflows, #events, #extensive_name, #find_deceased_members_parent_group, #group_of_groups=, #group_of_groups?, #leaf_groups, #members_postal_addresses, #members_to_pdf, #name, #name_with_corporation, #title, #to_param, #upcoming_events

Methods inherited from ActiveRecord::Base

#readonly?

Class Method Details

.corporations_parentObject

This returns the group that has all Corporations as children. The corporations_parent itself is a Group, no Corporation.



15
16
17
# File 'app/models/corporation.rb', line 15

def self.corporations_parent
  self.find_corporations_parent_group || self.create_corporations_parent_group
end

.create_corporations_parent_groupObject



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

def self.create_corporations_parent_group
  new_group = Group.create name: 'all_corporations'
  new_group.add_flag :corporations_parent
  new_group.add_flag :group_of_groups
  Group.everyone << new_group
  return new_group
end

.find_corporations_parent_groupObject



19
20
21
# File 'app/models/corporation.rb', line 19

def self.find_corporations_parent_group
  Group.find_by_flag :corporations_parent
end

Instance Method Details

#deceased_membersObject

This method lists all deceased members of the corporation.



73
74
75
# File 'app/models/corporation.rb', line 73

def deceased_members
  child_groups.find_by_flag(:deceased_parent).try(:members) || []
end

#deceased_members_membershipsObject



76
77
78
# File 'app/models/corporation.rb', line 76

def deceased_members_memberships
  child_groups.find_by_flag(:deceased_parent).try(:memberships) || []
end

#former_membersObject

This method lists all former members of the corporation. This is not determined by the user group membership validity range but by the membership in the former_members sub group, since all members of subgroups are considered also members of the group.



64
65
66
# File 'app/models/corporation.rb', line 64

def former_members
  child_groups.find_by_flag(:former_members_parent).try(:members) || []
end

#former_members_membershipsObject



67
68
69
# File 'app/models/corporation.rb', line 67

def former_members_memberships
  child_groups.find_by_flag(:former_members_parent).try(:memberships) || []
end

#is_first_corporation_this_user_has_joined?(user) ⇒ Boolean

This method returns true if this (self) is the one corporation the given user has joined first, i.e. before he joined any other corporation.

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'app/models/corporation.rb', line 35

def is_first_corporation_this_user_has_joined?( user )
  return false if not user.groups.include? self
  return true if user.corporations.count == 1
  this_membership_valid_from = UserGroupMembership.find_by_user_and_group( user, self ).valid_from
  user.memberships.each do |membership|
    return false if membership.valid_from.to_i < this_membership_valid_from.to_i
  end
  return true
end

#status_group(group_name) ⇒ Object

This method returns the status group with the given name.



55
56
57
# File 'app/models/corporation.rb', line 55

def status_group(group_name)
  status_groups.select { |g| g.name == group_name }.first
end

#status_groupsObject

This method returns all status groups of the corporation. In this general context, each leaf group of the corporation is a status group. But this is likely to be overridden by the main application.



49
50
51
# File 'app/models/corporation.rb', line 49

def status_groups
  cached { StatusGroup.find_all_by_corporation(self) }
end