Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
getting sponsors and speakers per event
ij committed Apr 5, 2017
1 parent c7e8d53 commit d3e9961
Showing 4 changed files with 41 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/sf/reg_registration.rb
@@ -1,7 +1,7 @@
require "csv"
class Sf::RegRegistration
include Sf::Base
attr_accessor :registration, :zip
attr_accessor :registration, :zip, :speaker, :sponsor

FIELDS = ['account_id', 'cc_email', 'city', 'contact_id', 'country',
'created_at', 'designation', 'email', 'event_code',
@@ -16,6 +16,8 @@ class Sf::RegRegistration
'fax_number', 'check_in_at', 'receipt_id' ]

FIELDS_SELECT_STR = FIELDS.map{|fd| "#{fd}__c"}.join(', ')
CKIN_REG_ITEMS_NO_DISP = %w(rwelcome paoi QFIRST)
CKIN_REG_RATES_NO_DISP = %w(MK20 MOURATE MRATE MINCOM MEARLY GENERAL CRATE CMOU MFEDDISC NMEM MDAY)

def initialize(reg_registration=nil)
@reg_registration = reg_registration.nil? ? Restforce::SObject.new(sobject_type: 'RegRegistration__c') : reg_registration
@@ -213,5 +215,16 @@ def self.to_csv(list)
end
end
end

def self.with_speakers_and_sponsors(event_code, attendees)
speaker_ids = Sf::Session.presenter_ids_by_event_code(event_code)
sponsor_ids = Sf::Sponsorship.by_event_code(event_code).map(&:sponsor__c)
attendees.map do |a|
a.speaker = true if speaker_ids.include?(a.contact_id__c)
a.sponsor = true if sponsor_ids.include?(a.account_id__c)
a
end
end

end

13 changes: 13 additions & 0 deletions lib/sf/session.rb
@@ -79,6 +79,19 @@ def self.by_event_code(code)
self.where(event__c: event.Id) unless event.blank?
end

def self.presenters_by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
sobjects = Sf.client.query("select Id, cms_session_id__c, (select Id, contact_id__c from Event_Presenters__r)
from EventSession__c where event__c = \'#{event.Id}\'")
build_collection sobjects unless sobjects.blank?
end

def self.presenter_ids_by_event_code(code)
self.presenters_by_event_code(code).map do |s|
s.Event_Presenters__r.map(&:contact_id__c) unless s.Event_Presenters__r.blank?
end.flatten.uniq.compact
end

def self.unpublished_by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
self.where(event__c: event.Id, cms_session_id__c: '') unless event.blank?
14 changes: 13 additions & 1 deletion lib/sf/sponsorship.rb
@@ -1,6 +1,6 @@
class Sf::Sponsorship
include Sf::Base
attr_reader :sobject
attr_reader :sobject
attr_accessor :sponsor

def initialize(sobject=nil)
@@ -35,6 +35,18 @@ def update_from_sponsor
attrs["Id"] = self.Id
Sf.client.update!("EventSponsorship__c", attrs) if self.sponsor.present?
end

def self.by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
self.where(event__c: event.Id) unless event.blank?
end
def self.where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select Id, event__c, contact__c, sponsor__c, logo_url__c,
cms_sponsor_id__c, cms_sponsor_name__c, sponsorship_type__c
from EventSponsorship__c where #{where}")
build_collection sobjects unless sobjects.blank?
end
end


2 changes: 1 addition & 1 deletion lib/sf/version.rb
@@ -1,3 +1,3 @@
module Sf
VERSION = "0.1.46"
VERSION = "0.1.47"
end

0 comments on commit d3e9961

Please sign in to comment.