Class: SocialFramework::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SocialFramework::Event
- Defined in:
- app/models/social_framework/event.rb
Overview
Class that represents events that may have a schedule
Instance Method Summary collapse
-
#add_route(user, route) ⇒ Object
- Add a route to this event ====== Params:
user
User
responsible to add the route to eventroute
-
Route
to add to event Returns nil if inviting has not :add_route permission or isn’t in event.
- Add a route to this event ====== Params:
-
#change_participant_role(maker, participant, action) ⇒ Object
- Make a event participant an administrator or inviter ====== Params:
maker
User
responsible to make other user an administrator, should be current_userparticipant
User
to make administratoraction
-
Symbol
to verify Returns ParticipantEvent updated or nil if maker has no actions required.
- Make a event participant an administrator or inviter ====== Params:
-
#invite(inviting, guest, relationship = SocialFramework.relationship_type_to_invite) ⇒ Object
- Invite someone to an event # ====== Params:
inviting
User
responsible to invite other user, should be current_userguest
User
invited, must be in inviting relationshipsrelationship
-
String
relationships types to find users, default is all to consider any relationship, can be an Array too with multiple relationships types Returns nil if inviting has not :invite permission or isn’t in event or the new ParticipantEvent created.
- Invite someone to an event # ====== Params:
-
#remove_participant(remover, participant) ⇒ Object
- Remove participants of the event ====== Params:
remover
User
responsible to remove participant, should be current_userparticipant
-
User
to remove Returns nil if has no permission or ParcipantEvent removed.
- Remove participants of the event ====== Params:
-
#users(confirmed = true, role = "all") ⇒ Object
- Get all users confirmed or not in event ====== Params:
confirmed
-
Boolean
specify if users are confirmed or no Event users.
- Get all users confirmed or not in event ====== Params:
Instance Method Details
#add_route(user, route) ⇒ Object
Add a route to this event
Params:
user
-
User
responsible to add the route to event route
-
Route
to add to event
Returns nil if inviting has not :add_route permission or isn’t in event
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/social_framework/event.rb', line 80 def add_route(user, route) participant_event = participant_event_class.find_by_event_id_and_schedule_id_and_confirmed( self.id, user.schedule.id, true) return if participant_event.nil? if (:add_route, participant_event) self.route = route relation_users_route self.save end end |
#change_participant_role(maker, participant, action) ⇒ Object
Make a event participant an administrator or inviter
Params:
maker
-
User
responsible to make other user an administrator, should be current_user participant
-
User
to make administrator action
-
Symbol
to verify
Returns ParticipantEvent updated or nil if maker has no actions required
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/social_framework/event.rb', line 32 def change_participant_role maker, participant, action maker = participant_event_class.find_by_event_id_and_schedule_id(self.id, maker.schedule.id) participant = participant_event_class.find_by_event_id_and_schedule_id(self.id, participant.schedule.id) return false if maker.nil? or participant.nil? words = action.to_s.split('_') if execute_action?(action, maker, participant, words.first) if action == :make_creator maker.role = "admin" maker.save end role = (words.first == "remove" ? "participant" : words.last) participant.role = role if words.first == "make" or participant.role == words.last return participant.save end return false end |
#invite(inviting, guest, relationship = SocialFramework.relationship_type_to_invite) ⇒ Object
Invite someone to an event # ====== Params:
inviting
-
User
responsible to invite other user, should be current_user guest
-
User
invited, must be in inviting relationships relationship
-
String
relationships types to find users, default is all to consider any relationship, can be an Array too with multiple relationships types
Returns nil if inviting has not :invite permission or isn’t in event or the new ParticipantEvent created
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/social_framework/event.rb', line 14 def invite inviting, guest, relationship = SocialFramework.relationship_type_to_invite participant_event = participant_event_class.find_by_event_id_and_schedule_id( self.id, inviting.schedule.id) return if participant_event.nil? = SocialFramework.[participant_event.role.to_sym].include? :invite if inviting.relationships(relationship).include?(guest) and participant_event_class.create(event: self, schedule: guest.schedule, confirmed: false, role: "participant") end end |
#remove_participant(remover, participant) ⇒ Object
Remove participants of the event
Params:
remover
-
User
responsible to remove participant, should be current_user participant
-
User
to remove
Returns nil if has no permission or ParcipantEvent removed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/social_framework/event.rb', line 58 def remove_participant(remover, participant) return if remover.nil? or participant.nil? remover = participant_event_class.find_by_event_id_and_schedule_id(self.id, remover.schedule.id) participant_event = participant_event_class.find_by_event_id_and_schedule_id( self.id, participant.schedule.id) return if remover.nil? or participant_event.nil? = "remove_#{participant_event.role}".to_sym if execute_action?(, remover, participant_event, "remove") self.route.users.delete(participant) unless self.route.nil? participant_event.destroy end end |
#users(confirmed = true, role = "all") ⇒ Object
Get all users confirmed or not in event
Params:
confirmed
-
Boolean
specify if users are confirmed or no
Event users
97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/social_framework/event.rb', line 97 def users confirmed = true, role = "all" result = Array.new participant_events.each do |participant| if (participant.confirmed == confirmed and (participant.role == role or role == "all")) result << participant.schedule.user end end return result end |