Class: StatusGroup

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

Overview

A StatusGroup is a sub-Group of a Corporation that memberships model the current status of members within the corporation.

At present time, the status of a user within a corporation is unique.

Class 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

.find_all_by_corporation(corporation) ⇒ Object



9
10
11
12
13
# File 'app/models/status_group.rb', line 9

def self.find_all_by_corporation(corporation)
  corporation.leaf_groups.select do |group|
    group.ancestor_events.count == 0
  end
end

.find_all_by_user(user, options = {}) ⇒ Object



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

def self.find_all_by_user(user, options = {})
  user_groups = options[:with_invalid] ? user.parent_groups : user.direct_groups
  user.corporations.collect do |corporation|
    StatusGroup.find_all_by_corporation(corporation)
  end.flatten & user_groups
end

.find_by_user_and_corporation(user, corporation) ⇒ Object



22
23
24
25
26
# File 'app/models/status_group.rb', line 22

def self.find_by_user_and_corporation(user, corporation)
  status_groups = (StatusGroup.find_all_by_corporation(corporation) & StatusGroup.find_all_by_user(user))
  raise "Slection algorithm not unique, yet. Please correct this. Found possible status groups: #{status_groups.map(&:name).join(', ')}." if status_groups.count > 1
  status_groups.last
end