Class: Program
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Program
- Includes:
- AffiliatableChild, AlgoliaSearch, Avatarable, Bannerable, Boardable, Feedable, Linkable, Mediumable, Membership, NotificationsHelpers, RecsysHelpers, RelationHelpers, Utils
- Defined in:
- app/models/program.rb
Overview
Umbrella object that holds this heirarchy: challenges -> projects -> needs Users can join the program (initiative) Can have a start and end date (as yet unused)
Instance Method Summary collapse
- #add_user_from_challenges ⇒ Object
- #all_owners_admins_members ⇒ Object
-
#frontend_link ⇒ Object
NOTE: the frontend has chosen "program" singular vs "programs" plural.
- #needs_count ⇒ Object
- #projects_count ⇒ Object
- #user_is_member?(user) ⇒ Boolean
Methods included from Utils
#obj_type, #reindex, #sanitize, #sanitize_content, #sanitize_description
Methods included from RelationHelpers
#clappers, #claps_count, #followers, #followers_count, #reviews_count, #saves_count
Methods included from RecsysHelpers
Methods included from NotificationsHelpers
#notif_new_follower, #notif_new_member, #notif_pending_member
Methods included from Membership
#admins, #has_privacy?, #members, #members_count, #owners, #pending_members, #users, #users_sm
Methods included from Feedable
Methods included from Bannerable
Methods included from Avatarable
Methods included from AffiliatableChild
#add_affiliation_to, #remove_affiliation_to
Instance Method Details
#add_user_from_challenges ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/models/program.rb', line 44 def add_user_from_challenges challenges.each do |challenge| challenge.users.each do |user| next if users.include? user user.add_role(:member, self) end end end |
#all_owners_admins_members ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/models/program.rb', line 67 def all_owners_admins_members query = super() challenges.each do |challenge| query = query.or(challenge.all_owners_admins_members) end query end |
#frontend_link ⇒ Object
NOTE: the frontend has chosen "program" singular vs "programs" plural
63 64 65 |
# File 'app/models/program.rb', line 63 def frontend_link "/program/#{short_title}" end |
#needs_count ⇒ Object
54 55 56 |
# File 'app/models/program.rb', line 54 def needs_count challenges.includes(challenges_projects: { project: :needs }).where("challenges_projects.project_status = #{ChallengesProject.project_statuses[:accepted]}").count(:needs) end |
#projects_count ⇒ Object
58 59 60 |
# File 'app/models/program.rb', line 58 def projects_count challenges.includes(:projects).where("challenges_projects.project_status = #{ChallengesProject.project_statuses[:accepted]}").where.not("projects.status": :draft).count(:projects) end |
#user_is_member?(user) ⇒ Boolean
75 76 77 78 79 |
# File 'app/models/program.rb', line 75 def user_is_member?(user) return true if super(user) challenges.any? { |challenge| challenge.user_is_member?(user) } end |