Class: Peoplefinder::Group

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/peoplefinder/group.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.departmentObject



33
34
35
# File 'app/models/peoplefinder/group.rb', line 33

def self.department
  roots.first
end

Instance Method Details

#all_peopleObject



53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/peoplefinder/group.rb', line 53

def all_people
  Peoplefinder::Person.find_by_sql(
  [
    'select distinct array_agg(role) as role_list, p.*
    from memberships m, people p
    where m.person_id = p.id AND group_id in (?)
    group by p.id;', subtree_ids
  ]).
  sort_by(&:name).
  each { |p| p.role_names = p.role_list.compact.join(', ') }
end

#deletable?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/peoplefinder/group.rb', line 45

def deletable?
  leaf_node? && memberships.reject(&:new_record?).empty?
end

#editable_parent?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/peoplefinder/group.rb', line 65

def editable_parent?
  new_record? || parent.present? || children.empty?
end

#leadershipObject



41
42
43
# File 'app/models/peoplefinder/group.rb', line 41

def leadership
  leaderships.first
end

#leaf_node?Boolean

Returns:

  • (Boolean)


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

def leaf_node?
  children.blank?
end

#name_and_sequenceObject



82
83
84
85
86
# File 'app/models/peoplefinder/group.rb', line 82

def name_and_sequence
  slug = name.to_param
  sequence = Peoplefinder::Group.where("slug like '#{slug}-%'").count + 2
  "#{slug}-#{sequence}"
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


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

def should_generate_new_friendly_id?
  name_changed?
end

#slug_candidatesObject



69
70
71
72
73
74
75
76
# File 'app/models/peoplefinder/group.rb', line 69

def slug_candidates
  candidates = [name]
  if parent.present?
    candidates <<  [parent.name, name]
    candidates <<  [parent.name, name_and_sequence]
  end
  candidates
end

#to_sObject



37
38
39
# File 'app/models/peoplefinder/group.rb', line 37

def to_s
  name
end