Class: Peoplefinder::Group
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Peoplefinder::Group
- Extended by:
- FriendlyId
- Defined in:
- app/models/peoplefinder/group.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_people ⇒ Object
- #deletable? ⇒ Boolean
- #editable_parent? ⇒ Boolean
- #leadership ⇒ Object
- #leaf_node? ⇒ Boolean
- #name_and_sequence ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #slug_candidates ⇒ Object
- #to_s ⇒ Object
Class Method Details
.department ⇒ Object
33 34 35 |
# File 'app/models/peoplefinder/group.rb', line 33 def self.department roots.first end |
Instance Method Details
#all_people ⇒ Object
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
45 46 47 |
# File 'app/models/peoplefinder/group.rb', line 45 def deletable? leaf_node? && memberships.reject(&:new_record?).empty? end |
#editable_parent? ⇒ Boolean
65 66 67 |
# File 'app/models/peoplefinder/group.rb', line 65 def editable_parent? new_record? || parent.present? || children.empty? end |
#leadership ⇒ Object
41 42 43 |
# File 'app/models/peoplefinder/group.rb', line 41 def leadership leaderships.first end |
#leaf_node? ⇒ Boolean
49 50 51 |
# File 'app/models/peoplefinder/group.rb', line 49 def leaf_node? children.blank? end |
#name_and_sequence ⇒ Object
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
78 79 80 |
# File 'app/models/peoplefinder/group.rb', line 78 def should_generate_new_friendly_id? name_changed? end |
#slug_candidates ⇒ Object
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_s ⇒ Object
37 38 39 |
# File 'app/models/peoplefinder/group.rb', line 37 def to_s name end |